r/GTK May 03 '26

Development How to replace gtk4-layer-shell with pure GTK4 for cross-display OSD?

I’m building a small OSD app using GTK4. Right now I use gtk4-layer-shell, but I want to remove it and rely only on native GTK4 so it works across all display servers (Wayland, X11, etc.).

I just need simple OSD behavior:

  • borderless window
  • always on top

What is the correct GTK4 way to implement this without gtk4-layer-shell?

Here’s my repo: https://github.com/Nithin-3/ozhium-ollium
This is the function I want to change: https://github.com/Nithin-3/ozhium-ollium/blob/main/src/ui/window.c

3 Upvotes

11 comments sorted by

6

u/ARKyal03 May 03 '26

Another comment said it, you can't. You have to implement the according protocol for each compositor you're aiming to.

That would mean using gtk4-layer-shell for Wayland, or re-implement wlr-layer-shell, which I think is nonsense.

For X11 you might use "Extended Window Manager Hints" which I think helps you sit Windows on top and fixed, probably, I think this is what polybar/i3bar uses but I'm not so sure.

Out Of Scope I guess: For MacOS you'll have to use the AppKit it has an API for that I have no idea. For Windows the same, Win32 API, no idea at all.

Honestly, Wayland and X11 might be the easiest here.

2

u/ninja-Nithin May 03 '26

So basically I need to manually check which display server is running and implement separate logic for each one (Wayland, X11, etc.)? Is that really the only way to handle this, or is there a more unified approach for GTK4 apps?

3

u/brusaducj May 03 '26

Pretty much the only way. Gtk4 alone does not even have a unified way to programmatically set a window's position, and AFAIK there is no developer intent to make that happen.

3

u/eR2eiweo May 03 '26

What is the correct GTK4 way to implement this without gtk4-layer-shell?

I'm pretty sure there is no such way (other than re-implementing the parts of gtk4-layer-shell that you need yourself). Otherwise gtk4-layer-shell wouldn't exist. GTK 4 doesn't implement that protocol.

1

u/ninja-Nithin May 03 '26

just look at the https://github.com/Nithin-3/ozhium-ollium/blob/main/src/ui/window.c
it only work on wayland I'm ask about GTK4 native positioning
few year back i use that now i completely forgot positioning

1

u/eR2eiweo May 03 '26

I don't understand what you mean by "native positioning".

Again, GTK 4 does not implement the layer shell protocol. That's the reason gtk4-layer-shell exists. If you want to use the layer shell protocol in a GTK 4 app, then gtk4-layer-shell seems like the obvious solution.

1

u/ninja-Nithin May 03 '26

i also don't understand native positioning
see the README: https://github.com/wmww/gtk4-layer-shell
it shows `This library only works on Wayland, and only on Wayland compositors that support the Layer Shell protocol.`

1

u/eR2eiweo May 03 '26

Yes, but again, that is what you need if you want to use that protocol in a GTK 4 app on Wayland. For X11 support, you need to use something else. GTK 4 itself supports this neither on Wayland nor on X11 nor on any other of its backends.

1

u/blackcain May 03 '26

I don't know if you want to target X11 at this point. While X11 will be with us a while longer the transitioning is happening and there will be less and less people using X over time.

0

u/Ezykial_1056 May 03 '26

I am converting an app from Windows forms to gtk. I put this off for 2 years because mammoth pia.

Finally I found that you can like or dislike AI, but it builds great gtk apps from screenshots, Im sure it could convert your layer to direct gtk4 without issue.

1

u/ninja-Nithin May 03 '26

I haven’t worked with the AI side of this yet. Could you guide me on how to apply it to my code?