rename bar module files and qmldir types to *Module
This commit is contained in:
parent
6461b9a943
commit
c3d7fa0bc5
24 changed files with 46 additions and 41 deletions
111
shell/modules/WorkspacesModule.qml
Normal file
111
shell/modules/WorkspacesModule.qml
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import "." as M
|
||||
import "../services" as S
|
||||
|
||||
Row {
|
||||
id: root
|
||||
spacing: 4
|
||||
|
||||
required property var bar
|
||||
|
||||
property var _allWorkspaces: []
|
||||
property int _activeId: -1
|
||||
readonly property string _output: bar.screen?.name ?? ""
|
||||
readonly property var _workspaces: _allWorkspaces.filter(w => w.output === root._output)
|
||||
|
||||
// Initial state
|
||||
Process {
|
||||
id: initProc
|
||||
running: true
|
||||
command: ["niri", "msg", "--json", "workspaces"]
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
try {
|
||||
const ws = JSON.parse(text);
|
||||
root._allWorkspaces = ws.sort((a, b) => a.idx - b.idx);
|
||||
for (const w of ws) {
|
||||
if (w.is_focused)
|
||||
root._activeId = w.id;
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Live updates via shared NiriIpc singleton
|
||||
Connections {
|
||||
target: M.NiriIpc
|
||||
function onWorkspacesChanged(workspaces) {
|
||||
root._allWorkspaces = workspaces.sort((a, b) => a.idx - b.idx);
|
||||
}
|
||||
function onWorkspaceActivated(id, focused) {
|
||||
if (focused)
|
||||
root._activeId = id;
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
id: switchProc
|
||||
property int wsId: -1
|
||||
command: ["niri", "msg", "action", "focus-workspace", String(wsId)]
|
||||
}
|
||||
|
||||
Repeater {
|
||||
model: root._workspaces
|
||||
|
||||
delegate: Rectangle {
|
||||
id: pill
|
||||
|
||||
required property var modelData
|
||||
|
||||
readonly property bool active: modelData.id === root._activeId
|
||||
property bool _hovered: false
|
||||
|
||||
HoverHandler {
|
||||
onHoveredChanged: {
|
||||
pill._hovered = hovered;
|
||||
const name = pill.modelData.name || ("Workspace " + pill.modelData.idx);
|
||||
if (hovered) {
|
||||
M.FlyoutState.text = name;
|
||||
M.FlyoutState.itemX = pill.mapToGlobal(pill.width / 2, 0).x - (QsWindow.window?.screen?.x ?? 0);
|
||||
M.FlyoutState.screen = QsWindow.window?.screen ?? null;
|
||||
M.FlyoutState.accentColor = root.parent?.accentColor ?? S.Theme.base05;
|
||||
M.FlyoutState.visible = true;
|
||||
} else {
|
||||
M.FlyoutState.visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
width: S.Theme.fontSize + 4
|
||||
height: S.Theme.fontSize + 4
|
||||
radius: width / 2
|
||||
color: pill.active ? (root.parent?.accentColor ?? S.Theme.base0D) : (pill._hovered ? S.Theme.base03 : S.Theme.base02)
|
||||
Behavior on color {
|
||||
ColorAnimation {
|
||||
duration: 150
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
text: pill.modelData.idx
|
||||
color: pill.active ? S.Theme.base00 : (root.parent?.accentColor ?? S.Theme.base05)
|
||||
font.pixelSize: S.Theme.fontSize - 2
|
||||
font.family: S.Theme.fontFamily
|
||||
font.bold: pill.active
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: {
|
||||
switchProc.wsId = pill.modelData.id;
|
||||
switchProc.running = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue