コード例 #1
0
ファイル: xim_trigger.c プロジェクト: epico/sunpinyin
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;
}
コード例 #2
0
ファイル: xim.c プロジェクト: WilliamRen/sunpinyin
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;
}