Ejemplo n.º 1
0
static gboolean
ibus_m17n_engine_process_key (IBusM17NEngine *m17n,
                              MSymbol         key)
{
    gchar *buf;
    MText *produced;
    gint retval;

    retval = minput_filter (m17n->context, key, NULL);

    if (retval) {
        return TRUE;
    }

    produced = mtext ();

    retval = minput_lookup (m17n->context, key, NULL, produced);

    if (retval) {
        // g_debug ("minput_lookup returns %d", retval);
    }

    buf = ibus_m17n_mtext_to_utf8 (produced);
    m17n_object_unref (produced);

    if (buf && strlen (buf)) {
        ibus_m17n_engine_commit_string (m17n, buf);
    }
    g_free (buf);

    return retval == 0;
}
Ejemplo n.º 2
0
void
nimf_m17n_reset (NimfEngine    *engine,
                 NimfServiceIC *target)
{
  g_debug (G_STRLOC ": %s", G_STRFUNC);

  NimfM17n *m17n = NIMF_M17N (engine);

  g_return_if_fail (m17n->im != NULL);

  nimf_candidatable_hide (m17n->candidatable);
  minput_filter (m17n->ic, Mnil, NULL);
  nimf_m17n_update_preedit (engine, target, g_strdup (""));
  minput_reset_ic (m17n->ic);
}
Ejemplo n.º 3
0
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;
}
Ejemplo n.º 4
0
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);
}