-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
248 lines (210 loc) · 7.24 KB
/
main.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
#include <glib.h>
#include <glib-object.h>
#include <glib/gstdio.h>
#include <ibus.h>
#include "module.h"
struct IBusModuleEngineClass
{
IBusEngineClass parent;
};
static IBusEngineClass *parent_class = NULL;
static SimpleIMForIBus *module_ = nullptr;
static void ibus_simpleim_engine_class_init(IBusModuleEngineClass *);
static void ibus_simpleim_engine_init(IBusEngine *engine);
static void ibus_simpleim_engine_destroy(IBusEngine *engine);
static gboolean ibus_simpleim_engine_process_key_event(IBusEngine *engine,
guint keyval,
guint keycode,
guint modifiers);
static void ibus_simpleim_engine_focus_in(IBusEngine *engine);
static void ibus_simpleim_engine_focus_out(IBusEngine *engine);
static void ibus_simpleim_engine_reset(IBusEngine *engine);
static void ibus_simpleim_engine_enable(IBusEngine *engine);
static void ibus_simpleim_engine_disable(IBusEngine *engine);
static void ibus_simpleim_engine_page_up(IBusEngine *engine);
static void ibus_simpleim_engine_page_down(IBusEngine *engine);
static void ibus_simpleim_engine_cursor_up(IBusEngine *engine);
static void ibus_simpleim_engine_cursor_down(IBusEngine *engine);
static void ibus_simpleim_engine_property_activate(IBusEngine *engine,
const gchar *prop_name,
guint prop_state);
static void ibus_simpleim_engine_candidate_clicked(IBusEngine *engine,
guint index,
guint button,
guint state);
static GType ibus_simpleim_engine_get_type()
{
static GType type = 0;
static const GTypeInfo type_info = {
sizeof(IBusModuleEngineClass),
(GBaseInitFunc)NULL,
(GBaseFinalizeFunc)NULL,
(GClassInitFunc)ibus_simpleim_engine_class_init,
NULL,
NULL,
sizeof(SimpleIMForIBus),
0,
(GInstanceInitFunc)ibus_simpleim_engine_init,
};
if (type == 0)
{
type = g_type_register_static(IBUS_TYPE_ENGINE,
"SimpleIMForIBus",
&type_info,
(GTypeFlags)0);
}
return type;
}
static void ibus_simpleim_engine_class_init(IBusModuleEngineClass *klass)
{
ibus_warning("func = %s line = %d\n", __FUNCTION__, __LINE__);
IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS(klass);
IBusEngineClass *engine_class = IBUS_ENGINE_CLASS(klass);
parent_class = (IBusEngineClass *)g_type_class_peek_parent(klass);
ibus_object_class->destroy = (IBusObjectDestroyFunc)ibus_simpleim_engine_destroy;
engine_class->process_key_event = ibus_simpleim_engine_process_key_event;
engine_class->focus_in = ibus_simpleim_engine_focus_in;
engine_class->focus_out = ibus_simpleim_engine_focus_out;
engine_class->reset = ibus_simpleim_engine_reset;
engine_class->enable = ibus_simpleim_engine_enable;
engine_class->disable = ibus_simpleim_engine_disable;
engine_class->page_up = ibus_simpleim_engine_page_up;
engine_class->page_down = ibus_simpleim_engine_page_down;
engine_class->cursor_up = ibus_simpleim_engine_cursor_up;
engine_class->cursor_down = ibus_simpleim_engine_cursor_down;
engine_class->property_activate = ibus_simpleim_engine_property_activate;
engine_class->candidate_clicked = ibus_simpleim_engine_candidate_clicked;
}
static void ibus_simpleim_engine_init(IBusEngine *engine)
{
ibus_warning("func = %s line = %d\n", __FUNCTION__, __LINE__);
module_ = new SimpleIMForIBus(engine);
}
static void ibus_simpleim_engine_destroy(IBusEngine *engine)
{
ibus_warning("func = %s line = %d\n", __FUNCTION__, __LINE__);
delete module_;
}
static gboolean ibus_simpleim_engine_process_key_event(IBusEngine *engine,
guint keyval,
guint keycode,
guint modifiers)
{
module_->keyEvent(engine, keyval, keycode, modifiers);
return false;
}
static void ibus_simpleim_engine_reset(IBusEngine *engine)
{
module_->reset(engine);
}
static void ibus_simpleim_engine_enable(IBusEngine *engine)
{
module_->activate(engine);
}
static void ibus_simpleim_engine_disable(IBusEngine *engine)
{
module_->deactivate(engine);
}
static void ibus_simpleim_engine_focus_in(IBusEngine *engine)
{
ibus_warning("func = %s line = %d\n", __FUNCTION__, __LINE__);
}
static void ibus_simpleim_engine_focus_out(IBusEngine *engine)
{
ibus_warning("func = %s line = %d\n", __FUNCTION__, __LINE__);
}
static void ibus_simpleim_engine_page_up(IBusEngine *engine)
{
(void)(engine);
}
static void ibus_simpleim_engine_page_down(IBusEngine *engine)
{
(void)(engine);
}
static void ibus_simpleim_engine_cursor_up(IBusEngine *engine)
{
(void)(engine);
}
static void ibus_simpleim_engine_cursor_down(IBusEngine *engine)
{
(void)(engine);
}
static void ibus_simpleim_engine_property_activate(IBusEngine *engine,
const gchar *prop_name,
guint prop_state)
{
(void)(engine);
(void)(prop_name);
(void)(prop_state);
}
static void ibus_simpleim_engine_candidate_clicked(IBusEngine *engine,
guint index,
guint button,
guint state)
{
(void)(engine);
(void)(index);
(void)(button);
(void)(state);
}
class ConnectToIBus
{
public:
ConnectToIBus()
{
init_with_ibus();
init_with_factory();
}
~ConnectToIBus()
{
g_object_unref(bus_);
g_object_unref(factory_);
}
void exec()
{
ibus_main();
}
private:
void init_with_ibus()
{
ibus_init();
bus_ = ibus_bus_new();
if (!ibus_bus_is_connected(bus_))
{
ibus_warning("ibus bus is not connect!");
exit(0);
}
g_signal_connect(bus_, "disconnected", G_CALLBACK(ibus_disconnect_cb), NULL);
}
void init_with_factory()
{
GType type = ibus_simpleim_engine_get_type();
if (type == G_TYPE_INVALID)
{
ibus_warning("Can not create engine type!\n");
exit(1);
}
factory_ = ibus_factory_new(ibus_bus_get_connection(bus_));
ibus_factory_add_engine(factory_, "SimpleInputMethod", type);
if (!ibus_bus_request_name(bus_, "com.simple.InputMethod", 0))
{
ibus_warning("error requesting bus name!");
}
}
static void ibus_disconnect_cb()
{
ibus_warning("bus disconnected\n");
ibus_quit();
}
private:
IBusBus *bus_ = nullptr;
IBusComponent *component = nullptr;
IBusFactory *factory_ = nullptr;
};
int main(int argc, char **argv)
{
ibus_warning("ibus - simpleim input method.\n");
ConnectToIBus connectToIBus;
connectToIBus.exec();
return 0;
}