Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: bus/ibusimpl.c

Issue 1702015: Support engine specific hotkey. (Closed) Base URL: ssh://git@chromiumos-git/ibus.git
Patch Set: Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « bus/ibusimpl.h ('k') | ibus/component.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* vim:set et sts=4: */ 1 /* vim:set et sts=4: */
2 /* ibus - The Input Bus 2 /* ibus - The Input Bus
3 * Copyright (C) 2008-2010 Peng Huang <shawn.p.huang@gmail.com> 3 * Copyright (C) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
4 * Copyright (C) 2008-2010 Red Hat, Inc. 4 * Copyright (C) 2008-2010 Red Hat, Inc.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public 7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 static void bus_ibus_impl_set_global_engine (BusIBusImpl *ibus, 81 static void bus_ibus_impl_set_global_engine (BusIBusImpl *ibus,
82 BusEngineProxy *engine); 82 BusEngineProxy *engine);
83 83
84 static void bus_ibus_impl_registry_changed (BusIBusImpl *ibus); 84 static void bus_ibus_impl_registry_changed (BusIBusImpl *ibus);
85 static void bus_ibus_impl_global_engine_changed 85 static void bus_ibus_impl_global_engine_changed
86 (BusIBusImpl *ibus); 86 (BusIBusImpl *ibus);
87 87
88 static void _factory_destroy_cb (BusFactoryProxy *factory, 88 static void _factory_destroy_cb (BusFactoryProxy *factory,
89 BusIBusImpl *ibus); 89 BusIBusImpl *ibus);
90 90
91 static void bus_ibus_impl_set_context_engine_from_desc
92 (BusIBusImpl *ibus,
93 BusInputContext *context,
94 IBusEngineDesc *engine_desc );
91 static void bus_ibus_impl_set_context_engine(BusIBusImpl *ibus, 95 static void bus_ibus_impl_set_context_engine(BusIBusImpl *ibus,
92 BusInputContext *context, 96 BusInputContext *context,
93 BusEngineProxy *engine); 97 BusEngineProxy *engine);
94 98
95 static gchar *bus_ibus_impl_load_global_engine_name_from_config 99 static gchar *bus_ibus_impl_load_global_engine_name_from_config
96 (BusIBusImpl *ibus); 100 (BusIBusImpl *ibus);
97 static void bus_ibus_impl_save_global_engine_name_to_config 101 static void bus_ibus_impl_save_global_engine_name_to_config
98 (BusIBusImpl *ibus); 102 (BusIBusImpl *ibus);
99 103
100 static gchar *bus_ibus_impl_load_global_previous_engine_name_from_config 104 static gchar *bus_ibus_impl_load_global_previous_engine_name_from_config
101 (BusIBusImpl *ibus); 105 (BusIBusImpl *ibus);
102 static void bus_ibus_impl_save_global_previous_engine_name_to_config 106 static void bus_ibus_impl_save_global_previous_engine_name_to_config
103 (BusIBusImpl *ibus); 107 (BusIBusImpl *ibus);
108 static void bus_ibus_impl_update_engines_hotkey_profile
109 (BusIBusImpl *ibus);
104 110
105 G_DEFINE_TYPE(BusIBusImpl, bus_ibus_impl, IBUS_TYPE_SERVICE) 111 G_DEFINE_TYPE(BusIBusImpl, bus_ibus_impl, IBUS_TYPE_SERVICE)
106 112
107 BusIBusImpl * 113 BusIBusImpl *
108 bus_ibus_impl_get_default (void) 114 bus_ibus_impl_get_default (void)
109 { 115 {
110 static BusIBusImpl *ibus = NULL; 116 static BusIBusImpl *ibus = NULL;
111 117
112 if (ibus == NULL) { 118 if (ibus == NULL) {
113 ibus = (BusIBusImpl *) g_object_new (BUS_TYPE_IBUS_IMPL, 119 ibus = (BusIBusImpl *) g_object_new (BUS_TYPE_IBUS_IMPL,
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 ibus->engine_list = engine_list; 247 ibus->engine_list = engine_list;
242 248
243 if (ibus->engine_list) { 249 if (ibus->engine_list) {
244 IBusComponent *component; 250 IBusComponent *component;
245 251
246 component = ibus_component_get_from_engine ((IBusEngineDesc *) ibus->eng ine_list->data); 252 component = ibus_component_get_from_engine ((IBusEngineDesc *) ibus->eng ine_list->data);
247 if (component && !ibus_component_is_running (component)) { 253 if (component && !ibus_component_is_running (component)) {
248 ibus_component_start (component, g_verbose); 254 ibus_component_start (component, g_verbose);
249 } 255 }
250 } 256 }
257
258 bus_ibus_impl_update_engines_hotkey_profile (ibus);
251 } 259 }
252 260
253 static void 261 static void
254 bus_ibus_impl_set_use_sys_layout (BusIBusImpl *ibus, 262 bus_ibus_impl_set_use_sys_layout (BusIBusImpl *ibus,
255 GValue *value) 263 GValue *value)
256 { 264 {
257 if (value != NULL && G_VALUE_TYPE (value) == G_TYPE_BOOLEAN) { 265 if (value != NULL && G_VALUE_TYPE (value) == G_TYPE_BOOLEAN) {
258 ibus->use_sys_layout = g_value_get_boolean (value); 266 ibus->use_sys_layout = g_value_get_boolean (value);
259 } 267 }
260 } 268 }
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 ibus->hotkey_profile = ibus_hotkey_profile_new (); 607 ibus->hotkey_profile = ibus_hotkey_profile_new ();
600 ibus->keymap = ibus_keymap_get ("us"); 608 ibus->keymap = ibus_keymap_get ("us");
601 609
602 ibus->use_sys_layout = FALSE; 610 ibus->use_sys_layout = FALSE;
603 ibus->embed_preedit_text = TRUE; 611 ibus->embed_preedit_text = TRUE;
604 ibus->enable_by_default = FALSE; 612 ibus->enable_by_default = FALSE;
605 ibus->use_global_engine = FALSE; 613 ibus->use_global_engine = FALSE;
606 ibus->global_engine = NULL; 614 ibus->global_engine = NULL;
607 ibus->global_previous_engine_name = NULL; 615 ibus->global_previous_engine_name = NULL;
608 616
617 ibus->engines_hotkey_profile = NULL;
618 ibus->hotkey_to_engines_map = NULL;
619
609 bus_ibus_impl_reload_config (ibus); 620 bus_ibus_impl_reload_config (ibus);
610 621
611 g_signal_connect (BUS_DEFAULT_DBUS, 622 g_signal_connect (BUS_DEFAULT_DBUS,
612 "name-owner-changed", 623 "name-owner-changed",
613 G_CALLBACK (_dbus_name_owner_changed_cb), 624 G_CALLBACK (_dbus_name_owner_changed_cb),
614 ibus); 625 ibus);
615 } 626 }
616 627
617 static void 628 static void
618 bus_ibus_impl_destroy (BusIBusImpl *ibus) 629 bus_ibus_impl_destroy (BusIBusImpl *ibus)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 ibus->keymap = NULL; 686 ibus->keymap = NULL;
676 } 687 }
677 688
678 if (ibus->global_engine) { 689 if (ibus->global_engine) {
679 g_object_unref (ibus->global_engine); 690 g_object_unref (ibus->global_engine);
680 ibus->global_engine = NULL; 691 ibus->global_engine = NULL;
681 } 692 }
682 693
683 g_free (ibus->global_previous_engine_name); 694 g_free (ibus->global_previous_engine_name);
684 695
696 if (ibus->engines_hotkey_profile != NULL) {
697 g_object_unref (ibus->engines_hotkey_profile);
698 ibus->engines_hotkey_profile = NULL;
699 }
700
701 if (ibus->hotkey_to_engines_map) {
702 g_hash_table_unref (ibus->hotkey_to_engines_map);
703 ibus->hotkey_to_engines_map = NULL;
704 }
705
685 bus_server_quit (BUS_DEFAULT_SERVER); 706 bus_server_quit (BUS_DEFAULT_SERVER);
686 ibus_object_destroy ((IBusObject *) BUS_DEFAULT_SERVER); 707 ibus_object_destroy ((IBusObject *) BUS_DEFAULT_SERVER);
687 IBUS_OBJECT_CLASS(bus_ibus_impl_parent_class)->destroy (IBUS_OBJECT (ibus)); 708 IBUS_OBJECT_CLASS(bus_ibus_impl_parent_class)->destroy (IBUS_OBJECT (ibus));
688 } 709 }
689 710
690 /* introspectable interface */ 711 /* introspectable interface */
691 static IBusMessage * 712 static IBusMessage *
692 _ibus_introspect (BusIBusImpl *ibus, 713 _ibus_introspect (BusIBusImpl *ibus,
693 IBusMessage *message, 714 IBusMessage *message,
694 BusConnection *connection) 715 BusConnection *connection)
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 else if (ibus->engine_list) { 905 else if (ibus->engine_list) {
885 engine_desc = (IBusEngineDesc *)ibus->engine_list->data; 906 engine_desc = (IBusEngineDesc *)ibus->engine_list->data;
886 } 907 }
887 } 908 }
888 } 909 }
889 else { 910 else {
890 /* request engine by name */ 911 /* request engine by name */
891 engine_desc = _find_engine_desc_by_name (ibus, engine_name); 912 engine_desc = _find_engine_desc_by_name (ibus, engine_name);
892 } 913 }
893 914
894 if (engine_desc != NULL) { 915 bus_ibus_impl_set_context_engine_from_desc (ibus, context, engine_desc);
895 engine = bus_ibus_impl_create_engine (engine_desc);
896 if (engine != NULL) {
897 bus_ibus_impl_set_context_engine (ibus, context, engine);
898 }
899 }
900 } 916 }
901 917
902 static void 918 static void
903 bus_ibus_impl_context_request_next_engine_in_menu (BusIBusImpl *ibus, 919 bus_ibus_impl_context_request_next_engine_in_menu (BusIBusImpl *ibus,
904 BusInputContext *context) 920 BusInputContext *context)
905 { 921 {
906 BusEngineProxy *engine; 922 BusEngineProxy *engine;
907 IBusEngineDesc *desc; 923 IBusEngineDesc *desc;
908 IBusEngineDesc *next_desc = NULL; 924 IBusEngineDesc *next_desc = NULL;
909 GList *p; 925 GList *p;
(...skipping 22 matching lines...) Expand all
932 } 948 }
933 else { 949 else {
934 if (ibus->register_engine_list) { 950 if (ibus->register_engine_list) {
935 next_desc = (IBusEngineDesc *)ibus->register_engine_list->data; 951 next_desc = (IBusEngineDesc *)ibus->register_engine_list->data;
936 } 952 }
937 else if (ibus->engine_list) { 953 else if (ibus->engine_list) {
938 next_desc = (IBusEngineDesc *)ibus->engine_list->data; 954 next_desc = (IBusEngineDesc *)ibus->engine_list->data;
939 } 955 }
940 } 956 }
941 957
942 if (next_desc != NULL) { 958 bus_ibus_impl_set_context_engine_from_desc (ibus, context, next_desc);
943 engine = bus_ibus_impl_create_engine (next_desc);
944 if (engine != NULL) {
945 bus_ibus_impl_set_context_engine (ibus, context, engine);
946 }
947 }
948 } 959 }
949 960
950 static void 961 static void
951 bus_ibus_impl_context_request_previous_engine (BusIBusImpl *ibus, 962 bus_ibus_impl_context_request_previous_engine (BusIBusImpl *ibus,
952 BusInputContext *context) 963 BusInputContext *context)
953 { 964 {
954 gchar *engine_name = NULL; 965 gchar *engine_name = NULL;
955 if (!ibus->use_global_engine) { 966 if (!ibus->use_global_engine) {
956 engine_name = (gchar *) g_object_get_data (G_OBJECT (context), "previous -engine-name"); 967 engine_name = (gchar *) g_object_get_data (G_OBJECT (context), "previous -engine-name");
957 } 968 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 g_signal_connect (ibus->global_engine, "destroy", 1017 g_signal_connect (ibus->global_engine, "destroy",
1007 G_CALLBACK (_global_engine_destroy_cb), ibus); 1018 G_CALLBACK (_global_engine_destroy_cb), ibus);
1008 } 1019 }
1009 1020
1010 bus_ibus_impl_save_global_engine_name_to_config (ibus); 1021 bus_ibus_impl_save_global_engine_name_to_config (ibus);
1011 bus_ibus_impl_save_global_previous_engine_name_to_config (ibus); 1022 bus_ibus_impl_save_global_previous_engine_name_to_config (ibus);
1012 bus_ibus_impl_global_engine_changed (ibus); 1023 bus_ibus_impl_global_engine_changed (ibus);
1013 } 1024 }
1014 1025
1015 static void 1026 static void
1027 bus_ibus_impl_set_context_engine_from_desc (BusIBusImpl *ibus,
1028 BusInputContext *context,
1029 IBusEngineDesc *engine_desc)
1030 {
1031 if (engine_desc != NULL) {
1032 BusEngineProxy *engine = bus_ibus_impl_create_engine (engine_desc);
1033 if (engine != NULL) {
1034 bus_ibus_impl_set_context_engine (ibus, context, engine);
1035 }
1036 }
1037 }
1038
1039 static void
1016 bus_ibus_impl_set_context_engine (BusIBusImpl *ibus, 1040 bus_ibus_impl_set_context_engine (BusIBusImpl *ibus,
1017 BusInputContext *context, 1041 BusInputContext *context,
1018 BusEngineProxy *engine) { 1042 BusEngineProxy *engine) {
1019 g_object_set_data (G_OBJECT (context), "previous-engine-name", NULL); 1043 g_object_set_data (G_OBJECT (context), "previous-engine-name", NULL);
1020 1044
1021 /* If use_global_engine is disabled, then we need to save the previous engine 1045 /* If use_global_engine is disabled, then we need to save the previous engine
1022 * of each input context. */ 1046 * of each input context. */
1023 if (!ibus->use_global_engine) { 1047 if (!ibus->use_global_engine) {
1024 BusEngineProxy *previous_engine = bus_input_context_get_engine (context); 1048 BusEngineProxy *previous_engine = bus_input_context_get_engine (context);
1025 if (previous_engine) { 1049 if (previous_engine) {
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1278 for (; p != NULL; p = p->next) { 1302 for (; p != NULL; p = p->next) {
1279 if (g_list_find (ibus->register_engine_list, p->data)) { 1303 if (g_list_find (ibus->register_engine_list, p->data)) {
1280 ibus->register_engine_list = g_list_remove (ibus->register_engin e_list, p->data); 1304 ibus->register_engine_list = g_list_remove (ibus->register_engin e_list, p->data);
1281 g_object_unref (p->data); 1305 g_object_unref (p->data);
1282 } 1306 }
1283 } 1307 }
1284 g_list_free (engines); 1308 g_list_free (engines);
1285 } 1309 }
1286 1310
1287 g_object_unref (factory); 1311 g_object_unref (factory);
1312
1313 bus_ibus_impl_update_engines_hotkey_profile (ibus);
1288 } 1314 }
1289 1315
1290 static void 1316 static void
1291 bus_ibus_impl_add_factory (BusIBusImpl *ibus, 1317 bus_ibus_impl_add_factory (BusIBusImpl *ibus,
1292 BusFactoryProxy *factory) 1318 BusFactoryProxy *factory)
1293 { 1319 {
1294 g_assert (BUS_IS_IBUS_IMPL (ibus)); 1320 g_assert (BUS_IS_IBUS_IMPL (ibus));
1295 g_assert (BUS_IS_FACTORY_PROXY (factory)); 1321 g_assert (BUS_IS_FACTORY_PROXY (factory));
1296 1322
1297 g_object_ref_sink (factory); 1323 g_object_ref_sink (factory);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 } 1363 }
1338 1364
1339 bus_ibus_impl_add_factory (ibus, factory); 1365 bus_ibus_impl_add_factory (ibus, factory);
1340 1366
1341 engines = ibus_component_get_engines (component); 1367 engines = ibus_component_get_engines (component);
1342 1368
1343 g_list_foreach (engines, (GFunc) g_object_ref, NULL); 1369 g_list_foreach (engines, (GFunc) g_object_ref, NULL);
1344 ibus->register_engine_list = g_list_concat (ibus->register_engine_list, engi nes); 1370 ibus->register_engine_list = g_list_concat (ibus->register_engine_list, engi nes);
1345 g_object_unref (component); 1371 g_object_unref (component);
1346 1372
1373 bus_ibus_impl_update_engines_hotkey_profile (ibus);
1374
1347 reply = ibus_message_new_method_return (message); 1375 reply = ibus_message_new_method_return (message);
1348 return reply; 1376 return reply;
1349 } 1377 }
1350 1378
1351 static IBusMessage * 1379 static IBusMessage *
1352 _ibus_list_engines (BusIBusImpl *ibus, 1380 _ibus_list_engines (BusIBusImpl *ibus,
1353 IBusMessage *message, 1381 IBusMessage *message,
1354 BusConnection *connection) 1382 BusConnection *connection)
1355 { 1383 {
1356 IBusMessage *reply; 1384 IBusMessage *reply;
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
1774 BusInputContext *context, 1802 BusInputContext *context,
1775 guint keyval, 1803 guint keyval,
1776 guint modifiers, 1804 guint modifiers,
1777 guint prev_keyval, 1805 guint prev_keyval,
1778 guint prev_modifiers) 1806 guint prev_modifiers)
1779 { 1807 {
1780 static GQuark trigger = 0; 1808 static GQuark trigger = 0;
1781 static GQuark next = 0; 1809 static GQuark next = 0;
1782 static GQuark previous = 0; 1810 static GQuark previous = 0;
1783 1811
1812 GQuark event;
1813 GList *engine_list;
1814
1784 if (trigger == 0) { 1815 if (trigger == 0) {
1785 trigger = g_quark_from_static_string ("trigger"); 1816 trigger = g_quark_from_static_string ("trigger");
1786 next = g_quark_from_static_string ("next-engine-in-menu"); 1817 next = g_quark_from_static_string ("next-engine-in-menu");
1787 previous = g_quark_from_static_string ("previous-engine"); 1818 previous = g_quark_from_static_string ("previous-engine");
1788 } 1819 }
1789 1820
1790 GQuark event = ibus_hotkey_profile_filter_key_event (ibus->hotkey_profile, 1821 /* Try global hotkeys first. */
1791 keyval, 1822 event = ibus_hotkey_profile_filter_key_event (ibus->hotkey_profile,
1792 modifiers, 1823 keyval,
1793 prev_keyval, 1824 modifiers,
1794 prev_modifiers, 1825 prev_keyval,
1795 0); 1826 prev_modifiers,
1827 0);
1796 1828
1797 if (event == trigger) { 1829 if (event == trigger) {
1798 gboolean enabled = bus_input_context_is_enabled (context); 1830 gboolean enabled = bus_input_context_is_enabled (context);
1799 if (enabled) { 1831 if (enabled) {
1800 bus_input_context_disable (context); 1832 bus_input_context_disable (context);
1801 } 1833 }
1802 else { 1834 else {
1803 bus_input_context_enable (context); 1835 bus_input_context_enable (context);
1804 } 1836 }
1805 return (enabled != bus_input_context_is_enabled (context)); 1837 return (enabled != bus_input_context_is_enabled (context));
1806 } 1838 }
1807 if (event == next) { 1839 if (event == next) {
1808 if (bus_input_context_is_enabled(context)) { 1840 if (bus_input_context_is_enabled(context)) {
1809 bus_ibus_impl_context_request_next_engine_in_menu (ibus, context); 1841 bus_ibus_impl_context_request_next_engine_in_menu (ibus, context);
1810 } 1842 }
1811 else { 1843 else {
1812 bus_input_context_enable (context); 1844 bus_input_context_enable (context);
1813 } 1845 }
1814 return TRUE; 1846 return TRUE;
1815 } 1847 }
1816 if (event == previous) { 1848 if (event == previous) {
1817 if (bus_input_context_is_enabled(context)) { 1849 if (bus_input_context_is_enabled(context)) {
1818 bus_ibus_impl_context_request_previous_engine (ibus, context); 1850 bus_ibus_impl_context_request_previous_engine (ibus, context);
1819 } 1851 }
1820 else { 1852 else {
1821 bus_input_context_enable (context); 1853 bus_input_context_enable (context);
1822 } 1854 }
1823 return TRUE; 1855 return TRUE;
1824 } 1856 }
1857
1858 if (!ibus->engines_hotkey_profile || !ibus->hotkey_to_engines_map) {
1859 return FALSE;
1860 }
1861
1862 /* Then try engines hotkeys. */
1863 event = ibus_hotkey_profile_filter_key_event (ibus->engines_hotkey_profile,
1864 keyval,
1865 modifiers,
1866 prev_keyval,
1867 prev_modifiers,
1868 0);
1869 if (event == 0) {
1870 return FALSE;
1871 }
1872
1873 engine_list = g_hash_table_lookup (ibus->hotkey_to_engines_map,
1874 GUINT_TO_POINTER (event));
1875 if (engine_list) {
1876 BusEngineProxy *current_engine = bus_input_context_get_engine (context);
1877 IBusEngineDesc *current_engine_desc =
1878 (current_engine ? bus_engine_proxy_get_desc (current_engine) : NULL) ;
1879 IBusEngineDesc *new_engine_desc = (IBusEngineDesc *) engine_list->data;
1880
1881 g_assert (new_engine_desc);
1882
1883 /* Find out what engine we should switch to. If the current engine has
1884 * the same hotkey, then we should switch to the next engine with the
1885 * same hotkey in the list. Otherwise, we just switch to the first
1886 * engine in the list. */
1887 GList *p = engine_list;
1888 for (; p->next != NULL; p = p->next) {
1889 if (current_engine_desc == (IBusEngineDesc *) p->data) {
1890 new_engine_desc = (IBusEngineDesc *) p->next->data;
1891 break;
1892 }
1893 }
1894
1895 if (current_engine_desc != new_engine_desc) {
1896 bus_ibus_impl_set_context_engine_from_desc (ibus, context, new_engin e_desc);
1897 return TRUE;
1898 }
1899 }
1900
1825 return FALSE; 1901 return FALSE;
1826 } 1902 }
1827 1903
1828 static gchar* 1904 static gchar*
1829 bus_ibus_impl_load_global_engine_name_from_config (BusIBusImpl *ibus) 1905 bus_ibus_impl_load_global_engine_name_from_config (BusIBusImpl *ibus)
1830 { 1906 {
1831 GValue value = { 0 }; 1907 GValue value = { 0 };
1832 gchar *global_engine_name = NULL; 1908 gchar *global_engine_name = NULL;
1833 1909
1834 g_assert (IBUS_IS_CONFIG (ibus->config)); 1910 g_assert (IBUS_IS_CONFIG (ibus->config));
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1881 1957
1882 if (ibus->use_global_engine && ibus->global_previous_engine_name) { 1958 if (ibus->use_global_engine && ibus->global_previous_engine_name) {
1883 GValue value = { 0 }; 1959 GValue value = { 0 };
1884 g_value_init (&value, G_TYPE_STRING); 1960 g_value_init (&value, G_TYPE_STRING);
1885 g_value_set_static_string (&value, ibus->global_previous_engine_name); 1961 g_value_set_static_string (&value, ibus->global_previous_engine_name);
1886 1962
1887 ibus_config_set_value (ibus->config, "general", "global_previous_engine" , &value); 1963 ibus_config_set_value (ibus->config, "general", "global_previous_engine" , &value);
1888 g_value_unset (&value); 1964 g_value_unset (&value);
1889 } 1965 }
1890 } 1966 }
1967
1968 static void
1969 _add_engine_hotkey (IBusEngineDesc *engine, BusIBusImpl *ibus)
1970 {
1971 gchar **hotkey_list;
1972 gchar **p;
1973 gchar *hotkey;
1974 GList *engine_list;
1975
1976 GQuark event;
1977 guint keyval;
1978 guint modifiers;
1979
1980 if (!engine || !engine->hotkeys || !*engine->hotkeys) {
1981 return;
1982 }
1983
1984 hotkey_list = g_strsplit_set (engine->hotkeys, ";,", 0);
1985
1986 for (p = hotkey_list; p && *p; ++p) {
1987 hotkey = g_strstrip (*p);
1988 if (!*hotkey || !ibus_key_event_from_string (hotkey, &keyval, &modifiers )) {
1989 continue;
1990 }
1991
1992 /* If the hotkey already exists, we won't need to add it again. */
1993 event = ibus_hotkey_profile_lookup_hotkey (ibus->engines_hotkey_profile,
1994 keyval, modifiers);
1995 if (event == 0) {
1996 event = g_quark_from_string (hotkey);
1997 ibus_hotkey_profile_add_hotkey (ibus->engines_hotkey_profile,
1998 keyval, modifiers, event);
1999 }
2000
2001 engine_list = g_hash_table_lookup (ibus->hotkey_to_engines_map,
2002 GUINT_TO_POINTER (event));
2003
2004 /* As we will rebuild the engines hotkey map whenever an engine was
2005 * added or removed, we don't need to hold a reference of the engine
2006 * here. */
2007 engine_list = g_list_append (engine_list, engine);
2008
2009 /* We need to steal the value before adding it back, otherwise it will
2010 * be destroyed. */
2011 g_hash_table_steal (ibus->hotkey_to_engines_map, GUINT_TO_POINTER (event ));
2012
2013 g_hash_table_insert (ibus->hotkey_to_engines_map,
2014 GUINT_TO_POINTER (event), engine_list);
2015 }
2016
2017 g_strfreev (hotkey_list);
2018 }
2019
2020 static void
2021 bus_ibus_impl_update_engines_hotkey_profile (BusIBusImpl *ibus)
2022 {
2023 if (ibus->engines_hotkey_profile) {
2024 g_object_unref (ibus->engines_hotkey_profile);
2025 }
2026
2027 if (ibus->hotkey_to_engines_map) {
2028 g_hash_table_unref (ibus->hotkey_to_engines_map);
2029 }
2030
2031 ibus->engines_hotkey_profile = ibus_hotkey_profile_new();
2032 ibus->hotkey_to_engines_map =
2033 g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) g_list_free);
2034
2035 g_list_foreach (ibus->register_engine_list, (GFunc) _add_engine_hotkey, ibus );
2036 g_list_foreach (ibus->engine_list, (GFunc) _add_engine_hotkey, ibus);
2037 }
OLDNEW
« no previous file with comments | « bus/ibusimpl.h ('k') | ibus/component.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698