From be29519f58a325b64516c9b34b4c761234fa0809 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sat, 31 May 2025 22:33:39 +0200 Subject: [PATCH] group button & ripple button: fix non-left btn release, add more actions --- .../modules/common/widgets/GroupButton.qml | 23 +++++++++++++------ .../modules/common/widgets/RippleButton.qml | 9 ++++++-- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/.config/quickshell/modules/common/widgets/GroupButton.qml b/.config/quickshell/modules/common/widgets/GroupButton.qml index 76aa5be0e..5d4d9d199 100644 --- a/.config/quickshell/modules/common/widgets/GroupButton.qml +++ b/.config/quickshell/modules/common/widgets/GroupButton.qml @@ -18,8 +18,10 @@ Button { property string buttonText property real buttonRadius: Appearance?.rounding?.small ?? 4 property real buttonRadiusPressed: buttonRadius - property var altAction - property var middleClickAction + property var downAction // When left clicking (down) + property var releaseAction // When left clicking (release) + property var altAction // When right clicking + property var middleClickAction // When middle clicking property bool bounce: true property real baseWidth: contentItem.implicitWidth + padding * 2 property real baseHeight: contentItem.implicitHeight + padding * 2 @@ -37,6 +39,10 @@ Button { animation: Appearance.animation.clickBounce.numberAnimation.createObject(this) } + Behavior on implicitHeight { + animation: Appearance.animation.clickBounce.numberAnimation.createObject(this) + } + Behavior on radius { animation: Appearance.animation.elementMoveFast.numberAnimation.createObject(this) } @@ -70,18 +76,21 @@ Button { cursorShape: Qt.PointingHandCursor acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton onPressed: (event) => { - if (event.button === Qt.MiddleButton) { - if (root.middleClickAction) root.middleClickAction(); - return; - } - if (event.button === Qt.RightButton) { + if(event.button === Qt.RightButton) { if (root.altAction) root.altAction(); return; } + if(event.button === Qt.MiddleButton) { + if (root.middleClickAction) root.middleClickAction(); + return; + } root.down = true + if (root.downAction) root.downAction(); } onReleased: (event) => { root.down = false + if (event.button != Qt.LeftButton) return; + if (root.releaseAction) root.releaseAction(); root.click() // Because the MouseArea already consumed the event } onCanceled: (event) => { diff --git a/.config/quickshell/modules/common/widgets/RippleButton.qml b/.config/quickshell/modules/common/widgets/RippleButton.qml index cd0d47a98..0a3a8743b 100644 --- a/.config/quickshell/modules/common/widgets/RippleButton.qml +++ b/.config/quickshell/modules/common/widgets/RippleButton.qml @@ -20,8 +20,10 @@ Button { property real buttonEffectiveRadius: root.down ? root.buttonRadiusPressed : root.buttonRadius property int rippleDuration: 1200 property bool rippleEnabled: true - property var altAction - property var middleClickAction + property var downAction // When left clicking (down) + property var releaseAction // When left clicking (release) + property var altAction // When right clicking + property var middleClickAction // When middle clicking property color colBackground: ColorUtils.transparentize(Appearance?.colors.colLayer1Hover, 1) || "transparent" property color colBackgroundHover: Appearance?.colors.colLayer1Hover ?? "#E5DFED" @@ -70,12 +72,15 @@ Button { return; } root.down = true + if (root.downAction) root.downAction(); if (!root.rippleEnabled) return; const {x,y} = event startRipple(x, y) } onReleased: (event) => { root.down = false + if (event.button != Qt.LeftButton) return; + if (root.releaseAction) root.releaseAction(); root.click() // Because the MouseArea already consumed the event if (!root.rippleEnabled) return; rippleFadeAnim.restart();