static int _xim_destroy_ic(XIMHandle* handle, IMChangeICStruct* proto) { LOG("XIM_DESTROY_IC %d", proto->icid); icmgr_destroy_ic(proto->icid); icmgr_refresh(); return 1; }
static int _xim_unset_ic_focus(XIMHandle* handle, IMChangeFocusStruct* proto) { LOG("unset focus on ic %d", proto->icid); IC* ic = icmgr_get_current(); if (ic != NULL && ic->icid == proto->icid && preedit_status() == false) { icmgr_clear_current(); icmgr_refresh(); } return 1; }
int _xim_forward_event(XIMHandle* handle, IMForwardEventStruct* proto) { LOG("%d", proto->icid); XKeyEvent* evt = (XKeyEvent*) &(proto->event); IC* ic = icmgr_get_current(); if (ic == NULL) { icmgr_set_current(proto->icid); ic = icmgr_get_current(); if (ic == NULL) return 1; } /* some of swing applications like netbeans won't set focus, * we have to set focus ourself */ if (ic->icid != proto->icid || preedit_status() == false) { icmgr_set_current(proto->icid); ic = icmgr_get_current(); icmgr_refresh(); } if (!__filter_forward_triger_key(handle, ic, evt)) { int masked_state = evt->state & STATE_MASK; if (masked_state != ShiftMask && masked_state != 0) { __do_forward_event(handle, proto); } else if (!ic->is_enabled || ic->is_english) { __do_forward_event(handle, proto); } else { KeySym sym; XLookupString(evt, NULL, 0, &sym, NULL); if ((sym <= 0x20 || sym > 0x7E) && preedit_status() == false) { __do_forward_event(handle, proto); } else if (sym >= 0x30 && sym <= 0x39 && preedit_status() == false) { // digit key pressed if (settings_get_int(SMART_PUNCT) && evt->type == KeyPress) { preedit_omit_next_punct(); } __do_forward_event(handle, proto); } else { if (evt->type == KeyPress) { __move_preedit(ic); preedit_on_key(handle, sym, evt->state); } else { LOG("ignore"); } } } } return 1; }
static int _xim_set_ic_focus(XIMHandle* handle, IMChangeFocusStruct* proto) { DEBUG("%d", proto->icid); LOG("set focus on ic %d %d", proto->icid, preedit_status()); /* if use didn't finish typing, we won't focus to new context */ if (preedit_status() == false) { icmgr_set_current(proto->icid); } icmgr_refresh(); return 1; }
static bool __filter_forward_triger_key(XIMHandle* handle, IC* ic, XKeyEvent* evt) { KeySym sym = 0; hotkey_t hk; settings_get(TRIGGER_KEY, &hk); XLookupString(evt, NULL, 0, &sym, NULL); unsigned int masked_state = (evt->state & STATE_MASK); if (masked_state == hk.modifiers && sym == hk.keysym) { if (evt->type == KeyRelease) return true; ic->is_enabled = !ic->is_enabled; __toggle_preedit_status(handle, ic->is_enabled); icmgr_refresh(); return true; } settings_get(ENG_KEY, &hk); if ((masked_state & hk.modifiers) == hk.modifiers && sym == hk.keysym) { if (evt->type == KeyPress) { last_shift_available = true; return true; } else if (evt->type == KeyRelease && last_shift_available) { last_shift_available = false; if (ic->is_enabled) { ic->is_english = !ic->is_english; icmgr_refresh(); } } return true; } else { last_shift_available = false; } return false; }
static int _xim_trigger_notify(XIMHandle* handle, IMTriggerNotifyStruct* proto) { LOG("trigger key pressed, %d", proto->icid); IC* ic = icmgr_get(proto->icid); if (ic == NULL) return 1; icmgr_set_current(proto->icid); ic->is_enabled = true; xim_start_preedit(handle); icmgr_refresh(); return 1; }