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>
555 lines
24 KiB
QML
555 lines
24 KiB
QML
pragma ComponentBehavior: Bound
|
||
import QtQuick
|
||
import QtQuick.Layouts
|
||
import Quickshell
|
||
import Quickshell.Wayland
|
||
import "../components"
|
||
import "../services"
|
||
import "../theme"
|
||
import "../services/WidgetLogic.js" as Logic
|
||
|
||
// Desktop widget editor for one output (after Serpantinum's widget redactor):
|
||
// drag to move, handles to resize, snapping guides or a grid, a toolbar to add
|
||
// widgets and an inspector for the selected one. The real widget surfaces sit
|
||
// below and follow every change live.
|
||
// qmllint disable uncreatable-type
|
||
PanelWindow {
|
||
id: root
|
||
required property var modelData
|
||
screen: modelData
|
||
anchors {
|
||
top: true
|
||
bottom: true
|
||
left: true
|
||
right: true
|
||
}
|
||
color: Theme.transparent
|
||
exclusionMode: ExclusionMode.Ignore
|
||
WlrLayershell.layer: WlrLayer.Overlay
|
||
WlrLayershell.namespace: "glassMxrph-widget-editor"
|
||
WlrLayershell.keyboardFocus: WlrKeyboardFocus.Exclusive
|
||
Component.onCompleted: WidgetState.editors = WidgetState.editors.concat([keys])
|
||
Component.onDestruction: WidgetState.editors = WidgetState.editors.filter(e => e !== keys)
|
||
|
||
readonly property var bounds: ({
|
||
w: width,
|
||
h: height
|
||
})
|
||
readonly property var onScreen: WidgetState.items.filter(i => i.monitor === screen.name && !!WidgetRegistry.type(i.type))
|
||
readonly property var selectedItem: WidgetState.item(WidgetState.selected)
|
||
readonly property var selectedType: selectedItem ? WidgetRegistry.type(selectedItem.type) : null
|
||
readonly property bool selectionHere: !!selectedItem && selectedItem.monitor === screen.name
|
||
readonly property var selectedRect: selectionHere ? WidgetState.rect(selectedItem.id) : null
|
||
// Move the toolbar and inspector to the top when they would cover the selection.
|
||
readonly property bool chromeOnTop: !!selectedRect && height > 0 && selectedRect.y + selectedRect.h > height - 280
|
||
readonly property int gridStep: WidgetState.grid ? WidgetState.gridSize : 0
|
||
property var guides: ({
|
||
x: [],
|
||
y: []
|
||
})
|
||
function others(id) {
|
||
return onScreen.filter(i => i.id !== id).map(i => WidgetState.rect(i.id));
|
||
}
|
||
function nudge(dx, dy) {
|
||
if (!selectionHere)
|
||
return;
|
||
const r = WidgetState.rect(selectedItem.id);
|
||
WidgetState.setDraft(selectedItem.id, Logic.clampRect({
|
||
x: r.x + dx,
|
||
y: r.y + dy,
|
||
w: r.w,
|
||
h: r.h
|
||
}, bounds));
|
||
WidgetState.commit(selectedItem.id);
|
||
}
|
||
|
||
Item {
|
||
id: keys
|
||
anchors.fill: parent
|
||
focus: true
|
||
Component.onCompleted: forceActiveFocus()
|
||
Keys.onPressed: event => {
|
||
const step = event.modifiers & Qt.ShiftModifier ? 10 : 1;
|
||
if (event.key === Qt.Key_Escape) {
|
||
if (WidgetState.selected)
|
||
WidgetState.selected = "";
|
||
else
|
||
WidgetState.done();
|
||
} else if ((event.key === Qt.Key_Delete || event.key === Qt.Key_Backspace) && root.selectionHere)
|
||
WidgetState.remove(root.selectedItem.id);
|
||
else if (event.key === Qt.Key_Left)
|
||
root.nudge(-step, 0);
|
||
else if (event.key === Qt.Key_Right)
|
||
root.nudge(step, 0);
|
||
else if (event.key === Qt.Key_Up)
|
||
root.nudge(0, -step);
|
||
else if (event.key === Qt.Key_Down)
|
||
root.nudge(0, step);
|
||
else
|
||
return;
|
||
event.accepted = true;
|
||
}
|
||
|
||
Rectangle {
|
||
anchors.fill: parent
|
||
color: Qt.alpha("#000000", 0.3)
|
||
}
|
||
Canvas {
|
||
id: gridLines
|
||
anchors.fill: parent
|
||
visible: WidgetState.grid
|
||
readonly property color line: Qt.alpha(Theme.text, 0.07)
|
||
onVisibleChanged: requestPaint()
|
||
onPaint: {
|
||
const ctx = getContext("2d");
|
||
ctx.reset();
|
||
ctx.strokeStyle = line;
|
||
ctx.lineWidth = 1;
|
||
ctx.beginPath();
|
||
for (let x = WidgetState.gridSize; x < width; x += WidgetState.gridSize) {
|
||
ctx.moveTo(x + 0.5, 0);
|
||
ctx.lineTo(x + 0.5, height);
|
||
}
|
||
for (let y = WidgetState.gridSize; y < height; y += WidgetState.gridSize) {
|
||
ctx.moveTo(0, y + 0.5);
|
||
ctx.lineTo(width, y + 0.5);
|
||
}
|
||
ctx.stroke();
|
||
}
|
||
}
|
||
MouseArea {
|
||
anchors.fill: parent
|
||
onPressed: {
|
||
WidgetState.selected = "";
|
||
keys.forceActiveFocus();
|
||
}
|
||
}
|
||
Repeater {
|
||
model: root.guides.x
|
||
Rectangle {
|
||
required property real modelData
|
||
x: modelData
|
||
width: 1
|
||
height: parent.height
|
||
color: Theme.accent
|
||
}
|
||
}
|
||
Repeater {
|
||
model: root.guides.y
|
||
Rectangle {
|
||
required property real modelData
|
||
y: modelData
|
||
height: 1
|
||
width: parent.width
|
||
color: Theme.accent
|
||
}
|
||
}
|
||
|
||
// One frame per widget on this output.
|
||
Repeater {
|
||
model: root.onScreen.map(i => i.id)
|
||
Item {
|
||
id: proxy
|
||
required property string modelData
|
||
readonly property var item: WidgetState.item(modelData)
|
||
readonly property var geometry: WidgetState.rect(modelData)
|
||
readonly property bool selected: WidgetState.selected === modelData
|
||
x: geometry.x
|
||
y: geometry.y
|
||
width: geometry.w
|
||
height: geometry.h
|
||
z: selected ? 2 : 1
|
||
|
||
Rectangle {
|
||
anchors.fill: parent
|
||
radius: Math.min(Theme.radius, width / 2, height / 2)
|
||
color: proxy.selected ? Qt.alpha(Theme.accent, 0.1) : move.containsMouse ? Qt.alpha(Theme.text, 0.06) : Theme.transparent
|
||
border.width: proxy.selected ? 2 : 1
|
||
border.color: proxy.selected ? Theme.accent : Qt.alpha(Theme.text, move.containsMouse ? 0.6 : 0.3)
|
||
}
|
||
Rectangle {
|
||
visible: proxy.selected || move.containsMouse
|
||
y: proxy.y > 30 ? -26 : proxy.height + 4
|
||
implicitWidth: label.implicitWidth + 16
|
||
implicitHeight: 22
|
||
radius: 11
|
||
color: proxy.selected ? Theme.accent : Qt.alpha(Theme.tint, 0.75)
|
||
Text {
|
||
id: label
|
||
anchors.centerIn: parent
|
||
text: proxy.item ? WidgetRegistry.type(proxy.item.type).name + " " + Math.round(proxy.geometry.w) + "×" + Math.round(proxy.geometry.h) : ""
|
||
color: proxy.selected ? Theme.accentText : Theme.text
|
||
font.pixelSize: 11
|
||
}
|
||
}
|
||
MouseArea {
|
||
id: move
|
||
objectName: "widgetMove-" + proxy.modelData
|
||
anchors.fill: parent
|
||
hoverEnabled: true
|
||
cursorShape: pressed ? Qt.ClosedHandCursor : Qt.OpenHandCursor
|
||
property point start
|
||
property var startRect
|
||
onPressed: mouse => {
|
||
WidgetState.selected = proxy.modelData;
|
||
keys.forceActiveFocus();
|
||
start = mapToItem(null, mouse.x, mouse.y);
|
||
startRect = proxy.geometry;
|
||
}
|
||
onPositionChanged: mouse => {
|
||
if (!pressed)
|
||
return;
|
||
const p = mapToItem(null, mouse.x, mouse.y);
|
||
const snapped = Logic.snapMove({
|
||
x: startRect.x + p.x - start.x,
|
||
y: startRect.y + p.y - start.y,
|
||
w: startRect.w,
|
||
h: startRect.h
|
||
}, root.others(proxy.modelData), root.bounds, root.gridStep, 10);
|
||
WidgetState.setDraft(proxy.modelData, snapped);
|
||
root.guides = snapped.guides;
|
||
}
|
||
onReleased: {
|
||
WidgetState.commit(proxy.modelData);
|
||
root.guides = {
|
||
x: [],
|
||
y: []
|
||
};
|
||
}
|
||
}
|
||
// Corner and edge handles.
|
||
Repeater {
|
||
model: proxy.selected ? [
|
||
{
|
||
fx: 0,
|
||
fy: 0,
|
||
edges: {
|
||
left: true,
|
||
top: true
|
||
},
|
||
cursor: Qt.SizeFDiagCursor
|
||
},
|
||
{
|
||
fx: 0.5,
|
||
fy: 0,
|
||
edges: {
|
||
top: true
|
||
},
|
||
cursor: Qt.SizeVerCursor
|
||
},
|
||
{
|
||
fx: 1,
|
||
fy: 0,
|
||
edges: {
|
||
right: true,
|
||
top: true
|
||
},
|
||
cursor: Qt.SizeBDiagCursor
|
||
},
|
||
{
|
||
fx: 1,
|
||
fy: 0.5,
|
||
edges: {
|
||
right: true
|
||
},
|
||
cursor: Qt.SizeHorCursor
|
||
},
|
||
{
|
||
fx: 1,
|
||
fy: 1,
|
||
edges: {
|
||
right: true,
|
||
bottom: true
|
||
},
|
||
cursor: Qt.SizeFDiagCursor
|
||
},
|
||
{
|
||
fx: 0.5,
|
||
fy: 1,
|
||
edges: {
|
||
bottom: true
|
||
},
|
||
cursor: Qt.SizeVerCursor
|
||
},
|
||
{
|
||
fx: 0,
|
||
fy: 1,
|
||
edges: {
|
||
left: true,
|
||
bottom: true
|
||
},
|
||
cursor: Qt.SizeBDiagCursor
|
||
},
|
||
{
|
||
fx: 0,
|
||
fy: 0.5,
|
||
edges: {
|
||
left: true
|
||
},
|
||
cursor: Qt.SizeHorCursor
|
||
}
|
||
] : []
|
||
Rectangle {
|
||
id: handle
|
||
required property var modelData
|
||
x: proxy.width * modelData.fx - width / 2
|
||
y: proxy.height * modelData.fy - height / 2
|
||
width: 14
|
||
height: 14
|
||
radius: 7
|
||
color: Theme.text
|
||
border.width: 2
|
||
border.color: Theme.accent
|
||
MouseArea {
|
||
anchors.fill: parent
|
||
anchors.margins: -4
|
||
cursorShape: handle.modelData.cursor
|
||
property point start
|
||
property var startRect
|
||
onPressed: mouse => {
|
||
start = mapToItem(null, mouse.x, mouse.y);
|
||
startRect = proxy.geometry;
|
||
}
|
||
onPositionChanged: mouse => {
|
||
if (!pressed)
|
||
return;
|
||
const p = mapToItem(null, mouse.x, mouse.y);
|
||
WidgetState.setDraft(proxy.modelData, Logic.resizeRect(startRect, p.x - start.x, p.y - start.y, handle.modelData.edges, WidgetState.limits(proxy.item.type), root.bounds, root.gridStep));
|
||
}
|
||
onReleased: WidgetState.commit(proxy.modelData)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// Toolbar and inspector, stacked at the bottom (or top, away from the selection).
|
||
Column {
|
||
id: chrome
|
||
// Above every widget frame.
|
||
z: 10
|
||
anchors.horizontalCenter: parent.horizontalCenter
|
||
// Plain y (not switched anchors, which do not reliably reset).
|
||
y: root.chromeOnTop ? (ConfigService.ready ? ConfigService.data.bar.margin + ConfigService.data.bar.height : 48) + 20 : parent.height - height - 28
|
||
width: Math.min(root.width - 48, 900)
|
||
spacing: 12
|
||
|
||
// Inspector for the selected widget.
|
||
GlassPanel {
|
||
id: inspector
|
||
objectName: "widgetInspector"
|
||
visible: root.selectionHere
|
||
surfaceOpacity: Math.max(Theme.panelOpacity, 0.8)
|
||
anchors.horizontalCenter: parent.horizontalCenter
|
||
width: Math.min(chrome.width, 520)
|
||
height: inspectorBody.implicitHeight + 28
|
||
MouseArea {
|
||
anchors.fill: parent
|
||
}
|
||
ColumnLayout {
|
||
id: inspectorBody
|
||
anchors.left: parent.left
|
||
anchors.right: parent.right
|
||
anchors.top: parent.top
|
||
anchors.margins: 14
|
||
spacing: 10
|
||
RowLayout {
|
||
Layout.fillWidth: true
|
||
spacing: 10
|
||
GlassIcon {
|
||
size: 32
|
||
glyph: root.selectedType ? root.selectedType.icon : ""
|
||
fallback: root.selectedType ? root.selectedType.name.charAt(0) : ""
|
||
active: true
|
||
}
|
||
Text {
|
||
text: root.selectedType ? root.selectedType.name : ""
|
||
color: Theme.text
|
||
font.pixelSize: 14
|
||
font.weight: Font.DemiBold
|
||
Layout.fillWidth: true
|
||
}
|
||
GlassButton {
|
||
text: "Duplicate"
|
||
onClicked: WidgetState.duplicate(root.selectedItem.id)
|
||
}
|
||
GlassButton {
|
||
objectName: "widgetDelete"
|
||
text: "Delete"
|
||
onClicked: WidgetState.remove(root.selectedItem.id)
|
||
}
|
||
}
|
||
RowLayout {
|
||
visible: !!root.selectedItem && WidgetRegistry.variants(root.selectedItem.type).length > 1
|
||
Layout.fillWidth: true
|
||
Text {
|
||
text: "Style"
|
||
color: Theme.textSecondary
|
||
font.pixelSize: 12
|
||
Layout.preferredWidth: 70
|
||
}
|
||
GlassSegmented {
|
||
model: root.selectedItem ? WidgetRegistry.variants(root.selectedItem.type) : []
|
||
currentIndex: root.selectedItem ? model.indexOf(root.selectedItem.variant) : -1
|
||
onActivated: (index, value) => WidgetState.update(root.selectedItem.id, {
|
||
variant: value
|
||
})
|
||
}
|
||
Item {
|
||
Layout.fillWidth: true
|
||
}
|
||
}
|
||
RowLayout {
|
||
Layout.fillWidth: true
|
||
Text {
|
||
text: "Opacity"
|
||
color: Theme.textSecondary
|
||
font.pixelSize: 12
|
||
Layout.preferredWidth: 70
|
||
}
|
||
GlassSlider {
|
||
Layout.fillWidth: true
|
||
from: 0.1
|
||
to: 1
|
||
stepSize: 0.05
|
||
value: root.selectedItem ? root.selectedItem.opacity : 1
|
||
onMoved: WidgetState.update(root.selectedItem.id, {
|
||
opacity: Math.round(value * 100) / 100
|
||
})
|
||
}
|
||
Text {
|
||
text: root.selectedItem ? Math.round(root.selectedItem.opacity * 100) + "%" : ""
|
||
color: Theme.textSecondary
|
||
font.pixelSize: 12
|
||
Layout.preferredWidth: 40
|
||
horizontalAlignment: Text.AlignRight
|
||
}
|
||
}
|
||
Repeater {
|
||
model: root.selectedType && root.selectedType.options ? root.selectedType.options : []
|
||
RowLayout {
|
||
id: option
|
||
required property var modelData
|
||
readonly property var current: root.selectedItem && root.selectedItem.options ? root.selectedItem.options[modelData.id] : undefined
|
||
Layout.fillWidth: true
|
||
Text {
|
||
text: option.modelData.label
|
||
color: Theme.textSecondary
|
||
font.pixelSize: 12
|
||
Layout.fillWidth: option.modelData.kind === "toggle"
|
||
Layout.preferredWidth: option.modelData.kind === "toggle" ? -1 : 150
|
||
wrapMode: Text.Wrap
|
||
}
|
||
GlassToggle {
|
||
visible: option.modelData.kind === "toggle"
|
||
checked: !!option.current
|
||
onToggled: WidgetState.setOption(root.selectedItem.id, option.modelData.id, checked)
|
||
}
|
||
GlassTextField {
|
||
visible: option.modelData.kind === "text"
|
||
Layout.fillWidth: true
|
||
text: option.current || ""
|
||
onEditingFinished: WidgetState.setOption(root.selectedItem.id, option.modelData.id, text.trim())
|
||
Keys.onEscapePressed: keys.forceActiveFocus()
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// Add widgets, grid toggle and Done.
|
||
GlassPanel {
|
||
objectName: "widgetToolbar"
|
||
surfaceOpacity: Math.max(Theme.panelOpacity, 0.8)
|
||
width: chrome.width
|
||
height: toolbarBody.implicitHeight + 24
|
||
MouseArea {
|
||
anchors.fill: parent
|
||
}
|
||
ColumnLayout {
|
||
id: toolbarBody
|
||
anchors.left: parent.left
|
||
anchors.right: parent.right
|
||
anchors.top: parent.top
|
||
anchors.margins: 12
|
||
spacing: 10
|
||
Flow {
|
||
Layout.preferredWidth: chrome.width - 24
|
||
Layout.fillWidth: true
|
||
spacing: 6
|
||
Repeater {
|
||
model: WidgetRegistry.order
|
||
Rectangle {
|
||
id: adder
|
||
required property string modelData
|
||
readonly property var type: WidgetRegistry.type(modelData)
|
||
objectName: "widgetAdd-" + modelData
|
||
width: 64
|
||
height: 62
|
||
radius: 12
|
||
color: addArea.containsMouse ? Theme.hover : Theme.transparent
|
||
Column {
|
||
anchors.centerIn: parent
|
||
spacing: 4
|
||
GlassIcon {
|
||
anchors.horizontalCenter: parent.horizontalCenter
|
||
size: 34
|
||
glyph: adder.type.icon
|
||
fallback: adder.type.name.charAt(0)
|
||
}
|
||
Text {
|
||
anchors.horizontalCenter: parent.horizontalCenter
|
||
width: 60
|
||
horizontalAlignment: Text.AlignHCenter
|
||
elide: Text.ElideRight
|
||
text: adder.type.name
|
||
color: Theme.textSecondary
|
||
font.pixelSize: 10
|
||
}
|
||
}
|
||
MouseArea {
|
||
id: addArea
|
||
anchors.fill: parent
|
||
hoverEnabled: true
|
||
cursorShape: Qt.PointingHandCursor
|
||
onClicked: {
|
||
WidgetState.add(adder.modelData, root.screen.name);
|
||
keys.forceActiveFocus();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
RowLayout {
|
||
Layout.fillWidth: true
|
||
spacing: 10
|
||
Text {
|
||
text: "Drag to move · handles resize · arrows nudge · Delete removes · Esc finishes"
|
||
color: Theme.textSecondary
|
||
font.pixelSize: 11
|
||
elide: Text.ElideRight
|
||
Layout.fillWidth: true
|
||
}
|
||
Text {
|
||
text: "Snap to grid"
|
||
color: Theme.text
|
||
font.pixelSize: 12
|
||
}
|
||
GlassToggle {
|
||
objectName: "widgetGrid"
|
||
checked: WidgetState.grid
|
||
onToggled: ConfigService.setValue("desktopWidgets.grid", checked)
|
||
}
|
||
GlassButton {
|
||
objectName: "widgetDone"
|
||
text: "Done"
|
||
accented: true
|
||
onClicked: WidgetState.done()
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|