My Retro Arcade Videogames Screensaver for Linux
Tags: screensaver, linux, fun
Published: 2020-05-23 19:39:25

---
title: My Retro Arcade Videogames Screensaver for Linux
published: true
date: 2018-07-26 18:16:28 UTC
tags: screensaver,linux,fun
canonical_url: http://www.streppone.it/cosimo/blog/2018/07/my-retro-arcade-videogames-screensaver-for-linux/
---

 **Screensavers are magic, they’re like magnets** , at least to me. I’ve always been fascinated by them. There’s great creativity and programming energy that goes into making one.

I think the first screensavers I encountered were probably the ones written for Windows 3.1, even though the loading colored bars of the Commodore 64 could perhaps qualify as a screensaver as well.

One of the greatest screensavers I remember is the one that came with Novell Netware servers. This was around 1997, and it looked approximately like this video:

{% youtube RitHgCBNrNs %}

This is a work of art. It was a text-mode screensaver, and it displayed a few “snakes” going around the screen. Each snake represented a processor. Multi-core processors were very much in the future back then, but we were running our Netware server with a SMP machine and two Pentium Pro processors, which was pretty awesome for the time.

If the processor occupancy was high, the snake would move faster and at the same time, IIRC the higher the number of processes active on each processor, the longer the snake. Simple and brilliant. With a simple look at the screen, you could instantly tell how much the system was loaded, and that was very important, since that Netware machine enabled hundreds of employees to do their daily job.

I have used Linux as my workstation operating system for at least fifteen years now, and [jwz’s xscreensaver package](http://www.jwz.org/xscreensaver/) has always been present and very appreciated, so much so that one day I started my own screensaver project for fun. I decided to rewrite the Netware screensaver obviously and I wrote about it [in the past](http://www.streppone.it/cosimo/blog/2011/03/loadsnake-aka-the-novell-netware-snake-screensaver-clone/).

All this to explain that screensavers are a thing for me :-)

Fast forward to now, I think I found the next level of screensaver goodness, and I’m quite satisfied of it. It is a **retro-arcade-videogames screensaver.** The craze started when I changed job and started using a new Linux workstation. I noticed all my colleagues running MacOS running this [rather stunning aerial video](https://github.com/JohnCoates/Aerial) footage as screensaver.

I soon discovered that it’s possible to run the same on Linux, and there’s a project called [xscreensaver-aerial](https://github.com/graysky2/xscreensaver-aerial/blob/master/atv4.sh)that you can run as part of xscreensaver. While that is very cool,  
it became boring quickly. The idea of xscreensaver-aerial however is neat. You can display your own video files in fullscreen, just fill up a folder with video files and when xscreensaver is invoked, one of those videos will be played. The shell script linked above does this, with the help of **mpv** , a nice video player for Linux, even though in a slightly convoluted way.

The following step was obvious: use **mpv** and adapt the shell script to do what I wanted. Pick random video files from a folder. I started downloading longplay videos of my favourite video games. For example, [Bomb Jack](https://www.youtube.com/watch?v=XvHk6LTh-Ks) or Space Ace, all the rage 80’s arcades or Amiga games, for  
that nice nostalgia factor.

{% youtube 4iplXu8jXc0 %}

Started using this version for a while. I run a two monitor setup, one in portrait mode for code and text editing, and another one in landscape mode for browser and every other need.

Sometimes the screensaver would play the same video on both monitors (lame) or play a video with an inappropriate aspect ratio for the monitor, filling the screen with vertical or horizontal black bars.

Thus, last improvement was to automatically detect the aspect ratio of each monitor and pick from either a **`landscape`** or **`portrait`** video folder.

The trick I used to do this is nothing else than some shell code:

```
#
# Overwrites $MODE with either `landscape` or `portrait`
#
check_monitor_mode() {
  MODE="landscape"
  local tmpfile="$(mktemp)"
  logger -t xscreensaver "xwinid: $XSCREENSAVER_WINDOW" xwininfo -id "${XSCREENSAVER_WINDOW}" > "${tmpfile}"
  local width=$(grep "Width: " "${tmpfile}" | awk '{ print $2 }')
  local height=$(grep "Height: " "${tmpfile}" | awk '{ print $2 }')
  unlink "${tmpfile}"
  if [$width -gt $height]; then
    logger -t xscreensaver "landscape mode (${width}x${height})"
  else
    logger -t xscreensaver "portrait mode (${width}x${height})"
    MODE="portrait"
  fi
}
```

The command to play the video, which must be saved as an xscreensaver module, is:

```
mpv --really-quiet --no-audio --fs --no-stop-screensaver --wid="$XSCREENSAVER\_WINDOW" "${themovie}" &
```

By customizing ~/.xscreensaver it’s possible to add your own executable programs, give them a name, etc, so for example my ~/.xscreensaver contains the following:

```
...
programs:
  - "Apple TV Aerial" atv4
  - retro-arcade-screensaver
  - "Novell Netware Screensaver" loadsnake
...
```

Here’s the final result:

[![](http://www.streppone.it/cosimo/blog/wp-content/uploads/2018/07/20180627_202625-1024x576.jpg)](http://www.streppone.it/cosimo/blog/wp-content/uploads/2018/07/20180627_202625.jpg)