views:

239

answers:

7

Hello everybody,
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 :]

+4  A: 

Linux almost always uses X11 (Gnome/KDE are higher-level APIs). On X11, the "desktop" is known as the "root window". So, paint on that.

MSalters
This used to work just fine, but many modern desktop environments (Gnome, KDE) implement the "desktop" as a window sitting just above the root window, so the actual root window may be obscured. In that case, you may want to look into something more tailored to the environment.
ephemient
Sorry, downvote, because it will nearly always fail on a modern desktop system.
ypnos
A: 
Pavel Shved
A: 

I have seen compiz solutions that are able to achieve something similar to that. Unfotunatly compiz is not very document AFAIK but this tutorial might get you started

mandel
+2  A: 

If you want to target a specific desktop enviroment, take a look at gdesklets fo GNOME or plasma widgets for KDE. Or you can go "bare metal" as MSalters say and draw directly to the root window (check for example this tutorial)

Mr Shunz
+1 try to be compatible with the users desktop environment
Otto Allmendinger
i was thinking about using the desklets on gnome, but i dont like them at all so i think ill 'bare metal' as it should work much better and compatible with all x11 based enviroments. Thanks for the tutorial ill check it out when im back from school :]
Arg
A: 

Google Desktop Gadgets or gdesklets could be of help instead of starting from scratch.

dtmilano
A: 

The KDE Plasma-Desktop supports so called activities, which are modules for different desktop types (C++). I think this is a good point to have a simple and integrated base for doing something like that.

+4  A: 

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!

ypnos
very interesting answer, thanks for the tips
Arg