wayland: ask xdg-decoration protocol extension to use server-side decorations if possible.
1.1 --- a/src/video/wayland/SDL_waylandvideo.c Tue Nov 20 10:55:00 2018 +0300
1.2 +++ b/src/video/wayland/SDL_waylandvideo.c Sun Nov 04 21:08:40 2018 +0100
1.3 @@ -47,6 +47,7 @@
1.4
1.5 #include "xdg-shell-client-protocol.h"
1.6 #include "xdg-shell-unstable-v6-client-protocol.h"
1.7 +#include "xdg-decoration-unstable-v1-client-protocol.h"
1.8 #include "org-kde-kwin-server-decoration-manager-client-protocol.h"
1.9
1.10 #define WAYLANDVID_DRIVER_NAME "wayland"
1.11 @@ -372,6 +373,8 @@
1.12 Wayland_display_add_pointer_constraints(d, id);
1.13 } else if (strcmp(interface, "wl_data_device_manager") == 0) {
1.14 d->data_device_manager = wl_registry_bind(d->registry, id, &wl_data_device_manager_interface, 3);
1.15 + } else if (strcmp(interface, "zxdg_decoration_manager_v1") == 0) {
1.16 + d->decoration_manager = wl_registry_bind(d->registry, id, &zxdg_decoration_manager_v1_interface, 1);
1.17 } else if (strcmp(interface, "org_kde_kwin_server_decoration_manager") == 0) {
1.18 d->kwin_server_decoration_manager = wl_registry_bind(d->registry, id, &org_kde_kwin_server_decoration_manager_interface, 1);
1.19
2.1 --- a/src/video/wayland/SDL_waylandvideo.h Tue Nov 20 10:55:00 2018 +0300
2.2 +++ b/src/video/wayland/SDL_waylandvideo.h Sun Nov 04 21:08:40 2018 +0100
2.3 @@ -61,6 +61,7 @@
2.4 struct zwp_relative_pointer_manager_v1 *relative_pointer_manager;
2.5 struct zwp_pointer_constraints_v1 *pointer_constraints;
2.6 struct wl_data_device_manager *data_device_manager;
2.7 + struct zxdg_decoration_manager_v1 *decoration_manager;
2.8 struct org_kde_kwin_server_decoration_manager *kwin_server_decoration_manager;
2.9
2.10 EGLDisplay edpy;
3.1 --- a/src/video/wayland/SDL_waylandwindow.c Tue Nov 20 10:55:00 2018 +0300
3.2 +++ b/src/video/wayland/SDL_waylandwindow.c Sun Nov 04 21:08:40 2018 +0100
3.3 @@ -35,6 +35,7 @@
3.4
3.5 #include "xdg-shell-client-protocol.h"
3.6 #include "xdg-shell-unstable-v6-client-protocol.h"
3.7 +#include "xdg-decoration-unstable-v1-client-protocol.h"
3.8 #include "org-kde-kwin-server-decoration-manager-client-protocol.h"
3.9
3.10 /* On modern desktops, we probably will use the xdg-shell protocol instead
3.11 @@ -498,7 +499,10 @@
3.12 {
3.13 SDL_WindowData *wind = window->driverdata;
3.14 const SDL_VideoData *viddata = (const SDL_VideoData *) _this->driverdata;
3.15 - if ((viddata->kwin_server_decoration_manager) && (wind->kwin_server_decoration)) {
3.16 + if ((viddata->decoration_manager) && (wind->server_decoration)) {
3.17 + const enum zxdg_toplevel_decoration_v1_mode mode = bordered ? ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE : ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE;
3.18 + zxdg_toplevel_decoration_v1_set_mode(wind->server_decoration, mode);
3.19 + } else if ((viddata->kwin_server_decoration_manager) && (wind->kwin_server_decoration)) {
3.20 const enum org_kde_kwin_server_decoration_mode mode = bordered ? ORG_KDE_KWIN_SERVER_DECORATION_MANAGER_MODE_SERVER : ORG_KDE_KWIN_SERVER_DECORATION_MANAGER_MODE_NONE;
3.21 org_kde_kwin_server_decoration_request_mode(wind->kwin_server_decoration, mode);
3.22 }
3.23 @@ -617,7 +621,14 @@
3.24 }
3.25 #endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
3.26
3.27 - if (c->kwin_server_decoration_manager) {
3.28 + if (c->decoration_manager && c->shell.xdg && data->shell_surface.xdg.surface) {
3.29 + data->server_decoration = zxdg_decoration_manager_v1_get_toplevel_decoration(c->decoration_manager, data->shell_surface.xdg.roleobj.toplevel);
3.30 + if (data->server_decoration) {
3.31 + const SDL_bool bordered = (window->flags & SDL_WINDOW_BORDERLESS) == 0;
3.32 + const enum zxdg_toplevel_decoration_v1_mode mode = bordered ? ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE : ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE;
3.33 + zxdg_toplevel_decoration_v1_set_mode(data->server_decoration, mode);
3.34 + }
3.35 + } else if (c->kwin_server_decoration_manager) {
3.36 data->kwin_server_decoration = org_kde_kwin_server_decoration_manager_create(c->kwin_server_decoration_manager, data->surface);
3.37 if (data->kwin_server_decoration) {
3.38 const SDL_bool bordered = (window->flags & SDL_WINDOW_BORDERLESS) == 0;
3.39 @@ -700,6 +711,10 @@
3.40 SDL_EGL_DestroySurface(_this, wind->egl_surface);
3.41 WAYLAND_wl_egl_window_destroy(wind->egl_window);
3.42
3.43 + if (wind->server_decoration) {
3.44 + zxdg_toplevel_decoration_v1_destroy(wind->server_decoration);
3.45 + }
3.46 +
3.47 if (wind->kwin_server_decoration) {
3.48 org_kde_kwin_server_decoration_release(wind->kwin_server_decoration);
3.49 }
4.1 --- a/src/video/wayland/SDL_waylandwindow.h Tue Nov 20 10:55:00 2018 +0300
4.2 +++ b/src/video/wayland/SDL_waylandwindow.h Sun Nov 04 21:08:40 2018 +0100
4.3 @@ -62,6 +62,7 @@
4.4 struct SDL_WaylandInput *keyboard_device;
4.5 EGLSurface egl_surface;
4.6 struct zwp_locked_pointer_v1 *locked_pointer;
4.7 + struct zxdg_toplevel_decoration_v1 *server_decoration;
4.8 struct org_kde_kwin_server_decoration *kwin_server_decoration;
4.9
4.10 #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/wayland-protocols/xdg-decoration-unstable-v1.xml Sun Nov 04 21:08:40 2018 +0100
5.3 @@ -0,0 +1,156 @@
5.4 +<?xml version="1.0" encoding="UTF-8"?>
5.5 +<protocol name="xdg_decoration_unstable_v1">
5.6 + <copyright>
5.7 + Copyright © 2018 Simon Ser
5.8 +
5.9 + Permission is hereby granted, free of charge, to any person obtaining a
5.10 + copy of this software and associated documentation files (the "Software"),
5.11 + to deal in the Software without restriction, including without limitation
5.12 + the rights to use, copy, modify, merge, publish, distribute, sublicense,
5.13 + and/or sell copies of the Software, and to permit persons to whom the
5.14 + Software is furnished to do so, subject to the following conditions:
5.15 +
5.16 + The above copyright notice and this permission notice (including the next
5.17 + paragraph) shall be included in all copies or substantial portions of the
5.18 + Software.
5.19 +
5.20 + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5.21 + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
5.22 + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
5.23 + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
5.24 + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
5.25 + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
5.26 + DEALINGS IN THE SOFTWARE.
5.27 + </copyright>
5.28 +
5.29 + <interface name="zxdg_decoration_manager_v1" version="1">
5.30 + <description summary="window decoration manager">
5.31 + This interface allows a compositor to announce support for server-side
5.32 + decorations.
5.33 +
5.34 + A window decoration is a set of window controls as deemed appropriate by
5.35 + the party managing them, such as user interface components used to move,
5.36 + resize and change a window's state.
5.37 +
5.38 + A client can use this protocol to request being decorated by a supporting
5.39 + compositor.
5.40 +
5.41 + If compositor and client do not negotiate the use of a server-side
5.42 + decoration using this protocol, clients continue to self-decorate as they
5.43 + see fit.
5.44 +
5.45 + Warning! The protocol described in this file is experimental and
5.46 + backward incompatible changes may be made. Backward compatible changes
5.47 + may be added together with the corresponding interface version bump.
5.48 + Backward incompatible changes are done by bumping the version number in
5.49 + the protocol and interface names and resetting the interface version.
5.50 + Once the protocol is to be declared stable, the 'z' prefix and the
5.51 + version number in the protocol and interface names are removed and the
5.52 + interface version number is reset.
5.53 + </description>
5.54 +
5.55 + <request name="destroy" type="destructor">
5.56 + <description summary="destroy the decoration manager object">
5.57 + Destroy the decoration manager. This doesn't destroy objects created
5.58 + with the manager.
5.59 + </description>
5.60 + </request>
5.61 +
5.62 + <request name="get_toplevel_decoration">
5.63 + <description summary="create a new toplevel decoration object">
5.64 + Create a new decoration object associated with the given toplevel.
5.65 +
5.66 + Creating an xdg_toplevel_decoration from an xdg_toplevel which has a
5.67 + buffer attached or committed is a client error, and any attempts by a
5.68 + client to attach or manipulate a buffer prior to the first
5.69 + xdg_toplevel_decoration.configure event must also be treated as
5.70 + errors.
5.71 + </description>
5.72 + <arg name="id" type="new_id" interface="zxdg_toplevel_decoration_v1"/>
5.73 + <arg name="toplevel" type="object" interface="xdg_toplevel"/>
5.74 + </request>
5.75 + </interface>
5.76 +
5.77 + <interface name="zxdg_toplevel_decoration_v1" version="1">
5.78 + <description summary="decoration object for a toplevel surface">
5.79 + The decoration object allows the compositor to toggle server-side window
5.80 + decorations for a toplevel surface. The client can request to switch to
5.81 + another mode.
5.82 +
5.83 + The xdg_toplevel_decoration object must be destroyed before its
5.84 + xdg_toplevel.
5.85 + </description>
5.86 +
5.87 + <enum name="error">
5.88 + <entry name="unconfigured_buffer" value="0"
5.89 + summary="xdg_toplevel has a buffer attached before configure"/>
5.90 + <entry name="already_constructed" value="1"
5.91 + summary="xdg_toplevel already has a decoration object"/>
5.92 + <entry name="orphaned" value="2"
5.93 + summary="xdg_toplevel destroyed before the decoration object"/>
5.94 + </enum>
5.95 +
5.96 + <request name="destroy" type="destructor">
5.97 + <description summary="destroy the decoration object">
5.98 + Switch back to a mode without any server-side decorations at the next
5.99 + commit.
5.100 + </description>
5.101 + </request>
5.102 +
5.103 + <enum name="mode">
5.104 + <description summary="window decoration modes">
5.105 + These values describe window decoration modes.
5.106 + </description>
5.107 + <entry name="client_side" value="1"
5.108 + summary="no server-side window decoration"/>
5.109 + <entry name="server_side" value="2"
5.110 + summary="server-side window decoration"/>
5.111 + </enum>
5.112 +
5.113 + <request name="set_mode">
5.114 + <description summary="set the decoration mode">
5.115 + Set the toplevel surface decoration mode. This informs the compositor
5.116 + that the client prefers the provided decoration mode.
5.117 +
5.118 + After requesting a decoration mode, the compositor will respond by
5.119 + emitting a xdg_surface.configure event. The client should then update
5.120 + its content, drawing it without decorations if the received mode is
5.121 + server-side decorations. The client must also acknowledge the configure
5.122 + when committing the new content (see xdg_surface.ack_configure).
5.123 +
5.124 + The compositor can decide not to use the client's mode and enforce a
5.125 + different mode instead.
5.126 +
5.127 + Clients whose decoration mode depend on the xdg_toplevel state may send
5.128 + a set_mode request in response to a xdg_surface.configure event and wait
5.129 + for the next xdg_surface.configure event to prevent unwanted state.
5.130 + Such clients are responsible for preventing configure loops and must
5.131 + make sure not to send multiple successive set_mode requests with the
5.132 + same decoration mode.
5.133 + </description>
5.134 + <arg name="mode" type="uint" enum="mode" summary="the decoration mode"/>
5.135 + </request>
5.136 +
5.137 + <request name="unset_mode">
5.138 + <description summary="unset the decoration mode">
5.139 + Unset the toplevel surface decoration mode. This informs the compositor
5.140 + that the client doesn't prefer a particular decoration mode.
5.141 +
5.142 + This request has the same semantics as set_mode.
5.143 + </description>
5.144 + </request>
5.145 +
5.146 + <event name="configure">
5.147 + <description summary="suggest a surface change">
5.148 + The configure event asks the client to change its decoration mode. The
5.149 + configured state should not be applied immediately. Clients must send an
5.150 + ack_configure in response to this event. See xdg_surface.configure and
5.151 + xdg_surface.ack_configure for details.
5.152 +
5.153 + A configure event can be sent at any time. The specified mode must be
5.154 + obeyed by the client.
5.155 + </description>
5.156 + <arg name="mode" type="uint" enum="mode" summary="the decoration mode"/>
5.157 + </event>
5.158 + </interface>
5.159 +</protocol>