Ejemplo n.º 1
0
gboolean
bus_test_client_send_key (BusTestClient *client,
                     guint      keysym)
{
    gboolean is_modifier = _is_modifier_key (keysym);
    gint16 keycode;
    guint state;

    if (is_modifier) {
        IDEBUG ("key: %d is modifier.", keysym);
        gboolean is_modifier_set = _is_modifier_set (client, keysym);
        keycode = _get_keysym_to_keycode (keysym);
        state = _get_modifiers_to_mask (client);

        if (is_modifier_set) {
            state |= IBUS_RELEASE_MASK;
        }
        ibus_input_context_process_key_event (client->ibuscontext,
                                              keysym,
                                              keycode,
                                              state);
        _store_modifier_state (client, keysym);
    } else {
        IDEBUG ("key: %d is not modifier.", keysym);
        gboolean is_upper = !gdk_keyval_is_lower (keysym);
        gboolean is_shift_set = _is_shift_set (client);

        if (is_upper && !is_shift_set) {
            _store_modifier_state (client, IBUS_Shift_L);
        }
        keycode = _get_keysym_to_keycode (keysym);
        state = _get_modifiers_to_mask (client);
        ibus_input_context_process_key_event (client->ibuscontext,
                                              keysym,
                                              keycode,
                                              state);
        state |= IBUS_RELEASE_MASK;
        ibus_input_context_process_key_event (client->ibuscontext,
                                              keysym,
                                              keycode,
                                              state);
        if (is_upper && !is_shift_set) {
            _store_modifier_state (client, IBUS_Shift_L);
        }
    }
    return TRUE;
}
Ejemplo n.º 2
0
Archivo: main.c Proyecto: hychen/ibus
static int
xim_forward_event (XIMS xims, IMForwardEventStruct *call_data)
{
    X11IC *x11ic;
    XKeyEvent *xevent;
    GdkEventKey event;
    gboolean retval;

    LOG (1, "XIM_FORWARD_EVENT ic=%d connect_id=%d",
                call_data->icid, call_data->connect_id);

    x11ic = (X11IC *) g_hash_table_lookup (_x11_ic_table,
                                           GINT_TO_POINTER ((gint) call_data->icid));
    g_return_val_if_fail (x11ic != NULL, 0);

    xevent = (XKeyEvent*) &(call_data->event);

    translate_key_event (gdk_display_get_default (),
        (GdkEvent *)&event, (XEvent *)xevent);

    event.send_event = xevent->send_event;
    event.window = NULL;

    if (event.type == GDK_KEY_RELEASE) {
        event.state |= IBUS_RELEASE_MASK;
    }

    retval = ibus_input_context_process_key_event (x11ic->context,
                                                   event.keyval,
                                                   event.hardware_keycode - 8,
                                                   event.state);
    if (retval) {
        if (! x11ic->has_preedit_area) {
            _xim_set_cursor_location (x11ic);
        }
        return 1;
    }

    IMForwardEventStruct fe;
    memset (&fe, 0, sizeof (fe));

    fe.major_code = XIM_FORWARD_EVENT;
    fe.icid = x11ic->icid;
    fe.connect_id = x11ic->connect_id;
    fe.sync_bit = 0;
    fe.serial_number = 0L;
    fe.event = call_data->event;

    IMForwardEvent (_xims, (XPointer) &fe);

    return 1;
}
Ejemplo n.º 3
0
static void
test_input_context (void)
{
    GList *engines;
    gchar *active_engine_name = NULL;
    IBusInputContext *context;
    IBusEngineDesc *engine_desc;
    gchar *current_ic;

    context = ibus_bus_create_input_context (bus, "test");
    call_basic_ipcs (context);

    engines = ibus_bus_list_active_engines (bus);
    if (engines != NULL) {
        active_engine_name = get_last_engine_id (engines);
    } else {
        active_engine_name = g_strdup ("dummy");
    }
    g_assert (active_engine_name);
    g_debug ("Use '%s' for testing.", active_engine_name);

    ibus_input_context_set_engine (context, active_engine_name);
    current_ic = ibus_bus_current_input_context (bus);
    g_assert (!strcmp (current_ic, g_dbus_proxy_get_object_path ((GDBusProxy *)context)));

    g_test_log_set_fatal_handler (fatal_handler, NULL);
    engine_desc = ibus_input_context_get_engine (context);
    if (engine_desc) {
        /* FIXME race condition between ibus_input_context_set_engine and _get_engine.
         * ibus_input_context_get_engine is not guaranteed to return non-NULL
         * (even if we use synchronous set_engine()) because ibus-daemon sets a context
         * engine in an asynchronous manner. See _context_request_engine_cb in
         * ibusimpl.c which handles context_signals[REQUEST_ENGINE] signal. */
        g_assert (!strcmp (active_engine_name, ibus_engine_desc_get_name(engine_desc)));
        g_object_unref (engine_desc);
        engine_desc = NULL;
    }
    ibus_input_context_process_key_event (context, 0, 0, 0);

    /* An engine is set. Try to call basic IPCs again. */
    call_basic_ipcs (context);

    g_free (current_ic);
    g_object_unref (context);

    g_free (active_engine_name);
    g_list_foreach (engines, (GFunc) g_object_unref, NULL);
    g_list_free (engines);
}