summaryrefslogtreecommitdiff
path: root/engine/main.vala
blob: d2b2b481e8bbe9a49565fa07f9d8cd283cce6986 (plain)
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
/* vim:set et sts=4 sw=4:
 *
 * ibus - The Input Bus
 *
 * Copyright(c) 2011-2013 Peng Huang <shawn.p.huang@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
 * USA
 */

using IBus;

class DummyEngine : IBus.EngineSimple {
}

public int main(string[] args) {
    Intl.setlocale(LocaleCategory.ALL, "");
    IBus.init();

    IBus.Bus bus = new IBus.Bus();
    if (!bus.is_connected()) {
        warning("ibus-daemon does not exist.");
        return 1;
    }

    bus.disconnected.connect((bus) => {
        debug("bus disconnected");
        IBus.quit();
    });

    IBus.Factory factory = new IBus.Factory(bus.get_connection());
    
    int id = 0;

    factory.create_engine.connect((factory, name) => {
        const string path = "/org/freedesktop/IBus/engine/simple/%d";

        IBus.Engine engine = new IBus.Engine.with_type(
            typeof(IBus.EngineSimple), name,
            path.printf(++id), bus.get_connection());

        /* I think "c" + "'" is c with acute U+0107 and
         * "c" + "," is c with cedilla U+00E7 and they are
         * visually comprehensible. But pt-br people need
         * "c" + "'" is c with cedilla and I think the
         * cedilla_compose_seqs is needed for the specific keyboards
         * or regions.
         * X11 uses compose by locale:
         * In /usr/share/X11/locale/en_US.UTF-8/Compose ,
         * <Multi_key> <apostrophe> <c> : U0107
         * At the moment, LC_CTYPE is checked here.
         * I am not sure if cedilla_compose_seqs is needed for us layout.
         * FIXME: Need to provide the customization.
         */
        IBus.EngineSimple? simple = (IBus.EngineSimple ?) engine; 
        simple.add_table_by_locale(null);

        return engine;
    });

    uint flags = 
        IBus.BusNameFlag.REPLACE_EXISTING |
        IBus.BusNameFlag.ALLOW_REPLACEMENT;
    uint retval = bus.request_name("org.freedesktop.IBus.Simple", flags);

    if (retval == 0) {
        warning("Registry bus name org.freedesktop.IBus.Simple failed!");
        return 1;
    }

    IBus.main();

    return 0;
}