Files
glassMxrph/tests/controlcenter_runtime.py
mxandClaude Opus 5.5 d37f9b7121 Hold power actions to confirm instead of a confirm row
Logout, reboot and shut down now fill with accent liquid while held and
run once full; letting go early drains it. A tap hints to hold. Replaces
the Confirm/Cancel rows in the control center tile and dashboard tab.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 01:05:11 +01:00

170 lines
14 KiB
Python

#!/usr/bin/env python3
"""Real Wayland/read-only native discovery, then recording adapters for all writes."""
import json,os,subprocess,tempfile,time
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1]
BASE=['quickshell','ipc','--path',str(ROOT/'quickshell'),'call']
def ipc(target,method,*args):
r=subprocess.run(BASE+[target,method,*map(str,args)],capture_output=True,text=True)
return json.loads(r.stdout) if r.returncode==0 and r.stdout.strip() else None
def state():return ipc('controlTest','snapshot') or {}
def wait(check,label):
end=time.monotonic()+15
while time.monotonic()<end:
try:
if check():return
except (TypeError,KeyError,ValueError):pass
time.sleep(.08)
raise AssertionError(label+': '+str(state()))
def pref(key,value):assert ipc('shell','setPreference',key,' '+json.dumps(value)),ipc('shell','status')
if ipc('shell','status'):raise SystemExit('Use an isolated source path; instance already active.')
log=ROOT/'.cache/controlcenter-runtime.log';log.parent.mkdir(exist_ok=True)
monitors=json.loads(subprocess.check_output(['hyprctl','monitors','-j'],text=True));original=next((m['name'] for m in monitors if m['focused']),None)
with tempfile.TemporaryDirectory(prefix='glassmxrph-controls-') as tmp:
events=Path(tmp)/'events';cfg=Path(tmp)/'config/glassMxrph/config.json';cfg.parent.mkdir(parents=True)
# A Noctalia-style plugin offering a Control Center widget.
fixture=Path(tmp)/'data/glassMxrph/plugins/cc-fixture';fixture.mkdir(parents=True)
(fixture/'manifest.json').write_text(json.dumps({'id':'cc-fixture','name':'CC Fixture','version':'1.0.0','minNoctaliaVersion':'3.6.0','author':'tests','description':'Control Center widget fixture','entryPoints':{'controlCenterWidget':'ControlCenterWidget.qml'}}))
(fixture/'ControlCenterWidget.qml').write_text('import QtQuick\nItem {\n property var pluginApi: null\n property var screen: null\n property int clicks: 0\n property string tooltipText: "Fixture hint"\n objectName: "fixtureCcButton"\n implicitWidth: 30\n implicitHeight: 30\n MouseArea { anchors.fill: parent; onClicked: parent.clicks++ }\n}\n')
# The user's live shell owns the notification bus name; a second server would warn.
cfg.write_text(json.dumps({'schemaVersion':3,'media':{'enabled':False},'dock':{'enabled':False},'notifications':{'enabled':False},'plugins':{'enabled':['cc-fixture']}}))
env=dict(os.environ,XDG_CONFIG_HOME=tmp+'/config',XDG_DATA_HOME=tmp+'/data',XDG_STATE_HOME=tmp+'/state',XDG_CACHE_HOME=tmp+'/cache',GLASSMXRPH_CONTROL_TESTING='1',GLASSMXRPH_SYSTEM_EVENTS=str(events),QT_QPA_PLATFORMTHEME='',QT_NO_XDG_DESKTOP_PORTAL='1')
with log.open('w') as output:
shell=subprocess.Popen([str(ROOT/'scripts/glassmxrph'),'run'],env=env,stdout=output,stderr=subprocess.STDOUT)
try:
wait(lambda:ipc('shell','status')['ready'],'ready')
time.sleep(.25)
assert ipc('controlTest','clickSystem')
wait(lambda:ipc('controlcenter','status')['opened'],'system pill opens')
wait(lambda:not state()['busy'] and 'power' in state()['state'],'read-only native providers')
assert ipc('controlcenter','status')['screen']==state()['active']
time.sleep(.4)
s=state();assert s['x']>s['screenWidth']/2 and s['x']+s['width']<=s['screenWidth'] and s['y']+s['height']<=s['screenHeight']
wait(lambda:ipc('controlTest','inject'),'inject recording adapters')
wait(lambda:not state()['busy'] and state()['state']['brightness']['available'],'fixture providers')
assert ipc('controlTest','click','volumeMute');wait(lambda:state()['muted'],'mute click')
assert ipc('controlTest','slider','volumeSlider');wait(lambda:state()['volume']>.6,'volume slider')
assert ipc('controlTest','click','microphoneMute');wait(lambda:state()['microphone'],'microphone click')
# Per-app volume: right click extends Sound with the app streams.
assert ipc('controlTest','rightClick','outputTile');wait(lambda:state()['extras'].get('output',0)>0,'Sound extends')
time.sleep(.4)
assert state()['streams']==['Fixture player'],'only playback streams are listed: '+str(state()['streams'])
t=next(i for i in state()['tiles'] if i['id']=='input');assert t['row']>0
assert ipc('controlTest','slider','appSlider-Fixture player');wait(lambda:state()['streamVolume']>.6,'app volume slider')
assert ipc('controlTest','click','appMute-Fixture player');wait(lambda:state()['streamMuted'],'app mute')
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')
assert ipc('controlTest','connectFixtures')
for name,key in [('nightLightToggle','nightLight'),('dndToggle','dnd')]:
assert ipc('controlTest','click',name)
wait(lambda:not state()['busy'] and state()['state'][key]['enabled'],key+' readback')
failure=events.with_suffix('.fail');failure.touch()
assert ipc('controlTest','click','dndToggle')
wait(lambda:not state()['busy'] and bool(state()['error']),'provider error')
assert state()['state']['dnd']['enabled'] and ipc('controlTest','checked','dndToggle'),'Failed request changed displayed real state'
assert ipc('controlTest','slider','brightnessSlider')
wait(lambda:not state()['busy'] and bool(state()['error']),'brightness error')
assert ipc('controlTest','value','brightnessSlider')==state()['state']['brightness']['value'],'Failed brightness request changed display'
failure.unlink();assert ipc('controlTest','click','dndToggle')
wait(lambda:not state()['busy'] and not state()['error'] and not state()['state']['dnd']['enabled'],'provider recovery')
assert ipc('controlTest','slider','brightnessSlider')
wait(lambda:not state()['busy'] and state()['state']['brightness']['value']>60,'brightness readback')
assert ipc('controlTest','click','power-reboot');assert state()['power']==''
assert ipc('controlTest','hold','power-shutdown',250);assert state()['power']==''
assert not any(json.loads(line)['action']=='power' for line in events.read_text().splitlines())
assert ipc('controlcenter','status')['opened']
assert ipc('controlTest','hold','power-reboot',1200)
wait(lambda:not state()['busy'],'recorded hold confirmation')
actions=[json.loads(line) for line in events.read_text().splitlines()]
power=[a for a in actions if a['action']=='power'];assert len(power)==1 and power[0]['value']=='reboot' and power[0]['confirmed'] is True,str(actions)
ipc('controlcenter','close');time.sleep(.3);ipc('controlcenter','open');time.sleep(.35)
assert ipc('controlTest','screenshot',str(ROOT/'.cache/controlcenter-preview.png'))
ipc('controlTest','outside');wait(lambda:not state()['windowVisible'],'outside closes')
for monitor in monitors:
subprocess.run(['hyprctl','dispatch','focusmonitor',monitor['name']],check=True,capture_output=True)
wait(lambda:state()['active']==monitor['name'],'active monitor event')
ipc('controlcenter','open');wait(lambda:state()['windowVisible'],'mapped on output');time.sleep(.3)
assert ipc('controlcenter','status')['screen']==monitor['name']
s=state();assert s['x']>=0 and s['x']+s['width']<=s['screenWidth'] and s['y']+s['height']<=s['screenHeight']
ipc('controlcenter','close');wait(lambda:not state()['windowVisible'],'close before monitor switch')
pref('animation.reducedMotion',True)
for _ in range(3):
ipc('controlcenter','open');wait(lambda:state()['windowVisible'],'reduced motion open')
ipc('controlcenter','close');wait(lambda:not state()['windowVisible'],'reduced motion close')
pref('animation.reducedMotion',False)
ipc('controlcenter','open');ipc('launcher','open');wait(lambda:not ipc('controlcenter','status')['opened'],'launcher exclusivity');ipc('launcher','close')
# Edit mode: drag to reorder, resize from the handle, remove and add, Escape leaves it.
ipc('controlcenter','open');wait(lambda:state()['windowVisible'],'reopen for editing');time.sleep(.4)
assert ipc('controlTest','click','controlEdit');wait(lambda:state()['editing'],'edit mode')
time.sleep(.6);assert ipc('controlTest','screenshot',str(ROOT/'.cache/controlcenter-editing.png'))
s=state();tiles={t['id']:t for t in s['tiles']};step=s['cellWidth']+10
bt,wifi,caf=tiles['bluetooth'],tiles['wifi'],tiles['caffeine']
ids=lambda:[m['id'] for m in state()['modules']]
pos=lambda i:next((t for t in state()['tiles'] if t['id']==i),None)
cfgpos=lambda i:next(m for m in state()['modules'] if m['id']==i)
# Dropping on a tile takes its cell and pushes it straight down.
assert ipc('controlTest','drag','controlMove-bluetooth',(wifi['col']-bt['col'])*step,(wifi['row']-bt['row'])*78)
wait(lambda:cfgpos('bluetooth').get('x')==wifi['col'] and cfgpos('bluetooth').get('y')==wifi['row'],'drag places the tile')
assert pos('wifi')['row']>wifi['row'] and pos('wifi')['col']==wifi['col'],'tile underneath is pushed down: '+str(pos('wifi'))
# Dropping into empty space leaves an air gap where it was.
time.sleep(.3);s=state();caf=pos('caffeine');rows=max(t['row']+t['h'] for t in s['tiles'])
assert ipc('controlTest','drag','controlMove-caffeine',(3-caf['col'])*step,(rows-caf['row'])*78)
wait(lambda:pos('caffeine')['row']==rows and pos('caffeine')['col']==3,'drop into empty row')
cell=lambda c,r:[t['id'] for t in state()['tiles'] if t['col']<=c<t['col']+t['w'] and t['row']<=r<t['row']+t['h']]
assert cell(caf['col'],caf['row'])==[],'air gap kept: '+str(cell(caf['col'],caf['row']))
time.sleep(.3)
assert ipc('controlTest','drag','controlResize-wifi',step,78)
wait(lambda:any(m['id']=='wifi' and m.get('w')==3 and m.get('h')==2 for m in state()['modules']),'resize to 3x2')
assert next(t for t in state()['tiles'] if t['id']=='wifi')['w']==3
time.sleep(.3);dnd=pos('dnd')
assert ipc('controlTest','click','controlRemove-dnd')
wait(lambda:not next(m for m in state()['modules'] if m['id']=='dnd')['enabled'],'remove badge')
assert not any(t['id']=='dnd' for t in state()['tiles'])
assert cell(dnd['col'],dnd['row'])==[],'removing leaves a gap'
# Plugin Control Center widgets are offered as tiles and keep their own clicks.
assert ipc('controlTest','click','controlAdd-plugin:cc-fixture')
wait(lambda:pos('plugin:cc-fixture'),'plugin tile added')
assert ipc('controlTest','click','controlEdit');wait(lambda:not state()['editing'],'leave edit for plugin click')
time.sleep(.4);assert ipc('controlTest','click','fixtureCcButton')
wait(lambda:ipc('controlTest','itemValue','fixtureCcButton','clicks')==1,'plugin widget click')
assert ipc('controlTest','click','controlEdit');wait(lambda:state()['editing'],'edit again')
assert ipc('controlTest','click','controlAdd-dnd')
wait(lambda:any(t['id']=='dnd' for t in state()['tiles']),'add from tray')
ipc('controlTest','pressEscape');wait(lambda:not state()['editing'],'Escape leaves edit mode')
assert ipc('controlcenter','status')['opened']
time.sleep(.6);assert ipc('controlTest','screenshot',str(ROOT/'.cache/controlcenter-edited.png'))
assert ipc('controlTest','click','controlEdit');wait(lambda:state()['editing'],'edit mode again')
time.sleep(.5);assert ipc('controlTest','click','controlReset')
wait(lambda:all('w' not in m and 'x' not in m for m in state()['modules']) and ids()[0]=='wifi','reset layout')
assert ipc('controlTest','click','controlEdit');wait(lambda:not state()['editing'],'done')
ipc('controlcenter','close');wait(lambda:not state()['windowVisible'],'close after editing')
ipc('shell','openSettings','controlcenter');wait(lambda:state()['settingsVisible'],'module editor opens');time.sleep(.3)
second=state()['modules'][1]['id']
assert ipc('controlTest','settingsDrag','control-drag-wifi','control-drag-'+second)
wait(lambda:state()['modules'][1]['id']=='wifi','visual module reorder')
assert ipc('controlTest','settingsClick','control-enable-output')
wait(lambda:not next(m for m in state()['modules'] if m['id']=='output')['enabled'],'visual module toggle')
ipc('shell','close');wait(lambda:not state()['settingsVisible'],'settings closes')
for page in ['controlcenter','audio','network','bluetooth','displays','notifications','power']:
ipc('shell','openSettings',page);time.sleep(.3)
wait(lambda:not state()['scan'],'network scan released')
ipc('shell','close');pref('controlCenter.modules',[])
ipc('controlcenter','open');time.sleep(.3);ipc('controlTest','pressEscape');wait(lambda:not ipc('controlcenter','status')['opened'],'Escape closes empty panel')
wait(lambda:json.loads(cfg.read_text())['controlCenter']['modules']==[],'module persistence')
finally:
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/Game Mode/network/Bluetooth/display/DND actions, free grid edit mode (place, push down, air gaps, resize, remove, add, plugin tiles, reset), power hold-to-confirm/early release, outside/Escape/exclusivity, settings, clean logs.')