Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using desktop as canvas on linux


i was wondering if somebody could help me out. I have a plan of making clone of geek tools for linux. But i have no idea if you can somehow use linux desktop as canvas for drawing text etc. I tried to google it up but i found nothing. What i need to do is basically be able to draw text on certain parts of desktop so it would appear like they are part of wallpaper (from c++). Either that or be able to create borderless, transparent windows that can be clicked through and are always on background. If anyone could give me any pointers where to start, i will be very happy.
Thanks for your help in advance :]

like image 551
Arg Avatar asked Jan 23 '23 13:01

Arg


1 Answers

You already accepted a partial answer, but I hope you will still read this.

It is true that the desktop background by convention is the root window. However, there are two important mechanics going on on a typical modern desktop:

  • root pixmap setting (wallpaper), which is not drawn on the background of the root window
  • enrichment of the desktop background (for example clickable icons) by obstructing the root window with another base level window

If you only want to draw on the background, only the latter matters to you. If you however also want to read the background, for example for real transparency, also the first point plays a role.

Drawing to the background:

The authors of the program xsnow and xpenguins were the first to deal with this problem. They wrote a clever function that can derive KDE and Gnome desktop windows if they are present. As other window managers that obstruct the root window tend to obey these de-facto standards, it works very reliably. With their code, you instantly know which window to draw to.

Reading the root background (pixmap):

This is harder. The naive query for window pixels will fail because all foreground windows are also part of the root window; so this makes it easy to do a screenshot, but not to get the real background.

There is a convention however, on a global name of the root pixmap (as used by any decent background pixmap setter). The pixmap can be found by querying for that name. It gets nasty however, if either the background setter sucks and does not obey to that rule, or the background is not a pixmap, but only a pattern or whatever.

The second option, of which I only found recently, is to use the XDBE (double buffer) extension to get the root window's background. This is very clean, only takes like two or three lines of codes and works in any case. But Xorg sees XDBE as deprecated (or, more precisely, soon-to-be deprecated). So I don't know if using it only for that purpose is still a good idea. But I can give you code on request!

Finally the implementation:

Yes, there is an implementation available for both things. Check out http://fopref.meinungsverstaerker.de/xmms-rootvis/ In that archive, which is GPL, getroot.c is taken from xpenguins, without dependencies to other xpenguins code. Also, starting in line 144 of rootvis.c you will find the code to grab the background pixmap.

Have fun!

like image 57
ypnos Avatar answered Jan 31 '23 22:01

ypnos