add interface in obt to create an Input Context for a window
authorDana Jansens <danakj@orodu.net>
Thu, 11 Feb 2010 16:27:36 +0000 (11:27 -0500)
committerDana Jansens <danakj@orodu.net>
Thu, 11 Feb 2010 16:27:36 +0000 (11:27 -0500)
obt/keyboard.c
obt/keyboard.h

index bd7ec7b..bd5d5df 100644 (file)
 #include <X11/Xlib.h>
 #include <X11/keysym.h>
 
+struct _ObtIC
+{
+    guint ref;
+    XIC xic;
+};
+
 /* These masks are constants and the modifier keys are bound to them as
    anyone sees fit:
         ShiftMask (1<<0), LockMask (1<<1), ControlMask (1<<2), Mod1Mask (1<<3),
@@ -291,3 +297,35 @@ gunichar obt_keyboard_keycode_to_unichar(guint keycode)
     g_free(key);
     return unikey;
 }
+
+ObtIC* obt_keyboard_context_new(Window w)
+{
+    ObtIC *ic = NULL;
+
+    if (w != None) {
+        ic = g_new(ObtIC, 1);
+        ic->ref = 1;
+        ic->xic = NULL;
+
+        if (xim)
+            ic->xic = XCreateIC(xim,
+                                XNInputStyle, xim_style,
+                                XNClientWindow, w,
+                                XNFocusWindow, w,
+                                NULL);
+    }
+    return ic;
+}
+
+void obt_keyboard_context_ref(ObtIC *ic)
+{
+    ++ic->ref;
+}
+
+void obt_keyboard_context_unref(ObtIC *ic)
+{
+    if (--ic->ref < 1) {
+        XDestroyIC(ic->xic);
+        g_free(ic);
+    }
+}
index 4fb6018..d166faa 100644 (file)
@@ -40,6 +40,8 @@ typedef enum {
     OBT_KEYBOARD_NUM_MODKEYS
 } ObtModkeysKey;
 
+typedef struct _ObtIC ObtIC;
+
 void obt_keyboard_reload(void);
 
 /*! Get the modifier mask(s) for a KeyCode. (eg. a keycode bound to Alt_L could
@@ -63,6 +65,11 @@ gchar *obt_keyboard_keycode_to_string(guint keycode);
 /*! Translate a KeyCode to the unicode character it represents */
 gunichar obt_keyboard_keycode_to_unichar(guint keycode);
 
+/*! Create an input context for a window */
+ObtIC* obt_keyboard_context_new(Window w);
+
+void obt_keyboard_context_ref(ObtIC *ic);
+void obt_keyboard_context_unref(ObtIC *ic);
 
 G_END_DECLS