ibus-m17n/ibus-m17n-HEAD.patch

319 lines
11 KiB
Diff
Raw Normal View History

2010-11-05 02:42:24 +00:00
diff --git a/codereview.settings b/codereview.settings
new file mode 100644
index 0000000..71ecbee
--- /dev/null
+++ b/codereview.settings
@@ -0,0 +1,2 @@
+# This file is used by "git cl" to get code review information.
+CODE_REVIEW_SERVER: codereview.appspot.com
2010-10-14 03:30:14 +00:00
diff --git a/src/engine.c b/src/engine.c
2010-11-05 02:42:24 +00:00
index 260a806..1dbcf34 100644
2010-10-14 03:30:14 +00:00
--- a/src/engine.c
+++ b/src/engine.c
2010-11-05 02:42:24 +00:00
@@ -149,6 +149,7 @@ ibus_m17n_engine_class_init (IBusM17NEngineClass *klass)
engine_class->cursor_down = ibus_m17n_engine_cursor_down;
engine_class->property_activate = ibus_m17n_engine_property_activate;
+
}
static void
@@ -279,7 +280,10 @@ ibus_m17n_engine_constructor (GType type,
mplist_put (im->driver.callback_list, Minput_candidates_done, ibus_m17n_engine_callback);
mplist_put (im->driver.callback_list, Minput_set_spot, ibus_m17n_engine_callback);
mplist_put (im->driver.callback_list, Minput_toggle, ibus_m17n_engine_callback);
- mplist_put (im->driver.callback_list, Minput_reset, ibus_m17n_engine_callback);
+ /*
+ Does not set reset callback, uses the default callback in m17n.
+ mplist_put (im->driver.callback_list, Minput_reset, ibus_m17n_engine_callback);
+ */
mplist_put (im->driver.callback_list, Minput_get_surrounding_text, ibus_m17n_engine_callback);
mplist_put (im->driver.callback_list, Minput_delete_surrounding_text, ibus_m17n_engine_callback);
@@ -294,8 +298,7 @@ ibus_m17n_engine_constructor (GType type,
return NULL;
}
- m17n->context = minput_create_ic (im, NULL);
- mplist_add (m17n->context->plist, msymbol ("IBusEngine"), m17n);
+ m17n->context = minput_create_ic (im, m17n);
m17n->config_section = g_strdup_printf ("engine/M17N/%s/%s",
lang, name);
@@ -421,9 +424,9 @@ ibus_m17n_engine_commit_string (IBusM17NEngine *m17n,
2010-10-14 03:30:14 +00:00
ibus_m17n_engine_update_preedit (m17n);
}
-/* Note on AltGr handling: While currently we expect AltGr == mod5, it
- would be better to not expect the modifier always be assigned
- to particular modX. However, it needs some code like:
+/* Note on AltGr (Level3 Shift) handling: While currently we expect
+ AltGr == mod5, it would be better to not expect the modifier always
+ be assigned to particular modX. However, it needs some code like:
KeyCode altgr = XKeysymToKeycode (display, XK_ISO_Level3_Shift);
XModifierKeymap *mods = XGetModifierMapping (display);
2010-11-05 02:42:24 +00:00
@@ -445,20 +448,26 @@ ibus_m17n_key_event_to_symbol (guint keycode,
2010-10-14 03:30:14 +00:00
MSymbol mkeysym = Mnil;
guint mask = 0;
IBusKeymap *keymap;
- guint base_keyval;
if (keyval >= IBUS_Shift_L && keyval <= IBUS_Hyper_R) {
return Mnil;
}
- keymap = ibus_keymap_get ("us");
- base_keyval = ibus_keymap_lookup_keysym (keymap, keycode, 0);
- g_object_unref (keymap);
+ /* Here, keyval is already translated by IBUS_MOD5_MASK. Obtain
+ the untranslated keyval from the underlying keymap and
+ represent the translated keyval as the form "G-<untranslated
+ keyval>", which m17n-lib accepts. */
+ if (modifiers & IBUS_MOD5_MASK) {
+ keymap = ibus_keymap_get ("us");
+ keyval = ibus_keymap_lookup_keysym (keymap, keycode,
+ modifiers & ~IBUS_MOD5_MASK);
+ g_object_unref (keymap);
+ }
keysym = g_string_new ("");
- if (base_keyval >= IBUS_space && base_keyval <= IBUS_asciitilde) {
- gint c = (modifiers & IBUS_MOD5_MASK) ? base_keyval : keyval;
+ if (keyval >= IBUS_space && keyval <= IBUS_asciitilde) {
+ gint c = keyval;
if (keyval == IBUS_space && modifiers & IBUS_SHIFT_MASK)
mask |= IBUS_SHIFT_MASK;
2010-11-05 02:42:24 +00:00
@@ -572,7 +581,7 @@ ibus_m17n_engine_focus_in (IBusEngine *engine)
IBusM17NEngine *m17n = (IBusM17NEngine *) engine;
ibus_engine_register_properties (engine, m17n->prop_list);
- ibus_m17n_engine_process_key (m17n, msymbol ("input-focus-in"));
+ ibus_m17n_engine_process_key (m17n, Minput_focus_in);
parent_class->focus_in (engine);
}
@@ -582,7 +591,7 @@ ibus_m17n_engine_focus_out (IBusEngine *engine)
{
IBusM17NEngine *m17n = (IBusM17NEngine *) engine;
- ibus_m17n_engine_process_key (m17n, msymbol ("input-focus-out"));
+ ibus_m17n_engine_process_key (m17n, Minput_focus_out);
parent_class->focus_out (engine);
}
@@ -593,7 +602,8 @@ ibus_m17n_engine_reset (IBusEngine *engine)
IBusM17NEngine *m17n = (IBusM17NEngine *) engine;
parent_class->reset (engine);
- ibus_m17n_engine_focus_in (engine);
+
+ minput_reset_ic (m17n->context);
}
static void
@@ -676,7 +686,7 @@ ibus_m17n_engine_property_activate (IBusEngine *engine,
static void
ibus_m17n_engine_update_lookup_table (IBusM17NEngine *m17n)
{
- ibus_lookup_table_clear (m17n->table);
+ ibus_lookup_table_clear (m17n->table);
if (m17n->context->candidate_list && m17n->context->candidate_show) {
IBusText *text;
@@ -752,15 +762,14 @@ ibus_m17n_engine_callback (MInputContext *context,
MSymbol command)
{
IBusM17NEngine *m17n = NULL;
- MPlist *p = NULL;
- p = mplist_find_by_key (context->plist, msymbol ("IBusEngine"));
- if (p) {
- m17n = (IBusM17NEngine *) mplist_value (p);
- }
+ m17n = context->arg;
+ g_return_if_fail (m17n != NULL);
- if (m17n == NULL) {
- return;
+ /* the callback may be called in minput_create_ic, in the time
+ * m17n->context has not be assigned, so need assign it. */
+ if (m17n->context == NULL) {
+ m17n->context = context;
}
if (command == Minput_preedit_start) {
2010-10-14 03:30:14 +00:00
diff --git a/src/m17nutil.c b/src/m17nutil.c
index ae0fe56..22b9fe1 100644
--- a/src/m17nutil.c
+++ b/src/m17nutil.c
@@ -7,37 +7,60 @@
static MConverter *utf8_converter = NULL;
-static const gchar *keymap[] = {
- "m17n:as:phonetic",
- "m17n:bn:inscript",
- "m17n:gu:inscript",
- "m17n:hi:inscript",
- "m17n:kn:kgp",
- "m17n:ks:kbd",
- "m17n:mai:inscript",
- "m17n:ml:inscript",
- "m17n:mr:inscript",
- "m17n:ne:rom",
- "m17n:or:inscript",
- "m17n:pa:inscript",
- "m17n:sa:harvard-kyoto",
- "m17n:sd:inscript",
- "m17n:si:wijesekera",
- "m17n:ta:tamil99",
- "m17n:te:inscript"
-};
-
-static const gchar *preedit_highlight[] = {
- "m17n:ja:anthy",
- "m17n:zh:cangjie",
- "m17n:zh:py-b5",
- "m17n:zh:py-gb",
- "m17n:zh:py",
- "m17n:zh:quick",
- "m17n:zh:tonepy-b5",
- "m17n:zh:tonepy-gb",
- "m17n:zh:tonepy",
- "m17n:zh:util",
+static const struct {
+ const gchar *name;
+ gint rank; /* engine rank (default 0) */
+ gboolean preedit_highlight; /* whether to highlight preedit (default 0) */
+} engine_config[] = {
+ /* Indic engines which represent languages. */
+ {"m17n:as:phonetic", 2, FALSE},
+ {"m17n:bn:inscript", 2, FALSE},
+ {"m17n:gu:inscript", 2, FALSE},
+ {"m17n:hi:inscript", 2, FALSE},
+ {"m17n:kn:kgp", 2, FALSE},
+ {"m17n:ks:kbd", 2, FALSE},
+ {"m17n:mai:inscript", 2, FALSE},
+ {"m17n:ml:inscript", 2, FALSE},
+ {"m17n:mr:inscript", 2, FALSE},
+ {"m17n:ne:rom", 2, FALSE},
+ {"m17n:or:inscript", 2, FALSE},
+ {"m17n:pa:inscript", 2, FALSE},
+ {"m17n:sa:harvard-kyoto", 2, FALSE},
+ {"m17n:sd:inscript", 2, FALSE},
+ {"m17n:si:wijesekera", 2, FALSE},
+ {"m17n:ta:tamil99", 2, FALSE},
+ {"m17n:te:inscript", 2, FALSE},
+ /* Other Indic engines should be selected by default:
+ https://bugzilla.redhat.com/show_bug.cgi?id=640896
+ */
+ {"m17n:as:*", 1, FALSE},
+ {"m17n:bn:*", 1, FALSE},
+ {"m17n:gu:*", 1, FALSE},
+ {"m17n:hi:*", 1, FALSE},
+ {"m17n:kn:*", 1, FALSE},
+ {"m17n:ks:*", 1, FALSE},
+ {"m17n:mai:*", 1, FALSE},
+ {"m17n:ml:*", 1, FALSE},
+ {"m17n:mr:*", 1, FALSE},
+ {"m17n:ne:*", 1, FALSE},
+ {"m17n:or:*", 1, FALSE},
+ {"m17n:pa:*", 1, FALSE},
+ {"m17n:sa:*", 1, FALSE},
+ {"m17n:sd:*", 1, FALSE},
+ {"m17n:si:*", 1, FALSE},
+ {"m17n:ta:*", 1, FALSE},
+ {"m17n:te:*", 1, FALSE},
+ /* Chinese and Japanese engines which require preedit decoration. */
+ {"m17n:ja:anthy", 0, TRUE},
+ {"m17n:zh:cangjie", 0, TRUE},
+ {"m17n:zh:py-b5", 0, TRUE},
+ {"m17n:zh:py-gb", 0, TRUE},
+ {"m17n:zh:py", 0, TRUE},
+ {"m17n:zh:quick", 0, TRUE},
+ {"m17n:zh:tonepy-b5", 0, TRUE},
+ {"m17n:zh:tonepy-gb", 0, TRUE},
+ {"m17n:zh:tonepy", 0, TRUE},
+ {"m17n:zh:util", 0, TRUE}
};
void
@@ -101,11 +124,16 @@ guint
ibus_m17n_parse_color (const gchar *hex)
{
guint color;
- if (hex && *hex == '#' &&
- ((color = strtoul (&hex[1], NULL, 16)) != ULONG_MAX ||
- errno != ERANGE))
- return color;
- return (guint)-1;
+
+ if (!hex || *hex != '#')
+ return (guint)-1;
+
+ errno = 0;
+ color = strtoul (&hex[1], NULL, 16);
+ if ((errno == ERANGE && color == ULONG_MAX)
+ || (errno != 0 && color == 0))
+ return (guint)-1;
+ return color;
}
static IBusEngineDesc *
@@ -141,10 +169,10 @@ ibus_m17n_engine_new (MSymbol lang,
/* set default rank to 0 */
engine->rank = 0;
- for (i = 0; i < G_N_ELEMENTS(keymap); i++) {
- if (strcmp (engine_name, keymap[i]) == 0) {
+ for (i = 0; i < G_N_ELEMENTS(engine_config); i++) {
+ if (g_pattern_match_simple (engine_config[i].name, engine_name)) {
/* set rank of default keymap to 1 */
- engine->rank = 1;
+ engine->rank = engine_config[i].rank;
break;
}
}
@@ -271,9 +299,9 @@ ibus_m17n_preedit_highlight (const gchar *engine_name)
{
gint i;
- for (i = 0; i < G_N_ELEMENTS(preedit_highlight); i++) {
- if (strcmp (engine_name, preedit_highlight[i]) == 0)
- return TRUE;
+ for (i = 0; i < G_N_ELEMENTS(engine_config); i++) {
+ if (g_pattern_match_simple (engine_config[i].name, engine_name))
+ return engine_config[i].preedit_highlight;
}
return FALSE;
}
2010-11-05 02:42:24 +00:00
diff --git a/src/main.c b/src/main.c
index b8d7c72..514d971 100644
--- a/src/main.c
+++ b/src/main.c
@@ -74,8 +74,7 @@ print_engines_xml (void)
ibus_init ();
- bus = ibus_bus_new ();
- ibus_m17n_init (bus);
+ ibus_m17n_init_common ();
component = ibus_m17n_get_component ();
output = g_string_new ("");
2010-10-14 03:30:14 +00:00
diff --git a/src/setup.c b/src/setup.c
index 7442159..0fe6e1b 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -83,6 +83,7 @@ parse_value (MPlist *plist, gchar *text)
if (mplist_key (plist) == Minteger) {
long val;
+ errno = 0;
val = strtol (text, NULL, 10);
if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))
|| (errno != 0 && val == 0))