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:
1 parent
9e1ac4efe7
commit
bfbfc8961e
15 files changed
+325
-1
No files matched your search
@@ -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
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user