waylandwindow-decoration

Wayland window decorations


I am writing a Wayland client, using only the Wayland C library (wayland-client.h). I want to spend as less effort as needed to add window decorations for moving, resizing, minimising and closing the window.

The options I see are: a) request the compositor to draw window decorations around my Wayland surface (server side decorations), or b) use a small library or code snipped to draw the decorations myself in the client (client side decorations).

Which ways exist to achieve both of the options? E.g. for the simple hello_wayland example, how do I request server side decorations (a) or how can I draw window decorations in the client (b)? For the latter option, I am looking for something like the Rust library https://github.com/Smithay/wayland-window, but for C/C++.

Edit: For the client-side decoration option (b) I found the dedicated decoration library libdecor.


Solution

  • UPDATE: In case you don't read comments, just want to highlight that the protocol outlined in the original answer as proposed has since been accepted into unstable. https://github.com/wayland-project/wayland-protocols/commit/76d1ae8c65739eff3434ef219c58a913ad34e988

    ORIGINAL: Right now, there is no standard/stable way to do server-side decorations on Wayland. The protocol itself doesn't disallow for server-side decorations, but it certainly did not seem to prioritize it. (Though, the complaint is moot since the shell protocol is being redefined for desktops under the xdg-namespaced protocols anyways.)

    KDE obviously was impacted by this, especially since server-side decorations are used for Plasma Shell to maintain consistent theming. The KDE folks have a protocol extension for their implementation called simply "server-decorations" KWayland server-decorations. You could test for this interface, and utilize it if it is present.

    The more long-term solution still hasn't landed yet. This is something that the group of people working on Wayland protocols (likely the XDG ones) will have to agree upon. There was an attempt to roll this into the xdg-namespaced Wayland protocols under the name xdg-toplevel-decoration. The patch eventually being marked superseded. The latest attempt to patch this protocol in is still in the proposal state - xdg-decoration.

    Without server-side decorations, you're stuck drawing your own decorations (as well as handling the key events to make the window functional). I feel like the a protocol will appear at some point for this - lack of one begs for a ton of extension protocols and code smell checking for each and every one of them. Nonetheless, I am hopeful that the current lack of action is because the proposal phase for a new protocol is picky by nature. It's very difficult to change a protocol after its been issued as stable, so it will likely take time to see this even enter an unstable state.

    My recommendation is to continue to show support for this kind of change, but exercise patience and don't assume it will come any time soon (we aren't even in possession of an unstable state of a protocol). In the meantime, if you really want to get work done, check for KDE's server-decorations protocol extension, and use that if it is available. And don't assume that it will be available.