| 1 | pragma Singleton |
| 2 | import QtQuick |
| 3 | import Quickshell |
| 4 | |
| 5 | // Compositor actions. Your waybar config uses the new Lua-style dispatchers |
| 6 | // (hl.dsp.focus{...}), so that is the default; flip luaSyntax for older Hyprland. |
| 7 | Singleton { |
| 8 | property bool luaSyntax: true |
| 9 | |
| 10 | function workspace(arg) { |
| 11 | if (luaSyntax) |
| 12 | Quickshell.execDetached(["hyprctl", "dispatch", 'hl.dsp.focus({workspace="' + arg + '"})']) |
| 13 | else |
| 14 | Quickshell.execDetached(["hyprctl", "dispatch", "workspace", String(arg)]) |
| 15 | } |
| 16 | |
| 17 | function addr(a) { a = String(a); return a.indexOf("0x") === 0 ? a : "0x" + a } |
| 18 | |
| 19 | function focusWindow(a) { |
| 20 | if (luaSyntax) |
| 21 | Quickshell.execDetached(["hyprctl", "dispatch", 'hl.dsp.focus({window="address:' + addr(a) + '"})']) |
| 22 | else |
| 23 | Quickshell.execDetached(["hyprctl", "dispatch", "focuswindow", "address:" + addr(a)]) |
| 24 | } |
| 25 | // window.move ignores an unknown `window=` key (returns ok and moves the active window instead), |
| 26 | // so focus the target first and then move the active one |
| 27 | function moveWindow(a, ws) { |
| 28 | if (luaSyntax) |
| 29 | Quickshell.execDetached(["hyprctl", "--batch", |
| 30 | 'dispatch hl.dsp.focus({window="address:' + addr(a) + '"}); dispatch hl.dsp.window.move({workspace=' + Number(ws) + '})']) |
| 31 | else |
| 32 | Quickshell.execDetached(["hyprctl", "dispatch", "movetoworkspacesilent", Number(ws) + ",address:" + addr(a)]) |
| 33 | } |
| 34 | |
| 35 | // compositor-agnostic logout |
| 36 | function logout() { Quickshell.execDetached(["sh", "-c", 'loginctl terminate-user "$USER"']) } |
| 37 | } |