use hyprland global keybind dispatch for window toggling

This commit is contained in:
end-4
2025-04-27 23:06:22 +02:00
parent 4548000077
commit 9b0d769598
13 changed files with 134 additions and 111 deletions
+6 -26
View File
@@ -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;
}
}
@@ -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(/<img/g, "\n <img").split("\n")[0]
onLinkActivated: {
Qt.openUrlExternally(link)
closeSidebarProcess.running = true
Hyprland.dispatch("global quickshell:sidebarRightClose")
}
MouseArea {
anchors.fill: parent
@@ -6,6 +6,7 @@ import QtQuick.Controls
import QtQuick.Layouts
import Quickshell
import Quickshell.Io
import Quickshell.Hyprland
import Quickshell.Wayland
Scope {
@@ -122,4 +123,21 @@ Scope {
}
}
GlobalShortcut {
name: "osdBrightnessTrigger"
description: "Triggers brightness OSD on press"
onPressed: {
root.triggerOsd()
}
}
GlobalShortcut {
name: "osdBrightnessHide"
description: "Hides brightness OSD on press"
onPressed: {
root.showOsdValues = false
}
}
}
@@ -7,6 +7,7 @@ import QtQuick.Layouts
import Quickshell
import Quickshell.Io
import Quickshell.Wayland
import Quickshell.Hyprland
Scope {
id: root
@@ -121,5 +122,21 @@ Scope {
showOsdValues = !showOsdValues
}
}
GlobalShortcut {
name: "osdVolumeTrigger"
description: "Triggers volume OSD on press"
onPressed: {
root.triggerOsd()
}
}
GlobalShortcut {
name: "osdVolumeHide"
description: "Hides volume OSD on press"
onPressed: {
root.showOsdValues = false
}
}
}
@@ -21,15 +21,16 @@ Scope {
property var modelData
property string searchingText: ""
screen: modelData
visible: GlobalStates.overviewOpen
// visible: GlobalStates.overviewOpen
visible: true
WlrLayershell.namespace: "quickshell:overview"
WlrLayershell.layer: WlrLayer.Overlay
WlrLayershell.keyboardFocus: WlrKeyboardFocus.Exclusive
// WlrLayershell.keyboardFocus: WlrKeyboardFocus.Exclusive
color: "transparent"
mask: Region {
item: columnLayout
item: GlobalStates.overviewOpen ? columnLayout : null
}
anchors {
@@ -69,6 +70,7 @@ Scope {
ColumnLayout {
id: columnLayout
visible: GlobalStates.overviewOpen
anchors.horizontalCenter: parent.horizontalCenter
Keys.onPressed: (event) => {
@@ -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"
@@ -42,11 +42,6 @@ Item {
property Component windowComponent: OverviewWindow {}
property list<OverviewWindow> 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) {
@@ -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
@@ -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?
}
}
+21 -41
View File
@@ -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
}
}
}
}
}
@@ -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();
}
}
}
}
}
@@ -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();
}
}
}
}
}
@@ -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"}`]
@@ -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"]