Files
glassMxrph/tests/customization_runtime.py
T
mxandClaude Opus 5.5 99e64a7713 Add glassMxrph shell sources
Initial commit of the Quickshell desktop suite: bar, dock, launcher,
settings, Control Center, dashboard, OSD, lock screen, desktop widgets,
plugin host with the vendored Noctalia/Omarchy compatibility layer,
helpers, packaging, tests and phase documentation.

Includes the optimization work so far: usage widgets and dashboard
gauges no longer animate continuously, desktop widgets pause while
covered, system controls stop flickering on background polls, dock app
matching uses an indexed catalog, and workspace ghosts are created only
for occupied slots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 22:36:17 +02:00

90 lines
6.3 KiB
Python

#!/usr/bin/env python3
"""Native wallpaper and DnD on Wayland; global glass writes go to a recording hyprctl."""
import importlib.util,json,os,shutil,struct,subprocess,tempfile,time,zlib
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1]
BASE=['quickshell','ipc','--path',str(ROOT/'quickshell'),'call']
def ipc(target,method,*args):
p=subprocess.run(BASE+[target,method,*map(str,args)],text=True,capture_output=True,timeout=5)
return json.loads(p.stdout) if p.returncode==0 and p.stdout.strip() else None
def state():return ipc('settingsTest','snapshot') or {}
def wait(fn):
end=time.monotonic()+20
while time.monotonic()<end:
try:
if fn():return
except (TypeError,KeyError,ValueError,FileNotFoundError):pass
time.sleep(.1)
raise AssertionError(str(state()))
def pref(key,value):assert ipc('shell','setPreference',key,' '+json.dumps(value)) is True
spec=importlib.util.spec_from_file_location('glass',ROOT/'quickshell/helpers/glass.py');g=importlib.util.module_from_spec(spec);spec.loader.exec_module(g)
def png(path,rgb):
def chunk(k,d):return struct.pack('!I',len(d))+k+d+struct.pack('!I',zlib.crc32(k+d)&0xffffffff)
path.write_bytes(b'\x89PNG\r\n\x1a\n'+chunk(b'IHDR',struct.pack('!2I5B',64,64,8,2,0,0,0))+chunk(b'IDAT',zlib.compress((b'\x00'+bytes(rgb)*64)*64))+chunk(b'IEND',b''))
if ipc('shell','status'):raise SystemExit('Stop the running project preview before this isolated test.')
with tempfile.TemporaryDirectory(prefix='glassmxrph-customization-') as tmp:
t=Path(tmp);(t/'bin').mkdir();images=t/'images';images.mkdir();png(images/'amber #1.png',(140,90,20));png(images/'blue.png',(20,65,120))
initial={k:('liquid' if k=='default_preset' else 'auto' if k=='layers:mask_mode' else '' if isinstance(v,str) else 0) for k,v in g.values({'layers':True,'values':g.GHOSTTY}).items()}
initial.update({'layers:namespaces':'','layers:exclude_namespaces':'','layers:namespace_presets':''})
record=t/'glass.json';record.write_text(json.dumps(initial))
real=shutil.which('hyprctl')
fake=t/'bin/hyprctl';fake.write_text('''#!/usr/bin/env python3
import json,os,subprocess,sys
from pathlib import Path
args=sys.argv[1:];p=Path(os.environ['GLASS_TEST_RECORD']);d=json.loads(p.read_text())
if 'getoption' in args and args[-1].startswith('plugin:hyprglass:'):
k=args[-1].removeprefix('plugin:hyprglass:');v=d[k];print(json.dumps({'str' if isinstance(v,str) else 'float' if isinstance(v,float) else 'int':v,'set':True}))
elif args[0]=='keyword' and args[1].startswith('plugin:hyprglass:'):
k=args[1].removeprefix('plugin:hyprglass:');v=args[2]
if not isinstance(d[k],str):v=float(v);v=int(v) if v.is_integer() else v
d[k]=v;p.write_text(json.dumps(d));print('ok')
else:os.execv(os.environ['GLASS_REAL_HYPRCTL'],[os.environ['GLASS_REAL_HYPRCTL'],*args])
''');fake.chmod(0o755)
config=t/'config/glassMxrph/config.json';config.parent.mkdir(parents=True);config.write_text(json.dumps({'schemaVersion':3,'wallpaper':{'backend':'native','directories':[str(images)]},'dock':{'enabled':False},'media':{'enabled':False}}))
env=dict(os.environ,PATH=str(t/'bin')+':'+os.environ['PATH'],XDG_CONFIG_HOME=str(t/'config'),XDG_STATE_HOME=str(t/'state'),GLASSMXRPH_SETTINGS_TESTING='1',GLASS_TEST_RECORD=str(record),GLASS_REAL_HYPRCTL=real)
log=ROOT/'.cache/customization-runtime.log'
with log.open('w') as out:
shell=subprocess.Popen([str(ROOT/'scripts/glassmxrph'),'run'],env=env,stdout=out,stderr=subprocess.STDOUT)
try:
wait(lambda:state().get('data',{}).get('schemaVersion')==3)
ipc('shell','openSettings','bar');time.sleep(.35)
assert ipc('settingsTest','dragModule','workspaces','right','tray')
wait(lambda:next(m for m in state()['data']['bar']['modules'] if m['id']=='workspaces')['position']=='right')
assert ipc('settingsTest','dragModule','clock','left','settings')
wait(lambda:state()['data']['bar']['modules'][0]['id']=='clock')
assert ipc('settingsTest','dragModule','clock','center','')
wait(lambda:next(m for m in state()['data']['bar']['modules'] if m['id']=='clock')['position']=='center')
assert ipc('settingsTest','screenshot',str(ROOT/'.cache/bar-drag-preview.png'))
ipc('shell','openSettings','wallpaper');time.sleep(.25)
assert ipc('settingsTest','click','openWallpaperPicker')
wait(lambda:state()['picker'] and len(state()['images'])==2)
ipc('settingsTest','pickerQuery','amber')
assert ipc('settingsTest','pickerSelect',0)
wait(lambda:state()['wallpaper'].endswith('amber #1.png') and not ipc('wallpaper','status')['busy'])
assert state()['data']['wallpaper']['history'][0].endswith('amber #1.png')
layers=json.loads(subprocess.check_output([real,'-j','layers']))
assert any(i['namespace']=='glassMxrph-wallpaper' for m in layers.values() for layer in m['levels'].values() for i in layer)
assert ipc('settingsTest','pickerScreenshot',str(ROOT/'.cache/wallpaper-picker-preview.png'))
ipc('shell','openSettings','appearance');wait(lambda:state()['glass'].get('available'))
assert ipc('settingsTest','click','glassMatchGhostty')
wait(lambda:state()['data']['appearance']['panelOpacity']==.3)
assert ipc('settingsTest','click','glassApply')
wait(lambda:not state()['glassBusy'] and state()['data']['hyprglass']['enabled'])
assert not state()['glassError'],state()['glassError']
applied=json.loads(record.read_text());assert applied['dark:refraction_strength']==3 and applied['default_preset']=='default'
assert applied['layers:enabled']==1
pref('hyprglass.values.blur_strength',1.25)
assert ipc('settingsTest','click','glassApply')
wait(lambda:not state()['glassBusy'] and json.loads(record.read_text())['dark:blur_strength']==1.25)
pref('hyprglass.effectEnabled',False)
assert ipc('settingsTest','click','glassApply')
wait(lambda:not state()['glassBusy'] and json.loads(record.read_text())['enabled']==0)
assert json.loads(record.read_text())['layers:enabled']==0
assert ipc('settingsTest','click','glassRestore')
wait(lambda:not state()['glassBusy'] and not state()['data']['hyprglass']['enabled'])
assert json.loads(record.read_text())==initial
wait(lambda:json.loads(config.read_text())['wallpaper']['history'])
finally:shell.terminate();shell.wait(timeout=8)
text=log.read_text();assert 'WARN' not in text and 'ERROR' not in text,text
print('PASS: drag across/within/into empty lanes, native picker/search/apply/history/background, Ghostty match, global apply/update/restore via recording compositor, persistence and clean logs.')