[gtk/readonly-events-1: 28/35] Always deliver focus events to toplevels



commit 588d334f226e7a79783dada971a083e899f8aa96
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Feb 17 09:17:42 2020 -0500

    Always deliver focus events to toplevels
    
    Its was GTK expects. This change gets rid of the "Ignoring an
    unexpected focus event from GDK on a non-toplevel surface."
    warning.

 gdk/gdksurface.c | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)
---
diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c
index 976327e317..8acc869de4 100644
--- a/gdk/gdksurface.c
+++ b/gdk/gdksurface.c
@@ -3997,12 +3997,13 @@ check_autohide (GdkEvent *event)
 }
 
 static gboolean
-is_key_event (GdkEvent *event)
+is_keyboard_event (GdkEvent *event)
 {
   switch ((guint) gdk_event_get_event_type (event))
     {
     case GDK_KEY_PRESS:
     case GDK_KEY_RELEASE:
+    case GDK_FOCUS_CHANGE:
       return TRUE;
     default:;
     }
@@ -4022,17 +4023,23 @@ rewrite_event_for_toplevel (GdkEvent *event)
   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_event_get_modifier_state (event),
-                            gdk_key_event_get_keyval (event),
-                            gdk_key_event_get_keycode (event),
-                            gdk_key_event_get_scancode (event),
-                            gdk_key_event_get_group (event),
-                            gdk_key_event_is_modifier (event));
+  if (gdk_event_get_event_type (event) == GDK_FOCUS_CHANGE)
+    return gdk_event_focus_new (surface,
+                                gdk_event_get_device (event),
+                                gdk_event_get_source_device (event),
+                                gdk_focus_event_get_in (event));
+  else
+    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_event_get_modifier_state (event),
+                              gdk_key_event_get_keyval (event),
+                              gdk_key_event_get_keycode (event),
+                              gdk_key_event_get_scancode (event),
+                              gdk_key_event_get_group (event),
+                              gdk_key_event_is_modifier (event));
 }
 
 static void
@@ -4152,7 +4159,7 @@ gdk_surface_handle_event (GdkEvent *event)
     {
       GdkEvent *emitted;
 
-      if (is_key_event (event))
+      if (is_keyboard_event (event))
         emitted = rewrite_event_for_toplevel (event);
       else
         emitted = gdk_event_ref (event);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]