forked from Shinonome/dots-hyprland
hefty: bar: workspace widget
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import QtQuick
|
||||
import Quickshell.Wayland
|
||||
import Quickshell.Hyprland
|
||||
import qs.services
|
||||
import qs.modules.common as C
|
||||
|
||||
NestableObject {
|
||||
id: root
|
||||
|
||||
required property HyprlandMonitor monitor
|
||||
readonly property Toplevel activeWindow: ToplevelManager.activeToplevel
|
||||
readonly property int activeWorkspace: monitor?.activeWorkspace?.id
|
||||
readonly property bool currentWorkspaceNotFake: activeWindow?.activated ?? false // Active empty workspace = fake. At least, that's how I like to call it.
|
||||
readonly property int fakeWorkspace: currentWorkspaceNotFake ? -9999 : activeWorkspace
|
||||
readonly property int shownCount: C.Config.options.bar.workspaces.shown
|
||||
readonly property int group: Math.floor((activeWorkspace - 1) / shownCount)
|
||||
|
||||
property list<bool> occupied: []
|
||||
property list<var> biggestWindow: occupied.map((_, index) => {
|
||||
const wsId = getWorkspaceIdAt(index);
|
||||
var biggestWindow = HyprlandData.biggestWindowForWorkspace(wsId);
|
||||
return biggestWindow;
|
||||
})
|
||||
|
||||
function getWorkspaceId(group, index) {
|
||||
return group * root.shownCount + index + 1;
|
||||
}
|
||||
function getWorkspaceIdAt(index) {
|
||||
return root.getWorkspaceId(root.group, index);
|
||||
}
|
||||
|
||||
// Function to update workspaceOccupied
|
||||
function updateWorkspaceOccupied() {
|
||||
root.occupied = Array.from({
|
||||
length: root.shownCount
|
||||
}, (_, i) => {
|
||||
const thisWorkspaceId = getWorkspaceId(root.group, i);
|
||||
return Hyprland.workspaces.values.some(ws => ws.id === thisWorkspaceId);
|
||||
});
|
||||
}
|
||||
|
||||
// Occupied workspace updates
|
||||
Component.onCompleted: updateWorkspaceOccupied()
|
||||
Connections {
|
||||
target: Hyprland.workspaces
|
||||
function onValuesChanged() {
|
||||
root.updateWorkspaceOccupied();
|
||||
}
|
||||
}
|
||||
Connections {
|
||||
target: Hyprland
|
||||
function onFocusedWorkspaceChanged() {
|
||||
root.updateWorkspaceOccupied();
|
||||
}
|
||||
}
|
||||
onGroupChanged: {
|
||||
updateWorkspaceOccupied();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user