Debian Codegraph @

engine/main.vala

raw
1 /* vim:set et sts=4 sw=4:
2 *
3 * ibus - The Input Bus
4 *
5 * Copyright (c) 2011-2013 Peng Huang <[email protected]>
6 * Copyright (c) 2015-2025 Takao Fujiwara <[email protected]>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
21 * USA
22 */
23
24 using IBus;
25
26 static IBus.EngineSimple m_simple;
27
28 class DummyEngine : IBus.EngineSimple {
29 }
30
31 public int main(string[] args) {
32 Intl.setlocale(LocaleCategory.ALL, "");
33 IBus.init();
34
35 IBus.Bus bus = new IBus.Bus();
36 if (!bus.is_connected()) {
37 warning("ibus-daemon does not exist.");
38 return 1;
39 }
40
41 bus.disconnected.connect((bus) => {
42 debug("bus disconnected");
43 IBus.quit();
44 });
45
46 IBus.Factory factory = new IBus.Factory(bus.get_connection());
47
48 int id = 0;
49
50 factory.create_engine.connect((factory, name) => {
51 if (!name.has_prefix("xkb:"))
52 return null;
53
54 const string path = "/org/freedesktop/IBus/engine/simple/%d";
55
56 IBus.Engine engine = new IBus.Engine.with_type(
57 typeof(IBus.EngineSimple), name,
58 path.printf(++id), bus.get_connection());
59 /* the type change causes engine.ref(). */
60 m_simple = (IBus.EngineSimple)engine;
61 m_simple.unref();
62
63 /* Use Idle.add() to reduce the lag caused by file io */
64 GLib.Idle.add(() => {
65 /* I think "c" + "'" is c with acute U+0107 and
66 * "c" + "," is c with cedilla U+00E7 and they are
67 * visually comprehensible. But pt-br people need
68 * "c" + "'" is c with cedilla and I think the
69 * cedilla_compose_seqs is needed for the specific keyboards
70 * or regions.
71 * X11 uses compose by locale:
72 * In /usr/share/X11/locale/en_US.UTF-8/Compose ,
73 * <Multi_key> <apostrophe> <c> : U0107
74 */
75 m_simple.add_table_by_locale(null);
76
77 string user_file = null;
78
79 var home = GLib.Environment.get_home_dir();
80 if (home != null) {
81 user_file = home + "/.XCompose";
82 if (GLib.FileUtils.test(user_file, GLib.FileTest.EXISTS))
83 m_simple.add_compose_file(user_file);
84 }
85
86 user_file = GLib.Environment.get_variable("XCOMPOSEFILE");
87 if (user_file != null) {
88 if (GLib.FileUtils.test(user_file, GLib.FileTest.EXISTS))
89 m_simple.add_compose_file(user_file);
90 }
91
92 return false;
93 });
94
95 return engine;
96 });
97
98 uint flags =
99 IBus.BusNameFlag.REPLACE_EXISTING |
100 IBus.BusNameFlag.ALLOW_REPLACEMENT;
101 uint retval = bus.request_name("org.freedesktop.IBus.Simple", flags);
102
103 if (retval == 0) {
104 warning("Registry bus name org.freedesktop.IBus.Simple failed!");
105 return 1;
106 }
107
108 IBus.main();
109 m_simple = null;
110
111 return 0;
112 }