[gimp/gtk3-port] app: port some stuff to gdk_seat_grab/ungrab



commit 713243e92b41f93bb2802c6391167236f35b5b04
Author: Michael Natterer <mitch gimp org>
Date:   Tue May 1 13:42:19 2018 +0200

    app: port some stuff to gdk_seat_grab/ungrab

 app/display/gimpdisplayshell-callbacks.c |    4 ++-
 app/display/gimpnavigationeditor.c       |    3 +-
 app/display/gimpnavigationeditor.h       |    1 +
 app/widgets/gimpcombotagentry.c          |    2 +-
 app/widgets/gimphistogramview.c          |   21 ++++++-----
 app/widgets/gimphistogramview.h          |    2 +-
 app/widgets/gimpnavigationview.c         |   17 ++++-----
 app/widgets/gimpnavigationview.h         |    3 +-
 app/widgets/gimppopup.c                  |   57 ++++++++++++++----------------
 app/widgets/gimptagpopup.c               |   30 ++++++++--------
 app/widgets/gimptagpopup.h               |    3 +-
 11 files changed, 73 insertions(+), 70 deletions(-)
---
diff --git a/app/display/gimpdisplayshell-callbacks.c b/app/display/gimpdisplayshell-callbacks.c
index fb6b492..8341e7b 100644
--- a/app/display/gimpdisplayshell-callbacks.c
+++ b/app/display/gimpdisplayshell-callbacks.c
@@ -346,7 +346,9 @@ gimp_display_shell_navigation_button_press (GtkWidget        *widget,
 
   if (bevent->type == GDK_BUTTON_PRESS && bevent->button == 1)
     {
-      gimp_navigation_editor_popup (shell, widget, bevent->x, bevent->y);
+      gimp_navigation_editor_popup (shell, widget,
+                                    (GdkEvent *) bevent,
+                                    bevent->x, bevent->y);
     }
 
   return TRUE;
diff --git a/app/display/gimpnavigationeditor.c b/app/display/gimpnavigationeditor.c
index 9983cb5..398f113 100644
--- a/app/display/gimpnavigationeditor.c
+++ b/app/display/gimpnavigationeditor.c
@@ -230,6 +230,7 @@ gimp_navigation_editor_new (GimpMenuFactory *menu_factory)
 void
 gimp_navigation_editor_popup (GimpDisplayShell *shell,
                               GtkWidget        *widget,
+                              GdkEvent         *event,
                               gint              click_x,
                               gint              click_y)
 {
@@ -339,7 +340,7 @@ gimp_navigation_editor_popup (GimpDisplayShell *shell,
 
   /* fill in then grab pointer */
   gimp_navigation_view_set_motion_offset (view, 0, 0);
-  gimp_navigation_view_grab_pointer (view);
+  gimp_navigation_view_grab_pointer (view, event);
 }
 
 
diff --git a/app/display/gimpnavigationeditor.h b/app/display/gimpnavigationeditor.h
index 2658b16..611617c 100644
--- a/app/display/gimpnavigationeditor.h
+++ b/app/display/gimpnavigationeditor.h
@@ -70,6 +70,7 @@ GType       gimp_navigation_editor_get_type  (void) G_GNUC_CONST;
 GtkWidget * gimp_navigation_editor_new       (GimpMenuFactory  *menu_factory);
 void        gimp_navigation_editor_popup     (GimpDisplayShell *shell,
                                               GtkWidget        *widget,
+                                              GdkEvent         *event,
                                               gint              click_x,
                                               gint              click_y);
 
diff --git a/app/widgets/gimpcombotagentry.c b/app/widgets/gimpcombotagentry.c
index 93e0d1f..7fc17bb 100644
--- a/app/widgets/gimpcombotagentry.c
+++ b/app/widgets/gimpcombotagentry.c
@@ -264,7 +264,7 @@ gimp_combo_tag_entry_icon_press (GtkWidget            *widget,
           g_signal_connect (entry->popup, "destroy",
                             G_CALLBACK (gimp_combo_tag_entry_popup_destroy),
                             entry);
-          gimp_tag_popup_show (GIMP_TAG_POPUP (entry->popup));
+          gimp_tag_popup_show (GIMP_TAG_POPUP (entry->popup), event);
         }
     }
   else
diff --git a/app/widgets/gimphistogramview.c b/app/widgets/gimphistogramview.c
index 953df32..eda6042 100644
--- a/app/widgets/gimphistogramview.c
+++ b/app/widgets/gimphistogramview.c
@@ -587,22 +587,22 @@ gimp_histogram_view_button_press (GtkWidget      *widget,
 {
   GimpHistogramView *view = GIMP_HISTOGRAM_VIEW (widget);
 
-  if (! view->grab_device &&
+  if (! view->grab_seat &&
       bevent->type == GDK_BUTTON_PRESS && bevent->button == 1)
     {
-      GdkDevice     *device = gdk_event_get_device ((GdkEvent *) bevent);
+      GdkSeat       *seat = gdk_event_get_seat ((GdkEvent *) bevent);
       GtkAllocation  allocation;
       gint           width;
 
-      if (gdk_device_grab (device, gtk_widget_get_window (widget),
-                           GDK_OWNERSHIP_WINDOW, FALSE,
-                           GDK_BUTTON_RELEASE_MASK | GDK_BUTTON1_MOTION_MASK,
-                           NULL, bevent->time) != GDK_GRAB_SUCCESS)
+      if (gdk_seat_grab (seat, gtk_widget_get_window (widget),
+                         GDK_SEAT_CAPABILITY_ALL, FALSE,
+                         NULL, (GdkEvent *) bevent,
+                         NULL, NULL) != GDK_GRAB_SUCCESS)
         {
           return TRUE;
         }
 
-      view->grab_device = device;
+      view->grab_seat = seat;
 
       gtk_widget_get_allocation (widget, &allocation);
 
@@ -624,12 +624,13 @@ gimp_histogram_view_button_release (GtkWidget      *widget,
 {
   GimpHistogramView *view = GIMP_HISTOGRAM_VIEW (widget);
 
-  if (gdk_event_get_device ((GdkEvent *) bevent) == view->grab_device &&
+  if (gdk_event_get_seat ((GdkEvent *) bevent) == view->grab_seat &&
       bevent->button == 1)
     {
       gint start, end;
 
-      gdk_device_ungrab (view->grab_device, bevent->time);
+      gdk_seat_ungrab (view->grab_seat);
+      view->grab_seat = NULL;
 
       start = view->start;
       end   = view->end;
@@ -652,7 +653,7 @@ gimp_histogram_view_motion_notify (GtkWidget      *widget,
   GtkAllocation      allocation;
   gint               width;
 
-  if (gdk_event_get_device ((GdkEvent *) mevent) == view->grab_device)
+  if (gdk_event_get_seat ((GdkEvent *) mevent) == view->grab_seat)
     {
       gtk_widget_get_allocation (widget, &allocation);
 
diff --git a/app/widgets/gimphistogramview.h b/app/widgets/gimphistogramview.h
index c48e7e8..176cb56 100644
--- a/app/widgets/gimphistogramview.h
+++ b/app/widgets/gimphistogramview.h
@@ -44,7 +44,7 @@ struct _GimpHistogramView
   gint                   border_width;
   gint                   subdivisions;
 
-  GdkDevice             *grab_device;
+  GdkSeat               *grab_seat;
 };
 
 struct _GimpHistogramViewClass
diff --git a/app/widgets/gimpnavigationview.c b/app/widgets/gimpnavigationview.c
index 13dc6ab..d11a741 100644
--- a/app/widgets/gimpnavigationview.c
+++ b/app/widgets/gimpnavigationview.c
@@ -209,7 +209,8 @@ gimp_navigation_view_draw (GtkWidget *widget,
 }
 
 void
-gimp_navigation_view_grab_pointer (GimpNavigationView *nav_view)
+gimp_navigation_view_grab_pointer (GimpNavigationView *nav_view,
+                                   GdkEvent           *event)
 {
   GtkWidget  *widget = GTK_WIDGET (nav_view);
   GdkDisplay *display;
@@ -225,11 +226,10 @@ gimp_navigation_view_grab_pointer (GimpNavigationView *nav_view)
 
   window = GIMP_VIEW (nav_view)->event_window;
 
-  gdk_pointer_grab (window, FALSE,
-                    GDK_BUTTON_RELEASE_MASK      |
-                    GDK_POINTER_MOTION_HINT_MASK |
-                    GDK_BUTTON_MOTION_MASK,
-                    NULL, cursor, GDK_CURRENT_TIME);
+  gdk_seat_grab (gdk_event_get_seat (event),
+                 window,
+                 GDK_SEAT_CAPABILITY_ALL,
+                 FALSE, cursor, event, NULL, NULL);
 
   g_object_unref (cursor);
 }
@@ -267,7 +267,7 @@ gimp_navigation_view_button_press (GtkWidget      *widget,
           nav_view->motion_offset_y = ty - nav_view->p_center_y;
         }
 
-      gimp_navigation_view_grab_pointer (nav_view);
+      gimp_navigation_view_grab_pointer (nav_view, (GdkEvent *) bevent);
     }
 
   return TRUE;
@@ -284,8 +284,7 @@ gimp_navigation_view_button_release (GtkWidget      *widget,
       nav_view->has_grab = FALSE;
 
       gtk_grab_remove (widget);
-      gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
-                                  GDK_CURRENT_TIME);
+      gdk_seat_ungrab (gdk_event_get_seat ((GdkEvent *) bevent));
     }
 
   return TRUE;
diff --git a/app/widgets/gimpnavigationview.h b/app/widgets/gimpnavigationview.h
index b2c6cb5..1a6dfc0 100644
--- a/app/widgets/gimpnavigationview.h
+++ b/app/widgets/gimpnavigationview.h
@@ -73,7 +73,8 @@ void    gimp_navigation_view_get_local_marker
                                            gint               *center_y,
                                            gint               *width,
                                            gint               *height);
-void    gimp_navigation_view_grab_pointer (GimpNavigationView *view);
+void    gimp_navigation_view_grab_pointer (GimpNavigationView *view,
+                                           GdkEvent           *event);
 
 
 #endif /* __GIMP_NAVIGATION_VIEW_H__ */
diff --git a/app/widgets/gimppopup.c b/app/widgets/gimppopup.c
index 3f6c3d9..b24abe7 100644
--- a/app/widgets/gimppopup.c
+++ b/app/widgets/gimppopup.c
@@ -135,45 +135,42 @@ gimp_popup_grab_broken_event (GtkWidget          *widget,
 }
 
 static gboolean
-gimp_popup_map_event (GtkWidget                 *widget,
-                      G_GNUC_UNUSED GdkEventAny *event)
+gimp_popup_map_event (GtkWidget   *widget,
+                      GdkEventAny *event)
 {
+  GdkDisplay *display = gtk_widget_get_display (widget);
+
   GTK_WIDGET_CLASS (parent_class)->map_event (widget, event);
 
   /*  grab with owner_events == TRUE so the popup's widgets can
    *  receive events. we filter away events outside this toplevel
    *  away in button_press()
    */
-  if (gdk_pointer_grab (gtk_widget_get_window (widget), TRUE,
-                        GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
-                        GDK_POINTER_MOTION_MASK,
-                        NULL, NULL, GDK_CURRENT_TIME) == GDK_GRAB_SUCCESS)
+  if (gdk_seat_grab (gdk_display_get_default_seat (display),
+                     gtk_widget_get_window (widget),
+                     GDK_SEAT_CAPABILITY_ALL,
+                     TRUE,
+                     NULL,
+                     (GdkEvent *) event,
+                     NULL, NULL) == GDK_GRAB_SUCCESS)
     {
-      if (gdk_keyboard_grab (gtk_widget_get_window (widget), TRUE,
-                             GDK_CURRENT_TIME) == GDK_GRAB_SUCCESS)
-        {
-          gtk_grab_add (widget);
+      gtk_grab_add (widget);
 
-          g_signal_connect (widget, "grab-notify",
-                            G_CALLBACK (gimp_popup_grab_notify),
-                            widget);
-          g_signal_connect (widget, "grab-broken-event",
-                            G_CALLBACK (gimp_popup_grab_broken_event),
-                            widget);
+      g_signal_connect (widget, "grab-notify",
+                        G_CALLBACK (gimp_popup_grab_notify),
+                        widget);
+      g_signal_connect (widget, "grab-broken-event",
+                        G_CALLBACK (gimp_popup_grab_broken_event),
+                        widget);
 
-          return FALSE;
-        }
-      else
-        {
-          gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
-                                      GDK_CURRENT_TIME);
-        }
+      return FALSE;
     }
 
   /*  if we could not grab, destroy the popup instead of leaving it
    *  around uncloseable.
    */
   g_signal_emit (widget, popup_signals[CANCEL], 0);
+
   return FALSE;
 }
 
@@ -286,11 +283,11 @@ void
 gimp_popup_show (GimpPopup *popup,
                  GtkWidget *widget)
 {
-  GdkScreen      *screen;
+  GdkDisplay     *display;
+  GdkMonitor     *monitor;
   GtkRequisition  requisition;
   GtkAllocation   allocation;
   GdkRectangle    rect;
-  gint            monitor;
   gint            orig_x;
   gint            orig_y;
   gint            x;
@@ -299,7 +296,7 @@ gimp_popup_show (GimpPopup *popup,
   g_return_if_fail (GIMP_IS_POPUP (popup));
   g_return_if_fail (GTK_IS_WIDGET (widget));
 
-  gtk_widget_size_request (GTK_WIDGET (popup), &requisition);
+  gtk_widget_get_preferred_size (GTK_WIDGET (popup), &requisition, NULL);
 
   gtk_widget_get_allocation (widget, &allocation);
   gdk_window_get_origin (gtk_widget_get_window (widget), &orig_x, &orig_y);
@@ -310,10 +307,10 @@ gimp_popup_show (GimpPopup *popup,
       orig_y += allocation.y;
     }
 
-  screen = gtk_widget_get_screen (widget);
+  display = gtk_widget_get_display (widget);
 
-  monitor = gdk_screen_get_monitor_at_point (screen, orig_x, orig_y);
-  gdk_screen_get_monitor_workarea (screen, monitor, &rect);
+  monitor = gdk_display_get_monitor_at_point (display, orig_x, orig_y);
+  gdk_monitor_get_workarea (monitor, &rect);
 
   if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
     {
@@ -335,7 +332,7 @@ gimp_popup_show (GimpPopup *popup,
   if (y + requisition.height > rect.y + rect.height)
     y = orig_y - requisition.height;
 
-  gtk_window_set_screen (GTK_WINDOW (popup), screen);
+  gtk_window_set_screen (GTK_WINDOW (popup), gtk_widget_get_screen (widget));
   gtk_window_set_transient_for (GTK_WINDOW (popup),
                                 GTK_WINDOW (gtk_widget_get_toplevel (widget)));
 
diff --git a/app/widgets/gimptagpopup.c b/app/widgets/gimptagpopup.c
index da23328..38e89f9 100644
--- a/app/widgets/gimptagpopup.c
+++ b/app/widgets/gimptagpopup.c
@@ -467,7 +467,8 @@ gimp_tag_popup_new (GimpComboTagEntry *combo_entry)
  * it is destroyed.
  **/
 void
-gimp_tag_popup_show (GimpTagPopup *popup)
+gimp_tag_popup_show (GimpTagPopup *popup,
+                     GdkEvent     *event)
 {
   GtkWidget *widget;
 
@@ -480,12 +481,10 @@ gimp_tag_popup_show (GimpTagPopup *popup)
   gtk_grab_add (widget);
   gtk_widget_grab_focus (widget);
 
-  if (gdk_pointer_grab (gtk_widget_get_window (widget), TRUE,
-                        GDK_BUTTON_PRESS_MASK   |
-                        GDK_BUTTON_RELEASE_MASK |
-                        GDK_POINTER_MOTION_MASK,
-                        NULL, NULL,
-                        GDK_CURRENT_TIME) != GDK_GRAB_SUCCESS)
+  if (gdk_seat_grab (gdk_event_get_seat (event),
+                     gtk_widget_get_window (widget),
+                     GDK_SEAT_CAPABILITY_ALL,
+                     TRUE, NULL, event, NULL, NULL) != GDK_GRAB_SUCCESS)
     {
       /* pointer grab must be attained otherwise user would have
        * problems closing the popup window.
@@ -673,7 +672,9 @@ gimp_tag_popup_border_event (GtkWidget *widget,
 
       gtk_widget_get_allocation (widget, &allocation);
 
-      gdk_window_get_pointer (gtk_widget_get_window (widget), &x, &y, NULL);
+      gdk_window_get_device_position (gtk_widget_get_window (widget),
+                                      gdk_event_get_device (event),
+                                      &x, &y, NULL);
 
       if (button_event->window != gtk_widget_get_window (popup->tag_area) &&
           (x < allocation.y                    ||
@@ -685,8 +686,7 @@ gimp_tag_popup_border_event (GtkWidget *widget,
            * which means it should be hidden.
            */
           gtk_grab_remove (widget);
-          gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
-                                      GDK_CURRENT_TIME);
+          gdk_seat_ungrab (gdk_event_get_seat (event));
           gtk_widget_destroy (widget);
         }
     }
@@ -695,7 +695,9 @@ gimp_tag_popup_border_event (GtkWidget *widget,
       GdkEventMotion *motion_event = (GdkEventMotion *) event;
       gint            x, y;
 
-      gdk_window_get_pointer (gtk_widget_get_window (widget), &x, &y, NULL);
+      gdk_window_get_device_position (gtk_widget_get_window (widget),
+                                      gdk_event_get_device (event),
+                                      &x, &y, NULL);
 
       gimp_tag_popup_handle_scrolling (popup, x, y,
                                        motion_event->window ==
@@ -717,15 +719,13 @@ gimp_tag_popup_border_event (GtkWidget *widget,
   else if (event->type == GDK_GRAB_BROKEN)
     {
       gtk_grab_remove (widget);
-      gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
-                                  GDK_CURRENT_TIME);
+      gdk_seat_ungrab (gdk_event_get_seat (event));
       gtk_widget_destroy (widget);
     }
   else if (event->type == GDK_KEY_PRESS)
     {
       gtk_grab_remove (widget);
-      gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
-                                  GDK_CURRENT_TIME);
+      gdk_seat_ungrab (gdk_event_get_seat (event));
       gtk_widget_destroy (widget);
     }
   else if (event->type == GDK_SCROLL)
diff --git a/app/widgets/gimptagpopup.h b/app/widgets/gimptagpopup.h
index dfb0faf..3f21dca 100644
--- a/app/widgets/gimptagpopup.h
+++ b/app/widgets/gimptagpopup.h
@@ -77,7 +77,8 @@ GType       gimp_tag_popup_get_type (void) G_GNUC_CONST;
 
 GtkWidget * gimp_tag_popup_new      (GimpComboTagEntry *entry);
 
-void        gimp_tag_popup_show     (GimpTagPopup      *popup);
+void        gimp_tag_popup_show     (GimpTagPopup      *popup,
+                                     GdkEvent          *event);
 
 
 #endif  /*  __GIMP_TAG_POPUP_H__  */


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