wayland/gtk-shell: Add titlebar_gesture request

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: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1944>
This commit is contained in:
Florian Müllner 2021-07-29 02:42:18 +02:00 committed by Marge Bot
parent eed1db4379
commit 111055acdd
3 changed files with 112 additions and 4 deletions

View File

@ -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 static void
gtk_surface_release (struct wl_client *client, gtk_surface_release (struct wl_client *client,
struct wl_resource *resource) 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_unset_modal,
gtk_surface_present, gtk_surface_present,
gtk_surface_request_focus, gtk_surface_request_focus,
gtk_surface_release gtk_surface_release,
gtk_surface_titlebar_gesture
}; };
static void static void

View File

@ -43,7 +43,7 @@
#define META_WL_SEAT_VERSION 5 #define META_WL_SEAT_VERSION 5
#define META_WL_OUTPUT_VERSION 2 #define META_WL_OUTPUT_VERSION 2
#define META_XSERVER_VERSION 1 #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_WL_SUBCOMPOSITOR_VERSION 1
#define META_ZWP_POINTER_GESTURES_V1_VERSION 1 #define META_ZWP_POINTER_GESTURES_V1_VERSION 1
#define META_ZXDG_EXPORTER_V1_VERSION 1 #define META_ZXDG_EXPORTER_V1_VERSION 1

View File

@ -1,6 +1,6 @@
<protocol name="gtk"> <protocol name="gtk">
<interface name="gtk_shell1" version="4"> <interface name="gtk_shell1" version="5">
<description summary="gtk specific extensions"> <description summary="gtk specific extensions">
gtk_shell is a protocol extension providing additional features for gtk_shell is a protocol extension providing additional features for
clients implementing it. clients implementing it.
@ -35,7 +35,7 @@
</request> </request>
</interface> </interface>
<interface name="gtk_surface1" version="4"> <interface name="gtk_surface1" version="5">
<request name="set_dbus_properties"> <request name="set_dbus_properties">
<arg name="application_id" type="string" allow-null="true"/> <arg name="application_id" type="string" allow-null="true"/>
<arg name="app_menu_path" type="string" allow-null="true"/> <arg name="app_menu_path" type="string" allow-null="true"/>
@ -85,6 +85,23 @@
<!-- Version 4 additions --> <!-- Version 4 additions -->
<request name="release" type="destructor" since="4"/> <request name="release" type="destructor" since="4"/>
<!-- Version 5 additions -->
<enum name="gesture" since="5">
<entry name="double_click" value="1"/>
<entry name="right_click" value="2"/>
<entry name="middle_click" value="3"/>
</enum>
<enum name="error" since="5">
<entry name="invalid_gesture" value="0"/>
</enum>
<request name="titlebar_gesture" since="5">
<arg name="serial" type="uint"/>
<arg name="seat" type="object" interface="wl_seat"/>
<arg name="gesture" type="uint" enum="gesture"/>
</request>
</interface> </interface>
</protocol> </protocol>