modules: Update input context impls to using GdkEvent API

This commit is contained in:
Carlos Garnacho 2017-08-25 16:40:59 +02:00
parent ab5f02771a
commit 668bb1bddd
3 changed files with 32 additions and 18 deletions

View File

@ -224,15 +224,18 @@ vfunc_filter_keypress (GtkIMContext *context, GdkEventKey *event)
multipress_context = GTK_IM_CONTEXT_MULTIPRESS (context);
if (event->type == GDK_KEY_PRESS)
if (gdk_event_get_event_type ((GdkEvent *) event) == GDK_KEY_PRESS)
{
KeySequence *possible;
guint keyval;
gdk_event_get_keyval ((GdkEvent *) event, &keyval);
/* Check whether the current key is the same as previously entered, because
* if it is not then we should accept the previous one, and start a new
* character. */
if (multipress_context->compose_count > 0
&& multipress_context->key_last_entered != event->keyval
&& multipress_context->key_last_entered != keyval
&& multipress_context->tentative_match != NULL)
{
/* Accept the previously chosen character. This wipes
@ -243,7 +246,7 @@ vfunc_filter_keypress (GtkIMContext *context, GdkEventKey *event)
/* Decide what character this key press would choose: */
possible = g_hash_table_lookup (multipress_context->key_sequences,
GUINT_TO_POINTER (event->keyval));
GUINT_TO_POINTER (keyval));
if (possible != NULL)
{
if (multipress_context->compose_count == 0)
@ -255,7 +258,7 @@ vfunc_filter_keypress (GtkIMContext *context, GdkEventKey *event)
multipress_context->compose_count = 0;
/* Store the last key pressed in the compose sequence. */
multipress_context->key_last_entered = event->keyval;
multipress_context->key_last_entered = keyval;
/* Get the possible match for this number of presses of the key.
* compose_count starts at 1, so that 0 can mean not composing. */
@ -291,7 +294,7 @@ vfunc_filter_keypress (GtkIMContext *context, GdkEventKey *event)
accept_character (multipress_context,
multipress_context->tentative_match);
}
keyval_uchar = gdk_keyval_to_unicode (event->keyval);
keyval_uchar = gdk_keyval_to_unicode (keyval);
/* Convert to a string for accept_character(). */
if (keyval_uchar != 0)

View File

@ -281,20 +281,24 @@ gtk_im_context_thai_filter_keypress (GtkIMContext *context,
gunichar prev_char, new_char;
gboolean is_reject;
GtkIMContextThaiISCMode isc_mode;
GdkModifierType state;
guint keyval;
if (event->type != GDK_KEY_PRESS)
if (gdk_event_get_event_type ((GdkEvent *) event) != GDK_KEY_PRESS ||
!gdk_event_get_state ((GdkEvent *) event, &state) ||
!gdk_event_get_keyval ((GdkEvent *) event, &keyval))
return FALSE;
if (event->state & (GDK_MODIFIER_MASK
& ~(GDK_SHIFT_MASK | GDK_LOCK_MASK | GDK_MOD2_MASK)) ||
is_context_lost_key (event->keyval))
if (state & (GDK_MODIFIER_MASK
& ~(GDK_SHIFT_MASK | GDK_LOCK_MASK | GDK_MOD2_MASK)) ||
is_context_lost_key (keyval))
{
#ifndef GTK_IM_CONTEXT_THAI_NO_FALLBACK
forget_previous_chars (context_thai);
#endif /* !GTK_IM_CONTEXT_THAI_NO_FALLBACK */
return FALSE;
}
if (event->keyval == 0 || is_context_intact_key (event->keyval))
if (keyval == 0 || is_context_intact_key (keyval))
{
return FALSE;
}
@ -302,7 +306,7 @@ gtk_im_context_thai_filter_keypress (GtkIMContext *context,
prev_char = get_previous_char (context_thai, -1);
if (!prev_char)
prev_char = ' ';
new_char = gdk_keyval_to_unicode (event->keyval);
new_char = gdk_keyval_to_unicode (keyval);
is_reject = TRUE;
isc_mode = gtk_im_context_thai_get_isc_mode (context_thai);
if (thai_is_accept (new_char, prev_char, isc_mode))

View File

@ -662,30 +662,37 @@ gtk_im_context_xim_filter_keypress (GtkIMContext *context,
gboolean result = FALSE;
GdkWindow *window;
XKeyPressedEvent xevent;
GdkEventType event_type;
guint state;
if (event->type == GDK_KEY_RELEASE && !context_xim->filter_key_release)
event_type = gdk_event_get_event_type ((GdkEvent *) event);
if (!gdk_event_get_state ((GdkEvent *) event, &state))
return GDK_EVENT_PROPAGATE;
if (event_type == GDK_KEY_RELEASE && !context_xim->filter_key_release)
return FALSE;
window = gdk_window_get_toplevel (event->window);
window = gdk_window_get_toplevel (gdk_event_get_window ((GdkEvent *) event));
xevent.type = (event->type == GDK_KEY_PRESS) ? KeyPress : KeyRelease;
xevent.type = (event_type == GDK_KEY_PRESS) ? KeyPress : KeyRelease;
xevent.serial = 0; /* hope it doesn't matter */
xevent.send_event = event->send_event;
xevent.display = GDK_WINDOW_XDISPLAY (window);
xevent.window = GDK_WINDOW_XID (window);
xevent.root = DefaultRootWindow(GDK_WINDOW_XDISPLAY (window));
xevent.subwindow = xevent.window;
xevent.time = event->time;
xevent.time = gdk_event_get_time ((GdkEvent *) event);
xevent.x = xevent.x_root = 0;
xevent.y = xevent.y_root = 0;
xevent.state = event->state;
xevent.keycode = event->hardware_keycode;
xevent.state = state;
xevent.keycode = gdk_event_get_scancode ((GdkEvent *) event);
xevent.same_screen = True;
if (XFilterEvent ((XEvent *)&xevent, context_xim->client_window_xid))
return TRUE;
if (event->state &
if (state &
(gtk_accelerator_get_default_mod_mask () & ~(GDK_SHIFT_MASK | GDK_CONTROL_MASK)))
return FALSE;