quickshell overview starting work

This commit is contained in:
ari committed 2026-08-31 11:22:54 -04:00
1 parent 3c86efa4ff
commit fdca7d8d9d
21 files changed
+580 -272

No files matched your search

@@ -0,0 +1,188 @@
import QtQuick
import Quickshell
import Quickshell.Wayland
import Quickshell.Hyprland
PanelWindow {
id: root
required property bool shellOpen
signal requestClose()
readonly property var monitor: Hyprland.monitorFor(root.screen)
readonly property bool monitorFocused: monitor && Hyprland.focusedMonitor && monitor.id === Hyprland.focusedMonitor.id
visible: root.shellOpen && root.monitorFocused
color: "transparent"
WlrLayershell.namespace: "quickshell:overview"
WlrLayershell.layer: WlrLayer.Overlay
WlrLayershell.exclusiveZone: -1
WlrLayershell.keyboardFocus: root.visible ? WlrKeyboardFocus.OnDemand : WlrKeyboardFocus.None
anchors {
top: true
left: true
right: true
bottom: true
}
property Theme theme: Theme {}
// Sorts a workspace's toplevels by x-position so card order matches the
// scrolling layout's column order.
function sortedToplevels(ws) {
const list = (ws && ws.toplevels) ? ws.toplevels.values.slice() : [];
return list.sort((a, b) => {
const ax = a?.lastIpcObject?.at?.[0] ?? 0;
const bx = b?.lastIpcObject?.at?.[0] ?? 0;
return ax - bx;
});
}
// Workspace rows for this monitor, top-to-bottom by workspace id. Special
// (scratchpad) workspaces have negative ids and are excluded.
readonly property var rows: {
const mon = root.monitor;
if (!mon || !Hyprland.workspaces) return [];
const workspaces = Hyprland.workspaces.values
.filter(ws => ws && ws.id > 0 && ws.monitor && ws.monitor.name === mon.name)
.sort((a, b) => a.id - b.id);
return workspaces.map(ws => ({ workspace: ws, toplevels: root.sortedToplevels(ws) }));
}
property int selectedRow: 0
property int selectedCol: 0
function clampSelection() {
if (root.rows.length === 0) {
root.selectedRow = 0;
root.selectedCol = 0;
return;
}
if (root.selectedRow >= root.rows.length) root.selectedRow = root.rows.length - 1;
if (root.selectedRow < 0) root.selectedRow = 0;
const count = root.rows[root.selectedRow].toplevels.length;
if (root.selectedCol >= count) root.selectedCol = Math.max(0, count - 1);
if (root.selectedCol < 0) root.selectedCol = 0;
}
// Reset the selection to the active workspace/window whenever the
// overview opens.
function resetSelection() {
const activeRowIndex = root.rows.findIndex(r => r.workspace.active);
root.selectedRow = activeRowIndex >= 0 ? activeRowIndex : 0;
const row = root.rows[root.selectedRow];
const activeColIndex = row ? row.toplevels.findIndex(tl => tl.activated) : -1;
root.selectedCol = activeColIndex >= 0 ? activeColIndex : 0;
root.clampSelection();
}
function moveSelection(dRow, dCol) {
if (root.rows.length === 0) return;
if (dRow !== 0) {
root.selectedRow = (root.selectedRow + dRow + root.rows.length) % root.rows.length;
root.clampSelection();
}
if (dCol !== 0) {
const count = root.rows[root.selectedRow].toplevels.length;
if (count > 0) root.selectedCol = (root.selectedCol + dCol + count) % count;
}
}
function activateSelection() {
const row = root.rows[root.selectedRow];
if (!row) { root.requestClose(); return; }
if (!row.workspace.active) Hyprland.dispatch("workspace " + row.workspace.id);
const tl = row.toplevels[root.selectedCol];
if (tl) Hyprland.dispatch("focuswindow address:" + tl.address);
root.requestClose();
}
onVisibleChanged: {
if (root.visible) {
Hyprland.refreshMonitors();
Hyprland.refreshWorkspaces();
Hyprland.refreshToplevels();
root.resetSelection();
Qt.callLater(() => focusScope.forceActiveFocus());
}
}
HyprlandFocusGrab {
windows: [root]
active: root.visible
onCleared: {
if (root.visible) root.requestClose();
}
}
Rectangle {
anchors.fill: parent
color: root.theme.backdrop
MouseArea {
anchors.fill: parent
onClicked: root.requestClose()
}
}
FocusScope {
id: focusScope
anchors.fill: parent
focus: root.visible
Keys.onPressed: event => {
switch (event.key) {
case Qt.Key_Left:
root.moveSelection(0, -1);
break;
case Qt.Key_Right:
root.moveSelection(0, 1);
break;
case Qt.Key_Up:
root.moveSelection(-1, 0);
break;
case Qt.Key_Down:
root.moveSelection(1, 0);
break;
case Qt.Key_Return:
case Qt.Key_Enter:
root.activateSelection();
break;
case Qt.Key_Escape:
root.requestClose();
break;
default:
return;
}
event.accepted = true;
}
Column {
anchors.centerIn: parent
spacing: root.theme.rowSpacing
Repeater {
model: root.rows
WorkspaceRow {
required property var modelData
required property int index
theme: root.theme
workspace: modelData.workspace
toplevels: modelData.toplevels
selectedIndex: index === root.selectedRow ? root.selectedCol : -1
live: root.visible
onCardClicked: colIndex => {
root.selectedRow = index;
root.selectedCol = colIndex;
root.activateSelection();
}
}
}
}
}
}
@@ -0,0 +1,14 @@
import QtQuick
QtObject {
readonly property color backdrop: "#cc0b0e14"
readonly property color cardBg: "#332a2e3a"
readonly property color cardBorder: "#40ffffff"
readonly property color selectedBorder: "#7aa2f7"
readonly property color textColor: "#ffffff"
readonly property color emptyTextColor: "#80ffffff"
readonly property real cornerRadius: 10
readonly property real cardHeight: 180
readonly property real cardSpacing: 20
readonly property real rowSpacing: 28
}
@@ -0,0 +1,69 @@
import QtQuick
import Quickshell
import Quickshell.Wayland
Rectangle {
id: root
required property var theme
required property var toplevel
required property bool selected
required property bool live
signal activated()
readonly property var ipc: root.toplevel ? root.toplevel.lastIpcObject : null
readonly property real aspect: (ipc && ipc.size && ipc.size[0] > 0 && ipc.size[1] > 0) ? ipc.size[0] / ipc.size[1] : (16 / 9)
width: Math.min(height * aspect, theme.cardHeight * 2.2)
height: theme.cardHeight
radius: theme.cornerRadius
color: theme.cardBg
border.width: selected ? 3 : 1
border.color: selected ? theme.selectedBorder : theme.cardBorder
clip: true
ScreencopyView {
anchors.fill: parent
anchors.margins: 3
captureSource: root.live && root.toplevel ? root.toplevel.wayland : null
live: root.live
paintCursor: false
}
Image {
anchors.left: parent.left
anchors.bottom: parent.bottom
anchors.margins: 6
width: 20
height: 20
source: Quickshell.iconPath(ipc ? ipc.class : "", "application-x-executable")
sourceSize: Qt.size(20, 20)
}
Rectangle {
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
height: title.implicitHeight + 8
color: "#99000000"
Text {
id: title
anchors.left: parent.left
anchors.right: parent.right
anchors.leftMargin: 30
anchors.rightMargin: 6
anchors.verticalCenter: parent.verticalCenter
elide: Text.ElideRight
color: theme.textColor
text: root.toplevel ? root.toplevel.title : ""
font.pixelSize: 12
}
}
MouseArea {
anchors.fill: parent
onClicked: root.activated()
}
}
@@ -0,0 +1,72 @@
import QtQuick
Item {
id: root
required property var theme
required property var workspace
required property var toplevels
required property int selectedIndex
required property bool live
signal cardClicked(int index)
implicitWidth: content.implicitWidth
implicitHeight: content.implicitHeight
Column {
id: content
spacing: root.theme.cardSpacing * 0.5
Text {
anchors.horizontalCenter: parent.horizontalCenter
text: "Workspace " + (root.workspace ? root.workspace.id : "?")
color: root.theme.textColor
font.pixelSize: 14
font.bold: root.workspace && root.workspace.active
}
Row {
spacing: root.theme.cardSpacing
Repeater {
model: root.toplevels
WindowCard {
required property var modelData
required property int index
theme: root.theme
toplevel: modelData
selected: index === root.selectedIndex
live: root.live
onActivated: root.cardClicked(index)
}
}
// Placeholder for an empty workspace so the row stays visible
// and selectable even with no windows.
Rectangle {
visible: root.toplevels.length === 0
width: root.theme.cardHeight * 1.6
height: root.theme.cardHeight
radius: root.theme.cornerRadius
color: "transparent"
border.width: root.selectedIndex === 0 ? 3 : 1
border.color: root.selectedIndex === 0 ? root.theme.selectedBorder : root.theme.cardBorder
Text {
anchors.centerIn: parent
text: "Empty"
color: root.theme.emptyTextColor
}
MouseArea {
anchors.fill: parent
onClicked: root.cardClicked(0)
}
}
}
}
}
@@ -0,0 +1,37 @@
import Quickshell
import Quickshell.Io
// Scrolling overview for Hyprland — vertical stack of workspace rows on the
// current monitor, each row a horizontal strip of that workspace's windows.
// Toggle with `qs -c overview ipc call overview <toggle|open|close>`; wired
// to Mod+Tab and a 4-finger swipe in the Hyprland config.
ShellRoot {
id: shell
property bool overviewOpen: false
IpcHandler {
target: "overview"
function toggle(): void {
shell.overviewOpen = !shell.overviewOpen;
}
function open(): void {
shell.overviewOpen = true;
}
function close(): void {
shell.overviewOpen = false;
}
}
Variants {
model: Quickshell.screens
OverviewWindow {
required property var modelData
screen: modelData
shellOpen: shell.overviewOpen
onRequestClose: shell.overviewOpen = false
}
}
}