preview works
This commit is contained in:
1 parent
2432c43f5f
commit
a148aaa30d
5 files changed
+305
-63
No files matched your search
@@ -48,6 +48,28 @@ Item {
|
||||
// False while a query is being restarted, so a leftover finish is ignored.
|
||||
property bool acceptStream: false
|
||||
|
||||
// Niri IPC responses come wrapped in {"Ok": {"Variant": value}}.
|
||||
// This helper unwraps them so the rest of the code sees bare arrays/objects.
|
||||
function unwrapJson(text: string): var {
|
||||
const parsed = JSON.parse(text);
|
||||
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
||||
if ("Ok" in parsed) {
|
||||
const inner = parsed.Ok;
|
||||
if (inner && typeof inner === "object" && !Array.isArray(inner)) {
|
||||
const keys = Object.keys(inner);
|
||||
if (keys.length === 1)
|
||||
return inner[keys[0]];
|
||||
}
|
||||
return inner;
|
||||
}
|
||||
if ("Err" in parsed) {
|
||||
console.warn("workspace-manager: compositor IPC error:", parsed.Err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
// Argv arrays waiting to run. A list of lists, so this stays untyped.
|
||||
property var focusQueue: []
|
||||
property var focusPending: []
|
||||
@@ -109,23 +131,46 @@ Item {
|
||||
|
||||
function parseOutputs(parsed): void {
|
||||
const layout = {};
|
||||
const list = Array.isArray(parsed) ? parsed : [];
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
const out = list[i];
|
||||
const name = root.asString(out.name);
|
||||
if (name.length === 0)
|
||||
continue;
|
||||
const logical = out.logical ?? {};
|
||||
const x = root.asNumber(logical.x, 0);
|
||||
const y = root.asNumber(logical.y, 0);
|
||||
const known = Number.isFinite(Number(logical.x)) && Number.isFinite(Number(logical.y));
|
||||
layout[name] = {
|
||||
x: x,
|
||||
y: y,
|
||||
known: known,
|
||||
activeId: -1,
|
||||
monitorFocused: false
|
||||
};
|
||||
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
||||
// niri format: HashMap<String, Output>
|
||||
const names = Object.keys(parsed);
|
||||
for (let i = 0; i < names.length; i++) {
|
||||
const out = parsed[names[i]];
|
||||
const name = root.asString(out.name);
|
||||
if (name.length === 0)
|
||||
continue;
|
||||
const logical = out.logical ?? {};
|
||||
const x = root.asNumber(logical.x, 0);
|
||||
const y = root.asNumber(logical.y, 0);
|
||||
const known = Number.isFinite(Number(logical.x)) && Number.isFinite(Number(logical.y));
|
||||
layout[name] = {
|
||||
x: x,
|
||||
y: y,
|
||||
known: known,
|
||||
activeId: -1,
|
||||
monitorFocused: false
|
||||
};
|
||||
}
|
||||
} else {
|
||||
// Hyprland format: Array (unused, Hyprland uses parseMonitors)
|
||||
const list = Array.isArray(parsed) ? parsed : [];
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
const out = list[i];
|
||||
const name = root.asString(out.name);
|
||||
if (name.length === 0)
|
||||
continue;
|
||||
const logical = out.logical ?? {};
|
||||
const x = root.asNumber(logical.x, 0);
|
||||
const y = root.asNumber(logical.y, 0);
|
||||
const known = Number.isFinite(Number(logical.x)) && Number.isFinite(Number(logical.y));
|
||||
layout[name] = {
|
||||
x: x,
|
||||
y: y,
|
||||
known: known,
|
||||
activeId: -1,
|
||||
monitorFocused: false
|
||||
};
|
||||
}
|
||||
}
|
||||
root.outputLayout = layout;
|
||||
}
|
||||
@@ -235,12 +280,14 @@ Item {
|
||||
const ws = workspaces[j];
|
||||
ws.windows = root.windowList.filter(w => root.matchWindow(w, name, ws.idx, ws.id));
|
||||
}
|
||||
// Hide empty workspaces unless they are the active one on this monitor.
|
||||
const visible = workspaces.filter(ws => ws.active || ws.windows.length > 0);
|
||||
const pos = root.outputLayout[name] ?? {};
|
||||
built.push({
|
||||
name: name,
|
||||
x: root.asNumber(pos.x, 0),
|
||||
y: root.asNumber(pos.y, 0),
|
||||
workspaces: workspaces
|
||||
workspaces: visible
|
||||
});
|
||||
}
|
||||
|
||||
@@ -294,6 +341,41 @@ Item {
|
||||
root.currentName = trimmed;
|
||||
}
|
||||
|
||||
// Rename a workspace by index (niri) or id (Hyprland).
|
||||
// Used from the carousel to rename the selected workspace.
|
||||
function renameWorkspace(wsId: int, wsIdx: int, name: string): void {
|
||||
const trimmed = name.trim();
|
||||
if (root.kind === "niri") {
|
||||
// niri's --workspace flag accepts an index (number) or name (string).
|
||||
if (trimmed.length > 0)
|
||||
action.command = ["niri", "msg", "action", "set-workspace-name", "--workspace", String(wsIdx), trimmed];
|
||||
else
|
||||
action.command = ["niri", "msg", "action", "unset-workspace-name", String(wsIdx)];
|
||||
} else if (root.kind === "hyprland") {
|
||||
if (wsId < 0)
|
||||
return;
|
||||
const id = String(wsId);
|
||||
action.command = ["hyprctl", "dispatch", "renameworkspace", id, trimmed.length > 0 ? trimmed : id];
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
action.running = false;
|
||||
action.running = true;
|
||||
// Update the name locally so the carousel reflects it immediately.
|
||||
if (root.currentId === wsId)
|
||||
root.currentName = trimmed;
|
||||
const mons = root.monitors;
|
||||
for (let i = 0; i < mons.length; i++) {
|
||||
const wsList = mons[i].workspaces ?? [];
|
||||
for (let j = 0; j < wsList.length; j++) {
|
||||
if (wsList[j].id === wsId) {
|
||||
wsList[j].name = trimmed;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Niri indexes count on the focused monitor only, so focus that monitor
|
||||
// first, then the index. Hyprland switches by workspace id in one command.
|
||||
function focusWorkspace(output: string, idx: int, id: int): void {
|
||||
@@ -350,7 +432,7 @@ Item {
|
||||
|
||||
let parsed = null;
|
||||
try {
|
||||
parsed = JSON.parse(this.text);
|
||||
parsed = root.unwrapJson(this.text);
|
||||
} catch (e) {
|
||||
console.warn("workspace-manager: could not read workspace data:", e);
|
||||
if (root.queryStage === "outputs" || root.queryStage === "monitors") {
|
||||
@@ -369,6 +451,12 @@ Item {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!parsed) {
|
||||
// unwrapJson returned null (niri IPC error)
|
||||
root.finishQuery();
|
||||
return;
|
||||
}
|
||||
|
||||
if (root.queryStage === "outputs") {
|
||||
root.parseOutputs(parsed);
|
||||
root.startStage("workspaces");
|
||||
|
||||
@@ -36,6 +36,9 @@ PanelWindow {
|
||||
property bool seedPending: false
|
||||
property bool animate: false
|
||||
|
||||
// Whether the name field (rename mode) currently has focus.
|
||||
property bool nameFieldActive: false
|
||||
|
||||
function workspaceIndexAt(index: int): int {
|
||||
const list = root.workspaceIndices;
|
||||
if (!list || index < 0 || index >= list.length)
|
||||
@@ -83,6 +86,7 @@ PanelWindow {
|
||||
copy.push(0);
|
||||
copy[root.monitorIndex] = next;
|
||||
root.workspaceIndices = copy;
|
||||
root.syncNameField();
|
||||
}
|
||||
|
||||
function moveMonitor(delta: int): void {
|
||||
@@ -94,6 +98,7 @@ PanelWindow {
|
||||
if (next < 0 || next >= count)
|
||||
return;
|
||||
root.monitorIndex = next;
|
||||
root.syncNameField();
|
||||
}
|
||||
|
||||
function activateAt(monitorAt: int, workspaceAt: int): void {
|
||||
@@ -116,8 +121,55 @@ PanelWindow {
|
||||
root.activateAt(root.monitorIndex, root.workspaceIndexAt(root.monitorIndex));
|
||||
}
|
||||
|
||||
// ── rename bar helpers ──────────────────────────────────────────────
|
||||
|
||||
function selectedWorkspace(): var {
|
||||
const mons = root.compositor.monitors ?? [];
|
||||
if (root.monitorIndex < 0 || root.monitorIndex >= mons.length)
|
||||
return null;
|
||||
const wsList = mons[root.monitorIndex].workspaces ?? [];
|
||||
const idx = root.workspaceIndexAt(root.monitorIndex);
|
||||
if (idx < 0 || idx >= wsList.length)
|
||||
return null;
|
||||
return wsList[idx];
|
||||
}
|
||||
|
||||
function syncNameField(): void {
|
||||
const ws = root.selectedWorkspace();
|
||||
nameInput.text = ws ? ws.name : "";
|
||||
}
|
||||
|
||||
function enterRename(): void {
|
||||
root.nameFieldActive = true;
|
||||
root.syncNameField();
|
||||
nameInput.forceActiveFocus();
|
||||
nameInput.selectAll();
|
||||
}
|
||||
|
||||
function leaveRename(): void {
|
||||
root.nameFieldActive = false;
|
||||
nameInput.focus = false;
|
||||
Qt.callLater(() => focusScope.forceActiveFocus());
|
||||
}
|
||||
|
||||
function isToggleRenameKey(event): bool {
|
||||
const mods = event.modifiers;
|
||||
const ctrl = (mods & Qt.ControlModifier) && !(mods & Qt.AltModifier) && !(mods & Qt.MetaModifier);
|
||||
return event.key === Qt.Key_G && ctrl;
|
||||
}
|
||||
|
||||
function applyRename(): void {
|
||||
const ws = root.selectedWorkspace();
|
||||
if (ws)
|
||||
root.compositor.renameWorkspace(ws.id, ws.idx, nameInput.text);
|
||||
root.leaveRename();
|
||||
}
|
||||
|
||||
// ── visibility handling ─────────────────────────────────────────────
|
||||
|
||||
onVisibleChanged: {
|
||||
root.animate = false;
|
||||
root.nameFieldActive = false;
|
||||
if (!root.visible) {
|
||||
root.seedPending = false;
|
||||
return;
|
||||
@@ -133,30 +185,163 @@ PanelWindow {
|
||||
function onRefreshed(): void {
|
||||
if (!root.visible || !root.seedPending)
|
||||
return;
|
||||
// This read is stale. Keep waiting for the one already queued.
|
||||
if (root.compositor.refreshQueued)
|
||||
return;
|
||||
root.seedPending = false;
|
||||
root.seedSelection();
|
||||
root.syncNameField();
|
||||
}
|
||||
}
|
||||
|
||||
// ── backdrop ────────────────────────────────────────────────────────
|
||||
|
||||
Rectangle {
|
||||
id: backdrop
|
||||
anchors.fill: parent
|
||||
color: root.theme.backdrop
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: root.requestBack()
|
||||
onClicked: {
|
||||
if (root.nameFieldActive)
|
||||
root.leaveRename();
|
||||
else
|
||||
root.requestBack();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ── rename bar (always visible at the top) ──────────────────────────
|
||||
|
||||
Item {
|
||||
id: renameBar
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: 40
|
||||
width: root.theme.barWidth
|
||||
height: root.theme.barHeight
|
||||
z: 10
|
||||
|
||||
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
|
||||
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: nameInput.activeFocus ? root.theme.fieldBorder : root.theme.barBorder
|
||||
border.width: 1
|
||||
|
||||
TextInput {
|
||||
id: nameInput
|
||||
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: false
|
||||
|
||||
onAccepted: root.applyRename()
|
||||
|
||||
// Escape from rename field returns to carousel.
|
||||
Keys.onEscapePressed: event => {
|
||||
root.leaveRename();
|
||||
event.accepted = true;
|
||||
}
|
||||
|
||||
// Ctrl+G toggles back to carousel.
|
||||
Keys.onShortcutOverride: event => {
|
||||
if (root.isToggleRenameKey(event))
|
||||
event.accepted = true;
|
||||
}
|
||||
Keys.onPressed: event => {
|
||||
if (root.isToggleRenameKey(event)) {
|
||||
root.leaveRename();
|
||||
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.applyRename()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ── carousel ────────────────────────────────────────────────────────
|
||||
|
||||
FocusScope {
|
||||
id: focusScope
|
||||
anchors.fill: parent
|
||||
focus: root.visible
|
||||
|
||||
Keys.onPressed: event => {
|
||||
// Ctrl+G toggles to rename mode.
|
||||
if (root.isToggleRenameKey(event)) {
|
||||
root.enterRename();
|
||||
event.accepted = true;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (event.key) {
|
||||
case Qt.Key_Left:
|
||||
root.moveWorkspace(-1);
|
||||
@@ -229,8 +414,6 @@ PanelWindow {
|
||||
required property var modelData
|
||||
required property int index
|
||||
|
||||
// Each row centers its own workspace. Rows are not lined up
|
||||
// in columns across monitors.
|
||||
readonly property int rowIndex: index
|
||||
readonly property int selectedWs: root.workspaceIndexAt(rowIndex)
|
||||
readonly property var workspaces: modelData.workspaces ?? []
|
||||
|
||||
@@ -7,6 +7,7 @@ QtObject {
|
||||
readonly property color labelColor: "#a9b1d6"
|
||||
readonly property color fieldBg: "#332a2e3a"
|
||||
readonly property color fieldBorder: "#7aa2f7"
|
||||
readonly property color cardBg: "#cc1a1e2a"
|
||||
readonly property color buttonBg: "#7aa2f7"
|
||||
readonly property color buttonText: "#0b0e14"
|
||||
|
||||
@@ -23,10 +24,10 @@ QtObject {
|
||||
readonly property real buttonWidth: 86
|
||||
|
||||
// Fullscreen dim behind the workspace carousel.
|
||||
readonly property color backdrop: "#cc0b0e14"
|
||||
readonly property color backdrop: "#0d0b0e14"
|
||||
|
||||
readonly property real cardWidth: 280
|
||||
readonly property real cardHeight: 160
|
||||
readonly property real cardHeight: 220
|
||||
readonly property real cardSpacing: 36
|
||||
readonly property real cardRadius: 16
|
||||
readonly property real monitorLabelSize: 18
|
||||
@@ -35,7 +36,7 @@ QtObject {
|
||||
// One step across a monitor's workspaces, and one step between monitors.
|
||||
// The gap above a card leaves room for that monitor's name.
|
||||
readonly property real carouselStepX: cardWidth + cardSpacing
|
||||
readonly property real carouselStepY: cardHeight + 110
|
||||
readonly property real carouselStepY: cardHeight + 180
|
||||
readonly property real carouselFadeStep: 0.35
|
||||
readonly property real carouselMaxFade: 0.85
|
||||
readonly property real carouselScaleStep: 0.08
|
||||
|
||||
@@ -22,7 +22,7 @@ Rectangle {
|
||||
width: root.theme.cardWidth
|
||||
height: root.theme.cardHeight
|
||||
radius: root.theme.cardRadius
|
||||
color: root.theme.fieldBg
|
||||
color: root.theme.cardBg
|
||||
border.width: root.selected ? 3 : 1
|
||||
border.color: root.selected ? root.theme.fieldBorder : root.theme.barBorder
|
||||
clip: true
|
||||
|
||||
@@ -5,10 +5,7 @@ import Quickshell.Io
|
||||
ShellRoot {
|
||||
id: shell
|
||||
|
||||
// "", "rename", or "goto".
|
||||
property string mode: ""
|
||||
// Set only when Ctrl+G opens the carousel from the rename bar.
|
||||
property bool gotoReturnsToRename: false
|
||||
property bool open: false
|
||||
|
||||
Compositor {
|
||||
id: compositor
|
||||
@@ -23,54 +20,27 @@ ShellRoot {
|
||||
console.warn("workspace-manager: neither niri nor Hyprland was detected");
|
||||
}
|
||||
|
||||
function openGoto(returnToRename: bool): void {
|
||||
shell.gotoReturnsToRename = returnToRename;
|
||||
shell.mode = "goto";
|
||||
}
|
||||
|
||||
function closeAll(): void {
|
||||
shell.mode = "";
|
||||
shell.gotoReturnsToRename = false;
|
||||
shell.open = false;
|
||||
}
|
||||
|
||||
IpcHandler {
|
||||
target: "workspace"
|
||||
|
||||
function toggle(): void {
|
||||
if (shell.mode === "")
|
||||
shell.mode = "rename";
|
||||
else
|
||||
shell.closeAll();
|
||||
shell.open = !shell.open;
|
||||
}
|
||||
|
||||
// "goto" is a reserved word, so the IPC name is goTo.
|
||||
function goTo(): void {
|
||||
if (shell.mode === "goto")
|
||||
shell.closeAll();
|
||||
else
|
||||
shell.openGoto(false);
|
||||
shell.open = true;
|
||||
}
|
||||
}
|
||||
|
||||
RenameBar {
|
||||
shellOpen: shell.mode === "rename"
|
||||
compositor: compositor
|
||||
theme: theme
|
||||
onRequestClose: shell.closeAll()
|
||||
onRequestGoto: shell.openGoto(true)
|
||||
}
|
||||
|
||||
GotoView {
|
||||
shellOpen: shell.mode === "goto"
|
||||
shellOpen: shell.open
|
||||
compositor: compositor
|
||||
theme: theme
|
||||
onRequestClose: shell.closeAll()
|
||||
onRequestBack: {
|
||||
if (shell.gotoReturnsToRename)
|
||||
shell.mode = "rename";
|
||||
else
|
||||
shell.mode = "";
|
||||
shell.gotoReturnsToRename = false;
|
||||
}
|
||||
onRequestBack: shell.closeAll()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user