Blame engine/main.vala

Packit 3ff832
/* vim:set et sts=4 sw=4:
Packit 3ff832
 *
Packit 3ff832
 * ibus - The Input Bus
Packit 3ff832
 *
Packit 3ff832
 * Copyright (c) 2011-2013 Peng Huang <shawn.p.huang@gmail.com>
Packit 3ff832
 * Copyright (c) 2015 Takao Fujiwara <takao.fujiwara1@gmail.com>
Packit 3ff832
 *
Packit 3ff832
 * This library is free software; you can redistribute it and/or
Packit 3ff832
 * modify it under the terms of the GNU Lesser General Public
Packit 3ff832
 * License as published by the Free Software Foundation; either
Packit 3ff832
 * version 2.1 of the License, or (at your option) any later version.
Packit 3ff832
 *
Packit 3ff832
 * This library is distributed in the hope that it will be useful,
Packit 3ff832
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 3ff832
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 3ff832
 * Lesser General Public License for more details.
Packit 3ff832
 *
Packit 3ff832
 * You should have received a copy of the GNU Lesser General Public
Packit 3ff832
 * License along with this library; if not, write to the Free Software
Packit 3ff832
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
Packit 3ff832
 * USA
Packit 3ff832
 */
Packit 3ff832
Packit 3ff832
using IBus;
Packit 3ff832
Packit 3ff832
class DummyEngine : IBus.EngineSimple {
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
public int main(string[] args) {
Packit 3ff832
    Intl.setlocale(LocaleCategory.ALL, "");
Packit 3ff832
    IBus.init();
Packit 3ff832
Packit 3ff832
    IBus.Bus bus = new IBus.Bus();
Packit 3ff832
    if (!bus.is_connected()) {
Packit 3ff832
        warning("ibus-daemon does not exist.");
Packit 3ff832
        return 1;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    bus.disconnected.connect((bus) => {
Packit 3ff832
        debug("bus disconnected");
Packit 3ff832
        IBus.quit();
Packit 3ff832
    });
Packit 3ff832
Packit 3ff832
    IBus.Factory factory = new IBus.Factory(bus.get_connection());
Packit 3ff832
    
Packit 3ff832
    int id = 0;
Packit 3ff832
Packit 3ff832
    factory.create_engine.connect((factory, name) => {
Packit 3ff832
        if (!name.has_prefix("xkb:"))
Packit 3ff832
            return null;
Packit 3ff832
Packit 3ff832
        const string path = "/org/freedesktop/IBus/engine/simple/%d";
Packit 3ff832
Packit 3ff832
        IBus.Engine engine = new IBus.Engine.with_type(
Packit 3ff832
            typeof(IBus.EngineSimple), name,
Packit 3ff832
            path.printf(++id), bus.get_connection());
Packit 3ff832
Packit 3ff832
        /* Use Idle.add() to reduce the lag caused by file io */
Packit 3ff832
        GLib.Idle.add(() => {
Packit 3ff832
            /* I think "c" + "'" is c with acute U+0107 and
Packit 3ff832
             * "c" + "," is c with cedilla U+00E7 and they are
Packit 3ff832
             * visually comprehensible. But pt-br people need
Packit 3ff832
             * "c" + "'" is c with cedilla and I think the
Packit 3ff832
             * cedilla_compose_seqs is needed for the specific keyboards
Packit 3ff832
             * or regions.
Packit 3ff832
             * X11 uses compose by locale:
Packit 3ff832
             * In /usr/share/X11/locale/en_US.UTF-8/Compose ,
Packit 3ff832
             * <Multi_key> <apostrophe> <c> : U0107
Packit 3ff832
             */
Packit 3ff832
            IBus.EngineSimple? simple = (IBus.EngineSimple ?) engine; 
Packit 3ff832
            simple.add_table_by_locale(null);
Packit 3ff832
Packit 3ff832
            string user_file = null;
Packit 3ff832
Packit 3ff832
            var home = GLib.Environment.get_home_dir();
Packit 3ff832
            if (home != null) {
Packit 3ff832
                user_file = home + "/.XCompose";
Packit 3ff832
                if (GLib.FileUtils.test(user_file, GLib.FileTest.EXISTS))
Packit 3ff832
                    simple.add_compose_file(user_file);
Packit 3ff832
            }
Packit 3ff832
Packit 3ff832
            user_file = GLib.Environment.get_variable("XCOMPOSEFILE");
Packit 3ff832
            if (user_file != null) {
Packit 3ff832
                if (GLib.FileUtils.test(user_file, GLib.FileTest.EXISTS))
Packit 3ff832
                    simple.add_compose_file(user_file);
Packit 3ff832
            }
Packit 3ff832
Packit 3ff832
            return false;
Packit 3ff832
        });
Packit 3ff832
Packit 3ff832
        return engine;
Packit 3ff832
    });
Packit 3ff832
Packit 3ff832
    uint flags = 
Packit 3ff832
        IBus.BusNameFlag.REPLACE_EXISTING |
Packit 3ff832
        IBus.BusNameFlag.ALLOW_REPLACEMENT;
Packit 3ff832
    uint retval = bus.request_name("org.freedesktop.IBus.Simple", flags);
Packit 3ff832
Packit 3ff832
    if (retval == 0) {
Packit 3ff832
        warning("Registry bus name org.freedesktop.IBus.Simple failed!");
Packit 3ff832
        return 1;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    IBus.main();
Packit 3ff832
Packit 3ff832
    return 0;
Packit 3ff832
}