C vs C++
Xsnow is written in C. However, because I needed a reliable hash function to maintain a cache of bird surfaces, some C++ has been crept in. To store the bird surfaces, an 'unordered_map' is used if available. Otherwise, 'map' is used, which is not implemented as a hash function but as a binary tree. For housekeeping of the snow flakes, an '(unordered) set' is used. The WWW recommends to compile the main program with C++ when using a mix of C and C++, so a very small main() is written in C++, which calls the original C main() function. All sources have been adapted to compile using C++, so, if you are a C++ adept, you can do:
CC=g++ ./configure make make install
The original xsnow-1.42 has an more or less ad-hoc timing mechanism. The program offers many flags to tweak the speed of Santa, the speed of snow and the like. Xsnow-2.0 has a more straight forward timing mechanism, in principle, every speed is defined in pixels/second.
The updating and drawing of Santa are decoupled, so the refreshing rate of Santa does not affect His speed.
Fallen snow (bottom and on windows) is nice in xsnow-1.42, but after running for some time, the visualization of fallen snow is not realistic. Therefore I use now a complete new strategy for the handling of fallen snow.
The handling of wind is changed in xsnow-2.0: it is now more or less windy all the time, but the original code from xsnow-1.42 is still used to experience more dramatic wind effects. The algorithm for the sensibility to wind of Santa and snow has been changed: The velocities of Santa and snow are changed by the wind.
In xsnow-1.42 an fixed-length array was used to hold the snow flakes. In xsnow-2.0, the flakes are in a double-linked list. But now, the housekeeping is done with a C++ 'set' or 'unordered set'. This makes it possible to add snow flakes at random times, for example when converting fallen snow to snow flakes. Furthermore, the amount of snow is now determined by the rate the flakes are produced and removed. The production rate is given in flakes per second per pixel (i.e. the width of the window measured in pixels). This has the effect that, in a steady state situation, a larger window shows more flakes than a smaller one.
Since I stumbled upon https://www.cairographics.org/Xlib/, I decided to use only GTK/cairo to make the animations.
The preferred way for xsnow to make it's drawings is to use a transparent, click-through window that covers the whole screen.
This requires a compositing window manager, which is not always available. In those cases painting is done at the root-window (or window 'pcmanfm' when running LXDE). Using XdbeSwapBuffers and friends a double buffer is used. When this is not desirable (for example when running xsnow together with xpenguins), then you can specify the flag '--doublebuffer 0', at the cost of some flicker in the animations. Also, when you specify '-xwininfo' or '-id
Self replication is implemented by including an ascii-representation of a tar file, made by
make dist. Xsnow is not really a self-replication program, because the ascii representation is not part of the tar file, but it works beautifully:
xsnow -selfrep | tar zxf - cd xsnow-3.4.3 ./configure make # test: src/xsnow # to let it snow src/xsnow -selfrep | tar zxf - # to create also here xsnow-3.4.3 cd xsnow-3.4.3 ./configure make # etc.
Window manager issues
An in-depth story about difficult to find good managers in general. Question: does this also apply for window managers?
Here follows some information about the cooperation of xsnow and a few window managers, taken from the man page:
In general, xsnow works better when using a compositing window manager like xcompmgr, compton or picom. However, with some window managers (FVWM for example), the xsnow-window is transparent, but not click-through. Flags to be tried in this case include: -root, -doublebuffer, -xwininfo, -id. Here follow some window managers with their issues: AWESOME Without compositor: no issues. With compositor: no click-through xsnow window BSPWM No issues if you add to your bspwmrc (the bspwm configuration file): bspc rule -a Xsnow state=floating border=off CINNAMON No issues. DWM No issues, except the "Below Windows" setting in the "settings" panel. ENLIGHTENMENT No issuses. FLUXBOX Without compositor: no issues. With compositor: no click-through xsnow window FVWM Without compositor: no issues. With compositor: no click-through xsnow window GNOME No issues. HERBSTLUFTWM No issues. I3 Without compositor: no issues, using the next line in "config": for_window [class="Xsnow"] floating enable;border none With compositor: unworkable. JVM No issues. LXDE With compositor: no issues. Without compositor: use: xsnow -xwininfo LXQT Without compositor: unworkable. With compositor: no click-through xsnow window. MATE No issues. OPENBOX No issues. PLASMA (KDE) No issues. SPECTREWM Without compositor: no snow on windows, use the next line in "spetrewm.conf": quirk[Xsnow] = FLOAT With compositor: no satisfactorily results. TWM Without compositor: no issues. With compositor: no click-through xsnow window WINDOW MAKER Without compositor: no issues. With compositor: no click-through xsnow window XFCE No issues when compositing is on, unworkable when compositing is off. See settings -> Window Manager Tweaks -> Compositor XMONAD No issues if you add to your xmonad.hs in the ManageHook section: className = ? "Xsnow" --> doFloat
Xsnow tries to find out if it can create a transparent click-through window. If successful, xsnow will create one. In general for this a running compositing window manager (xcompmgr, picom, compton) is needed. Alas, in some cases, the window created by xsnow is transparent, but not click-through.
If not successful, xsnow will use the root window, except:
In LXDE, xsnow will snow on the window with the name 'pcmanfm'. If you have a multi-monitor setup, changes are that the wrong window is chosen. Remedy: start xsnow like this:
xsnow -xwininfoand click on the desktop.
In XFCE, xsnow will snow on the window with the name 'Desktop'.
If xsnow is runnig, but you don't see anything (this happens for example in the LXQt environment)
Try to start a compositing window manager first, like xcompmgr, compton or picom, like:
Xsnow can use any window, you can choose one (using
xsnow -xwininfo), or you can specify a window-id (using
xsnow -id window-id). This feature does not always works perfect.
Raspberry 64 bit, and maybe others: xsnow is confused by the 'xcompmgr' daemon, which results in a black background. The reason:
xcompmgris started with the flag
-a, this seems to be beneficial for Openbox, but is detrimental for xsnow and others. I hope to find a fix for this, for now I have this remedy (I don't know if this is detrimental for Openbox...):
- On the command line, before starting xsnow:
killall xcompmgr nohup xcompmgr -n &
- Or: start xsnow with
xsnow -xwininfoand click on the desktop for a less than perfect xsnow experience.
- Or (permanent solution): edit
/usr/lib/raspi-config/cmstart.sh, change the flag
-nand restart your system. I don't know if this is detrimental for Openbox...
Xsnow by default starts on all workspaces. In the
settingstab, you can choose: run on all workspaces or run only in the current workspace.
Among the downloads I included shell scripts 'startondesktop' and 'startonalldesktops' (I should have called then 'startonworkspace' and 'startonworkspaces'...) that you can try to start xsnow on (a subset of) all workspaces if xsnow itself does not run in all workspaces on your system.
The location of the top of the windows (we need that to figure out where snow should fall on), including the decorations, is a known issue on the web. I found a solution for this issue: see the code in wmctrl.c (from the xsnow tarball). And, by looking at the code of the programs wmctrl, xwininfo and xprop, I was able to incorporate the things I need in xsnow with respect to choosing a window, locate a window etc.
It seems there is something wrong with the Breeze theme: xsnow works, but the buttons behave strangely.
Before version 2.10, xsnow refused to run on Wayland (that is the proposed successor of X11 and is the default on recent Debian-derived installations). I was prepared for major code changes in xsnow, but, after lots of googling, I found a solution, at least for xsnow: simply set the environment variable GDK_BACKEND=x11. So, before the gtk environment is initialized (using gtk_init()), xsnow sets (using setenv()) that variable to the desired value. Of course, the official GDK documentation has something about the issue . It could very well be that things work thanks to XWayland, I really don't know very much about X11 and Wayland. In Wayland, applications have only a restricted control over the windows that are not owned by the application. So, xsnow cannot snow in other windows. But for many of the windows the information about the where-abouts are available to xsnow. For example, xsnow is snowing on the windows of firefox, gimp, gvim, xsnow, xterm, xclock and xcalc, but not on the windows of aislerioth, gedit, nautilus and gnome-terminal.