From ca9fcf800485ac5dff633275d56f0b33c4670225 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Wed, 9 Jul 2025 11:55:23 +0800 Subject: finished bar --- bar/Workspace.qml | 59 ++++++++++++++++++++++++++++++++++++++++----------- 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 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(); } } } -- cgit v1.2.3