Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions bin/omarchy-debug-idle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ section "Idle inhibitors"
hyprctl clients -j 2>/dev/null \
| jq -r '.[] | select(.inhibitingIdle == true or ((.tags // []) | index("noidle"))) | [.pid,.class,.title,((.tags // []) | join(",")),.inhibitingIdle] | @tsv' || true

section "D-Bus idle inhibitors"
if [[ -f $HOME/.local/state/omarchy/idle-inhibitors ]]; then
idle_inhibitors="$(jq -r '.count // 0' "$HOME/.local/state/omarchy/idle-inhibitors" 2>/dev/null)"
if [[ $idle_inhibitors -gt 0 ]]; then
echo "active count: $idle_inhibitors"
jq -r '.inhibitors[]? | " \(.app): \(.reason) (cookie \(.cookie))"' "$HOME/.local/state/omarchy/idle-inhibitors" 2>/dev/null || true
else
echo "none"
fi
else
echo "none"
fi

section "Screensaver detector"
if hyprctl clients -j 2>/dev/null | jq -e '.[] | select(.class == "org.omarchy.screensaver" or .initialClass == "org.omarchy.screensaver")' >/dev/null; then
echo "running-window"
Expand Down
160 changes: 160 additions & 0 deletions bin/omarchy-idle-inhibit
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
#!/usr/bin/env python3

# omarchy:summary=Own the D-Bus idle-inhibit name so apps can suppress the screensaver
# omarchy:group=system
# omarchy:hidden=true

"""Own org.freedesktop.ScreenSaver on the session bus and track idle inhibitors.

Quattro replaced hypridle with a Quickshell idle service. hypridle natively owned
the org.freedesktop.ScreenSaver D-Bus name, so apps playing video (Firefox, Chromium,
Zen, VLC) could call Inhibit() to keep the screensaver from firing. That role was
never reimplemented, so D-Bus Inhibit() calls are silently dropped and the
screensaver fires during playback (issue #6475).

This daemon re-owns that name, counts active Inhibits, and writes the count plus a
detail list to a state file that the Quickshell idle service watches. The service
suppresses idle while any inhibitor is active, exactly as hypridle did.
"""

import argparse
import json
import os
import signal
import tempfile

import dbus
import dbus.mainloop.glib
import dbus.service
from gi.repository import GLib
from gi.repository import GLibUnix

# GLib main loop priority for signal handlers.
_PRIORITY = GLib.PRIORITY_DEFAULT

STATE_DIR = os.path.expanduser("~/.local/state/omarchy")
STATE_FILE = os.path.join(STATE_DIR, "idle-inhibitors")

SERVICE_NAME = "org.freedesktop.ScreenSaver"
OBJECT_PATH = "/ScreenSaver"


def atomic_write(path, data):
"""Write JSON atomically so the watcher never reads a half-written file."""
os.makedirs(os.path.dirname(path), exist_ok=True)
fd, tmp = tempfile.mkstemp(dir=os.path.dirname(path), prefix=".idle-inhibitors-")
try:
with os.fdopen(fd, "w") as f:
json.dump(data, f, indent=2)
f.flush()
os.fsync(f.fileno())
os.replace(tmp, path)
except BaseException:
try:
os.unlink(tmp)
except OSError:
pass
raise


class ScreenSaver(dbus.service.Object):
"""Minimal org.freedesktop.ScreenSaver that tracks active inhibitors."""

def __init__(self, bus_name, emit):
super().__init__(bus_name, OBJECT_PATH)
self._cookies = {}
self._next_cookie = 1
self._emit = emit

def _emit_state(self):
self._emit(len(self._cookies), list(self._cookies.values()))

@dbus.service.method(SERVICE_NAME, in_signature="ss", out_signature="u",
sender_keyword="sender")
def Inhibit(self, app_name, reason, sender=None):
cookie = self._next_cookie
self._next_cookie += 1
self._cookies[cookie] = {
"app": app_name,
"reason": reason,
"cookie": cookie,
"owner": sender,
}
self._emit_state()
return cookie

