summaryrefslogtreecommitdiff
path: root/obt
diff options
context:
space:
mode:
authorDana Jansens <danakj@orodu.net>2010-02-11 11:16:17 -0500
committerDana Jansens <danakj@orodu.net>2010-02-11 11:16:17 -0500
commit6e280e9f532d5c2424bb4165f1e9a886740c1bc3 (patch)
treefe520238a60c15236480c77858d1c0283f43b2bc /obt
parente83803b8b001bb7eb24ac7441668e57d964f0b27 (diff)
create an X Input Method in obt for the app to use for all input
Diffstat (limited to 'obt')
-rw-r--r--obt/display.h2
-rw-r--r--obt/keyboard.c60
2 files changed, 62 insertions, 0 deletions
diff --git a/obt/display.h b/obt/display.h
index ff20f9c9..b5816a9a 100644
--- a/obt/display.h
+++ b/obt/display.h
@@ -56,6 +56,8 @@ extern gint obt_display_extension_sync_basep;
extern Display* obt_display;
+/*! Open the X display. You should call g_set_prgname() before calling this
+ function for X Input Methods to work correctly. */
gboolean obt_display_open(const char *display_name);
void obt_display_close(void);
diff --git a/obt/keyboard.c b/obt/keyboard.c
index 6bb13861..bd7ec7b6 100644
--- a/obt/keyboard.c
+++ b/obt/keyboard.c
@@ -34,6 +34,7 @@
#define nth_mask(n) (1 << n)
static void set_modkey_mask(guchar mask, KeySym sym);
+static void xim_init(void);
void obt_keyboard_shutdown();
static XModifierKeymap *modmap;
@@ -49,6 +50,9 @@ static gboolean hyper_l = FALSE;
static gboolean started = FALSE;
+static XIM xim = NULL;
+static XIMStyle xim_style = 0;
+
void obt_keyboard_reload(void)
{
gint i, j, k;
@@ -56,6 +60,8 @@ void obt_keyboard_reload(void)
if (started) obt_keyboard_shutdown(); /* free stuff */
started = TRUE;
+ xim_init();
+
/* reset the keys to not be bound to any masks */
for (i = 0; i < OBT_KEYBOARD_NUM_MODKEYS; ++i)
modkeys_keys[i] = 0;
@@ -104,9 +110,63 @@ void obt_keyboard_shutdown(void)
modmap = NULL;
XFree(keymap);
keymap = NULL;
+ if (xim) XCloseIM(xim);
+ xim = NULL;
+ xim_style = 0;
started = FALSE;
}
+void xim_init(void)
+{
+ gchar *aname, *aclass;
+
+ aname = g_strdup(g_get_prgname());
+ if (!aname) aname = g_strdup("obt");
+
+ aclass = g_strdup(aname);
+ if (g_ascii_islower(aclass[0]))
+ aclass[0] = g_ascii_toupper(aclass[0]);
+
+ g_print("Opening Input Method for %s %s\n", aname, aclass);
+ xim = XOpenIM(obt_display, NULL, aname, aclass);
+
+ if (!xim)
+ g_message("Failed to open an Input Method");
+ else {
+ XIMStyles *xim_styles = NULL;
+ char *r;
+
+ /* get the input method styles */
+ r = XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL);
+ if (r || !xim_styles)
+ g_message("Input Method does not support any styles");
+ if (xim_styles) {
+ int i;
+
+ /* find a style that doesnt need preedit or status */
+ for (i = 0; i < xim_styles->count_styles; ++i) {
+ if (xim_styles->supported_styles[i] ==
+ (XIMPreeditNothing | XIMStatusNothing))
+ {
+ xim_style = xim_styles->supported_styles[i];
+ break;
+ }
+ }
+ XFree(xim_styles);
+ }
+
+ if (!xim_style) {
+ g_message("Input Method does not support a usable style");
+
+ XCloseIM(xim);
+ xim = NULL;
+ }
+ }
+
+ g_free(aclass);
+ g_free(aname);
+}
+
guint obt_keyboard_keycode_to_modmask(guint keycode)
{
gint i, j;