summaryrefslogtreecommitdiff
path: root/aerial_screensaver.py
diff options
context:
space:
mode:
authorChristopher Warner <cwarner@kernelcode.com>2026-10-12 10:36:27 -0400
committerChristopher Warner <cwarner@kernelcode.com>2026-10-12 10:36:27 -0400
commitead35d75893dcbc34a97beb165a2d46f7741bfc8 (patch)
tree1e826741ccf7f24df6a592aa00fe7341a17c1c4b /aerial_screensaver.py
parent2f45bfb39e7c0b296082c033b728436c88b189fc (diff)
downloadaerial-screensaver-linux-ead35d75893dcbc34a97beb165a2d46f7741bfc8.tar.gz
aerial-screensaver-linux-ead35d75893dcbc34a97beb165a2d46f7741bfc8.tar.bz2
aerial-screensaver-linux-ead35d75893dcbc34a97beb165a2d46f7741bfc8.tar.xz
aerial-screensaver-linux-ead35d75893dcbc34a97beb165a2d46f7741bfc8.zip
Show Aerial screensaver on every connected monitor.
Spawn one fullscreen mpv per GNOME logical monitor so idle playback covers the laptop panel and external display, not only the primary. Co-authored-by: Cursor <cursoragent@cursor.com>
Diffstat (limited to 'aerial_screensaver.py')
-rwxr-xr-xaerial_screensaver.py174
1 files changed, 119 insertions, 55 deletions
diff --git a/aerial_screensaver.py b/aerial_screensaver.py
index 87d7581..3c93086 100755
--- a/aerial_screensaver.py
+++ b/aerial_screensaver.py
@@ -2,7 +2,6 @@
import time
import subprocess
import os
-import random
import sys
import threading
import logging
@@ -23,38 +22,47 @@ logging.basicConfig(
IDLE_TIMEOUT_SECONDS = 300 # 5 minutes
VIDEO_DIR = os.path.expanduser("~/Videos/Screensavers/Aerial")
LID_STATE_FILE = "/proc/acpi/button/lid/LID0/state"
+IPC_SOCKET_PREFIX = "/tmp/mpv_aerial_"
-# mpv "Lite" Command (Mimicking VLC efficiency)
-MPV_COMMAND = [
+# Quiet playback: iGPU VAAPI decode, cheap scaling, no audio, drop freely.
+MPV_BASE_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)
+ "--vo=gpu",
"--gpu-context=wayland",
- "--video-sync=audio", # Lower overhead than display-resample
- "--framedrop=vo", # Efficiently drop frames to match display
+ "--gpu-api=opengl",
+ "--scale=bilinear",
+ "--cscale=bilinear",
+ "--dscale=bilinear",
+ "--dither=no",
+ "--correct-downscaling=no",
+ "--sigmoid-upscaling=no",
+ "--video-sync=audio",
+ "--framedrop=vo",
+ "--vf=fps=24",
"--no-osc",
"--no-osd-bar",
"--osd-level=0",
"--cursor-autohide=always",
"--no-audio",
- "--playlist=-"
+ "--playlist=-",
]
+
class AerialScreensaver:
def __init__(self):
- self.process = None
+ self.processes = []
self.idle_monitor = None
self.watch_id = None
-
- logging.info("Initializing Aerial Screensaver (mpv Lite Backend, AC-only, Lid-Aware)...")
-
+
+ logging.info("Initializing Aerial Screensaver (mpv Lite Backend, AC-only, Lid-Aware, multi-screen)...")
+
connected = False
while not connected:
try:
@@ -67,8 +75,7 @@ class AerialScreensaver:
"org.gnome.Mutter.IdleMonitor",
None
)
-
- # Add watch for idle time
+
reply = self.idle_monitor.call_sync(
"AddIdleWatch",
GLib.Variant("(t)", (IDLE_TIMEOUT_SECONDS * 1000,)),
@@ -78,11 +85,10 @@ class AerialScreensaver:
)
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)
connected = True
-
+
except Exception as e:
logging.error(f"Failed to connect to IdleMonitor: {e}")
logging.info("Retrying in 5 seconds...")
@@ -112,6 +118,34 @@ class AerialScreensaver:
logging.error(f"Error checking lid status: {e}")
return True
+ def get_screen_count(self):
+ """Return active GNOME logical monitor count (fallback: 1)."""
+ try:
+ proxy = Gio.DBusProxy.new_for_bus_sync(
+ Gio.BusType.SESSION,
+ Gio.DBusProxyFlags.NONE,
+ None,
+ "org.gnome.Mutter.DisplayConfig",
+ "/org/gnome/Mutter/DisplayConfig",
+ "org.gnome.Mutter.DisplayConfig",
+ None
+ )
+ reply = proxy.call_sync(
+ "GetCurrentState",
+ None,
+ Gio.DBusCallFlags.NONE,
+ -1,
+ None
+ )
+ _serial, _monitors, logical_monitors, _props = reply.unpack()
+ count = len(logical_monitors)
+ if count < 1:
+ return 1
+ return count
+ except Exception as e:
+ logging.error(f"Error detecting screens, defaulting to 1: {e}")
+ return 1
+
def on_dbus_signal(self, proxy, sender_name, signal_name, parameters):
if signal_name == "WatchFired":
watch_id = parameters.unpack()[0]
@@ -122,50 +156,71 @@ class AerialScreensaver:
else:
logging.info(f"Idle threshold reached but skip (AC: {self.is_on_ac()}, Lid Open: {self.is_lid_open()})")
+ def _collect_videos(self):
+ if not os.path.isdir(VIDEO_DIR):
+ return []
+ return [
+ os.path.join(VIDEO_DIR, f)
+ for f in os.listdir(VIDEO_DIR)
+ if f.lower().endswith((".mov", ".mp4", ".mkv"))
+ and not f.startswith("_test")
+ and not f.startswith(".")
+ and ".partial." not in f.lower()
+ ]
+
+ def _any_running(self):
+ return any(p.poll() is None for p in self.processes)
+
def start_screensaver(self):
- if self.process and self.process.poll() is None:
+ if self._any_running():
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'))
- ]
-
+ videos = self._collect_videos()
if not videos:
- logging.error("No video files found.")
+ logging.error(f"No video files found in {VIDEO_DIR}")
return
+ screen_count = self.get_screen_count()
+ logging.info(f"Using {len(videos)} clips from {VIDEO_DIR} on {screen_count} screen(s)")
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}")
+
+ self.processes = []
+ for screen in range(screen_count):
+ ipc = f"{IPC_SOCKET_PREFIX}{screen}"
+ try:
+ os.unlink(ipc)
+ except FileNotFoundError:
+ pass
+
+ cmd = MPV_BASE_COMMAND + [
+ f"--input-ipc-server={ipc}",
+ f"--screen={screen}",
+ f"--fs-screen={screen}",
+ ]
+ proc = subprocess.Popen(
+ cmd,
+ stdin=subprocess.PIPE,
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.DEVNULL,
+ text=True
+ )
+ if proc.stdin:
+ proc.stdin.write(urls)
+ proc.stdin.close()
+ self.processes.append(proc)
+ logging.info(f"mpv started on screen {screen} with PID: {proc.pid}")
+
threading.Thread(target=self.monitor_activity, daemon=True).start()
-
+
except Exception as e:
logging.error(f"Error starting mpv: {e}")
+ self.stop_screensaver()
def monitor_activity(self):
- while self.process and self.process.poll() is None:
+ while self._any_running():
time.sleep(1)
try:
- # Stop if lid is closed
if not self.is_lid_open():
logging.info("Lid closed during playback. Stopping mpv.")
self.stop_screensaver()
@@ -179,11 +234,11 @@ class AerialScreensaver:
None
)
idle_time = reply.unpack()[0]
-
- if idle_time < 1000:
+
+ if idle_time < 1000:
self.stop_screensaver()
break
-
+
if not self.is_on_ac():
self.stop_screensaver()
break
@@ -193,13 +248,21 @@ class AerialScreensaver:
break
def stop_screensaver(self):
- if self.process:
- self.process.terminate()
+ for proc in self.processes:
+ if proc.poll() is None:
+ proc.terminate()
+ try:
+ proc.wait(timeout=2)
+ except subprocess.TimeoutExpired:
+ proc.kill()
+ self.processes = []
+ for path in (
+ f"{IPC_SOCKET_PREFIX}{i}" for i in range(8)
+ ):
try:
- self.process.wait(timeout=2)
- except subprocess.TimeoutExpired:
- self.process.kill()
- self.process = None
+ os.unlink(path)
+ except FileNotFoundError:
+ pass
def run(self):
loop = GLib.MainLoop()
@@ -208,6 +271,7 @@ class AerialScreensaver:
except KeyboardInterrupt:
pass
+
if __name__ == "__main__":
app = AerialScreensaver()
app.run()