[gtk/present-toplevel-2: 5/83] Simplify surface move/drag api
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/present-toplevel-2: 5/83] Simplify surface move/drag api
- Date: Thu, 12 Mar 2020 00:43:25 +0000 (UTC)
commit 78d71eb43964cdf884139aae71cc26b2011d2445
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Feb 29 11:25:32 2020 -0500
Simplify surface move/drag api
Drop the with_device variants, and always pass a device.
gdk/gdksurface.c | 92 ++++++++++++++------------------------------------
gdk/gdksurface.h | 14 +-------
gtk/gtkwindow.c | 24 +++++++------
tests/testwindowdrag.c | 4 +--
4 files changed, 42 insertions(+), 92 deletions(-)
---
diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c
index 8c9a23db10..76aedf90a2 100644
--- a/gdk/gdksurface.c
+++ b/gdk/gdksurface.c
@@ -3408,7 +3408,7 @@ gdk_surface_set_functions (GdkSurface *surface,
}
/**
- * gdk_surface_begin_resize_drag_for_device:
+ * gdk_surface_begin_resize_drag:
* @surface: a toplevel #GdkSurface
* @edge: the edge or corner from which the drag is started
* @device: the device used for the operation
@@ -3421,95 +3421,55 @@ gdk_surface_set_functions (GdkSurface *surface,
* 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 x,
- gint y,
- guint32 timestamp)
-{
- GDK_SURFACE_GET_CLASS (surface)->begin_resize_drag (surface, edge, device, button, x, y, timestamp);
-}
-
-/**
- * gdk_surface_begin_resize_drag:
- * @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
- * @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).
- *
- * This function assumes that the drag is controlled by the
- * client pointer device, use gdk_surface_begin_resize_drag_for_device()
- * to begin a drag with a different device.
- */
-void
gdk_surface_begin_resize_drag (GdkSurface *surface,
GdkSurfaceEdge edge,
+ GdkDevice *device,
gint button,
gint x,
gint y,
guint32 timestamp)
{
- GdkDevice *device;
-
- device = gdk_seat_get_pointer (gdk_display_get_default_seat (surface->display));
- gdk_surface_begin_resize_drag_for_device (surface, edge,
- device, button, x, y, timestamp);
-}
+ if (device == NULL)
+ {
+ GdkSeat *seat = gdk_display_get_default_seat (surface->display);
+ if (button == 0)
+ device = gdk_seat_get_keyboard (seat);
+ else
+ device = gdk_seat_get_pointer (seat);
+ }
-/**
- * gdk_surface_begin_move_drag_for_device:
- * @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
- * @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).
- */
-void
-gdk_surface_begin_move_drag_for_device (GdkSurface *surface,
- GdkDevice *device,
- gint button,
- gint x,
- gint y,
- guint32 timestamp)
-{
- GDK_SURFACE_GET_CLASS (surface)->begin_move_drag (surface,
- device, button, x, y, timestamp);
+ GDK_SURFACE_GET_CLASS (surface)->begin_resize_drag (surface, edge, device, button, x, y, timestamp);
}
/**
* gdk_surface_begin_move_drag:
* @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
* @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).
- *
- * This function assumes that the drag is controlled by the
- * client pointer device, use gdk_surface_begin_move_drag_for_device()
- * to begin a drag with a different device.
*/
void
gdk_surface_begin_move_drag (GdkSurface *surface,
- gint button,
- gint x,
- gint y,
- guint32 timestamp)
+ GdkDevice *device,
+ gint button,
+ gint x,
+ gint y,
+ guint32 timestamp)
{
- GdkDevice *device;
+ if (device == NULL)
+ {
+ GdkSeat *seat = gdk_display_get_default_seat (surface->display);
+ if (button == 0)
+ device = gdk_seat_get_keyboard (seat);
+ else
+ device = gdk_seat_get_pointer (seat);
+ }
- device = gdk_seat_get_pointer (gdk_display_get_default_seat (surface->display));
- gdk_surface_begin_move_drag_for_device (surface, device, button, x, y, timestamp);
+ GDK_SURFACE_GET_CLASS (surface)->begin_move_drag (surface, device, button, x, y, timestamp);
}
/**
diff --git a/gdk/gdksurface.h b/gdk/gdksurface.h
index 67ba05b4ae..5d796d9508 100644
--- a/gdk/gdksurface.h
+++ b/gdk/gdksurface.h
@@ -539,27 +539,15 @@ void gdk_surface_set_opacity (GdkSurface *surface,
GDK_AVAILABLE_IN_ALL
void gdk_surface_begin_resize_drag (GdkSurface *surface,
- GdkSurfaceEdge edge,
- 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 x,
gint y,
guint32 timestamp);
+
GDK_AVAILABLE_IN_ALL
void gdk_surface_begin_move_drag (GdkSurface *surface,
- 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 x,
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index f598e905ee..ee054a20c3 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -1428,12 +1428,12 @@ click_gesture_pressed_cb (GtkGestureClick *gesture,
gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
gdk_event_get_position (event, &tx, &ty);
- gdk_surface_begin_resize_drag_for_device (priv->surface,
- (GdkSurfaceEdge) region,
- gdk_event_get_device ((GdkEvent *) event),
- GDK_BUTTON_PRIMARY,
- tx, ty,
- gdk_event_get_time (event));
+ gdk_surface_begin_resize_drag (priv->surface,
+ (GdkSurfaceEdge) region,
+ gdk_event_get_device ((GdkEvent *) event),
+ GDK_BUTTON_PRIMARY,
+ tx, ty,
+ gdk_event_get_time (event));
gtk_event_controller_reset (GTK_EVENT_CONTROLLER (gesture));
gtk_event_controller_reset (GTK_EVENT_CONTROLLER (priv->drag_gesture));
@@ -1529,11 +1529,11 @@ drag_gesture_update_cb (GtkGestureDrag *gesture,
gtk_gesture_drag_get_start_point (gesture, &start_x, &start_y);
- gdk_surface_begin_move_drag_for_device (priv->surface,
- gtk_gesture_get_device (GTK_GESTURE (gesture)),
- gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE
(gesture)),
- (int)start_x, (int)start_y,
- gtk_get_current_event_time ());
+ gdk_surface_begin_move_drag (priv->surface,
+ gtk_gesture_get_device (GTK_GESTURE (gesture)),
+ gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture)),
+ (int)start_x, (int)start_y,
+ gtk_get_current_event_time ());
gtk_event_controller_reset (GTK_EVENT_CONTROLLER (gesture));
gtk_event_controller_reset (GTK_EVENT_CONTROLLER (priv->click_gesture));
@@ -6688,6 +6688,7 @@ move_window_clicked (GtkModelButton *button,
GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
gdk_surface_begin_move_drag (priv->surface,
+ NULL,
0, /* 0 means "use keyboard" */
0, 0,
GDK_CURRENT_TIME);
@@ -6702,6 +6703,7 @@ resize_window_clicked (GtkModelButton *button,
gdk_surface_begin_resize_drag (priv->surface,
0,
+ NULL,
0, /* 0 means "use keyboard" */
0, 0,
GDK_CURRENT_TIME);
diff --git a/tests/testwindowdrag.c b/tests/testwindowdrag.c
index 90dc9766b6..e25abf0cef 100644
--- a/tests/testwindowdrag.c
+++ b/tests/testwindowdrag.c
@@ -28,7 +28,7 @@ start_resize (GtkGestureClick *gesture,
gtk_widget_translate_coordinates (widget, GTK_WIDGET (gtk_widget_get_root (widget)),
xx, yy, &xx, &yy);
- gdk_surface_begin_resize_drag (surface, edge, button, xx, yy, timestamp);
+ gdk_surface_begin_resize_drag (surface, edge, gdk_event_get_device (event), button, xx, yy, timestamp);
gtk_event_controller_reset (GTK_EVENT_CONTROLLER (gesture));
}
@@ -76,7 +76,7 @@ start_move (GtkGestureClick *gesture,
gtk_widget_translate_coordinates (widget, GTK_WIDGET (gtk_widget_get_root (widget)),
xx, yy, &xx, &yy);
- gdk_surface_begin_move_drag (surface, button, xx, yy, timestamp);
+ gdk_surface_begin_move_drag (surface, gdk_event_get_device (event), button, xx, yy, timestamp);
gtk_event_controller_reset (GTK_EVENT_CONTROLLER (gesture));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]