How it works
The design decisions behind DeskPets, and what broke along the way
This page is the engineering view. For what the animations mean, see Pets and states. For how the artwork was made, see Art pipeline.
Design decisions
Telemetry-driven behavior. The pets read CPU, RAM, swap, GPU, battery, and idle time. A calm machine gets a calm cat. Sustained high CPU gets a jumping cat. A hot GPU gets a grumpy one.
A state machine, not an if-statement. Ten animation states are chosen by a priority ladder with hysteresis and minimum dwell times. A CPU reading bouncing between 78% and 82% produces one transition, not four, so the cats don’t flicker. The ladder and the thresholds are laid out in Which one wins and No flickering.
Privacy by design. The app only asks the system how long it has been idle: GetLastInputInfo on Windows, Quartz’s idle-time query on macOS, and the X11 screensaver extension or the desktop’s idle monitor on Linux. There is no keyboard hook, no record of what I type, and nothing on macOS that needs an Accessibility or Input Monitoring permission.
Built to run next to heavy workloads. That was the original point. Telemetry runs on its own worker thread and shuts down cleanly in about 15 ms. Sprites are decoded with Qt alone, and Pillow is deliberately not a runtime dependency.
Built for changing art. The sprites change independently of the code, so nothing in the code hard-codes the art. Frame rectangles, counts, durations, and loop flags all come from an atlas JSON file, and the loader never computes positions from a grid. A state whose animation isn’t in the atlas yet is simply unreachable, so a new behavior can ship before its art does.
What broke along the way
My first prototype was a sketch. I kept a phase log as I went, and it records what didn’t survive contact with the real machine:
- A use-after-free in the sprite loader. The prototype wrapped a temporary bytes object in a
QImage. I moved toQImage(path)pluscopy(rect)and dropped Pillow from the runtime. - An unreachable idle state. The spec said “idle if CPU < 20% and RAM < 60%.” I measured my own desktop, and it idles at about 70% RAM, so the idle animation could never trigger. I made idle the unconditional default and demoted RAM to a hint on the card.
- A hang on quit. The telemetry thread was a
while Truewith no stop flag. I replaced it with a worker driven by a timer. - A click-through that couldn’t work. Qt’s widget-level mouse-transparency attribute only affects events inside the app, so the other windows never got the clicks. On Windows only the
WS_EX_TRANSPARENTstyle makes the OS skip the window. - A click-through that couldn’t be turned off. On Linux, click-through uses Qt’s window-level
WindowTransparentForInputflag. Turning it off silently failed: Qt 6 puts the flag back every time the window flags are reapplied, as long as the widget’s mouse-transparency attribute is still set. The fix was to clear the attribute first. A test now forces that path on every system.
I also recorded what I didn’t solve, such as pixel art that stretches at 1.5× display scaling. The gaps are documented, not hidden.
One app, three systems
DeskPets runs on Windows, macOS, and Linux from one codebase. Almost all of it is plain Qt and psutil and runs unchanged everywhere: the sprite loader, the animator, the state machine, the stats card, the tray, and the telemetry. What differs is a handful of things no cross-platform library does for a desktop pet. Those live behind one small platform seam, src/core/platform/, with one backend per system:
| Windows | macOS | Linux | |
|---|---|---|---|
| Click-through | WS_EX_TRANSPARENT window style |
NSWindow.setIgnoresMouseEvents |
Qt’s WindowTransparentForInput (an empty X11 input shape) |
| Idle time | GetLastInputInfo |
CGEventSourceSecondsSinceLastEventType |
XScreenSaver on X11, the GNOME/KDE idle monitor on Wayland |
| Staying visible | Qt’s always-on-top | visible on all Spaces and over full-screen apps, not hidden when the app loses focus | Qt’s always-on-top |
| No taskbar or Dock entry | Qt tool window | accessory app (menu bar only) | Qt tool window |
| Pomodoro chime | MessageBeep |
NSSound |
the desktop’s sound player, if present |
| Settings folder | %APPDATA% |
~/Library/Application Support |
$XDG_CONFIG_HOME or ~/.config |
| Native bindings | ctypes |
pyobjc |
ctypes and Qt D-Bus |
A few rules keep it honest:
- Nothing outside the seam knows which system it is on. A test walks the source tree and fails if any other file imports
ctypes, the macOS bindings, or readssys.platform. When a widget needs system behavior, the seam gets a new hook with a do-nothing default, such asprepare_window, which macOS uses to keep the pets on every Space. - Every hook degrades instead of crashing. A system call that fails returns “didn’t happen” and logs once. If a backend can’t load at all, a null backend takes over and the pets still run, just without click-through or the sleep animations.
- The tray reports what actually happened. Click-through is confirmed by reading the state back from the system before the menu shows it as on, and it is only offered when a tray exists, so there is always a way back.
- Native windows get recreated, so settings are reapplied. Changing window flags makes Qt destroy and rebuild the native window, which silently drops anything set on the old one. The pet reapplies click-through and the macOS window behavior after every show, flag change, and screen change.
Wayland was the awkward one. A normal Wayland app can’t choose where its window goes or stay above others, and a pet that forgets where you put it isn’t much of a pet. So on a Wayland session DeskPets asks Qt to use X11 through XWayland, which every mainstream Wayland desktop includes. Idle time is the one thing XWayland can’t see properly, so there it comes from the desktop’s own idle monitor over D-Bus.
Every pull request runs the test suite on Windows, macOS on both Apple Silicon and Intel, and Linux under a virtual display.
The Pomodoro timer
The Pomodoro timer went from idea to working feature in six commits, tests included. That was possible because the UI, the telemetry, and the config were already separate. The timer is one small class, PomodoroTimer in src/core/pomodoro.py. It is a single countdown that knows nothing about the pets or the card.
- A fixed deadline, not a tick count. Starting it records
now + 45 minuteson a monotonic clock, and the time remaining is always the deadline minus the current time. A once-a-second ticker only refreshes the display and notices that the deadline has passed, so a stalled app can’t make the timer drift. - Three signals carry everything outward:
state_changed(bool)when it starts, is cancelled, or finishes;ticked(int)every second with the seconds left; andfinished(), which fires exactly once per run and never on cancel. That is what keeps a cancelled block from triggering a celebration. - Small rules:
toggle()starts or cancels, starting during a run restarts it, and it lives on the GUI thread only. The clock can be swapped for a fake one, so tests don’t wait 45 minutes.
When finished() fires, the app plays the chime and forces the pleased state for five minutes. Both lengths are in src/config.py.
Building the app
DeskPets is developed as Python source, but most people shouldn’t need Python to run it. Each release freezes the app into native code once per system: a Windows installer, a macOS app for each chip, and a Linux archive. Each build is made on its own system, because none of them cross-compile. This is what I learned doing it, including the parts that went wrong. The Windows build came first, so most of the measurements below are from it.
Why Nuitka
I chose Nuitka over PyInstaller mainly because I wanted to learn it, and because it compiles Python to C instead of bundling a bytecode interpreter. It supports Python 3.14, which is what DeskPets uses. The cost is a C compiler: on macOS that is Apple’s free Command Line Tools, on Linux the system’s GCC, and on Windows Visual Studio’s build tools. Its fallbacks (MinGW, Zig) didn’t work for Python 3.14 on my machine, so installing the “Desktop development with C++” workload was the fix.
One warning from the Nuitka PyQt6 plugin worried me: Qt threading does not work. DeskPets samples system metrics on a worker QThread, so I ran the frozen build with telemetry live before trusting it. It sampled normally, including the NVIDIA reading. That is encouraging but not a long-running soak test.
Finding the assets when frozen
The sprite atlas used to be found relative to the source file. A frozen app has no source tree, so a build that works on my machine could fail on yours. config.app_root() now returns the install folder when the app is frozen and the repository root otherwise, and never uses the working directory. The --validate flag doubles as a smoke test: it loads the atlas from the frozen build and fails loudly if it can’t.
Making it smaller
The first working build was 628 MB, which is absurd for a desktop pet. Most of it was one dependency:
| Step | Folder size |
|---|---|
| First build (numpy with Intel MKL) | 628 MB |
| numpy with OpenBLAS instead | 116 MB |
| numpy removed | 73 MB |
| Unused standard-library modules excluded | 72 MB |
numpy came with conda’s MKL math libraries, which are about 400 MB. Swapping to OpenBLAS cut that, but the real question was why the app needed numpy at all. It was used in exactly one place, a scan that finds the opaque bounds of each frame. That is now a short pure-Python loop over row slices of the 82-frame atlas, so numpy is gone from the runtime environment. The test that checks content bounds still passes, so the result is the same. I am curious how much the test slows down without numpy, but it is only run on demand.
The build also excludes everything the app never imports (the art-pipeline tools, test packages, and parts of the standard library such as XML and compression). The installer itself, which compresses the folder, is 22.4 MB.
Two things didn’t shrink: OpenSSL (about 8 MB) is still bundled because the standard library’s hashing module links to it, and the Qt libraries are most of what remains. Excluding both is possible, but I left them in for now because the saving didn’t seem worth the risk of breaking something untested.
The Windows installer
The folder is wrapped with Inno Setup into DeskPets-Setup-0.1.1.exe. It installs per user, so it needs no administrator rights, adds a Start Menu shortcut, and has an uninstaller. “Start when I sign in to Windows” is offered as an option that is off by default, and it only touches the current user’s startup entry. Settings live in %APPDATA%\LC-pet-stat, which the uninstaller leaves alone, so they survive both uninstalling and upgrading.
The last page of the installer has a “Launch DeskPets” box, unticked by default. I made it opt-in after a test on a clean virtual machine: the first start after installing is slow, because Windows Defender scans the new files, and the pet can take a noticeable while to appear. Starting it a second time was almost instant. That fits Defender scanning on first run, which I haven’t isolated further. In my test, impatient double launches produced two pets, because the app doesn’t stop a second copy from starting.
The macOS app
On macOS, Nuitka builds a real DeskPets.app bundle, marked as a menu-bar-only app so it has no Dock icon. There is one build per chip, Apple Silicon and Intel, each made on that kind of Mac. Each is zipped with ditto, which keeps the bundle’s metadata intact.
The app is ad-hoc signed and not notarized. Notarization needs a paid Apple Developer membership, which doesn’t make sense for a free side project. Ad-hoc signing is free and is what Apple Silicon requires before it will run native code at all. The trade-off is one extra step for the user: macOS blocks the first launch until it is allowed once in Privacy & Security, or the quarantine flag is removed in Terminal. The Download page explains both, and running from source with pixi avoids the question entirely, because nothing is downloaded as an app.
The frozen app finds its sprites inside the bundle through the same config.app_root() as on Windows, and --validate checks that from the built app.
The Linux archive
On Linux the frozen folder ships as a plain .tar.gz with a .desktop file for the application menu and for autostart. No installer, no root access, and nothing outside the folder you extract it to, apart from the settings in ~/.config/LC-pet-stat. It needs the system’s X11 and OpenGL libraries, which every graphical desktop already has.
What I tested on a clean machine
I ran the Windows installer on a fresh Windows 11 virtual machine (Hyper-V), reverted to a clean checkpoint before each run. These all worked:
- Install and run. The app installs without administrator rights and runs.
- Settings survive uninstalling. They stay in
%APPDATA%\LC-pet-stat, as designed. - Upgrading in place works. Installing a newer build over the old one keeps the settings.
- Quit leaves nothing behind. After choosing Quit from the tray, no
DeskPets.exeprocess remains. - Start when I sign in. With the option ticked the app starts at sign-in, and with it unticked nothing is added. Uninstalling removes the entry.
- Hover card and Pomodoro. The stats card appears on hover, and the Pomodoro timer’s ping plays when it finishes.
- No NVIDIA GPU. The virtual machine has no GPU at all, and the app runs normally without it.
What isn’t proven yet
- The Windows installer is unsigned, so Windows SmartScreen will warn when it is downloaded. The macOS app is not notarized, so Gatekeeper asks once.
- The first start after installing can be slow while Windows scans the files. This is expected to affect any freshly installed program, but I’ve only seen it in one virtual machine.
- The app is still in early development and needs to be tried on other people’s machines. That goes double for macOS and Linux, where the variety of hardware and desktops is the real test.