Is there subsurface support for wayland?

GTK does not support wayland subsurface, but i see a popup type window which is also positioned relative to its parent. So my question is how is this supported under wayland protocol if the subsurface is not used. I am thinking about a scenario where I need to position multiple windows in different positions, and it seems no way to control the position of these windows unless a subsurface is used. Or i am having the wrong understanding of subsurface in gtk, it is just still buried somewhere, wrapped in something else?

Thanks!

Hello, the popups in GTK4 are done with xdg_popup instead of subsurfaces. Wayland subsurfaces are not really meant to do popups, they are supposed to be for embedded plugins and video players and such.

In general, you can run Wayland programs with the environment variable WAYLAND_DEBUG=1 to see a log of what protocol requests are sent.

for example, i have a main window, full screen, and inside the main window, i want to have some other windows like view window on the left part, then right half is another window for example project window. Imaging vs code window layout. So if i am not able to control positions of these windows, how am i suppose to achieve this? @jfrancis the popup in gtk3 is using subsurface actually, but it is not recommended. I guess to setup positions for these accessory windows, there is some way to control their position right? How does the positioning work in wayland without subsurface in place, xdg_shell?

In GTK if you want to have different things on each side of a window then you would use widgets and layouts, like a box layout or a pane. You do not need additional Wayland surfaces. Are you thinking something similar to GNOME Builder?

There is another xdg_positioner object that sets some rules for where the popup can be placed relative to the parent surface. But it is not meant to guarantee any position. It should only be used for popup menus and tooltips and such, not widgets that are actually part of the main windows of the app.

@jfrancis since i am working with wayland, and i want to customize my window. So what i did is to use
gdk_wayland_window_get_wl_surface on the native window from the widget. When doing this, it seems gtk has already assigned a surface role to the underlying surface created.

parent = gtk_fixed_new()
window = gtk_drawing_area_new()
gtk_fixed_put(parent,window)
xdg_surface = xdg_shell_get_xdg_surface (
gdk_wayland_display_get_xdg_shell(window)
gdk_wayland_window_get_wl_surface(window)));
xdg_surface_set_window_geometry(xdg_surface ,x,y,w,h);
… finally
egl_swapbuffer()

what i would like to do is to repeat the above step for each ‘sub-window’ inside the fix container, and put them in the designed location one by one.

This would fail with wayland protocol error. As I checked with gtk, each drawArea will have the same surface with its parent, but it is confusing why getting the wayland surface and change its surface role won’t work.

By customize i meant to be able to control where this item is placed approximately, and how its appearance looks like.

If all you need is a place to draw some OpenGL content then there is no need to use “sub-windows” or wayland subsurfaces, just use a GtkGLArea. You can put multiple of them in the same window. Wayland subsurfaces are not the same as child windows in X11 and you should not try to use them as such.

in x11 it is easy to work with a native x11 window as glx provides the functionality and sets the window position and the associated surface where i wanted. Wayland does not allow me to do so, which is painful to figure out how things work…

again, it looks like GtkGLArea does not allow me to set positions of these window, does it? Maybe i could try with gtk_window_move… Thanks a lot for helping out.

You can put many GtkGLArea widgets in a GtkFixed to position them.

If you are stuck on GTK3 and you really need to create your own EGL context, then you could get it to work similar to a GLX child window but then you have to create a new surface, assign it the subsurface role and parent it to the GTK surface with wl_subcompositor_get_subsurface, and position it with wl_subsurface_set_position. You cannot change the role of any surface given to you by GTK. It is mostly pointless to do this in GTK4, and in any case it is a lot easier and more portable to just use GtkGLArea.

making a new subsurface to be the parent of the gtk window surface? this is also a helpful hint! I would try with glarea first, if that didn’t work out i might try the second way.
Thanks again for giving all these insights, this would save me so much time…i struggled reading stuff online everywhere and the source code is big. :slight_smile:

one more question… if making a the gtk draw area the parent of a newly created subsurface and move the subsurface, wouldn’t the draw area(the parent) not move at all, so the content of my window won’t move? or am i not getting this correctly?

You cannot make a subsurface the child of a widget. GTK cannot interact at all with subsurfaces created by you. You must handle all positioning and input events on the subsurface yourself.

Again, Wayland subsurfaces are only really meant for embedded plugins and such; that means things that need to handle their own drawing and event loop separate from any toolkit. They are not meant for implementing random GTK widgets. If you are making a GTK app you should just use the facilities available to you in GTK, and stop trying to sidestep the toolkit.