[gtk+/wip/carlosg/event-delivery: 12/75] gtk: Implement per-focus implicit grabs



commit 9afabc07c465bac5ee9a71e9a7daf51351f63e8f
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Mar 31 17:55:49 2017 +0200

    gtk: Implement per-focus implicit grabs
    
    Unlike GTK+ grabs which are global to all/one device, the implicit grab
    is per focus, which means each may have implicit grabs on different or
    the same widget.

 gtk/gtkmain.c          |   10 ++++++++++
 gtk/gtkwindow.c        |   13 +++++++++++++
 gtk/gtkwindowprivate.h |    4 ++++
 3 files changed, 27 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c
index 2f45867..3791c9f 100644
--- a/gtk/gtkmain.c
+++ b/gtk/gtkmain.c
@@ -1504,6 +1504,9 @@ handle_pointing_event (GdkEvent *event)
       if (event->type == GDK_MOTION_NOTIFY || event->type == GDK_ENTER_NOTIFY)
         update_cursor (toplevel, device, target);
 
+      if (event->type == GDK_TOUCH_BEGIN)
+        gtk_window_set_pointer_focus_grab (toplevel, device, sequence, target);
+
       /* Let it take the effective pointer focus anyway, as it may change due
        * to implicit grabs.
        */
@@ -1511,6 +1514,13 @@ handle_pointing_event (GdkEvent *event)
       break;
     case GDK_BUTTON_PRESS:
     case GDK_BUTTON_RELEASE:
+      target = gtk_window_lookup_effective_pointer_focus_widget (toplevel,
+                                                                 device,
+                                                                 sequence);
+      gtk_window_set_pointer_focus_grab (toplevel, device, sequence,
+                                         event->type == GDK_BUTTON_PRESS ?
+                                         target : NULL);
+      break;
     case GDK_SCROLL:
     case GDK_TOUCHPAD_PINCH:
     case GDK_TOUCHPAD_SWIPE:
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 26ea1a0..8d5200f 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -11486,3 +11486,16 @@ gtk_window_update_pointer_focus_on_state_change (GtkWindow *window,
         }
     }
 }
+
+void
+gtk_window_set_pointer_focus_grab (GtkWindow        *window,
+                                   GdkDevice        *device,
+                                   GdkEventSequence *sequence,
+                                   GtkWidget        *grab_widget)
+{
+  GtkPointerFocus *focus;
+
+  focus = gtk_window_lookup_pointer_focus (window, device, sequence);
+  g_assert (focus != NULL);
+  gtk_pointer_focus_set_implicit_grab (focus, grab_widget);
+}
diff --git a/gtk/gtkwindowprivate.h b/gtk/gtkwindowprivate.h
index 7f62cc7..7d8d189 100644
--- a/gtk/gtkwindowprivate.h
+++ b/gtk/gtkwindowprivate.h
@@ -153,6 +153,10 @@ void             gtk_window_update_pointer_focus (GtkWindow        *window,
                                                   GtkWidget        *target,
                                                   gdouble           x,
                                                   gdouble           y);
+void             gtk_window_set_pointer_focus_grab (GtkWindow        *window,
+                                                    GdkDevice        *device,
+                                                    GdkEventSequence *sequence,
+                                                    GtkWidget        *grab_widget);
 
 void             gtk_window_update_pointer_focus_on_state_change (GtkWindow *window,
                                                                   GtkWidget *widget);


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