Alexander Gromnitsky's Blog

gtk4 & shadertoy

Latest update:

All I wanted was to render a nice shader onto an X11 root window, like so:

(IRL this doesn't look junky, the GPU renders the background at 60 fps.)

First, I tried to search for a "desktop" shadertoy renderer. No luck. Then I remembered that a nifty gtk4-demo program included some shader examples. Aha! What if I extract their custom widget & create a standalone little app?

Second, I tried to find out how to draw gtk4 widgets onto an X11 root window. No luck. Apparently, this has been deprecated:

'The root window is an X11-centric concept that is no longer exposed in the backend-neutral GDK API.'

Third, I attempted to simulate such behavior by having the app send hints to the WM, such as "I want to be on the lowest layer, on every virtual desktop, & not listed in the taskbar." Theoretically, this can be achieved by setting a couple of X11 Atoms for a specific window in the _NET_WM_STATE list.

The troubles began with the WM I'm using--fvwm3. While I managed to set the _NET_WM_STATE_BELOW Atom without any server errors using ancient X11 APIs (XSendEvent), the WM ignored the operation until I added the following line to ~/.fvwm/config:

Style * EWMHUseStackingOrderHints

But no matter what I did next, fvwm3 refused to obey messages for _NET_WM_STATE_SKIP_TASKBAR & _NET_WM_STATE_SKIP_PAGER Atoms. I asked on fvwmforums.org what could be the reason, but received 0 answers.

Then it was gtk4 itself. I suspect that the authors assume you will develop apps with the full gtk4/glib repositories cloned for reference, because good tutorials are scant & the APIs docs are devoid of examples. The most primitive stuff, like parsing command line options, took me several hours to figure out.

The only pleasant surprise was finding gdk_frame_clock_get_fps() in the repo. I didn't anticipate such luxury.

The final result is here. I think I should incorporate some form of a socket listener into the app, allowing external programs to send commands such as "change the shader," "quit," "pause," &c.


Tags: ойті
Authors: ag