[gtk/wip/matthiasc/popup2: 87/108] Avoid root coordinates in begin_drag/move apis



commit c09241aeec0b47ccfc281c94fbe04b6a1c6eeaf0
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Mar 23 14:56:21 2019 -0400

    Avoid root coordinates in begin_drag/move apis
    
    Change the all the begin_drag and begin_move apis in
    GdkSurface and GtkWindow to expect surface coordinates.
    
    Update the x11 implementation to translate to root
    coordinates where it matters. Wayland is ignoring the
    coordinates anyway.

 gdk/gdksurface.c                 | 66 ++++++++++++++++++----------------------
 gdk/gdksurface.h                 | 36 +++++++++++-----------
 gdk/wayland/gdksurface-wayland.c |  8 ++---
 gdk/x11/gdksurface-x11.c         | 41 ++++++++++++++-----------
 gtk/gtkwindow.c                  | 63 ++++++++++++++------------------------
 gtk/gtkwindow.h                  |  8 ++---
 6 files changed, 102 insertions(+), 120 deletions(-)
---
diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c
index d230d97c6b..15a9e3255d 100644
--- a/gdk/gdksurface.c
+++ b/gdk/gdksurface.c
@@ -3910,27 +3910,23 @@ gdk_surface_set_functions (GdkSurface    *surface,
  * @edge: the edge or corner from which the drag is started
  * @device: the device used for the operation
  * @button: the button being used to drag, or 0 for a keyboard-initiated drag
- * @root_x: root window X coordinate of mouse click that began the drag
- * @root_y: root window Y coordinate of mouse click that began the drag
+ * @x: surface X coordinate of mouse click that began the drag
+ * @y: surface Y coordinate of mouse click that began the drag
  * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
  *
  * Begins a surface resize operation (for a toplevel surface).
- * You might use this function to implement a “window resize grip,” for
- * example; in fact #GtkStatusbar uses it. The function works best
- * with window managers that support the
- * [Extended Window Manager Hints](http://www.freedesktop.org/Standards/wm-spec)
- * but has a fallback implementation for other window managers.
+ * You might use this function to implement a “window resize grip,”
  */
 void
 gdk_surface_begin_resize_drag_for_device (GdkSurface     *surface,
                                           GdkSurfaceEdge  edge,
-                                          GdkDevice     *device,
-                                          gint           button,
-                                          gint           root_x,
-                                          gint           root_y,
-                                          guint32        timestamp)
+                                          GdkDevice      *device,
+                                          gint            button,
+                                          gint            x,
+                                          gint            y,
+                                          guint32         timestamp)
 {
-  GDK_SURFACE_IMPL_GET_CLASS (surface->impl)->begin_resize_drag (surface, edge, device, button, root_x, 
root_y, timestamp);
+  GDK_SURFACE_IMPL_GET_CLASS (surface->impl)->begin_resize_drag (surface, edge, device, button, x, y, 
timestamp);
 }
 
 /**
@@ -3938,8 +3934,8 @@ gdk_surface_begin_resize_drag_for_device (GdkSurface     *surface,
  * @surface: a toplevel #GdkSurface
  * @edge: the edge or corner from which the drag is started
  * @button: the button being used to drag, or 0 for a keyboard-initiated drag
- * @root_x: root window X coordinate of mouse click that began the drag
- * @root_y: root window Y coordinate of mouse click that began the drag
+ * @x: surface X coordinate of mouse click that began the drag
+ * @y: surface Y coordinate of mouse click that began the drag
  * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
  *
  * Begins a surface resize operation (for a toplevel surface).
@@ -3951,10 +3947,10 @@ gdk_surface_begin_resize_drag_for_device (GdkSurface     *surface,
 void
 gdk_surface_begin_resize_drag (GdkSurface     *surface,
                                GdkSurfaceEdge  edge,
-                               gint           button,
-                               gint           root_x,
-                               gint           root_y,
-                               guint32        timestamp)
+                               gint            button,
+                               gint            x,
+                               gint            y,
+                               guint32         timestamp)
 {
   GdkDisplay *display;
   GdkDevice *device;
@@ -3962,7 +3958,7 @@ gdk_surface_begin_resize_drag (GdkSurface     *surface,
   display = gdk_surface_get_display (surface);
   device = gdk_seat_get_pointer (gdk_display_get_default_seat (display));
   gdk_surface_begin_resize_drag_for_device (surface, edge,
-                                           device, button, root_x, root_y, timestamp);
+                                            device, button, x, y, timestamp);
 }
 
 /**
@@ -3970,34 +3966,30 @@ gdk_surface_begin_resize_drag (GdkSurface     *surface,
  * @surface: a toplevel #GdkSurface
  * @device: the device used for the operation
  * @button: the button being used to drag, or 0 for a keyboard-initiated drag
- * @root_x: root window X coordinate of mouse click that began the drag
- * @root_y: root window Y coordinate of mouse click that began the drag
+ * @x: surface X coordinate of mouse click that began the drag
+ * @y: surface Y coordinate of mouse click that began the drag
  * @timestamp: timestamp of mouse click that began the drag
  *
  * Begins a surface move operation (for a toplevel surface).
- * You might use this function to implement a “window move grip,” for
- * example. The function works best with window managers that support the
- * [Extended Window Manager Hints](http://www.freedesktop.org/Standards/wm-spec)
- * but has a fallback implementation for other window managers.
  */
 void
 gdk_surface_begin_move_drag_for_device (GdkSurface *surface,
-                                        GdkDevice *device,
-                                        gint       button,
-                                        gint       root_x,
-                                        gint       root_y,
-                                        guint32    timestamp)
+                                        GdkDevice  *device,
+                                        gint        button,
+                                        gint        x,
+                                        gint        y,
+                                        guint32     timestamp)
 {
   GDK_SURFACE_IMPL_GET_CLASS (surface->impl)->begin_move_drag (surface,
-                                                             device, button, root_x, root_y, timestamp);
+                                                               device, button, x, y, timestamp);
 }
 
 /**
  * gdk_surface_begin_move_drag:
  * @surface: a toplevel #GdkSurface
  * @button: the button being used to drag, or 0 for a keyboard-initiated drag
- * @root_x: root window X coordinate of mouse click that began the drag
- * @root_y: root window Y coordinate of mouse click that began the drag
+ * @x: surface X coordinate of mouse click that began the drag
+ * @y: surface Y coordinate of mouse click that began the drag
  * @timestamp: timestamp of mouse click that began the drag
  *
  * Begins a surface move operation (for a toplevel surface).
@@ -4009,8 +4001,8 @@ gdk_surface_begin_move_drag_for_device (GdkSurface *surface,
 void
 gdk_surface_begin_move_drag (GdkSurface *surface,
                              gint       button,
-                             gint       root_x,
-                             gint       root_y,
+                             gint       x,
+                             gint       y,
                              guint32    timestamp)
 {
   GdkDisplay *display;
@@ -4018,7 +4010,7 @@ gdk_surface_begin_move_drag (GdkSurface *surface,
 
   display = gdk_surface_get_display (surface);
   device = gdk_seat_get_pointer (gdk_display_get_default_seat (display));
-  gdk_surface_begin_move_drag_for_device (surface, device, button, root_x, root_y, timestamp);
+  gdk_surface_begin_move_drag_for_device (surface, device, button, x, y, timestamp);
 }
 
 /**
diff --git a/gdk/gdksurface.h b/gdk/gdksurface.h
index 06271ceaca..2756552d22 100644
--- a/gdk/gdksurface.h
+++ b/gdk/gdksurface.h
@@ -717,31 +717,31 @@ void          gdk_surface_register_dnd    (GdkSurface       *surface);
 GDK_AVAILABLE_IN_ALL
 void gdk_surface_begin_resize_drag            (GdkSurface     *surface,
                                                GdkSurfaceEdge  edge,
-                                               gint           button,
-                                               gint           root_x,
-                                               gint           root_y,
-                                               guint32        timestamp);
+                                               gint            button,
+                                               gint            x,
+                                               gint            y,
+                                               guint32         timestamp);
 GDK_AVAILABLE_IN_ALL
 void gdk_surface_begin_resize_drag_for_device (GdkSurface     *surface,
                                                GdkSurfaceEdge  edge,
-                                               GdkDevice     *device,
-                                               gint           button,
-                                               gint           root_x,
-                                               gint           root_y,
-                                               guint32        timestamp);
+                                               GdkDevice      *device,
+                                               gint            button,
+                                               gint            x,
+                                               gint            y,
+                                               guint32         timestamp);
 GDK_AVAILABLE_IN_ALL
 void gdk_surface_begin_move_drag              (GdkSurface     *surface,
-                                               gint           button,
-                                               gint           root_x,
-                                               gint           root_y,
-                                               guint32        timestamp);
+                                               gint            button,
+                                               gint            x,
+                                               gint            y,
+                                               guint32         timestamp);
 GDK_AVAILABLE_IN_ALL
 void gdk_surface_begin_move_drag_for_device   (GdkSurface     *surface,
-                                               GdkDevice     *device,
-                                               gint           button,
-                                               gint           root_x,
-                                               gint           root_y,
-                                               guint32        timestamp);
+                                               GdkDevice      *device,
+                                               gint            button,
+                                               gint            x,
+                                               gint            y,
+                                               guint32         timestamp);
 
 /* Interface for dirty-region queueing */
 GDK_AVAILABLE_IN_ALL
