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; }
void xim_cancel_preedit(XIMHandle* handle) { IC* ic = icmgr_get_current(); if (ic == NULL) return; IMPreeditStateStruct ps; ps.icid = ic->icid; ps.connect_id = ic->connect_id; IMPreeditEnd(handle, (XPointer) &ps); }
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; }
void xim_commit_preedit(XIMHandle* handle, const char* result_str) { IC* ic = icmgr_get_current(); if (ic == NULL) return; XTextProperty tp; IMCommitStruct cs; Xutf8TextListToTextProperty(dpy, (char**) &result_str, 1, XCompoundTextStyle, &tp); memset(&cs, 0, sizeof(IMCommitStruct)); cs.major_code = XIM_COMMIT; cs.icid = ic->icid; cs.connect_id = ic->connect_id; cs.flag = XimLookupChars; cs.commit_string = (char*) tp.value; IMCommitString(handle, (XPointer) &cs); XFree(tp.value); }
static int _xim_set_ic_values(XIMHandle* handle, IMChangeICStruct* proto) { __xim_ic_events(proto); IC* ic = icmgr_get(proto->icid); /* some crapy swing application will have synchronization problems */ if (ic == NULL) return 1; LOG("XIM_SET_IC_VALUES %d", proto->icid); ic->offset_x = __preedit_x; ic->offset_y = __preedit_y; IC* cur_ic = icmgr_get_current(); /* if we change the current ic position, we might wanna * move it along the way */ if (cur_ic != NULL && ic->icid == cur_ic->icid) { __move_preedit(ic); } return 1; }