diff --git a/modules/bar/components/bluetooth/Bluetooth.qml b/modules/bar/components/bluetooth/Bluetooth.qml index 2414f69..80097e0 100644 --- a/modules/bar/components/bluetooth/Bluetooth.qml +++ b/modules/bar/components/bluetooth/Bluetooth.qml @@ -5,9 +5,7 @@ import qs.widgets StyledButton { id: root - onClicked: { - popup.opened = !popup.opened; - } + onClicked: popup.toggle() content: StyledText { id: text diff --git a/modules/bar/components/tray/TrayItem.qml b/modules/bar/components/tray/TrayItem.qml index e09977d..e199d8d 100644 --- a/modules/bar/components/tray/TrayItem.qml +++ b/modules/bar/components/tray/TrayItem.qml @@ -11,13 +11,8 @@ StyledButton { id: root property SystemTrayItem trayItem - property bool menuOpened: false - onClicked: toggleMenu() - - function toggleMenu() { - menuOpened = !menuOpened; - } + onClicked: menu.toggle() content: IconImage { id: icon @@ -36,8 +31,6 @@ StyledButton { Menu { id: menu - opened: root.menuOpened - anchor.item: root anchor.rect.x: root.width / 2 - width / 2 anchor.rect.y: root.height + 8 diff --git a/services/Visibility.qml b/services/Visibility.qml new file mode 100644 index 0000000..3015f7a --- /dev/null +++ b/services/Visibility.qml @@ -0,0 +1,16 @@ +pragma Singleton + +import qs.widgets +import Quickshell + +Singleton { + property StyledPopupWindow activePopup + + function togglePopup(popup: StyledPopupWindow) { + if (activePopup && popup != activePopup) { + activePopup.state = ""; + } + popup.state = popup.state == "opened" ? "" : "opened"; + activePopup = popup; + } +} diff --git a/widgets/StyledPopupWindow.qml b/widgets/StyledPopupWindow.qml index 924001a..4b7ed4f 100644 --- a/widgets/StyledPopupWindow.qml +++ b/widgets/StyledPopupWindow.qml @@ -1,3 +1,4 @@ +import qs.services import QtQuick import Quickshell import Quickshell.Widgets @@ -9,10 +10,15 @@ PopupWindow { property alias margins: background.margin property alias backgroundColor: background.color property alias radius: background.radius + property alias state: background.state required property Component content color: "transparent" + function toggle() { + Visibility.togglePopup(this); + } + implicitWidth: background.width Behavior on implicitWidth { NumberAnimation {