[PATCH] Add the KDE server decoration protocol

Jonas Ådahl jadahl at gmail.com
Mon Oct 30 05:03:20 UTC 2017

On Fri, Oct 27, 2017 at 01:13:15PM +0100, David Edmundson wrote:
> The server decoration protocol negotiates between the client and server
> whether the client should default to drawing window decorations, and
> informs the compositor what the client is doing.
> This is useful not just for a compostior that is doing decorations
> itself, but much more importantly for a toolkit, such as Qt which
> primarily targets embedded and IVI applications, not to have to modify
> clients
> to add a header bar which makes them usable on a desktop compositor.
> This file is currently copied in multiple places across GTK, Sway as well
> as being needed in both Qt and KDE. We should have this in a shared
> place.

I think that this functionality is in scope for wayland-protocols, but
wayland-protocols was AFAIK never meant as a distribution of arbitrary
external protocols. In the beginning, a major reason why it was created
at all was because wayland.xml was getting too large and it was too
inconvenient to wait for wayland releases for adding a new protocol or
protocol version would we instead add new XML files to the wayland repo.

I'd expect protocols that aim to be included here to be willing to go
through protocol review and adhere to the conventions we have set up.
I have read through the protocol and will provide feedback as if the
protocol aims to follow the conventions we have in place.

> ---
>  unstable/server-decoration/server-decoration.xml | 94
> ++++++++++++++++++++++++
>  1 file changed, 94 insertions(+)
>  create mode 100644 unstable/server-decoration/server-decoration.xml
> diff --git a/unstable/server-decoration/server-decoration.xml
> b/unstable/server-decoration/server-decoration.xml
> new file mode 100644
> index 0000000..8bc106c
> --- /dev/null
> +++ b/unstable/server-decoration/server-decoration.xml
> @@ -0,0 +1,94 @@
> +<?xml version="1.0" encoding="UTF-8"?>
> +<protocol name="server_decoration">
> +  <copyright><![CDATA[
> +    Copyright (C) 2015 Martin Gräßlin
> +
> +    This program is free software: you can redistribute it and/or modify
> +    it under the terms of the GNU Lesser General Public License as
> published by
> +    the Free Software Foundation, either version 2.1 of the License, or
> +    (at your option) any later version.
> +
> +    This program is distributed in the hope that it will be useful,
> +    but WITHOUT ANY WARRANTY; without even the implied warranty of
> +    GNU Lesser General Public License for more details.
> +
> +    You should have received a copy of the GNU Lesser General Public
> License
> +    along with this program.  If not, see <http://www.gnu.org/licenses/>.

As mentioned elsewhere, it mixing different licenses could be somewhat

> +  ]]></copyright>
> +  <interface  name="org_kde_kwin_server_decoration_manager" version="1">

I believe a protocol related to window decorations belong in the "xdg"
family of protocols, extending 'xdg_wm_base'. For example
'xdg_wm_window_decorations' could be the name of a window decoration
extension to xdg_wm_base (that is the main interface of xdg_shell).

> +      <description summary="Server side window decoration manager">
> +        This interface allows to coordinate whether the server should
> create
> +        a server-side window decoration around a wl_surface representing a
> +        shell surface (wl_shell_surface or similar). By announcing support
> +        for this interface the server indicates that it supports server
> +        side decorations.
> +      </description>
> +      <request name="create">
> +        <description summary="Create a server-side decoration object for a
> given surface">
> +            When a client creates a server-side decoration object it
> indicates
> +            that it supports the protocol. The client is supposed to tell
> the
> +            server whether it wants server-side decorations or will provide
> +            client-side decorations.
> +
> +            If the client does not create a server-side decoration object
> for
> +            a surface the server interprets this as lack of support for
> this
> +            protocol and considers it as client-side decorated.
> Nevertheless a
> +            client-side decorated surface should use this protocol to
> indicate
> +            to the server that it does not want a server-side deco.

What is the purpose of a client not supporting server side decorations
to create this object anyway? I assume functionality wise it shouldn't
make any difference right?

> +        </description>
> +        <arg name="id" type="new_id"
> interface="org_kde_kwin_server_decoration"/>
> +        <arg name="surface" type="object" interface="wl_surface"/>
> +      </request>
> +      <enum name="mode">
> +            <description summary="Possible values to use in request_mode
> and the event mode."/>
> +            <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."/>

Why would a popup surface create a window decoration object at all? It
seems pointless. I might be missing something but it seems to only make
any sense to only deal with toplevels. A request creating the window
decoration object could for example require that a surface passed is 'an
xdg_toplevel or equivalent'.

> +            <entry name="Client" value="1" summary="Client-side
> decoration: The decoration is part of the surface and the client."/>
> +            <entry name="Server" value="2" summary="Server-side
> decoration: The server embeds the surface into a decoration frame."/>

style nit: For consistency, use lower case for all entry names. They'll
become upper case anyway in the C file.

> +      </enum>
> +      <event name="default_mode">
> +          <description summary="The default mode used on the server">
> +              This event is emitted directly after binding the interface.
> It contains
> +              the default mode for the decoration. When a new server
> decoration object
> +              is created this new object will be in the default mode until
> the first
> +              request_mode is requested.
> +
> +              The server may change the default mode at any time.
> +          </description>
> +          <arg name="mode" type="uint" summary="The default decoration
> mode applied to newly created server decorations."/>
> +      </event>

