summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHuang Peng <shawn.p.huang@gmail.com>2008-06-19 15:48:09 +0800
committerHuang Peng <shawn.p.huang@gmail.com>2008-06-19 15:48:09 +0800
commitfdbbcd9fe7af509a17eea1fcd3d78a5a013c6971 (patch)
treedefbbd079a8b27caf8191ad60eea6d2f997e2db7
parentafb1e11faa1a0a93cc8b0d2a52dffb1ee4c8af57 (diff)
downloadibus-fdbbcd9fe7af509a17eea1fcd3d78a5a013c6971.tar.gz
ibus-fdbbcd9fe7af509a17eea1fcd3d78a5a013c6971.tar.xz
ibus-fdbbcd9fe7af509a17eea1fcd3d78a5a013c6971.zip
Rename gik to ibus.
-rw-r--r--gtk2/Makefile.am31
-rw-r--r--gtk2/gikimclient.h98
-rw-r--r--gtk2/gikimcontext.c376
-rw-r--r--gtk2/ibusim.c (renamed from gtk2/gikim.c)32
-rw-r--r--gtk2/ibusimclient.c (renamed from gtk2/gikimclient.c)238
-rw-r--r--gtk2/ibusimclient.h98
-rw-r--r--gtk2/ibusimcontext.c376
-rw-r--r--gtk2/ibusimcontext.h (renamed from gtk2/gikimcontext.h)26
8 files changed, 640 insertions, 635 deletions
diff --git a/gtk2/Makefile.am b/gtk2/Makefile.am
index e0c0f0e..e365ed7 100644
--- a/gtk2/Makefile.am
+++ b/gtk2/Makefile.am
@@ -1,6 +1,6 @@
# vim:set noet ts=4:
#
-# gik - The G Input Toolkit
+# ibus - The Input Bus
#
# Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
#
@@ -25,28 +25,32 @@
INCLUDES = \
-I$(top_srcdir)
-im_gik_sources = \
- gikim.c \
- gikimclient.c \
- gikimcontext.c \
+im_ibus_sources = \
+ ibusim.c \
+ ibusimclient.c \
+ ibusimcontext.c \
$(NULL)
-im_gik_private_headers = \
- gikimcontext.h \
- gikimclient.h \
+im_ibus_private_headers = \
+ ibusimcontext.h \
+ ibusimclient.h \
$(NULL)
immoduledir = $(libdir)/gtk-2.0/immodules
-immodule_LTLIBRARIES = im-gik.la
+immodule_LTLIBRARIES = im-ibus.la
-im_gik_la_SOURCES = $(im_gik_sources) $(im_gik_private_headers)
-im_gik_la_CFLAGS = \
+im_ibus_la_SOURCES = \
+ $(im_ibus_sources) \
+ $(im_ibus_private_headers) \
+ $(NULL)
+
+im_ibus_la_CFLAGS = \
@GTK2_CFLAGS@ \
@DBUS_CFLAGS@ \
- -DG_LOG_DOMAIN=\"GIK\" \
+ -DG_LOG_DOMAIN=\"IBUS\" \
$(NULL)
-im_gik_la_LDFLAGS = \
+im_ibus_la_LDFLAGS = \
@GTK2_LIBS@ \
@DBUS_LIBS@ \
-avoid-version \
@@ -54,3 +58,4 @@ im_gik_la_LDFLAGS = \
$(NULL)
EXTRA_DIST =
+
diff --git a/gtk2/gikimclient.h b/gtk2/gikimclient.h
deleted file mode 100644
index ba55448..0000000
--- a/gtk2/gikimclient.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/* vim:set et ts=4: */
-/* GIK - The G Input Toolkit
- * Copyright (C) 2008-2009 Huang Peng
- *
- * 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 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., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-#ifndef __GIK_IM_CLIENT_H_
-#define __GIK_IM_CLIENT_H_
-
-#include <gtk/gtk.h>
-
-/*
- * Type macros.
- */
-
-/* define GOBJECT macros */
-#define GIK_TYPE_IM_CLIENT \
- (gik_im_client_get_type ())
-#define GIK_IM_CLIENT(obj) \
- (GTK_CHECK_CAST ((obj), GIK_TYPE_IM_CLIENT, GikIMClient))
-#define GIK_IM_CLIENT_CLASS(klass) \
- (GTK_CHECK_CLASS_CAST ((klass), GIK_TYPE_IM_CLIENT, GikIMClientClass))
-#define GIK_IS_IM_CLIENT(obj) \
- (GTK_CHECK_TYPE ((obj), GIK_TYPE_IM_CLIENT))
-#define GIK_IS_IM_CLIENT_CLASS(klass) \
- (GTK_CHECK_CLASS_TYPE ((klass), GIK_TYPE_IM_CLIENT))
-#define GIK_IM_CLIENT_GET_CLASS(obj) \
- (GTK_CHECK_GET_CLASS ((obj), GIK_TYPE_IM_CLIENT, GikIMClientClass))
-
-#if 0
-#define DEBUG_FUNCTION_IN g_debug("%s IN", __FUNCTION__);
-#define DEBUG_FUNCTION_OUT g_debug("%s OUT", __FUNCTION__);
-#else
-#define DEBUG_FUNCTION_IN
-#define DEBUG_FUNCTION_OUT
-#endif
-
-
-
-#define GIK_DBUS_SERVICE "org.freedesktop.gik"
-#define GIK_DBUS_INTERFACE "org.freedesktop.gik.Manager"
-#define GIK_DBUS_PATH "/org/freedesktop/gik/Manager"
-
-G_BEGIN_DECLS
-typedef struct _GikIMClient GikIMClient;
-typedef struct _GikIMClientClass GikIMClientClass;
-typedef struct _GikIMClientPrivate GikIMClientPrivate;
-
-struct _GikIMClient {
- GtkObject parent;
- /* instance members */
- GikIMClientPrivate *priv;
-};
-
-struct _GikIMClientClass {
- GtkObjectClass parent;
- /* class members */
-};
-
-GType gik_im_client_get_type (void);
-GikIMClient *gik_im_client_get_client (void);
-void gik_im_client_register_type (GTypeModule *type_module);
-void gik_im_client_shutdown (void);
-void gik_im_client_focus_in (GikIMClient *client);
-void gik_im_client_focus_out (GikIMClient *client);
-void gik_im_client_set_im_context (GikIMClient *client,
- GtkIMContext *context);
-GtkIMContext *gik_im_client_get_im_context (GikIMClient *client);
-void gik_im_client_reset (GikIMClient *client);
-gboolean gik_im_client_filter_keypress (GikIMClient *client,
- GdkEventKey *key);
-gboolean gik_im_client_get_preedit_string
- (GikIMClient *client,
- gchar **str,
- PangoAttrList **attrs,
- gint *cursor_pos);
-void gik_im_client_set_cursor_location
- (GikIMClient *client,
- GdkRectangle *area);
-gboolean gik_im_client_is_enabled (GikIMClient *client);
-
-
-G_END_DECLS
-#endif
-
diff --git a/gtk2/gikimcontext.c b/gtk2/gikimcontext.c
deleted file mode 100644
index 1d19c01..0000000
--- a/gtk2/gikimcontext.c
+++ /dev/null
@@ -1,376 +0,0 @@
-/* vim:set et ts=4: */
-/* GIK - The G Input Toolkit
- * Copyright (C) 2008-2009 Huang Peng
- *
- * 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 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., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-#include <gdk/gdkkeysyms.h>
-#include <gdk/gdkx.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <sys/un.h>
-#include "gikimcontext.h"
-#include "gikimclient.h"
-
-/* define GOBJECT macros */
-#define GIK_TYPE_IM_CONTEXT \
- (_gik_type_im_context)
-#define GIK_IM_CONTEXT(obj) \
- (GTK_CHECK_CAST ((obj), GIK_TYPE_IM_CONTEXT, GikIMContext))
-#define GIK_IM_CONTEXT_CLASS(klass) \
- (GTK_CHECK_CLASS_CAST ((klass), GIK_TYPE_IM_CONTEXT, GikIMContextClass))
-#define GIK_IS_IM_CONTEXT(obj) \
- (GTK_CHECK_TYPE ((obj), GIK_TYPE_IM_CONTEXT))
-#define GIK_IS_IM_CONTEXT_CLASS(klass) \
- (GTK_CHECK_CLASS_TYPE ((klass), GIK_TYPE_IM_CONTEXT))
-#define GIK_IM_CONTEXT_GET_CLASS(obj) \
- (GTK_CHECK_GET_CLASS ((obj), GIK_TYPE_IM_CONTEXT, GikIMContextClass))
-
-#define CURRENT_CONTEXT (gik_im_client_get_im_context (priv->client))
-
-/* GikIMContextPriv */
-struct _GikIMContextPrivate {
- GtkIMContext *slave;
- GikIMClient *client;
- GdkWindow *client_window;
-};
-
-
-/* functions prototype */
-static void gik_im_context_class_init (GikIMContextClass *klass);
-static void gik_im_context_init (GikIMContext *obj);
-static void gik_im_context_finalize (GObject *obj);
-static void gik_im_context_reset (GtkIMContext *context);
-static gboolean gik_im_context_filter_keypress
- (GtkIMContext *context,
- GdkEventKey *key);
-static void gik_im_context_focus_in (GtkIMContext *context);
-static void gik_im_context_focus_out (GtkIMContext *context);
-static void gik_im_context_get_preedit_string
- (GtkIMContext *context,
- gchar **str,
- PangoAttrList **attrs,
- gint *cursor_pos);
-static void gik_im_context_set_client_window
- (GtkIMContext *context,
- GdkWindow *client);
-static void gik_im_context_set_cursor_location
- (GtkIMContext *context,
- GdkRectangle *area);
-
-/* callback functions for slave context */
-static void _slave_commit_cb (GtkIMContext *slave,
- gchar *string,
- GikIMContext *context);
-static void _slave_preedit_changed_cb (GtkIMContext *slave,
- GikIMContext *context);
-static void _slave_preedit_start_cb (GtkIMContext *slave,
- GikIMContext *context);
-static void _slave_preedit_end_cb (GtkIMContext *slave,
- GikIMContext *context);
-static void _slave_retrieve_surrounding_cb
- (GtkIMContext *slave,
- GikIMContext *context);
-static void _slave_delete_surrounding_cb
- (GtkIMContext *slave,
- gint arg1,
- gint arg2,
- GikIMContext *context);
-
-
-
-static GType _gik_type_im_context = 0;
-static GtkIMContextClass *parent_class = NULL;
-
-void
-gik_im_context_register_type (GTypeModule *type_module)
-{
- static const GTypeInfo gik_im_context_info = {
- sizeof (GikIMContextClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) gik_im_context_class_init,
- NULL, /* class finialize */
- NULL, /* class data */
- sizeof (GikIMContext),
- 0,
- (GInstanceInitFunc) gik_im_context_init,
- };
-
- if (! _gik_type_im_context ) {
- _gik_type_im_context =
- g_type_module_register_type (type_module,
- GTK_TYPE_IM_CONTEXT,
- "GikIMContext",
- &gik_im_context_info,
- (GTypeFlags)0);
- }
-}
-
-GtkIMContext *
-gik_im_context_new (void)
-{
- GikIMContext *obj;
-
- obj = GIK_IM_CONTEXT(g_object_new (GIK_TYPE_IM_CONTEXT, NULL));
-
- return GTK_IM_CONTEXT(obj);
-}
-
-static void
-gik_im_context_class_init (GikIMContextClass *klass)
-{
- GtkIMContextClass *im_context_class = GTK_IM_CONTEXT_CLASS (klass);
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-
- parent_class = (GtkIMContextClass *) g_type_class_peek_parent (klass);
-
- g_type_class_add_private (klass, sizeof (GikIMContextPrivate));
-
- im_context_class->reset = &gik_im_context_reset;
- im_context_class->focus_in = &gik_im_context_focus_in;
- im_context_class->focus_out = &gik_im_context_focus_out;
- im_context_class->filter_keypress = &gik_im_context_filter_keypress;
- im_context_class->get_preedit_string = &gik_im_context_get_preedit_string;
- im_context_class->set_client_window = &gik_im_context_set_client_window;
- im_context_class->set_cursor_location = &gik_im_context_set_cursor_location;
- gobject_class->finalize = &gik_im_context_finalize;
-}
-
-static void
-gik_im_context_init (GikIMContext *obj)
-{
- DEBUG_FUNCTION_IN;
-
- GError *error;
- GikIMContext *gik = GIK_IM_CONTEXT (obj);
- gik->priv = G_TYPE_INSTANCE_GET_PRIVATE (gik, GIK_TYPE_IM_CONTEXT, GikIMContextPrivate);
-
- gik->priv->client = gik_im_client_get_client ();
- gik->priv->client_window = NULL;
-
- // Create slave im context
- gik->priv->slave = gtk_im_context_simple_new ();
- g_signal_connect (gik->priv->slave,
- "commit", G_CALLBACK (_slave_commit_cb), obj);
- g_signal_connect (gik->priv->slave,
- "preedit-start", G_CALLBACK (_slave_preedit_start_cb), obj);
- g_signal_connect (gik->priv->slave,
- "preedit-end", G_CALLBACK (_slave_preedit_end_cb), obj);
- g_signal_connect (gik->priv->slave,
- "preedit-changed", G_CALLBACK (_slave_preedit_changed_cb), obj);
- g_signal_connect (gik->priv->slave,
- "retrieve-surrounding", G_CALLBACK (_slave_retrieve_surrounding_cb), obj);
- g_signal_connect (gik->priv->slave,
- "delete-surrounding", G_CALLBACK (_slave_delete_surrounding_cb), obj);
-}
-
-static void
-gik_im_context_finalize (GObject *obj)
-{
- DEBUG_FUNCTION_IN;
-
- GikIMContext *gik = GIK_IM_CONTEXT (obj);
- GikIMContextPrivate *priv = gik->priv;
-
- if (GTK_IM_CONTEXT (gik) == CURRENT_CONTEXT) {
- gik_im_client_focus_out (priv->client);
- gik_im_client_set_im_context (priv->client, NULL);
- }
-
- g_object_unref (priv->slave);
- g_object_unref (priv->client);
-
- G_OBJECT_CLASS(parent_class)->finalize (obj);
-}
-
-static gboolean
-gik_im_context_filter_keypress (GtkIMContext *context,
- GdkEventKey *event)
-{
- DEBUG_FUNCTION_IN;
-
- GikIMContext *gik = GIK_IM_CONTEXT (context);
- GikIMContextPrivate *priv = gik->priv;
-
- if (context != CURRENT_CONTEXT)
- return FALSE;
-
- if (gik_im_client_filter_keypress (priv->client, event))
- return TRUE;
- return gtk_im_context_filter_keypress (priv->slave, event);
-}
-
-static void
-gik_im_context_focus_in (GtkIMContext *context)
-{
- DEBUG_FUNCTION_IN;
-
- GikIMContext *gik = GIK_IM_CONTEXT (context);
- GikIMContextPrivate *priv = gik->priv;
-
- if (context != CURRENT_CONTEXT) {
- gik_im_client_focus_out (priv->client);
- gik_im_client_set_im_context (priv->client, context);
- }
-
- gik_im_client_focus_in (priv->client);
- gtk_im_context_focus_in (priv->slave);
-}
-
-static void
-gik_im_context_focus_out (GtkIMContext *context)
-{
- DEBUG_FUNCTION_IN;
-
- GikIMContext *gik = GIK_IM_CONTEXT (context);
- GikIMContextPrivate *priv = gik->priv;
-
- gik_im_client_focus_out (priv->client);
- gtk_im_context_focus_out (priv->slave);
-}
-
-static void
-gik_im_context_reset (GtkIMContext *context)
-{
- DEBUG_FUNCTION_IN;
-
- GikIMContext *gik = GIK_IM_CONTEXT (context);
- GikIMContextPrivate *priv = gik->priv;
-
- if (context == CURRENT_CONTEXT) {
- gik_im_client_reset (priv->client);
- }
- gtk_im_context_reset (priv->slave);
-}
-
-
-static void
-gik_im_context_get_preedit_string (GtkIMContext *context,
- gchar **str,
- PangoAttrList **attrs,
- gint *cursor_pos)
-{
- DEBUG_FUNCTION_IN;
-
- GikIMContext *gik = GIK_IM_CONTEXT (context);
- GikIMContextPrivate *priv = gik->priv;
-
- if (context == CURRENT_CONTEXT &&
- gik_im_client_is_enabled (priv->client)) {
- gik_im_client_get_preedit_string (priv->client, str, attrs, cursor_pos);
- return;
- }
- gtk_im_context_get_preedit_string (gik->priv->slave, str, attrs, cursor_pos);
-}
-
-
-static void
-gik_im_context_set_client_window (GtkIMContext *context, GdkWindow *client)
-{
- DEBUG_FUNCTION_IN;
-
- GikIMContext *gik = GIK_IM_CONTEXT (context);
- GikIMContextPrivate *priv = gik->priv;
- priv->client_window = client;
- gtk_im_context_set_client_window (gik->priv->slave, client);
-}
-
-static void
-gik_im_context_set_cursor_location (GtkIMContext *context, GdkRectangle *area)
-{
- DEBUG_FUNCTION_IN;
-
- GikIMContext *gik = GIK_IM_CONTEXT (context);
- GikIMContextPrivate *priv = gik->priv;
- if (context == CURRENT_CONTEXT && gik_im_client_is_enabled (priv->client)) {
- /* It is the focused context */
- gint x, y;
- if(priv->client_window) {
- gdk_window_get_origin (priv->client_window, &x, &y);
- area->x += x;
- area->y += y;
- }
- gik_im_client_set_cursor_location (priv->client, area);
- }
- gtk_im_context_set_cursor_location (priv->slave, area);
-}
-
-/* Callback functions for slave context */
-static void
-_slave_commit_cb (GtkIMContext *slave, gchar *string, GikIMContext *context)
-{
- DEBUG_FUNCTION_IN;
-
- GikIMContextPrivate *priv = context->priv;
-#if 0
- if ((GtkIMContext *)context == CURRENT_CONTEXT && gik_im_client_is_enabled (priv->client))
- return;
-#endif
- g_signal_emit_by_name (context, "commit", string);
-}
-
-static void
-_slave_preedit_changed_cb (GtkIMContext *slave, GikIMContext *context)
-{
- DEBUG_FUNCTION_IN;
- GikIMContextPrivate *priv = context->priv;
- if ((GtkIMContext *)context == CURRENT_CONTEXT && gik_im_client_is_enabled (priv->client))
- return;
- g_signal_emit_by_name (context, "preedit-changed");
-}
-
-static void
-_slave_preedit_start_cb (GtkIMContext *slave, GikIMContext *context)
-{
- DEBUG_FUNCTION_IN;
- GikIMContextPrivate *priv = context->priv;
- if ((GtkIMContext *)context == CURRENT_CONTEXT && gik_im_client_is_enabled (priv->client))
- return;
- g_signal_emit_by_name (context, "preedit-start");
-}
-
-static void
-_slave_preedit_end_cb (GtkIMContext *slave, GikIMContext *context)
-{
- DEBUG_FUNCTION_IN;
- GikIMContextPrivate *priv = context->priv;
- if ((GtkIMContext *)context == CURRENT_CONTEXT && gik_im_client_is_enabled (priv->client))
- return;
- g_signal_emit_by_name (context, "preedit-end");
-}
-
-static void
-_slave_retrieve_surrounding_cb (GtkIMContext *slave, GikIMContext *context)
-{
- DEBUG_FUNCTION_IN;
- GikIMContextPrivate *priv = context->priv;
- if ((GtkIMContext *)context == CURRENT_CONTEXT && gik_im_client_is_enabled (priv->client))
- return;
- g_signal_emit_by_name (context, "retrieve-surrounding");
-}
-
-static void
-_slave_delete_surrounding_cb (GtkIMContext *slave, gint a1, gint a2, GikIMContext *context)
-{
- DEBUG_FUNCTION_IN;
- GikIMContextPrivate *priv = context->priv;
- if ((GtkIMContext *)context == CURRENT_CONTEXT && gik_im_client_is_enabled (priv->client))
- return;
- g_signal_emit_by_name (context, "delete-surrounding", a1, a2);
-}
-
diff --git a/gtk2/gikim.c b/gtk2/ibusim.c
index e394a78..2445fc1 100644
--- a/gtk2/gikim.c
+++ b/gtk2/ibusim.c
@@ -1,6 +1,6 @@
/* vim:set et ts=4: */
-/* GIK - The G Input Toolkit
- * Copyright (C) 2008-2009 Huang Peng
+/* IBus - The Input Bus
+ * Copyright (C) 2008-2009 Huang Peng <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
@@ -21,28 +21,28 @@
#include <gtk/gtkimmodule.h>
#include <string.h>
#include <stdio.h>
-#include "gikimclient.h"
-#include "gikimcontext.h"
+#include "ibusimclient.h"
+#include "ibusimcontext.h"
-#define GIK_LOCALDIR ""
+#define IBUS_LOCALDIR ""
-static const GtkIMContextInfo gik_im_info = {
- "gik",
- "The G Input Toolkit",
- "gik",
- GIK_LOCALDIR,
+static const GtkIMContextInfo ibus_im_info = {
+ "ibus",
+ "The Input Bus",
+ "ibus",
+ IBUS_LOCALDIR,
""
};
static const GtkIMContextInfo * info_list[] = {
- &gik_im_info
+ &ibus_im_info
};
-void
+void
im_module_init (GTypeModule *type_module)
{
- gik_im_client_register_type(type_module);
- gik_im_context_register_type(type_module);
+ ibus_im_client_register_type(type_module);
+ ibus_im_context_register_type(type_module);
}
void
@@ -53,8 +53,8 @@ im_module_exit (void)
GtkIMContext *
im_module_create (const gchar *context_id)
{
- if (strcmp (context_id, "gik") == 0)
- return gik_im_context_new ();
+ if (strcmp (context_id, "ibus") == 0)
+ return ibus_im_context_new ();
return NULL;
}
diff --git a/gtk2/gikimclient.c b/gtk2/ibusimclient.c
index ea18d5a..ef7410e 100644
--- a/gtk2/gikimclient.c
+++ b/gtk2/ibusimclient.c
@@ -1,6 +1,6 @@
/* vim:set et ts=4: */
-/* GIK - The G Input Toolkit
- * Copyright (C) 2008-2009 Huang Peng
+/* IBus - The Input Bus
+ * Copyright (C) 2008-2009 Huang Peng <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
@@ -33,7 +33,7 @@
#define HAVE_INOTIFY
# include <sys/inotify.h>
#endif
-#include "gikimclient.h"
+#include "ibusimclient.h"
#define IBUS_NAME "org.freedesktop.IBus"
#define IBUS_IFACE "org.freedesktop.IBus"
@@ -41,8 +41,8 @@
#define IBUS_ADDR "unix:abstract=/tmp/ibus"
//#define IBUS_ADDR "tcp:host=localhost,port=7799"
-/* GikIMClientPriv */
-struct _GikIMClientPrivate {
+/* IBusIMClientPriv */
+struct _IBusIMClientPrivate {
#if USE_DBUS_SESSION_BUS
DBusConnection *dbus;
#endif
@@ -68,20 +68,20 @@ struct _GikIMClientPrivate {
};
/* functions prototype */
-static void gik_im_client_class_init (GikIMClientClass *klass);
-static void gik_im_client_init (GikIMClient *client);
-static void gik_im_client_finalize (GObject *obj);
+static void ibus_im_client_class_init (IBusIMClientClass *klass);
+static void ibus_im_client_init (IBusIMClient *client);
+static void ibus_im_client_finalize (GObject *obj);
-static void gik_im_client_commit_string(GikIMClient *client,
+static void ibus_im_client_commit_string(IBusIMClient *client,
const gchar *string);
-static void gik_im_client_update_preedit
- (GikIMClient *client,
+static void ibus_im_client_update_preedit
+ (IBusIMClient *client,
const gchar *string,
PangoAttrList *attrs,
gint cursor_pos,
gboolean show);
-static void gik_im_client_sync_hotkeys (GikIMClient *client);
+static void ibus_im_client_sync_hotkeys (IBusIMClient *client);
static gboolean _ibus_call_with_reply_and_block
(DBusConnection *connection,
const gchar *method,
@@ -106,7 +106,7 @@ static gboolean _dbus_call_with_reply_and_block
/* callback functions */
static DBusHandlerResult
- _gik_im_client_message_filter_cb
+ _ibus_im_client_message_filter_cb
(DBusConnection *connection,
DBusMessage *message,
void *user_data);
@@ -115,52 +115,52 @@ static void _dbus_name_owner_changed_cb (DBusGProxy *proxy,
const gchar *name,
const gchar *old_name,
const gchar *new_name,
- GikIMClient *client);
+ IBusIMClient *client);
-static GType gik_type_im_client = 0;
+static GType ibus_type_im_client = 0;
static GtkObjectClass *parent_class = NULL;
-static GikIMClient *_client = NULL;
+static IBusIMClient *_client = NULL;
static gboolean has_focus = FALSE;
GType
-gik_im_client_get_type (void)
+ibus_im_client_get_type (void)
{
- g_assert (gik_type_im_client != 0);
- return gik_type_im_client;
+ g_assert (ibus_type_im_client != 0);
+ return ibus_type_im_client;
}
void
-gik_im_client_register_type (GTypeModule *type_module)
+ibus_im_client_register_type (GTypeModule *type_module)
{
- static const GTypeInfo gik_im_client_info = {
- sizeof (GikIMClientClass),
+ static const GTypeInfo ibus_im_client_info = {
+ sizeof (IBusIMClientClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
- (GClassInitFunc) gik_im_client_class_init,
+ (GClassInitFunc) ibus_im_client_class_init,
NULL, /* class finialize */
NULL, /* class data */
- sizeof (GikIMClient),
+ sizeof (IBusIMClient),
0,
- (GInstanceInitFunc) gik_im_client_init,
+ (GInstanceInitFunc) ibus_im_client_init,
};
- if (! gik_type_im_client ) {
- gik_type_im_client =
+ if (! ibus_type_im_client ) {
+ ibus_type_im_client =
g_type_module_register_type (type_module,
GTK_TYPE_OBJECT,
- "GikIMClient",
- &gik_im_client_info,
+ "IBusIMClient",
+ &ibus_im_client_info,
(GTypeFlags)0);
}
}
-GikIMClient *
-gik_im_client_get_client (void)
+IBusIMClient *
+ibus_im_client_get_client (void)
{
if (_client == NULL) {
- _client = GIK_IM_CLIENT(g_object_new (GIK_TYPE_IM_CLIENT, NULL));
+ _client = IBUS_IM_CLIENT(g_object_new (IBUS_TYPE_IM_CLIENT, NULL));
g_object_ref_sink (_client);
}
else {
@@ -172,35 +172,35 @@ gik_im_client_get_client (void)
static void
-gik_im_client_class_init (GikIMClientClass *klass)
+ibus_im_client_class_init (IBusIMClientClass *klass)
{
GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
parent_class = (GtkObjectClass *) g_type_class_peek_parent (klass);
- g_type_class_add_private (klass, sizeof (GikIMClientPrivate));
+ g_type_class_add_private (klass, sizeof (IBusIMClientPrivate));
- gobject_class->finalize = &gik_im_client_finalize;
+ gobject_class->finalize = &ibus_im_client_finalize;
}
#if 0
static void
-_gik_im_client_reinit_imm (GikIMClient *client)
+_ibus_im_client_reinit_imm (IBusIMClient *client)
{
GError *error;
- GikIMClientPrivate *priv = client->priv;
+ IBusIMClientPrivate *priv = client->priv;
if (priv->imm != NULL) {
g_object_unref (priv->imm);
}
- /* get gik proxy */
+ /* get ibus proxy */
error = NULL;
priv->imm = dbus_g_proxy_new_for_name_owner (priv->ibus,
- GIK_DBUS_SERVICE,
- GIK_DBUS_PATH,
- GIK_DBUS_INTERFACE,
+ IBUS_DBUS_SERVICE,
+ IBUS_DBUS_PATH,
+ IBUS_DBUS_INTERFACE,
&error);
if (priv->imm == NULL) {
@@ -219,18 +219,18 @@ _gik_im_client_reinit_imm (GikIMClient *client)
return;
}
- gik_im_client_sync_hotkeys (client);
+ ibus_im_client_sync_hotkeys (client);
g_debug ("new imm %s", dbus_g_proxy_get_bus_name (priv->imm));
}
#endif
static void
-_gik_im_client_ibus_open (GikIMClient *client)
+_ibus_im_client_ibus_open (IBusIMClient *client)
{
gchar *ibus_addr = NULL;
DBusError error;
- GikIMClientPrivate *priv = client->priv;
+ IBusIMClientPrivate *priv = client->priv;
if (priv->ibus != NULL)
return;
@@ -281,7 +281,7 @@ _gik_im_client_ibus_open (GikIMClient *client)
}
if (!dbus_connection_add_filter (priv->ibus,
- _gik_im_client_message_filter_cb,
+ _ibus_im_client_message_filter_cb,
client, NULL)) {
g_warning ("Out of memory");
return;
@@ -299,11 +299,11 @@ _gik_im_client_ibus_open (GikIMClient *client)
}
static void
-_gik_im_client_ibus_close (GikIMClient *client)
+_ibus_im_client_ibus_close (IBusIMClient *client)
{
DBusError error;
- GikIMClientPrivate *priv = client->priv;
+ IBusIMClientPrivate *priv = client->priv;
if (priv->ibus) {
dbus_connection_close (priv->ibus);
@@ -330,7 +330,7 @@ _gik_im_client_ibus_close (GikIMClient *client)
#ifdef HAVE_INOTIFY
static gboolean
-_gik_im_client_inotify_cb (GIOChannel *source, GIOCondition condition, GikIMClient *client)
+_ibus_im_client_inotify_cb (GIOChannel *source, GIOCondition condition, IBusIMClient *client)
{
struct inotify_event *p = NULL;
gchar *name;
@@ -355,7 +355,7 @@ _gik_im_client_inotify_cb (GIOChannel *source, GIOCondition condition, GikIMClie
if (g_strcmp0 (p->name, name) == 0) {
if (p->mask & IN_CREATE) {
g_usleep (1000);
- _gik_im_client_ibus_open (client);
+ _ibus_im_client_ibus_open (client);
}
}
g_free (name);
@@ -365,13 +365,13 @@ _gik_im_client_inotify_cb (GIOChannel *source, GIOCondition condition, GikIMClie
#endif
static void
-gik_im_client_init (GikIMClient *obj)
+ibus_im_client_init (IBusIMClient *obj)
{
DEBUG_FUNCTION_IN;
DBusError error;
- GikIMClient *client = GIK_IM_CLIENT (obj);
- GikIMClientPrivate *priv;
+ IBusIMClient *client = IBUS_IM_CLIENT (obj);
+ IBusIMClientPrivate *priv;
gchar *watch_path;
struct stat stat_buf;
@@ -380,7 +380,7 @@ gik_im_client_init (GikIMClient *obj)
gint inotify_fd = inotify_init ();
#endif
- priv = G_TYPE_INSTANCE_GET_PRIVATE (client, GIK_TYPE_IM_CLIENT, GikIMClientPrivate);
+ priv = G_TYPE_INSTANCE_GET_PRIVATE (client, IBUS_TYPE_IM_CLIENT, IBusIMClientPrivate);
client->priv = priv;
priv->context = NULL;
@@ -403,7 +403,7 @@ gik_im_client_init (GikIMClient *obj)
g_io_channel_set_close_on_unref (priv->inotify_channel, TRUE);
priv->inotify_source = g_io_add_watch (priv->inotify_channel,
G_IO_IN,
- (GIOFunc)_gik_im_client_inotify_cb,
+ (GIOFunc)_ibus_im_client_inotify_cb,
(gpointer)client);
#endif
g_free (watch_path);
@@ -421,11 +421,11 @@ gik_im_client_init (GikIMClient *obj)
}
#endif
- _gik_im_client_ibus_open (client);
+ _ibus_im_client_ibus_open (client);
#if USE_DBUS_SESSION_BUS
if (!dbus_connection_add_filter (priv->dbus,
- _gik_im_client_message_filter_cb,
+ _ibus_im_client_message_filter_cb,
client, NULL)) {
g_warning ("Out of memory");
return;
@@ -474,22 +474,22 @@ gik_im_client_init (GikIMClient *obj)
"',interface='" DBUS_INTERFACE_DBUS
"',path='" DBUS_PATH_DBUS
"',member='NameOwnerChanged',"
- "arg0='" GIK_DBUS_SERVICE "'",
+ "arg0='" IBUS_DBUS_SERVICE "'",
&dbus_error);
- _gik_im_client_reinit_imm (client);
+ _ibus_im_client_reinit_imm (client);
#endif
}
static void
-gik_im_client_finalize (GObject *obj)
+ibus_im_client_finalize (GObject *obj)
{
DEBUG_FUNCTION_IN;
- GikIMClient *client = GIK_IM_CLIENT (obj);
- GikIMClientPrivate *priv = client->priv;
+ IBusIMClient *client = IBUS_IM_CLIENT (obj);
+ IBusIMClientPrivate *priv = client->priv;
g_assert (client == _client);
@@ -503,7 +503,7 @@ gik_im_client_finalize (GObject *obj)
dbus_connection_unref (priv->dbus);
}
#endif
- _gik_im_client_ibus_close (client);
+ _ibus_im_client_ibus_close (client);
G_OBJECT_CLASS(parent_class)->finalize (obj);
@@ -512,23 +512,23 @@ gik_im_client_finalize (GObject *obj)
void
-gik_im_client_set_im_context (GikIMClient *client, GtkIMContext *context)
+ibus_im_client_set_im_context (IBusIMClient *client, GtkIMContext *context)
{
- GikIMClientPrivate *priv = client->priv;
+ IBusIMClientPrivate *priv = client->priv;
priv->context = context;
}
GtkIMContext *
-gik_im_client_get_im_context (GikIMClient *client)
+ibus_im_client_get_im_context (IBusIMClient *client)
{
- GikIMClientPrivate *priv = client->priv;
+ IBusIMClientPrivate *priv = client->priv;
return priv->context;
}
static void
-gik_im_client_commit_string (GikIMClient *client, const gchar *string)
+ibus_im_client_commit_string (IBusIMClient *client, const gchar *string)
{
- GikIMClientPrivate *priv = client->priv;
+ IBusIMClientPrivate *priv = client->priv;
if (priv->context) {
g_signal_emit_by_name (priv->context, "commit", string);
@@ -536,10 +536,10 @@ gik_im_client_commit_string (GikIMClient *client, const gchar *string)
}
static void
-gik_im_client_update_preedit (GikIMClient *client, const gchar *string,
+ibus_im_client_update_preedit (IBusIMClient *client, const gchar *string,
PangoAttrList *attrs, gint cursor_pos, gboolean show)
{
- GikIMClientPrivate *priv = client->priv;
+ IBusIMClientPrivate *priv = client->priv;
if (priv->preedit_string) {
g_free (priv->preedit_string);
}
@@ -562,10 +562,10 @@ gik_im_client_update_preedit (GikIMClient *client, const gchar *string,
}
static void
-_gik_signal_commit_string_handler (DBusConnection *connection, DBusMessage *message, GikIMClient *client)
+_ibus_signal_commit_string_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
{
/* Handle CommitString signal */
- GikIMClientPrivate *priv = client->priv;
+ IBusIMClientPrivate *priv = client->priv;
DBusError error = {0};
gchar *ic = NULL;
gchar *string = NULL;
@@ -582,15 +582,15 @@ _gik_signal_commit_string_handler (DBusConnection *connection, DBusMessage *mess
g_warning ("ic is wrong!");
return;
}
- gik_im_client_commit_string (client, string);
+ ibus_im_client_commit_string (client, string);
}
}
static void
-_gik_signal_update_preedit_handler (DBusConnection *connection, DBusMessage *message, GikIMClient *client)
+_ibus_signal_update_preedit_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
{
/* Handle UpdatePreedit signal */
- GikIMClientPrivate *priv = client->priv;
+ IBusIMClientPrivate *priv = client->priv;
DBusError error = {0};
DBusMessageIter iter, sub_iter;
gint type, sub_type;
@@ -715,16 +715,16 @@ _gik_signal_update_preedit_handler (DBusConnection *connection, DBusMessage *mes
dbus_message_iter_get_basic (&iter, &show);
dbus_message_iter_next (&iter);
- gik_im_client_update_preedit (client, string, attrs, cursor, show);
+ ibus_im_client_update_preedit (client, string, attrs, cursor, show);
pango_attr_list_unref (attrs);
}
#ifdef USE_DBUS_SESSION_BUS
static void
-_gik_signal_name_owner_changed_handler (DBusConnection *connection, DBusMessage *message, GikIMClient *client)
+_ibus_signal_name_owner_changed_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
{
- GikIMClientPrivate *priv = client->priv;
+ IBusIMClientPrivate *priv = client->priv;
gchar *name = NULL;
gchar *old_name = NULL;
@@ -743,24 +743,24 @@ _gik_signal_name_owner_changed_handler (DBusConnection *connection, DBusMessage
g_return_if_fail (strcmp (name, IBUS_NAME) == 0);
if (g_strcmp0 (new_name, "") == 0) {
- _gik_im_client_ibus_close (client);
+ _ibus_im_client_ibus_close (client);
priv->enable = FALSE;
}
else {
- _gik_im_client_ibus_open (client);
+ _ibus_im_client_ibus_open (client);
priv->enable = TRUE;
}
}
#endif
static void
-_gik_signal_disconnected_handler (DBusConnection *connection, DBusMessage *message, GikIMClient *client)
+_ibus_signal_disconnected_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
{
- _gik_im_client_ibus_close (client);
+ _ibus_im_client_ibus_close (client);
}
static void
-_gik_signal_enabled_handler (DBusConnection *connection, DBusMessage *message, GikIMClient *client)
+_ibus_signal_enabled_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
{
DEBUG_FUNCTION_IN;
client->priv->enable = TRUE;
@@ -768,29 +768,29 @@ _gik_signal_enabled_handler (DBusConnection *connection, DBusMessage *message, G
static void
-_gik_signal_disabled_handler (DBusConnection *connection, DBusMessage *message, GikIMClient *client)
+_ibus_signal_disabled_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
{
DEBUG_FUNCTION_IN;
client->priv->enable = FALSE;
}
static DBusHandlerResult
-_gik_im_client_message_filter_cb (DBusConnection *connection, DBusMessage *message, void *user_data)
+_ibus_im_client_message_filter_cb (DBusConnection *connection, DBusMessage *message, void *user_data)
{
- GikIMClient *client = (GikIMClient *) user_data;
+ IBusIMClient *client = (IBusIMClient *) user_data;
static struct SIGNAL_HANDLER {
const gchar *iface;
const gchar *name;
- void (* handler) (DBusConnection *, DBusMessage *, GikIMClient *);
+ void (* handler) (DBusConnection *, DBusMessage *, IBusIMClient *);
} handlers[] = {
#ifdef USE_DBUS_SESSION_BUS
- { DBUS_INTERFACE_DBUS, "NameOwnerChanged", _gik_signal_name_owner_changed_handler },
+ { DBUS_INTERFACE_DBUS, "NameOwnerChanged", _ibus_signal_name_owner_changed_handler },
#endif
- { DBUS_INTERFACE_LOCAL, "Disconnected", _gik_signal_disconnected_handler },
- { IBUS_IFACE, "CommitString", _gik_signal_commit_string_handler },
- { IBUS_IFACE, "UpdatePreedit", _gik_signal_update_preedit_handler },
- { IBUS_IFACE, "Enabled", _gik_signal_enabled_handler },
- { IBUS_IFACE, "Disabled", _gik_signal_disabled_handler },
+ { DBUS_INTERFACE_LOCAL, "Disconnected", _ibus_signal_disconnected_handler },
+ { IBUS_IFACE, "CommitString", _ibus_signal_commit_string_handler },
+ { IBUS_IFACE, "UpdatePreedit", _ibus_signal_update_preedit_handler },
+ { IBUS_IFACE, "Enabled", _ibus_signal_enabled_handler },
+ { IBUS_IFACE, "Disabled", _ibus_signal_disabled_handler },
{0},
};
@@ -1011,7 +1011,7 @@ _ibus_call_with_reply (DBusConnection *connection, const gchar *method,
static void
-_gik_filter_keypress_reply_cb (DBusPendingCall *pending, void *user_data)
+_ibus_filter_keypress_reply_cb (DBusPendingCall *pending, void *user_data)
{
DBusMessage *reply;
DBusError error = {0};
@@ -1043,9 +1043,9 @@ _gik_filter_keypress_reply_cb (DBusPendingCall *pending, void *user_data)
}
gboolean
-gik_im_client_filter_keypress (GikIMClient *client, GdkEventKey *event)
+ibus_im_client_filter_keypress (IBusIMClient *client, GdkEventKey *event)
{
- GikIMClientPrivate *priv = client->priv;
+ IBusIMClientPrivate *priv = client->priv;
guint state = event->state & GDK_MODIFIER_MASK;
gboolean is_press = event->type == GDK_KEY_PRESS;
@@ -1057,7 +1057,7 @@ gik_im_client_filter_keypress (GikIMClient *client, GdkEventKey *event)
/* Call IBus ProcessKeyEvent method */
if (!_ibus_call_with_reply (priv->ibus,
"ProcessKeyEvent",
- _gik_filter_keypress_reply_cb,
+ _ibus_filter_keypress_reply_cb,
gdk_event_copy ((GdkEvent *)event),
(DBusFreeFunction)gdk_event_free,
DBUS_TYPE_STRING, &priv->ic,
@@ -1072,9 +1072,9 @@ gik_im_client_filter_keypress (GikIMClient *client, GdkEventKey *event)
void
-gik_im_client_focus_in (GikIMClient *client)
+ibus_im_client_focus_in (IBusIMClient *client)
{
- GikIMClientPrivate *priv = client->priv;
+ IBusIMClientPrivate *priv = client->priv;
/* Call IBus FocusIn method */
_ibus_call_with_reply_and_block (client->priv->ibus,
"FocusIn",
@@ -1084,9 +1084,9 @@ gik_im_client_focus_in (GikIMClient *client)
}
void
-gik_im_client_focus_out (GikIMClient *client)
+ibus_im_client_focus_out (IBusIMClient *client)
{
- GikIMClientPrivate *priv = client->priv;
+ IBusIMClientPrivate *priv = client->priv;
/* Call IBus FocusOut method */
_ibus_call_with_reply_and_block (client->priv->ibus,
"FocusOut",
@@ -1097,9 +1097,9 @@ gik_im_client_focus_out (GikIMClient *client)
}
void
-gik_im_client_reset (GikIMClient *client)
+ibus_im_client_reset (IBusIMClient *client)
{
- GikIMClientPrivate *priv = client->priv;
+ IBusIMClientPrivate *priv = client->priv;
/* Call IBus Reset method */
_ibus_call_with_reply_and_block (client->priv->ibus,
"Reset",
@@ -1111,14 +1111,14 @@ gik_im_client_reset (GikIMClient *client)
gboolean
-gik_im_client_get_preedit_string (
- GikIMClient *client,
+ibus_im_client_get_preedit_string (
+ IBusIMClient *client,
gchar **str,
PangoAttrList **attrs,
gint *cursor_pos
)
{
- GikIMClientPrivate *priv = client->priv;
+ IBusIMClientPrivate *priv = client->priv;
if (!priv->preedit_show) {
if (str) *str = g_strdup ("");
@@ -1149,15 +1149,15 @@ gik_im_client_get_preedit_string (
void
-gik_im_client_set_client_window (GikIMClient *client, GdkWindow *window)
+ibus_im_client_set_client_window (IBusIMClient *client, GdkWindow *window)
{
- GikIMClientPrivate *priv = client->priv;
+ IBusIMClientPrivate *priv = client->priv;
}
void
-gik_im_client_set_cursor_location (GikIMClient *client, GdkRectangle *area)
+ibus_im_client_set_cursor_location (IBusIMClient *client, GdkRectangle *area)
{
- GikIMClientPrivate *priv = client->priv;
+ IBusIMClientPrivate *priv = client->priv;
_ibus_call_with_reply_and_block (client->priv->ibus,
"SetCursorLocation",
@@ -1172,19 +1172,19 @@ gik_im_client_set_cursor_location (GikIMClient *client, GdkRectangle *area)
gboolean
-gik_im_client_is_enabled (GikIMClient *client)
+ibus_im_client_is_enabled (IBusIMClient *client)
{
return (client->priv->ibus != NULL) && (client->priv->enable);
}
static void
-gik_im_client_sync_hotkeys (GikIMClient *client)
+ibus_im_client_sync_hotkeys (IBusIMClient *client)
{
GError *error;
gchar **hotkeys = NULL;
gint i;
- GikIMClientPrivate *priv = client->priv;
+ IBusIMClientPrivate *priv = client->priv;
#if 0
g_return_if_fail (priv->imm != NULL);
@@ -1216,13 +1216,13 @@ _dbus_name_owner_changed_cb (
const gchar *name,
const gchar *prev_owner,
const gchar *new_owner,
- GikIMClient *client)
+ IBusIMClient *client)
{
- GikIMClientPrivate *priv = client->priv;
+ IBusIMClientPrivate *priv = client->priv;
- if (strcmp (name, GIK_DBUS_SERVICE) == 0) {
+ if (strcmp (name, IBUS_DBUS_SERVICE) == 0) {
if (strcmp (new_owner, "") == 0) {
- /* Gik service exited */
+ /* IBus service exited */
if (priv->imm) {
g_object_unref (priv->imm);
priv->imm = NULL;
@@ -1233,8 +1233,8 @@ _dbus_name_owner_changed_cb (
}
}
else {
- /* Gik service avaliable or owner changed */
- _gik_im_client_reinit_imm (client);
+ /* IBus service avaliable or owner changed */
+ _ibus_im_client_reinit_imm (client);
}
}
}
diff --git a/gtk2/ibusimclient.h b/gtk2/ibusimclient.h
new file mode 100644
index 0000000..48489d2
--- /dev/null
+++ b/gtk2/ibusimclient.h
@@ -0,0 +1,98 @@
+/* vim:set et ts=4: */
+/* IBus - The Input Bus
+ * Copyright (C) 2008-2009 Huang Peng <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 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#ifndef __IBUS_IM_CLIENT_H_
+#define __IBUS_IM_CLIENT_H_
+
+#include <gtk/gtk.h>
+
+/*
+ * Type macros.
+ */
+
+/* define GOBJECT macros */
+#define IBUS_TYPE_IM_CLIENT \
+ (ibus_im_client_get_type ())
+#define IBUS_IM_CLIENT(obj) \
+ (GTK_CHECK_CAST ((obj), IBUS_TYPE_IM_CLIENT, IBusIMClient))
+#define IBUS_IM_CLIENT_CLASS(klass) \
+ (GTK_CHECK_CLASS_CAST ((klass), IBUS_TYPE_IM_CLIENT, IBusIMClientClass))
+#define IBUS_IS_IM_CLIENT(obj) \
+ (GTK_CHECK_TYPE ((obj), IBUS_TYPE_IM_CLIENT))
+#define IBUS_IS_IM_CLIENT_CLASS(klass) \
+ (GTK_CHECK_CLASS_TYPE ((klass), IBUS_TYPE_IM_CLIENT))
+#define IBUS_IM_CLIENT_GET_CLASS(obj) \
+ (GTK_CHECK_GET_CLASS ((obj), IBUS_TYPE_IM_CLIENT, IBusIMClientClass))
+
+#if 0
+#define DEBUG_FUNCTION_IN g_debug("%s IN", __FUNCTION__);
+#define DEBUG_FUNCTION_OUT g_debug("%s OUT", __FUNCTION__);
+#else
+#define DEBUG_FUNCTION_IN
+#define DEBUG_FUNCTION_OUT
+#endif
+
+
+
+#define IBUS_DBUS_SERVICE "org.freedesktop.ibus"
+#define IBUS_DBUS_INTERFACE "org.freedesktop.ibus.Manager"
+#define IBUS_DBUS_PATH "/org/freedesktop/ibus/Manager"
+
+G_BEGIN_DECLS
+typedef struct _IBusIMClient IBusIMClient;
+typedef struct _IBusIMClientClass IBusIMClientClass;
+typedef struct _IBusIMClientPrivate IBusIMClientPrivate;
+
+struct _IBusIMClient {
+ GtkObject parent;
+ /* instance members */
+ IBusIMClientPrivate *priv;
+};
+
+struct _IBusIMClientClass {
+ GtkObjectClass parent;
+ /* class members */
+};
+
+GType ibus_im_client_get_type (void);
+IBusIMClient *ibus_im_client_get_client (void);
+void ibus_im_client_register_type (GTypeModule *type_module);
+void ibus_im_client_shutdown (void);
+void ibus_im_client_focus_in (IBusIMClient *client);
+void ibus_im_client_focus_out (IBusIMClient *client);
+void ibus_im_client_set_im_context (IBusIMClient *client,
+ GtkIMContext *context);
+GtkIMContext *ibus_im_client_get_im_context (IBusIMClient *client);
+void ibus_im_client_reset (IBusIMClient *client);
+gboolean ibus_im_client_filter_keypress (IBusIMClient *client,
+ GdkEventKey *key);
+gboolean ibus_im_client_get_preedit_string
+ (IBusIMClient *client,
+ gchar **str,
+ PangoAttrList **attrs,
+ gint *cursor_pos);
+void ibus_im_client_set_cursor_location
+ (IBusIMClient *client,
+ GdkRectangle *area);
+gboolean ibus_im_client_is_enabled (IBusIMClient *client);
+
+
+G_END_DECLS
+#endif
+
diff --git a/gtk2/ibusimcontext.c b/gtk2/ibusimcontext.c
new file mode 100644
index 0000000..5b9c089
--- /dev/null
+++ b/gtk2/ibusimcontext.c
@@ -0,0 +1,376 @@
+/* vim:set et ts=4: */
+/* IBus - The Input Bus
+ * Copyright (C) 2008-2009 Huang Peng <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 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include <gdk/gdkkeysyms.h>
+#include <gdk/gdkx.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <sys/un.h>
+#include "ibusimcontext.h"
+#include "ibusimclient.h"
+
+/* define GOBJECT macros */
+#define IBUS_TYPE_IM_CONTEXT \
+ (_ibus_type_im_context)
+#define IBUS_IM_CONTEXT(obj) \
+ (GTK_CHECK_CAST ((obj), IBUS_TYPE_IM_CONTEXT, IBusIMContext))
+#define IBUS_IM_CONTEXT_CLASS(klass) \
+ (GTK_CHECK_CLASS_CAST ((klass), IBUS_TYPE_IM_CONTEXT, IBusIMContextClass))
+#define IBUS_IS_IM_CONTEXT(obj) \
+ (GTK_CHECK_TYPE ((obj), IBUS_TYPE_IM_CONTEXT))
+#define IBUS_IS_IM_CONTEXT_CLASS(klass) \
+ (GTK_CHECK_CLASS_TYPE ((klass), IBUS_TYPE_IM_CONTEXT))
+#define IBUS_IM_CONTEXT_GET_CLASS(obj) \
+ (GTK_CHECK_GET_CLASS ((obj), IBUS_TYPE_IM_CONTEXT, IBusIMContextClass))
+
+#define CURRENT_CONTEXT (ibus_im_client_get_im_context (priv->client))
+
+/* IBusIMContextPriv */
+struct _IBusIMContextPrivate {
+ GtkIMContext *slave;
+ IBusIMClient *client;
+ GdkWindow *client_window;
+};
+
+
+/* functions prototype */
+static void ibus_im_context_class_init (IBusIMContextClass *klass);
+static void ibus_im_context_init (IBusIMContext *obj);
+static void ibus_im_context_finalize (GObject *obj);
+static void ibus_im_context_reset (GtkIMContext *context);
+static gboolean ibus_im_context_filter_keypress
+ (GtkIMContext *context,
+ GdkEventKey *key);
+static void ibus_im_context_focus_in (GtkIMContext *context);
+static void ibus_im_context_focus_out (GtkIMContext *context);
+static void ibus_im_context_get_preedit_string
+ (GtkIMContext *context,
+ gchar **str,
+ PangoAttrList **attrs,
+ gint *cursor_pos);
+static void ibus_im_context_set_client_window
+ (GtkIMContext *context,
+ GdkWindow *client);
+static void ibus_im_context_set_cursor_location
+ (GtkIMContext *context,
+ GdkRectangle *area);
+
+/* callback functions for slave context */
+static void _slave_commit_cb (GtkIMContext *slave,
+ gchar *string,
+ IBusIMContext *context);
+static void _slave_preedit_changed_cb (GtkIMContext *slave,
+ IBusIMContext *context);
+static void _slave_preedit_start_cb (GtkIMContext *slave,
+ IBusIMContext *context);
+static void _slave_preedit_end_cb (GtkIMContext *slave,
+ IBusIMContext *context);
+static void _slave_retrieve_surrounding_cb
+ (GtkIMContext *slave,
+ IBusIMContext *context);
+static void _slave_delete_surrounding_cb
+ (GtkIMContext *slave,
+ gint arg1,
+ gint arg2,
+ IBusIMContext *context);
+
+
+
+static GType _ibus_type_im_context = 0;
+static GtkIMContextClass *parent_class = NULL;
+
+void
+ibus_im_context_register_type (GTypeModule *type_module)
+{
+ static const GTypeInfo ibus_im_context_info = {
+ sizeof (IBusIMContextClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) ibus_im_context_class_init,
+ NULL, /* class finialize */
+ NULL, /* class data */
+ sizeof (IBusIMContext),
+ 0,
+ (GInstanceInitFunc) ibus_im_context_init,
+ };
+
+ if (! _ibus_type_im_context ) {
+ _ibus_type_im_context =
+ g_type_module_register_type (type_module,
+ GTK_TYPE_IM_CONTEXT,
+ "IBusIMContext",
+ &ibus_im_context_info,
+ (GTypeFlags)0);
+ }
+}
+
+GtkIMContext *
+ibus_im_context_new (void)
+{
+ IBusIMContext *obj;
+
+ obj = IBUS_IM_CONTEXT(g_object_new (IBUS_TYPE_IM_CONTEXT, NULL));
+
+ return GTK_IM_CONTEXT(obj);
+}
+
+static void
+ibus_im_context_class_init (IBusIMContextClass *klass)
+{
+ GtkIMContextClass *im_context_class = GTK_IM_CONTEXT_CLASS (klass);
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ parent_class = (GtkIMContextClass *) g_type_class_peek_parent (klass);
+
+ g_type_class_add_private (klass, sizeof (IBusIMContextPrivate));
+
+ im_context_class->reset = &ibus_im_context_reset;
+ im_context_class->focus_in = &ibus_im_context_focus_in;
+ im_context_class->focus_out = &ibus_im_context_focus_out;
+ im_context_class->filter_keypress = &ibus_im_context_filter_keypress;
+ im_context_class->get_preedit_string = &ibus_im_context_get_preedit_string;
+ im_context_class->set_client_window = &ibus_im_context_set_client_window;
+ im_context_class->set_cursor_location = &ibus_im_context_set_cursor_location;
+ gobject_class->finalize = &ibus_im_context_finalize;
+}
+
+static void
+ibus_im_context_init (IBusIMContext *obj)
+{
+ DEBUG_FUNCTION_IN;
+
+ GError *error;
+ IBusIMContext *ibus = IBUS_IM_CONTEXT (obj);
+ ibus->priv = G_TYPE_INSTANCE_GET_PRIVATE (ibus, IBUS_TYPE_IM_CONTEXT, IBusIMContextPrivate);
+
+ ibus->priv->client = ibus_im_client_get_client ();
+ ibus->priv->client_window = NULL;
+
+ // Create slave im context
+ ibus->priv->slave = gtk_im_context_simple_new ();
+ g_signal_connect (ibus->priv->slave,
+ "commit", G_CALLBACK (_slave_commit_cb), obj);
+ g_signal_connect (ibus->priv->slave,
+ "preedit-start", G_CALLBACK (_slave_preedit_start_cb), obj);
+ g_signal_connect (ibus->priv->slave,
+ "preedit-end", G_CALLBACK (_slave_preedit_end_cb), obj);
+ g_signal_connect (ibus->priv->slave,
+ "preedit-changed", G_CALLBACK (_slave_preedit_changed_cb), obj);
+ g_signal_connect (ibus->priv->slave,
+ "retrieve-surrounding", G_CALLBACK (_slave_retrieve_surrounding_cb), obj);
+ g_signal_connect (ibus->priv->slave,
+ "delete-surrounding", G_CALLBACK (_slave_delete_surrounding_cb), obj);
+}
+
+static void
+ibus_im_context_finalize (GObject *obj)
+{
+ DEBUG_FUNCTION_IN;
+
+ IBusIMContext *ibus = IBUS_IM_CONTEXT (obj);
+ IBusIMContextPrivate *priv = ibus->priv;
+
+ if (GTK_IM_CONTEXT (ibus) == CURRENT_CONTEXT) {
+ ibus_im_client_focus_out (priv->client);
+ ibus_im_client_set_im_context (priv->client, NULL);
+ }
+
+ g_object_unref (priv->slave);
+ g_object_unref (priv->client);
+
+ G_OBJECT_CLASS(parent_class)->finalize (obj);
+}
+
+static gboolean
+ibus_im_context_filter_keypress (GtkIMContext *context,
+ GdkEventKey *event)
+{
+ DEBUG_FUNCTION_IN;
+
+ IBusIMContext *ibus = IBUS_IM_CONTEXT (context);
+ IBusIMContextPrivate *priv = ibus->priv;
+
+ if (context != CURRENT_CONTEXT)
+ return FALSE;
+
+ if (ibus_im_client_filter_keypress (priv->client, event))
+ return TRUE;
+ return gtk_im_context_filter_keypress (priv->slave, event);
+}
+
+static void
+ibus_im_context_focus_in (GtkIMContext *context)
+{
+ DEBUG_FUNCTION_IN;
+
+ IBusIMContext *ibus = IBUS_IM_CONTEXT (context);
+ IBusIMContextPrivate *priv = ibus->priv;
+
+ if (context != CURRENT_CONTEXT) {
+ ibus_im_client_focus_out (priv->client);
+ ibus_im_client_set_im_context (priv->client, context);
+ }
+
+ ibus_im_client_focus_in (priv->client);
+ gtk_im_context_focus_in (priv->slave);
+}
+
+static void
+ibus_im_context_focus_out (GtkIMContext *context)
+{
+ DEBUG_FUNCTION_IN;
+
+ IBusIMContext *ibus = IBUS_IM_CONTEXT (context);
+ IBusIMContextPrivate *priv = ibus->priv;
+
+ ibus_im_client_focus_out (priv->client);
+ gtk_im_context_focus_out (priv->slave);
+}
+
+static void
+ibus_im_context_reset (GtkIMContext *context)
+{
+ DEBUG_FUNCTION_IN;
+
+ IBusIMContext *ibus = IBUS_IM_CONTEXT (context);
+ IBusIMContextPrivate *priv = ibus->priv;
+
+ if (context == CURRENT_CONTEXT) {
+ ibus_im_client_reset (priv->client);
+ }
+ gtk_im_context_reset (priv->slave);
+}
+
+
+static void
+ibus_im_context_get_preedit_string (GtkIMContext *context,
+ gchar **str,
+ PangoAttrList **attrs,
+ gint *cursor_pos)
+{
+ DEBUG_FUNCTION_IN;
+
+ IBusIMContext *ibus = IBUS_IM_CONTEXT (context);
+ IBusIMContextPrivate *priv = ibus->priv;
+
+ if (context == CURRENT_CONTEXT &&
+ ibus_im_client_is_enabled (priv->client)) {
+ ibus_im_client_get_preedit_string (priv->client, str, attrs, cursor_pos);
+ return;
+ }
+ gtk_im_context_get_preedit_string (ibus->priv->slave, str, attrs, cursor_pos);
+}
+
+
+static void
+ibus_im_context_set_client_window (GtkIMContext *context, GdkWindow *client)
+{
+ DEBUG_FUNCTION_IN;
+
+ IBusIMContext *ibus = IBUS_IM_CONTEXT (context);
+ IBusIMContextPrivate *priv = ibus->priv;
+ priv->client_window = client;
+ gtk_im_context_set_client_window (ibus->priv->slave, client);
+}
+
+static void
+ibus_im_context_set_cursor_location (GtkIMContext *context, GdkRectangle *area)
+{
+ DEBUG_FUNCTION_IN;
+
+ IBusIMContext *ibus = IBUS_IM_CONTEXT (context);
+ IBusIMContextPrivate *priv = ibus->priv;
+ if (context == CURRENT_CONTEXT && ibus_im_client_is_enabled (priv->client)) {
+ /* It is the focused context */
+ gint x, y;
+ if(priv->client_window) {
+ gdk_window_get_origin (priv->client_window, &x, &y);
+ area->x += x;
+ area->y += y;
+ }
+ ibus_im_client_set_cursor_location (priv->client, area);
+ }
+ gtk_im_context_set_cursor_location (priv->slave, area);
+}
+
+/* Callback functions for slave context */
+static void
+_slave_commit_cb (GtkIMContext *slave, gchar *string, IBusIMContext *context)
+{
+ DEBUG_FUNCTION_IN;
+
+ IBusIMContextPrivate *priv = context->priv;
+#if 0
+ if ((GtkIMContext *)context == CURRENT_CONTEXT && ibus_im_client_is_enabled (priv->client))
+ return;
+#endif
+ g_signal_emit_by_name (context, "commit", string);
+}
+
+static void
+_slave_preedit_changed_cb (GtkIMContext *slave, IBusIMContext *context)
+{
+ DEBUG_FUNCTION_IN;
+ IBusIMContextPrivate *priv = context->priv;
+ if ((GtkIMContext *)context == CURRENT_CONTEXT && ibus_im_client_is_enabled (priv->client))
+ return;
+ g_signal_emit_by_name (context, "preedit-changed");
+}
+
+static void
+_slave_preedit_start_cb (GtkIMContext *slave, IBusIMContext *context)
+{
+ DEBUG_FUNCTION_IN;
+ IBusIMContextPrivate *priv = context->priv;
+ if ((GtkIMContext *)context == CURRENT_CONTEXT && ibus_im_client_is_enabled (priv->client))
+ return;
+ g_signal_emit_by_name (context, "preedit-start");
+}
+
+static void
+_slave_preedit_end_cb (GtkIMContext *slave, IBusIMContext *context)
+{
+ DEBUG_FUNCTION_IN;
+ IBusIMContextPrivate *priv = context->priv;
+ if ((GtkIMContext *)context == CURRENT_CONTEXT && ibus_im_client_is_enabled (priv->client))
+ return;
+ g_signal_emit_by_name (context, "preedit-end");
+}
+
+static void
+_slave_retrieve_surrounding_cb (GtkIMContext *slave, IBusIMContext *context)
+{
+ DEBUG_FUNCTION_IN;
+ IBusIMContextPrivate *priv = context->priv;
+ if ((GtkIMContext *)context == CURRENT_CONTEXT && ibus_im_client_is_enabled (priv->client))
+ return;
+ g_signal_emit_by_name (context, "retrieve-surrounding");
+}
+
+static void
+_slave_delete_surrounding_cb (GtkIMContext *slave, gint a1, gint a2, IBusIMContext *context)
+{
+ DEBUG_FUNCTION_IN;
+ IBusIMContextPrivate *priv = context->priv;
+ if ((GtkIMContext *)context == CURRENT_CONTEXT && ibus_im_client_is_enabled (priv->client))
+ return;
+ g_signal_emit_by_name (context, "delete-surrounding", a1, a2);
+}
+
diff --git a/gtk2/gikimcontext.h b/gtk2/ibusimcontext.h
index 39f8e4e..074d1e6 100644
--- a/gtk2/gikimcontext.h
+++ b/gtk2/ibusimcontext.h
@@ -1,6 +1,6 @@
/* vim:set et ts=4: */
-/* GIK - The G Input Toolkit
- * Copyright (C) 2008-2009 Huang Peng
+/* IBus - The Input Bus
+ * Copyright (C) 2008-2009 Huang Peng <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
@@ -17,8 +17,8 @@
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
-#ifndef __GIK_IM_CONTEXT_H_
-#define __GIK_IM_CONTEXT_H_
+#ifndef __IBUS_IM_CONTEXT_H_
+#define __IBUS_IM_CONTEXT_H_
#include <gtk/gtk.h>
@@ -27,24 +27,24 @@
*/
G_BEGIN_DECLS
-typedef struct _GikIMContext GikIMContext;
-typedef struct _GikIMContextClass GikIMContextClass;
-typedef struct _GikIMContextPrivate GikIMContextPrivate;
+typedef struct _IBusIMContext IBusIMContext;
+typedef struct _IBusIMContextClass IBusIMContextClass;
+typedef struct _IBusIMContextPrivate IBusIMContextPrivate;
-struct _GikIMContext {
+struct _IBusIMContext {
GtkIMContext parent;
/* instance members */
- GikIMContextPrivate *priv;
+ IBusIMContextPrivate *priv;
};
-struct _GikIMContextClass {
+struct _IBusIMContextClass {
GtkIMContextClass parent;
/* class members */
};
-GtkIMContext *gik_im_context_new (void);
-void gik_im_context_register_type (GTypeModule *type_module);
-void gik_im_context_shutdown (void);
+GtkIMContext *ibus_im_context_new (void);
+void ibus_im_context_register_type (GTypeModule *type_module);
+void ibus_im_context_shutdown (void);
G_END_DECLS
#endif