Overlay with gtk3 on wayland

I made an application using gtk3 that displays notifications by briefly showing an image in the center of the screen. To do this I created a GTK_WINDOW_POPUP window, as I didn’t want decorations and I didn’t want it to show up in the taskbar or pager, and I wanted it to always be on top of everything. I also used gtk_window_input_shape_combine_region to let clicks “pass through” the window.

This worked fine on ubuntu 18 with x11. When I tried it on debian with wayland however, a number of problems appeared. From my understanding it’s not possible to center a window in wayland. I managed to solve this by maximizing (not fullscreen as it had the side effect of hiding some gnome desktop stuff) the window and drawing with an offset so the image appeared centered. But there were a few more problems I had that I didn’t manage to solve:

  • When I used a GTK_WINDOW_POPUP I got warnings in terminal. But if I used GTK_WINDOW_TOPLEVEL then gtk_window_input_shape_combine_region stopped working - my window would eat all click events. So I had to use POPUP and live with the warnings. Also even with POPUP it seemed to work inconsistently.
  • The window now showed up in taskbar ( I also tried explicitly calling gtk_window_set_skip_taskbar_hint)
  • The window now showed up in pager (I also tried explicitly calling gtk_window_set_skip_pager_hint)
  • The window no longer was always on top (I also tried explicitly calling gtk_window_set_keep_above)
  • The picture jumps a little bit a split second after appearing.

When I tried the original code in an x11 session in debian everything was fine.
When I tried the original code in a wayland session in debian but with GDK_BACKEND=x11 everything was also fine.

According to /usr/include/gtk-3.0/gtk/gtkversion.h I’m on major:3, minor:24, micro:5
My mutter version is 3.30.2-9~deb10u1

Yes, Wayland is different from X11, and some things you can do with X11—things like positioning windows directly using global coordinates, or changing the input mask—are not possible with Wayland. Additionally, all the hints API may not work—but those were never guaranteed to work on X11 either, hence the “hint” in their name.

If you want to display a system notification, you should use the notification API. If you want to display what we usually call “an in app notification”, you probably want to look at GdNotification or, use a GtkOverlay widget to display a widget overlaid on top of you window.

My understanding of the GDK_BACKEND=x11 case which I tried and which worked is that
my application <-> gtk <-> xorg <-> mutter
Somehow xorg manages to hint correctly and set input masks when it runs as a wayland client. And if xorg can do it, doesn’t that mean it should be possible for gtk to do it too?

When using the X11 backend for GDK, you’re talking to the X server (XWayland); the output of that server is forwarded to the Wayland compositor, but whatever happens in the X server stays in the X server.

Wayland does have support for input regions, but those are limited to your own window surfaces; you cannot set input regions on windows you did not create within your process, unlike on X11.

Again: Wayland is not X11; as much as GTK can paper over some of the differences when it comes to input and output, the mental model and capabilities of the two windowing system are different.