diff options
Diffstat (limited to 'aerial_screensaver.py')
| -rwxr-xr-x | aerial_screensaver.py | 89 |
1 files changed, 67 insertions, 22 deletions
diff --git a/aerial_screensaver.py b/aerial_screensaver.py index 7b64cac..e1a0753 100755 --- a/aerial_screensaver.py +++ b/aerial_screensaver.py @@ -205,8 +205,12 @@ class AerialScreensaver: logging.error("Error checking lid status: %s", e) return True - def _display_state(self) -> tuple[int, bool]: - """Return (logical_monitor_count, has_external_display).""" + def list_logical_screens(self) -> list[dict]: + """Active GNOME logical monitors as mpv screen targets. + + Each item: {index, connector, primary, builtin}. + Index matches Mutter logical-monitor order (what mpv --screen uses). + """ try: proxy = Gio.DBusProxy.new_for_bus_sync( Gio.BusType.SESSION, @@ -225,29 +229,33 @@ class AerialScreensaver: None, ) _serial, _monitors, logical_monitors, _props = reply.unpack() - has_external = False - for lm in logical_monitors: + screens: list[dict] = [] + for index, lm in enumerate(logical_monitors): # (x, y, scale, transform, primary, monitors, properties) - for mon in lm[5]: - connector = mon[0] - if not _connector_is_builtin(connector): - has_external = True - break - if has_external: - break - return len(logical_monitors), has_external + primary = bool(lm[4]) + connectors = [mon[0] for mon in lm[5]] + connector = connectors[0] if connectors else f"screen-{index}" + builtin = any(_connector_is_builtin(c) for c in connectors) + screens.append( + { + "index": index, + "connector": connector, + "primary": primary, + "builtin": builtin, + } + ) + return screens except Exception as e: logging.error("Error detecting displays: %s", e) - return 0, False + return [] def get_screen_count(self) -> int: """Return active GNOME logical monitor count (fallback: 1).""" - count, _external = self._display_state() - return max(1, count) if count > 0 else 1 + screens = self.list_logical_screens() + return max(1, len(screens)) if screens else 1 def has_external_display(self) -> bool: - _count, external = self._display_state() - return external + return any(not s["builtin"] for s in self.list_logical_screens()) def display_ok(self) -> bool: """Lid open, or clamshell (lid closed + external display) when allowed.""" @@ -257,6 +265,28 @@ class AerialScreensaver: return True return False + def screens_for_playback(self) -> list[dict]: + """Which screens should show the screensaver. + + Lid open: every logical monitor. + Lid closed (clamshell): only external (non-eDP) monitors, primary first. + """ + screens = self.list_logical_screens() + if not screens: + return [{"index": 0, "connector": "unknown", "primary": True, "builtin": False}] + + if self.is_lid_open(): + return screens + + external = [s for s in screens if not s["builtin"]] + if not external: + # No external detected — fall back to primary rather than a blank lid panel. + primary = [s for s in screens if s["primary"]] + return primary or screens[:1] + + external.sort(key=lambda s: (not s["primary"], s["index"])) + return external + def on_dbus_signal(self, proxy, sender_name, signal_name, parameters) -> None: if signal_name != "WatchFired": return @@ -338,22 +368,31 @@ class AerialScreensaver: logging.error("No video files found in %s", self.video_dir) return - screen_count = self.get_screen_count() + targets = self.screens_for_playback() logging.info( - "Using %s clips from %s on %s screen(s)", + "Using %s clips from %s on %s screen(s): %s", len(videos), self.video_dir, - screen_count, + len(targets), + ", ".join( + f"{t['connector']}(idx={t['index']},primary={t['primary']})" + for t in targets + ), ) urls = "\n".join(videos) base = self._mpv_base_command() self.processes = [] - for screen in range(screen_count): + for target in targets: + screen = int(target["index"]) + connector = target["connector"] ipc = f"{IPC_SOCKET_PREFIX}{screen}" try: os.unlink(ipc) except FileNotFoundError: pass + # Target by Mutter logical index (mpv --screen). When the lid is + # closed we only include external connectors, so we never put + # fullscreen video on a blank eDP panel that is still "screen 0". cmd = base + [ f"--input-ipc-server={ipc}", f"--screen={screen}", @@ -370,7 +409,13 @@ class AerialScreensaver: proc.stdin.write(urls) proc.stdin.close() self.processes.append(proc) - logging.info("mpv started on screen %s with PID: %s", screen, proc.pid) + logging.info( + "mpv started on %s (screen idx %s, primary=%s) with PID: %s", + connector, + screen, + target["primary"], + proc.pid, + ) threading.Thread(target=self.monitor_activity, daemon=True).start() except Exception as e: logging.error("Error starting mpv: %s", e) |
