diff options
| author | Christopher Warner <cwarner@kernelcode.com> | 2026-04-09 08:06:42 -0400 |
|---|---|---|
| committer | Christopher Warner <cwarner@kernelcode.com> | 2026-04-09 08:06:42 -0400 |
| commit | fbe633623adb570476ea6f6922d488130414cc42 (patch) | |
| tree | b841fe7957710a1f71994c65b4525803470d69dc | |
| parent | 1462d4bc701194c7e0c2569a8e7acfd50fd2f77d (diff) | |
| download | aerial-screensaver-linux-fbe633623adb570476ea6f6922d488130414cc42.tar.gz aerial-screensaver-linux-fbe633623adb570476ea6f6922d488130414cc42.tar.bz2 aerial-screensaver-linux-fbe633623adb570476ea6f6922d488130414cc42.tar.xz aerial-screensaver-linux-fbe633623adb570476ea6f6922d488130414cc42.zip | |
Make screensaver lid-aware to prevent idle timer reset when lid is closed
| -rwxr-xr-x | aerial-screensaver.py | 88 |
1 files changed, 56 insertions, 32 deletions
diff --git a/aerial-screensaver.py b/aerial-screensaver.py index 9d89796..87d7581 100755 --- a/aerial-screensaver.py +++ b/aerial-screensaver.py @@ -22,6 +22,7 @@ logging.basicConfig( # Configuration IDLE_TIMEOUT_SECONDS = 300 # 5 minutes VIDEO_DIR = os.path.expanduser("~/Videos/Screensavers/Aerial") +LID_STATE_FILE = "/proc/acpi/button/lid/LID0/state" # mpv "Lite" Command (Mimicking VLC efficiency) MPV_COMMAND = [ @@ -40,6 +41,7 @@ MPV_COMMAND = [ "--framedrop=vo", # Efficiently drop frames to match display "--no-osc", "--no-osd-bar", + "--osd-level=0", "--cursor-autohide=always", "--no-audio", "--playlist=-" @@ -51,36 +53,41 @@ class AerialScreensaver: self.idle_monitor = None self.watch_id = None - logging.info("Initializing Aerial Screensaver (mpv Lite Backend, AC-only)...") + logging.info("Initializing Aerial Screensaver (mpv Lite Backend, AC-only, Lid-Aware)...") - 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) + connected = False + while not connected: + 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) + connected = True + + except Exception as e: + logging.error(f"Failed to connect to IdleMonitor: {e}") + logging.info("Retrying in 5 seconds...") + time.sleep(5) + self.idle_monitor = None def is_on_ac(self): try: @@ -94,15 +101,26 @@ class AerialScreensaver: logging.error(f"Error checking AC status: {e}") return False + def is_lid_open(self): + try: + if not os.path.exists(LID_STATE_FILE): + return True + with open(LID_STATE_FILE, 'r') as f: + content = f.read().strip() + return "open" in content + except Exception as e: + logging.error(f"Error checking lid 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.") + if self.is_on_ac() and self.is_lid_open(): + logging.info("Idle threshold reached, on AC and lid is OPEN. Starting mpv.") self.start_screensaver() else: - logging.info("Idle threshold reached but on battery. Skipping.") + logging.info(f"Idle threshold reached but skip (AC: {self.is_on_ac()}, Lid Open: {self.is_lid_open()})") def start_screensaver(self): if self.process and self.process.poll() is None: @@ -147,6 +165,12 @@ class AerialScreensaver: while self.process and self.process.poll() is None: 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() + break + reply = self.idle_monitor.call_sync( "GetIdletime", None, |
