From e3140b7206d409419faa0c8bfa50f25ad3644cd0 Mon Sep 17 00:00:00 2001 From: Yusuke Sato Date: Fri, 11 Feb 2011 23:48:42 +0900 Subject: [PATCH] Support enable/disable hotkeys that enable or disable ibus unconditionally (i.e. not toggle.) I'll update ibus/po/*po files if the change looks good to you. BUG=http://code.google.com/p/ibus/issues/detail?id=1173 TEST=manually Review URL: http://codereview.appspot.com/3807047 --- bus/ibusimpl.c | 62 ++++++++++++++++++++--- ibus/common.py | 10 ++-- setup/main.py | 22 ++++++++ setup/setup.ui | 134 ++++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 195 insertions(+), 33 deletions(-) diff --git a/bus/ibusimpl.c b/bus/ibusimpl.c index cbcf7f42..79dbf276 100644 --- a/bus/ibusimpl.c +++ b/bus/ibusimpl.c @@ -319,6 +319,32 @@ bus_ibus_impl_set_trigger (BusIBusImpl *ibus, #endif } +/** + * bus_ibus_impl_set_enable_unconditional: + * + * A function to be called when "enable_unconditional" config is updated. + */ +static void +bus_ibus_impl_set_enable_unconditional (BusIBusImpl *ibus, + GVariant *value) +{ + GQuark hotkey = g_quark_from_static_string ("enable-unconditional"); + bus_ibus_impl_set_hotkey (ibus, hotkey, value); +} + +/** + * bus_ibus_impl_set_disable_unconditional: + * + * A function to be called when "disable_unconditional" config is updated. + */ +static void +bus_ibus_impl_set_disable_unconditional (BusIBusImpl *ibus, + GVariant *value) +{ + GQuark hotkey = g_quark_from_static_string ("disable-unconditional"); + bus_ibus_impl_set_hotkey (ibus, hotkey, value); +} + /** * bus_ibus_impl_set_next_engine_in_menu: * @@ -544,14 +570,16 @@ const static struct { gchar *key; void (*func) (BusIBusImpl *, GVariant *); } bus_ibus_impl_config_items [] = { - { "general/hotkey", "trigger", bus_ibus_impl_set_trigger }, - { "general/hotkey", "next_engine_in_menu", bus_ibus_impl_set_next_engine_in_menu }, - { "general/hotkey", "previous_engine", bus_ibus_impl_set_previous_engine }, - { "general", "preload_engines", bus_ibus_impl_set_preload_engines }, - { "general", "use_system_keyboard_layout", bus_ibus_impl_set_use_sys_layout }, - { "general", "use_global_engine", bus_ibus_impl_set_use_global_engine }, - { "general", "embed_preedit_text", bus_ibus_impl_set_embed_preedit_text }, - { "general", "enable_by_default", bus_ibus_impl_set_enable_by_default }, + { "general/hotkey", "trigger", bus_ibus_impl_set_trigger }, + { "general/hotkey", "enable_unconditional", bus_ibus_impl_set_enable_unconditional }, + { "general/hotkey", "disable_unconditional", bus_ibus_impl_set_disable_unconditional }, + { "general/hotkey", "next_engine_in_menu", bus_ibus_impl_set_next_engine_in_menu }, + { "general/hotkey", "previous_engine", bus_ibus_impl_set_previous_engine }, + { "general", "preload_engines", bus_ibus_impl_set_preload_engines }, + { "general", "use_system_keyboard_layout", bus_ibus_impl_set_use_sys_layout }, + { "general", "use_global_engine", bus_ibus_impl_set_use_global_engine }, + { "general", "embed_preedit_text", bus_ibus_impl_set_embed_preedit_text }, + { "general", "enable_by_default", bus_ibus_impl_set_enable_by_default }, }; /** @@ -1900,6 +1928,8 @@ bus_ibus_impl_filter_keyboard_shortcuts (BusIBusImpl *ibus, guint prev_modifiers) { static GQuark trigger = 0; + static GQuark enable_unconditional = 0; + static GQuark disable_unconditional = 0; static GQuark next = 0; static GQuark previous = 0; @@ -1908,6 +1938,8 @@ bus_ibus_impl_filter_keyboard_shortcuts (BusIBusImpl *ibus, if (trigger == 0) { trigger = g_quark_from_static_string ("trigger"); + enable_unconditional = g_quark_from_static_string ("enable-unconditional"); + disable_unconditional = g_quark_from_static_string ("disable-unconditional"); next = g_quark_from_static_string ("next-engine-in-menu"); previous = g_quark_from_static_string ("previous-engine"); } @@ -1930,6 +1962,20 @@ bus_ibus_impl_filter_keyboard_shortcuts (BusIBusImpl *ibus, } return (enabled != bus_input_context_is_enabled (context)); } + if (event == enable_unconditional) { + gboolean enabled = bus_input_context_is_enabled (context); + if (!enabled) { + bus_input_context_enable (context); + } + return bus_input_context_is_enabled (context); + } + if (event == disable_unconditional) { + gboolean enabled = bus_input_context_is_enabled (context); + if (enabled) { + bus_input_context_disable (context); + } + return !bus_input_context_is_enabled (context); + } if (event == next) { if (bus_input_context_is_enabled (context)) { bus_ibus_impl_context_request_next_engine_in_menu (ibus, context); diff --git a/ibus/common.py b/ibus/common.py index 763ed1c9..e105f180 100644 --- a/ibus/common.py +++ b/ibus/common.py @@ -36,10 +36,9 @@ __all__ = ( "default_reply_handler", "default_error_handler", "DEFAULT_ASYNC_HANDLERS", - "CONFIG_GENERAL_SHORTCUT_TRIGGER", - "CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE", - "CONFIG_GENERAL_SHORTCUT_PREV_ENGINE", "CONFIG_GENERAL_SHORTCUT_TRIGGER_DEFAULT", + "CONFIG_GENERAL_SHORTCUT_ENABLE_DEFAULT", + "CONFIG_GENERAL_SHORTCUT_DISABLE_DEFAULT", "CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE_DEFAULT", "CONFIG_GENERAL_SHORTCUT_PREV_ENGINE_DEFAULT", "main", @@ -144,14 +143,13 @@ DEFAULT_ASYNC_HANDLERS = { "error_handler" : default_error_handler } -CONFIG_GENERAL_SHORTCUT_TRIGGER = "/general/keyboard_shortcut_trigger" CONFIG_GENERAL_SHORTCUT_TRIGGER_DEFAULT = [ "Control+space", "Zenkaku_Hankaku", "Hangul"] -CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE = "/general/keyboard_shortcut_next_engine" +CONFIG_GENERAL_SHORTCUT_ENABLE_DEFAULT = [] +CONFIG_GENERAL_SHORTCUT_DISABLE_DEFAULT = [] CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE_DEFAULT = [] -CONFIG_GENERAL_SHORTCUT_PREV_ENGINE = "/general/keyboard_shortcut_prev_engine" CONFIG_GENERAL_SHORTCUT_PREV_ENGINE_DEFAULT = [] __mainloop = None diff --git a/setup/main.py b/setup/main.py index 96e94568..a22bb0c3 100644 --- a/setup/main.py +++ b/setup/main.py @@ -101,6 +101,28 @@ class Setup(object): button.connect("clicked", self.__shortcut_button_clicked_cb, N_("trigger"), "general/hotkey", "trigger", entry) + # enable (unconditional) + shortcuts = self.__config.get_value( + "general/hotkey", "enable_unconditional", + ibus.CONFIG_GENERAL_SHORTCUT_ENABLE_DEFAULT) + button = self.__builder.get_object("button_enable") + entry = self.__builder.get_object("entry_enable") + entry.set_text("; ".join(shortcuts)) + entry.set_tooltip_text("\n".join(shortcuts)) + button.connect("clicked", self.__shortcut_button_clicked_cb, + N_("enable"), "general/hotkey", "enable_unconditional", entry) + + # disable (unconditional) + shortcuts = self.__config.get_value( + "general/hotkey", "disable_unconditional", + ibus.CONFIG_GENERAL_SHORTCUT_DISABLE_DEFAULT) + button = self.__builder.get_object("button_disable") + entry = self.__builder.get_object("entry_disable") + entry.set_text("; ".join(shortcuts)) + entry.set_tooltip_text("\n".join(shortcuts)) + button.connect("clicked", self.__shortcut_button_clicked_cb, + N_("disable"), "general/hotkey", "disable_unconditional", entry) + # next engine shortcuts = self.__config.get_value( "general/hotkey", "next_engine_in_menu", diff --git a/setup/setup.ui b/setup/setup.ui index 0e31a78f..0a69df8c 100644 --- a/setup/setup.ui +++ b/setup/setup.ui @@ -96,22 +96,10 @@ True - 3 + 5 2 12 6 - - - True - The shortcut keys for turning input method on or off - 0 - Enable or disable: - - - GTK_FILL - GTK_FILL - - True @@ -120,8 +108,8 @@ Next input method: - 1 - 2 + 3 + 4 GTK_FILL GTK_FILL @@ -135,8 +123,8 @@ Previous input method: - 2 - 3 + 4 + 5 GTK_FILL GTK_FILL @@ -205,8 +193,8 @@ 1 2 - 1 - 2 + 3 + 4 @@ -239,6 +227,114 @@ + + 1 + 2 + 4 + 5 + + + + + True + The shortcut keys for turning input method on or off + 0 + Enable or disable: + + + GTK_FILL + GTK_FILL + + + + + True + 0 + Enable: + + + 1 + 2 + GTK_FILL + GTK_FILL + + + + + True + 6 + + + True + True + False + + + 0 + + + + + ... + True + True + True + True + + + False + 1 + + + + + 1 + 2 + 1 + 2 + + + + + True + 0 + Disable: + + + 2 + 3 + GTK_FILL + GTK_FILL + + + + + True + 6 + + + True + True + False + + + 0 + + + + + ... + True + True + True + True + + + False + 1 + + + 1 2 -- 2.34.1