179 lines
5.7 KiB
QML
179 lines
5.7 KiB
QML
import QtQuick
|
|
import Quickshell
|
|
import Quickshell.Wayland
|
|
|
|
PanelWindow {
|
|
id: root
|
|
|
|
required property bool shellOpen
|
|
required property Compositor compositor
|
|
required property Theme theme
|
|
|
|
signal requestClose
|
|
signal requestGoto
|
|
|
|
visible: root.shellOpen
|
|
color: "transparent"
|
|
|
|
implicitWidth: root.theme.barWidth
|
|
implicitHeight: root.theme.barHeight
|
|
|
|
exclusionMode: ExclusionMode.Ignore
|
|
WlrLayershell.namespace: "quickshell:workspace-manager"
|
|
WlrLayershell.layer: WlrLayer.Overlay
|
|
WlrLayershell.keyboardFocus: root.visible ? WlrKeyboardFocus.Exclusive : WlrKeyboardFocus.None
|
|
|
|
// No anchors: the layer surface is then centered on the screen.
|
|
|
|
onVisibleChanged: {
|
|
if (!root.visible)
|
|
return;
|
|
root.compositor.refresh();
|
|
nameField.text = root.compositor.currentName;
|
|
Qt.callLater(() => {
|
|
nameField.forceActiveFocus();
|
|
nameField.selectAll();
|
|
});
|
|
}
|
|
|
|
Connections {
|
|
target: root.compositor
|
|
|
|
function onRefreshed(): void {
|
|
if (root.visible) {
|
|
nameField.text = root.compositor.currentName;
|
|
nameField.selectAll();
|
|
}
|
|
}
|
|
}
|
|
|
|
function accept(): void {
|
|
root.compositor.apply(nameField.text);
|
|
root.requestClose();
|
|
}
|
|
|
|
function isGotoKey(event): bool {
|
|
const mods = event.modifiers;
|
|
const ctrl = (mods & Qt.ControlModifier) && !(mods & Qt.AltModifier) && !(mods & Qt.MetaModifier);
|
|
return event.key === Qt.Key_G && ctrl;
|
|
}
|
|
|
|
Glass {
|
|
anchors.fill: parent
|
|
theme: root.theme
|
|
radius: root.theme.cornerRadius
|
|
tint: root.theme.barBg
|
|
selected: false
|
|
// The window is only as big as the bar, so a shadow would be cut off.
|
|
shadow: false
|
|
}
|
|
|
|
Item {
|
|
anchors.fill: parent
|
|
|
|
Row {
|
|
anchors.fill: parent
|
|
anchors.margins: root.theme.barPadding
|
|
spacing: root.theme.barSpacing
|
|
|
|
Image {
|
|
width: root.theme.logoSize
|
|
height: root.theme.logoSize
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
source: root.compositor.logoSource
|
|
visible: root.compositor.logoSource !== ""
|
|
sourceSize.width: root.theme.logoSize * 2
|
|
sourceSize.height: root.theme.logoSize * 2
|
|
fillMode: Image.PreserveAspectFit
|
|
smooth: true
|
|
// Raster source, so filter the downscale.
|
|
mipmap: true
|
|
}
|
|
|
|
Text {
|
|
id: label
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
text: "Workspace Name: "
|
|
color: root.theme.labelColor
|
|
font.pixelSize: root.theme.fontSize
|
|
}
|
|
|
|
Item {
|
|
id: field
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
width: parent.width - label.width - okButton.width - root.theme.logoSize - root.theme.barSpacing * 3
|
|
height: root.theme.barHeight - root.theme.barPadding * 2
|
|
|
|
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
|
|
focus: root.visible
|
|
|
|
onAccepted: root.accept()
|
|
|
|
Keys.onEscapePressed: event => {
|
|
root.requestClose();
|
|
event.accepted = true;
|
|
}
|
|
|
|
// Ctrl+G opens the carousel. A plain G still types into the name.
|
|
// Other keys must be rejected, or the field would swallow them.
|
|
Keys.onShortcutOverride: event => {
|
|
if (root.isGotoKey(event))
|
|
event.accepted = true;
|
|
}
|
|
Keys.onPressed: event => {
|
|
if (!root.isGotoKey(event)) {
|
|
event.accepted = false;
|
|
return;
|
|
}
|
|
root.requestGoto();
|
|
event.accepted = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
Rectangle {
|
|
id: okButton
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
width: root.theme.buttonWidth
|
|
height: root.theme.barHeight - root.theme.barPadding * 2
|
|
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
|
|
onClicked: root.accept()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|