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.
This commit is contained in:
Matthias Clasen 2019-03-23 14:56:21 -04:00
parent 6b6f26ed45
commit d45996c728
6 changed files with 102 additions and 120 deletions

View File

@ -4868,27 +4868,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);
}
/**
@ -4896,8 +4892,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).
@ -4909,10 +4905,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;
@ -4920,7 +4916,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);
}
/**
@ -4928,34 +4924,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).
@ -4967,8 +4959,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;
@ -4976,7 +4968,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);
}
/**

View File

@ -731,31 +731,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

View File

@ -3556,8 +3556,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;
@ -3646,8 +3646,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;

View File

@ -4293,12 +4293,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);
@ -4338,17 +4338,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);
@ -4358,12 +4362,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))
@ -4374,6 +4379,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);

View File

@ -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));
@ -9126,24 +9123,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;
@ -9154,33 +9147,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;
@ -9191,10 +9177,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);
}
/**

View File

@ -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