@dbus.service.method(SERVICE_NAME, in_signature="u", out_signature="")
def UnInhibit(self, cookie):
self._cookies.pop(int(cookie), None)
self._emit_state()

def release_owner(self, owner):
"""Drop every inhibitor registered by a now-disconnected caller.

Apps can die without calling UnInhibit (a crash, a killed tab, an OOM
kill). If we kept their inhibitors, the screen would stay awake forever,
so we release them as soon as the owning connection leaves the bus.
"""
dead = [cookie for cookie, info in self._cookies.items()
if info.get("owner") == owner]
for cookie in dead:
del self._cookies[cookie]
if dead:
self._emit_state()


def parse_args():
parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0])
parser.add_argument(
"--state-file",
default=STATE_FILE,
help="path to the state file (default: %(default)s)",
)
return parser.parse_args()


def run(state_file):
def emit(count, inhibitors):
atomic_write(state_file, {"count": count, "inhibitors": inhibitors})

# Fresh ownership: nothing is inhibited until an app calls Inhibit().
emit(0, [])

dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
bus_name = dbus.service.BusName(SERVICE_NAME, bus)
saver = ScreenSaver(bus_name, emit)

# Apps can die without UnInhibit; release their inhibitors when their
# connection leaves the bus so a crashed browser can't keep the screen
# awake forever.
def on_name_owner_changed(name, _old_owner, new_owner):
if name.startswith(":") and new_owner == "":
saver.release_owner(name)

bus.add_signal_receiver(
on_name_owner_changed,
dbus_interface="org.freedesktop.DBus",
signal_name="NameOwnerChanged",
path="/org/freedesktop/DBus",
)

loop = GLib.MainLoop()

def shutdown():
# Releasing the name means no app is inhibited; clear the state file so
# the idle service re-arms immediately rather than waiting for a watcher.
emit(0, [])
loop.quit()
return GLib.SOURCE_REMOVE

# Handle signals through GLib so they integrate with the main loop instead
# of racing it. Without this, SIGTERM during loop.run() is dropped.
GLibUnix.signal_add(_PRIORITY, signal.SIGTERM, shutdown)
GLibUnix.signal_add(_PRIORITY, signal.SIGINT, shutdown)

loop.run()


if __name__ == "__main__":
run(parse_args().state_file)
20 changes: 20 additions & 0 deletions default/systemd/user/omarchy-idle-inhibit.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[Unit]
Description=Own the D-Bus idle-inhibit name for Omarchy
# The daemon owns org.freedesktop.ScreenSaver on the session bus. Wait until
# UWSM has imported OMARCHY_PATH and WAYLAND_DISPLAY, but keep the default
# target ordering so the daemon starts before graphical-session.target is
# reached.
After=dbus.socket wayland-session-waitenv.service
Requires=dbus.socket
PartOf=graphical-session.target
ConditionEnvironment=OMARCHY_PATH
ConditionEnvironment=WAYLAND_DISPLAY

[Service]
Type=simple
ExecStart=/usr/bin/omarchy-idle-inhibit
Restart=always
RestartSec=2

[Install]
WantedBy=graphical-session.target
1 change: 1 addition & 0 deletions install/omarchy-base.packages
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ plymouth
postgresql-libs
power-profiles-daemon
python-gobject
python-dbus
python-poetry-core
python-terminaltexteffects
qemu-user-static-binfmt
Expand Down
1 change: 1 addition & 0 deletions install/user/first-run/enable-user-units.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ set -euo pipefail
systemctl --user daemon-reload
systemctl --user enable --now \
bt-agent.service \
omarchy-idle-inhibit.service \
omarchy-recover-internal-monitor.service \
omarchy-sleep-lock.service \
omarchy-migrate-notify.service \
Expand Down
52 changes: 52 additions & 0 deletions migrations/1785963476.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
echo "Enable the D-Bus idle-inhibit daemon so apps can suppress the screensaver"

# Enable + start the idle-inhibit daemon for existing Quattro users. It owns
# org.freedesktop.ScreenSaver on the session bus so apps playing video can keep
# the screensaver from firing (issue #6475).

