diff options
| author | Christopher Warner <cwarner@kernelcode.com> | 2026-01-24 20:38:57 -0500 |
|---|---|---|
| committer | Christopher Warner <cwarner@kernelcode.com> | 2026-01-24 20:38:57 -0500 |
| commit | 2b20f2b5b02542a178e137622247e3563143b907 (patch) | |
| tree | 9c93f328c23aa49947ef89fc57a04e10ff2fe17b | |
| download | aerial-screensaver-linux-2b20f2b5b02542a178e137622247e3563143b907.tar.gz aerial-screensaver-linux-2b20f2b5b02542a178e137622247e3563143b907.tar.bz2 aerial-screensaver-linux-2b20f2b5b02542a178e137622247e3563143b907.tar.xz aerial-screensaver-linux-2b20f2b5b02542a178e137622247e3563143b907.zip | |
Initial commit: High-performance screensaver for Framework 16
| -rw-r--r-- | README.md | 26 | ||||
| -rwxr-xr-x | aerial-screensaver.py | 189 | ||||
| -rw-r--r-- | aerial-screensaver.service | 13 |
3 files changed, 228 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..fc71976 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# Aerial Screensaver for Linux + +A high-performance, power-efficient Apple Aerial screensaver implementation for Linux, optimized for the Framework 16 and AMD graphics. + +## Features +- **Power Efficient**: Only runs when connected to AC power. +- **Low Impact**: Runs with `nice 19` priority and `idle` scheduling. +- **Hardware Accelerated**: Uses VA-API on the Integrated GPU to keep the Discrete GPU asleep. +- **Smooth Playback**: Optimized for local 4K HEVC files with frame-dropping logic for 60Hz displays. +- **Systemd Integration**: Runs as a background user service. + +## Requirements +- `mpv` +- `python3` +- `python3-gobject` (for GNOME IdleMonitor access) +- `systemd` + +## Installation +1. Place your Aerial videos in `~/Videos/Screensavers/Aerial`. +2. Copy `aerial-screensaver.py` to `~/.local/bin/aerial-screensaver`. +3. Copy `aerial-screensaver.service` to `~/.config/systemd/user/`. +4. Enable the service: + ```bash + systemctl --user daemon-reload + systemctl --user enable --now aerial-screensaver + ``` diff --git a/aerial-screensaver.py b/aerial-screensaver.py new file mode 100755 index 0000000..04eb972 --- /dev/null +++ b/aerial-screensaver.py @@ -0,0 +1,189 @@ +#!/usr/bin/env python3 +import time +import subprocess +import os +import random +import sys +import threading +import logging +from gi.repository import Gio, GLib + +# Setup Logging +LOG_PATH = os.path.expanduser("~/aerial_debug.log") +logging.basicConfig( + level=logging.DEBUG, + format='%(asctime)s %(levelname)s: %(message)s', + handlers=[ + logging.FileHandler(LOG_PATH), + logging.StreamHandler(sys.stdout) + ] +) + +# Configuration +IDLE_TIMEOUT_SECONDS = 300 # 5 minutes +VIDEO_DIR = os.path.expanduser("~/Videos/Screensavers/Aerial") + +# mpv "Lite" Command (Mimicking VLC efficiency) +MPV_COMMAND = [ + "nice", "-n", "19", + "mpv", + "--fullscreen", + "--no-stop-screensaver", + "--loop-playlist=inf", + "--shuffle", + "--input-ipc-server=/tmp/mpv_socket", + "--hwdec=vaapi", + "--vaapi-device=/dev/dri/by-path/pci-0000:c4:00.0-render", + "--vo=gpu", # Standard GPU renderer (lighter than gpu-next) + "--gpu-context=wayland", + "--video-sync=audio", # Lower overhead than display-resample + "--framedrop=vo", # Efficiently drop frames to match display + "--no-osc", + "--no-osd-bar", + "--cursor-autohide=always", + "--no-audio", + "--playlist=-" +] + +class AerialScreensaver: + def __init__(self): + self.process = None + self.idle_monitor = None + self.watch_id = None + + logging.info("Initializing Aerial Screensaver (mpv Lite Backend, AC-only)...") + + try: + self.idle_monitor = Gio.DBusProxy.new_for_bus_sync( + Gio.BusType.SESSION, + Gio.DBusProxyFlags.NONE, + None, + "org.gnome.Mutter.IdleMonitor", + "/org/gnome/Mutter/IdleMonitor/Core", + "org.gnome.Mutter.IdleMonitor", + None + ) + + # Add watch for idle time + reply = self.idle_monitor.call_sync( + "AddIdleWatch", + GLib.Variant("(t)", (IDLE_TIMEOUT_SECONDS * 1000,)), + Gio.DBusCallFlags.NONE, + -1, + None + ) + self.watch_id = reply.unpack()[0] + logging.info(f"Added IdleWatch with ID: {self.watch_id} for {IDLE_TIMEOUT_SECONDS}s") + + # Listen for signals + self.idle_monitor.connect("g-signal", self.on_dbus_signal) + + except Exception as e: + logging.error(f"Failed to connect to IdleMonitor: {e}") + sys.exit(1) + + def is_on_ac(self): + try: + for ac in os.listdir('/sys/class/power_supply/'): + if ac.startswith('AC'): + with open(f'/sys/class/power_supply/{ac}/online', 'r') as f: + if f.read().strip() == '1': + return True + return False + except Exception as e: + logging.error(f"Error checking AC status: {e}") + return True + + def on_dbus_signal(self, proxy, sender_name, signal_name, parameters): + if signal_name == "WatchFired": + watch_id = parameters.unpack()[0] + if watch_id == self.watch_id: + if self.is_on_ac(): + logging.info("Idle threshold reached and on AC. Starting mpv.") + self.start_screensaver() + else: + logging.info("Idle threshold reached but on battery. Skipping.") + + def start_screensaver(self): + if self.process and self.process.poll() is None: + return + + try: + if not os.path.isdir(VIDEO_DIR): + logging.error(f"Video directory not found: {VIDEO_DIR}") + return + + videos = [ + os.path.join(VIDEO_DIR, f) + for f in os.listdir(VIDEO_DIR) + if f.lower().endswith(('.mov', '.mp4', '.mkv')) + ] + + if not videos: + logging.error("No video files found.") + return + + urls = "\n".join(videos) + + self.process = subprocess.Popen( + MPV_COMMAND, + stdin=subprocess.PIPE, + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + text=True + ) + + if self.process.stdin: + self.process.stdin.write(urls) + self.process.stdin.close() + + logging.info(f"mpv started with PID: {self.process.pid}") + threading.Thread(target=self.monitor_activity, daemon=True).start() + + except Exception as e: + logging.error(f"Error starting mpv: {e}") + + def monitor_activity(self): + while self.process and self.process.poll() is None: + time.sleep(1) + try: + reply = self.idle_monitor.call_sync( + "GetIdletime", + None, + Gio.DBusCallFlags.NONE, + -1, + None + ) + idle_time = reply.unpack()[0] + + if idle_time < 1000: + self.stop_screensaver() + break + + if not self.is_on_ac(): + self.stop_screensaver() + break + + except Exception as e: + logging.error(f"Error in monitor_activity: {e}") + break + + def stop_screensaver(self): + if self.process: + self.process.terminate() + try: + self.process.wait(timeout=2) + except subprocess.TimeoutExpired: + self.process.kill() + self.process = None + + def run(self): + loop = GLib.MainLoop() + try: + loop.run() + except KeyboardInterrupt: + pass + +if __name__ == "__main__": + app = AerialScreensaver() + app.run() diff --git a/aerial-screensaver.service b/aerial-screensaver.service new file mode 100644 index 0000000..b6cc5eb --- /dev/null +++ b/aerial-screensaver.service @@ -0,0 +1,13 @@ +[Unit] +Description=Aerial Screensaver Daemon (AC only, Low Priority) +After=network.target + +[Service] +ExecStart=/usr/bin/python3 /home/christopherwarner/.local/bin/aerial-screensaver +Restart=always +Nice=19 +CPUSchedulingPolicy=idle +IOSchedulingClass=idle + +[Install] +WantedBy=default.target |
