From f316fe0f58014d6fa24dcc62df01a4a2c1e7d4f7 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 17 May 2020 12:06:26 -0400 Subject: [PATCH] window: Use toplevel begin_move/resize api The GdkSurface api for this is going away. --- gtk/gtkwindow.c | 17 +++++++++-------- gtk/gtkwindowhandle.c | 36 ++++++++++++++++++++---------------- tests/testwindowdrag.c | 4 ++-- 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index ddfb38792f..eb572e5486 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -1218,12 +1218,14 @@ click_gesture_pressed_cb (GtkGestureClick *gesture, GdkEventSequence *sequence; GtkWindowRegion region; GdkEvent *event; + GdkDevice *device; guint button; double tx, ty; sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture)); button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture)); event = gtk_gesture_get_last_event (GTK_GESTURE (gesture), sequence); + device = gtk_gesture_get_device (GTK_GESTURE (gesture)); if (!event) return; @@ -1234,8 +1236,7 @@ click_gesture_pressed_cb (GtkGestureClick *gesture, if (priv->maximized) return; - if (gdk_display_device_is_grabbed (gtk_widget_get_display (GTK_WIDGET (window)), - gtk_gesture_get_device (GTK_GESTURE (gesture)))) + if (gdk_display_device_is_grabbed (gtk_widget_get_display (GTK_WIDGET (window)), device)) return; region = get_active_region_type (window, x, y); @@ -1246,12 +1247,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 (priv->surface, - (GdkSurfaceEdge) region, - gdk_event_get_device ((GdkEvent *) event), - GDK_BUTTON_PRIMARY, - tx, ty, - gdk_event_get_time (event)); + gdk_toplevel_begin_resize (GDK_TOPLEVEL (priv->surface), + (GdkSurfaceEdge) region, + device, + GDK_BUTTON_PRIMARY, + tx, ty, + gdk_event_get_time (event)); gtk_event_controller_reset (GTK_EVENT_CONTROLLER (gesture)); } diff --git a/gtk/gtkwindowhandle.c b/gtk/gtkwindowhandle.c index 3e411465b5..ef1964e433 100644 --- a/gtk/gtkwindowhandle.c +++ b/gtk/gtkwindowhandle.c @@ -113,11 +113,12 @@ move_window_clicked (GtkModelButton *button, GtkNative *native = gtk_widget_get_native (GTK_WIDGET (self)); GdkSurface *surface = gtk_native_get_surface (native); - gdk_surface_begin_move_drag (surface, - NULL, - 0, /* 0 means "use keyboard" */ - 0, 0, - GDK_CURRENT_TIME); + if (GDK_IS_TOPLEVEL (surface)) + gdk_toplevel_begin_move (GDK_TOPLEVEL (surface), + NULL, + 0, /* 0 means "use keyboard" */ + 0, 0, + GDK_CURRENT_TIME); } static void @@ -127,12 +128,13 @@ resize_window_clicked (GtkModelButton *button, GtkNative *native = gtk_widget_get_native (GTK_WIDGET (self)); GdkSurface *surface = gtk_native_get_surface (native); - gdk_surface_begin_resize_drag (surface, - 0, - NULL, - 0, /* 0 means "use keyboard" */ - 0, 0, - GDK_CURRENT_TIME); + if (GDK_IS_TOPLEVEL (surface)) + gdk_toplevel_begin_resize (GDK_TOPLEVEL (surface), + 0, + NULL, + 0, /* 0 means "use keyboard" */ + 0, 0, + GDK_CURRENT_TIME); } static void @@ -475,17 +477,19 @@ drag_gesture_update_cb (GtkGestureDrag *gesture, gtk_gesture_drag_get_start_point (gesture, &start_x, &start_y); native = gtk_widget_get_native (GTK_WIDGET (self)); + gtk_widget_translate_coordinates (GTK_WIDGET (self), GTK_WIDGET (native), start_x, start_y, &window_x, &window_y); surface = gtk_native_get_surface (native); - gdk_surface_begin_move_drag (surface, - gtk_gesture_get_device (GTK_GESTURE (gesture)), - gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture)), - window_x, window_y, - gtk_event_controller_get_current_event_time (GTK_EVENT_CONTROLLER (gesture))); + if (GDK_IS_TOPLEVEL (surface)) + gdk_toplevel_begin_move (GDK_TOPLEVEL (surface), + gtk_gesture_get_device (GTK_GESTURE (gesture)), + gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture)), + window_x, window_y, + gtk_event_controller_get_current_event_time (GTK_EVENT_CONTROLLER (gesture))); gtk_event_controller_reset (GTK_EVENT_CONTROLLER (gesture)); gtk_event_controller_reset (GTK_EVENT_CONTROLLER (self->click_gesture)); diff --git a/tests/testwindowdrag.c b/tests/testwindowdrag.c index 2f8d1539ac..d53a0c17c5 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, gdk_event_get_device (event), button, xx, yy, timestamp); + gdk_toplevel_begin_resize (GDK_TOPLEVEL (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, gdk_event_get_device (event), button, xx, yy, timestamp); + gdk_toplevel_begin_move (GDK_TOPLEVEL (surface), gdk_event_get_device (event), button, xx, yy, timestamp); gtk_event_controller_reset (GTK_EVENT_CONTROLLER (gesture)); }