Custom screen saver with XSecureLock

Vincent Bernat

i3lock is a pop­u­lar X11 screen lock util­ity. As far as cus­tomiza­tion goes, it only al­lows one to set a back­ground from a PNG file. This lim­i­ta­tion is part of the de­sign of i3lock: its pri­mary goal is to keep the screen locked, some­thing dif­fi­cult enough with X11. Each ad­di­tional fea­ture would in­crease the at­tack sur­face and move away from this goal.1 Many are frus­trated with these lim­i­ta­tions and ex­tend i3lock through sim­ple wrap­per scripts or by fork­ing it.2 The first so­lu­tion is usu­ally safe, but the sec­ond goes against the spirit of i3lock.

XSecureLock is a less-known al­ter­na­tive to i3lock. One of the most at­trac­tive fea­tures of this locker is to del­e­gate the screen saver fea­ture to an­other process. This process can be any­thing as long it can at­tach to an ex­ist­ing win­dow pro­vided by XSecureLock, which won’t pass any in­put to it. It will also put a black win­dow be­low it to en­sure the screen stays locked in case of a crash.

XSecureLock is shipped with a few screen savers, no­tably one us­ing mpv to dis­play pho­tos or videos, like the Ap­ple TV aerial videos. I have writ­ten my own saver us­ing Python and GTK.3 It shows a back­ground im­age, a clock, and the cur­rent weather.4

Custom screen saver for XSecureLock, displaying a clock and the
current weather
Custom screen saver for XSecureLock

I ap­ply two patches on top of XSecureLock:

  • Sleep be­fore map­ping screen saver win­dow. This patch pre­vents a flash of black when start­ing XSecureLock by wait­ing a bit for the screen saver to be ready be­fore dis­play­ing it. As I am also us­ing a cus­tom dim­mer fad­ing to the ex­pected back­ground be­fore lock­ing, the flash of black was quite an­noy­ing for me. I have good hope this patch will be ac­cepted upstream.
  • Do not mess with DPMS/blanking. This patch pre­vents XSecureLock from blank­ing the screen. I think this is solely the role of the X11 DPMS ex­ten­sion. This makes the code sim­pler. I am un­sure if this patch would be ac­cepted by upstream.

Up­date (2023-05)

The first patch has been ac­cepted and is avail­able in 1.8.0. In­stead of the sec­ond patch, I am now set­ting XSECURELOCK_​BLANK_​TIMEOUT to -1.

XSecureLock also del­e­gates the au­then­ti­ca­tion win­dow to an­other process, but I was less com­fort­able pro­vid­ing a cus­tom one as it is a bit more se­cu­rity-sen­si­tive. While ba­sic, the shipped au­then­ti­ca­tion ap­pli­ca­tion is fine by me.

I think peo­ple should avoid mod­i­fy­ing i3lock code and use XSecureLock in­stead. I hope this post will help a bit.

Up­date (2022-01)

XScreenSaver can also run ar­bi­trary pro­grams as a screen saver.