From 764f8197fbf47ad9e072f432a81ea594bd19ab25 Mon Sep 17 00:00:00 2001 From: Hannes Date: Tue, 1 Sep 2026 13:52:03 +0200 Subject: [PATCH] feat: refactor bar spacing functions to use dedicated functions --- config/Config.qml | 12 +++++++++--- modules/bar/Bar.qml | 9 +++++---- modules/bar/BarLoader.qml | 6 +++++- modules/bar/widgets/AudioSink.qml | 8 ++++---- modules/bar/widgets/AudioSource.qml | 2 +- modules/bar/widgets/Battery.qml | 6 +++--- modules/bar/widgets/Clock.qml | 4 ++-- modules/bar/widgets/IdleButton.qml | 2 +- modules/bar/widgets/Network.qml | 4 ++-- modules/bar/widgets/PowerButton.qml | 2 +- modules/bar/widgets/Tray.qml | 6 +++--- modules/bar/widgets/WindowInfo.qml | 4 ++-- modules/bar/widgets/Workspaces.qml | 18 +++++++++--------- 13 files changed, 47 insertions(+), 36 deletions(-) diff --git a/config/Config.qml b/config/Config.qml index b40937a..342be08 100644 --- a/config/Config.qml +++ b/config/Config.qml @@ -12,9 +12,13 @@ QtObject { readonly property int small_spacing: 4 readonly property int spacing: 8 - function small_spacing_fun(screenHeight) { return Math.floor(barHeight(screenHeight) / 16) } - function spacing_fun(barH) { return Math.floor(barH / 8) } - function big_spacing_fun(barH) { return Math.floor(barH / 6) } + function bar_small_bar_spacing_fun(barH) { return Math.floor(barHeight(barH) / 16) } + function bar_spacing_fun(barH) { return Math.floor(barH / 8) } + function bar_big_spacing_fun(barH) { return Math.floor(barH / 6) } + + function screen_small_bar_spacing_fun(screenHeight) { return Math.floor((screenHeight / 1080)*2) } + function screen_spacing_fun(screenHeight) { return Math.floor((screenHeight / 1080)*4) } + function screen_big_spacing_fun(screenHeight) { return Math.floor((screenHeight / 1080)*8) } function font_size(spaceHeight) { return Math.floor(spaceHeight * 0.75) } function font_size_small(spaceHeight) { return Math.floor(spaceHeight * 0.625) } @@ -29,6 +33,8 @@ QtObject { readonly property int radius: 16 function small_radius_fun(barHeight) { return Math.floor(barHeight / 8) } function radius_fun(barHeight) { return Math.floor(barHeight / 4) } + function screen_radius_fun(screenHeight) { return Math.floor((screenHeight / 1080)*4) } + function screen_big_radius_fun(screenHeight) { return Math.floor((screenHeight / 1080)*6) } readonly property int big_radius: 10 readonly property int border_width: 2 diff --git a/modules/bar/Bar.qml b/modules/bar/Bar.qml index 858a3af..0aa7e6d 100644 --- a/modules/bar/Bar.qml +++ b/modules/bar/Bar.qml @@ -9,6 +9,7 @@ PanelWindow { id: panel color: "transparent" + visible: Hyprland.monitorFor(screen).activeWorkspace.hasFullscreen anchors.top: true anchors.left: true @@ -40,8 +41,8 @@ PanelWindow { anchors.verticalCenter: parent.verticalCenter anchors.left: parent.left - anchors.leftMargin: Config.big_spacing_fun(height) - spacing: Config.big_spacing_fun(height) + anchors.leftMargin: Config.bar_big_spacing_fun(height) + spacing: Config.bar_big_spacing_fun(height) MenuButton {} @@ -57,7 +58,7 @@ PanelWindow { Row { // bar widgets center id: widgetsCenter anchors.centerIn: parent - spacing: Config.big_spacing_fun(height) + spacing: Config.bar_big_spacing_fun(height) Clock {} @@ -69,7 +70,7 @@ PanelWindow { anchors.verticalCenter: parent.verticalCenter anchors.right: parent.right anchors.rightMargin: 0 - spacing: Config.big_spacing_fun(height) + spacing: Config.bar_big_spacing_fun(height) // TODO: Add bluetooth, network, audio, power, maybe HW monitor Tray{} diff --git a/modules/bar/BarLoader.qml b/modules/bar/BarLoader.qml index 9ccc5ed..dd7a6a3 100644 --- a/modules/bar/BarLoader.qml +++ b/modules/bar/BarLoader.qml @@ -1,5 +1,6 @@ import QtQuick import Quickshell +import Quickshell.Hyprland Item { @@ -8,7 +9,10 @@ Item { model: Quickshell.screens delegate: Loader { active: true // loads object - sourceComponent: Bar {screen: modelData} // creates instance of bar component + sourceComponent: Bar { + screen: modelData + visible: !Hyprland.monitorFor(modelData).activeWorkspace.hasFullscreen + } // creates instance of bar component } } } \ No newline at end of file diff --git a/modules/bar/widgets/AudioSink.qml b/modules/bar/widgets/AudioSink.qml index 6809cf2..b303267 100644 --- a/modules/bar/widgets/AudioSink.qml +++ b/modules/bar/widgets/AudioSink.qml @@ -6,7 +6,7 @@ import Quickshell.Hyprland MouseArea { id: audioButton - width: Math.max(audioRow.width + Config.spacing_fun(height)*3.5, height) + width: Math.max(audioRow.width + Config.bar_spacing_fun(height)*3.5, height) height: bar.height hoverEnabled: true cursorShape: Qt.PointingHandCursor @@ -22,9 +22,9 @@ MouseArea { Row { id: audioRow - width: audioSourceText.width + audioSinkText.width + audioPercentageText.width + Config.spacing_fun(height)*2 + width: audioSourceText.width + audioSinkText.width + audioPercentageText.width + Config.bar_spacing_fun(height)*2 height: parent.height - spacing: Config.spacing_fun(height)/2 + spacing: Config.bar_spacing_fun(height)/2 anchors.centerIn: parent Text { @@ -35,7 +35,7 @@ MouseArea { font.pixelSize: Config.iconSize(bar.height) font.family: Config.font color: audioButton.containsMouse ? Colors.tertiary_fg : Colors.primary - rightPadding: Config.spacing_fun(height)*1.5 + rightPadding: Config.bar_spacing_fun(height)*1.5 } Text { diff --git a/modules/bar/widgets/AudioSource.qml b/modules/bar/widgets/AudioSource.qml index 4e5ef17..eea75e6 100644 --- a/modules/bar/widgets/AudioSource.qml +++ b/modules/bar/widgets/AudioSource.qml @@ -5,7 +5,7 @@ import "../states/Audio" MouseArea { id: audioButton - width: Math.max(audioText.width + Config.spacing_fun(height)*2, height) + width: Math.max(audioText.width + Config.bar_spacing_fun(height)*2, height) height: bar.height hoverEnabled: true cursorShape: Qt.PointingHandCursor diff --git a/modules/bar/widgets/Battery.qml b/modules/bar/widgets/Battery.qml index 9cf6af4..244bf48 100644 --- a/modules/bar/widgets/Battery.qml +++ b/modules/bar/widgets/Battery.qml @@ -6,7 +6,7 @@ import "../states/Battery" MouseArea { id: batteryButton - width: expanded ? Math.max(expandedRow.width + Config.spacing_fun(height)*3, bar.height) : Math.max(batteryText.width + Config.spacing_fun(height)*2, bar.height) + width: expanded ? Math.max(expandedRow.width + Config.bar_spacing_fun(height)*3, bar.height) : Math.max(batteryText.width + Config.bar_spacing_fun(height)*2, bar.height) height: bar.height hoverEnabled: true cursorShape: Qt.PointingHandCursor @@ -63,7 +63,7 @@ MouseArea { id: expandedRow visible: expanded anchors.centerIn: parent - spacing: Config.spacing_fun(batteryButton.height) + spacing: Config.bar_spacing_fun(batteryButton.height) Text { id: batteryPercentageSymbol @@ -121,7 +121,7 @@ MouseArea { id: batteryPopup anchorItem: batteryButton anchorHovered: batteryButton.containsMouse - spacingValue: Config.spacing_fun(batteryButton.height) + spacingValue: Config.bar_spacing_fun(batteryButton.height) radiusValue: Config.radius_fun(batteryButton.height) Column { diff --git a/modules/bar/widgets/Clock.qml b/modules/bar/widgets/Clock.qml index 9837d9a..1df1dac 100644 --- a/modules/bar/widgets/Clock.qml +++ b/modules/bar/widgets/Clock.qml @@ -6,7 +6,7 @@ import "../states/Clock" Rectangle { //workspace id: clockRect - width: ClockState.expanded ? Math.max(dateText.width + timeText.width + Config.spacing_fun(height)*3, bar.height) : Math.max(timeText.width + Config.spacing_fun(height)*2, bar.height) + width: ClockState.expanded ? Math.max(dateText.width + timeText.width + Config.bar_spacing_fun(height)*3, bar.height) : Math.max(timeText.width + Config.bar_spacing_fun(height)*2, bar.height) height: bar.height radius: Config.radius_fun(height) color: clockArea.containsMouse ? Colors.tertiaryContainer : Colors.primaryContainer @@ -61,7 +61,7 @@ Rectangle { //workspace id: clockPopup anchorItem: clockRect anchorHovered: clockArea.containsMouse - spacingValue: Config.spacing_fun(clockRect.height) + spacingValue: Config.bar_spacing_fun(clockRect.height) radiusValue: Config.radius_fun(clockRect.height) Column { diff --git a/modules/bar/widgets/IdleButton.qml b/modules/bar/widgets/IdleButton.qml index 95e8236..e118f99 100644 --- a/modules/bar/widgets/IdleButton.qml +++ b/modules/bar/widgets/IdleButton.qml @@ -7,7 +7,7 @@ import "../states/Idle" MouseArea { id: idleButton - width: Math.max(idleText.width + Config.spacing_fun(height)*2, height) + width: Math.max(idleText.width + Config.bar_spacing_fun(height)*2, height) height: bar.height hoverEnabled: true cursorShape: Qt.PointingHandCursor diff --git a/modules/bar/widgets/Network.qml b/modules/bar/widgets/Network.qml index c8ae6f7..a8717ce 100644 --- a/modules/bar/widgets/Network.qml +++ b/modules/bar/widgets/Network.qml @@ -5,7 +5,7 @@ import "../states/Network" MouseArea { id: networkButton - width: Math.max(networkText.width + Config.spacing_fun(height)*2, height) + width: Math.max(networkText.width + Config.bar_spacing_fun(height)*2, height) height: bar.height hoverEnabled: true cursorShape: Qt.PointingHandCursor @@ -37,7 +37,7 @@ MouseArea { id: clockPopup anchorItem: networkButton anchorHovered: networkButton.containsMouse - spacingValue: Config.spacing_fun(networkButton.height) + spacingValue: Config.bar_spacing_fun(networkButton.height) radiusValue: Config.radius_fun(networkButton.height) Column { diff --git a/modules/bar/widgets/PowerButton.qml b/modules/bar/widgets/PowerButton.qml index b486c49..d95a24e 100644 --- a/modules/bar/widgets/PowerButton.qml +++ b/modules/bar/widgets/PowerButton.qml @@ -4,7 +4,7 @@ import "../../../config" MouseArea { id: powerButton - width: Math.max(powerText.width + Config.spacing_fun(height), height) + width: Math.max(powerText.width + Config.bar_spacing_fun(height), height) height: bar.height hoverEnabled: true cursorShape: Qt.PointingHandCursor diff --git a/modules/bar/widgets/Tray.qml b/modules/bar/widgets/Tray.qml index 2287aef..e9016b8 100644 --- a/modules/bar/widgets/Tray.qml +++ b/modules/bar/widgets/Tray.qml @@ -7,7 +7,7 @@ import "../../../config" Row { // Workspace Row id: trayRow - spacing: Config.small_spacing_fun(height) + spacing: Config.bar_small_bar_spacing_fun(height) Repeater { model: SystemTray.items @@ -19,8 +19,8 @@ Row { // Workspace Row Rectangle { //trayItem id: trayItem - width: iconImage.width + Config.spacing_fun(bar.height) - height: iconImage.height + Config.spacing_fun(bar.height) + width: iconImage.width + Config.bar_spacing_fun(bar.height) + height: iconImage.height + Config.bar_spacing_fun(bar.height) radius: Config.radius_fun(trayRow.height) color: trayArea.containsMouse ? Colors.tertiaryContainer : modelData.active ? Colors.primaryContainer diff --git a/modules/bar/widgets/WindowInfo.qml b/modules/bar/widgets/WindowInfo.qml index 1d95e38..94e3981 100644 --- a/modules/bar/widgets/WindowInfo.qml +++ b/modules/bar/widgets/WindowInfo.qml @@ -7,7 +7,7 @@ import "../states/Apps" Item { id: root - property real pad: Config.spacing_fun(bar.height) * 1.5 + property real pad: Config.bar_spacing_fun(bar.height) * 1.5 anchors.verticalCenter: parent.verticalCenter @@ -39,7 +39,7 @@ Item { Row { id: contentRow - spacing: Config.spacing_fun(bar.height) * 1.25 + spacing: Config.bar_spacing_fun(bar.height) * 1.25 anchors.centerIn: parent Text { diff --git a/modules/bar/widgets/Workspaces.qml b/modules/bar/widgets/Workspaces.qml index 80625fc..e4e4e98 100644 --- a/modules/bar/widgets/Workspaces.qml +++ b/modules/bar/widgets/Workspaces.qml @@ -8,8 +8,8 @@ Rectangle { id: workspacesContainer required property HyprlandMonitor thisMonitor - height: bar.height - (Config.spacing_fun(bar.height) * 1.5) - width: workspacesRow.width + (Config.spacing_fun(bar.height) * 2) + height: bar.height - (Config.bar_spacing_fun(bar.height) * 1.5) + width: workspacesRow.width + (Config.bar_spacing_fun(bar.height) * 2) radius: height / 2 @@ -20,7 +20,7 @@ Rectangle { Row { id: workspacesRow anchors.centerIn: parent - spacing: Config.spacing_fun(bar.height) / 2 + spacing: Config.bar_spacing_fun(bar.height) / 2 Repeater { model: Hyprland.workspaces @@ -30,9 +30,9 @@ Rectangle { id: wsItem property var workspaceData: modelData - width: Math.max(40, wsIconsRow.width==0 ? wsNum.width + 2*Config.spacing_fun(bar.height) : wsNum.width + wsIconsRow.width + 3*Config.spacing_fun(bar.height)+Config.spacing_fun(bar.height)) + width: Math.max(40, wsIconsRow.width==0 ? wsNum.width + 2*Config.bar_spacing_fun(bar.height) : wsNum.width + wsIconsRow.width + 3*Config.bar_spacing_fun(bar.height)+Config.bar_spacing_fun(bar.height)) // width: { - // var spacing = Config.spacing_fun(bar.height) + // var spacing = Config.bar_spacing_fun(bar.height) // var cw = wsNum.width // if (wsIconsRow.children.length > 0) { // cw += spacing + wsIconsRow.width + spacing @@ -47,7 +47,7 @@ Rectangle { Rectangle { anchors.centerIn: parent width: parent.width - height: parent.height - (Config.spacing_fun(bar.height) * 1.5) + height: parent.height - (Config.bar_spacing_fun(bar.height) * 1.5) radius: height / 2 @@ -79,9 +79,9 @@ Rectangle { Row { anchors.left: parent.left - anchors.leftMargin: wsIconsRow.width==0 ? (wsItem.width-wsNum.width)/2 : (wsItem.width-wsNum.width-wsIconsRow.width-Config.spacing_fun(bar.height))/2 + anchors.leftMargin: wsIconsRow.width==0 ? (wsItem.width-wsNum.width)/2 : (wsItem.width-wsNum.width-wsIconsRow.width-Config.bar_spacing_fun(bar.height))/2 anchors.verticalCenter: parent.verticalCenter - spacing: Config.spacing_fun(bar.height) + spacing: Config.bar_spacing_fun(bar.height) Text { id: wsNum @@ -97,7 +97,7 @@ Rectangle { Row { id: wsIconsRow - spacing: Config.spacing_fun(workspacesContainer.height) + spacing: Config.bar_spacing_fun(workspacesContainer.height) anchors.verticalCenter: parent.verticalCenter Repeater {