This post reffers to the one before and I recommend you to read it:
https://dbeef.lol/2018/12/26/writing-x11-screensaver-with-c-opengl/
Root windows
As we made through our attempt to write a screensaver for XScreenSaver server we stepped on a concept of virtual root windows.
As the Wikipedia states:
The virtual root window is also used by XScreenSaver: when the screensaver is activated, this program creates a virtual root window, places it at the top of all other windows, and calls one of its hacks (modules), which finds the virtual root window and draws in it.
Our program found the virtual root window that XScreenSaver created when 1 minute of idleness passed and used its window handle to do OpenGL calls. But as you probably imagine, if we can find the root window, which is your desktop, we can draw whatever we want over it. And apparently, that’s how widgets (aka screenlets) work.
There’s a program called Conky (named after a doll from Trailer Park Boys TV series),
that does exactly the same thing. As its FAQ states:
Conky is a program which can display arbitrary information (such as the date, CPU temperature from i2c, MPD info, and anything else you desire) to the root window in X11. Conky normally does this by drawing to the root window, however Conky can also be run in windowed mode (though this is not how conky was meant to be used).
As the concept by which Conky’s screenlets work is similiar to our screensaver’s, let’s install it and check anatomy of screenlets.
Prerequisites
Process of installing either from sources or packages is described on their wiki:
https://github.com/brndnmtthws/conky/wiki/Installation
…and I’m assuming that when you type ‘conky‘ in your terminal, it starts Conky process.
I’m using Ubuntu 16.04 with Compiz.
What’s optional is conky-manager, you may build it from source:
https://github.com/teejee2008/conky-manager
Sample screenlet
As Conky has built-in support for Lua scripts, it doesn’t mean that conky configuration files are written in Lua (they use Lua syntax since Conky 1.10). They’re more like configuration files that define what is drawn and where, and to get some values, or draw something, they can call Lua scripts. They can also call bash scripts. For some values they need no Lua nor bash, because they are handled by Conky itself.
Conky developers even distribute Conky-related Lua tutorial:
https://github.com/brndnmtthws/conky/wiki/Lua
Making a sample screenlet consists of:
- Writing ~/.conkyrc file, possibly copy-pasting some portions of configuration from other screenlets because it’s redundant.
Possible configuration settings are defined here:
http://conky.sourceforge.net/docs.html - (optional) Writing Lua script or bash script that you may want to call in it, maybe also putting some images/other resources into script directory. You can refer to the tutorial linked above.
Example conkyrc with Lua script (not mine):
https://github.com/zenzire/conkyrc
One particularly creative conky
As a fan of Thinkpads, when I’ve seen this:
I immediately downloaded scripts this guy shared and set them up on my own Ubuntu.
What was needed:
- Download this config file and save it as ~/.conkyrc file:
https://pastebin.com/6VKhNRUJ - Download shell scripts and save them under ~/.bin directory:
https://pastebin.com/u/u0xpsec - Edit those sh scripts, they relate to /home/u0xpsec directory, change it to your own.
- In terminal, type ‘conky’.
I experienced one annoying bug; on clicking desktop, this conky disappeared.
Link below helped disappearing on desktop click, but didn’t help disappearing on alt+tab to desktop (which hides everything):
https://ubuntuforums.org/showthread.php?t=1717351
What helped me on disappearing on ‘hide all windows’ was the tip i found on Arch Linux Wiki:
https://wiki.archlinux.org/index.php/conky
Using Compiz: If the ‘Show Desktop’ button or key-binding minimizes Conky along with all other windows, start the Compiz configuration settings manager, go to “General Options” and uncheck the “Hide Skip Taskbar Windows” option.
To download Compiz configuration settings manager type:
sudo apt-get install compizconfig-settings-manager
And run it via ‘ccsm’.
Alas, this conky took ~2% of CPU (quering system status is costly), so you may think twice before installing it.
Links
Conky has its own subreddits:
https://www.reddit.com/r/Conkyporn
https://www.reddit.com/r/Conky
And you can find more screenlets on deviantart, i.e this one:
Which is also very amusing.