850 lines
28 KiB
Diff
850 lines
28 KiB
Diff
From 49d2f16638aaa9160b87936cb89fea92186e5171 Mon Sep 17 00:00:00 2001
|
|
From: Daiki Ueno <ueno@unixuser.org>
|
|
Date: Wed, 31 Aug 2011 18:28:48 +0900
|
|
Subject: [PATCH 5/6] Support virtual keyboard.
|
|
|
|
---
|
|
configure.ac | 17 +++
|
|
src/Makefile.am | 7 ++
|
|
src/default.xml.in.in | 111 ++++++++++++++++++++
|
|
src/engine.c | 66 ++++++++++++
|
|
src/ibus-m17n-preferences.ui | 16 +++
|
|
src/m17nutil.c | 59 +++++++++++-
|
|
src/m17nutil.h | 11 ++
|
|
src/setup.c | 26 +++++
|
|
src/virtkbd.c | 233 ++++++++++++++++++++++++++++++++++++++++++
|
|
src/virtkbd.h | 31 ++++++
|
|
10 files changed, 576 insertions(+), 1 deletions(-)
|
|
create mode 100644 src/virtkbd.c
|
|
create mode 100644 src/virtkbd.h
|
|
|
|
diff --git a/configure.ac b/configure.ac
|
|
index 23102c4..13e42f8 100644
|
|
--- a/configure.ac
|
|
+++ b/configure.ac
|
|
@@ -88,6 +88,23 @@ fi
|
|
|
|
AM_CONDITIONAL([HAVE_GTK],[test x$with_gtk != xno])
|
|
|
|
+dnl check eekboard for virtual keyboard
|
|
+AC_MSG_CHECKING([whether you enable eekboard])
|
|
+AC_ARG_ENABLE(eekboard,
|
|
+ AS_HELP_STRING([--enable-eekboard=no/yes],
|
|
+ [Enable eekboard default=yes]),
|
|
+ enable_eekboard=$enableval,
|
|
+ enable_eekboard=yes)
|
|
+
|
|
+if test x$enable_eekboard = xyes; then
|
|
+ PKG_CHECK_MODULES([EEKBOARD], [eekboard-0.90], , enable_xtest=no)
|
|
+ if test x$enable_eekboard = xyes; then
|
|
+ AC_DEFINE([HAVE_EEKBOARD], [1], [Define if eekboard is found])
|
|
+ fi
|
|
+fi
|
|
+AM_CONDITIONAL(ENABLE_EEKBOARD, [test x$enable_eekboard = xyes])
|
|
+AC_MSG_RESULT($enable_eekboard)
|
|
+
|
|
# check if minput_list, which is available in m17n-lib 1.6.2+ (CVS)
|
|
save_CFLAGS="$CFLAGS"
|
|
save_LIBS="$LIBS"
|
|
diff --git a/src/Makefile.am b/src/Makefile.am
|
|
index e354149..eac6629 100644
|
|
--- a/src/Makefile.am
|
|
+++ b/src/Makefile.am
|
|
@@ -64,11 +64,18 @@ ibus_engine_m17n_SOURCES = \
|
|
main.c \
|
|
engine.c \
|
|
engine.h \
|
|
+ virtkbd.c \
|
|
+ virtkbd.h \
|
|
+ $(NULL)
|
|
+ibus_engine_m17n_CFLAGS = \
|
|
+ @EEKBOARD_CFLAGS@ \
|
|
+ $(AM_CFLAGS) \
|
|
$(NULL)
|
|
ibus_engine_m17n_LDADD = \
|
|
libm17ncommon.a \
|
|
@IBUS_LIBS@ \
|
|
@M17N_LIBS@ \
|
|
+ @EEKBOARD_LIBS@ \
|
|
$(NULL)
|
|
|
|
if HAVE_GTK
|
|
diff --git a/src/default.xml.in.in b/src/default.xml.in.in
|
|
index b1c77c5..dfcd978 100644
|
|
--- a/src/default.xml.in.in
|
|
+++ b/src/default.xml.in.in
|
|
@@ -12,6 +12,7 @@
|
|
<preedit-highlight>FALSE</preedit-highlight>
|
|
<symbol></symbol>
|
|
@IBUS_HOTKEYS_XML@
|
|
+ <virtual-keyboard>us</virtual-keyboard>
|
|
</engine>
|
|
<!-- Indic engines should be selected by default:
|
|
https://bugzilla.redhat.com/show_bug.cgi?id=640896 -->
|
|
@@ -410,4 +411,114 @@
|
|
<name>m17n:zh:tonepy*</name>
|
|
<symbol>调</symbol>
|
|
</engine>
|
|
+
|
|
+ <!-- Virtual keyboard. -->
|
|
+ <engine>
|
|
+ <name>m17n:ar:kbd</name>
|
|
+ <virtual-keyboard>ar,us</virtual-keyboard>
|
|
+ </engine>
|
|
+ <engine>
|
|
+ <name>m17n:be:kbd</name>
|
|
+ <virtual-keyboard>be,us</virtual-keyboard>
|
|
+ </engine>
|
|
+ <engine>
|
|
+ <name>m17n:fa:kbd</name>
|
|
+ <virtual-keyboard>fa,us</virtual-keyboard>
|
|
+ </engine>
|
|
+ <engine>
|
|
+ <name>m17n:he:kbd</name>
|
|
+ <virtual-keyboard>he,us</virtual-keyboard>
|
|
+ </engine>
|
|
+ <engine>
|
|
+ <name>m17n:kk:kbd</name>
|
|
+ <virtual-keyboard>kk,us</virtual-keyboard>
|
|
+ </engine>
|
|
+ <engine>
|
|
+ <name>m17n:ks:kbd</name>
|
|
+ <virtual-keyboard>ks,us</virtual-keyboard>
|
|
+ </engine>
|
|
+ <engine>
|
|
+ <name>m17n:my:kbd</name>
|
|
+ <virtual-keyboard>my,us</virtual-keyboard>
|
|
+ </engine>
|
|
+ <engine>
|
|
+ <name>m17n:ru:kbd</name>
|
|
+ <virtual-keyboard>ru,us</virtual-keyboard>
|
|
+ </engine>
|
|
+ <engine>
|
|
+ <name>m17n:ua:kbd</name>
|
|
+ <virtual-keyboard>ua,us</virtual-keyboard>
|
|
+ </engine>
|
|
+ <engine>
|
|
+ <name>m17n:ug:kbd</name>
|
|
+ <virtual-keyboard>ug,us</virtual-keyboard>
|
|
+ </engine>
|
|
+ <engine>
|
|
+ <name>m17n:be:kbd</name>
|
|
+ <virtual-keyboard>be,us</virtual-keyboard>
|
|
+ </engine>
|
|
+ <engine>
|
|
+ <name>m17n:th:*</name>
|
|
+ <virtual-keyboard>th,us</virtual-keyboard>
|
|
+ </engine>
|
|
+ <engine>
|
|
+ <name>m17n:zh:bopomofo</name>
|
|
+ <virtual-keyboard>zh-bopomofo,us</virtual-keyboard>
|
|
+ </engine>
|
|
+ <engine>
|
|
+ <name>m17n:as:inscript</name>
|
|
+ <virtual-keyboard>as-inscript,us</virtual-keyboard>
|
|
+ </engine>
|
|
+ <engine>
|
|
+ <name>m17n:bn:inscript</name>
|
|
+ <virtual-keyboard>bn-inscript,us</virtual-keyboard>
|
|
+ </engine>
|
|
+ <engine>
|
|
+ <name>m17n:gu:inscript</name>
|
|
+ <virtual-keyboard>gu-inscript,us</virtual-keyboard>
|
|
+ </engine>
|
|
+ <engine>
|
|
+ <name>m17n:hi:inscript</name>
|
|
+ <virtual-keyboard>hi-inscript,us</virtual-keyboard>
|
|
+ </engine>
|
|
+ <engine>
|
|
+ <name>m17n:kn:inscript</name>
|
|
+ <virtual-keyboard>kn-inscript,us</virtual-keyboard>
|
|
+ </engine>
|
|
+ <engine>
|
|
+ <name>m17n:ks:inscript</name>
|
|
+ <virtual-keyboard>kn-inscript,us</virtual-keyboard>
|
|
+ </engine>
|
|
+ <engine>
|
|
+ <name>m17n:mai:inscript</name>
|
|
+ <virtual-keyboard>mai-inscript,us</virtual-keyboard>
|
|
+ </engine>
|
|
+ <engine>
|
|
+ <name>m17n:ml:inscript</name>
|
|
+ <virtual-keyboard>ml-inscript,us</virtual-keyboard>
|
|
+ </engine>
|
|
+ <engine>
|
|
+ <name>m17n:mr:inscript</name>
|
|
+ <virtual-keyboard>mr-inscript,us</virtual-keyboard>
|
|
+ </engine>
|
|
+ <engine>
|
|
+ <name>m17n:or:inscript</name>
|
|
+ <virtual-keyboard>or-inscript,us</virtual-keyboard>
|
|
+ </engine>
|
|
+ <engine>
|
|
+ <name>m17n:pa:inscript</name>
|
|
+ <virtual-keyboard>pa-inscript,us</virtual-keyboard>
|
|
+ </engine>
|
|
+ <engine>
|
|
+ <name>m17n:sd:inscript</name>
|
|
+ <virtual-keyboard>sd-inscript,us</virtual-keyboard>
|
|
+ </engine>
|
|
+ <engine>
|
|
+ <name>m17n:ta:inscript</name>
|
|
+ <virtual-keyboard>ta-inscript,us</virtual-keyboard>
|
|
+ </engine>
|
|
+ <engine>
|
|
+ <name>m17n:te:inscript</name>
|
|
+ <virtual-keyboard>te-inscript,us</virtual-keyboard>
|
|
+ </engine>
|
|
</engines>
|
|
diff --git a/src/engine.c b/src/engine.c
|
|
index dcff0c7..1e6bd1b 100644
|
|
--- a/src/engine.c
|
|
+++ b/src/engine.c
|
|
@@ -7,6 +7,7 @@
|
|
#include <m17n.h>
|
|
#include <string.h>
|
|
#include "m17nutil.h"
|
|
+#include "virtkbd.h"
|
|
#include "engine.h"
|
|
|
|
typedef struct _IBusM17NEngine IBusM17NEngine;
|
|
@@ -18,10 +19,13 @@ struct _IBusM17NEngine {
|
|
/* members */
|
|
MInputContext *context;
|
|
IBusLookupTable *table;
|
|
+ IBusM17NVirtualKeyboard *virtkbd;
|
|
+
|
|
IBusProperty *status_prop;
|
|
#ifdef HAVE_SETUP
|
|
IBusProperty *setup_prop;
|
|
#endif /* HAVE_SETUP */
|
|
+ IBusProperty *virtkbd_prop;
|
|
IBusPropList *prop_list;
|
|
};
|
|
|
|
@@ -34,6 +38,8 @@ struct _IBusM17NEngineClass {
|
|
guint preedit_background;
|
|
gint preedit_underline;
|
|
gint lookup_table_orientation;
|
|
+ gchar *virtual_keyboard;
|
|
+ gboolean virtual_keyboard_enabled;
|
|
|
|
MInputMethod *im;
|
|
};
|
|
@@ -256,6 +262,7 @@ ibus_m17n_engine_class_init (IBusM17NEngineClass *klass)
|
|
klass->preedit_background = INVALID_COLOR;
|
|
klass->preedit_underline = IBUS_ATTR_UNDERLINE_NONE;
|
|
klass->lookup_table_orientation = IBUS_ORIENTATION_SYSTEM;
|
|
+ klass->virtual_keyboard_enabled = FALSE;
|
|
|
|
engine_config = ibus_m17n_get_engine_config (engine_name);
|
|
g_free (engine_name);
|
|
@@ -290,6 +297,14 @@ ibus_m17n_engine_class_init (IBusM17NEngineClass *klass)
|
|
&klass->lookup_table_orientation))
|
|
klass->lookup_table_orientation = IBUS_ORIENTATION_SYSTEM;
|
|
|
|
+ if (!ibus_m17n_config_get_boolean (config,
|
|
+ klass->config_section,
|
|
+ "virtual_keyboard_enabled",
|
|
+ &klass->virtual_keyboard_enabled))
|
|
+ klass->virtual_keyboard_enabled = FALSE;
|
|
+
|
|
+ klass->virtual_keyboard = engine_config->virtual_keyboard;
|
|
+
|
|
ibus_m17n_engine_config_free (engine_config);
|
|
|
|
g_signal_connect (config, "value-changed",
|
|
@@ -346,6 +361,7 @@ ibus_m17n_engine_init (IBusM17NEngine *m17n)
|
|
{
|
|
IBusText* label;
|
|
IBusText* tooltip;
|
|
+ IBusM17NEngineClass *klass = (IBusM17NEngineClass *) G_OBJECT_GET_CLASS (m17n);
|
|
|
|
m17n->prop_list = ibus_prop_list_new ();
|
|
g_object_ref_sink (m17n->prop_list);
|
|
@@ -378,6 +394,24 @@ ibus_m17n_engine_init (IBusM17NEngine *m17n)
|
|
ibus_prop_list_append (m17n->prop_list, m17n->setup_prop);
|
|
#endif /* HAVE_SETUP */
|
|
|
|
+ label = ibus_text_new_from_string ("On-screen Keyboard");
|
|
+ tooltip = ibus_text_new_from_string ("Show on-screen keyboard");
|
|
+ m17n->virtkbd_prop = ibus_property_new ("virtual-keyboard",
|
|
+ PROP_TYPE_NORMAL,
|
|
+ label,
|
|
+ "input-keyboard",
|
|
+ tooltip,
|
|
+ TRUE,
|
|
+ FALSE,
|
|
+ PROP_STATE_UNCHECKED,
|
|
+ NULL);
|
|
+ g_object_ref_sink (m17n->virtkbd_prop);
|
|
+ ibus_prop_list_append (m17n->prop_list, m17n->virtkbd_prop);
|
|
+
|
|
+ if (klass->virtual_keyboard_enabled &&
|
|
+ klass->virtual_keyboard != NULL)
|
|
+ ibus_property_set_visible (m17n->virtkbd_prop, TRUE);
|
|
+
|
|
m17n->table = ibus_lookup_table_new (9, 0, TRUE, TRUE);
|
|
g_object_ref_sink (m17n->table);
|
|
m17n->context = NULL;
|
|
@@ -463,6 +497,11 @@ ibus_m17n_engine_destroy (IBusM17NEngine *m17n)
|
|
}
|
|
#endif /* HAVE_SETUP */
|
|
|
|
+ if (m17n->virtkbd_prop) {
|
|
+ g_object_unref (m17n->virtkbd_prop);
|
|
+ m17n->virtkbd_prop = NULL;
|
|
+ }
|
|
+
|
|
if (m17n->table) {
|
|
g_object_unref (m17n->table);
|
|
m17n->table = NULL;
|
|
@@ -473,6 +512,11 @@ ibus_m17n_engine_destroy (IBusM17NEngine *m17n)
|
|
m17n->context = NULL;
|
|
}
|
|
|
|
+ if (m17n->virtkbd) {
|
|
+ g_object_unref (m17n->virtkbd);
|
|
+ m17n->virtkbd = NULL;
|
|
+ }
|
|
+
|
|
IBUS_OBJECT_CLASS (parent_class)->destroy ((IBusObject *)m17n);
|
|
}
|
|
|
|
@@ -705,6 +749,9 @@ ibus_m17n_engine_enable (IBusEngine *engine)
|
|
input context that we will use surrounding-text. */
|
|
ibus_engine_get_surrounding_text (engine, NULL, NULL, NULL);
|
|
#endif /* HAVE_IBUS_ENGINE_GET_SURROUNDING_TEXT */
|
|
+
|
|
+ if (m17n->virtkbd)
|
|
+ ibus_m17n_virtual_keyboard_enable (m17n->virtkbd);
|
|
}
|
|
|
|
static void
|
|
@@ -714,6 +761,9 @@ ibus_m17n_engine_disable (IBusEngine *engine)
|
|
|
|
ibus_m17n_engine_focus_out (engine);
|
|
parent_class->disable (engine);
|
|
+
|
|
+ if (m17n->virtkbd)
|
|
+ ibus_m17n_virtual_keyboard_disable (m17n->virtkbd);
|
|
}
|
|
|
|
static void
|
|
@@ -776,6 +826,22 @@ ibus_m17n_engine_property_activate (IBusEngine *engine,
|
|
}
|
|
#endif /* HAVE_SETUP */
|
|
|
|
+#ifdef HAVE_EEKBOARD
|
|
+ if (g_strcmp0 (prop_name, "virtual-keyboard") == 0) {
|
|
+ /* virtual keyboard is not initialized until a user activates
|
|
+ the "virtual-keyboard" prop for the first time */
|
|
+ if (m17n->virtkbd == NULL) {
|
|
+ IBusM17NEngineClass *klass =
|
|
+ (IBusM17NEngineClass *) G_OBJECT_GET_CLASS (m17n);
|
|
+
|
|
+ m17n->virtkbd =
|
|
+ ibus_m17n_virtual_keyboard_new ((IBusEngine *)m17n,
|
|
+ klass->virtual_keyboard);
|
|
+ }
|
|
+ ibus_m17n_virtual_keyboard_toggle_display (m17n->virtkbd);
|
|
+ }
|
|
+#endif /* HAVE_EEKBOARD */
|
|
+
|
|
parent_class->property_activate (engine, prop_name, prop_state);
|
|
}
|
|
|
|
diff --git a/src/ibus-m17n-preferences.ui b/src/ibus-m17n-preferences.ui
|
|
index a46ab49..bca034d 100644
|
|
--- a/src/ibus-m17n-preferences.ui
|
|
+++ b/src/ibus-m17n-preferences.ui
|
|
@@ -192,6 +192,7 @@
|
|
<child>
|
|
<object class="GtkTable" id="table2">
|
|
<property name="visible">True</property>
|
|
+ <property name="n_rows">2</property>
|
|
<property name="n_columns">2</property>
|
|
<child>
|
|
<object class="GtkLabel" id="label9">
|
|
@@ -210,6 +211,21 @@
|
|
<property name="right_attach">2</property>
|
|
</packing>
|
|
</child>
|
|
+ <child>
|
|
+ <object class="GtkCheckButton" id="checkbutton_virtkbd">
|
|
+ <property name="label" translatable="yes">Enable Virtual Keyboard</property>
|
|
+ <property name="visible">True</property>
|
|
+ <property name="can_focus">True</property>
|
|
+ <property name="receives_default">False</property>
|
|
+ <property name="draw_indicator">True</property>
|
|
+ </object>
|
|
+ <packing>
|
|
+ <property name="left_attach">0</property>
|
|
+ <property name="right_attach">2</property>
|
|
+ <property name="top_attach">1</property>
|
|
+ <property name="bottom_attach">2</property>
|
|
+ </packing>
|
|
+ </child>
|
|
</object>
|
|
</child>
|
|
</object>
|
|
diff --git a/src/m17nutil.c b/src/m17nutil.c
|
|
index 94a6891..2143e54 100644
|
|
--- a/src/m17nutil.c
|
|
+++ b/src/m17nutil.c
|
|
@@ -18,7 +18,8 @@ typedef enum {
|
|
ENGINE_CONFIG_LAYOUT_MASK = 1 << 1,
|
|
ENGINE_CONFIG_HOTKEYS_MASK = 1 << 2,
|
|
ENGINE_CONFIG_SYMBOL_MASK = 1 << 3,
|
|
- ENGINE_CONFIG_PREEDIT_HIGHLIGHT_MASK = 1 << 4
|
|
+ ENGINE_CONFIG_PREEDIT_HIGHLIGHT_MASK = 1 << 4,
|
|
+ ENGINE_CONFIG_VIRTUAL_KEYBOARD_MASK = 1 << 5
|
|
} EngineConfigMask;
|
|
|
|
struct _EngineConfigNode {
|
|
@@ -285,6 +286,8 @@ ibus_m17n_get_engine_config (const gchar *engine_name)
|
|
config->symbol = cnode->config.symbol;
|
|
if (cnode->mask & ENGINE_CONFIG_PREEDIT_HIGHLIGHT_MASK)
|
|
config->preedit_highlight = cnode->config.preedit_highlight;
|
|
+ if (cnode->mask & ENGINE_CONFIG_VIRTUAL_KEYBOARD_MASK)
|
|
+ config->virtual_keyboard = cnode->config.virtual_keyboard;
|
|
}
|
|
}
|
|
return config;
|
|
@@ -340,6 +343,11 @@ ibus_m17n_engine_config_parse_xml_node (EngineConfigNode *cnode,
|
|
cnode->mask |= ENGINE_CONFIG_PREEDIT_HIGHLIGHT_MASK;
|
|
continue;
|
|
}
|
|
+ if (g_strcmp0 (sub_node->name , "virtual-keyboard") == 0) {
|
|
+ cnode->config.virtual_keyboard = g_strdup (sub_node->text);
|
|
+ cnode->mask |= ENGINE_CONFIG_VIRTUAL_KEYBOARD_MASK;
|
|
+ continue;
|
|
+ }
|
|
g_warning ("<engine> element contains invalid element <%s>",
|
|
sub_node->name);
|
|
}
|
|
@@ -494,3 +502,52 @@ ibus_m17n_config_get_int (IBusConfig *config,
|
|
return FALSE;
|
|
#endif /* !IBUS_CHECK_VERSION(1,3,99) */
|
|
}
|
|
+
|
|
+void
|
|
+ibus_m17n_config_set_boolean (IBusConfig *config,
|
|
+ const gchar *section,
|
|
+ const gchar *name,
|
|
+ gboolean value)
|
|
+{
|
|
+#if IBUS_CHECK_VERSION(1,3,99)
|
|
+ ibus_config_set_value (config, section, name, g_variant_new_boolean (value));
|
|
+#else
|
|
+ GValue v = { 0 };
|
|
+
|
|
+ g_value_init (&v, G_TYPE_BOOLEAN);
|
|
+ g_value_set_boolean (&v, value);
|
|
+ ibus_config_set_value (config, section, name, &v);
|
|
+#endif /* !IBUS_CHECK_VERSION(1,3,99) */
|
|
+}
|
|
+
|
|
+gboolean
|
|
+ibus_m17n_config_get_boolean (IBusConfig *config,
|
|
+ const gchar *section,
|
|
+ const gchar *name,
|
|
+ gboolean *result)
|
|
+{
|
|
+#if IBUS_CHECK_VERSION(1,3,99)
|
|
+ GVariant *value = NULL;
|
|
+
|
|
+ g_return_val_if_fail (result != NULL, FALSE);
|
|
+
|
|
+ value = ibus_config_get_value (config, section, name);
|
|
+ if (value) {
|
|
+ *result = g_variant_get_boolean (value);
|
|
+ g_variant_unref (value);
|
|
+ return TRUE;
|
|
+ }
|
|
+ return FALSE;
|
|
+#else
|
|
+ GValue value = { 0 };
|
|
+
|
|
+ g_return_val_if_fail (result != NULL, FALSE);
|
|
+
|
|
+ if (ibus_config_get_value (config, section, name, &value)) {
|
|
+ *result = g_value_get_boolean (&value);
|
|
+ g_value_unset (&value);
|
|
+ return TRUE;
|
|
+ }
|
|
+ return FALSE;
|
|
+#endif /* !IBUS_CHECK_VERSION(1,3,99) */
|
|
+}
|
|
diff --git a/src/m17nutil.h b/src/m17nutil.h
|
|
index 21b1bb9..9c3fca8 100644
|
|
--- a/src/m17nutil.h
|
|
+++ b/src/m17nutil.h
|
|
@@ -25,6 +25,9 @@ struct _IBusM17NEngineConfig {
|
|
|
|
/* whether to highlight preedit */
|
|
gboolean preedit_highlight;
|
|
+
|
|
+ /* virtual keyboard type */
|
|
+ gchar *virtual_keyboard;
|
|
};
|
|
|
|
typedef struct _IBusM17NEngineConfig IBusM17NEngineConfig;
|
|
@@ -56,4 +59,12 @@ gboolean ibus_m17n_config_get_int (IBusConfig *config,
|
|
const gchar *section,
|
|
const gchar *name,
|
|
gint *result);
|
|
+void ibus_m17n_config_set_boolean (IBusConfig *config,
|
|
+ const gchar *section,
|
|
+ const gchar *name,
|
|
+ gboolean value);
|
|
+gboolean ibus_m17n_config_get_boolean (IBusConfig *config,
|
|
+ const gchar *section,
|
|
+ const gchar *name,
|
|
+ gboolean *result);
|
|
#endif
|
|
diff --git a/src/setup.c b/src/setup.c
|
|
index 30386df..1c534d6 100644
|
|
--- a/src/setup.c
|
|
+++ b/src/setup.c
|
|
@@ -25,6 +25,7 @@ struct _SetupDialog {
|
|
GtkWidget *colorbutton_foreground;
|
|
GtkWidget *checkbutton_background;
|
|
GtkWidget *colorbutton_background;
|
|
+ GtkWidget *checkbutton_virtkbd;
|
|
GtkWidget *treeview;
|
|
GtkListStore *store;
|
|
|
|
@@ -322,6 +323,15 @@ setup_dialog_load_config (SetupDialog *dialog)
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX(dialog->combobox_orientation),
|
|
index);
|
|
|
|
+ if (!ibus_m17n_config_get_boolean (dialog->config,
|
|
+ dialog->section,
|
|
+ "virtual_keyboard_enabled",
|
|
+ &bvalue))
|
|
+ bvalue = FALSE;
|
|
+
|
|
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(dialog->checkbutton_virtkbd),
|
|
+ bvalue);
|
|
+
|
|
/* Advanced -> m17n-lib configuration */
|
|
dialog->store = gtk_list_store_new (NUM_COLS,
|
|
G_TYPE_STRING,
|
|
@@ -404,6 +414,17 @@ save_choice (SetupDialog *dialog,
|
|
ibus_m17n_config_set_int (dialog->config, dialog->section, name, active);
|
|
}
|
|
|
|
+static void
|
|
+save_toggle (SetupDialog *dialog,
|
|
+ GtkToggleButton *togglebutton,
|
|
+ const gchar *name)
|
|
+{
|
|
+ ibus_m17n_config_set_boolean (dialog->config,
|
|
+ dialog->section,
|
|
+ name,
|
|
+ gtk_toggle_button_get_active (togglebutton));
|
|
+}
|
|
+
|
|
static gboolean
|
|
save_m17n_options (SetupDialog *dialog)
|
|
{
|
|
@@ -486,6 +507,9 @@ setup_dialog_save_config (SetupDialog *dialog)
|
|
save_choice (dialog,
|
|
GTK_COMBO_BOX(dialog->combobox_orientation),
|
|
"lookup_table_orientation");
|
|
+ save_toggle (dialog,
|
|
+ GTK_TOGGLE_BUTTON(dialog->checkbutton_virtkbd),
|
|
+ "virtual_keyboard_enabled");
|
|
save_m17n_options (dialog);
|
|
}
|
|
|
|
@@ -528,6 +552,8 @@ setup_dialog_new (IBusConfig *config,
|
|
dialog->combobox_underline = GTK_WIDGET(object);
|
|
object = gtk_builder_get_object (builder, "combobox_orientation");
|
|
dialog->combobox_orientation = GTK_WIDGET(object);
|
|
+ object = gtk_builder_get_object (builder, "checkbutton_virtkbd");
|
|
+ dialog->checkbutton_virtkbd = GTK_WIDGET(object);
|
|
object = gtk_builder_get_object (builder, "treeview_mim_config");
|
|
dialog->treeview = GTK_WIDGET(object);
|
|
|
|
diff --git a/src/virtkbd.c b/src/virtkbd.c
|
|
new file mode 100644
|
|
index 0000000..9baf971
|
|
--- /dev/null
|
|
+++ b/src/virtkbd.c
|
|
@@ -0,0 +1,233 @@
|
|
+/* vim:set et sts=4: */
|
|
+#ifdef HAVE_CONFIG_H
|
|
+#include <config.h>
|
|
+#endif
|
|
+
|
|
+#ifdef HAVE_EEKBOARD
|
|
+#include <eekboard/eekboard-client.h>
|
|
+#endif /* HAVE_EEKBOARD */
|
|
+
|
|
+#include "virtkbd.h"
|
|
+
|
|
+struct _IBusM17NVirtualKeyboard {
|
|
+ GObject parent;
|
|
+ IBusEngine *engine;
|
|
+ gchar *keyboard_type;
|
|
+ GSList *keyboards;
|
|
+
|
|
+#ifdef HAVE_EEKBOARD
|
|
+ EekboardClient *client;
|
|
+ EekboardContext *context;
|
|
+#endif /* HAVE_EEKBOARD */
|
|
+};
|
|
+
|
|
+struct _IBusM17NVirtualKeyboardClass {
|
|
+ GObjectClass parent_class;
|
|
+};
|
|
+
|
|
+typedef struct _IBusM17NVirtualKeyboardClass IBusM17NVirtualKeyboardClass;
|
|
+
|
|
+#ifdef HAVE_EEKBOARD
|
|
+#define _EEK_INIT() eek_init ()
|
|
+#else
|
|
+#define _EEK_INIT()
|
|
+#endif /* HAVE_EEKBOARD */
|
|
+
|
|
+G_DEFINE_TYPE_WITH_CODE (IBusM17NVirtualKeyboard, ibus_m17n_virtual_keyboard,
|
|
+ G_TYPE_OBJECT, _EEK_INIT());
|
|
+
|
|
+static void
|
|
+ibus_m17n_virtual_keyboard_dispose (GObject *object)
|
|
+{
|
|
+ IBusM17NVirtualKeyboard *virtkbd = IBUS_M17N_VIRTUAL_KEYBOARD (object);
|
|
+
|
|
+ if (virtkbd->engine) {
|
|
+ g_object_unref (virtkbd->engine);
|
|
+ virtkbd->engine = NULL;
|
|
+ }
|
|
+ if (virtkbd->keyboards) {
|
|
+ GSList *next = virtkbd->keyboards->next;
|
|
+ /* virtkbd->keyboards is a ring; break it before free */
|
|
+ virtkbd->keyboards->next = NULL;
|
|
+ g_slist_free (next);
|
|
+ }
|
|
+
|
|
+#ifdef HAVE_EEKBOARD
|
|
+ if (virtkbd->context) {
|
|
+ g_object_unref (virtkbd->context);
|
|
+ virtkbd->context = NULL;
|
|
+ }
|
|
+ if (virtkbd->client) {
|
|
+ g_object_unref (virtkbd->client);
|
|
+ virtkbd->client = NULL;
|
|
+ }
|
|
+#endif /* HAVE_EEKBOARD */
|
|
+
|
|
+ G_OBJECT_CLASS (ibus_m17n_virtual_keyboard_parent_class)->dispose (object);
|
|
+}
|
|
+
|
|
+static void
|
|
+ibus_m17n_virtual_keyboard_finalize (GObject *object)
|
|
+{
|
|
+ IBusM17NVirtualKeyboard *virtkbd = IBUS_M17N_VIRTUAL_KEYBOARD (object);
|
|
+
|
|
+ g_free (virtkbd->keyboard_type);
|
|
+
|
|
+ G_OBJECT_CLASS (ibus_m17n_virtual_keyboard_parent_class)->finalize (object);
|
|
+}
|
|
+
|
|
+static void
|
|
+ibus_m17n_virtual_keyboard_class_init (IBusM17NVirtualKeyboardClass *klass)
|
|
+{
|
|
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
+ gobject_class->dispose = ibus_m17n_virtual_keyboard_dispose;
|
|
+ gobject_class->finalize = ibus_m17n_virtual_keyboard_finalize;
|
|
+}
|
|
+
|
|
+static void
|
|
+ibus_m17n_virtual_keyboard_init (IBusM17NVirtualKeyboard *self)
|
|
+{
|
|
+}
|
|
+
|
|
+#ifdef HAVE_EEKBOARD
|
|
+static void
|
|
+destroyed_cb (EekboardClient *client,
|
|
+ IBusM17NVirtualKeyboard *virtkbd)
|
|
+{
|
|
+ if (virtkbd->context) {
|
|
+ g_object_unref (virtkbd->context);
|
|
+ virtkbd->context = NULL;
|
|
+ }
|
|
+ if (virtkbd->client) {
|
|
+ g_object_unref (virtkbd->client);
|
|
+ virtkbd->client = NULL;
|
|
+ }
|
|
+}
|
|
+
|
|
+static void
|
|
+key_pressed_cb (EekboardContext *context,
|
|
+ gchar *keyname,
|
|
+ EekSymbol *symbol,
|
|
+ guint modifiers,
|
|
+ IBusM17NVirtualKeyboard *virtkbd)
|
|
+{
|
|
+ if (EEK_IS_TEXT (symbol)) {
|
|
+ const gchar *string;
|
|
+ IBusText *text;
|
|
+
|
|
+ string = eek_text_get_text (EEK_TEXT (symbol));
|
|
+ text = ibus_text_new_from_static_string (string);
|
|
+ ibus_engine_commit_text (virtkbd->engine, text);
|
|
+ } else if (EEK_IS_KEYSYM (symbol)) {
|
|
+ guint keyval = eek_keysym_get_xkeysym (EEK_KEYSYM (symbol));
|
|
+ ibus_engine_forward_key_event (virtkbd->engine,
|
|
+ keyval,
|
|
+ 0,
|
|
+ modifiers);
|
|
+ ibus_engine_forward_key_event (virtkbd->engine,
|
|
+ keyval,
|
|
+ 0,
|
|
+ modifiers | IBUS_RELEASE_MASK);
|
|
+ } else if (g_strcmp0 (eek_symbol_get_name (symbol),
|
|
+ "cycle-keyboard") == 0) {
|
|
+ virtkbd->keyboards = g_slist_next (virtkbd->keyboards);
|
|
+ eekboard_context_set_keyboard (virtkbd->context,
|
|
+ GPOINTER_TO_UINT (virtkbd->keyboards->data),
|
|
+ NULL);
|
|
+ }
|
|
+}
|
|
+
|
|
+static void
|
|
+init_client (IBusM17NVirtualKeyboard *virtkbd)
|
|
+{
|
|
+ GDBusConnection *connection;
|
|
+ GError *error;
|
|
+ gchar **strv, **p;
|
|
+
|
|
+ error = NULL;
|
|
+ connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
|
|
+ if (connection == NULL) {
|
|
+ g_printerr ("Can't connect to the session bus: %s\n",
|
|
+ error->message);
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ virtkbd->client = eekboard_client_new (connection, NULL);
|
|
+ g_object_unref (connection);
|
|
+ g_signal_connect (virtkbd->client, "destroyed",
|
|
+ G_CALLBACK (destroyed_cb), virtkbd);
|
|
+
|
|
+ virtkbd->context = eekboard_client_create_context (virtkbd->client,
|
|
+ "ibus-m17n",
|
|
+ NULL);
|
|
+ g_signal_connect (virtkbd->context, "key-pressed",
|
|
+ G_CALLBACK (key_pressed_cb), virtkbd);
|
|
+
|
|
+ strv = g_strsplit (virtkbd->keyboard_type, ",", -1);
|
|
+ for (p = strv; *p; p++) {
|
|
+ guint keyboard;
|
|
+
|
|
+ keyboard = eekboard_context_add_keyboard (virtkbd->context,
|
|
+ g_strstrip (*p),
|
|
+ NULL);
|
|
+ virtkbd->keyboards = g_slist_prepend (virtkbd->keyboards,
|
|
+ GUINT_TO_POINTER (keyboard));
|
|
+ }
|
|
+ virtkbd->keyboards = g_slist_reverse (virtkbd->keyboards);
|
|
+ g_strfreev (strv);
|
|
+
|
|
+ /* make a cycle */
|
|
+ g_slist_last (virtkbd->keyboards)->next = virtkbd->keyboards;
|
|
+
|
|
+ eekboard_context_set_keyboard (virtkbd->context,
|
|
+ GPOINTER_TO_UINT (virtkbd->keyboards->data),
|
|
+ NULL);
|
|
+}
|
|
+#endif /* HAVE_EEKBOARD */
|
|
+
|
|
+void
|
|
+ibus_m17n_virtual_keyboard_toggle_display (IBusM17NVirtualKeyboard *virtkbd)
|
|
+{
|
|
+#ifdef HAVE_EEKBOARD
|
|
+ if (virtkbd->client == NULL)
|
|
+ ibus_m17n_virtual_keyboard_enable (virtkbd);
|
|
+
|
|
+ if (virtkbd->client != NULL) {
|
|
+ if (eekboard_context_is_visible (virtkbd->context))
|
|
+ eekboard_context_hide_keyboard (virtkbd->context, NULL);
|
|
+ else
|
|
+ eekboard_context_show_keyboard (virtkbd->context, NULL);
|
|
+ }
|
|
+#endif /* HAVE_EEKBOARD */
|
|
+}
|
|
+
|
|
+void
|
|
+ibus_m17n_virtual_keyboard_enable (IBusM17NVirtualKeyboard *virtkbd)
|
|
+{
|
|
+#ifdef HAVE_EEKBOARD
|
|
+ if (virtkbd->client == NULL)
|
|
+ init_client (virtkbd);
|
|
+
|
|
+ if (virtkbd->client != NULL)
|
|
+ eekboard_client_push_context (virtkbd->client, virtkbd->context, NULL);
|
|
+#endif /* HAVE_EEKBOARD */
|
|
+}
|
|
+
|
|
+void
|
|
+ibus_m17n_virtual_keyboard_disable (IBusM17NVirtualKeyboard *virtkbd)
|
|
+{
|
|
+#ifdef HAVE_EEKBOARD
|
|
+ if (virtkbd->client != NULL)
|
|
+ eekboard_client_pop_context (virtkbd->client, NULL);
|
|
+#endif /* HAVE_EEKBOARD */
|
|
+}
|
|
+
|
|
+IBusM17NVirtualKeyboard *
|
|
+ibus_m17n_virtual_keyboard_new (IBusEngine *engine,
|
|
+ const gchar *keyboard_type)
|
|
+{
|
|
+ IBusM17NVirtualKeyboard *virtkbd = g_object_new (IBUS_M17N_TYPE_VIRTUAL_KEYBOARD, NULL);
|
|
+ virtkbd->engine = g_object_ref (engine);
|
|
+ virtkbd->keyboard_type = g_strdup (keyboard_type);
|
|
+ return virtkbd;
|
|
+}
|
|
diff --git a/src/virtkbd.h b/src/virtkbd.h
|
|
new file mode 100644
|
|
index 0000000..c28953a
|
|
--- /dev/null
|
|
+++ b/src/virtkbd.h
|
|
@@ -0,0 +1,31 @@
|
|
+#ifndef __VIRTKBD_H__
|
|
+#define __VIRTKBD_H__ 1
|
|
+
|
|
+#include <ibus.h>
|
|
+
|
|
+G_BEGIN_DECLS
|
|
+
|
|
+#define IBUS_M17N_TYPE_VIRTUAL_KEYBOARD (ibus_m17n_virtual_keyboard_get_type())
|
|
+#define IBUS_M17N_VIRTUAL_KEYBOARD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IBUS_M17N_TYPE_VIRTUAL_KEYBOARD, IBusM17NVirtualKeyboard))
|
|
+#define IBUS_M17N_VIRTUAL_KEYBOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IBUS_M17N_TYPE_VIRTUAL_KEYBOARD, IBusM17NVirtualKeyboardClass))
|
|
+#define IBUS_M17N_IS_VIRTUAL_KEYBOARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IBUS_M17N_TYPE_VIRTUAL_KEYBOARD))
|
|
+#define IBUS_M17N_IS_VIRTUAL_KEYBOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IBUS_M17N_TYPE_VIRTUAL_KEYBOARD))
|
|
+#define IBUS_M17N_VIRTUAL_KEYBOARD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IBUS_M17N_TYPE_VIRTUAL_KEYBOARD, IBusM17NVirtualKeyboardClass))
|
|
+
|
|
+typedef struct _IBusM17NVirtualKeyboard IBusM17NVirtualKeyboard;
|
|
+
|
|
+GType ibus_m17n_virtual_keyboard_get_type
|
|
+ (void);
|
|
+IBusM17NVirtualKeyboard *ibus_m17n_virtual_keyboard_new
|
|
+ (IBusEngine *engine,
|
|
+ const gchar *keyboard_type);
|
|
+void ibus_m17n_virtual_keyboard_toggle_display
|
|
+ (IBusM17NVirtualKeyboard *virtkbd);
|
|
+void ibus_m17n_virtual_keyboard_enable
|
|
+ (IBusM17NVirtualKeyboard *virtkbd);
|
|
+void ibus_m17n_virtual_keyboard_disable
|
|
+ (IBusM17NVirtualKeyboard *virtkbd);
|
|
+
|
|
+G_END_DECLS
|
|
+
|
|
+#endif /* __VIRTKBD_H__ */
|
|
--
|
|
1.7.6.2
|
|
|