Using a potentially changing 'default_mode' seems racy to me, especially
if the protocol allows a client to rely on what is default to choose.
Exposing a 'preferred_mode' that doesn't actually affect the state seems
less prone to races, as a client will then actively take the
'preferred_mode' into consideration when setting up its state.

> +  </interface>
> +  <interface name="org_kde_kwin_server_decoration" version="1">

Correct me if I'm wrong, but this is an object about decorating a
toplevel (i.e. non-popup/non-tooltip) window right? A suggestion of what
to call it is "xdg_toplevel_window_decorator", to indicate that it
extends the xdg_toplevel (or an equivalent).

> +      <request name="release" type="destructor">

This should be "destroy", as otherwise wayland-scanner will create a
_destroy() function that doesn't actually destroy the server side

> +        <description summary="release the server decoration object"/>
> +      </request>
> +      <enum name="mode">
> +            <description summary="Possible values to use in request_mode
> and the event mode."/>
> +            <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."/>
> +            <entry name="Client" value="1" summary="Client-side
> decoration: The decoration is part of the surface and the client."/>
> +            <entry name="Server" value="2" summary="Server-side
> decoration: The server embeds the surface into a decoration frame."/>
> +      </enum>

No need to redefine the same mode enum here. Just use the one in the
parent interface.

> +      <request name="request_mode">
> +          <description summary="The decoration mode the surface wants to
> use."/>
> +          <arg name="mode" type="uint" summary="The mode this surface
> wants to use."/>
> +      </request>

For consistency with other xdg_* protocols, I'd suggest calling this
"set_mode" instead.

> +      <event name="mode">
> +          <description summary="The new decoration mode applied by the
> server">
> +              This event is emitted directly after the decoration is
> created and
> +              represents the base decoration policy by the server. E.g. a
> server
> +              which wants all surfaces to be client-side decorated will
> send Client,
> +              a server which wants server-side decoration will send Server.
> +
> +              The client can request a different mode through the
> decoration request.
> +              The server will acknowledge this by another event with the
> same mode. So
> +              even if a server prefers server-side decoration it's
> possible to force a
> +              client-side decoration.
> +
> +              The server may emit this event at any time. In this case the
> client can
> +              again request a different mode. It's the responsibility of
> the server to
> +              prevent a feedback loop.

The way this seem to work seems racy, as it doesn't contain any
information about how to guarantee that a window is displayed properly
every frame. I think it should instead make use of the mechanism we now
have in place that is meant to fix exactly this type of problems:
xdg_surface.configure & xdg_surface.ack_configure. By using extending
that functionality, a client and compositor can negotiate a state while
guaranteeing that when a client sends a surface state, the compositor
will know exactly what its configuration is. xdg_toplevel and xdg_popup
already extends this functionality for negotiating state, and a
decoration protocol should do the same.

I also don't think it makes any sense for the server to notify about a
state which the client may not support, relying on the client to
"override" the configuration it was given.

I imagine it should rather look like something like this (making use of
wl_surface.commit, xdg_surface.configure and xdg_surface.ack_configure).

1) A client binds the decoration manager interface and receives a
'preferred' mode.

decoration_manager = bind(xdg_wm_window_decoration_manager)
preferred_mode = receive manager.preferred_mode

2) A client creates a toplevel window and sets up initial state,
including decoration specifics. Lets say the preferred mode is 'server'.

wl_surface = wl_compositor.create_surface()
xdg_surface = xdg_wm_base.get_xdg_surface(wl_surface)
xdg_toplevel = xdg_surface.get_toplevel(xdg_surface)
xdg_toplevel_decorator = decoration_manager.decorate(xdg_toplevel)

At this ponit in time, the client doesn't know how to draw itself, as
the compositor is the one who will making decisions about various state,
such as being maximized etc.

3) The compositor configures the surface. Lets say it is initially
maximized, for example because it had a rule about maximizing the
window of "app_id" or something. The decorator.configure() is simply
what the client asked for.

xdg_toplevel.configure(1024, 728, ['maximized', 'active'])
xdg_surface.configure(1234) # 1234 = configuration serial

When receiving xdg_surface.configure, the client knows exactly how it
should draw its window. It should use the window geometry size 1024x728,
it should draw it undecorated (because the server draws the decoration),
and it should draw it as if it is active ("focused").

4) The clients draws and commits the first frame, as desccribed above

buffer = create_buffer(1024, 728)
draw(buffer) # draw given the known state

This would guarantee that the first frame is drawn correctly. If the
preferred mode would change mid-session, the compositor would send a new
preferred_mode 'client', the client would issue something like tho


(Note, no new buffer attached, thus no new content, this is the same way
as a client maximizes/unmaximizes etc).

The compositor would then in the same way as shown in the above step #3
configure the surface with a new state, with a new serial, and the
client would then response with new surface content while ack:ing the


> +          </description>
> +          <arg name="mode" type="uint" summary="The decoration mode
> applied to the surface by the server."/>
> +      </event>
> +  </interface>
> +</protocol>
> -- 
> 2.14.1

> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/wayland-devel

More information about the wayland-devel mailing list