refactor: workspaces use inner bar height

Also simplify boxpadding
This commit is contained in:
2 * r + 2 * t 2025-04-29 12:07:44 +10:00
parent 398c508f99
commit 82139e9c2d
5 changed files with 24 additions and 115 deletions

View file

@ -11,6 +11,7 @@ Singleton {
component Sizes: QtObject {
readonly property int height: 50
readonly property int innerHeight: 30
readonly property int floatingGap: 10
readonly property int floatingGapLarge: 15
}

View file

@ -1,9 +1,7 @@
import "root:/widgets"
import "root:/services"
import "root:/config"
import QtQuick
import QtQuick.Layouts
import Qt5Compat.GraphicalEffects
BoxLayout {
id: root
@ -33,8 +31,8 @@ BoxLayout {
bottomRightRadius: roundRight
// Ugh stupid size errors on reload
Layout.preferredWidth: root.vertical ? layout.width : root.workspaces[index]?.width ?? 1
Layout.preferredHeight: root.vertical ? root.workspaces[index]?.height ?? 1 : layout.height
Layout.preferredWidth: root.vertical ? BarConfig.sizes.innerHeight : root.workspaces[index]?.width ?? 1
Layout.preferredHeight: root.vertical ? root.workspaces[index]?.height ?? 1 : BarConfig.sizes.innerHeight
Behavior on opacity {
NumberAnimation {

View file

@ -7,12 +7,12 @@ StyledText {
required property int index
required property BoxLayout layout
required property var occupied
readonly property bool isWorkspace: true
readonly property bool isWorkspace: true // Flag for finding workspace children
text: index + 1
color: BarConfig.workspaces.occupiedBg || occupied[index + 1] ? Appearance.colours.text : Appearance.colours.subtext0
horizontalAlignment: StyledText.AlignHCenter
Layout.preferredWidth: layout.homogenous && !layout.vertical ? layout.height : -1
Layout.preferredHeight: layout.homogenous && layout.vertical ? layout.width : -1
Layout.preferredWidth: layout.homogenous && !layout.vertical ? BarConfig.sizes.innerHeight : -1
Layout.preferredHeight: layout.homogenous && layout.vertical ? BarConfig.sizes.innerHeight : -1
}

View file

@ -28,8 +28,7 @@ Item {
BoxLayout {
id: layout
padding: vertical ? [0, Appearance.padding.smaller / 2] : [Appearance.padding.smaller / 2, 0]
anchors.centerIn: parent
anchors.fill: parent
homogenous: true
spacing: 0
@ -72,8 +71,8 @@ Item {
Rectangle {
id: active
property int currentIdx: 0
property int lastIdx: 0
property int currentIdx: (Hyprland.activeWorkspace?.id ?? 1) - 1
property int lastIdx: currentIdx
property real leading: root.workspaces[currentIdx][root.vertical ? "y" : "x"]
property real trailing: root.workspaces[lastIdx][root.vertical ? "y" : "x"]
property real currentSize: root.workspaces[currentIdx][root.vertical ? "height" : "width"]
@ -83,19 +82,13 @@ Item {
clip: true
x: root.vertical ? 0 : offset
y: root.vertical ? offset : 0
width: root.vertical ? layout.width : size
height: root.vertical ? size : layout.height
width: root.vertical ? BarConfig.sizes.innerHeight : size
height: root.vertical ? size : BarConfig.sizes.innerHeight
color: Appearance.colours.mauve
radius: Appearance.rounding.full
Connections {
target: Hyprland
function onActiveWorkspaceChanged() {
active.currentIdx = (Hyprland.activeWorkspace?.id ?? 1) - 1;
active.lastIdx = active.currentIdx;
}
}
anchors.horizontalCenter: root.vertical ? parent.horizontalCenter : undefined
anchors.verticalCenter: root.vertical ? undefined : parent.verticalCenter
Rectangle {
id: base
@ -113,6 +106,9 @@ Item {
y: root.vertical ? -parent.offset : 0
width: root.width
height: root.height
anchors.horizontalCenter: root.vertical ? parent.horizontalCenter : undefined
anchors.verticalCenter: root.vertical ? undefined : parent.verticalCenter
}
Behavior on leading {

View file

@ -1,102 +1,16 @@
import "root:/config"
import QtQuick
import QtQuick.Layouts
Rectangle {
id: root
default property alias children: layout.children
readonly property alias visibleChildren: layout.visibleChildren
GridLayout {
property bool vertical: false
property bool homogenous: false
property bool animated: false
property int spacing: Appearance.spacing.small
property var padding: 0
readonly property int paddingTop: getRealPadding().top
readonly property int paddingRight: getRealPadding().right
readonly property int paddingBottom: getRealPadding().bottom
readonly property int paddingLeft: getRealPadding().left
readonly property int paddingX: getRealPadding().x
readonly property int paddingY: getRealPadding().y
function getRealPadding() {
const pad = {};
if (Array.isArray(padding)) {
if (padding.length === 2) {
pad.top = pad.bottom = padding[0];
pad.left = pad.right = padding[1];
} else if (padding.length === 3) {
pad.top = padding[0];
pad.left = pad.right = padding[1];
pad.bottom = padding[2];
} else if (padding.length === 4) {
pad.top = padding[0];
pad.right = padding[1];
pad.bottom = padding[2];
pad.left = padding[3];
}
} else {
pad.top = pad.bottom = pad.left = pad.right = padding;
}
pad.x = pad.left + pad.right;
pad.y = pad.top + pad.bottom;
return pad;
}
function childAt(x: real, y: real): Item {
return layout.childAt(x, y);
}
color: "transparent"
implicitWidth: layout.implicitWidth + paddingX
implicitHeight: layout.implicitHeight + paddingY
GridLayout {
id: layout
x: root.paddingLeft
y: root.paddingTop
flow: root.vertical ? GridLayout.TopToBottom : GridLayout.LeftToRight
uniformCellWidths: root.homogenous || root.vertical
uniformCellHeights: root.homogenous || !root.vertical
rows: root.vertical ? -1 : 1
columns: root.vertical ? 1 : -1
rowSpacing: root.spacing
columnSpacing: root.spacing
}
Behavior on color {
ColorAnimation {
duration: Appearance.anim.durations.normal
easing.type: Easing.BezierSpline
easing.bezierCurve: Appearance.anim.curves.standard
}
}
Behavior on implicitWidth {
enabled: root.animated
NumberAnimation {
duration: Appearance.anim.durations.normal
easing.type: Easing.BezierSpline
easing.bezierCurve: Appearance.anim.curves.emphasized
}
}
Behavior on implicitHeight {
enabled: root.animated
NumberAnimation {
duration: Appearance.anim.durations.normal
easing.type: Easing.BezierSpline
easing.bezierCurve: Appearance.anim.curves.emphasized
}
}
flow: vertical ? GridLayout.TopToBottom : GridLayout.LeftToRight
uniformCellWidths: homogenous || vertical
uniformCellHeights: homogenous || !vertical
rows: vertical ? -1 : 1
columns: vertical ? 1 : -1
rowSpacing: spacing
columnSpacing: spacing
}