diff options
author | Matthias Clasen <mclasen@redhat.com> | 2020-04-15 14:56:32 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2020-04-15 14:56:32 -0400 |
commit | 8e9406a082574f5a3c74e18c1d4a7f59cfab00aa (patch) | |
tree | 10294aa81883dcd567230890157c9bb3a9455ee3 /gtk/gtkmain.c | |
parent | 031b248c2093e1b99435080e6c5da2c33a67f510 (diff) | |
download | gtk+-8e9406a082574f5a3c74e18c1d4a7f59cfab00aa.tar.gz |
Move key event rewriting
Stop rewriting key and focus events on the GDK side.
Instead deliver them as they are, and propagate them
from the root on the gtk side, in gtkmain.c. And
stop complaining about focus events on popups - we
can just ignore them if we have no use for them.
Diffstat (limited to 'gtk/gtkmain.c')
-rw-r--r-- | gtk/gtkmain.c | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c index a34d2a8f84..59af57fb7d 100644 --- a/gtk/gtkmain.c +++ b/gtk/gtkmain.c @@ -1226,6 +1226,30 @@ rewrite_event_for_grabs (GdkEvent *event) return NULL; } +static GdkEvent * +rewrite_event_for_toplevel (GdkEvent *event) +{ + GdkSurface *surface; + + surface = gdk_event_get_surface (event); + if (!surface->parent) + return NULL; + + while (surface->parent) + surface = surface->parent; + + return gdk_event_key_new (gdk_event_get_event_type (event), + surface, + gdk_event_get_device (event), + gdk_event_get_source_device (event), + gdk_event_get_time (event), + gdk_key_event_get_keycode (event), + gdk_event_get_modifier_state (event), + gdk_key_event_is_modifier (event), + &event->key.translated[0], + &event->key.translated[1]); +} + static gboolean translate_event_coordinates (GdkEvent *event, double *x, @@ -1430,19 +1454,6 @@ is_key_event (GdkEvent *event) } } -static gboolean -is_focus_event (GdkEvent *event) -{ - switch ((guint) gdk_event_get_event_type (event)) - { - case GDK_FOCUS_CHANGE: - return TRUE; - break; - default: - return FALSE; - } -} - static inline void set_widget_active_state (GtkWidget *target, const gboolean release) @@ -1620,10 +1631,16 @@ gtk_main_do_event (GdkEvent *event) target_widget = event_widget; - /* If pointer or keyboard grabs are in effect, munge the events + /* We propagate key events from the root, even if they are + * delivered to a popup surface. + * + * If pointer or keyboard grabs are in effect, munge the events * so that each window group looks like a separate app. */ - rewritten_event = rewrite_event_for_grabs (event); + if (is_key_event (event)) + rewritten_event = rewrite_event_for_toplevel (event); + else + rewritten_event = rewrite_event_for_grabs (event); if (rewritten_event) { event = rewritten_event; @@ -1643,14 +1660,6 @@ gtk_main_do_event (GdkEvent *event) { target_widget = handle_key_event (event); } - else if (is_focus_event (event)) - { - if (!GTK_IS_WINDOW (target_widget)) - { - g_message ("Ignoring an unexpected focus event from GDK on a non-toplevel surface."); - goto cleanup; - } - } if (!target_widget) goto cleanup; |