From 23e79d2eb2bc9aa4b630ab2dee4b38a8fc70af5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Thu, 29 Jul 2021 04:00:22 +0200 Subject: gtk/windowhandle: Delegate titlebar action to the compositor if possible Delegating the action to the compositor not only improves consistency with server-side decorations, but also allows for actions that aren't available client-side (like lower-in-middle-click). https://gitlab.gnome.org/GNOME/mutter/-/issues/602 --- gtk/gtkwindowhandle.c | 52 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 10 deletions(-) (limited to 'gtk') diff --git a/gtk/gtkwindowhandle.c b/gtk/gtkwindowhandle.c index 1cf9067405..b1494043f2 100644 --- a/gtk/gtkwindowhandle.c +++ b/gtk/gtkwindowhandle.c @@ -266,26 +266,24 @@ do_popup (GtkWindowHandle *self, } static gboolean -perform_titlebar_action (GtkWindowHandle *self, - GdkEvent *event, - guint button, - int n_press) +perform_titlebar_action_fallback (GtkWindowHandle *self, + GdkEvent *event, + GdkTitlebarGesture gesture) { GtkSettings *settings; char *action = NULL; gboolean retval = TRUE; settings = gtk_widget_get_settings (GTK_WIDGET (self)); - switch (button) + switch (gesture) { - case GDK_BUTTON_PRIMARY: - if (n_press == 2) - g_object_get (settings, "gtk-titlebar-double-click", &action, NULL); + case GDK_TITLEBAR_GESTURE_DOUBLE_CLICK: + g_object_get (settings, "gtk-titlebar-double-click", &action, NULL); break; - case GDK_BUTTON_MIDDLE: + case GDK_TITLEBAR_GESTURE_MIDDLE_CLICK: g_object_get (settings, "gtk-titlebar-middle-click", &action, NULL); break; - case GDK_BUTTON_SECONDARY: + case GDK_TITLEBAR_GESTURE_RIGHT_CLICK: g_object_get (settings, "gtk-titlebar-right-click", &action, NULL); break; default: @@ -320,6 +318,40 @@ perform_titlebar_action (GtkWindowHandle *self, return retval; } +static gboolean +perform_titlebar_action (GtkWindowHandle *self, + GdkEvent *event, + guint button, + int n_press) +{ + GdkSurface *surface = + gtk_native_get_surface (gtk_widget_get_native (GTK_WIDGET (self))); + GdkTitlebarGesture gesture; + + switch (button) + { + case GDK_BUTTON_PRIMARY: + if (n_press == 2) + gesture = GDK_TITLEBAR_GESTURE_DOUBLE_CLICK; + else + return FALSE; + break; + case GDK_BUTTON_MIDDLE: + gesture = GDK_TITLEBAR_GESTURE_MIDDLE_CLICK; + break; + case GDK_BUTTON_SECONDARY: + gesture = GDK_TITLEBAR_GESTURE_RIGHT_CLICK; + break; + default: + break; + } + + if (gdk_toplevel_titlebar_gesture (GDK_TOPLEVEL (surface), gesture)) + return TRUE; + + return perform_titlebar_action_fallback (self, event, gesture); +} + static void click_gesture_pressed_cb (GtkGestureClick *gesture, int n_press, -- cgit v1.2.1