From f806e2c22cef5cd4e1798ae86ae66b59f9c1edf9 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Fri, 8 Aug 2025 19:54:10 +0700 Subject: [PATCH] bar: add auto hide --- .config/quickshell/ii/GlobalStates.qml | 9 +- .config/quickshell/ii/modules/bar/Bar.qml | 176 ++++++++++-------- .../quickshell/ii/modules/common/Config.qml | 5 + 3 files changed, 113 insertions(+), 77 deletions(-) diff --git a/.config/quickshell/ii/GlobalStates.qml b/.config/quickshell/ii/GlobalStates.qml index b3a124eb..aa4db9b0 100644 --- a/.config/quickshell/ii/GlobalStates.qml +++ b/.config/quickshell/ii/GlobalStates.qml @@ -17,11 +17,12 @@ Singleton { property bool osdVolumeOpen: false property bool oskOpen: false property bool overviewOpen: false - property bool sessionOpen: false - property bool workspaceShowNumbers: false - property bool superReleaseMightTrigger: true property bool screenLocked: false property bool screenLockContainsCharacters: false + property bool sessionOpen: false + property bool superDown: false + property bool superReleaseMightTrigger: true + property bool workspaceShowNumbers: false property real screenZoom: 1 onScreenZoomChanged: { @@ -51,9 +52,11 @@ Singleton { description: "Hold to show workspace numbers, release to show icons" onPressed: { + root.superDown = true workspaceShowNumbersTimer.start() } onReleased: { + root.superDown = false workspaceShowNumbersTimer.stop() workspaceShowNumbers = false } diff --git a/.config/quickshell/ii/modules/bar/Bar.qml b/.config/quickshell/ii/modules/bar/Bar.qml index c08133ad..1c2d66a4 100644 --- a/.config/quickshell/ii/modules/bar/Bar.qml +++ b/.config/quickshell/ii/modules/bar/Bar.qml @@ -39,8 +39,10 @@ Scope { property real useShortenedForm: (Appearance.sizes.barHellaShortenScreenWidthThreshold >= screen.width) ? 2 : (Appearance.sizes.barShortenScreenWidthThreshold >= screen.width) ? 1 : 0 readonly property int centerSideModuleWidth: (useShortenedForm == 2) ? Appearance.sizes.barCenterSideModuleWidthHellaShortened : (useShortenedForm == 1) ? Appearance.sizes.barCenterSideModuleWidthShortened : Appearance.sizes.barCenterSideModuleWidth + property bool mustShow: hoverRegion.containsMouse || (Config?.options.bar.autoHide.showWhenPressingSuper && GlobalStates.superDown) exclusionMode: ExclusionMode.Ignore - exclusiveZone: Appearance.sizes.baseBarHeight + (Config.options.bar.cornerStyle === 1 ? Appearance.sizes.hyprlandGapsOut : 0) + exclusiveZone: (Config?.options.bar.autoHide.enabled && (!mustShow || !Config?.options.bar.autoHide.pushWindows)) ? 0 : + Appearance.sizes.baseBarHeight + (Config.options.bar.cornerStyle === 1 ? Appearance.sizes.hyprlandGapsOut : 0) WlrLayershell.namespace: "quickshell:bar" implicitHeight: Appearance.sizes.barHeight + Appearance.rounding.screenRounding mask: Region { @@ -55,90 +57,116 @@ Scope { right: true } - BarContent { - id: barContent - - anchors { - right: parent.right - left: parent.left - top: parent.top - bottom: undefined - } - implicitHeight: Appearance.sizes.barHeight + MouseArea { + id: hoverRegion + hoverEnabled: true + anchors.fill: parent - states: State { - name: "bottom" - when: Config.options.bar.bottom - AnchorChanges { - target: barContent - anchors { - right: parent.right - left: parent.left - top: undefined - bottom: parent.bottom + BarContent { + id: barContent + + implicitHeight: Appearance.sizes.barHeight + anchors { + right: parent.right + left: parent.left + top: parent.top + bottom: undefined + topMargin: (Config?.options.bar.autoHide.enabled && !mustShow) ? -Appearance.sizes.barHeight + 1 : 0 + bottomMargin: 0 + } + Behavior on anchors.topMargin { + animation: Appearance.animation.elementMoveFast.numberAnimation.createObject(this) + } + Behavior on anchors.bottomMargin { + animation: Appearance.animation.elementMoveFast.numberAnimation.createObject(this) + } + + states: State { + name: "bottom" + when: Config.options.bar.bottom + AnchorChanges { + target: barContent + anchors { + right: parent.right + left: parent.left + top: undefined + bottom: parent.bottom + } + } + PropertyChanges { + target: barContent + anchors.topMargin: 0 + anchors.bottomMargin: (Config?.options.bar.autoHide.enabled && !mustShow) ? -Appearance.sizes.barHeight + 1 : 0 } } } - } - // Round decorators - Loader { - id: roundDecorators - anchors { - left: parent.left - right: parent.right - } - y: Appearance.sizes.barHeight - width: parent.width - height: Appearance.rounding.screenRounding - active: showBarBackground && Config.options.bar.cornerStyle === 0 // Hug - - states: State { - name: "bottom" - when: Config.options.bar.bottom - PropertyChanges { - roundDecorators.y: 0 + // Round decorators + Loader { + id: roundDecorators + anchors { + left: parent.left + right: parent.right + top: barContent.bottom + bottom: undefined } - } + width: parent.width + height: Appearance.rounding.screenRounding + active: showBarBackground && Config.options.bar.cornerStyle === 0 // Hug - sourceComponent: Item { - implicitHeight: Appearance.rounding.screenRounding - RoundCorner { - id: leftCorner - anchors { - top: parent.top - bottom: parent.bottom - left: parent.left - } - - implicitSize: Appearance.rounding.screenRounding - color: showBarBackground ? Appearance.colors.colLayer0 : "transparent" - - corner: RoundCorner.CornerEnum.TopLeft - states: State { - name: "bottom" - when: Config.options.bar.bottom - PropertyChanges { - leftCorner.corner: RoundCorner.CornerEnum.BottomLeft + states: State { + name: "bottom" + when: Config.options.bar.bottom + AnchorChanges { + target: roundDecorators + anchors { + right: parent.right + left: parent.left + top: undefined + bottom: barContent.top } } } - RoundCorner { - id: rightCorner - anchors { - right: parent.right - top: !Config.options.bar.bottom ? parent.top : undefined - bottom: Config.options.bar.bottom ? parent.bottom : undefined - } - implicitSize: Appearance.rounding.screenRounding - color: showBarBackground ? Appearance.colors.colLayer0 : "transparent" - corner: RoundCorner.CornerEnum.TopRight - states: State { - name: "bottom" - when: Config.options.bar.bottom - PropertyChanges { - rightCorner.corner: RoundCorner.CornerEnum.BottomRight + sourceComponent: Item { + implicitHeight: Appearance.rounding.screenRounding + RoundCorner { + id: leftCorner + anchors { + top: parent.top + bottom: parent.bottom + left: parent.left + } + + implicitSize: Appearance.rounding.screenRounding + color: showBarBackground ? Appearance.colors.colLayer0 : "transparent" + + corner: RoundCorner.CornerEnum.TopLeft + states: State { + name: "bottom" + when: Config.options.bar.bottom + PropertyChanges { + leftCorner.corner: RoundCorner.CornerEnum.BottomLeft + } + } + } + RoundCorner { + id: rightCorner + anchors { + right: parent.right + top: !Config.options.bar.bottom ? parent.top : undefined + bottom: Config.options.bar.bottom ? parent.bottom : undefined + } + implicitSize: Appearance.rounding.screenRounding + color: showBarBackground ? Appearance.colors.colLayer0 : "transparent" + + corner: RoundCorner.CornerEnum.TopRight + states: State { + name: "bottom" + when: Config.options.bar.bottom + PropertyChanges { + rightCorner.corner: RoundCorner.CornerEnum.BottomRight + } } } } diff --git a/.config/quickshell/ii/modules/common/Config.qml b/.config/quickshell/ii/modules/common/Config.qml index ac8c4da4..3ca1daa6 100644 --- a/.config/quickshell/ii/modules/common/Config.qml +++ b/.config/quickshell/ii/modules/common/Config.qml @@ -124,6 +124,11 @@ Singleton { } property JsonObject bar: JsonObject { + property JsonObject autoHide: JsonObject { + property bool enabled: false + property bool pushWindows: false + property bool showWhenPressingSuper: true + } property bool bottom: false // Instead of top property int cornerStyle: 0 // 0: Hug | 1: Float | 2: Plain rectangle property bool borderless: false // true for no grouping of items