summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHuang Peng <shawn.p.huang@gmail.com>2008-08-21 11:40:05 +0800
committerHuang Peng <shawn.p.huang@gmail.com>2008-08-21 11:40:05 +0800
commit766f22120dfeaa883ef0c3346898d9a7a690dd11 (patch)
tree0f1d1f681315c16e2b3124f0af1b25a1cf6b531a
parent6a605c9f5fa77ab32dc74fd91afd4c46d8d92c2e (diff)
downloadibus-766f22120dfeaa883ef0c3346898d9a7a690dd11.tar.gz
ibus-766f22120dfeaa883ef0c3346898d9a7a690dd11.tar.xz
ibus-766f22120dfeaa883ef0c3346898d9a7a690dd11.zip
WIP.
-rw-r--r--client/gtk2/ibusimcontext.c5
-rw-r--r--daemon/bus.py52
-rw-r--r--lib/gtk2/ibusimclient.c2
-rw-r--r--setup/main.py2
4 files changed, 42 insertions, 19 deletions
diff --git a/client/gtk2/ibusimcontext.c b/client/gtk2/ibusimcontext.c
index 3bc1bef..d9bb469 100644
--- a/client/gtk2/ibusimcontext.c
+++ b/client/gtk2/ibusimcontext.c
@@ -280,8 +280,9 @@ ibus_im_context_filter_keypress (GtkIMContext *context,
IBusIMContext *ibus = IBUS_IM_CONTEXT (context);
IBusIMContextPrivate *priv = ibus->priv;
-
- if (priv->ic && ibus_im_client_filter_keypress (_client, priv->ic, event, _block_filter_key_event))
+ if (priv->ic &&
+ ibus_im_client_filter_keypress (_client,
+ priv->ic, event, _block_filter_key_event))
return TRUE;
else
return gtk_im_context_filter_keypress (priv->slave, event);
diff --git a/daemon/bus.py b/daemon/bus.py
index c4d3fc8..6e68f1e 100644
--- a/daemon/bus.py
+++ b/daemon/bus.py
@@ -31,6 +31,10 @@ from panel import Panel, DummyPanel
from config import Config, DefaultConfig
from register import Register
+CONFIG_GENERAL_SHORTCUT_TRIGGER = "/general/keyboard_shortcut_trigger"
+CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE = "/general/keyboard_shortcut_next_engine"
+CONFIG_GENERAL_SHORTCUT_PREV_ENGINE = "/general/keyboard_shortcut_prev_engine"
+
class IBus(ibus.Object):
def __init__(self):
super(IBus, self).__init__()
@@ -56,6 +60,9 @@ class IBus(ibus.Object):
self.__connections = list()
self.__prev_key = None
+ self.__shortcut_trigger = [(keysyms.space, modifier.CONTROL_MASK)]
+ m = modifier.CONTROL_MASK | modifier.SHIFT_MASK | modifier.RELEASE_MASK
+ self.__shortcut_next_engine = [(keysyms.Shift_L, m), (keysyms.Shift_R, m)]
def new_connection(self, dbusconn):
conn = Connection(dbusconn)
@@ -123,7 +130,7 @@ class IBus(ibus.Object):
conn, reply_cb, error_cb):
context = self.__lookup_context(ic, conn)
- if self.__filter_hotkeys(context, keyval, is_press, state):
+ if self.__filter_keyboard_shortcuts(context, keyval, is_press, state):
reply_cb(True)
return
else:
@@ -158,30 +165,37 @@ class IBus(ibus.Object):
context.set_engine(engine)
self.__panel.states_changed()
- def __filter_hotkeys(self, context, keyval, is_press, state):
- retval = False
- state = state & (modifier.MOD1_MASK | modifier.SHIFT_MASK | modifier.CONTROL_MASK)
-
- if is_press and keyval == keysyms.space \
- and state == modifier.CONTROL_MASK:
+ def __match_keyboard_shortcuts(self, keyval, is_press, state, shortcuts):
+ for sc in shortcuts:
+ if state == sc[1] and keyval == sc[0]:
+ if state & modifier.RELEASE_MASK == 0:
+ return True
+ if self.__prev_key[0] == keyval and \
+ self.__prev_key[1] == True:
+ return True
+ return False
+
+ def __filter_keyboard_shortcuts(self, context, keyval, is_press, state):
+ if not is_press:
+ state = state | modifier.RELEASE_MASK
+
+ retval = True
+ if self.__match_keyboard_shortcuts(keyval,
+ is_press, state, self.__shortcut_trigger):
if context.is_enabled():
self.__context_disable(context)
else:
self.__context_enable(context)
retval = True
- elif self.__prev_key != None and \
- self.__prev_key[0] == keyval and \
- self.__prev_key[1] == True and \
- self.__prev_key[2] == modifier.CONTROL_MASK and \
- is_press == False and \
- keyval in (keysyms.Shift_L, keysyms.Shift_R) and \
- state == modifier.CONTROL_MASK | modifier.SHIFT_MASK:
+ elif self.__match_keyboard_shortcuts(keyval,
+ is_press, state, self.__shortcut_next_engine):
if not context.is_enabled():
self.__context_enable(context)
else:
self.__context_next_factory(context)
+ else:
+ retval = False
- retval = True
self.__prev_key = (keyval, is_press, state)
return retval
@@ -428,6 +442,14 @@ class IBus(ibus.Object):
for conn in self.__config_watch[_dir]:
conn.emit_dbus_signal("ConfigValueChanged", key, value)
+ # check daemon configure
+ if key == CONFIG_GENERAL_SHORTCUT_TRIGGER:
+ print value
+ elif key == CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE:
+ print value
+ elif key == CONFIG_GENERAL_SHORTCUT_PREV_ENGINE:
+ print value
+
def __config_destroy_cb(self, config):
if config == self.__config:
self.__config = DefaultConfig()
diff --git a/lib/gtk2/ibusimclient.c b/lib/gtk2/ibusimclient.c
index e7b117e..929f1ea 100644
--- a/lib/gtk2/ibusimclient.c
+++ b/lib/gtk2/ibusimclient.c
@@ -639,7 +639,7 @@ ibus_im_client_filter_keypress (IBusIMClient *client, const gchar *ic, GdkEventK
IBusIMClientPrivate *priv = client->priv;
- guint state = event->state & GDK_MODIFIER_MASK;
+ guint state = event->state;
gboolean is_press = event->type == GDK_KEY_PRESS;
if (event->send_event) {
diff --git a/setup/main.py b/setup/main.py
index 9b0315b..56c394c 100644
--- a/setup/main.py
+++ b/setup/main.py
@@ -202,7 +202,7 @@ class Setup(object):
shortcuts = None
dialog.set_shortcuts(shortcuts)
id = dialog.run()
- shortcuts = dialog.get_shortcuts()
+ shortcuts = list(set(dialog.get_shortcuts()))
dialog.destroy()
if id != gtk.RESPONSE_OK:
return