This repository has been archived by the owner on May 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
factory.cpp
251 lines (218 loc) · 6.71 KB
/
factory.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* Copyright (C) Hiroyuki Ikezoe <poincare@ikezoe.net>
* Copyright (C) 2004 Takuro Ashie <ashie@homa.ne.jp>
* Copyright (C) 2012 CSSlayer
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*
* The original code is scim_uim_imengine.cpp in scim-uim-0.1.3.
* Copyright (C) 2004 James Su <suzhe@tsinghua.org.cn>
*/
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <fcitx/instance.h>
#include <libintl.h>
#include <fcitx-config/xdg.h>
#include <fcitx/hook.h>
#include <fcitx-utils/log.h>
#include <errno.h>
#include "factory.h"
#include "imengine.h"
static void* FcitxAnthyCreate(FcitxInstance* instance);
static void FcitxAnthyDestory(void* arg);
static boolean FcitxAnthyInit(void* arg);
static INPUT_RETURN_VALUE FcitxAnthyDoInput(void* arg, FcitxKeySym sym, unsigned int state);
static INPUT_RETURN_VALUE FcitxAnthyDoReleaseInput(void* arg, FcitxKeySym sym, unsigned int state);
static void FcitxAnthyReloadConfig(void* arg);
static void FcitxAnthySave(void* arg);
static void FcitxAnthyReset(void* arg);
static void FcitxAnthyFocusIn(void* arg);
static void FcitxAnthyResetIM(void* arg);
static void FcitxAnthyOnClose(void* arg, FcitxIMCloseEventType event);
static const char * FcitxAnthyGetSubModeName(void* arg);
FCITX_DEFINE_PLUGIN(fcitx_anthy, ime2, FcitxIMClass2) = {
FcitxAnthyCreate,
FcitxAnthyDestory,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
};
void* FcitxAnthyCreate(FcitxInstance* instance)
{
if (anthy_init())
return NULL;
AnthyInstance* anthy = new AnthyInstance(instance);
if (!anthy->load_config()) {
anthy_quit();
delete anthy;
return NULL;
}
bindtextdomain("fcitx-anthy", LOCALEDIR);
bind_textdomain_codeset("fcitx-anthy", "UTF-8");
FcitxIMIFace iface;
memset(&iface, 0, sizeof(FcitxIMIFace));
iface.Init = FcitxAnthyInit;
iface.ResetIM = FcitxAnthyResetIM;
iface.DoInput = FcitxAnthyDoInput;
iface.DoReleaseInput = FcitxAnthyDoReleaseInput;
iface.ReloadConfig = FcitxAnthyReloadConfig;
iface.Save = FcitxAnthySave;
iface.OnClose = FcitxAnthyOnClose;
iface.GetSubModeName = FcitxAnthyGetSubModeName;
FcitxInstanceRegisterIMv2(
instance,
anthy,
"anthy",
_("Anthy"),
"anthy",
iface,
1,
"ja"
);
FcitxIMEventHook hk;
hk.arg = anthy;
hk.func = FcitxAnthyReset;
FcitxInstanceRegisterResetInputHook(instance, hk);
hk.func = FcitxAnthyFocusIn;
FcitxInstanceRegisterInputFocusHook(instance, hk);
return anthy;
}
void FcitxAnthyDestory(void* arg)
{
AnthyInstance* anthy = (AnthyInstance*) arg;
delete anthy;
anthy_quit();
}
boolean FcitxAnthyInit(void* arg)
{
AnthyInstance* anthy = (AnthyInstance*) arg;
anthy->init();
anthy->update_ui();
return true;
}
void FcitxAnthyResetIM(void* arg)
{
AnthyInstance* anthy = (AnthyInstance*) arg;
anthy->reset_im();
anthy->update_ui();
}
void FcitxAnthyReset(void* arg)
{
AnthyInstance* anthy = (AnthyInstance*) arg;
anthy->reset();
anthy->update_ui();
}
void FcitxAnthyShowIMInfo(void* arg)
{
AnthyInstance* anthy = (AnthyInstance*) arg;
static FcitxInputContext* ic;
// don't show the info again if ic is not changed, this is annoying
// when cursor jumps within same application.
FcitxInputContext* newic = FcitxInstanceGetCurrentIC(anthy->get_owner());
if (newic == ic) {
return;
}
ic = newic;
if (!ic) {
return;
}
FcitxIM* im = FcitxInstanceGetCurrentIM(anthy->get_owner());
if (im && strcmp(im->uniqueName, "anthy") == 0) {
FcitxInstanceShowCurrentIMInfo(anthy->get_owner());
}
}
void FcitxAnthyFocusIn(void* arg)
{
AnthyInstance* anthy = (AnthyInstance*) arg;
FcitxInstance* instance = anthy->get_owner();
if (anthy->get_config()->m_show_input_mode_on_focus &&
!FcitxInstanceCheckTimeoutByFunc(instance, FcitxAnthyShowIMInfo)) {
FcitxInstanceAddTimeout(instance, 100, FcitxAnthyShowIMInfo, anthy);
}
}
void FcitxAnthySave(void* arg)
{
}
INPUT_RETURN_VALUE FcitxAnthyDoInput(void* arg, FcitxKeySym sym, unsigned int state)
{
AnthyInstance* anthy = (AnthyInstance*) arg;
KeyEvent event;
FcitxInputState* input = FcitxInstanceGetInputState(anthy->get_owner());
event.sym = (FcitxKeySym) FcitxInputStateGetKeySym(input);
event.is_release = false;
event.keycode = FcitxInputStateGetKeyCode(input);
event.state = FcitxInputStateGetKeyState(input) & FcitxKeyState_SimpleMask;
bool result = anthy->process_key_event(event);
anthy->update_ui();
if (result)
return IRV_DO_NOTHING;
else
return IRV_TO_PROCESS;
}
INPUT_RETURN_VALUE FcitxAnthyDoReleaseInput(void* arg, FcitxKeySym sym, unsigned int state)
{
AnthyInstance* anthy = (AnthyInstance*) arg;
KeyEvent event;
FcitxInputState* input = FcitxInstanceGetInputState(anthy->get_owner());
event.sym = (FcitxKeySym) FcitxInputStateGetKeySym(input);
event.keycode = FcitxInputStateGetKeyCode(input);
event.is_release = true;
event.state = FcitxInputStateGetKeyState(input) & FcitxKeyState_SimpleMask;
bool result = anthy->process_key_event(event);
anthy->update_ui();
if (result)
return IRV_DO_NOTHING;
else
return IRV_TO_PROCESS;
}
void FcitxAnthyReloadConfig(void* arg)
{
AnthyInstance* anthy = (AnthyInstance*) arg;
anthy->load_config();
anthy->configure();
anthy->update_ui();
}
void FcitxAnthyOnClose(void* arg, FcitxIMCloseEventType event)
{
AnthyInstance* anthy = (AnthyInstance*) arg;
anthy->auto_commit(event);
}
const char * FcitxAnthyGetSubModeName(void *arg)
{
AnthyInstance* anthy = (AnthyInstance*) arg;
return anthy->get_input_mode_name();
}
void
SaveAnthyConfig(AnthyInstance* anthy)
{
anthy->save_config();
}
boolean
LoadAnthyConfig(AnthyInstance* anthy)
{
anthy->load_config();
return true;
}
void ConfigAnthy(AnthyInstance* anthy) {
anthy->configure();
anthy->update_ui();
}