diff options
Diffstat (limited to 'shared/Status.qml')
| -rw-r--r-- | shared/Status.qml | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/shared/Status.qml b/shared/Status.qml index dfb6b83..36853af 100644 --- a/shared/Status.qml +++ b/shared/Status.qml @@ -31,7 +31,11 @@ Singleton { readonly property string dir: Quickshell.env("XDG_RUNTIME_DIR") || "/tmp" readonly property bool dnd: dndFile.value - readonly property bool presentation: presFile.value + // Set by the game detector below, on its own file so it never fights the + // manual toggle: presentation is the OR, and a game ending clears only its + // half. A manual "on" therefore survives a game session. + readonly property bool gaming: gamingFile.value + readonly property bool presentation: presFile.value || gamingFile.value // Stored as "auto-lock disabled", so the missing-file default of off is // the wanted default of locking on. The row inverts it for the label. readonly property bool nolock: nolockFile.value @@ -104,6 +108,12 @@ Singleton { else if (name === "nolock") root.setMode("nolock", !root.nolock); } + // The detector calls this every poll; a write on an unchanged value would + // still land as an atomic write and re-fire the FileView watch for nothing. + function setGaming(on) { + if (on !== root.gaming) gamingFile.write(on); + } + // The timed disable re-enables itself. Runs only while a deadline is // pending, so no tick burns while the mode is off or permanently on. Timer { @@ -162,6 +172,43 @@ Singleton { } } + // --- game detection --------------------------------------------------- + // + // A game is a fullscreen app that already holds the screen, and the idle + // lock, DND and breaktimer are all unwanted while it runs, so presentation + // is set automatically. This machine's games come from Steam and launch + // either under gamescope or directly, so both are tested and either one is + // enough. + // + // The steam pattern is bracketed so it cannot match this very command + // line: pgrep -f reads the whole argv, and the literal "steamapps/common" + // here would otherwise match the sh running the check and report a game + // forever. The character class makes the needle miss itself while still + // matching a real game path. + Process { + id: gameProc + command: ["sh", "-c", + "pgrep -x gamescope >/dev/null 2>&1 || pgrep -f 'steamapps/commo[n]' >/dev/null 2>&1"] + onExited: code => root.setGaming(code === 0) + } + + // Process lifecycle is not a file to watch, so this polls. A game launch + // does not need sub-second latency to present; a missed start corrects on + // the next tick. triggeredOnStart covers a shell start while a game is + // already up. + Timer { + interval: 5000 + repeat: true + running: true + triggeredOnStart: true + onTriggered: { + // Re-assigning running on an already-running Process is a no-op, + // so it is cleared first. + gameProc.running = false; + gameProc.running = true; + } + } + // Wayland idle inhibit. The compositor advertises // zwp_idle_inhibit_manager_v1 and hypridle honours it, so no D-Bus path // is needed even though elogind runs here. nolock is the sole holder; @@ -250,6 +297,8 @@ Singleton { ModeFile { id: dndFile; path: root.dir + "/status.dnd" } ModeFile { id: presFile; path: root.dir + "/status.presentation" } ModeFile { id: nolockFile; path: root.dir + "/status.nolock" } + // Written only by the game detector above, never by statusctl. + ModeFile { id: gamingFile; path: root.dir + "/status.gaming" } WordFile { id: btStateFile; path: root.dir + "/breaktimer.state" } WordFile { id: btPhaseFile; path: root.dir + "/breaktimer.phase" } |
