239 lines
8.3 KiB
QML
239 lines
8.3 KiB
QML
import QtQuick
|
|
import Quickshell
|
|
import Quickshell.Wayland
|
|
|
|
// Opens in the middle of one monitor when a badge is clicked: a box to
|
|
// rename the workspace and a box to pick its color and opacity.
|
|
// Clicking anywhere else or pressing Escape closes it.
|
|
PanelWindow {
|
|
id: root
|
|
|
|
required property Compositor compositor
|
|
required property ColorStore store
|
|
required property Theme theme
|
|
|
|
// The workspace being edited. Copied in openFor() so a refresh while
|
|
// the popup is open does not swap it for another one.
|
|
property string output
|
|
property int wsId
|
|
property string wsName
|
|
property string colorKey
|
|
|
|
// Hidden until a badge is clicked.
|
|
visible: false
|
|
color: "transparent"
|
|
|
|
anchors {
|
|
top: true
|
|
bottom: true
|
|
left: true
|
|
right: true
|
|
}
|
|
|
|
exclusionMode: ExclusionMode.Ignore
|
|
WlrLayershell.namespace: "quickshell:workspace-badge-editor"
|
|
WlrLayershell.layer: WlrLayer.Overlay
|
|
WlrLayershell.keyboardFocus: root.visible ? WlrKeyboardFocus.Exclusive : WlrKeyboardFocus.None
|
|
|
|
function openFor(output: string, id: int, name: string, key: string): void {
|
|
root.output = output;
|
|
root.wsId = id;
|
|
root.wsName = name;
|
|
root.colorKey = key;
|
|
nameField.text = name;
|
|
root.visible = true;
|
|
Qt.callLater(() => {
|
|
nameField.forceActiveFocus();
|
|
nameField.selectAll();
|
|
});
|
|
}
|
|
|
|
function close(): void {
|
|
root.visible = false;
|
|
}
|
|
|
|
// Color and opacity are saved as they are picked; only the name waits for this.
|
|
function accept(): void {
|
|
const name = nameField.text.trim();
|
|
if (name !== root.wsName) {
|
|
root.compositor.rename(root.output, root.wsId, root.wsName, name);
|
|
root.store.move(root.colorKey, root.store.keyFor(root.wsId, name));
|
|
}
|
|
root.close();
|
|
}
|
|
|
|
// Clicks that miss both boxes land here.
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
onClicked: root.close()
|
|
}
|
|
|
|
FocusScope {
|
|
anchors.centerIn: parent
|
|
width: Math.min(root.theme.popupMaxWidth, parent.width - root.theme.popupMargin * 2)
|
|
height: boxes.implicitHeight
|
|
focus: true
|
|
|
|
Keys.onEscapePressed: event => {
|
|
root.close();
|
|
event.accepted = true;
|
|
}
|
|
|
|
Column {
|
|
id: boxes
|
|
width: parent.width
|
|
spacing: root.theme.popupGap
|
|
|
|
// ── rename box ──────────────────────────────────────────────
|
|
|
|
Item {
|
|
width: parent.width
|
|
height: renameColumn.implicitHeight + root.theme.popupPadding * 2
|
|
|
|
// Keeps clicks on the box from closing the popup.
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
}
|
|
|
|
Glass {
|
|
anchors.fill: parent
|
|
theme: root.theme
|
|
radius: root.theme.cornerRadius
|
|
tint: root.theme.panelBg
|
|
selected: false
|
|
shadow: false
|
|
}
|
|
|
|
Column {
|
|
id: renameColumn
|
|
anchors.left: parent.left
|
|
anchors.right: parent.right
|
|
anchors.top: parent.top
|
|
anchors.margins: root.theme.popupPadding
|
|
spacing: root.theme.popupSpacing
|
|
|
|
Text {
|
|
text: "Rename workspace"
|
|
color: root.theme.labelColor
|
|
font.pixelSize: root.theme.labelSize
|
|
}
|
|
|
|
Row {
|
|
width: parent.width
|
|
spacing: root.theme.popupSpacing
|
|
|
|
Item {
|
|
width: parent.width - okButton.width - parent.spacing
|
|
height: root.theme.fieldHeight
|
|
|
|
Glass {
|
|
anchors.fill: parent
|
|
theme: root.theme
|
|
radius: root.theme.cornerRadius / 2
|
|
tint: root.theme.fieldBg
|
|
selected: nameField.activeFocus
|
|
shadow: false
|
|
}
|
|
|
|
TextInput {
|
|
id: nameField
|
|
anchors.fill: parent
|
|
anchors.leftMargin: root.theme.fieldPadding
|
|
anchors.rightMargin: root.theme.fieldPadding
|
|
verticalAlignment: TextInput.AlignVCenter
|
|
color: root.theme.textColor
|
|
font.pixelSize: root.theme.fontSize
|
|
selectByMouse: true
|
|
selectionColor: root.theme.fieldBorder
|
|
selectedTextColor: root.theme.buttonText
|
|
clip: true
|
|
|
|
onAccepted: root.accept()
|
|
}
|
|
}
|
|
|
|
Rectangle {
|
|
id: okButton
|
|
width: root.theme.buttonWidth
|
|
height: root.theme.fieldHeight
|
|
radius: root.theme.cornerRadius / 2
|
|
color: okArea.pressed ? Qt.darker(root.theme.buttonBg, 1.2) : root.theme.buttonBg
|
|
|
|
Text {
|
|
anchors.centerIn: parent
|
|
text: "OK"
|
|
color: root.theme.buttonText
|
|
font.pixelSize: root.theme.fontSize
|
|
font.bold: true
|
|
}
|
|
|
|
MouseArea {
|
|
id: okArea
|
|
anchors.fill: parent
|
|
cursorShape: Qt.PointingHandCursor
|
|
onClicked: root.accept()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// ── color box ───────────────────────────────────────────────
|
|
|
|
Item {
|
|
width: parent.width
|
|
height: colorColumn.implicitHeight + root.theme.popupPadding * 2
|
|
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
}
|
|
|
|
Glass {
|
|
anchors.fill: parent
|
|
theme: root.theme
|
|
radius: root.theme.cornerRadius
|
|
tint: root.theme.panelBg
|
|
selected: false
|
|
shadow: false
|
|
}
|
|
|
|
Column {
|
|
id: colorColumn
|
|
anchors.left: parent.left
|
|
anchors.right: parent.right
|
|
anchors.top: parent.top
|
|
anchors.margins: root.theme.popupPadding
|
|
spacing: root.theme.popupSpacing
|
|
|
|
Text {
|
|
text: "Color"
|
|
color: root.theme.labelColor
|
|
font.pixelSize: root.theme.labelSize
|
|
}
|
|
|
|
ColorPicker {
|
|
width: parent.width
|
|
theme: root.theme
|
|
current: root.store.colorFor(root.colorKey)
|
|
onPicked: value => root.store.setColor(root.colorKey, value)
|
|
}
|
|
|
|
Text {
|
|
text: "Opacity"
|
|
color: root.theme.labelColor
|
|
font.pixelSize: root.theme.labelSize
|
|
}
|
|
|
|
OpacitySlider {
|
|
width: parent.width
|
|
theme: root.theme
|
|
baseColor: root.store.colorFor(root.colorKey)
|
|
value: root.store.opacityFor(root.colorKey)
|
|
onPicked: value => root.store.setOpacity(root.colorKey, value)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|