static gboolean initable_init (GInitable *initable, GCancellable *cancellable, GError **error) { TransliteratorM17n *m17n = TRANSLITERATOR_M17N (initable); gchar *name, **strv; g_object_get (G_OBJECT (initable), "name", &name, NULL); strv = g_strsplit (name, "-", 2); g_return_val_if_fail (g_strv_length (strv) == 2, FALSE); m17n->im = minput_open_im (msymbol (strv[0]), msymbol (strv[1]), NULL); g_free (name); g_strfreev (strv); if (m17n->im) { m17n->ic = minput_create_ic (m17n->im, NULL); return TRUE; } g_set_error (error, TRANSLIT_ERROR, TRANSLIT_ERROR_LOAD_FAILED, "can't open m17n IM"); return FALSE; }
static GObject* ibus_m17n_engine_constructor (GType type, guint n_construct_params, GObjectConstructParam *construct_params) { IBusM17NEngine *m17n; GObjectClass *object_class; IBusM17NEngineClass *klass; m17n = (IBusM17NEngine *) G_OBJECT_CLASS (parent_class)->constructor (type, n_construct_params, construct_params); object_class = G_OBJECT_GET_CLASS (m17n); klass = (IBusM17NEngineClass *) object_class; if (klass->im == NULL) { const gchar *engine_name; gchar *lang = NULL, *name = NULL; engine_name = ibus_engine_get_name ((IBusEngine *) m17n); if (!ibus_m17n_scan_engine_name (engine_name, &lang, &name)) { g_free (lang); g_free (name); return NULL; } klass->im = minput_open_im (msymbol (lang), msymbol (name), NULL); g_free (lang); g_free (name); if (klass->im == NULL) { g_warning ("Can not find m17n keymap %s", engine_name); g_object_unref (m17n); return NULL; } mplist_put (klass->im->driver.callback_list, Minput_preedit_start, ibus_m17n_engine_callback); mplist_put (klass->im->driver.callback_list, Minput_preedit_draw, ibus_m17n_engine_callback); mplist_put (klass->im->driver.callback_list, Minput_preedit_done, ibus_m17n_engine_callback); mplist_put (klass->im->driver.callback_list, Minput_status_start, ibus_m17n_engine_callback); mplist_put (klass->im->driver.callback_list, Minput_status_draw, ibus_m17n_engine_callback); mplist_put (klass->im->driver.callback_list, Minput_status_done, ibus_m17n_engine_callback); mplist_put (klass->im->driver.callback_list, Minput_candidates_start, ibus_m17n_engine_callback); mplist_put (klass->im->driver.callback_list, Minput_candidates_draw, ibus_m17n_engine_callback); mplist_put (klass->im->driver.callback_list, Minput_candidates_done, ibus_m17n_engine_callback); mplist_put (klass->im->driver.callback_list, Minput_set_spot, ibus_m17n_engine_callback); mplist_put (klass->im->driver.callback_list, Minput_toggle, ibus_m17n_engine_callback); /* Does not set reset callback, uses the default callback in m17n. mplist_put (klass->im->driver.callback_list, Minput_reset, ibus_m17n_engine_callback); */ mplist_put (klass->im->driver.callback_list, Minput_get_surrounding_text, ibus_m17n_engine_callback); mplist_put (klass->im->driver.callback_list, Minput_delete_surrounding_text, ibus_m17n_engine_callback); } m17n->context = minput_create_ic (klass->im, m17n); return (GObject *) m17n; }
static MPlist * parse_m17n_value (MPlist *plist, gchar *text) { MPlist *value; if (mplist_key (plist) == Msymbol) { value = mplist (); mplist_add (value, Msymbol, msymbol (text)); return value; } if (mplist_key (plist) == Mtext) { MText *mtext; mtext = mtext_from_data (text, strlen (text), MTEXT_FORMAT_UTF_8); value = mplist (); mplist_add (value, Mtext, mtext); return value; } 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)) return NULL; value = mplist (); mplist_add (value, Minteger, (void *)val); return value; } return NULL; }
static uim_lisp init_m17nlib() { MPlist *imlist, *elm; M17N_INIT(); nr_input_methods = 0; nr_input_contexts = 0; im_array = NULL; ic_array = NULL; imlist = mdatabase_list(msymbol("input-method"), Mnil, Mnil, Mnil); if (!imlist) { /* maybe user forgot to install m17n-db */ return uim_scm_f(); } for (elm = imlist; mplist_key(elm) != Mnil; elm = mplist_next(elm)) { MDatabase *mdb; MSymbol *tag, lang, imname; uim_bool is_complete_im; mdb = mplist_value(elm); tag = mdatabase_tag(mdb); lang = tag[1]; imname = tag[2]; is_complete_im = (lang != Mnil && imname != Mnil); /* [uim-ja 30] */ if (is_complete_im) { /* pass NULL as IM to enable lazy instantiation */ pushback_input_method(NULL, msymbol_name(lang), msymbol_name(imname)); } } #if 0 register_callbacks(); #endif m17n_object_unref(imlist); converter = mconv_buffer_converter(msymbol("utf8"), NULL, 0); if (!converter) return uim_scm_f(); m17nlib_ok = 1; return uim_scm_t(); }
static void ibus_m17n_engine_page_up (IBusEngine *engine) { IBusM17NEngine *m17n = (IBusM17NEngine *) engine; ibus_m17n_engine_process_key (m17n, msymbol ("Up")); parent_class->page_up (engine); }
static void ibus_m17n_engine_cursor_down (IBusEngine *engine) { IBusM17NEngine *m17n = (IBusM17NEngine *) engine; ibus_m17n_engine_process_key (m17n, msymbol ("Right")); parent_class->cursor_down (engine); }
int m17n_known_code(const char *name){ if( m17n_lib_init() < 0 ){ return 0; } m17n_Init(); if( mconv_resolve_coding(msymbol(name)) ){ return 1; }else{ return 0; } }
int m17n_ccx_init(M17nCCX *m17n,const char *icode,const char *ocode){ m17n->m_Start = Time(); if( m17n_lib_init() < 0 ){ return -1; } LAP("dylib-done"); m17n_Init(); LAP("init-done"); if( icode == 0 ) icode = "utf-8"; if( (m17n->m_icode = mconv_resolve_coding(msymbol(icode))) == 0 ){ fprintf(stderr,"--M17N unknown code: %s\n",icode); return -2; } if( ocode == 0 ) ocode = "utf-8"; if( (m17n->m_ocode = mconv_resolve_coding(msymbol(ocode))) == 0 ){ fprintf(stderr,"--M17N unknown code: %s\n",ocode); return -3; } LAP("ccx-init-done"); return 0; }
int main() { MPlist *imlist, *elm; MSymbol utf8 = msymbol("utf8"); M17N_INIT(); imlist = mdatabase_list(msymbol("input-method"), Mnil, Mnil, Mnil); for (elm = imlist; elm && mplist_key(elm) != Mnil; elm = mplist_next(elm)) { MDatabase *mdb = (MDatabase *) mplist_value(elm); MSymbol *tag = mdatabase_tag(mdb); if (tag[1] != Mnil) { MInputMethod *im = minput_open_im(tag[1], tag[2], NULL); if (im) { std::cout << msymbol_name (im->language); std::cout << "-"; std::cout << msymbol_name (im->name); std::cout << "\n"; } } } M17N_FINI(); }
MPlist * init (MPlist *args) { MInputContext *ic = mplist_value (args); TableContext *context; fflush (stderr); if (! initialized++) { init_phrase_dict (); Mtable = msymbol (" table"); Mibus = msymbol ("ibus"); Mscim = msymbol ("scim"); } context = calloc (sizeof (TableContext), 1); context->ic = ic; context->converter = mconv_buffer_converter (Mcoding_utf_8, NULL, 0); if (context) mplist_push (ic->plist, Mtable, context); return NULL; }
static void nimf_m17n_open_im (NimfM17n *m17n) { g_debug (G_STRLOC ": %s", G_STRFUNC); gchar **strv; m17n->preedit = g_strdup (""); m17n->preedit_attrs[0] = nimf_preedit_attr_new (NIMF_PREEDIT_ATTR_UNDERLINE, 0, 0); m17n->preedit_attrs[0]->type = NIMF_PREEDIT_ATTR_UNDERLINE; m17n->preedit_attrs[0]->start_index = 0; m17n->preedit_attrs[0]->end_index = 0; m17n->preedit_attrs[1] = NULL; M17N_INIT(); strv = g_strsplit (m17n->method, ":", 2); if (g_strv_length (strv) > 1) { m17n->im = minput_open_im (msymbol (strv[0]), msymbol (strv[1]), NULL); if (m17n->im) { mplist_put (m17n->im->driver.callback_list, Minput_get_surrounding_text, on_get_surrounding_text); mplist_put (m17n->im->driver.callback_list, Minput_delete_surrounding_text, on_delete_surrounding_text); m17n->ic = minput_create_ic (m17n->im, m17n); m17n->converter = mconv_buffer_converter (Mcoding_utf_8, NULL, 0); } } g_strfreev (strv); g_return_if_fail (m17n->im != NULL); }
int m17n_Init(){ if( m17n_stat < 0 ) return -1; if( m17n_stat == 0 ){ m17n_init(); /*if( merror_code != MERROR_NONE )*/ if( mconv_resolve_coding(msymbol("iso-2022-jp")) == 0 ){ fprintf(stderr,"--M17n Failed to initialize"); m17n_stat = -1; }else{ m17n_stat = 1; } } return 0 < m17n_stat; }
static MPlist * parse_m17n_value (MPlist *plist, gchar *text) { MPlist *value; if (mplist_key (plist) == Msymbol) { value = mplist (); mplist_add (value, Msymbol, msymbol (text)); return value; } if (mplist_key (plist) == Mtext) { MText *mtext; mtext = mconv_decode_buffer (Mcoding_utf_8, (const unsigned char *) text, strlen (text)); value = mplist (); mplist_add (value, Mtext, mtext); return value; } 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)) return NULL; value = mplist (); mplist_add (value, Minteger, (void *)val); return value; } return NULL; }
gboolean nimf_m17n_filter_event (NimfEngine *engine, NimfServiceIC *target, NimfEvent *event) { g_debug (G_STRLOC ": %s", G_STRFUNC); NimfM17n *m17n = NIMF_M17N (engine); g_return_val_if_fail (m17n->im != NULL, FALSE); if (event->key.type == NIMF_EVENT_KEY_RELEASE || event->key.keyval == NIMF_KEY_Shift_L || event->key.keyval == NIMF_KEY_Shift_R) return FALSE; nimf_service_im_target = target; guint keyval = event->key.keyval; gboolean move = FALSE; if (nimf_candidatable_is_visible (m17n->candidatable)) { switch (keyval) { case NIMF_KEY_Up: case NIMF_KEY_KP_Up: keyval = NIMF_KEY_Left; break; case NIMF_KEY_Down: case NIMF_KEY_KP_Down: keyval = NIMF_KEY_Right; break; case NIMF_KEY_Left: case NIMF_KEY_KP_Left: case NIMF_KEY_Page_Up: case NIMF_KEY_KP_Page_Up: keyval = NIMF_KEY_Up; nimf_m17n_page_up (m17n); break; case NIMF_KEY_Right: case NIMF_KEY_KP_Right: case NIMF_KEY_Page_Down: case NIMF_KEY_KP_Page_Down: keyval = NIMF_KEY_Down; nimf_m17n_page_down (m17n); break; case NIMF_KEY_KP_0: keyval = NIMF_KEY_0; break; case NIMF_KEY_KP_1: keyval = NIMF_KEY_1; break; case NIMF_KEY_KP_2: keyval = NIMF_KEY_2; break; case NIMF_KEY_KP_3: keyval = NIMF_KEY_3; break; case NIMF_KEY_KP_4: keyval = NIMF_KEY_4; break; case NIMF_KEY_KP_5: keyval = NIMF_KEY_5; break; case NIMF_KEY_KP_6: keyval = NIMF_KEY_6; break; case NIMF_KEY_KP_7: keyval = NIMF_KEY_7; break; case NIMF_KEY_KP_8: keyval = NIMF_KEY_8; break; case NIMF_KEY_KP_9: keyval = NIMF_KEY_9; break; default: move = TRUE; break; } } const gchar *keysym_name; gboolean retval; keysym_name = nimf_keyval_to_keysym_name (keyval); MSymbol symbol; if (keysym_name) { GString *string; string = g_string_new (""); if (event->key.state & NIMF_HYPER_MASK) g_string_append (string, "H-"); if (event->key.state & NIMF_SUPER_MASK) g_string_append (string, "s-"); if (event->key.state & NIMF_MOD5_MASK) g_string_append (string, "G-"); if (event->key.state & NIMF_MOD1_MASK) g_string_append (string, "A-"); if (event->key.state & NIMF_META_MASK) g_string_append (string, "M-"); if (event->key.state & NIMF_CONTROL_MASK) g_string_append (string, "C-"); if (event->key.state & NIMF_SHIFT_MASK) g_string_append (string, "S-"); g_string_append (string, keysym_name); symbol = msymbol (string->str); g_string_free (string, TRUE); } else { g_warning (G_STRLOC ": %s: keysym name not found", G_STRFUNC); symbol = Mnil; } retval = minput_filter (m17n->ic, symbol, NULL); if (!retval) { MText *produced; produced = mtext (); retval = !minput_lookup (m17n->ic, symbol, NULL, produced); if (mtext_len (produced) > 0) { gchar *buf; buf = nimf_m17n_mtext_to_utf8 (m17n, produced); if (m17n->converter->nbytes > 0) nimf_engine_emit_commit (engine, target, (const gchar *) buf); g_free (buf); } m17n_object_unref (produced); } if (m17n->ic->preedit_changed) { gchar *new_preedit = nimf_m17n_mtext_to_utf8 (m17n, m17n->ic->preedit); nimf_m17n_update_preedit (engine, target, new_preedit); } if (m17n->ic->status_changed) { gchar *status; status = nimf_m17n_mtext_to_utf8 (m17n, m17n->ic->status); if (status && strlen (status)) g_debug ("Minput_status_draw: %s", status); g_free (status); } if (m17n->ic->candidate_list && m17n->ic->candidate_show) { nimf_m17n_update_candidate (engine, target); if (!nimf_candidatable_is_visible (m17n->candidatable)) nimf_candidatable_show (m17n->candidatable, target, FALSE); else if (move) nimf_candidatable_show (m17n->candidatable, target, FALSE); } else { nimf_candidatable_hide (m17n->candidatable); } nimf_service_im_target = NULL; return retval; }
MPlist * lookup (MPlist *args) { MInputContext *ic; MPlist *actions = NULL, *candidates, *plist; MSymbol init_state; MSymbol select_state; TableContext *context; MText *mt; ic = mplist_value (args); context = get_context (ic); args = mplist_next (args); init_state = (MSymbol) mplist_value (args); args = mplist_next (args); select_state = (MSymbol) mplist_value (args); if (context->desc) candidates = (*context->desc->lookup) (context, args); else candidates = mplist (); if (mplist_length (candidates) == 0) { m17n_object_unref (candidates); return NULL; } #if 0 /* FIXME: if only one candidate is matching, we should insert it and commit immediately. However, this feature is disabled for now since users would type extra characters after the match. For example, with mr-inscript-typing-booster, an Indic word "Epgyepgne" is only one candidate when a user type "Epgyepgn", but the user will likely to type "e" after commit. */ if (mplist_length (candidates) == 1) { actions = mplist (); add_action (actions, msymbol ("delete"), Msymbol, msymbol ("@<")); add_action (actions, msymbol ("insert"), Mtext, mplist_value (candidates)); add_action (actions, msymbol ("commit"), Mnil, NULL); m17n_object_unref (candidates); return actions; } #endif actions = mplist (); mt = mtext_dup (ic->preedit); mplist_push (candidates, Mtext, mt); m17n_object_unref (mt); plist = paginate (candidates); m17n_object_unref (candidates); add_action (actions, msymbol ("delete"), Msymbol, msymbol ("@<")); mplist_add (actions, Mplist, plist); m17n_object_unref (plist); add_action (actions, msymbol ("select"), Minteger, (void *)1); add_action (actions, msymbol ("show"), Mnil, NULL); add_action (actions, msymbol ("shift"), Msymbol, select_state); return actions; }
static gchar * transliterator_m17n_real_transliterate (TranslitTransliterator *self, const gchar *input, guint *endpos, GError **error) { TransliteratorM17n *m17n = TRANSLITERATOR_M17N (self); const gchar *p; GString *string; gchar *output; gint n_filtered = 0; string = g_string_sized_new (strlen (input)); minput_reset_ic (m17n->ic); for (p = input; ; p = g_utf8_next_char (p)) { gunichar uc = g_utf8_get_char (p); MSymbol symbol; gint retval; if (*p == '\0') symbol = Mnil; else { gint length; gchar *utf8; length = g_unichar_to_utf8 (uc, NULL); utf8 = g_slice_alloc0 (length + 1); g_unichar_to_utf8 (uc, utf8); symbol = msymbol (utf8); g_slice_free1 (length, utf8); } retval = minput_filter (m17n->ic, symbol, NULL); if (retval == 0) { MText *mt = mtext (); retval = minput_lookup (m17n->ic, symbol, NULL, mt); if (mtext_len (mt) > 0) { output = mtext_to_utf8 (mt); g_string_append (string, output); g_free (output); } if (retval) g_string_append_unichar (string, uc); m17n_object_unref (mt); n_filtered = 0; } else n_filtered++; if (symbol == Mnil) break; } if (endpos) *endpos = g_utf8_strlen (input, -1) - n_filtered; return g_string_free (string, FALSE); }
/* 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); for (i = 3; i < 8; i++) for (j = 0; j < mods->max_keypermod; j++) { KeyCode code = mods->modifiermap[i * mods->max_keypermod + j]; if (code == altgr) ... } Since IBus engines are supposed to be cross-platform, the code should go into IBus core, instead of ibus-m17n. */ MSymbol ibus_m17n_key_event_to_symbol (guint keycode, guint keyval, guint modifiers) { GString *keysym; MSymbol mkeysym = Mnil; guint mask = 0; IBusKeymap *keymap; if (keyval >= IBUS_Shift_L && keyval <= IBUS_Hyper_R) { return Mnil; } /* 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 (keyval >= IBUS_space && keyval <= IBUS_asciitilde) { gint c = keyval; if (keyval == IBUS_space && modifiers & IBUS_SHIFT_MASK) mask |= IBUS_SHIFT_MASK; if (modifiers & IBUS_CONTROL_MASK) { if (c >= IBUS_a && c <= IBUS_z) c += IBUS_A - IBUS_a; mask |= IBUS_CONTROL_MASK; } g_string_append_c (keysym, c); } else { mask |= modifiers & (IBUS_CONTROL_MASK | IBUS_SHIFT_MASK); g_string_append (keysym, ibus_keyval_name (keyval)); if (keysym->len == 0) { g_string_free (keysym, TRUE); return Mnil; } } mask |= modifiers & (IBUS_MOD1_MASK | IBUS_MOD5_MASK | IBUS_META_MASK | IBUS_SUPER_MASK | IBUS_HYPER_MASK); if (mask & IBUS_HYPER_MASK) { g_string_prepend (keysym, "H-"); } if (mask & IBUS_SUPER_MASK) { g_string_prepend (keysym, "s-"); } if (mask & IBUS_MOD5_MASK) { g_string_prepend (keysym, "G-"); } if (mask & IBUS_MOD1_MASK) { g_string_prepend (keysym, "A-"); } if (mask & IBUS_META_MASK) { g_string_prepend (keysym, "M-"); } if (mask & IBUS_CONTROL_MASK) { g_string_prepend (keysym, "C-"); } if (mask & IBUS_SHIFT_MASK) { g_string_prepend (keysym, "S-"); } mkeysym = msymbol (keysym->str); g_string_free (keysym, TRUE); return mkeysym; }