INPUT_RETURN_VALUE FcitxUnikeyDoInputPreedit(FcitxUnikey* unikey, FcitxKeySym sym, unsigned int state) { if (state & FcitxKeyState_Ctrl || state & FcitxKeyState_Alt // alternate mask || sym == FcitxKey_Control_L || sym == FcitxKey_Control_R || sym == FcitxKey_Tab || sym == FcitxKey_Return || sym == FcitxKey_Delete || sym == FcitxKey_KP_Enter || (sym >= FcitxKey_Home && sym <= FcitxKey_Insert) || (sym >= FcitxKey_KP_Home && sym <= FcitxKey_KP_Delete) ) { FcitxUnikeyCommit(unikey); return IRV_FLAG_FORWARD_KEY; } else if (state & FcitxKeyState_Super) { return IRV_TO_PROCESS; } else if ((sym >= FcitxKey_Caps_Lock && sym <= FcitxKey_Hyper_R) || (!(state & FcitxKeyState_Shift) && (sym == FcitxKey_Shift_L || sym == FcitxKey_Shift_R)) // when press one shift key ) { return IRV_TO_PROCESS; } // capture BackSpace else if (sym == FcitxKey_BackSpace) { UnikeyBackspacePress(); if (UnikeyBackspaces == 0 || unikey->preeditstr->empty()) { FcitxUnikeyCommit(unikey); return IRV_FLAG_FORWARD_KEY; } else { if (unikey->preeditstr->length() <= (unsigned int)UnikeyBackspaces) { unikey->preeditstr->clear(); unikey->auto_commit = true; } else { FcitxUnikeyEraseChars(unikey, UnikeyBackspaces); } // change tone position after press backspace if (UnikeyBufChars > 0) { if (unikey->config.oc == UKCONV_XUTF8) { unikey->preeditstr->append((const char*)UnikeyBuf, UnikeyBufChars); } else { static unsigned char buf[CONVERT_BUF_SIZE]; int bufSize = CONVERT_BUF_SIZE; latinToUtf(buf, UnikeyBuf, UnikeyBufChars, &bufSize); unikey->preeditstr->append((const char*)buf, CONVERT_BUF_SIZE - bufSize); } unikey->auto_commit = false; } FcitxUnikeyUpdatePreedit(unikey); } return IRV_DISPLAY_MESSAGE; } // end capture BackSpace else if (sym >=FcitxKey_KP_Multiply && sym <=FcitxKey_KP_9) { FcitxUnikeyCommit(unikey); return IRV_FLAG_FORWARD_KEY; } // capture ascii printable char else if ((sym >= FcitxKey_space && sym <=FcitxKey_asciitilde) || sym == FcitxKey_Shift_L || sym == FcitxKey_Shift_R) // sure this have FcitxKey_SHIFT_MASK { unsigned int i = 0; UnikeySetCapsState(state & FcitxKeyState_Shift, state & FcitxKeyState_CapsLock); // process sym // auto commit word that never need to change later in preedit string (like consonant - phu am) // if macro enabled, then not auto commit. Because macro may change any word if (unikey->ukopt.macroEnabled == 0 && (UnikeyAtWordBeginning() || unikey->auto_commit)) { for (i =0; i < sizeof(WordAutoCommit); i++) { if (sym == WordAutoCommit[i]) { UnikeyPutChar(sym); unikey->auto_commit = true; return IRV_FLAG_FORWARD_KEY; } } } // end auto commit if ((unikey->config.im == UkTelex || unikey->config.im == UkSimpleTelex2) && unikey->config.process_w_at_begin == false && UnikeyAtWordBeginning() && (sym == FcitxKey_w || sym == FcitxKey_W)) { UnikeyPutChar(sym); if (unikey->ukopt.macroEnabled == 0) { return IRV_TO_PROCESS; } else { unikey->preeditstr->append(sym==FcitxKey_w?"w":"W"); FcitxUnikeyUpdatePreedit(unikey); return IRV_DISPLAY_MESSAGE; } } unikey->auto_commit = false; // shift + space, shift + shift event if ((unikey->last_key_with_shift == false && state & FcitxKeyState_Shift && sym == FcitxKey_space && !UnikeyAtWordBeginning()) || (sym == FcitxKey_Shift_L || sym == FcitxKey_Shift_R) // (&& state & FcitxKey_SHIFT_MASK), sure this have FcitxKey_SHIFT_MASK ) { UnikeyRestoreKeyStrokes(); } // end shift + space, shift + shift event else { UnikeyFilter(sym); } // end process sym // process result of ukengine if (UnikeyBackspaces > 0) { if (unikey->preeditstr->length() <= (unsigned int)UnikeyBackspaces) { unikey->preeditstr->clear(); } else { FcitxUnikeyEraseChars(unikey, UnikeyBackspaces); } } if (UnikeyBufChars > 0) { if (unikey->config.oc == UKCONV_XUTF8) { unikey->preeditstr->append((const char*)UnikeyBuf, UnikeyBufChars); } else { unsigned char buf[CONVERT_BUF_SIZE + 1]; int bufSize = CONVERT_BUF_SIZE; latinToUtf(buf, UnikeyBuf, UnikeyBufChars, &bufSize); unikey->preeditstr->append((const char*)buf, CONVERT_BUF_SIZE - bufSize); } } else if (sym != FcitxKey_Shift_L && sym != FcitxKey_Shift_R) // if ukengine not process { int n; char s[7] = {0, 0, 0, 0, 0, 0, 0}; n = FcitxUnikeyUcs4ToUtf8(unikey, (unsigned int)sym, s); // convert ucs4 to utf8 char unikey->preeditstr->append(s, n); } // end process result of ukengine // commit string: if need if (unikey->preeditstr->length() > 0) { unsigned int i; for (i = 0; i < sizeof(WordBreakSyms); i++) { if (WordBreakSyms[i] == unikey->preeditstr->at(unikey->preeditstr->length()-1) && WordBreakSyms[i] == sym) { FcitxUnikeyCommit(unikey); return IRV_DO_NOTHING; } } } // end commit string FcitxUnikeyUpdatePreedit(unikey); return IRV_DISPLAY_MESSAGE; } //end capture printable char // non process key FcitxUnikeyCommit(unikey); return IRV_FLAG_FORWARD_KEY; }
static gboolean ibus_unikey_engine_process_key_event_preedit(IBusEngine* engine, guint keyval, guint keycode, guint modifiers) { if (modifiers & IBUS_RELEASE_MASK) { return false; } else if (modifiers & IBUS_CONTROL_MASK || modifiers & IBUS_MOD1_MASK // alternate mask || keyval == IBUS_Control_L || keyval == IBUS_Control_R || keyval == IBUS_Tab || keyval == IBUS_Return || keyval == IBUS_Delete || keyval == IBUS_KP_Enter || (keyval >= IBUS_Home && keyval <= IBUS_Insert) || (keyval >= IBUS_KP_Home && keyval <= IBUS_KP_Delete) ) { ibus_unikey_engine_reset(engine); return false; } else if ((keyval >= IBUS_Caps_Lock && keyval <= IBUS_Hyper_R) || (!(modifiers & IBUS_SHIFT_MASK) && (keyval == IBUS_Shift_L || keyval == IBUS_Shift_R)) // when press one shift key ) { return false; } // capture BackSpace else if (keyval == IBUS_BackSpace) { UnikeyBackspacePress(); if (UnikeyBackspaces == 0 || unikey->preeditstr->empty()) { ibus_unikey_engine_reset(engine); return false; } else { if (unikey->preeditstr->length() <= (guint)UnikeyBackspaces) { unikey->preeditstr->clear(); ibus_engine_hide_preedit_text(engine); unikey->auto_commit = true; } else { ibus_unikey_engine_erase_chars(engine, UnikeyBackspaces); ibus_unikey_engine_update_preedit_string(engine, unikey->preeditstr->c_str(), true); } // change tone position after press backspace if (UnikeyBufChars > 0) { if (unikey->oc == CONV_CHARSET_XUTF8) { unikey->preeditstr->append((const gchar*)UnikeyBuf, UnikeyBufChars); } else { static unsigned char buf[CONVERT_BUF_SIZE]; int bufSize = CONVERT_BUF_SIZE; latinToUtf(buf, UnikeyBuf, UnikeyBufChars, &bufSize); unikey->preeditstr->append((const gchar*)buf, CONVERT_BUF_SIZE - bufSize); } unikey->auto_commit = false; ibus_unikey_engine_update_preedit_string(engine, unikey->preeditstr->c_str(), true); } } return true; } // end capture BackSpace else if (keyval >=IBUS_KP_Multiply && keyval <=IBUS_KP_9) { ibus_unikey_engine_reset(engine); return false; } // capture ascii printable char else if ((keyval >= IBUS_space && keyval <=IBUS_asciitilde) || keyval == IBUS_Shift_L || keyval == IBUS_Shift_R) // sure this have IBUS_SHIFT_MASK { static guint i; UnikeySetCapsState(modifiers & IBUS_SHIFT_MASK, modifiers & IBUS_LOCK_MASK); // process keyval // auto commit word that never need to change later in preedit string (like consonant - phu am) // if macro enabled, then not auto commit. Because macro may change any word if (unikey->ukopt.macroEnabled == 0 && (UnikeyAtWordBeginning() || unikey->auto_commit)) { for (i =0; i < sizeof(WordAutoCommit); i++) { if (keyval == WordAutoCommit[i]) { UnikeyPutChar(keyval); unikey->auto_commit = true; return false; } } } // end auto commit if ((unikey->im == UkTelex || unikey->im == UkSimpleTelex2) && unikey->process_w_at_begin == false && UnikeyAtWordBeginning() && (keyval == IBUS_w || keyval == IBUS_W)) { UnikeyPutChar(keyval); if (unikey->ukopt.macroEnabled == 0) { return false; } else { unikey->preeditstr->append(keyval==IBUS_w?"w":"W"); ibus_unikey_engine_update_preedit_string(engine, unikey->preeditstr->c_str(), true); return true; } } unikey->auto_commit = false; // shift + space, shift + shift event if ((unikey->last_key_with_shift == false && modifiers & IBUS_SHIFT_MASK && keyval == IBUS_space && !UnikeyAtWordBeginning()) || (keyval == IBUS_Shift_L || keyval == IBUS_Shift_R) // (&& modifiers & IBUS_SHIFT_MASK), sure this have IBUS_SHIFT_MASK ) { UnikeyRestoreKeyStrokes(); } // end shift + space, shift + shift event else { UnikeyFilter(keyval); } // end process keyval // process result of ukengine if (UnikeyBackspaces > 0) { if (unikey->preeditstr->length() <= (guint)UnikeyBackspaces) { unikey->preeditstr->clear(); } else { ibus_unikey_engine_erase_chars(engine, UnikeyBackspaces); } } if (UnikeyBufChars > 0) { if (unikey->oc == CONV_CHARSET_XUTF8) { unikey->preeditstr->append((const gchar*)UnikeyBuf, UnikeyBufChars); } else { static unsigned char buf[CONVERT_BUF_SIZE]; int bufSize = CONVERT_BUF_SIZE; latinToUtf(buf, UnikeyBuf, UnikeyBufChars, &bufSize); unikey->preeditstr->append((const gchar*)buf, CONVERT_BUF_SIZE - bufSize); } } else if (keyval != IBUS_Shift_L && keyval != IBUS_Shift_R) // if ukengine not process { static int n; static char s[6]; n = g_unichar_to_utf8(keyval, s); // convert ucs4 to utf8 char unikey->preeditstr->append(s, n); } // end process result of ukengine // commit string: if need if (unikey->preeditstr->length() > 0) { static guint i; for (i = 0; i < sizeof(WordBreakSyms); i++) { if (WordBreakSyms[i] == unikey->preeditstr->at(unikey->preeditstr->length()-1) && WordBreakSyms[i] == keyval) { ibus_unikey_engine_reset(engine); return true; } } } // end commit string ibus_unikey_engine_update_preedit_string(engine, unikey->preeditstr->c_str(), true); return true; } //end capture printable char // non process key ibus_unikey_engine_reset(engine); return false; }