Add a manual Game Mode Control Center tile

Turns off animations, blur, shadows and HyprGlass, switches to the
performance power profile and turns on Do Not Disturb, each optional in
Settings > Power. The helper journals the values it changes per Hyprland
session and restores them exactly, also after a shell crash.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mxandClaude Opus 5.5 committed 2026-10-17 22:13:48 +02:00
1 parent 9e1ac4efe7
commit bfbfc8961e
15 files changed
+325 -1

No files matched your search

+1
View File
@@ -88,6 +88,7 @@ function validate(c) {
const notes=c.notifications;
if(!notes || ["enabled","doNotDisturb","criticalInDnd"].some(k=>typeof notes[k]!=="boolean") || !["slide","drop","fade","shrink"].includes(notes.animation) || !["top-right","top-center"].includes(notes.position) || !Number.isInteger(notes.timeout) || notes.timeout<1000 || notes.timeout>30000 || !Number.isInteger(notes.maxPopups) || notes.maxPopups<1 || notes.maxPopups>6)throw Error("Invalid notification preferences");
if(c.controlCenter.version !== 2 || !Number.isFinite(c.controlCenter.width) || c.controlCenter.width < 320 || c.controlCenter.width > 600 || !Array.isArray(c.controlCenter.modules))throw Error("Invalid Control Center configuration");
if(!c.gameMode || ["effects","doNotDisturb","performance"].some(k=>typeof c.gameMode[k]!=="boolean"))throw Error("Invalid Game Mode preferences");
const controlIds=new Set();
for(const m of c.controlCenter.modules) { if(!m || typeof m.id!=="string" || controlIds.has(m.id) || typeof m.enabled!=="boolean" || ["w","h"].some(k=>m[k]!==undefined && (!Number.isInteger(m[k]) || m[k]<1 || m[k]>4)) || [["x",3],["y",63]].some(([k,max])=>m[k]!==undefined && (!Number.isInteger(m[k]) || m[k]<0 || m[k]>max)))throw Error("Invalid Control Center module"); controlIds.add(m.id); }
for(const group of [c.system.brightness,c.system.nightLight]) for(const key of ["statusCommand","setCommand"])if(!Array.isArray(group[key]) || group[key].some(v=>typeof v!=="string" || !v.length))throw Error("Provider command must be an argument array");
+81
View File
@@ -0,0 +1,81 @@
pragma Singleton
import QtQuick
import Quickshell
import Quickshell.Io
// Game Mode: compositor effects off, performance power profile and Do Not
// Disturb while gaming, switched by hand. The helper journals what it changed,
// so effects and the profile come back even after a shell crash.
Singleton {
id: root
property string helper: "helpers/gamemode.py"
property bool active: false
property string error: ""
readonly property var options: ConfigService.ready ? ConfigService.data.gameMode : ({
effects: true,
doNotDisturb: true,
performance: true
})
// What is applied right now, and the DND state to put back.
property bool applied: false
property var restoreDnd: null
function toggle() {
active = !active;
return true;
}
// Debounced, so quick double clicks settle on the last state.
onActiveChanged: sync.restart()
Timer {
id: sync
interval: 250
onTriggered: root.apply()
}
function apply() {
if (root.active === root.applied)
return;
if (job.running) {
sync.restart();
return;
}
applied = active;
job.start({
action: active ? "on" : "off",
effects: options.effects,
performance: options.performance
});
if (active && options.doNotDisturb && NotificationService.active && !NotificationService.dnd) {
restoreDnd = false;
NotificationService.setDnd(true);
} else if (!active && restoreDnd !== null) {
NotificationService.setDnd(restoreDnd);
restoreDnd = null;
}
}
// A crash while on left effects off: put back what the journal holds.
Component.onCompleted: job.start({
action: "off"
})
ProviderJob {
id: job
helper: root.helper
onFinished: (request, result) => {
root.error = result.ok ? "" : result.error || "Game Mode request failed";
// A change while the request ran is applied now.
if (root.active !== root.applied)
sync.restart();
}
}
IpcHandler {
target: "gamemode"
function toggle(): bool {
return root.toggle();
}
function status(): string {
return JSON.stringify({
active: root.active,
applied: root.applied,
error: root.error
});
}
}
}
+1
View File
@@ -20,3 +20,4 @@ singleton NotificationService 1.0 NotificationService.qml
singleton ClipboardService 1.0 ClipboardService.qml
singleton EmojiService 1.0 EmojiService.qml
singleton CaffeineService 1.0 CaffeineService.qml
singleton GameModeService 1.0 GameModeService.qml