From 9b0d76959869d3338f67f30b536fe766e281b7f5 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sun, 27 Apr 2025 23:06:22 +0200 Subject: [PATCH] use hyprland global keybind dispatch for window toggling --- .config/quickshell/modules/bar/Bar.qml | 32 ++-------- .../common/widgets/NotificationWidget.qml | 8 +-- .../OnScreenDisplayBrightness.qml | 18 ++++++ .../onScreenDisplay/OnScreenDisplayVolume.qml | 17 +++++ .../quickshell/modules/overview/Overview.qml | 16 ++++- .../modules/overview/OverviewWidget.qml | 9 +-- .../modules/overview/OverviewWindow.qml | 5 -- .../modules/overview/SearchItem.qml | 8 +-- .../quickshell/modules/session/Session.qml | 62 +++++++------------ .../modules/sidebarLeft/SidebarLeft.qml | 15 +++++ .../modules/sidebarRight/SidebarRight.qml | 34 ++++++++-- .../quickToggles/BluetoothToggle.qml | 9 ++- .../quickToggles/NetworkToggle.qml | 12 ++-- 13 files changed, 134 insertions(+), 111 deletions(-) diff --git a/.config/quickshell/modules/bar/Bar.qml b/.config/quickshell/modules/bar/Bar.qml index 718b79a13..b71cdc401 100644 --- a/.config/quickshell/modules/bar/Bar.qml +++ b/.config/quickshell/modules/bar/Bar.qml @@ -5,6 +5,7 @@ import QtQuick import QtQuick.Controls import QtQuick.Layouts import Quickshell +import Quickshell.Hyprland import Quickshell.Io import Quickshell.Services.Mpris @@ -15,27 +16,6 @@ Scope { readonly property int barCenterSideModuleWidth: Appearance.sizes.barCenterSideModuleWidth readonly property int osdHideMouseMoveThreshold: 20 - Process { - id: openSidebarRight - command: ["qs", "ipc", "call", "sidebarRight", "open"] - } - Process { - id: openSidebarLeft - command: ["qs", "ipc", "call", "sidebarLeft", "open"] - } - Process { - id: hideOsdBrightness - command: ["qs", "ipc", "call", "osdBrightness", "hide"] - } - Process { - id: hideOsdVolume - command: ["qs", "ipc", "call", "osdVolume", "hide"] - } - Process { - id: toggleOverview - command: ["qs", "ipc", "call", "overview", "toggle"] - } - Variants { // For each monitor model: Quickshell.screens @@ -203,7 +183,7 @@ Scope { } onPressed: (event) => { if (event.button === Qt.LeftButton) { - openSidebarLeft.running = true + Hyprland.dispatch('global quickshell:sidebarLeftOpen') } } // Scroll to change brightness @@ -225,7 +205,7 @@ Scope { const dx = mouse.x - barLeftSideMouseArea.lastScrollX; const dy = mouse.y - barLeftSideMouseArea.lastScrollY; if (Math.sqrt(dx*dx + dy*dy) > osdHideMouseMoveThreshold) { - hideOsdBrightness.running = true; + Hyprland.dispatch('global quickshell:osdBrightnessHide') barLeftSideMouseArea.trackingScroll = false; } } @@ -239,7 +219,7 @@ Scope { onPressed: (event) => { if (event.button === Qt.RightButton) { - toggleOverview.running = true; + Hyprland.dispatch('global quickshell:overviewToggle') } } @@ -264,7 +244,7 @@ Scope { } onPressed: (event) => { if (event.button === Qt.LeftButton) { - openSidebarRight.running = true + Hyprland.dispatch('global quickshell:sidebarRightOpen') } else if (event.button === Qt.RightButton) { MprisController.activePlayer.next() @@ -291,7 +271,7 @@ Scope { const dx = mouse.x - barRightSideMouseArea.lastScrollX; const dy = mouse.y - barRightSideMouseArea.lastScrollY; if (Math.sqrt(dx*dx + dy*dy) > osdHideMouseMoveThreshold) { - hideOsdVolume.running = true; + Hyprland.dispatch('global quickshell:osdVolumeHide') barRightSideMouseArea.trackingScroll = false; } } diff --git a/.config/quickshell/modules/common/widgets/NotificationWidget.qml b/.config/quickshell/modules/common/widgets/NotificationWidget.qml index 095653d7b..7dfcfd217 100644 --- a/.config/quickshell/modules/common/widgets/NotificationWidget.qml +++ b/.config/quickshell/modules/common/widgets/NotificationWidget.qml @@ -7,6 +7,7 @@ import QtQuick.Layouts import Quickshell import Quickshell.Io import Quickshell.Widgets +import Quickshell.Hyprland import Quickshell.Services.Notifications import "./notification_utils.js" as NotificationUtils @@ -23,11 +24,6 @@ Item { Layout.fillWidth: true clip: !popup - Process { - id: closeSidebarProcess - command: ["qs", "ipc", "call", "sidebarRight", "close"] - } - Process { id: copyNotificationBody command: ["bash", "-c", `wl-copy "${notificationObject.body}"`] @@ -456,7 +452,7 @@ Item { : notificationObject.body.replace(/ { @@ -125,6 +127,14 @@ Scope { GlobalStates.overviewOpen = !GlobalStates.overviewOpen } } + GlobalShortcut { + name: "overviewClose" + description: "Closes overview" + + onPressed: { + GlobalStates.overviewOpen = false + } + } GlobalShortcut { name: "overviewToggleRelease" description: "Toggles overview on release" diff --git a/.config/quickshell/modules/overview/OverviewWidget.qml b/.config/quickshell/modules/overview/OverviewWidget.qml index b1db1ec58..d15d548ee 100644 --- a/.config/quickshell/modules/overview/OverviewWidget.qml +++ b/.config/quickshell/modules/overview/OverviewWidget.qml @@ -42,11 +42,6 @@ Item { property Component windowComponent: OverviewWindow {} property list windowWidgets: [] - Process { - id: closeOverview - command: ["bash", "-c", "qs ipc call overview close &"] // Somehow has to be async to work? - } - Rectangle { id: overviewBackground @@ -91,7 +86,7 @@ Item { acceptedButtons: Qt.LeftButton onClicked: { if (root.draggingTargetWorkspace === -1) { - closeOverview.running = true + Hyprland.dispatch(`global quickshell:overviewClose`) Hyprland.dispatch(`workspace ${workspaceValue}`) } } @@ -191,7 +186,7 @@ Item { if (!windowData) return; if (event.button === Qt.LeftButton) { - closeOverview.running = true + Hyprland.dispatch(`global quickshell:overviewClose`) Hyprland.dispatch(`workspace ${windowData.workspace.id}`) event.accepted = true } else if (event.button === Qt.MiddleButton) { diff --git a/.config/quickshell/modules/overview/OverviewWindow.qml b/.config/quickshell/modules/overview/OverviewWindow.qml index d44a4c9f4..9be71a3d7 100644 --- a/.config/quickshell/modules/overview/OverviewWindow.qml +++ b/.config/quickshell/modules/overview/OverviewWindow.qml @@ -71,11 +71,6 @@ Rectangle { // Window } } - Process { - id: closeOverview - command: ["bash", "-c", "qs ipc call overview close &"] // Somehow has to by async to work? - } - ColumnLayout { anchors.verticalCenter: parent.verticalCenter anchors.left: parent.left diff --git a/.config/quickshell/modules/overview/SearchItem.qml b/.config/quickshell/modules/overview/SearchItem.qml index 1f874752b..2b10c5186 100644 --- a/.config/quickshell/modules/overview/SearchItem.qml +++ b/.config/quickshell/modules/overview/SearchItem.qml @@ -8,6 +8,7 @@ import QtQuick.Layouts import Quickshell import Quickshell.Io import Quickshell.Widgets +import Quickshell.Hyprland Button { id: root @@ -35,7 +36,7 @@ Button { PointingHandInteraction {} onClicked: { root.itemExecute() - closeOverview.running = true + Hyprland.dispatch("global quickshell:overviewClose") } Keys.onPressed: (event) => { if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) { @@ -116,9 +117,4 @@ Button { text: root.itemClickActionName } } - - Process { - id: closeOverview - command: ["bash", "-c", "qs ipc call overview close &"] // Somehow has to be async to work? - } } \ No newline at end of file diff --git a/.config/quickshell/modules/session/Session.qml b/.config/quickshell/modules/session/Session.qml index 65b52e585..47bed1435 100644 --- a/.config/quickshell/modules/session/Session.qml +++ b/.config/quickshell/modules/session/Session.qml @@ -111,7 +111,7 @@ Scope { focus: sessionRoot.visible buttonIcon: "lock" buttonText: qsTr("Lock") - onClicked: { lock.running = true; sessionRoot.visible = false } + onClicked: { Hyprland.dispatch("exec loginctl lock-session"); sessionRoot.visible = false } onFocusChanged: { if (focus) sessionRoot.subtitle = buttonText } KeyNavigation.right: sessionSleep KeyNavigation.down: sessionHibernate @@ -120,7 +120,7 @@ Scope { id: sessionSleep buttonIcon: "dark_mode" buttonText: qsTr("Sleep") - onClicked: { sleep.running = true; sessionRoot.visible = false } + onClicked: { Hyprland.dispatch("exec systemctl suspend || loginctl suspend"); sessionRoot.visible = false } onFocusChanged: { if (focus) sessionRoot.subtitle = buttonText } KeyNavigation.left: sessionLock KeyNavigation.right: sessionLogout @@ -130,7 +130,7 @@ Scope { id: sessionLogout buttonIcon: "logout" buttonText: qsTr("Logout") - onClicked: { logout.running = true; sessionRoot.visible = false } + onClicked: { Hyprland.dispatch("exec pkill Hyprland"); sessionRoot.visible = false } onFocusChanged: { if (focus) sessionRoot.subtitle = buttonText } KeyNavigation.left: sessionSleep KeyNavigation.right: sessionTaskManager @@ -140,7 +140,7 @@ Scope { id: sessionTaskManager buttonIcon: "browse_activity" buttonText: qsTr("Task Manager") - onClicked: { taskManager.running = true; sessionRoot.visible = false } + onClicked: { Hyprland.dispatch("exec gnome-system-monitor & disown"); sessionRoot.visible = false } onFocusChanged: { if (focus) sessionRoot.subtitle = buttonText } KeyNavigation.left: sessionLogout KeyNavigation.down: sessionFirmwareReboot @@ -153,7 +153,7 @@ Scope { id: sessionHibernate buttonIcon: "downloading" buttonText: qsTr("Hibernate") - onClicked: { hibernate.running = true; sessionRoot.visible = false } + onClicked: { Hyprland.dispatch("exec systemctl hibernate || loginctl hibernate"); sessionRoot.visible = false } onFocusChanged: { if (focus) sessionRoot.subtitle = buttonText } KeyNavigation.up: sessionLock KeyNavigation.right: sessionShutdown @@ -162,7 +162,7 @@ Scope { id: sessionShutdown buttonIcon: "power_settings_new" buttonText: qsTr("Shutdown") - onClicked: { shutdown.running = true; sessionRoot.visible = false } + onClicked: { Hyprland.dispatch("exec systemctl poweroff || loginctl poweroff"); sessionRoot.visible = false } onFocusChanged: { if (focus) sessionRoot.subtitle = buttonText } KeyNavigation.left: sessionHibernate KeyNavigation.right: sessionReboot @@ -172,7 +172,7 @@ Scope { id: sessionReboot buttonIcon: "restart_alt" buttonText: qsTr("Reboot") - onClicked: { reboot.running = true; sessionRoot.visible = false } + onClicked: { Hyprland.dispatch("exec reboot || loginctl reboot"); sessionRoot.visible = false } onFocusChanged: { if (focus) sessionRoot.subtitle = buttonText } KeyNavigation.left: sessionShutdown KeyNavigation.right: sessionFirmwareReboot @@ -182,7 +182,7 @@ Scope { id: sessionFirmwareReboot buttonIcon: "settings_applications" buttonText: qsTr("Reboot to firmware settings") - onClicked: { firmwareReboot.running = true; sessionRoot.visible = false } + onClicked: { Hyprland.dispatch("exec systemctl reboot --firmware-setup || loginctl reboot --firmware-setup"); sessionRoot.visible = false } onFocusChanged: { if (focus) sessionRoot.subtitle = buttonText } KeyNavigation.up: sessionTaskManager KeyNavigation.left: sessionReboot @@ -216,39 +216,6 @@ Scope { } - Process { - id: lock - command: ["bash", "-c", "loginctl lock-session"] - } - Process { - id: sleep - command: ["bash", "-c", "systemctl suspend || loginctl suspend"] - } - Process { - id: logout - command: ["bash", "-c", "pkill Hyprland"] // loginctl terminate-session hangs SDDM - } - Process { - id: hibernate - command: ["bash", "-c", "systemctl hibernate || loginctl hibernate"] - } - Process { - id: shutdown - command: ["bash", "-c", "systemctl poweroff || loginctl poweroff"] - } - Process { - id: reboot - command: ["bash", "-c", "systemctl reboot || loginctl reboot"] - } - Process { - id: firmwareReboot - command: ["bash", "-c", "systemctl reboot --firmware-setup || loginctl reboot --firmware-setup"] - } - Process { - id: taskManager - command: ["bash", "-c", "gnome-system-monitor & disown"] - } - IpcHandler { target: "session" @@ -293,5 +260,18 @@ Scope { } } } + GlobalShortcut { + name: "sessionOpen" + description: "Opens session screen on press" + + onPressed: { + for (let i = 0; i < sessionVariants.instances.length; i++) { + let panelWindow = sessionVariants.instances[i]; + if (panelWindow.modelData.name == Hyprland.focusedMonitor.name) { + panelWindow.visible = true + } + } + } + } } diff --git a/.config/quickshell/modules/sidebarLeft/SidebarLeft.qml b/.config/quickshell/modules/sidebarLeft/SidebarLeft.qml index e9d43e844..74254d4ad 100644 --- a/.config/quickshell/modules/sidebarLeft/SidebarLeft.qml +++ b/.config/quickshell/modules/sidebarLeft/SidebarLeft.qml @@ -203,4 +203,19 @@ Scope { // Scope } } + GlobalShortcut { + name: "sidebarLeftOpen" + description: "Opens left sidebar on press" + + onPressed: { + for (let i = 0; i < sidebarVariants.instances.length; i++) { + let panelWindow = sidebarVariants.instances[i]; + if (panelWindow.modelData.name == Hyprland.focusedMonitor.name) { + panelWindow.visible = true; + if(panelWindow.visible) Notifications.timeoutAll(); + } + } + } + } + } diff --git a/.config/quickshell/modules/sidebarRight/SidebarRight.qml b/.config/quickshell/modules/sidebarRight/SidebarRight.qml index cc291703a..537fa0245 100644 --- a/.config/quickshell/modules/sidebarRight/SidebarRight.qml +++ b/.config/quickshell/modules/sidebarRight/SidebarRight.qml @@ -130,11 +130,7 @@ Scope { toggled: false buttonIcon: "power_settings_new" onClicked: { - openSessionMenu.running = true - } - Process { - id: openSessionMenu - command: ["qs", "ipc", "call", "session", "open"] + Hyprland.dispatch("global quickshell:sessionOpen") } StyledToolTip { content: qsTr("Session") @@ -245,5 +241,33 @@ Scope { } } } + GlobalShortcut { + name: "sidebarRightOpen" + description: "Opens right sidebar on press" + + onPressed: { + for (let i = 0; i < sidebarVariants.instances.length; i++) { + let panelWindow = sidebarVariants.instances[i]; + if (panelWindow.modelData.name == Hyprland.focusedMonitor.name) { + panelWindow.visible = true; + if(panelWindow.visible) Notifications.timeoutAll(); + } + } + } + } + GlobalShortcut { + name: "sidebarRightClose" + description: "Closes right sidebar on press" + + onPressed: { + for (let i = 0; i < sidebarVariants.instances.length; i++) { + let panelWindow = sidebarVariants.instances[i]; + if (panelWindow.modelData.name == Hyprland.focusedMonitor.name) { + panelWindow.visible = false; + if(panelWindow.visible) Notifications.timeoutAll(); + } + } + } + } } diff --git a/.config/quickshell/modules/sidebarRight/quickToggles/BluetoothToggle.qml b/.config/quickshell/modules/sidebarRight/quickToggles/BluetoothToggle.qml index c7a24fc70..d73a66076 100644 --- a/.config/quickshell/modules/sidebarRight/quickToggles/BluetoothToggle.qml +++ b/.config/quickshell/modules/sidebarRight/quickToggles/BluetoothToggle.qml @@ -5,6 +5,7 @@ import "root:/modules/common/widgets" import QtQuick import Quickshell import Quickshell.Io +import Quickshell.Hyprland QuickToggleButton { toggled: Bluetooth.bluetoothEnabled @@ -17,17 +18,15 @@ QuickToggleButton { toggleBluetooth.running = true } if (mouse.button === Qt.RightButton) { - configureBluetooth.running = true + Hyprland.dispatch(`exec ${ConfigOptions.apps.bluetooth}`) + Hyprland.dispatch("global quickshell:sidebarRightClose") + } } hoverEnabled: false propagateComposedEvents: true cursorShape: Qt.PointingHandCursor } - Process { - id: configureBluetooth - command: ["bash", "-c", `${ConfigOptions.apps.bluetooth} & qs ipc call sidebarRight close`] - } Process { id: toggleBluetooth command: ["bash", "-c", `bluetoothctl power ${Bluetooth.bluetoothEnabled ? "off" : "on"}`] diff --git a/.config/quickshell/modules/sidebarRight/quickToggles/NetworkToggle.qml b/.config/quickshell/modules/sidebarRight/quickToggles/NetworkToggle.qml index 8c916aac9..742a2f480 100644 --- a/.config/quickshell/modules/sidebarRight/quickToggles/NetworkToggle.qml +++ b/.config/quickshell/modules/sidebarRight/quickToggles/NetworkToggle.qml @@ -2,9 +2,10 @@ import "root:/modules/common" import "root:/modules/common/widgets" import "root:/services" import "../" -import Quickshell.Io -import Quickshell import QtQuick +import Quickshell +import Quickshell.Io +import Quickshell.Hyprland QuickToggleButton { toggled: Network.networkName.length > 0 && Network.networkName != "lo" @@ -23,17 +24,14 @@ QuickToggleButton { toggleNetwork.running = true } if (mouse.button === Qt.RightButton) { - configureNetwork.running = true + Hyprland.dispatch(`exec ${ConfigOptions.apps.network}`) + Hyprland.dispatch("global quickshell:sidebarRightClose") } } hoverEnabled: false propagateComposedEvents: true cursorShape: Qt.PointingHandCursor } - Process { - id: configureNetwork - command: ["bash", "-c", `${ConfigOptions.apps.network} & qs ipc call sidebarRight close`] - } Process { id: toggleNetwork command: ["bash", "-c", "nmcli radio wifi | grep -q enabled && nmcli radio wifi off || nmcli radio wifi on"]