gtk/windowhandle: Delegate titlebar action to the compositor if possible
authorFlorian Müllner <fmuellner@gnome.org>
Thu, 29 Jul 2021 02:00:22 +0000 (04:00 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Thu, 29 Jul 2021 19:39:32 +0000 (21:39 +0200)
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

index 1cf90674050ed61002eac3f197ee81a35ec09c6b..b1494043f28e089ad781b941dbcb465b2fa1c179 100644 (file)
@@ -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,