Reorder Control Center modules by drag and drop

Rows drag from anywhere (or the grip, Ctrl+Up/Down from the keyboard) with
an accent drop indicator, replacing the up/down buttons. The Control Center
runtime test drags instead of clicking, and turns off built-in notifications
since the live shell owns the bus name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mxandClaude Opus 5.5 committed 2026-10-15 14:55:15 +02:00
1 parent 395de70b26
commit 0b3bb83bc9
3 files changed
+157 -30

No files matched your search

+137 -28
View File
@@ -5,6 +5,7 @@ import "../controls"
import "../../controlcenter" import "../../controlcenter"
import "../../components" import "../../components"
import "../../services" import "../../services"
import "../../theme"
SettingsPage { SettingsPage {
id: root id: root
@@ -13,15 +14,64 @@ SettingsPage {
list[index].enabled = enabled; list[index].enabled = enabled;
ConfigService.setValue("controlCenter.modules", list); ConfigService.setValue("controlCenter.modules", list);
} }
function move(index, step) { function move(index, to) {
const list = ConfigService.data.controlCenter.modules.slice(); const list = ConfigService.data.controlCenter.modules.slice();
const to = index + step; if (to < 0 || to >= list.length || to === index)
if (to < 0 || to >= list.length)
return; return;
const entry = list.splice(index, 1)[0]; const entry = list.splice(index, 1)[0];
list.splice(to, 0, entry); list.splice(to, 0, entry);
ConfigService.setValue("controlCenter.modules", list); ConfigService.setValue("controlCenter.modules", list);
} }
component Grip: MouseArea {
id: grip
required property var page
required property var card
property real startY
preventStealing: true
cursorShape: pressed && page.dragIndex >= 0 ? Qt.ClosedHandCursor : Qt.OpenHandCursor
onPressed: event => startY = event.y
onPositionChanged: event => {
if (!pressed)
return;
if (page.dragIndex < 0 && Math.abs(event.y - startY) < 6)
return;
page.dragIndex = card.index;
card.offset = event.y - startY;
page.updateDrop(grip, event.y);
}
onReleased: {
card.offset = 0;
page.finishDrag();
}
onCanceled: {
card.offset = 0;
page.dragIndex = -1;
page.dropIndex = -1;
}
}
// Drag state: the row being moved and the gap it would drop into (0..count).
property int dragIndex: -1
property int dropIndex: -1
function updateDrop(source, y) {
const p = source.mapToItem(rows, 0, y);
let gap = repeater.count;
for (let i = 0; i < repeater.count; ++i) {
const row = repeater.itemAt(i);
if (p.y < row.y + row.height / 2) {
gap = i;
break;
}
}
dropIndex = gap;
}
function finishDrag() {
const from = dragIndex, gap = dropIndex;
dragIndex = -1;
dropIndex = -1;
// Dropping into either gap next to the row leaves it in place.
if (from >= 0 && gap >= 0)
Qt.callLater(() => root.move(from, gap > from ? gap - 1 : gap));
}
SettingsSection { SettingsSection {
title: "Panel" title: "Panel"
PreferenceSlider { PreferenceSlider {
@@ -36,31 +86,90 @@ SettingsPage {
} }
SettingsSection { SettingsSection {
title: "Modules" title: "Modules"
description: "Enable, disable and order the Control Center cards" description: "Drag modules to reorder them; the switch shows or hides each card"
Repeater { ColumnLayout {
model: ConfigService.data.controlCenter.modules id: rows
SettingRow { objectName: "controlModuleList"
id: card Layout.fillWidth: true
required property var modelData spacing: 0
required property int index Repeater {
readonly property var entry: ControlRegistry.entry(modelData.id) id: repeater
title: entry ? entry.title : modelData.id + " (unavailable)" model: ConfigService.data.controlCenter.modules
GlassIconButton { Item {
objectName: "control-up-" + card.modelData.id id: card
text: "↑" required property var modelData
enabled: card.index > 0 required property int index
onClicked: root.move(card.index, -1) readonly property var entry: ControlRegistry.entry(modelData.id)
} readonly property bool lifted: root.dragIndex === index
GlassIconButton { property real offset: 0
objectName: "control-down-" + card.modelData.id Layout.fillWidth: true
text: "↓" implicitHeight: row.implicitHeight
enabled: card.index < ConfigService.data.controlCenter.modules.length - 1 z: lifted ? 10 : 0
onClicked: root.move(card.index, 1) // Press anywhere on the row and drag to reorder.
} Grip {
GlassToggle { anchors.fill: parent
objectName: "control-enable-" + card.modelData.id page: root
checked: card.modelData.enabled card: card
onClicked: root.edit(card.index, checked) }
SettingRow {
id: row
width: parent.width
y: card.offset
scale: card.lifted ? 1.02 : 1
opacity: card.lifted ? 0.9 : 1
title: card.entry ? card.entry.title : card.modelData.id + " (unavailable)"
icon: "󰇙"
Behavior on scale {
NumberAnimation {
duration: Theme.duration / 2
}
}
Rectangle {
parent: row
anchors.fill: parent
z: -1
visible: card.lifted
radius: Math.max(8, Theme.radius * 0.5)
color: Theme.surfaceVariant
border.width: 1
border.color: Theme.accent
}
GlassToggle {
objectName: "control-enable-" + card.modelData.id
checked: card.modelData.enabled
onClicked: root.edit(card.index, checked)
}
}
// The grip over the handle icon shows the hand cursor; the row
// itself keeps its hover highlight.
Grip {
objectName: "control-drag-" + card.modelData.id
page: root
card: card
x: 6
width: 44
height: parent.height
activeFocusOnTab: true
Accessible.role: Accessible.Button
Accessible.name: "Move " + row.title + " (Ctrl+Up/Down)"
Keys.onPressed: event => {
if (event.modifiers & Qt.ControlModifier && (event.key === Qt.Key_Up || event.key === Qt.Key_Down)) {
root.move(card.index, card.index + (event.key === Qt.Key_Up ? -1 : 1));
event.accepted = true;
}
}
}
// Drop indicator in the gap above this row (or below the last).
Rectangle {
readonly property bool after: card.index === repeater.count - 1 && root.dropIndex === repeater.count
visible: root.dragIndex >= 0 && (root.dropIndex === card.index || after)
y: after ? parent.height - 1 : -1
x: 12
width: parent.width - 24
height: 3
radius: 1.5
color: Theme.accent
}
} }
} }
} }
+16
View File
@@ -165,6 +165,22 @@ Item {
input.mouseClick(pill, pill.width / 2, pill.height / 2); input.mouseClick(pill, pill.width / 2, pill.height / 2);
return true; return true;
} }
// Drags one module grip onto the lower half of another row.
function settingsDrag(name: string, target: string): bool {
const content = ShellState.settingsWindow.contentItem;
const source = input.findChild(content, name), over = input.findChild(content, target);
if (!source || !over)
return false;
root.reveal(source);
const end = source.mapFromItem(over, over.width / 2, over.height - 4);
input.mousePress(source, source.width / 2, source.height / 2);
input.mouseMove(source, source.width / 2, source.height / 2 + 10, 40);
input.mouseMove(source, end.x, end.y, 80);
input.wait(80);
input.mouseRelease(source, end.x, end.y);
input.wait(80);
return true;
}
function settingsClick(name: string): bool { function settingsClick(name: string): bool {
const item = input.findChild(ShellState.settingsWindow.contentItem, name); const item = input.findChild(ShellState.settingsWindow.contentItem, name);
if (!item || !item.enabled) if (!item || !item.enabled)
+4 -2
View File
@@ -22,7 +22,8 @@ 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) 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: with tempfile.TemporaryDirectory(prefix='glassmxrph-controls-') as tmp:
events=Path(tmp)/'events';cfg=Path(tmp)/'config/glassMxrph/config.json';cfg.parent.mkdir(parents=True) events=Path(tmp)/'events';cfg=Path(tmp)/'config/glassMxrph/config.json';cfg.parent.mkdir(parents=True)
cfg.write_text(json.dumps({'schemaVersion':3,'media':{'enabled':False},'dock':{'enabled':False}})) # 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') 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')
with log.open('w') as output: with log.open('w') as output:
shell=subprocess.Popen([str(ROOT/'scripts/glassmxrph'),'run'],env=env,stdout=output,stderr=subprocess.STDOUT) shell=subprocess.Popen([str(ROOT/'scripts/glassmxrph'),'run'],env=env,stdout=output,stderr=subprocess.STDOUT)
@@ -84,7 +85,8 @@ with tempfile.TemporaryDirectory(prefix='glassmxrph-controls-') as tmp:
pref('animation.reducedMotion',False) pref('animation.reducedMotion',False)
ipc('controlcenter','open');ipc('launcher','open');wait(lambda:not ipc('controlcenter','status')['opened'],'launcher exclusivity');ipc('launcher','close') ipc('controlcenter','open');ipc('launcher','open');wait(lambda:not ipc('controlcenter','status')['opened'],'launcher exclusivity');ipc('launcher','close')
ipc('shell','openSettings','controlcenter');wait(lambda:state()['settingsVisible'],'module editor opens');time.sleep(.3) ipc('shell','openSettings','controlcenter');wait(lambda:state()['settingsVisible'],'module editor opens');time.sleep(.3)
assert ipc('controlTest','settingsClick','control-down-connectivity') second=state()['modules'][1]['id']
assert ipc('controlTest','settingsDrag','control-drag-connectivity','control-drag-'+second)
wait(lambda:state()['modules'][1]['id']=='connectivity','visual module reorder') wait(lambda:state()['modules'][1]['id']=='connectivity','visual module reorder')
assert ipc('controlTest','settingsClick','control-enable-audio') assert ipc('controlTest','settingsClick','control-enable-audio')
wait(lambda:not next(m for m in state()['modules'] if m['id']=='audio')['enabled'],'visual module toggle') wait(lambda:not next(m for m in state()['modules'] if m['id']=='audio')['enabled'],'visual module toggle')