wayland: ask KDE protocol extension to use server-side decorations if possible. SDL-ryan-batching-renderer
authorRyan C. Gordon <icculus@icculus.org>
Mon, 29 Oct 2018 10:14:59 -0400
branchSDL-ryan-batching-renderer
changeset 123678256aaaafe54
parent 12352 2b1707cc57fc
child 12380 f8db1cd5494e
wayland: ask KDE protocol extension to use server-side decorations if possible.
src/video/wayland/SDL_waylandvideo.c
src/video/wayland/SDL_waylandvideo.h
src/video/wayland/SDL_waylandwindow.c
src/video/wayland/SDL_waylandwindow.h
wayland-protocols/org-kde-kwin-server-decoration-manager.xml
     1.1 --- a/src/video/wayland/SDL_waylandvideo.c	Tue Oct 23 01:34:03 2018 -0400
     1.2 +++ b/src/video/wayland/SDL_waylandvideo.c	Mon Oct 29 10:14:59 2018 -0400
     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 "org-kde-kwin-server-decoration-manager-client-protocol.h"
     1.8  
     1.9  #define WAYLANDVID_DRIVER_NAME "wayland"
    1.10  
    1.11 @@ -182,6 +183,7 @@
    1.12      device->SetWindowFullscreen = Wayland_SetWindowFullscreen;
    1.13      device->MaximizeWindow = Wayland_MaximizeWindow;
    1.14      device->RestoreWindow = Wayland_RestoreWindow;
    1.15 +    device->SetWindowBordered = Wayland_SetWindowBordered;
    1.16      device->SetWindowSize = Wayland_SetWindowSize;
    1.17      device->SetWindowTitle = Wayland_SetWindowTitle;
    1.18      device->DestroyWindow = Wayland_DestroyWindow;
    1.19 @@ -345,6 +347,8 @@
    1.20  {
    1.21      SDL_VideoData *d = data;
    1.22  
    1.23 +    /*printf("WAYLAND INTERFACE: %s\n", interface);*/
    1.24 +
    1.25      if (strcmp(interface, "wl_compositor") == 0) {
    1.26          d->compositor = wl_registry_bind(d->registry, id, &wl_compositor_interface, 1);
    1.27      } else if (strcmp(interface, "wl_output") == 0) {
    1.28 @@ -368,6 +372,8 @@
    1.29          Wayland_display_add_pointer_constraints(d, id);
    1.30      } else if (strcmp(interface, "wl_data_device_manager") == 0) {
    1.31          d->data_device_manager = wl_registry_bind(d->registry, id, &wl_data_device_manager_interface, 3);
    1.32 +    } else if (strcmp(interface, "org_kde_kwin_server_decoration_manager") == 0) {
    1.33 +        d->kwin_server_decoration_manager = wl_registry_bind(d->registry, id, &org_kde_kwin_server_decoration_manager_interface, 1);
    1.34  
    1.35  #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
    1.36      } else if (strcmp(interface, "qt_touch_extension") == 0) {
     2.1 --- a/src/video/wayland/SDL_waylandvideo.h	Tue Oct 23 01:34:03 2018 -0400
     2.2 +++ b/src/video/wayland/SDL_waylandvideo.h	Mon Oct 29 10:14:59 2018 -0400
     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 org_kde_kwin_server_decoration_manager *kwin_server_decoration_manager;
     2.8  
     2.9      EGLDisplay edpy;
    2.10      EGLContext context;
     3.1 --- a/src/video/wayland/SDL_waylandwindow.c	Tue Oct 23 01:34:03 2018 -0400
     3.2 +++ b/src/video/wayland/SDL_waylandwindow.c	Mon Oct 29 10:14:59 2018 -0400
     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 "org-kde-kwin-server-decoration-manager-client-protocol.h"
     3.8  
     3.9  /* On modern desktops, we probably will use the xdg-shell protocol instead
    3.10     of wl_shell, but wl_shell might be useful on older Wayland installs that
    3.11 @@ -460,6 +461,17 @@
    3.12  }
    3.13  
    3.14  void
    3.15 +Wayland_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
    3.16 +{
    3.17 +    SDL_WindowData *wind = window->driverdata;
    3.18 +    const SDL_VideoData *viddata = (const SDL_VideoData *) _this->driverdata;
    3.19 +    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 +}
    3.24 +
    3.25 +void
    3.26  Wayland_MaximizeWindow(_THIS, SDL_Window * window)
    3.27  {
    3.28      SDL_WindowData *wind = window->driverdata;
    3.29 @@ -570,6 +582,15 @@
    3.30      }
    3.31  #endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
    3.32  
    3.33 +    if (c->kwin_server_decoration_manager) {
    3.34 +        data->kwin_server_decoration = org_kde_kwin_server_decoration_manager_create(c->kwin_server_decoration_manager, data->surface);
    3.35 +        if (data->kwin_server_decoration) {
    3.36 +            const SDL_bool bordered = (window->flags & SDL_WINDOW_BORDERLESS) == 0;
    3.37 +            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.38 +            org_kde_kwin_server_decoration_request_mode(data->kwin_server_decoration, mode);
    3.39 +        }
    3.40 +    }
    3.41 +
    3.42      region = wl_compositor_create_region(c->compositor);
    3.43      wl_region_add(region, 0, 0, window->w, window->h);
    3.44      wl_surface_set_opaque_region(data->surface, region);
    3.45 @@ -644,6 +665,10 @@
    3.46          SDL_EGL_DestroySurface(_this, wind->egl_surface);
    3.47          WAYLAND_wl_egl_window_destroy(wind->egl_window);
    3.48  
    3.49 +        if (wind->kwin_server_decoration) {
    3.50 +            org_kde_kwin_server_decoration_release(wind->kwin_server_decoration);
    3.51 +        }
    3.52 +
    3.53          if (data->shell.xdg) {
    3.54              if (wind->shell_surface.xdg.roleobj.toplevel) {
    3.55                  xdg_toplevel_destroy(wind->shell_surface.xdg.roleobj.toplevel);
     4.1 --- a/src/video/wayland/SDL_waylandwindow.h	Tue Oct 23 01:34:03 2018 -0400
     4.2 +++ b/src/video/wayland/SDL_waylandwindow.h	Mon Oct 29 10:14:59 2018 -0400
     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 org_kde_kwin_server_decoration *kwin_server_decoration;
     4.8  
     4.9  #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
    4.10      struct qt_extended_surface *extended_surface;
    4.11 @@ -74,6 +75,7 @@
    4.12                                          SDL_bool fullscreen);
    4.13  extern void Wayland_MaximizeWindow(_THIS, SDL_Window * window);
    4.14  extern void Wayland_RestoreWindow(_THIS, SDL_Window * window);
    4.15 +extern void Wayland_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered);
    4.16  extern int Wayland_CreateWindow(_THIS, SDL_Window *window);
    4.17  extern void Wayland_SetWindowSize(_THIS, SDL_Window * window);
    4.18  extern void Wayland_SetWindowTitle(_THIS, SDL_Window * window);
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/wayland-protocols/org-kde-kwin-server-decoration-manager.xml	Mon Oct 29 10:14:59 2018 -0400
     5.3 @@ -0,0 +1,94 @@
     5.4 +<?xml version="1.0" encoding="UTF-8"?>
     5.5 +<protocol name="server_decoration">
     5.6 +  <copyright><![CDATA[
     5.7 +    Copyright (C) 2015 Martin Gräßlin
     5.8 +
     5.9 +    This program is free software: you can redistribute it and/or modify
    5.10 +    it under the terms of the GNU Lesser General Public License as published by
    5.11 +    the Free Software Foundation, either version 2.1 of the License, or
    5.12 +    (at your option) any later version.
    5.13 +
    5.14 +    This program is distributed in the hope that it will be useful,
    5.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.17 +    GNU Lesser General Public License for more details.
    5.18 +
    5.19 +    You should have received a copy of the GNU Lesser General Public License
    5.20 +    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    5.21 +  ]]></copyright>
    5.22 +  <interface  name="org_kde_kwin_server_decoration_manager" version="1">
    5.23 +      <description summary="Server side window decoration manager">
    5.24 +        This interface allows to coordinate whether the server should create
    5.25 +        a server-side window decoration around a wl_surface representing a
    5.26 +        shell surface (wl_shell_surface or similar). By announcing support
    5.27 +        for this interface the server indicates that it supports server
    5.28 +        side decorations.
    5.29 +      </description>
    5.30 +      <request name="create">
    5.31 +        <description summary="Create a server-side decoration object for a given surface">
    5.32 +            When a client creates a server-side decoration object it indicates
    5.33 +            that it supports the protocol. The client is supposed to tell the
    5.34 +            server whether it wants server-side decorations or will provide
    5.35 +            client-side decorations.
    5.36 +
    5.37 +            If the client does not create a server-side decoration object for
    5.38 +            a surface the server interprets this as lack of support for this
    5.39 +            protocol and considers it as client-side decorated. Nevertheless a
    5.40 +            client-side decorated surface should use this protocol to indicate
    5.41 +            to the server that it does not want a server-side deco.
    5.42 +        </description>
    5.43 +        <arg name="id" type="new_id" interface="org_kde_kwin_server_decoration"/>
    5.44 +        <arg name="surface" type="object" interface="wl_surface"/>
    5.45 +      </request>
    5.46 +      <enum name="mode">
    5.47 +            <description summary="Possible values to use in request_mode and the event mode."/>
    5.48 +            <entry name="None" value="0" summary="Undecorated: The surface is not decorated at all, neither server nor client-side. An example is a popup surface which should not be decorated."/>
    5.49 +            <entry name="Client" value="1" summary="Client-side decoration: The decoration is part of the surface and the client."/>
    5.50 +            <entry name="Server" value="2" summary="Server-side decoration: The server embeds the surface into a decoration frame."/>
    5.51 +      </enum>
    5.52 +      <event name="default_mode">
    5.53 +          <description summary="The default mode used on the server">
    5.54 +              This event is emitted directly after binding the interface. It contains
    5.55 +              the default mode for the decoration. When a new server decoration object
    5.56 +              is created this new object will be in the default mode until the first
    5.57 +              request_mode is requested.
    5.58 +
    5.59 +              The server may change the default mode at any time.
    5.60 +          </description>
    5.61 +          <arg name="mode" type="uint" summary="The default decoration mode applied to newly created server decorations."/>
    5.62 +      </event>
    5.63 +  </interface>
    5.64 +  <interface name="org_kde_kwin_server_decoration" version="1">
    5.65 +      <request name="release" type="destructor">
    5.66 +        <description summary="release the server decoration object"/>
    5.67 +      </request>
    5.68 +      <enum name="mode">
    5.69 +            <description summary="Possible values to use in request_mode and the event mode."/>
    5.70 +            <entry name="None" value="0" summary="Undecorated: The surface is not decorated at all, neither server nor client-side. An example is a popup surface which should not be decorated."/>
    5.71 +            <entry name="Client" value="1" summary="Client-side decoration: The decoration is part of the surface and the client."/>
    5.72 +            <entry name="Server" value="2" summary="Server-side decoration: The server embeds the surface into a decoration frame."/>
    5.73 +      </enum>
    5.74 +      <request name="request_mode">
    5.75 +          <description summary="The decoration mode the surface wants to use."/>
    5.76 +          <arg name="mode" type="uint" summary="The mode this surface wants to use."/>
    5.77 +      </request>
    5.78 +      <event name="mode">
    5.79 +          <description summary="The new decoration mode applied by the server">
    5.80 +              This event is emitted directly after the decoration is created and
    5.81 +              represents the base decoration policy by the server. E.g. a server
    5.82 +              which wants all surfaces to be client-side decorated will send Client,
    5.83 +              a server which wants server-side decoration will send Server.
    5.84 +
    5.85 +              The client can request a different mode through the decoration request.
    5.86 +              The server will acknowledge this by another event with the same mode. So
    5.87 +              even if a server prefers server-side decoration it's possible to force a
    5.88 +              client-side decoration.
    5.89 +
    5.90 +              The server may emit this event at any time. In this case the client can
    5.91 +              again request a different mode. It's the responsibility of the server to
    5.92 +              prevent a feedback loop.
    5.93 +          </description>
    5.94 +          <arg name="mode" type="uint" summary="The decoration mode applied to the surface by the server."/>
    5.95 +      </event>
    5.96 +  </interface>
    5.97 +</protocol>