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

+2
View File
@@ -104,3 +104,5 @@ assert.equal(settings.dropModule(modules,'a','right','').find(m=>m.id==='a').cus
assert.throws(()=>api.load(defaults,{hyprglass:{values:{blur_iterations:2.5}}}));
assert.throws(()=>api.load(defaults,{hyprglass:{values:{refraction_strength:99}}}));
console.log('Drag/drop preserves module options and validates global glass preferences.');
assert.equal(loaded.gameMode.effects,true);assert.equal(api.update(loaded,'gameMode.performance',false).gameMode.performance,false);for(const v of ['yes',1,null])assert.throws(()=>api.update(loaded,'gameMode.effects',v),/Game Mode/);
console.log('Game Mode preferences validate.');
+8 -1
View File
@@ -55,6 +55,13 @@ with tempfile.TemporaryDirectory(prefix='glassmxrph-controls-') as tmp:
assert ipc('controlTest','rightClick','outputTile');wait(lambda:not state()['extras'].get('output',0),'Sound folds back')
assert ipc('controlTest','click','caffeineToggle');wait(lambda:state()['caffeine'] and state()['caffeineRunning'],'Caffeine on')
assert ipc('controlTest','click','caffeineToggle');wait(lambda:not state()['caffeine'] and not state()['caffeineRunning'],'Caffeine off')
# Game Mode runs its helper on and off (recorded, never the real compositor).
gm=events.with_suffix('.gamemode')
assert ipc('controlTest','click','gameModeToggle');wait(lambda:state()['gameModeApplied'],'Game Mode on')
wait(lambda:gm.exists() and json.loads(gm.read_text().splitlines()[-1])['action']=='on','Game Mode helper on')
assert ipc('controlTest','checked','gameModeToggle')
assert ipc('controlTest','click','gameModeToggle');wait(lambda:not state()['gameMode'] and not state()['gameModeApplied'],'Game Mode off')
wait(lambda:json.loads(gm.read_text().splitlines()[-1])['action']=='off','Game Mode helper off')
assert ipc('controlTest','click','wifiToggle');wait(lambda:not state()['wifi'],'Wi-Fi toggle')
assert ipc('controlTest','click','bluetoothToggle');wait(lambda:not state()['bluetooth'],'Bluetooth toggle')
assert ipc('controlTest','click','bluetoothToggle')
@@ -160,4 +167,4 @@ with tempfile.TemporaryDirectory(prefix='glassmxrph-controls-') as tmp:
shell.terminate();shell.wait(timeout=5)
if original:subprocess.run(['hyprctl','dispatch','focusmonitor',original],capture_output=True)
text=log.read_text();assert 'WARN' not in text and 'ERROR' not in text,text
print('PASS: native read-only discovery, active-monitor placement, system pill, recording audio/per-app volume/Caffeine/network/Bluetooth/display/DND actions, free grid edit mode (place, push down, air gaps, resize, remove, add, plugin tiles, reset), power confirmation/cancel, outside/Escape/exclusivity, settings, clean logs.')
print('PASS: native read-only discovery, active-monitor placement, system pill, recording audio/per-app volume/Caffeine/Game Mode/network/Bluetooth/display/DND actions, free grid edit mode (place, push down, air gaps, resize, remove, add, plugin tiles, reset), power confirmation/cancel, outside/Escape/exclusivity, settings, clean logs.')
+70
View File
@@ -0,0 +1,70 @@
import importlib.util,json,os,tempfile,unittest
from pathlib import Path
from unittest.mock import patch
spec=importlib.util.spec_from_file_location('gamemode',Path(__file__).resolve().parents[1]/'quickshell/helpers/gamemode.py')
gm=importlib.util.module_from_spec(spec);spec.loader.exec_module(gm)
class GameModeTests(unittest.TestCase):
def setUp(self):
# HyprGlass is not loaded here, and the user has shadows off.
self.state={'animations:enabled':1,'decoration:blur:enabled':1,'decoration:shadow:enabled':0}
def env(self,temp,sig='fixture'):
return patch.dict(os.environ,{'XDG_STATE_HOME':temp,'HYPRLAND_INSTANCE_SIGNATURE':sig})
def fakes(self,profile='balanced'):
self.profile=profile
def setp(name):self.profile=name
return patch.multiple(gm,get_many=lambda keys:{k:self.state[k] for k in keys if k in self.state},put_many=lambda values:self.state.update(values),get_profile=lambda:self.profile,set_profile=setp)
def test_on_off_restores_exact_values(self):
with tempfile.TemporaryDirectory() as temp,self.env(temp):
with self.fakes():
original=dict(self.state)
self.assertTrue(gm.dispatch({'action':'on'})['active'])
self.assertEqual(set(self.state.values()),{0})
self.assertEqual(self.profile,'performance')
self.assertNotIn('plugin:hyprglass:enabled',self.state)
self.assertTrue(gm.dispatch({'action':'status'})['active'])
self.assertFalse(gm.dispatch({'action':'off'})['active'])
self.assertEqual(self.state,original)
self.assertEqual(self.profile,'balanced')
self.assertFalse(gm.dispatch({'action':'status'})['active'])
def test_on_twice_keeps_first_journal(self):
with tempfile.TemporaryDirectory() as temp,self.env(temp):
with self.fakes():
gm.dispatch({'action':'on'});gm.dispatch({'action':'on'})
gm.dispatch({'action':'off'})
self.assertEqual(self.state['animations:enabled'],1)
def test_crash_recovery_and_other_sessions(self):
with tempfile.TemporaryDirectory() as temp:
with self.fakes():
with self.env(temp,'old'):gm.dispatch({'action':'on'})
# A new Hyprland session never applies the old journal.
with self.env(temp,'new'):
self.assertFalse(gm.dispatch({'action':'status'})['active'])
gm.dispatch({'action':'off'})
self.assertEqual(self.state['animations:enabled'],0)
# The same session (shell restarted) restores it.
with self.env(temp,'old'):
gm.dispatch({'action':'off'})
self.assertEqual(self.state['animations:enabled'],1)
def test_options_and_no_profiles_daemon(self):
with tempfile.TemporaryDirectory() as temp,self.env(temp):
with self.fakes(profile=None):
gm.dispatch({'action':'on','effects':False,'performance':True})
self.assertEqual(self.state['animations:enabled'],1)
self.assertIsNone(self.profile)
gm.dispatch({'action':'off'})
with self.fakes():
gm.dispatch({'action':'on','effects':True,'performance':False})
self.assertEqual(self.profile,'balanced')
gm.dispatch({'action':'off'})
self.assertEqual(self.state['animations:enabled'],1)
def test_parses_missing_options(self):
out='{"option": "animations:enabled", "int": 1, "set": true }\n\n\nno such option\n\n{"option": "decoration:blur:enabled", "int": 0, "set": true }\n'
with patch.object(gm,'run',lambda args:out):
self.assertEqual(gm.get_many(['animations:enabled','plugin:hyprglass:enabled','decoration:blur:enabled']),{'animations:enabled':1,'decoration:blur:enabled':0})
def test_rejected_keyword_raises(self):
with patch.object(gm,'run',lambda args:'ok\nconfig option <x> does not exist.'):
with self.assertRaises(ValueError):gm.put_many({'x':0,'y':0})
def test_unknown_action(self):
with tempfile.TemporaryDirectory() as temp,self.env(temp):
with self.assertRaises(ValueError):gm.dispatch({'action':'nope'})
if __name__=='__main__':unittest.main()