How To Write A Modern Studio Screensaver

Rocking it like it’s 1995

Sam Birley
XRLO — eXtended Reality Lowdown
7 min readNov 4, 2020

--

At REWIND, we take immense pride in the level of polish we apply to the software that we build. Whether it is being built for clients or solely for internal studio use, we hold ourselves to the same high standard. Internal use, of course, covers our development pipeline infrastructure, but also the user’s local development environment; the tools they have at their disposal, the stability of their OS, and yes, even their screensaver!

With the advent of modern displays panels, the humble screensaver’s purpose was taken away from it. Originally created to circumvent CRT-display phosphor burn-in, LCD-based technology resolved the issue at the hardware-design level, turning screensavers from a necessity into merely a decoration.

Goodnight sweet prince

With that said, screensavers are still relatively ubiquitous at organisations; most have a domain policy that will lock machines after a predetermined period of time, at which point you may as well show something fun and fancy, and a screensaver is an obvious choice.

Although their original purpose has been robbed from them, screensavers are still a pretty great place to advertise a studio internally — it’s a free and easy opportunity to communicate the studio’s brand to the team around the office. Why not make use of all those currently idling screens and turn them into something interesting/useful for staff walking past? What if we turned screensavers into an onboarding tool that could help build staff relationships?

That was our original motivation for a REWIND screensaver; we wanted to show off who we are to ourselves, and introduce the team (particularly new starters!) to their colleagues, maybe telling them something they didn’t already know about each other along the way.

The Naiïve Approach

A classic default Windows screensaver, ‘Photo Gallery’ is one where consecutive images are shown from a predefined directory in a carousel-like fashion. An approach that requires minimal short-term effort would be to use this screensaver, create an image for each member of staff, following a standardised format that includes some information about the staff member, who they are and what they do.

The Humble Windows Photo Gallery Screensaver

Whilst being pretty straightforward to set up, the problem with this approach is that it requires sustained manual effort. As new staff come and go, new images have to be added and old ones nuked, if staff want their content changed images need to be updated and perhaps others go out-of-date. We wanted something that requires minimal effort to maintain, and it was at that point that we realised we already had all the up-to-date information elsewhere, somewhere where staff can directly modify their data themselves!

We use a tool called Sapling to assist our HR department. When a new starter joins, we create a profile for them in Sapling, along with a profile picture. They are then asked to enter some details about themselves, including some fun stuff like hobbies, a fun fact and their favourite film. That’s exactly the kind of stuff we want to be showing in our screensaver, and, as it turns out, Sapling allows us to retrieve all of the data via its web API. Hooking into that, we can ensure our screensaver is always up-to-date with zero maintenance!

(Brief) Anatomy of a Windows Screensaver

Not knowing a lot about how Windows screensavers are built prior to starting, one of the first surprising things to discover is that Windows screensavers are nothing more than regular executables, with their .exe extension replaced by .scr. The Windows OS simply invokes the executable that has been selected via the Control Panel at the appropriate time, and as long as they exist in one of a few predefined locations, they will automatically appear in the screensaver settings panel.

The other unusual thing about screensavers is that they do not define a ‘main’ or ‘WinMain’ entry point. Instead, the screensaver application is expected to implement ‘ScreenSaverProc’. The function is called once per-frame throughout the lifetime of the screensaver with different message parameters and the programmer is expected to manage the state of their screensaver based on the messages received.

LRESULT WINAPI ScreenSaverProc(HWND HWnd, UINT Message, WPARAM WParam, LPARAM LParam)
{
switch (Message)
{
case WM_CREATE:
{
RECT ClientRect;
GetClientRect(HWnd, &ClientRect);
const unsigned int Width = ClientRect.right - ClientRect.left;
const unsigned int Height = ClientRect.bottom - ClientRect.top;
App = new ScreensaverApplication(HWnd, Width, Height);
SetTimer(HWnd, DRAW_TIMER, 33, NULL);
}
break;
case WM_ERASEBKGND:
break;
case WM_TIMER:
{
App->Update();
App->Draw();
}
break;
case WM_DESTROY:
{
delete App;
}
break;
default:
break;
}
return DefScreenSaverProc(HWnd, Message, WParam, LParam);
}

Once that is implemented, along with a couple of other functions required by Windows in order to be wired up correctly with the Control Panel and screensaver settings, we need to link against the Windows library ‘scrnsave.lib’, where the actual application entry point is defined and these functions are called.

A screensaver is not much different from any other executable really

And that’s really all there is to the anatomy of a screensaver! It’s surprisingly simple and straightforward, albeit not particularly well documented these days.

Show Me The Profiles!

As mentioned above, we already have all the data we want to show about the team housed over on Sapling, we just need a means of querying for it via the RESTful API Sapling kindly provides.

Our screensaver is written in C++ and we definitely don’t want to be writing our own http request API, instead, we adopt Microsoft’s C++ REST SDK; a great candidate for us since it is well maintained, widely adopted, and pretty fully featured. It makes good use of modern C++’s adoption of lambdas (particularly relevant given the asynchronous nature of RESTful APIs) and has some interesting API design choices that are intended to streamline/simplify the implementation of a series of http requests.

On the rendering side of things, we similarly do not want to invest in creating a bespoke graphics API just for the screensaver use-case, and in reality, we’re building a relatively unsophisticated app as far as graphical requirements go, so choosing something simple, portable, and fast to integrate makes a lot of sense. In our case, we chose SFML as this has built-in support for fonts, textures, and various mesh shapes that can be used to display textures on-screen.

Putting It All Together

When the screensaver starts up, we begin by using the C++ REST SDK to query Sapling for all staff names, their job title, their trivia and the URL for their profile picture. We cache the data, randomise the order of the staff and then start to display each staff member’s details on-screen in a carousel-like fashion, holding on each for long enough to allow the user to have a read.

For the profile images, once we have the set of URLs we only retrieve one at a time in the order that we will be showing the staff. We do this to minimise the bandwidth consumed by the application at any given time, and consequently the image retrieval time, hopefully guaranteeing that a member of staff’s profile image will be ready and waiting by the time we cycle through to display their info.

Since we want our screensaver executable to be entirely self-contained, with no external file-reads, we also bake all of our binary data (such as the background image and REWIND logo) into the executable itself in the form of static byte arrays.

And we end up with this!

Particularly in these times, where it is more difficult for new starters to forge connections with their new colleagues whilst working from home, having a custom screensaver for your organization can be a great bit of internal polish, and in general is a really useful tool to help staff get to know each other a little better. Moreover, as we have shown here, putting a Windows screensaver together is surprisingly easy to do, and if you have a centralised repository of staff information, you can build one just like this that requires next to no maintenance. Next up for us, port the project to OSX!

XRLO: eXtended Reality Lowdown is brought to you by REWIND, an immersive design and innovation company. If you want to talk tech, ideas, and the future, get in touch here.

Your claps and follows help us understand what our readers like. If you liked our articles, show them some love! ❤️

We’d also love to hear from you. If you’re passionate about all things XR, you can apply to contribute to XRLO here. ✍️

--

--