ibusでIMEをOn/Offするためのキー(toggleじゃないキー)をつくるためのhowto
参考:iBusの有効/無効に個別のホットキーを割り当てるseparate hotkey patchを作りました(ついでにvi協調機能付き) - 黒糖々日記/kokutoto diary
行数等は1.3.7の情報。
bus/ibusimpl.c
次を bus_ibus_impl_set_trigger の後あたりに追記。
static void bus_ibus_impl_set_enable (BusIBusImpl *ibus, GValue *value) { GQuark hotkey = g_quark_from_static_string ("enable"); bus_ibus_impl_set_hotkey (ibus, hotkey, value); }
static void bus_ibus_impl_set_disable (BusIBusImpl *ibus, GValue *value) { GQuark hotkey = g_quark_from_static_string ("disable"); bus_ibus_impl_set_hotkey (ibus, hotkey, value); }
"general/hotkey"ではじまる配列が並んでいるところ(l.425あたり)の、prev_engineの後あたりに、次を追記。
{ "general/hotkey", "enable", bus_ibus_impl_set_enable }, { "general/hotkey", "disable", bus_ibus_impl_set_disable },
念のために functions prototype (l.69あたり)に次を追記。
static void bus_ibus_impl_set_enable (BusIBusImpl *ibus, GValue *value); static void bus_ibus_impl_set_disable (BusIBusImpl *ibus, GValue *value);
bus_ibus_impl_filter_keyboard_shortcuts 関数の初期化部分(l.1850)、static GQuark triggerが並んでいるところに次を追記(最近のバージョンでかわったらしい部分)。
static GQuark enable = 0; static GQuark disable = 0;
すぐ下の初期化部分に
enable = g_quark_from_static_string ("enable"); disable = g_quark_from_static_string ("disable");
イベント分岐を追加(l.1909あたり)
if (event == enable){ if(!bus_input_context_is_enabled(context)){ bus_input_context_enable (context); } return TRUE; } if (event == disable){ if(bus_input_context_is_enabled(context)){ bus_input_context_disable (context); } return TRUE; }
/ibus/common.py
定数?を追加。(追加結果:)
"CONFIG_GENERAL_SHORTCUT_TRIGGER", "CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE", "CONFIG_GENERAL_SHORTCUT_PREV_ENGINE", "CONFIG_GENERAL_SHORTCUT_ENABLE", "CONFIG_GENERAL_SHORTCUT_DISABLE", "CONFIG_GENERAL_SHORTCUT_TRIGGER_DEFAULT", "CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE_DEFAULT", "CONFIG_GENERAL_SHORTCUT_PREV_ENGINE_DEFAULT", "CONFIG_GENERAL_SHORTCUT_ENABLE_DEFAULT", "CONFIG_GENERAL_SHORTCUT_DISABLE_
(l.160)あたりのマッピングに追加
CONFIG_GENERAL_SHORTCUT_ENABLE = "/general/keyboard_shortcut_enable" CONFIG_GENERAL_SHORTCUT_ENABLE_DEFAULT = [] CONFIG_GENERAL_SHORTCUT_DISABLE = "/general/keyboard_shortcut_disable" CONFIG_GENERAL_SHORTCUT_DISABLE_DEFAULT = []
/setup/main.py
l.120あたり、ボタン設定に次を追加。
# enable shortcuts = self.__config.get_value( "general/hotkey", "enable", 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", entry)
# disable shortcuts = self.__config.get_value( "general/hotkey", "disable", 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", entry)
/setup/setup.ui
(l.99)のtableの行数を増やす
<object class="GtkTable" id="table1"> <property name="visible">True</property> <property name="n_rows">6</property> <- 3から6に増加 <property name="n_columns">2</property> <property name="column_spacing">12</property> <property name="row_spacing">6</property>
PreviousButton用のラベルであるlabel9の次(l.157)に、enableとdisable用のラベルを追記。
PreviousButton用の選択部分であるhbox6の次にenableとdisable用のメニュー内容を追記するが、あまりにながくて煩雑なので、setup.ui全体を貼るに留める。
変更箇所はidの最後の数字、表示する文字列、top_attachとbottom_attachの値。
setup.ui