Something went wrong. Try again.
A Quickshell workspace overview for Hyprland.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248import QtQuickimport QtQuick.Controlsimport QtQuick.Layoutsimport Quickshellimport Quickshell.Ioimport Quickshell.Waylandimport Quickshell.Hyprlandimport "../../common"import "../../services"import "."
Scope { id: overviewScope
function workspaceNavigationState(monitorId) { const rows = Math.max(1, Config.options.overview.rows); const columns = Math.max(1, Config.options.overview.columns); const count = rows * columns; const currentId = Hyprland.focusedMonitor?.activeWorkspace?.id ?? 1; const workspaceMap = Config.options.overview.workspaceMap ?? []; const offset = Config.options.overview.useWorkspaceMap ? Number(workspaceMap[monitorId] ?? 0) : 0; const firstId = Math.floor((currentId - offset - 1) / count) * count + 1 + offset; const normalIndex = Math.max(0, Math.min(count - 1, currentId - firstId)); const normalRow = Math.floor(normalIndex / columns); const normalColumn = normalIndex % columns;
return { rows, columns, count, firstId, visualRow: Config.options.overview.orderBottomUp ? rows - normalRow - 1 : normalRow, visualColumn: Config.options.overview.orderRightLeft ? columns - normalColumn - 1 : normalColumn }; }
function workspaceInCell(state, visualRow, visualColumn): int { const normalRow = Config.options.overview.orderBottomUp ? state.rows - visualRow - 1 : visualRow; const normalColumn = Config.options.overview.orderRightLeft ? state.columns - visualColumn - 1 : visualColumn; return state.firstId + normalRow * state.columns + normalColumn; }
function workspaceAtLinearOffset(state, step): int { const visualIndex = state.visualRow * state.columns + state.visualColumn; const targetIndex = (visualIndex + step + state.count) % state.count; return workspaceInCell(state, Math.floor(targetIndex / state.columns), targetIndex % state.columns); }
function focusWorkspace(workspaceId): void { Hyprland.dispatch(`hl.dsp.focus({workspace = '${workspaceId}'})`); }
function handleWorkspaceKey(event, monitorId): bool { const state = workspaceNavigationState(monitorId); const tabForward = event.key === Qt.Key_Tab && !(event.modifiers & Qt.ShiftModifier); const tabBackward = event.key === Qt.Key_Backtab || (event.key === Qt.Key_Tab && (event.modifiers & Qt.ShiftModifier)); let targetId = 0;
if (event.key === Qt.Key_Left || event.key === Qt.Key_H || tabBackward) { targetId = workspaceAtLinearOffset(state, -1); } else if (event.key === Qt.Key_Right || event.key === Qt.Key_L || tabForward) { targetId = workspaceAtLinearOffset(state, 1); } else if (event.key === Qt.Key_Up || event.key === Qt.Key_K) { targetId = workspaceInCell(state, (state.visualRow - 1 + state.rows) % state.rows, state.visualColumn); } else if (event.key === Qt.Key_Down || event.key === Qt.Key_J) { targetId = workspaceInCell(state, (state.visualRow + 1) % state.rows, state.visualColumn); } else if (event.key >= Qt.Key_1 && event.key <= Qt.Key_9) { const position = event.key - Qt.Key_0; if (position <= state.count) targetId = state.firstId + position - 1; } else if (event.key === Qt.Key_0 && state.count >= 10) { targetId = state.firstId + 9; }
if (targetId === 0) return false;
focusWorkspace(targetId); return true; }
function cycleOrOpen(step): void { if (!GlobalStates.overviewOpen) { GlobalStates.overviewOpen = true; return; }
const monitorId = Hyprland.focusedMonitor?.id ?? 0; focusWorkspace(workspaceAtLinearOffset(workspaceNavigationState(monitorId), step)); }
Variants { id: overviewVariants model: Quickshell.screens PanelWindow { id: root required property var modelData readonly property HyprlandMonitor monitor: Hyprland.monitorFor(root.screen) property bool monitorIsFocused: Hyprland.focusedMonitor?.id == monitor?.id property bool backdropEnabled: Config.options.overview.effects.enableBackdrop property real backdropOpacity: Math.max(0, Math.min(1, Config.options.overview.effects.backdropOpacity)) property bool closeOnFocusLoss: Config.options.overview.closeOnFocusLoss ?? true screen: modelData visible: GlobalStates.overviewOpen
WlrLayershell.namespace: "overzicht" WlrLayershell.layer: WlrLayer.Overlay WlrLayershell.keyboardFocus: WlrKeyboardFocus.Exclusive color: "transparent"
anchors { top: true bottom: true left: true right: true }
HyprlandFocusGrab { id: grab windows: [root] property bool canBeActive: root.monitorIsFocused active: false onCleared: () => { if (root.closeOnFocusLoss && !active && canBeActive) GlobalStates.overviewOpen = false; } }
Connections { target: GlobalStates function onOverviewOpenChanged() { if (GlobalStates.overviewOpen) delayedGrabTimer.start(); } }
Connections { target: Hyprland function onFocusedMonitorChanged() { if (!GlobalStates.overviewOpen) return;
if (root.monitorIsFocused && !grab.active) grab.active = true; else if (!root.monitorIsFocused && grab.active) grab.active = false; } }
Timer { id: delayedGrabTimer interval: Config.options.hacks.arbitraryRaceConditionDelay repeat: false onTriggered: { if (!grab.canBeActive) return; grab.active = GlobalStates.overviewOpen; } }
implicitWidth: screen.width implicitHeight: screen.height
Item { id: keyHandler anchors.fill: parent visible: GlobalStates.overviewOpen focus: GlobalStates.overviewOpen z: 0
Rectangle { anchors.fill: parent visible: root.backdropEnabled color: "#000000" opacity: root.backdropOpacity z: 0 }
MouseArea { anchors.fill: parent acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton enabled: root.closeOnFocusLoss && GlobalStates.overviewOpen z: 0 onPressed: mouse => { GlobalStates.overviewOpen = false; mouse.accepted = true; } }
Keys.onPressed: event => { if (overviewLoader.item?.handleKeyPress(event)) { event.accepted = true; return; }
if (event.key === Qt.Key_Escape) { GlobalStates.overviewOpen = false; event.accepted = true; return; }
const monitorId = Hyprland.focusedMonitor?.id ?? root.monitor?.id ?? 0; event.accepted = overviewScope.handleWorkspaceKey(event, monitorId); } }
ColumnLayout { id: columnLayout visible: GlobalStates.overviewOpen anchors.centerIn: parent z: 1
Loader { id: overviewLoader active: (Config?.options.overview.enable ?? true) && GlobalStates.overviewOpen sourceComponent: OverviewWidget { panelWindow: root visible: true } } } } }
IpcHandler { target: "overview"
function toggle(): void { GlobalStates.overviewOpen = !GlobalStates.overviewOpen; } function close(): void { GlobalStates.overviewOpen = false; } function cycle(): void { overviewScope.cycleOrOpen(1); } function cycleBackwards(): void { overviewScope.cycleOrOpen(-1); } function open(): void { GlobalStates.overviewOpen = true; } function isOpen(): bool { return GlobalStates.overviewOpen; } }}