bar: workspaces: no more Layout

This commit is contained in:
end-4
2025-09-28 14:25:52 +02:00
parent 410971a228
commit d24555a4d7
@@ -5,7 +5,6 @@ import qs.modules.common.widgets
import qs.modules.common.functions import qs.modules.common.functions
import QtQuick import QtQuick
import QtQuick.Controls import QtQuick.Controls
import QtQuick.Layouts
import Quickshell import Quickshell
import Quickshell.Wayland import Quickshell.Wayland
import Quickshell.Hyprland import Quickshell.Hyprland
@@ -19,7 +18,8 @@ Item {
readonly property HyprlandMonitor monitor: Hyprland.monitorFor(root.QsWindow.window?.screen) readonly property HyprlandMonitor monitor: Hyprland.monitorFor(root.QsWindow.window?.screen)
readonly property Toplevel activeWindow: ToplevelManager.activeToplevel readonly property Toplevel activeWindow: ToplevelManager.activeToplevel
readonly property int workspaceGroup: Math.floor((monitor?.activeWorkspace?.id - 1) / Config.options.bar.workspaces.shown) readonly property int workspacesShown: Config.options.bar.workspaces.shown
readonly property int workspaceGroup: Math.floor((monitor?.activeWorkspace?.id - 1) / root.workspacesShown)
property list<bool> workspaceOccupied: [] property list<bool> workspaceOccupied: []
property int widgetPadding: 4 property int widgetPadding: 4
property int workspaceButtonWidth: 26 property int workspaceButtonWidth: 26
@@ -28,7 +28,7 @@ Item {
property real workspaceIconSizeShrinked: workspaceButtonWidth * 0.55 property real workspaceIconSizeShrinked: workspaceButtonWidth * 0.55
property real workspaceIconOpacityShrinked: 1 property real workspaceIconOpacityShrinked: 1
property real workspaceIconMarginShrinked: -4 property real workspaceIconMarginShrinked: -4
property int workspaceIndexInGroup: (monitor?.activeWorkspace?.id - 1) % Config.options.bar.workspaces.shown property int workspaceIndexInGroup: (monitor?.activeWorkspace?.id - 1) % root.workspacesShown
property bool showNumbers: false property bool showNumbers: false
Timer { Timer {
@@ -56,8 +56,8 @@ Item {
// Function to update workspaceOccupied // Function to update workspaceOccupied
function updateWorkspaceOccupied() { function updateWorkspaceOccupied() {
workspaceOccupied = Array.from({ length: Config.options.bar.workspaces.shown }, (_, i) => { workspaceOccupied = Array.from({ length: root.workspacesShown }, (_, i) => {
return Hyprland.workspaces.values.some(ws => ws.id === workspaceGroup * Config.options.bar.workspaces.shown + i + 1); return Hyprland.workspaces.values.some(ws => ws.id === workspaceGroup * root.workspacesShown + i + 1);
}) })
} }
@@ -79,8 +79,8 @@ Item {
updateWorkspaceOccupied(); updateWorkspaceOccupied();
} }
implicitWidth: root.vertical ? Appearance.sizes.verticalBarWidth : backgroundLayout.implicitWidth implicitWidth: root.vertical ? Appearance.sizes.verticalBarWidth : (root.workspaceButtonWidth * root.workspacesShown)
implicitHeight: root.vertical ? backgroundLayout.implicitHeight : Appearance.sizes.barHeight implicitHeight: root.vertical ? (root.workspaceButtonWidth * root.workspacesShown) : Appearance.sizes.barHeight
// Scroll to switch workspaces // Scroll to switch workspaces
WheelHandler { WheelHandler {
@@ -104,24 +104,20 @@ Item {
} }
// Workspaces - background // Workspaces - background
GridLayout { Grid {
id: backgroundLayout
z: 1 z: 1
anchors.fill: parent anchors.centerIn: parent
implicitHeight: root.vertical ? root.workspaceButtonWidth : Appearance.sizes.barHeight
implicitWidth: root.vertical ? Appearance.sizes.verticalBarWidth : root.workspaceButtonWidth
rowSpacing: 0 rowSpacing: 0
columnSpacing: 0 columnSpacing: 0
columns: root.vertical ? 1 : -1 columns: root.vertical ? 1 : root.workspacesShown
rows: root.vertical ? root.workspacesShown : 1
Repeater { Repeater {
model: Config.options.bar.workspaces.shown model: root.workspacesShown
Rectangle { Rectangle {
z: 1 z: 1
Layout.alignment: root.vertical ? Qt.AlignHCenter : Qt.AlignVCenter
implicitWidth: workspaceButtonWidth implicitWidth: workspaceButtonWidth
implicitHeight: workspaceButtonWidth implicitHeight: workspaceButtonWidth
radius: (width / 2) radius: (width / 2)
@@ -195,26 +191,24 @@ Item {
} }
// Workspaces - numbers // Workspaces - numbers
GridLayout { Grid {
id: rowLayoutNumbers
z: 3 z: 3
columns: vertical ? 1 : -1 columns: root.vertical ? 1 : root.workspacesShown
rows: root.vertical ? root.workspacesShown : 1
columnSpacing: 0 columnSpacing: 0
rowSpacing: 0 rowSpacing: 0
anchors.fill: parent anchors.fill: parent
implicitHeight: vertical ? Appearance.sizes.verticalBarWidth : Appearance.sizes.barHeight
implicitWidth: vertical ? Appearance.sizes.verticalBarWidth : Appearance.sizes.verticalBarWidth
Repeater { Repeater {
model: Config.options.bar.workspaces.shown model: root.workspacesShown
Button { Button {
id: button id: button
property int workspaceValue: workspaceGroup * Config.options.bar.workspaces.shown + index + 1 property int workspaceValue: workspaceGroup * root.workspacesShown + index + 1
Layout.fillHeight: !root.vertical implicitHeight: vertical ? Appearance.sizes.verticalBarWidth : Appearance.sizes.barHeight
Layout.fillWidth: root.vertical implicitWidth: vertical ? Appearance.sizes.verticalBarWidth : Appearance.sizes.verticalBarWidth
onPressed: Hyprland.dispatch(`workspace ${workspaceValue}`) onPressed: Hyprland.dispatch(`workspace ${workspaceValue}`)
width: vertical ? undefined : workspaceButtonWidth width: vertical ? undefined : workspaceButtonWidth
height: vertical ? workspaceButtonWidth : undefined height: vertical ? workspaceButtonWidth : undefined