diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-07-09 11:55:23 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-07-09 11:55:23 +0800 |
| commit | ca9fcf800485ac5dff633275d56f0b33c4670225 (patch) | |
| tree | a354cfeca9c5602e46ab31b3b1983e23dd64fedb | |
| parent | b707a6ee3ebfb5b527af63f0eacfb63ec1a580cb (diff) | |
finished bar
| -rw-r--r-- | bar/Workspace.qml | 59 | ||||
| -rw-r--r-- | services/Hyprland.qml | 19 |
2 files changed, 50 insertions, 28 deletions
diff --git a/bar/Workspace.qml b/bar/Workspace.qml index 2f8d1ea..9c78e30 100644 --- a/bar/Workspace.qml +++ b/bar/Workspace.qml @@ -1,21 +1,56 @@ import "../services" +import "../config" import QtQuick.Layouts import QtQuick import Quickshell Item { - Layout.preferredHeight: 50 - Layout.preferredWidth: parent.width / 3 + Layout.preferredHeight: 50 + Layout.preferredWidth: parent.width / 3 - RowLayout { - anchors.fill: parent - spacing: 0 - Repeater { - model: Hyprland.workspaces + property list<bool> workspaceOccupied: [] - Text { - text: modelData.active ? modelData.name + " (Active)" : modelData.name - } - } - } + function updateWorkspaceOccupied() { + // workspaceOccupied = Array.from({ length: Config.options.bar.workspaces.shown }, (_, i) => { + // return Hyprland.workspaces.values.some(ws => ws.id === workspaceGroup * Config.options.bar.workspaces.shown + i + 1); + // }) + workspaceOccupied = Array.from({ length: Bar.workspaces }, (_, i) => { + return Hyprland.workspaces.values.some(ws => ws.id === (i + 1)); + }); + } + function isActive(index: int): bool { + Hyprland.focusedWorkspace.id.toString() == (index + 1).toString(); + } + function isOccupied(index: int): bool { + return workspaceOccupied[index] === true; + } + + Connections { + target: Hyprland.workspaces + function onValuesChanged() { + updateWorkspaceOccupied(); + } + } + + Component.onCompleted: updateWorkspaceOccupied() + + RowLayout { + anchors.fill: parent + spacing: 0 + Repeater { + model: Bar.workspaces + + Rectangle { + Text { + text: Hyprland.focusedWorkspace.id.toString() == (index + 1).toString() + // text: isActive(index) + } + implicitWidth: 10 + implicitHeight: 10 + opacity: !isOccupied(index) ? 0.2 : 1 + // color: isActive(index) ? "#00ff00" : "#ffffff" + color: "#000000" + } + } + } } diff --git a/services/Hyprland.qml b/services/Hyprland.qml index 84db674..ea07b65 100644 --- a/services/Hyprland.qml +++ b/services/Hyprland.qml @@ -11,28 +11,15 @@ Singleton { readonly property var toplevels: Hyprland.toplevels readonly property var workspaces: Hyprland.workspaces readonly property var monitors: Hyprland.monitors + property var ws: ObjectModel // readonly property HyprlandToplevel activeToplevel: Hyprland.activeToplevel readonly property HyprlandWorkspace focusedWorkspace: Hyprland.focusedWorkspace readonly property HyprlandMonitor focusedMonitor: Hyprland.focusedMonitor - readonly property int activeWs: focusedWorkspace?.id ?? 1 function dispatch(request: string): void { Hyprland.dispatch(request); } - function getAllWorkspaces(): var { - var allWorkspaces = { - values: [], - count: 0 - }; - for (let i = 1; i <= Bar.workspaces; i++) { - if (workspaces[i] === undefined) { - allWorkspaces.values[i] = HyprlandWorkspace; - } - } - return allWorkspaces; - } - Connections { target: Hyprland @@ -44,8 +31,8 @@ Singleton { Hyprland.refreshMonitors(); else if (event.name.includes("workspace")) Hyprland.refreshWorkspaces(); - // else - // Hyprland.refreshToplevels(); + // else + // Hyprland.refreshToplevels(); } } } |
