Hide surface

Matt Hoosier matt.hoosier at gmail.com
Mon Nov 27 18:48:33 UTC 2017


On Sun, Nov 26, 2017 at 2:23 PM, ferreiradaselva
<ferreiradaselva at protonmail.com> wrote:
> Hi,
>
> My first time posting here (sorry if I'm posting on the wrong place).

You're in the right place. Welcome!

>
> I'm working on this window creation framework
> (https://github.com/ferreiradaselva/swfw), and for the Wayland backend I
> need to implement a function to hide the "window".
>
> I found that that is done by destroying the surface (I'm assuming the
> wl_shell_surface). This is currently how I'm trying to do:
>
> =============================
> void swfw_hide_window_wl(struct swfw_window_wl *swfw_win_wl)
> {
>     if (swfw_win_wl->shell_surface) {
>         wl_shell_surface_destroy(swfw_win_wl->shell_surface);
>         swfw_win_wl->shell_surface = NULL;
>         wl_surface_commit(swfw_win_wl->surface);
>     }
> }
>
> void swfw_show_window_wl(struct swfw_window_wl *swfw_win_wl)
> {
>     if (!swfw_win_wl->shell_surface) {
>         swfw_win_wl->shell_surface =
> wl_shell_get_shell_surface(swfw_win_wl->swfw_ctx_wl->shell,
> swfw_win_wl->surface);
>         wl_shell_surface_add_listener(swfw_win_wl->shell_surface,
> &shell_surface_listener, swfw_win_wl);
>         wl_shell_surface_set_toplevel(swfw_win_wl->shell_surface);
>         wl_surface_commit(swfw_win_wl->surface);
>     }
> }
> =============================
>
> However, even after destroying the shell surface, the surface is still
> rendered (testing on weston). Calling the function to show the surface again
> will result in the surface being rendered twice on the screen. I'm also
> using EGL, if that matters somehow.
>
> I couldn't find any example on internet on how to properly hide the surface
> (I couldn't get working with GLFW, and SDL doesn't seem to implement the
> hide function on wayland).

There are a couple levels of abstraction you might choose to approach
your need from. If you're always going to be using wl-shell, then you
can minimize the window. Have a look at wl_shell_surface::minimize.
Depending on the desktop environment, that may be the behavior you
were most closely seeking anyway.

If you simply want the application-defined window content to
disappear, however, then just attach a null buffer to the wl_surface.
That is, wl_surface::attach( NULL ). Upon the next
wl_surface::commit(), the prior renderbuffers will no longer get
painted into the composited scene.


More information about the wayland-devel mailing list