From 111055acdd5433c648509e190509d861fb1ef03a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Thu, 29 Jul 2021 02:42:18 +0200 Subject: [PATCH] wayland/gtk-shell: Add titlebar_gesture request MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows client to delegate titlebar gestures to the compositor, which allows for better consistency with server-side decorations, and a wider range of actions (including lower-on-middle-click). The protocol addition is based on a suggestion from Carlos Garnacho and Jonas Ã…dahl. https://gitlab.gnome.org/GNOME/mutter/-/issues/602 Part-of: --- src/wayland/meta-wayland-gtk-shell.c | 93 +++++++++++++++++++++++++++- src/wayland/meta-wayland-versions.h | 2 +- src/wayland/protocol/gtk-shell.xml | 21 ++++++- 3 files changed, 112 insertions(+), 4 deletions(-) diff --git a/src/wayland/meta-wayland-gtk-shell.c b/src/wayland/meta-wayland-gtk-shell.c index 12e1b0e4a..1ec5ffdf4 100644 --- a/src/wayland/meta-wayland-gtk-shell.c +++ b/src/wayland/meta-wayland-gtk-shell.c @@ -208,6 +208,96 @@ gtk_surface_request_focus (struct wl_client *client, } } +static void +gtk_surface_titlebar_gesture (struct wl_client *client, + struct wl_resource *resource, + uint32_t serial, + struct wl_resource *seat_resource, + uint32_t gesture) +{ + MetaWaylandGtkSurface *gtk_surface = wl_resource_get_user_data (resource); + MetaWaylandSurface *surface = gtk_surface->surface; + MetaWaylandSeat *seat = wl_resource_get_user_data (seat_resource); + GDesktopTitlebarAction action = G_DESKTOP_TITLEBAR_ACTION_NONE; + MetaWindow *window; + float x, y; + + if (!surface) + return; + + window = meta_wayland_surface_get_window (surface); + if (!window) + return; + + if (!meta_wayland_seat_get_grab_info (seat, surface, serial, FALSE, &x, &y)) + return; + + switch (gesture) + { + case GTK_SURFACE1_GESTURE_DOUBLE_CLICK: + action = meta_prefs_get_action_double_click_titlebar (); + break; + case GTK_SURFACE1_GESTURE_RIGHT_CLICK: + action = meta_prefs_get_action_right_click_titlebar (); + break; + case GTK_SURFACE1_GESTURE_MIDDLE_CLICK: + action = meta_prefs_get_action_middle_click_titlebar (); + break; + default: + wl_resource_post_error (resource, + GTK_SURFACE1_ERROR_INVALID_GESTURE, + "Invalid gesture passed"); + break; + } + + switch (action) + { + case G_DESKTOP_TITLEBAR_ACTION_TOGGLE_MAXIMIZE: + if (META_WINDOW_MAXIMIZED (window)) + meta_window_unmaximize (window, META_MAXIMIZE_BOTH); + else + meta_window_maximize (window, META_MAXIMIZE_BOTH); + break; + + case G_DESKTOP_TITLEBAR_ACTION_TOGGLE_MAXIMIZE_HORIZONTALLY: + if (META_WINDOW_MAXIMIZED_HORIZONTALLY (window)) + meta_window_unmaximize (window, META_MAXIMIZE_HORIZONTAL); + else + meta_window_maximize (window, META_MAXIMIZE_HORIZONTAL); + break; + + case G_DESKTOP_TITLEBAR_ACTION_TOGGLE_MAXIMIZE_VERTICALLY: + if (META_WINDOW_MAXIMIZED_VERTICALLY (window)) + meta_window_unmaximize (window, META_MAXIMIZE_VERTICAL); + else + meta_window_maximize (window, META_MAXIMIZE_VERTICAL); + break; + + case G_DESKTOP_TITLEBAR_ACTION_MINIMIZE: + meta_window_minimize (window); + break; + + case G_DESKTOP_TITLEBAR_ACTION_LOWER: + { + uint32_t timestamp; + + timestamp = meta_display_get_current_time_roundtrip (window->display); + meta_window_lower_with_transients (window, timestamp); + } + break; + + case G_DESKTOP_TITLEBAR_ACTION_MENU: + meta_window_show_menu (window, META_WINDOW_MENU_WM, x, y); + break; + + case G_DESKTOP_TITLEBAR_ACTION_TOGGLE_SHADE: + g_warning ("No shade! The library is closed."); + G_GNUC_FALLTHROUGH; + default: + return; + } +} + static void gtk_surface_release (struct wl_client *client, struct wl_resource *resource) @@ -221,7 +311,8 @@ static const struct gtk_surface1_interface meta_wayland_gtk_surface_interface = gtk_surface_unset_modal, gtk_surface_present, gtk_surface_request_focus, - gtk_surface_release + gtk_surface_release, + gtk_surface_titlebar_gesture }; static void diff --git a/src/wayland/meta-wayland-versions.h b/src/wayland/meta-wayland-versions.h index 05dd937b2..0e859b900 100644 --- a/src/wayland/meta-wayland-versions.h +++ b/src/wayland/meta-wayland-versions.h @@ -43,7 +43,7 @@ #define META_WL_SEAT_VERSION 5 #define META_WL_OUTPUT_VERSION 2 #define META_XSERVER_VERSION 1 -#define META_GTK_SHELL1_VERSION 4 +#define META_GTK_SHELL1_VERSION 5 #define META_WL_SUBCOMPOSITOR_VERSION 1 #define META_ZWP_POINTER_GESTURES_V1_VERSION 1 #define META_ZXDG_EXPORTER_V1_VERSION 1 diff --git a/src/wayland/protocol/gtk-shell.xml b/src/wayland/protocol/gtk-shell.xml index 1aab593c4..a8d51c65d 100644 --- a/src/wayland/protocol/gtk-shell.xml +++ b/src/wayland/protocol/gtk-shell.xml @@ -1,6 +1,6 @@ - + gtk_shell is a protocol extension providing additional features for clients implementing it. @@ -35,7 +35,7 @@ - + @@ -85,6 +85,23 @@ + + + + + + + + + + + + + + + + +