Exemple #1
0
INPUT_RETURN_VALUE FcitxThaiDoInput(void* arg, FcitxKeySym sym, unsigned int state)
{
    FcitxThai* thai = (FcitxThai*) arg;

    struct thcell_t context_cell;
    struct thinpconv_t conv;
    tischar_t new_char;

    if ((state & (FcitxKeyState_Ctrl | FcitxKeyState_Alt))
            || is_context_lost_key(sym)) {
        FcitxThaiForgetPrevChars(thai);
        return IRV_TO_PROCESS;
    }
    if (is_context_intact_key(sym)) {
        return IRV_TO_PROCESS;
    }

    new_char = keyval_to_tis(thai->config.kb_map, sym);
    if (0 == new_char)
        return IRV_TO_PROCESS;

    /* No correction -> just reject or commit */
    if (!thai->config.do_correct) {
        thchar_t prev_char = FcitxThaiGetPrevChar(thai);

        if (!th_isaccept(prev_char, new_char, thai->config.isc_mode))
            goto reject_char;

        return FcitxThaiCommitChars(thai, &new_char, 1);
    }

    FcitxThaiGetPrevCell(thai, &context_cell);
    if (!th_validate_leveled(context_cell, new_char, &conv,
                             thai->config.isc_mode)) {
        goto reject_char;
    }

    if (conv.offset < 0) {
        FcitxInputContext* ic = FcitxInstanceGetCurrentIC(thai->owner);
        /* Can't correct context, just fall back to rejection */
        if (!(ic->contextCaps & CAPACITY_SURROUNDING_TEXT))
            goto reject_char;

        FcitxInstanceDeleteSurroundingText(thai->owner, ic, conv.offset, -conv.offset);
    }
    FcitxThaiForgetPrevChars(thai);
    FcitxThaiRememberPrevChars(thai, new_char);

    return FcitxThaiCommitChars(thai, conv.conv, strlen((char*)conv.conv));

reject_char:
    /* gdk_beep (); */
    return true;
}
Exemple #2
0
static gboolean
lx_tn_engine_process_key_event (LxIEngine  *lx_iengine,
                                IBusEngine *ibus_engine,
                                guint       keyval,
                                guint       keycode,
                                guint       modifiers)
{
  LxTNEngine *lx_tn_engine = LX_TN_ENGINE (lx_iengine);
  gint shift_lv;
  gunichar new_char, prev_char;
  LxTNImAction action;

  if (modifiers & IBUS_RELEASE_MASK)
    return FALSE;

  if (modifiers & (IBUS_CONTROL_MASK | IBUS_MOD1_MASK))
    return FALSE;

  if (is_context_lost_key (keyval))
    return FALSE;

  if (0 == keyval || is_context_intact_key (keyval))
    return FALSE;

  shift_lv = !(modifiers & (IBUS_SHIFT_MASK | IBUS_MOD5_MASK)) ? 0
               : ((modifiers & IBUS_MOD5_MASK) ? 2 : 1);
  new_char = lx_tn_map_keycode (keycode, shift_lv);
  if (0 == new_char)
    return FALSE;

  if (lx_tn_engine_convert_seq (lx_tn_engine, ibus_engine, new_char))
    return TRUE;

  prev_char = lx_tn_engine_get_prev_surrounding_char (lx_tn_engine,
                                                      ibus_engine);
  action = lx_tn_im_action (prev_char, new_char);

  switch (lx_tn_engine->isc_mode)
    {
      case ISC_PASSTHROUGH:
        if (NA_R == action || NA_S == action)
          action = NA_A;
        break;
      case ISC_STRICT:
        if (NA_S == action)
          action = NA_R;
        break;
      case ISC_BASIC:
      default:
        if (NA_S == action)
          action = NA_A;
        break;
    }

  switch (action)
    {
      case NA_A:
        if (!lx_tn_engine_commit_char (lx_tn_engine, ibus_engine, new_char))
          goto reject_char;
        break;

      case NA_R:
      case NA_S:
        goto reject_char;

      default:
        /* shouldn't reach here! */
        break;
    }

  return TRUE;

reject_char:
  /* gdk_beep() */
  return TRUE;
}