diff --git a/package.nix b/package.nix index defb1c8..b7b505b 100644 --- a/package.nix +++ b/package.nix @@ -15,6 +15,7 @@ stdenvNoCC.mkDerivation { root = ./.; fileset = lib.fileset.unions [ ./app-carousel + ./workspace-rename ./skygqts.nu ]; }; @@ -27,6 +28,7 @@ stdenvNoCC.mkDerivation { runHook preInstall mkdir -p $out/share/skygqts cp -r app-carousel $out/share/skygqts/ + cp -r workspace-rename $out/share/skygqts/ cp skygqts.nu $out/share/skygqts/ mkdir -p $out/bin makeWrapper ${lib.getExe nushell} $out/bin/skygqts \ diff --git a/skygqts.nu b/skygqts.nu index 3a29bbc..bab3276 100755 --- a/skygqts.nu +++ b/skygqts.nu @@ -15,18 +15,25 @@ def "main carousel" [ qs -p ($REPO_ROOT | path join "app-carousel") } -def "main overview" [] { - qs -p ($REPO_ROOT | path join "overview") +const WS_RENAME_PATH = $REPO_ROOT | path join "workspace-rename" + +# Send an IPC call to the running workspace rename bar +def ws-rename-ipc [fn: string] { + qs ipc -p $WS_RENAME_PATH call wsname $fn } -def "main overview toggle" [] { - qs -p ($REPO_ROOT | path join "overview") ipc call overview toggle +# Run the workspace rename bar +def "main workspace-rename" [ + --daemon (-d) # detach from the terminal +] { + if $daemon { + qs -d -n -p $WS_RENAME_PATH + } else { + qs -n -p $WS_RENAME_PATH + } } -def "main skyview" [] { - qs -p ($REPO_ROOT | path join "skyview") -} - -def "main skyview toggle" [] { - qs -p ($REPO_ROOT | path join "skyview") ipc call skyview toggle +# Toggle the workspace rename bar +def "main workspace-rename toggle" [] { + ws-rename-ipc "toggle" } diff --git a/workspace-rename/Compositor.qml b/workspace-rename/Compositor.qml new file mode 100644 index 0000000..47fe648 --- /dev/null +++ b/workspace-rename/Compositor.qml @@ -0,0 +1,104 @@ +import QtQuick +import Quickshell +import Quickshell.Io + +// Talks to whichever compositor is running. Everything goes through the +// command line tools so this file works the same on niri and Hyprland. +Item { + id: root + + // "niri", "hyprland" or "" when neither was detected. + readonly property string kind: { + if (Quickshell.env("NIRI_SOCKET")) + return "niri"; + if (Quickshell.env("HYPRLAND_INSTANCE_SIGNATURE")) + return "hyprland"; + return ""; + } + + readonly property string logoSource: { + if (root.kind === "niri") + return Qt.resolvedUrl("assets/niri.png"); + if (root.kind === "hyprland") + return Qt.resolvedUrl("assets/hyprland.png"); + return ""; + } + + // Name of the focused workspace, empty when it has none. + property string currentName: "" + // Id of the focused workspace, -1 when unknown. Only Hyprland needs it. + property int currentId: -1 + + signal refreshed + + function refresh(): void { + if (root.kind === "") + return; + query.running = false; + query.command = root.kind === "niri" ? ["niri", "msg", "--json", "workspaces"] : ["hyprctl", "-j", "activeworkspace"]; + query.running = true; + } + + function apply(name: string): void { + const trimmed = name.trim(); + if (root.kind === "niri") { + action.command = trimmed.length > 0 ? ["niri", "msg", "action", "set-workspace-name", trimmed] : ["niri", "msg", "action", "unset-workspace-name"]; + } else if (root.kind === "hyprland") { + if (root.currentId < 0) + return; + const id = String(root.currentId); + // Hyprland has no "clear name", so fall back to the numeric id. + action.command = ["hyprctl", "dispatch", "renameworkspace", id, trimmed.length > 0 ? trimmed : id]; + } else { + return; + } + action.running = false; + action.running = true; + root.currentName = trimmed; + } + + Process { + id: query + running: false + + stdout: StdioCollector { + onStreamFinished: { + let parsed = null; + try { + parsed = JSON.parse(this.text); + } catch (e) { + console.warn("workspace-rename: could not read workspace data:", e); + return; + } + + if (root.kind === "niri") { + const focused = (parsed ?? []).find(ws => ws.is_focused); + if (!focused) { + console.warn("workspace-rename: no focused workspace reported"); + return; + } + root.currentId = focused.id ?? -1; + root.currentName = focused.name ?? ""; + } else { + root.currentId = parsed.id ?? -1; + // Unnamed Hyprland workspaces report their id as the name. + const name = String(parsed.name ?? ""); + root.currentName = name === String(root.currentId) ? "" : name; + } + root.refreshed(); + } + } + } + + Process { + id: action + running: false + + stderr: StdioCollector { + onStreamFinished: { + if (this.text.trim().length > 0) + console.warn("workspace-rename:", this.text.trim()); + } + } + } +} diff --git a/workspace-rename/RenameBar.qml b/workspace-rename/RenameBar.qml new file mode 100644 index 0000000..11e5132 --- /dev/null +++ b/workspace-rename/RenameBar.qml @@ -0,0 +1,145 @@ +import QtQuick +import Quickshell +import Quickshell.Wayland + +PanelWindow { + id: root + + required property bool shellOpen + required property Compositor compositor + required property Theme theme + + signal requestClose + + visible: root.shellOpen + color: "transparent" + + implicitWidth: root.theme.barWidth + implicitHeight: root.theme.barHeight + + exclusionMode: ExclusionMode.Ignore + WlrLayershell.namespace: "quickshell:workspace-rename" + 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(); + } + + Rectangle { + anchors.fill: parent + radius: root.theme.cornerRadius + color: root.theme.barBg + border.color: root.theme.barBorder + border.width: 1 + + 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 + } + + Rectangle { + 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 + radius: root.theme.cornerRadius / 2 + color: root.theme.fieldBg + border.color: nameField.activeFocus ? root.theme.fieldBorder : root.theme.barBorder + border.width: 1 + + 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; + } + } + } + + 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() + } + } + } + } +} diff --git a/workspace-rename/Theme.qml b/workspace-rename/Theme.qml new file mode 100644 index 0000000..2cb8242 --- /dev/null +++ b/workspace-rename/Theme.qml @@ -0,0 +1,24 @@ +import QtQuick + +QtObject { + readonly property color barBg: "#f00b0e14" + readonly property color barBorder: "#40ffffff" + readonly property color textColor: "#ffffff" + readonly property color labelColor: "#a9b1d6" + readonly property color fieldBg: "#332a2e3a" + readonly property color fieldBorder: "#7aa2f7" + readonly property color buttonBg: "#7aa2f7" + readonly property color buttonText: "#0b0e14" + + readonly property real cornerRadius: 12 + readonly property real barHeight: 84 + readonly property real barWidth: 800 + // Space between the bar edge and the boxes inside it. + readonly property real barPadding: 18 + readonly property real barSpacing: 14 + // Space between a box edge and its own text. + readonly property real fieldPadding: 14 + readonly property real logoSize: 36 + readonly property real fontSize: 24 + readonly property real buttonWidth: 86 +} diff --git a/workspace-rename/assets/niri.png b/workspace-rename/assets/niri.png new file mode 100644 index 0000000..5fa6753 Binary files /dev/null and b/workspace-rename/assets/niri.png differ diff --git a/workspace-rename/assets/niri.webp b/workspace-rename/assets/niri.webp new file mode 100644 index 0000000..73e9bdb Binary files /dev/null and b/workspace-rename/assets/niri.webp differ diff --git a/workspace-rename/shell.qml b/workspace-rename/shell.qml new file mode 100644 index 0000000..7555c5a --- /dev/null +++ b/workspace-rename/shell.qml @@ -0,0 +1,37 @@ +import QtQuick +import Quickshell +import Quickshell.Io + +ShellRoot { + id: shell + + property bool barOpen: false + + Compositor { + id: compositor + } + + Theme { + id: theme + } + + Component.onCompleted: { + if (compositor.kind === "") + console.warn("workspace-rename: neither niri nor Hyprland was detected"); + } + + IpcHandler { + target: "wsname" + + function toggle(): void { + shell.barOpen = !shell.barOpen; + } + } + + RenameBar { + shellOpen: shell.barOpen + compositor: compositor + theme: theme + onRequestClose: shell.barOpen = false + } +}