# The daemon imports python-dbus. `omarchy update` runs `pacman -Syu`, which does
# not reconcile install/omarchy-base.packages, so existing users may not have the
# dependency yet; install it before starting the service.
if omarchy-pkg-missing python-dbus; then
omarchy-pkg-add python-dbus
fi

# The unit is normally installed by the omarchy-settings package to
# /usr/lib/systemd/user. When the package update and this migration do not land
# together (e.g. a local checkout update), link a user copy so systemctl and the
# wants symlink below can find the unit. Symlink, not copy: a copied unit at
# ~/.config/systemd/user would permanently shadow the packaged unit and never
# receive later fixes, while the link tracks the checkout it came from.
user_config_home="${XDG_CONFIG_HOME:-$HOME/.config}"
unit_source="$OMARCHY_PATH/default/systemd/user/omarchy-idle-inhibit.service"
unit_dest="$user_config_home/systemd/user/omarchy-idle-inhibit.service"
unit_target="/usr/lib/systemd/user/omarchy-idle-inhibit.service"

# Resolve which file systemctl should load: the packaged unit when it exists,
# otherwise the checkout link. Prefer the packaged path so the wants symlink
# keeps tracking package fixes rather than a user-dir copy.
if [[ ! -f $unit_target ]]; then
unit_target="$unit_dest"
if [[ -f $unit_source ]]; then
mkdir -p "$(dirname "$unit_dest")"
ln -sfn "$unit_source" "$unit_dest"
fi
fi

systemctl --user daemon-reload >/dev/null 2>&1 || true

# `systemctl enable` needs a live user manager, which an update from a TTY/SSH
# does not have. Fall back to writing exactly the symlink it would have written,
# rather than silently leaving the daemon unenabled and the migration marked
# complete (which would strand the unit at the next graphical login).
if ! systemctl --user enable omarchy-idle-inhibit.service >/dev/null 2>&1; then
wants_dir="$user_config_home/systemd/user/graphical-session.target.wants"
mkdir -p "$wants_dir"
ln -sfn "$unit_target" "$wants_dir/omarchy-idle-inhibit.service"
fi

# Outside a graphical session there is no shell to feed idle inhibitors to; the
# enablement above is the whole job, and the next graphical login starts it.
if systemctl --user is-active --quiet graphical-session.target; then
systemctl --user start omarchy-idle-inhibit.service >/dev/null 2>&1 || true
fi
32 changes: 31 additions & 1 deletion shell/plugins/services/idle/IdleModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,34 @@ function eventParts(event, count) {
return String(event && event.data ? event.data : "").split(",")
}

// The idle-inhibit daemon writes {count, inhibitors} to a state file. Parse the
// file text into a safe count: a missing file, unparseable JSON, or an object
// without a numeric count all mean "no inhibitors" so a daemon failure clears a
// stale nonzero count instead of disabling the lock indefinitely.
function inhibitorCountFromText(text) {
var raw = text !== undefined && text !== null ? String(text) : ""
if (!raw.length) return 0

try {
var parsed = JSON.parse(raw)
if (parsed && typeof parsed.count === "number" && parsed.count > 0) {
return Math.floor(parsed.count)
}
} catch (error) {
}
return 0
}

// Decide what to do when the observed inhibitor count changes. Returns a string
// the caller switches on: "cancel" (an inhibitor appeared mid-cycle, pull back
// the screensaver/lock), "rearm" (all inhibitors released, idle may resume), or
// "noop" (no transition, keep the current behavior).
function inhibitorTransition(previous, current) {
if (previous === 0 && current > 0) return "cancel"
if (previous > 0 && current === 0) return "rearm"
return "noop"
}

function screensaverWindowsAfter(windows, address, visible) {
var key = String(address || "")
if (!key) {
Expand Down Expand Up @@ -47,6 +75,8 @@ if (typeof module !== "undefined") {
module.exports = {
secondsFromConfig: secondsFromConfig,
eventParts: eventParts,
screensaverWindowsAfter: screensaverWindowsAfter
screensaverWindowsAfter: screensaverWindowsAfter,
inhibitorCountFromText: inhibitorCountFromText,
inhibitorTransition: inhibitorTransition
}
}
Loading