--- /dev/null
+/* 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.
+ */
+
+%module IMdkit
+%{
+#include <X11/Xproto.h>
+#include <X11/Xlib.h>
+#include <X11/keysym.h>
+#include <X11/Xutil.h>
+#include <Xi18n.h>
+#include <pygobject.h>
+#include <pygtk/pygtk.h>
+#include <gdk/gdk.h>
+#include <gdk/gdkx.h>
+%}
+
+%init %{
+ pygobject_init (-1, -1, -1);
+ init_pygtk ();
+ /*
+ gint argc = 1;
+ gchar *argv [] = { NULL, NULL};
+ argv[0] = g_strdup (Py_GetProgramName ());
+ g_debug ("1 %s", argv[0]);
+ gdk_init (&argc, (gchar ***)&argv);
+ g_debug ("2");
+ g_debug ("3");
+ */
+%}
+
+%{
+/* define XIM structure */
+struct XIM {
+ struct XIMS *xims;
+ PyObject *window;
+ PyObject *protocol_handler;
+};
+
+static struct XIM * _xim = NULL;
+
+/* define protocol handler */
+static int
+_ims_protocol_handler (XIMS xims, IMProtocol *call_data)
+{
+ PyObject *xim = NULL;
+
+ if (_xim == NULL || _xim->xims != xims)
+ return 0;
+
+ return 0;
+}
+
+%}
+
+/* define exception */
+%exception {
+ $action;
+ if (PyErr_Occurred ()) {
+ return NULL;
+ }
+}
+
+/* define type maps */
+%typemap (in) PyObject * {
+ $1 = $input;
+}
+
+%typemap (out) PyObject * {
+ $result = $1;
+}
+
+struct XIM {
+ /* define property */
+ %immutable;
+ PyObject *window;
+ %mutable;
+};
+
+%extend XIM {
+ XIM (char *name, char *locale, PyObject *protocol_handler) {
+ struct XIM *self = NULL;
+
+ if (name == NULL) {
+ PyErr_Format (PyExc_TypeError,
+ "Argument 1 of XIM must be a string.");
+ goto failed;
+ }
+
+ if (locale == NULL) {
+ PyErr_Format (PyExc_TypeError,
+ "Argument 2 of XIM must be a string.");
+ goto failed;
+ }
+
+ if (!PyCallable_Check (protocol_handler)) {
+ PyErr_Format (PyExc_TypeError,
+ "Argument 3 of XIM must be a callable object.");
+ goto failed;
+ }
+
+ if (_xim != NULL) {
+ PyErr_Format (PyExc_RuntimeError,
+ "XIM can not be created second time.");
+ goto failed;
+
+ }
+
+ self = g_new (struct XIM, 1);
+
+ Py_INCREF (protocol_handler);
+ self->protocol_handler = protocol_handler;
+
+ XIMStyle ims_styles_overspot [] = {
+ XIMPreeditPosition | XIMStatusNothing,
+ XIMPreeditNothing | XIMStatusNothing,
+ XIMPreeditPosition | XIMStatusCallbacks,
+ XIMPreeditNothing | XIMStatusCallbacks,
+ 0
+ };
+
+ XIMStyle ims_styles_onspot [] = {
+ XIMPreeditPosition | XIMStatusNothing,
+ XIMPreeditCallbacks | XIMStatusNothing,
+ XIMPreeditNothing | XIMStatusNothing,
+ XIMPreeditPosition | XIMStatusCallbacks,
+ XIMPreeditCallbacks | XIMStatusCallbacks,
+ XIMPreeditNothing | XIMStatusCallbacks,
+ 0
+ };
+
+ XIMEncoding ims_encodings[] = {
+ "COMPOUND_TEXT",
+ 0
+ };
+
+ GdkWindowAttr window_attr = {
+ title : "xim2gtkim",
+ event_mask : GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
+ wclass: GDK_INPUT_OUTPUT,
+ window_type: GDK_WINDOW_TOPLEVEL,
+ override_redirect: 1,
+ };
+
+ GdkWindow *window = gdk_window_new (NULL, &window_attr, GDK_WA_TITLE);
+ self->window = pygobject_new (window);
+ Py_INCREF (self->window);
+
+ XIMStyles styles;
+ XIMEncodings encodings;
+
+ styles.count_styles =
+ sizeof (ims_styles_onspot)/sizeof (XIMStyle) - 1;
+ styles.supported_styles = ims_styles_onspot;
+
+ encodings.count_encodings =
+ sizeof (ims_encodings)/sizeof (XIMEncoding) - 1;
+ encodings.supported_encodings = ims_encodings;
+
+ self->xims = IMOpenIM (GDK_DISPLAY (),
+ IMModifiers, "Xi18n",
+ IMServerWindow, GDK_WINDOW_XWINDOW (window),
+ IMServerName, name,
+ IMLocale, locale,
+ IMServerTransport, "X/",
+ IMInputStyles, &styles,
+ IMEncodingList, &encodings,
+ IMProtocolHandler, _ims_protocol_handler,
+ IMFilterEventMask, KeyPressMask | KeyReleaseMask,
+ NULL
+ );
+
+ _xim = self;
+ return self;
+
+ failed:
+ if (self) {
+ Py_XDECREF (self->window);
+ Py_XDECREF (self->protocol_handler);
+ g_free (self);
+ }
+ return NULL;
+ }
+
+ ~XIM () {
+ if (self) {
+ if (self->xims) {
+ IMCloseIM (self->xims);
+ }
+ Py_XDECREF (self->window);
+ Py_XDECREF (self->protocol_handler);
+ g_free (self);
+ }
+ _xim = NULL;
+ }
+
+}
+
--- /dev/null
+# vim:set noet ts=4:
+#
+# ibus - The Input Bus
+#
+# Copyright (c) 2007-2008 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 program; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+# Boston, MA 02111-1307 USA
+
+SUBDIRS = \
+ IMdkit \
+ $(NULL)
+
+xim_PYTHON = \
+ engine.py \
+ factory.py \
+ main.py \
+ tables.py \
+ test.py \
+ $(NULL)
+
+ximdir = $(datadir)/ibus/xim
+
+IMdkit_DATA = \
+ IMdkit.py \
+ $(NULL)
+
+IMdkit_LTLIBRARIES = _IMdkit.la
+
+IMdkitdir = @pyexecdir@
+
+_IMdkit_la_SOURCES = \
+ $(NULL)
+
+nodist__IMdkit_la_SOURCES = \
+ IMdkit_wrap.c \
+ $(NULL)
+
+_IMdkit_la_CFLAGS = \
+ @X11_CFLAGS@ \
+ @GDK2_CFLAGS@ \
+ @PYGOBJECT2_CFLAGS@ \
+ @PYGTK2_CFLAGS@ \
+ @GTK2_CFLAGS@ \
+ @PYTHON_CFLAGS@ \
+ -IIMdkit \
+ $(NULL)
+
+_IMdkit_la_LDFLAGS = \
+ @X11_LIBS@ \
+ @GDK2_LIBS@ \
+ @PYGOBJECT2_LIBS@ \
+ @PYGTK2_LIBS@ \
+ @GTK2_LIBS@ \
+ @PYTHON_LIBS@ \
+ -rpath $(IMdkitdir) \
+ -avoid-version \
+ -module \
+ IMdkit/libIMdkit.la \
+ $(NULL)
+
+#libexec_SCRIPTS = ibus-xim
+
+IMdkit.py IMdkit_wrap.c: IMdkit.i
+ $(SWIG) -python -I/usr/include -o IMdkit_wrap.c $(srcdir)/IMdkit.i
+
+test: all
+ $(ENV) PYTHONPATH=$(builddir)/.libs python test.py
+
+test-ipython: all
+ $(ENV) PYTHONPATH=$(builddir)/.libs ipython
+
+EXTRA_DIST = \
+ IMdkit.i \
+ ibus-xim.in \
+ $(NULL)
+
+CLEANFILES = \
+ IMdkit.py \
+ IMdkit_wrap.* \
+ *.pyc \
+ $(MULL)
+
+DISTCLEANFILES = \
+ $(MULL)