Place Control Center tiles freely and host plugin widgets as tiles
Tiles keep the cell they are dropped in, so gaps stay where they are left; moving or resizing onto other tiles pushes those straight down. Enabled plugins with a Noctalia controlCenterWidget entry point are offered as tiles in edit mode. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
72a21c9363
commit
7f1189606c
14 files changed
+412
-157
No files matched your search
@@ -74,12 +74,13 @@ assert.equal(phase7.controlCenter.version,2);assert(phase7.controlCenter.modules
|
||||
assert.equal(api.load(defaults,{controlCenter:{version:1,modules:[]}}).controlCenter.modules.length,0);
|
||||
const customCenter=api.load(defaults,{controlCenter:{modules:[{id:'custom',enabled:false,metadata:'preserved'}]}});
|
||||
assert.equal(customCenter.controlCenter.modules[0].metadata,'preserved');assert.equal(customCenter.controlCenter.modules.map(m=>m.id).join(),'custom,caffeine');
|
||||
for(const controlCenter of [{version:3},{version:1,width:100},{version:2,modules:[{id:'output',enabled:true},{id:'output',enabled:false}]},{version:2,modules:[{id:'wifi',enabled:true,w:5}]},{version:2,modules:[{id:'wifi',enabled:true,h:0}]},{version:2,modules:[{id:'wifi',enabled:true,w:1.5}]}])assert.throws(()=>api.load(defaults,{controlCenter}));
|
||||
for(const controlCenter of [{version:3},{version:1,width:100},{version:2,modules:[{id:'output',enabled:true},{id:'output',enabled:false}]},{version:2,modules:[{id:'wifi',enabled:true,w:5}]},{version:2,modules:[{id:'wifi',enabled:true,h:0}]},{version:2,modules:[{id:'wifi',enabled:true,w:1.5}]},{version:2,modules:[{id:'wifi',enabled:true,x:4}]},{version:2,modules:[{id:'wifi',enabled:true,y:-1}]},{version:2,modules:[{id:'wifi',enabled:true,y:64}]}])assert.throws(()=>api.load(defaults,{controlCenter}));
|
||||
// Version 1 splits the combined cards in place, keeps enabled state and offers Caffeine.
|
||||
const v1=api.load(defaults,{controlCenter:{version:1,modules:[{id:'connectivity',enabled:true},{id:'media',enabled:true},{id:'audio',enabled:false},{id:'notifications',enabled:true}]}}).controlCenter;
|
||||
assert.equal(v1.version,2);assert.equal(v1.modules.map(m=>m.id+':'+m.enabled).join(),'wifi:true,bluetooth:true,network:true,media:true,output:false,input:false,notifications:true,caffeine:true');
|
||||
assert.equal(JSON.stringify(api.load(defaults,{controlCenter:{version:2,modules:[{id:'wifi',enabled:true,w:4,h:1}]}}).controlCenter.modules),'[{"id":"wifi","enabled":true,"w":4,"h":1}]');
|
||||
assert.equal(api.load(defaults,{controlCenter:{version:2,modules:[]}}).controlCenter.modules.length,0);
|
||||
assert.equal(api.load(defaults,{controlCenter:{version:2,modules:[{id:'wifi',enabled:true,x:3,y:63}]}}).controlCenter.modules[0].y,63);
|
||||
for(const system of [{brightness:{setCommand:'sh -c'}},{nightLight:{temperature:0}},{power:{lockCommand:['']}}])assert.throws(()=>api.load(defaults,{system}));
|
||||
console.log('Phase 7 one-time module migration, intentional empty layouts, provider validation and preservation passed.');
|
||||
|
||||
|
||||
@@ -1,35 +1,52 @@
|
||||
const assert = require('assert'), fs = require('fs'), path = require('path'), vm = require('vm');
|
||||
const api = vm.createContext({});
|
||||
vm.runInContext(fs.readFileSync(path.join(__dirname, '../quickshell/controlcenter/GridLogic.js'), 'utf8'), api);
|
||||
const ids = plan => plan.items.map(i => i.id + '@' + i.col + ',' + i.row + ':' + i.w + 'x' + i.h).join(' ');
|
||||
// First fit in list order; small tiles backfill gaps beside larger ones.
|
||||
let plan = api.pack([{id: 'wifi', w: 2, h: 1}, {id: 'media', w: 2, h: 2}, {id: 'bt', w: 1, h: 1}, {id: 'dnd', w: 1, h: 1}, {id: 'sound', w: 4, h: 1}]);
|
||||
assert.equal(ids(plan), 'wifi@0,0:2x1 media@2,0:2x2 bt@0,1:1x1 dnd@1,1:1x1 sound@0,2:4x1');
|
||||
const show = plan => plan.items.map(i => i.id + '@' + i.col + ',' + i.row + ':' + i.w + 'x' + i.h).join(' ');
|
||||
const at = (plan, col, row) => (plan.items.find(i => col >= i.col && col < i.col + i.w && row >= i.row && row < i.row + i.h) || {}).id;
|
||||
// Without positions: first free spot in order, so small tiles backfill gaps.
|
||||
let plan = api.layout([{id: 'wifi', w: 2, h: 1}, {id: 'media', w: 2, h: 2}, {id: 'bt', w: 1, h: 1}, {id: 'dnd', w: 1, h: 1}, {id: 'sound', w: 4, h: 1}]);
|
||||
assert.equal(show(plan), 'wifi@0,0:2x1 media@2,0:2x2 bt@0,1:1x1 dnd@1,1:1x1 sound@0,2:4x1');
|
||||
assert.equal(plan.rows, 3);
|
||||
plan = api.pack([{id: 'a', w: 3, h: 1}, {id: 'b', w: 2, h: 1}, {id: 'c', w: 1, h: 1}]);
|
||||
assert.equal(ids(plan), 'a@0,0:3x1 b@0,1:2x1 c@3,0:1x1');
|
||||
// Sizes clamp to 1..4 cells.
|
||||
assert.equal(ids(api.pack([{id: 'x', w: 9, h: 0}, {id: 'y', w: 1.4, h: 4.6}])), 'x@0,0:4x1 y@0,1:1x4');
|
||||
assert.equal(api.pack([]).rows, 0);
|
||||
// Hit testing covers spanned cells.
|
||||
plan = api.pack([{id: 'wifi', w: 2, h: 1}, {id: 'media', w: 2, h: 2}, {id: 'bt', w: 1, h: 1}]);
|
||||
assert.equal(api.at(plan, 3, 1).id, 'media');
|
||||
assert.equal(api.at(plan, 3, 2), null);
|
||||
// Dragging onto a tile takes its place in either direction; onto itself is a no-op.
|
||||
const order = ['wifi', 'media', 'bt'];
|
||||
assert.equal(api.reorder(order, plan, 'bt', 0, 0).join(), 'bt,wifi,media');
|
||||
assert.equal(api.reorder(order, plan, 'wifi', 0, 1).join(), 'media,bt,wifi');
|
||||
assert.equal(api.reorder(order, plan, 'wifi', 1, 0).join(), 'wifi,media,bt');
|
||||
// Empty space puts it after the last tile before that cell.
|
||||
assert.equal(api.reorder(order, plan, 'wifi', 1, 1).join(), 'media,bt,wifi');
|
||||
assert.equal(api.reorder(order, plan, 'bt', 0, 5).join(), 'wifi,media,bt');
|
||||
assert.equal(api.reorder(order, plan, 'nope', 0, 0).join(), order.join());
|
||||
// Resizing rounds to whole cells within 1..4.
|
||||
assert.equal(show(api.layout([{id: 'x', w: 9, h: 0}, {id: 'y', w: 1.4, h: 4.6}])), 'x@0,0:4x1 y@0,1:1x4');
|
||||
assert.equal(api.layout([]).rows, 0);
|
||||
// Positions are kept, gaps included; unpositioned tiles fill free spots.
|
||||
plan = api.layout([{id: 'a', w: 1, h: 1, x: 3, y: 2}, {id: 'b', w: 2, h: 1, x: 0, y: 0}, {id: 'c', w: 1, h: 1}]);
|
||||
assert.equal(show(plan), 'a@3,2:1x1 b@0,0:2x1 c@2,0:1x1');
|
||||
assert.equal(plan.rows, 3);
|
||||
assert.equal(at(plan, 0, 1), undefined);
|
||||
// Overlapping saved positions: the earlier entry wins, the later one moves down.
|
||||
assert.equal(show(api.layout([{id: 'a', w: 2, h: 2, x: 0, y: 0}, {id: 'b', w: 1, h: 1, x: 1, y: 1}])), 'a@0,0:2x2 b@1,2:1x1');
|
||||
// Positions clamp inside the grid.
|
||||
assert.equal(show(api.layout([{id: 'a', w: 3, h: 1, x: 3, y: -2}])), 'a@1,0:3x1');
|
||||
// A free spot for a new tile.
|
||||
plan = api.layout([{id: 'a', w: 4, h: 1, x: 0, y: 0}, {id: 'b', w: 1, h: 1, x: 0, y: 1}]);
|
||||
assert.equal(JSON.stringify(api.freeSpot(plan, 2, 1)), '{"id":"\\u0000new","col":1,"row":1,"w":2,"h":1}');
|
||||
// Moving into empty space leaves the old spot empty.
|
||||
plan = api.layout([{id: 'wifi', w: 2, h: 1}, {id: 'bt', w: 1, h: 1}, {id: 'sound', w: 4, h: 1}]);
|
||||
let moved = api.moveTo(plan, 'bt', {col: 3, row: 3});
|
||||
assert.equal(show(moved), 'wifi@0,0:2x1 bt@3,3:1x1 sound@0,1:4x1');
|
||||
assert.equal(at(moved, 2, 0), undefined);
|
||||
assert.equal(moved.rows, 4);
|
||||
assert.equal(show(plan), 'wifi@0,0:2x1 bt@2,0:1x1 sound@0,1:4x1', 'moveTo leaves the input plan alone');
|
||||
// Landing on tiles pushes them straight down, cascading; nothing moves up.
|
||||
moved = api.moveTo(plan, 'bt', {col: 0, row: 0});
|
||||
assert.equal(show(moved), 'wifi@0,1:2x1 bt@0,0:1x1 sound@0,2:4x1');
|
||||
// Resizing pushes the same way.
|
||||
moved = api.moveTo(plan, 'wifi', {w: 3, h: 2});
|
||||
assert.equal(show(moved), 'wifi@0,0:3x2 bt@2,2:1x1 sound@0,3:4x1');
|
||||
// A tile pushed onto the moved one goes below it instead.
|
||||
plan = api.layout([{id: 'tall', w: 1, h: 3, x: 0, y: 0}, {id: 'top', w: 2, h: 1, x: 1, y: 0}]);
|
||||
moved = api.moveTo(plan, 'top', {col: 0, row: 1});
|
||||
assert.equal(show(moved), 'tall@0,2:1x3 top@0,1:2x1');
|
||||
// Moves clamp to the grid.
|
||||
assert.equal(show(api.moveTo(plan, 'top', {col: 9, row: -4})), 'tall@0,0:1x3 top@2,0:2x1');
|
||||
// Pixel corner to the nearest cell; resizing rounds to whole cells within 1..4.
|
||||
assert.equal(JSON.stringify(api.cellAt(130, 40, 80, 68, 10)), '{"col":1,"row":1}');
|
||||
assert.equal(JSON.stringify(api.resize({w: 1, h: 1}, 50, 0, 80, 68, 10)), '{"w":2,"h":1}');
|
||||
assert.equal(JSON.stringify(api.resize({w: 2, h: 2}, -30, 400, 80, 68, 10)), '{"w":2,"h":4}');
|
||||
assert.equal(JSON.stringify(api.resize({w: 1, h: 1}, -500, -500, 80, 68, 10)), '{"w":1,"h":1}');
|
||||
// Geometry: an expanded tile pushes down everything from its bottom row.
|
||||
plan = api.pack([{id: 'out', w: 2, h: 1}, {id: 'media', w: 2, h: 2}, {id: 'a', w: 1, h: 1}, {id: 'b', w: 4, h: 1}]);
|
||||
plan = api.layout([{id: 'out', w: 2, h: 1}, {id: 'media', w: 2, h: 2}, {id: 'a', w: 1, h: 1}, {id: 'b', w: 4, h: 1}]);
|
||||
let g = api.geometry(plan, 80, 68, 10);
|
||||
assert.equal(JSON.stringify(g.tiles.media), '{"x":180,"y":0,"w":170,"h":146}');
|
||||
assert.equal(g.height, 3 * 78 - 10);
|
||||
@@ -39,4 +56,4 @@ assert.equal(g.tiles.media.y, 0);
|
||||
assert.equal(g.tiles.a.y, 78 + 110);
|
||||
assert.equal(g.tiles.b.y, 156 + 110);
|
||||
assert.equal(g.height, 3 * 78 - 10 + 110);
|
||||
console.log('Control Center grid packing, hit testing, reordering, resizing and expansion geometry passed.');
|
||||
console.log('Control Center free placement, push-down moves and resizes, free spots and expansion geometry passed.');
|
||||
@@ -22,9 +22,13 @@ 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}}))
|
||||
env=dict(os.environ,XDG_CONFIG_HOME=tmp+'/config',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')
|
||||
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:
|
||||
@@ -77,7 +81,7 @@ with tempfile.TemporaryDirectory(prefix='glassmxrph-controls-') as tmp:
|
||||
assert ipc('controlTest','click','power-reboot');assert ipc('controlTest','click','powerConfirm')
|
||||
wait(lambda:not state()['busy'],'recorded 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
|
||||
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')
|
||||
@@ -99,25 +103,44 @@ with tempfile.TemporaryDirectory(prefix='glassmxrph-controls-') as tmp:
|
||||
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=tiles['bluetooth'],tiles['wifi']
|
||||
assert ipc('controlTest','drag','controlMove-bluetooth',(wifi['col']-bt['col'])*step,(wifi['row']-bt['row'])*78)
|
||||
bt,wifi,caf=tiles['bluetooth'],tiles['wifi'],tiles['caffeine']
|
||||
ids=lambda:[m['id'] for m in state()['modules']]
|
||||
wait(lambda:ids().index('bluetooth')<ids().index('wifi'),'drag reorders')
|
||||
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')
|
||||
assert ipc('controlTest','click','controlReset')
|
||||
wait(lambda:all('w' not in m for m in state()['modules']) and ids()[0]=='wifi','reset layout')
|
||||
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)
|
||||
@@ -137,4 +160,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, grid edit mode (drag, resize, remove, add, 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/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.')
|
||||
Reference in new issue
Block a user