diff --git a/gdk/wayland/gdksurface-wayland.c b/gdk/wayland/gdksurface-wayland.c
index 9fd6d2e065..2c22f0fde3 100644
--- a/gdk/wayland/gdksurface-wayland.c
+++ b/gdk/wayland/gdksurface-wayland.c
@@ -3531,8 +3531,8 @@ gdk_wayland_surface_begin_resize_drag (GdkSurface     *surface,
                                        GdkSurfaceEdge  edge,
                                        GdkDevice      *device,
                                        gint            button,
-                                       gint            root_x,
-                                       gint            root_y,
+                                       gint            x,
+                                       gint            y,
                                        guint32         timestamp)
 {
   GdkSurfaceImplWayland *impl;
@@ -3621,8 +3621,8 @@ static void
 gdk_wayland_surface_begin_move_drag (GdkSurface *surface,
                                      GdkDevice  *device,
                                      gint        button,
-                                     gint        root_x,
-                                     gint        root_y,
+                                     gint        x,
+                                     gint        y,
                                      guint32     timestamp)
 {
   GdkSurfaceImplWayland *impl;
diff --git a/gdk/x11/gdksurface-x11.c b/gdk/x11/gdksurface-x11.c
index bb31eb7eae..1d6db2fd2d 100644
--- a/gdk/x11/gdksurface-x11.c
+++ b/gdk/x11/gdksurface-x11.c
@@ -4254,12 +4254,12 @@ emulate_resize_drag (GdkSurface     *surface,
 }
 
 static void
-emulate_move_drag (GdkSurface     *surface,
-                   GdkDevice     *device,
-                   gint           button,
-                   gint           root_x,
-                   gint           root_y,
-                   guint32        timestamp)
+emulate_move_drag (GdkSurface *surface,
+                   GdkDevice  *device,
+                   gint        button,
+                   gint        root_x,
+                   gint        root_y,
+                   guint32     timestamp)
 {
   MoveResizeData *mv_resize = get_move_resize_data (GDK_SURFACE_DISPLAY (surface), TRUE);
 
@@ -4299,17 +4299,21 @@ _should_perform_ewmh_drag (GdkSurface *surface,
 
 static void
 gdk_x11_surface_begin_resize_drag (GdkSurface     *surface,
-                                  GdkSurfaceEdge  edge,
-                                  GdkDevice     *device,
-                                  gint           button,
-                                  gint           root_x,
-                                  gint           root_y,
-                                  guint32        timestamp)
+                                   GdkSurfaceEdge  edge,
+                                   GdkDevice      *device,
+                                   gint            button,
+                                   gint            x,
+                                   gint            y,
+                                   guint32         timestamp)
 {
+  int root_x, root_y;
+
   if (GDK_SURFACE_DESTROYED (surface) ||
       !SURFACE_IS_TOPLEVEL (surface))
     return;
 
+  gdk_surface_x11_get_root_coords (surface, x, y, &root_x, &root_y);
+
   /* Avoid EWMH for touch devices */
   if (_should_perform_ewmh_drag (surface, device))
     wmspec_resize_drag (surface, edge, device, button, root_x, root_y, timestamp);
@@ -4319,12 +4323,13 @@ gdk_x11_surface_begin_resize_drag (GdkSurface     *surface,
 
 static void
 gdk_x11_surface_begin_move_drag (GdkSurface *surface,
-                                GdkDevice *device,
-                               gint       button,
-                               gint       root_x,
-                               gint       root_y,
-                               guint32    timestamp)
+                                 GdkDevice  *device,
+                                 gint        button,
+                                 gint        x,
+                                 gint        y,
+                                 guint32     timestamp)
 {
+  int root_x, root_y;
   gint direction;
 
   if (GDK_SURFACE_DESTROYED (surface) || !SURFACE_IS_TOPLEVEL (surface))
@@ -4335,6 +4340,8 @@ gdk_x11_surface_begin_move_drag (GdkSurface *surface,
   else
     direction = _NET_WM_MOVERESIZE_MOVE;
 
+  gdk_surface_x11_get_root_coords (surface, x, y, &root_x, &root_y);
+
   /* Avoid EWMH for touch devices */
   if (_should_perform_ewmh_drag (surface, device))
     wmspec_moveresize (surface, direction, device, button, root_x, root_y, timestamp);
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index abc2e47c84..fb0d22909b 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -1480,16 +1480,15 @@ multipress_gesture_pressed_cb (GtkGestureMultiPress *gesture,
     default:
       if (!priv->maximized)
         {
-          gdouble x_root, y_root;
-
+          double x, y;
           gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
 
-          gdk_event_get_root_coords (event, &x_root, &y_root);
+          gdk_event_get_coords (event, &x, &y);
           gdk_surface_begin_resize_drag_for_device (_gtk_widget_get_surface (widget),
                                                    (GdkSurfaceEdge) region,
                                                    gdk_event_get_device ((GdkEvent *) event),
                                                    GDK_BUTTON_PRIMARY,
-                                                   x_root, y_root,
+                                                   x, y,
                                                    gdk_event_get_time (event));
 
           gtk_event_controller_reset (GTK_EVENT_CONTROLLER (gesture));
@@ -1595,13 +1594,11 @@ drag_gesture_update_cb (GtkGestureDrag *gesture,
       gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
 
       gtk_gesture_drag_get_start_point (gesture, &start_x, &start_y);
-      gdk_surface_get_root_coords (_gtk_widget_get_surface (GTK_WIDGET (window)),
-                                  start_x, start_y, &x_root, &y_root);
 
       gdk_surface_begin_move_drag_for_device (_gtk_widget_get_surface (GTK_WIDGET (window)),
                                              gtk_gesture_get_device (GTK_GESTURE (gesture)),
                                              gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE 
(gesture)),
-                                             x_root, y_root,
+                                             (int)start_x, (int)start_y,
                                              gtk_get_current_event_time ());
 
       gtk_event_controller_reset (GTK_EVENT_CONTROLLER (gesture));
@@ -9233,24 +9230,20 @@ gtk_window_get_gravity (GtkWindow *window)
  * @window: a #GtkWindow
  * @button: mouse button that initiated the drag
  * @edge: position of the resize control
- * @root_x: X position where the user clicked to initiate the drag, in root window coordinates
- * @root_y: Y position where the user clicked to initiate the drag
+ * @x: X position where the user clicked to initiate the drag, in window coordinates
+ * @y: Y position where the user clicked to initiate the drag
  * @timestamp: timestamp from the click event that initiated the drag
  *
  * Starts resizing a window. This function is used if an application
- * has window resizing controls. When GDK can support it, the resize
- * will be done using the standard mechanism for the
- * [window manager][gtk-X11-arch] or windowing
- * system. Otherwise, GDK will try to emulate window resizing,
- * potentially not all that well, depending on the windowing system.
+ * has window resizing controls.
  */
 void
-gtk_window_begin_resize_drag  (GtkWindow     *window,
-                               GdkSurfaceEdge  edge,
-                               gint           button,
-                               gint           root_x,
-                               gint           root_y,
-                               guint32        timestamp)
+gtk_window_begin_resize_drag (GtkWindow      *window,
+                              GdkSurfaceEdge  edge,
+                              gint            button,
+                              gint            x,
+                              gint            y,
+                              guint32         timestamp)
 {
   GtkWidget *widget;
   GdkSurface *toplevel;
@@ -9261,33 +9254,26 @@ gtk_window_begin_resize_drag  (GtkWindow     *window,
 
   toplevel = _gtk_widget_get_surface (widget);
 
-  gdk_surface_begin_resize_drag (toplevel,
-                                edge, button,
-                                root_x, root_y,
-                                timestamp);
+  gdk_surface_begin_resize_drag (toplevel, edge, button, x, y, timestamp);
 }
 
 /**
  * gtk_window_begin_move_drag:
  * @window: a #GtkWindow
  * @button: mouse button that initiated the drag
- * @root_x: X position where the user clicked to initiate the drag, in root window coordinates
- * @root_y: Y position where the user clicked to initiate the drag
+ * @x: X position where the user clicked to initiate the drag, in window coordinates
+ * @y: Y position where the user clicked to initiate the drag
  * @timestamp: timestamp from the click event that initiated the drag
  *
  * Starts moving a window. This function is used if an application has
- * window movement grips. When GDK can support it, the window movement
- * will be done using the standard mechanism for the
- * [window manager][gtk-X11-arch] or windowing
- * system. Otherwise, GDK will try to emulate window movement,
- * potentially not all that well, depending on the windowing system.
+ * window movement grips.
  */
 void
-gtk_window_begin_move_drag  (GtkWindow *window,
-                             gint       button,
-                             gint       root_x,
-                             gint       root_y,
-                             guint32    timestamp)
+gtk_window_begin_move_drag (GtkWindow *window,
+                            gint       button,
+                            gint       x,
+                            gint       y,
+                            guint32    timestamp)
 {
   GtkWidget *widget;
   GdkSurface *toplevel;
@@ -9298,10 +9284,7 @@ gtk_window_begin_move_drag  (GtkWindow *window,
 
   toplevel = _gtk_widget_get_surface (widget);
 
-  gdk_surface_begin_move_drag (toplevel,
-                              button,
-                              root_x, root_y,
-                              timestamp);
+  gdk_surface_begin_move_drag (toplevel, button, x, y, timestamp);
 }
 
 /**
diff --git a/gtk/gtkwindow.h b/gtk/gtkwindow.h
index 2b7a0078f5..d823f8826e 100644
--- a/gtk/gtkwindow.h
+++ b/gtk/gtkwindow.h
@@ -355,14 +355,14 @@ GDK_AVAILABLE_IN_ALL
 void gtk_window_begin_resize_drag (GtkWindow     *window,
                                    GdkSurfaceEdge  edge,
                                    gint           button,
-                                   gint           root_x,
-                                   gint           root_y,
+                                   gint           x,
+                                   gint           y,
                                    guint32        timestamp);
 GDK_AVAILABLE_IN_ALL
 void gtk_window_begin_move_drag   (GtkWindow     *window,
                                    gint           button,
-                                   gint           root_x,
-                                   gint           root_y,
+                                   gint           x,
+                                   gint           y,
                                    guint32        timestamp);
 
 /* Set initial default size of the window (does not constrain user


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