Example #1
0
static void
start_component (void)
{
    GList *engines, *p;
    IBusComponent *component;

    ibus_init ();

    bus = ibus_bus_new ();
    g_signal_connect (bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NULL);

    component = ibus_xkb_get_component ();

    factory = ibus_factory_new (ibus_bus_get_connection (bus));

    engines = ibus_component_get_engines (component);
    for (p = engines; p != NULL; p = p->next) {
        IBusEngineDesc *engine = (IBusEngineDesc *)p->data;
        ibus_factory_add_engine (factory, engine->name, IBUS_TYPE_XKB_LAYOUT_ENGINE);
    }

    if (ibus) {
        ibus_bus_request_name (bus, "org.freedesktop.IBus.XKBLayouts", 0);
    }
    else {
        ibus_bus_register_component (bus, component);
    }

    g_object_unref (component);

    ibus_main ();
}
Example #2
0
int main()
{
	IBusBus *bus;

#if !GLIB_CHECK_VERSION(2,35,0)
	g_type_init ();
#endif
	IBUS_TYPE_ENGINE_DESC;

	bus = ibus_bus_new ();
	engines = ibus_bus_list_active_engines (bus);
	g_assert (engines);

	g_debug ("===== Global engine:");
	if (ibus_bus_get_use_global_engine (bus) == FALSE)
        return 0;

	g_signal_connect (bus, "global-engine-changed",
                          G_CALLBACK (global_engine_changed_cb), bus);

	g_idle_add ((GSourceFunc)change_global_engine_cb, bus);

	ibus_main();

	g_debug ("Test ibusbus.c's global engine api: passed.");
	g_list_free (engines);
	g_object_unref (bus);

	return 0;
}
Example #3
0
static gboolean
init (void)
{
  ibus_init ();

  bus = ibus_bus_new ();
  g_object_ref_sink (bus);
  g_signal_connect (bus, "disconnected", G_CALLBACK (ibus_disconnected_cb),
                    NULL);
	
  ibus_libthai_init (bus);

  factory = ibus_factory_new (ibus_bus_get_connection (bus));
  g_object_ref_sink (factory);
  ibus_factory_add_engine (factory, "libthai", IBUS_TYPE_LIBTHAI_ENGINE);

  if (opt_ibus)
    {
      ibus_bus_request_name (bus, "org.freedesktop.IBus.LibThai", 0);
    }
  else
    {
      IBusComponent *component;

      component = ibus_libthai_get_component ();
      if (!component)
        {
          g_print ("Cannot create LibThai component.\n");
          return FALSE;
        }
      ibus_bus_register_component (bus, component);
    }

  return TRUE;
}
Example #4
0
static void init_outside(const char * iconfile, const char *exefile)
{
    IBusComponent *component;
    IBusEngineDesc * desc;

    ibus_init();

    bus = ibus_bus_new();
    g_signal_connect (bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NULL);

    factory = ibus_factory_new(ibus_bus_get_connection(bus));

    ibus_bus_request_name(bus, "org.freedesktop.IBus.handwrite", 0);

    desc = ibus_engine_desc_new("handwrite", "handwrite",
                                _("hand write recognizer"), "zh_CN", "GPL",
                                MICROCAI_WITHEMAIL, iconfile, "us");

    component = ibus_component_new("org.freedesktop.IBus.handwrite",
                                   "handwrite", PACKAGE_VERSION, "GPL", MICROCAI_WITHEMAIL, PACKAGE_BUGREPORT,
                                   exefile, GETTEXT_PACKAGE);

    ibus_component_add_engine(component, desc);

    ibus_bus_register_component(bus, component);

    ibus_factory_add_engine(factory, "handwrite", IBUS_TYPE_HANDWRITE_ENGINE);

    g_object_unref(component);
}
Example #5
0
static void start_component(void)
{
    IBUS_CHEWING_LOG(INFO, "start_component");
    ibus_init();
    bus = ibus_bus_new();
    g_signal_connect(bus, "disconnected", G_CALLBACK(ibus_disconnected_cb),
		     NULL);

    factory = ibus_factory_new(ibus_bus_get_connection(bus));

    ibus_factory_add_engine(factory, "chewing", IBUS_TYPE_CHEWING_ENGINE);

    if (ibus) {
	ibus_bus_request_name(bus, QUOTE_ME(PROJECT_SCHEMA_ID), 0);
    } else {
	IBusComponent *component = NULL;
	if (xml) {
	    component = ibus_component_new_from_file(QUOTE_ME(DATA_DIR)
						     "/ibus/component/chewing.xml");
	} else {
	    component = ibus_component_new(QUOTE_ME(PROJECT_SCHEMA_ID),
					   _("Chewing component"),
					   QUOTE_ME(PRJ_VER), "GPLv2+",
					   _("Peng Huang, Ding-Yi Chen"),
					   "http://code.google.com/p/ibus",
					   QUOTE_ME(LIBEXEC_DIR)
					   "/ibus-engine-chewing --ibus",
					   QUOTE_ME(PROJECT_NAME));
	}
	IBusEngineDesc *engineDesc =
	    ibus_engine_desc_new_varargs("name", "chewing",
					 "longname", _("Chewing"),
					 "description",
					 _("Chinese chewing input method"),
					 "language", "zh_TW",
					 "license", "GPLv2+",
					 "author",
					 _("Peng Huang, Ding-Yi Chen"),
					 "icon",
					 QUOTE_ME(PRJ_DATA_DIR) "/icons/"
					 QUOTE_ME(PROJECT_NAME) ".png",
					 "layout", "us",
					 "setup",
					 QUOTE_ME(LIBEXEC_DIR)
					 "/ibus-setup-chewing",
					 "version", QUOTE_ME(PRJ_VER),
					 "textdomain",
					 QUOTE_ME(PROJECT_NAME),
					 NULL);
	ibus_component_add_engine(component, engineDesc);
	ibus_bus_register_component(bus, component);
    }
    ibus_main();
}
Example #6
0
static void rime_with_ibus() {
    ibus_init();
    IBusBus *bus = ibus_bus_new();
    g_object_ref_sink(bus);

    if (!ibus_bus_is_connected(bus)) {
        g_warning("not connected to ibus");
        exit(0);
    }

    g_signal_connect(bus, "disconnected", G_CALLBACK(ibus_disconnect_cb), NULL);

    IBusConfig *config = ibus_bus_get_config(bus);
    if (!config) {
        g_warning("ibus config not accessible");
    }
    else {
        g_object_ref_sink(config);
        ibus_rime_load_settings(config);
        g_signal_connect(config, "value-changed",
                         G_CALLBACK(ibus_rime_config_value_changed_cb), NULL);
    }

    IBusFactory *factory = ibus_factory_new(ibus_bus_get_connection(bus));
    g_object_ref_sink(factory);

    ibus_factory_add_engine(factory, "rime", IBUS_TYPE_RIME_ENGINE);
    if (!ibus_bus_request_name(bus, "com.googlecode.rimeime.Rime", 0)) {
        g_error("error requesting bus name");
        exit(1);
    }

    if (!notify_init("ibus-rime")) {
        g_error("notify_init failed");
        exit(1);
    }

    RimeSetupLogging("rime.ibus");

    gboolean full_check = FALSE;
    ibus_rime_start(full_check);

    ibus_main();

    RimeFinalize();
    notify_uninit();

    if (config) {
        g_object_unref(config);
    }
    g_object_unref(factory);
    g_object_unref(bus);
}
Example #7
0
File: main.c Project: hychen/ibus
static void
_init_ibus (void)
{
    if (_bus != NULL)
        return;

    ibus_init ();

    _bus = ibus_bus_new ();

    g_signal_connect (_bus, "disconnected",
                        G_CALLBACK (_bus_disconnected_cb), NULL);
}
Example #8
0
File: main.c Project: Abioy/ibus
static void
ibus_memconf_start (void)
{
    ibus_init ();
    bus = ibus_bus_new ();
    if (!ibus_bus_is_connected (bus)) {
        exit (-1);
    }
    g_signal_connect (bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NULL);
    config = ibus_config_memconf_new (ibus_bus_get_connection (bus));
    ibus_bus_request_name (bus, IBUS_SERVICE_CONFIG, 0);
    ibus_main ();
}
Example #9
0
File: main.c Project: Abioy/ibus
static void
_init_ibus (void)
{
    if (_bus != NULL)
        return;

    ibus_init ();

    _bus = ibus_bus_new ();

    g_signal_connect (_bus, "disconnected",
                        G_CALLBACK (_bus_disconnected_cb), NULL);

    _use_sync_mode = _get_boolean_env ("IBUS_ENABLE_SYNC_MODE", FALSE);
}
Example #10
0
static void
init ()
{
    ibus_init ();
    bus = ibus_bus_new ();
    g_object_ref_sink(bus);
    
    if (!ibus_bus_is_connected (bus)) {
        g_warning("Can not connect to ibus");
        exit (0);
    }
    
    g_signal_connect (bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NULL);
	
    IBusConfig* config = ibus_bus_get_config(bus);
    g_object_ref_sink(config);
    
    SunPinyinConfig::set_config(config);

    
    component = ibus_component_new ("org.freedesktop.IBus.SunPinyin",
                                    "SunPinyin2",
                                    "0.1.0",
                                    "LGPL/CDDL",
                                    "Kov Chai <[email protected]>",
                                    "http://code.google.com/p/sunpinyin/",
                                    "",
                                    "ibus-sunpinyin");
    ibus_component_add_engine (component,
                               ibus_engine_desc_new ("sunpinyin",
                                                     "SunPinyin",
                                                     _("Simplified Chinese Input Method developed by SUN"),
                                                     "zh_CN",
                                                     "LGPL/CDDL",
                                                     "Kov Chai <[email protected]>",
                                                     IBUS_SUNPINYIN_ICON_DIR"/sunpinyin-logo.png",
                                                     "en"));
    
    factory = ibus_factory_new (ibus_bus_get_connection (bus));
    ibus_factory_add_engine (factory, "sunpinyin", IBUS_TYPE_SUNPINYIN_ENGINE);

    if (by_ibus) {
        ibus_bus_request_name (bus, "org.freedesktop.IBus.SunPinyin", 0);
    } else {
        ibus_bus_register_component (bus, component);
    }
    ibus_main ();
}
Example #11
0
File: main.c Project: XueWei/ibus
static void
_init_ibus (void)
{
    if (_bus != NULL)
        return;
    ibus_init ();

    _bus = ibus_bus_new ();

    if (!ibus_bus_is_connected (_bus)) {
        g_error ("Can not connect to ibus-daemon!");
    }

    g_signal_connect (_bus, "disconnected",
                        G_CALLBACK (_bus_disconnected_cb), NULL);
}
Example #12
0
static void
test_list_engines (void)
{
    GList *engines;
    IBusBus *bus;
    IBUS_TYPE_ENGINE_DESC;

    bus = ibus_bus_new ();

    engines = ibus_bus_list_engines (bus);

    g_assert (engines);
    g_list_foreach (engines, (GFunc) g_object_unref, NULL);
    g_list_free (engines);
    g_object_unref (bus);
}
Example #13
0
File: test-bus.c Project: BBIO/ibus
int main()
{
	g_type_init ();

	IBusBus *bus;
	GList *engines;
	IBusInputContext *context;
	IBusEngineDesc *engine_desc;
	gchar *active_engine_name;

	bus = ibus_bus_new ();

	/* Test ibusbus.c */
	g_debug ("===== Active engines:");
	engines = ibus_bus_list_active_engines (bus);
	g_assert (engines);
	active_engine_name = get_last_engine_id (engines);
	print_engines (engines);
	g_list_free (engines);

	g_debug ("===== All engines:");
	engines = ibus_bus_list_engines (bus);
	g_assert (engines);
	print_engines (engines);
	g_list_free (engines);
	g_debug ("Test ibusbus.c: passed.");

	/* Test ibusinputcontext.c */
	context = ibus_bus_create_input_context (bus, "test");
	ibus_input_context_set_capabilities (context, 0);
	ibus_input_context_disable (context);
	g_assert (ibus_input_context_is_enabled (context) == FALSE);
	ibus_input_context_enable (context);
	g_assert (ibus_input_context_is_enabled (context) == TRUE);
	ibus_input_context_set_engine (context, active_engine_name);
	engine_desc = ibus_input_context_get_engine (context);
	g_assert (engine_desc);
	g_assert (!strcmp (active_engine_name, engine_desc->name));
	g_debug ("Test ibusinputcontext.c: passed.");

	g_free (active_engine_name);
	g_object_unref (engine_desc);
	g_object_unref (context);
	g_object_unref (bus);

	return 0;
}
Example #14
0
gint
main (gint    argc,
      gchar **argv)
{
    gint result;
    ibus_init ();
    g_test_init (&argc, &argv, NULL);
    bus = ibus_bus_new ();

    g_test_add_func ("/ibus/input_context", test_input_context);
    g_test_add_func ("/ibus/input_context_async_with_callback", test_async_apis);

    result = g_test_run ();
    g_object_unref (bus);

    return result;
}
Example #15
0
int main()
{
	g_type_init ();

	GMainLoop *mainloop;
	IBusBus *bus;
	IBusInputContext *context;

	mainloop = g_main_loop_new (NULL, FALSE);
	bus = ibus_bus_new ();
	context = ibus_bus_create_input_context (bus, "test");
	ibus_input_context_set_capabilities (context, 0);
	ibus_input_context_destroy (context);
	g_object_unref (context);
	g_object_unref (bus);

	g_main_loop_run (mainloop);

	return 0;
}
Example #16
0
static void
init (void)
{
    IBusComponent *component;

    ibus_init ();

    bus = ibus_bus_new ();
    g_signal_connect (bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NULL);

    ibus_array_init(bus);

    component = ibus_component_new ("org.freedesktop.IBus.Array",
                                    "Array 30 Input Method",
                                    "0.0.1",
                                    "GPL",
                                    "Yu-Chun Wang <[email protected]>",
                                    "http://code.google.com/p/ibus/",
                                    "",
                                    "ibus-array");
    ibus_component_add_engine (component,
                               ibus_engine_desc_new ("array",
                                       "Array 30 Input Method",
                                       "Array 30 Input Method",
                                       "zh_TW",
                                       "GPL",
                                       "Yu-Chun Wang <[email protected]>",
                                       PKGDATADIR"/icon/ibus-array.png",
                                       "us"));

    factory = ibus_factory_new (ibus_bus_get_connection (bus));
    ibus_factory_add_engine (factory, "array", IBUS_TYPE_ARRAY_ENGINE);

    if (ibus) {
        ibus_bus_request_name (bus, "org.freedesktop.IBus.Array", 0);
    }
    else {
        ibus_bus_register_component (bus, component);
    }
    g_object_unref (component);
}
Example #17
0
App::App(int argc, char** argv): QGuiApplication(argc, argv)
    ,m_eventFilter(new XcbEventFilter)
    ,m_init(false)
    ,m_bus(0)
    ,m_impanel(0)
    ,m_keyboardGrabbed(false)
    ,m_doGrab(false)
    ,m_syms(0)
{
    m_syms = xcb_key_symbols_alloc(QX11Info::connection());
    installNativeEventFilter(m_eventFilter.data());
    ibus_init ();
    m_bus = ibus_bus_new ();
    g_signal_connect (m_bus, "connected", G_CALLBACK (ibus_connected_cb), this);
    g_signal_connect (m_bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), this);
    if (ibus_bus_is_connected (m_bus)) {
        init();
    }

    initIconMap(m_iconMap);
}
Example #18
0
static void
bus_test_client_class_init (BusTestClientClass *klass)
{
    IDEBUG ("%s", __FUNCTION__);

    IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (klass);

    ibus_object_class->destroy = bus_test_client_destroy;

    /* init display object */
    if (_xdisplay == NULL) {
        _xdisplay = XOpenDisplay (gdk_display_get_name (gdk_display_get_default ()));
    }

    /* init bus object */
    if (_bus == NULL) {
        ibus_set_display (XDisplayString (_xdisplay));
        _bus = ibus_bus_new();
    }

    g_signal_connect (_bus, "disconnected", G_CALLBACK (_bus_disconnected_cb), NULL);
}
GtkWidget* unikey_main_setup_dialog_new()
{
    GtkBuilder* builder;
    IBusBus* bus;
    GtkDialog* dlgMain;

    ibus_init();
    bus = ibus_bus_new();
    g_signal_connect(bus, "disconnected", G_CALLBACK(gtk_main_quit), NULL);
    config = ibus_bus_get_config(bus);
    
    builder = gtk_builder_new();
    gtk_builder_add_from_file(builder, UI_DATA_DIR "/setup-main.ui", NULL);

    dlgMain = GTK_DIALOG(gtk_builder_get_object(builder, "dlg_main_setup"));

    init_dialog_controls(builder);

    g_object_unref(builder);

    return GTK_WIDGET(dlgMain);
}
Example #20
0
static void init_inside()
{
    IBusComponent *component;

    ibus_init();

    bus = ibus_bus_new();
    g_signal_connect (bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NULL);

    factory = ibus_factory_new(ibus_bus_get_connection(bus));

    ibus_bus_request_name(bus, "org.freedesktop.IBus.handwrite", 0);

    component = ibus_component_new("org.freedesktop.IBus.handwrite",
                                   "handwrite", PACKAGE_VERSION, "GPL", MICROCAI_WITHEMAIL, PACKAGE_BUGREPORT,
                                   PKGDATADIR, GETTEXT_PACKAGE);

    ibus_bus_register_component(bus, component);

    ibus_factory_add_engine(factory, "handwrite", IBUS_TYPE_HANDWRITE_ENGINE);

    g_object_unref(component);
}
Example #21
0
static void start_component (void) {
    GList* engines;
    GList* p;
    IBusComponent* component;

    ibus_init ();
    UnikeySetup ();

    bus = ibus_bus_new ();
    g_signal_connect (bus, "disconnected", G_CALLBACK(ibus_disconnected_cb), NULL);

    component = ibus_unikey_get_component ();

    factory = ibus_factory_new (ibus_bus_get_connection (bus));

    engines = ibus_component_get_engines (component);
    for (p = engines; p != NULL; p = p->next) {
        IBusEngineDesc* engine = (IBusEngineDesc*)p->data;
#if IBUS_CHECK_VERSION(1,3,99)
        ibus_factory_add_engine (factory, ibus_engine_desc_get_name(engine),
                                 IBUS_TYPE_UNIKEY_ENGINE);
#else
        ibus_factory_add_engine (factory, engine->name, IBUS_TYPE_UNIKEY_ENGINE);
#endif
    }

    if (ibus)
        ibus_bus_request_name (bus, "org.freedesktop.IBus.Unikey", 0);
    else
        ibus_bus_register_component (bus, component);

    g_object_unref (component);

    ibus_unikey_init (bus);
    ibus_main ();
    ibus_unikey_exit ();
}
Example #22
0
int main(int argc, char* argv[])
{
	IBusComponent *component;
	IBusEngineDesc * desc;

	GError * err = NULL;

	gboolean have_ibus=FALSE;

	const gchar * language="zh";

	const gchar * icon_dir = NULL;

	const gchar * locale_dir = NULL;


	setlocale(LC_ALL, "");
	gtk_set_locale();
	textdomain(GETTEXT_PACKAGE);

	GOptionEntry args[] =
	{
			{"ibus",'\0',0,G_OPTION_ARG_NONE,&have_ibus},
			{"icondir",'\0',0,G_OPTION_ARG_STRING,&icon_dir,_("the icon file"),N_("icon file")},
			{"table",'\0',0,G_OPTION_ARG_STRING,&tablefile,_("set table file path"),N_("tablefile")},
			{"locale",'\0',0,G_OPTION_ARG_STRING,&locale_dir,_("set locale path"),N_("locale")},
#ifdef WITH_ZINNIA
			{"lang",'\0',0,G_OPTION_ARG_STRING,&language,_("set languate, accept zh and jp"),N_("lang")},
#endif
			{0}
	};

	gtk_init_with_args(&argc,&argv,PACKAGE_NAME,args,PACKAGE_NAME,&err);


	if(G_UNLIKELY(!gtk_gl_init_check(&argc, &argv)))
	{
		g_warning("GLX extension not available, use slow soft cairo rendering instead");
	}

#ifdef WITH_ZINNIA
	if(strcmp(language,"zh")==0 ||strcmp(language,"zh_CN") ==0 )
	{

	}else if( strcmp(language,"jp") ==0 || strcmp(language,"ja")==0 )
	{
		g_strlcpy(lang,"ja",20);
	}else
	{
		g_error("pass jp or zh to --lang!");
	}

#endif

	if(locale_dir)
	{
		bindtextdomain(GETTEXT_PACKAGE,locale_dir);
	}

	gchar * engine_name = g_strdup_printf("handwrite-%s",lang);

	gchar * dbus_name = g_strdup_printf("org.freedesktop.IBus.handwrite-%s",lang);

	ibus_init();

	if(icon_dir)
		realpath(icon_dir, icondir);

	bus = ibus_bus_new();

	g_signal_connect (bus, "disconnected", G_CALLBACK (gtk_main_quit), NULL);

	factory = ibus_factory_new(ibus_bus_get_connection(bus));


	ibus_bus_request_name(bus, dbus_name, 0);

//	g_free(dbus_name);

	if (!have_ibus)
	{
		char * exefile ;

		exefile = realpath(argv[0],NULL);

		component = ibus_component_new(dbus_name,
				"handwrite", PACKAGE_VERSION, "GPL", MICROCAI_WITHEMAIL, PACKAGE_BUGREPORT,
				exefile, GETTEXT_PACKAGE);

		gchar * iconfile =  g_strdup_printf("%s/ibus-handwrite.svg",icondir);

		desc = ibus_engine_desc_new(engine_name, "handwrite",
				_("hand write recognizer"), lang, "GPL",
				MICROCAI_WITHEMAIL, iconfile, "us");

		ibus_component_add_engine(component, desc);

		free(exefile);
		g_free(iconfile);

	}else
	{
		component = ibus_component_new(dbus_name,
				"handwrite", PACKAGE_VERSION, "GPL", MICROCAI_WITHEMAIL, PACKAGE_BUGREPORT,
				PKGDATADIR, GETTEXT_PACKAGE);
	}

	g_free(dbus_name);


	ibus_bus_register_component(bus, component);


	ibus_factory_add_engine(factory, engine_name, IBUS_TYPE_HANDWRITE_ENGINE);

	g_free(engine_name);

	g_object_unref(component);

	GdkScreen * screen = gdk_screen_get_default();
	GdkColormap * map = gdk_screen_get_rgba_colormap(screen);
	if(map)	gtk_widget_set_default_colormap(map);

	printf(_("ibus-handwrite Version %s Start Up\n"), PACKAGE_VERSION);

	gtk_main();
	return 0;
}
Example #23
0
File: main.c Project: KDE/kimtoy
static void
ibus_impanel_start (void)
{
    ibus_init ();
    bus = ibus_bus_new ();
    if (!ibus_bus_is_connected (bus)) {
        exit (-1);
    }
    g_signal_connect (bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NULL);
    impanel = ibus_panel_impanel_new (ibus_bus_get_connection (bus));
    ibus_bus_request_name (bus, IBUS_SERVICE_PANEL, 0);
    ibus_panel_impanel_set_bus(impanel, bus);
#if !IBUS_CHECK_VERSION(1,4,99)
    ibus_main ();
#else

    Display*    dpy     = XOpenDisplay(0);
    Window      root    = DefaultRootWindow(dpy);
    XEvent      ev;

    unsigned int    modifiers       = ControlMask;
    int             keycode         = XKeysymToKeycode(dpy, XK_space);

    XGrabKey(dpy, keycode, modifiers, root, False, GrabModeAsync, GrabModeAsync);
    XGrabKey(dpy, keycode, modifiers | LockMask, root, False, GrabModeAsync, GrabModeAsync); // capslock
    XGrabKey(dpy, keycode, modifiers | Mod2Mask, root, False, GrabModeAsync, GrabModeAsync); // numlock
    XGrabKey(dpy, keycode, modifiers | LockMask | Mod2Mask, root, False, GrabModeAsync, GrabModeAsync);

    XSelectInput(dpy, root, KeyPressMask);

//     XCloseDisplay(dpy);

    main_loop = g_main_loop_new(NULL, FALSE);

    int dpyfd = ConnectionNumber(dpy);
    GPollFD dpy_pollfd = {dpyfd, G_IO_IN | G_IO_HUP | G_IO_ERR, 0};

    GSourceFuncs x11_source_funcs = {
        x11_fd_prepare,
        x11_fd_check,
        x11_fd_dispatch,
        NULL, /* finalize */
        NULL, /* closure_callback */
        NULL /* closure_marshal */
    };

    GSource *x11_source = g_source_new(&x11_source_funcs, sizeof(x11_source_t));
    ((x11_source_t*)x11_source)->dpy = dpy;

    g_source_add_poll(x11_source, &dpy_pollfd);
    g_source_set_can_recurse(x11_source, TRUE);
    g_source_attach(x11_source, NULL);

    g_main_loop_run (main_loop);

    g_main_loop_unref (main_loop);
    main_loop = NULL;

    XUngrabKey(dpy, keycode, modifiers, root);
    XUngrabKey(dpy, keycode, modifiers | LockMask, root);
    XUngrabKey(dpy, keycode, modifiers | Mod2Mask, root);
    XUngrabKey(dpy, keycode, modifiers | LockMask | Mod2Mask, root);

    XCloseDisplay(dpy);
#endif
}
Example #24
0
int main()
{
	g_type_init ();

	IBusBus *bus;
	GList *engines;
	gchar *active_engine_name;

	bus = ibus_bus_new ();

	/* Test ibusbus.c */
	g_debug ("===== Active engines:");
	engines = ibus_bus_list_active_engines (bus);
	g_assert (engines);
	active_engine_name = get_last_engine_id (engines);
	print_engines (engines);
	g_list_free (engines);

	g_debug ("===== All engines:");
	engines = ibus_bus_list_engines (bus);
	g_assert (engines);
	print_engines (engines);
	g_list_free (engines);

	g_debug ("===== Global engine:");
	if (ibus_bus_get_use_global_engine (bus)) {
	    g_debug ("use_global_engine is true.");
	    if (ibus_bus_is_global_engine_enabled (bus)) {
		g_debug ("Global engine is enabled.");
		IBusEngineDesc *global_engine = ibus_bus_get_global_engine (bus);
		g_assert (global_engine);
		g_debug ("%s (id:%s, icon:%s)", global_engine->longname,
			 global_engine->name, global_engine->icon);
		g_object_unref (global_engine);
	    }
	}

	g_debug ("===== Use system layout:%s", ibus_bus_get_use_sys_layout (bus) ? "true" : "false");

	g_debug ("Test ibusbus.c: passed.");

	/* Test ibusinputcontext.c */
#if 1
    {
	    IBusInputContext *context;
	    IBusEngineDesc *engine_desc;
	    gchar *current_ic;
	    context = ibus_bus_create_input_context (bus, "test");
	    ibus_input_context_set_capabilities (context, IBUS_CAP_FOCUS);
	    ibus_input_context_disable (context);
	    g_assert (ibus_input_context_is_enabled (context) == FALSE);
	    ibus_input_context_enable (context);
	    g_assert (ibus_input_context_is_enabled (context) == TRUE);
	    ibus_input_context_focus_in (context);
	    ibus_input_context_set_engine (context, active_engine_name);
	    current_ic = ibus_bus_current_input_context (bus);
	    g_assert (!strcmp (current_ic, ibus_proxy_get_path (IBUS_PROXY (context))));
	    engine_desc = ibus_input_context_get_engine (context);
	    g_assert (engine_desc);
	    g_assert (!strcmp (active_engine_name, engine_desc->name));
	    g_debug ("Test ibusinputcontext.c: passed.");

	    g_free (active_engine_name);
	    g_free (current_ic);
	    g_object_unref (engine_desc);
	    g_object_unref (context);
    }
#endif
	g_object_unref (bus);

	return 0;
}
Example #25
0
File: main.c Project: juhp/ibus
gint
main (gint argc, gchar **argv)
{
    GOptionContext *context;
    BusServer *server;
    IBusBus *bus;

    GError *error = NULL;

    setlocale (LC_ALL, "");

    context = g_option_context_new ("- ibus daemon");

    g_option_context_add_main_entries (context, entries, "ibus-daemon");

    g_argv = g_strdupv (argv);
    if (!g_option_context_parse (context, &argc, &argv, &error)) {
        g_printerr ("Option parsing failed: %s\n", error->message);
        exit (-1);
    }

    if (g_mempro) {
        g_mem_set_vtable (glib_mem_profiler_table);
        signal (SIGUSR2, _sig_usr2_handler);
    }

    /* check uid */
    {
        const gchar *username = ibus_get_user_name ();
        uid_t uid = getuid ();
        struct passwd *pwd = getpwuid (uid);

        if (pwd == NULL || g_strcmp0 (pwd->pw_name, username) != 0) {
            g_printerr ("Please run ibus-daemon with login user! Do not run ibus-daemon with sudo or su.\n");
            exit (-1);
        }
    }

    /* daemonize process */
    if (daemonize) {
        if (daemon (1, 0) != 0) {
            g_printerr ("Can not daemonize ibus.\n");
            exit (-1);
        }
    }

    /* create a new process group */
    setpgrp ();

    g_type_init ();

    g_log_set_handler (G_LOG_DOMAIN,
        G_LOG_LEVEL_WARNING | G_LOG_LEVEL_DEBUG | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
        _my_log_handler,
        NULL);

    /* check if ibus-daemon is running in this session */
    if (ibus_get_address () != NULL) {
        bus = ibus_bus_new ();

        if (ibus_bus_is_connected (bus)) {
            if (!replace) {
                g_printerr ("current session already has an ibus-daemon.\n");
                exit (-1);
            }
            ibus_bus_exit (bus, FALSE);
            while (ibus_bus_is_connected (bus)) {
                g_main_context_iteration (NULL, TRUE);
            }
        }
        g_object_unref (bus);
        bus = NULL;
    }

    /* create ibus server */
    server = bus_server_get_default ();
    bus_server_listen (server);

    if (!single) {
        /* execute config component */
        if (g_strcmp0 (config, "default") == 0) {
            IBusComponent *component;
            component = bus_registry_lookup_component_by_name (BUS_DEFAULT_REGISTRY, IBUS_SERVICE_CONFIG);
            if (component == NULL || !ibus_component_start (component, g_verbose)) {
                g_printerr ("Can not execute default config program\n");
                exit (-1);
            }
        } else if (g_strcmp0 (config, "disable") != 0 && g_strcmp0 (config, "") != 0) {
            if (!execute_cmdline (config))
                exit (-1);
        }

        /* execut panel component */
        if (g_strcmp0 (panel, "default") == 0) {
            IBusComponent *component;
            component = bus_registry_lookup_component_by_name (BUS_DEFAULT_REGISTRY, IBUS_SERVICE_PANEL);
            if (component == NULL || !ibus_component_start (component, g_verbose)) {
                g_printerr ("Can not execute default panel program\n");
                exit (-1);
            }
        } else if (g_strcmp0 (panel, "disable") != 0 && g_strcmp0 (panel, "") != 0) {
            if (!execute_cmdline (panel))
                exit (-1);
        }
    }

    /* execute ibus xim server */
    if (xim) {
        if (!execute_cmdline (LIBEXECDIR"/ibus-x11 --kill-daemon"))
            exit (-1);
    }

    bus_server_run (server);

    return 0;
}
Example #26
0
File: main.c Project: nzinfo/ibus
gint
main (gint argc, gchar **argv)
{
    setlocale (LC_ALL, "");

    GOptionContext *context = g_option_context_new ("- ibus daemon");
    g_option_context_add_main_entries (context, entries, "ibus-daemon");

    g_argv = g_strdupv (argv);
    GError *error = NULL;
    if (!g_option_context_parse (context, &argc, &argv, &error)) {
        g_printerr ("Option parsing failed: %s\n", error->message);
        g_error_free (error);
        exit (-1);
    }
    if (g_gdbus_timeout < -1) {
        g_printerr ("Bad timeout (must be >= -1): %d\n", g_gdbus_timeout);
        exit (-1);
    }

    if (g_mempro) {
        g_mem_set_vtable (glib_mem_profiler_table);
        signal (SIGUSR2, _sig_usr2_handler);
    }

    /* check uid */
    {
        const gchar *username = ibus_get_user_name ();
        uid_t uid = getuid ();
        struct passwd *pwd = getpwuid (uid);

        if (pwd == NULL || g_strcmp0 (pwd->pw_name, username) != 0) {
            g_printerr ("Please run ibus-daemon with login user! Do not run ibus-daemon with sudo or su.\n");
            exit (-1);
        }
    }

    /* daemonize process */
    if (daemonize) {
        if (daemon (1, 0) != 0) {
            g_printerr ("Can not daemonize ibus.\n");
            exit (-1);
        }
    }

    /* create a new process group. this is important to kill all of its children by SIGTERM at a time in bus_ibus_impl_destroy. */
    setpgid (0, 0);

    ibus_init ();

    ibus_set_log_handler (g_verbose);

    /* check if ibus-daemon is running in this session */
    if (ibus_get_address () != NULL) {
        IBusBus *bus = ibus_bus_new ();

        if (ibus_bus_is_connected (bus)) {
            if (!replace) {
                g_printerr ("current session already has an ibus-daemon.\n");
                exit (-1);
            }
            ibus_bus_exit (bus, FALSE);
            while (ibus_bus_is_connected (bus)) {
                g_main_context_iteration (NULL, TRUE);
            }
        }
        g_object_unref (bus);
    }

    bus_server_init ();
    if (!single) {
        /* execute config component */
        if (g_strcmp0 (config, "default") == 0) {
            BusComponent *component;
            component = bus_ibus_impl_lookup_component_by_name (
                            BUS_DEFAULT_IBUS, IBUS_SERVICE_CONFIG);
            if (component) {
                bus_component_set_restart (component, restart);
            }
            if (component == NULL || !bus_component_start (component, g_verbose)) {
                g_printerr ("Can not execute default config program\n");
                exit (-1);
            }
        } else if (g_strcmp0 (config, "disable") != 0 && g_strcmp0 (config, "") != 0) {
            if (!execute_cmdline (config))
                exit (-1);
        }

        /* execute panel component */
        if (g_strcmp0 (panel, "default") == 0) {
            BusComponent *component;
            component = bus_ibus_impl_lookup_component_by_name (
                            BUS_DEFAULT_IBUS, IBUS_SERVICE_PANEL);
            if (component) {
                bus_component_set_restart (component, restart);
            }
            if (component == NULL || !bus_component_start (component, g_verbose)) {
                g_printerr ("Can not execute default panel program\n");
                exit (-1);
            }
        } else if (g_strcmp0 (panel, "disable") != 0 && g_strcmp0 (panel, "") != 0) {
            if (!execute_cmdline (panel))
                exit (-1);
        }
    }

    /* execute ibus xim server */
    if (xim) {
        if (!execute_cmdline (LIBEXECDIR "/ibus-x11 --kill-daemon"))
            exit (-1);
    }

    bus_server_run ();
    return 0;
}
Example #27
0
gint
main (gint    argc,
      gchar **argv)
{
    g_type_init ();
    g_test_init (&argc, &argv, NULL);
#if 0
    g_test_add_func ("/ibus/list-engines", test_list_engines);
    g_test_add_func ("/ibus/list-active-engines", test_list_active_engines);
#endif
    return g_test_run ();
#if 0
    IBusBus *bus;
    GList *engines;
    gchar *active_engine_name;

    bus = ibus_bus_new ();

    if (ibus_bus_get_use_global_engine (bus)) {
        g_debug ("use_global_engine is true.");
        if (ibus_bus_is_global_engine_enabled (bus)) {
        g_debug ("Global engine is enabled.");
        IBusEngineDesc *global_engine = ibus_bus_get_global_engine (bus);
        g_assert (global_engine);
        g_debug ("%s (id:%s, icon:%s)", global_engine->longname,
             global_engine->name, global_engine->icon);
        g_object_unref (global_engine);
        }
    }

    g_debug ("===== Use system layout:%s", ibus_bus_get_use_sys_layout (bus) ? "true" : "false");

    g_debug ("Test ibusbus.c: passed.");

    /* Test ibusinputcontext.c */
#if 1
    {
        IBusInputContext *context;
        IBusEngineDesc *engine_desc;
        gchar *current_ic;
        context = ibus_bus_create_input_context (bus, "test");
        ibus_input_context_set_capabilities (context, IBUS_CAP_FOCUS);
        ibus_input_context_disable (context);
        g_assert (ibus_input_context_is_enabled (context) == FALSE);
        ibus_input_context_enable (context);
        g_assert (ibus_input_context_is_enabled (context) == TRUE);
        ibus_input_context_focus_in (context);
        ibus_input_context_set_engine (context, active_engine_name);
        current_ic = ibus_bus_current_input_context (bus);
        g_assert (!strcmp (current_ic, g_dbus_proxy_get_object_path ((GDBusProxy *)context)));
        engine_desc = ibus_input_context_get_engine (context);
        g_assert (engine_desc);
        g_assert (!strcmp (active_engine_name, engine_desc->name));
        g_debug ("Test ibusinputcontext.c: passed.");

        g_free (active_engine_name);
        g_free (current_ic);
        g_object_unref (engine_desc);
        g_object_unref (context);
    }
#endif
    g_object_unref (bus);
#endif
    return 0;
}