From: Florian Müllner Date: Thu, 29 Jul 2021 02:00:22 +0000 (+0200) Subject: gtk/windowhandle: Delegate titlebar action to the compositor if possible X-Git-Tag: archive/raspbian/4.4.1+ds1-2+rpi1^2~18^2~1^2~45^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=23e79d2eb2bc9aa4b630ab2dee4b38a8fc70af5c;p=gtk4.git 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 --- 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,