Add a native workspace overview drawer
SUPER+Tab opens a bar drawer with one live thumbnail per workspace, drawn over the monitor's wallpaper. Click to go, drag windows between workspaces, middle-click to close; arrows, 1-9, Enter and Esc from the keyboard. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ebace10767
commit
cc0ae50b95
9 files changed
+608
-2
No files matched your search
@@ -0,0 +1,440 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Hyprland
|
||||
import Quickshell.Io
|
||||
import Quickshell.Wayland
|
||||
import Quickshell.Widgets
|
||||
import "../components"
|
||||
import "../core"
|
||||
import "../services"
|
||||
import "../theme"
|
||||
import "OverviewLogic.js" as Logic
|
||||
import "../services/AppMatching.js" as Matching
|
||||
|
||||
// Workspace overview (SUPER+Tab): a drawer out of the bar with one live
|
||||
// thumbnail per workspace (bar.workspaces.count of them), drawn over that
|
||||
// monitor's wallpaper. Click a workspace or window to go there, drag a window
|
||||
// onto another workspace to move it, middle-click a window to close it.
|
||||
// Arrows/1–9 pick a workspace, Enter goes there, Esc closes.
|
||||
// qmllint disable uncreatable-type
|
||||
PanelWindow {
|
||||
// qmllint enable uncreatable-type
|
||||
id: root
|
||||
screen: ScreenService.current(ShellState.overviewScreen)
|
||||
anchors.top: true
|
||||
readonly property real screenWidth: screen ? screen.width : 1920
|
||||
readonly property real screenHeight: screen ? screen.height : 1080
|
||||
implicitWidth: Math.max(120, Math.round(surface.width))
|
||||
implicitHeight: Math.max(60, Math.round(BarDrawers.bottom + surface.contentHeight))
|
||||
visible: ShellState.overviewOpen || surface.shown
|
||||
color: Theme.transparent
|
||||
exclusionMode: ExclusionMode.Ignore
|
||||
WlrLayershell.namespace: "glassMxrph-overview"
|
||||
WlrLayershell.layer: WlrLayer.Overlay
|
||||
WlrLayershell.keyboardFocus: ShellState.overviewOpen ? WlrKeyboardFocus.Exclusive : WlrKeyboardFocus.None
|
||||
Component.onCompleted: ShellState.overviewWindow = root
|
||||
Component.onDestruction: ShellState.overviewWindow = null
|
||||
|
||||
readonly property bool live: ShellState.overviewOpen
|
||||
readonly property var layout: Logic.grid(ConfigService.ready ? ConfigService.data.bar.workspaces.count : 9)
|
||||
readonly property int focusedId: Hyprland.focusedWorkspace ? Hyprland.focusedWorkspace.id : 0
|
||||
// Workspaces shown on other monitors get a faint outline, as in the bar.
|
||||
readonly property var visibleIds: Hyprland.monitors.values.map(m => m.activeWorkspace ? m.activeWorkspace.id : 0).filter(id => id > 0 && id !== focusedId)
|
||||
readonly property int padding: 20
|
||||
readonly property int gap: 14
|
||||
readonly property int header: 40
|
||||
// Thumbnails keep this screen's aspect ratio.
|
||||
readonly property real aspect: screenHeight > 0 ? screenWidth / screenHeight : 16 / 9
|
||||
readonly property real maxWidth: Math.min(1320, screenWidth - 2 * (BarDrawers.margin + BarDrawers.radius + BarDrawers.ear))
|
||||
readonly property real thumbWidth: Math.floor(Math.min(300, (maxWidth - 2 * padding - (layout.columns - 1) * gap) / layout.columns, (screenHeight * 0.62 / layout.rows - gap) * aspect))
|
||||
readonly property real thumbHeight: Math.round(thumbWidth / aspect)
|
||||
readonly property real thumbRadius: Math.max(8, Theme.radius * 0.6)
|
||||
|
||||
property int selected: 0
|
||||
property string hoveredTitle: ""
|
||||
// Window being dragged, and the workspace slot under it.
|
||||
property string dragAddress: ""
|
||||
property int dropSlot: -1
|
||||
|
||||
function slotX(index) {
|
||||
return Logic.cell(index, layout).column * (thumbWidth + gap);
|
||||
}
|
||||
function slotY(index) {
|
||||
return Logic.cell(index, layout).row * (thumbHeight + gap);
|
||||
}
|
||||
// Workspace slot under a point in grid coordinates, or -1.
|
||||
function slotAt(x, y) {
|
||||
for (let i = 0; i < layout.count; i++)
|
||||
if (x >= slotX(i) && x < slotX(i) + thumbWidth && y >= slotY(i) && y < slotY(i) + thumbHeight)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
function screenNamed(name) {
|
||||
return Quickshell.screens.find(s => s.name === name) || null;
|
||||
}
|
||||
// The monitor a workspace lives on: Hyprland's, else this drawer's.
|
||||
function monitorOf(id) {
|
||||
const ws = Hyprland.workspaces.values.find(w => w.id === id);
|
||||
return ws && ws.monitor ? ws.monitor.name : (screen ? screen.name : "");
|
||||
}
|
||||
function wallpaperFor(name) {
|
||||
const path = WallpaperService.observed[name] || (ConfigService.ready ? ConfigService.data.wallpaper.byMonitor[name] : "") || "";
|
||||
return path ? "file://" + encodeURI(path).replace(/#/g, "%23").replace(/\?/g, "%3F") : "";
|
||||
}
|
||||
function iconFor(win) {
|
||||
const entry = Matching.match(win.appId, win.initialClass, ApplicationsService.entries, ConfigService.ready ? ConfigService.data.dock.appOverrides : ({}));
|
||||
return entry ? ApplicationsService.icon(entry) : Quickshell.iconPath(String(win.appId || "").toLowerCase(), "application-x-executable");
|
||||
}
|
||||
function go(index) {
|
||||
ShellState.overviewOpen = false;
|
||||
HyprlandService.focusWorkspace(index + 1);
|
||||
}
|
||||
function select(index) {
|
||||
if (index >= 0 && index < layout.count)
|
||||
selected = index;
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: ShellState
|
||||
function onOverviewOpenChanged() {
|
||||
if (ShellState.overviewOpen) {
|
||||
HyprlandService.refresh();
|
||||
root.selected = root.focusedId >= 1 && root.focusedId <= root.layout.count ? root.focusedId - 1 : 0;
|
||||
root.hoveredTitle = "";
|
||||
root.dragAddress = "";
|
||||
root.dropSlot = -1;
|
||||
Qt.callLater(() => surface.forceActiveFocus());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Exclusive focus routes outside clicks here (see ControlCenter).
|
||||
MouseArea {
|
||||
x: -20000
|
||||
y: -20000
|
||||
width: 40000
|
||||
height: 40000
|
||||
onPressed: ShellState.overviewOpen = false
|
||||
}
|
||||
|
||||
BarDrawer {
|
||||
id: surface
|
||||
objectName: "overviewSurface"
|
||||
y: BarDrawers.bottom
|
||||
open: ShellState.overviewOpen
|
||||
drawerId: "overview"
|
||||
screenName: root.screen ? root.screen.name : ""
|
||||
screenX: (root.screenWidth - width) / 2
|
||||
contentWidth: 2 * root.padding + root.layout.columns * root.thumbWidth + (root.layout.columns - 1) * root.gap
|
||||
contentHeight: 2 * root.padding + root.header + root.layout.rows * root.thumbHeight + (root.layout.rows - 1) * root.gap
|
||||
focus: ShellState.overviewOpen
|
||||
Keys.onEscapePressed: ShellState.overviewOpen = false
|
||||
Keys.onLeftPressed: root.select(Logic.step(root.selected, "left", root.layout))
|
||||
Keys.onRightPressed: root.select(Logic.step(root.selected, "right", root.layout))
|
||||
Keys.onUpPressed: root.select(Logic.step(root.selected, "up", root.layout))
|
||||
Keys.onDownPressed: root.select(Logic.step(root.selected, "down", root.layout))
|
||||
Keys.onTabPressed: root.select(Logic.step(root.selected, "right", root.layout))
|
||||
Keys.onBacktabPressed: root.select(Logic.step(root.selected, "left", root.layout))
|
||||
Keys.onReturnPressed: root.go(root.selected)
|
||||
Keys.onEnterPressed: root.go(root.selected)
|
||||
Keys.onPressed: event => {
|
||||
const n = event.key - Qt.Key_1;
|
||||
if (n >= 0 && n < Math.min(9, root.layout.count)) {
|
||||
root.go(n);
|
||||
event.accepted = true;
|
||||
}
|
||||
}
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
} // Consume inside clicks without dismissing.
|
||||
|
||||
// Header: title, then whatever is hovered or selected.
|
||||
Item {
|
||||
x: root.padding
|
||||
y: root.padding - 4
|
||||
width: surface.contentWidth - 2 * root.padding
|
||||
height: root.header
|
||||
Text {
|
||||
id: title
|
||||
anchors.left: parent.left
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: "Workspaces"
|
||||
color: Theme.text
|
||||
font.pixelSize: 20
|
||||
}
|
||||
Text {
|
||||
anchors.left: title.right
|
||||
anchors.leftMargin: 14
|
||||
anchors.right: closeButton.left
|
||||
anchors.rightMargin: 14
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: root.dragAddress ? (root.dropSlot >= 0 ? "Move to workspace " + (root.dropSlot + 1) : "Drop on a workspace") : root.hoveredTitle || "Workspace " + (root.selected + 1)
|
||||
color: Theme.textSecondary
|
||||
font.pixelSize: 13
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
GlassIconButton {
|
||||
id: closeButton
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
implicitWidth: 30
|
||||
implicitHeight: 30
|
||||
text: "×"
|
||||
Accessible.name: "Close overview"
|
||||
onClicked: ShellState.overviewOpen = false
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
id: gridArea
|
||||
x: root.padding
|
||||
y: root.padding + root.header
|
||||
width: surface.contentWidth - 2 * root.padding
|
||||
height: root.layout.rows * root.thumbHeight + (root.layout.rows - 1) * root.gap
|
||||
|
||||
Repeater {
|
||||
model: root.layout.count
|
||||
delegate: Item {
|
||||
id: slot
|
||||
required property int index
|
||||
readonly property int workspaceId: index + 1
|
||||
readonly property string monitorName: root.monitorOf(workspaceId)
|
||||
readonly property var monitor: root.screenNamed(monitorName)
|
||||
readonly property bool focused: root.focusedId === workspaceId
|
||||
readonly property bool shownElsewhere: root.visibleIds.includes(workspaceId)
|
||||
readonly property bool chosen: root.selected === index
|
||||
readonly property bool dropTarget: root.dropSlot === index
|
||||
readonly property var windows: root.live ? HyprlandService.windows.filter(w => w.workspace === workspaceId).sort((a, b) => (a.floating - b.floating) || (a.active - b.active)) : []
|
||||
x: root.slotX(index)
|
||||
y: root.slotY(index)
|
||||
width: root.thumbWidth
|
||||
height: root.thumbHeight
|
||||
z: windows.some(w => w.address === root.dragAddress) ? 2 : 0
|
||||
scale: dropTarget ? 1.03 : 1
|
||||
Behavior on scale {
|
||||
NumberAnimation {
|
||||
duration: Theme.duration
|
||||
easing.type: Easing.OutCubic
|
||||
}
|
||||
}
|
||||
|
||||
ClippingRectangle {
|
||||
anchors.fill: parent
|
||||
radius: root.thumbRadius
|
||||
color: Theme.surfaceVariant
|
||||
Image {
|
||||
anchors.fill: parent
|
||||
source: root.live ? root.wallpaperFor(slot.monitorName) : ""
|
||||
sourceSize: Qt.size(Math.round(root.thumbWidth * 1.5), Math.round(root.thumbHeight * 1.5))
|
||||
fillMode: Image.PreserveAspectCrop
|
||||
asynchronous: true
|
||||
opacity: status === Image.Ready ? (slot.windows.length ? 0.55 : 0.4) : 0
|
||||
Behavior on opacity {
|
||||
NumberAnimation {
|
||||
duration: Theme.duration
|
||||
}
|
||||
}
|
||||
}
|
||||
// Empty workspaces show their number large.
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
visible: !slot.windows.length
|
||||
text: slot.workspaceId
|
||||
color: Qt.alpha(Theme.text, 0.35)
|
||||
font.pixelSize: root.thumbHeight * 0.38
|
||||
font.weight: Font.DemiBold
|
||||
}
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
color: workspaceArea.containsMouse && !root.dragAddress ? Theme.hover : Theme.transparent
|
||||
Behavior on color {
|
||||
ColorAnimation {
|
||||
duration: Theme.duration / 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
MouseArea {
|
||||
id: workspaceArea
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onContainsMouseChanged: if (containsMouse) {
|
||||
root.select(slot.index);
|
||||
root.hoveredTitle = "";
|
||||
}
|
||||
onClicked: root.go(slot.index)
|
||||
}
|
||||
|
||||
// Windows, scaled from their monitor into the thumbnail.
|
||||
// Keyed by address so title changes keep each live preview.
|
||||
Repeater {
|
||||
model: ScriptModel {
|
||||
values: slot.windows
|
||||
objectProp: "address"
|
||||
}
|
||||
delegate: Item {
|
||||
id: tile
|
||||
required property var modelData
|
||||
readonly property var win: slot.windows.find(w => w.address === modelData.address) || modelData
|
||||
readonly property var rect: Logic.project(win, slot.monitor ? {
|
||||
x: slot.monitor.x,
|
||||
y: slot.monitor.y,
|
||||
width: slot.monitor.width,
|
||||
height: slot.monitor.height
|
||||
} : null, root.thumbWidth, root.thumbHeight)
|
||||
readonly property bool dragging: root.dragAddress === win.address
|
||||
visible: !!rect
|
||||
x: rect ? rect.x : 0
|
||||
y: rect ? rect.y : 0
|
||||
width: rect ? Math.max(6, rect.width) : 0
|
||||
height: rect ? Math.max(6, rect.height) : 0
|
||||
z: dragging ? 10 : 0
|
||||
opacity: dragging ? 0.85 : 1
|
||||
ClippingRectangle {
|
||||
anchors.fill: parent
|
||||
anchors.margins: 1
|
||||
radius: Math.max(4, root.thumbRadius * 0.5)
|
||||
color: Qt.alpha(Theme.surface, 0.6)
|
||||
border.width: 1
|
||||
border.color: windowArea.containsMouse || tile.dragging ? Theme.accent : Theme.hairline
|
||||
ScreencopyView {
|
||||
id: preview
|
||||
anchors.fill: parent
|
||||
captureSource: root.live && tile.win.handle ? tile.win.handle : null
|
||||
live: root.live
|
||||
constraintSize: Qt.size(Math.round(tile.width * 2), Math.round(tile.height * 2))
|
||||
opacity: hasContent ? 1 : 0
|
||||
Behavior on opacity {
|
||||
NumberAnimation {
|
||||
duration: Theme.duration
|
||||
}
|
||||
}
|
||||
}
|
||||
// App icon: the whole tile until the preview arrives, a badge after.
|
||||
Rectangle {
|
||||
readonly property real size: preview.hasContent ? Math.min(26, Math.max(16, Math.min(tile.width, tile.height) * 0.28)) : Math.min(40, Math.min(tile.width, tile.height) * 0.5)
|
||||
visible: size >= 12
|
||||
width: size + 6
|
||||
height: size + 6
|
||||
radius: width / 2.6
|
||||
anchors.centerIn: preview.hasContent ? undefined : parent
|
||||
anchors.right: preview.hasContent ? parent.right : undefined
|
||||
anchors.bottom: preview.hasContent ? parent.bottom : undefined
|
||||
anchors.margins: 4
|
||||
color: preview.hasContent ? Qt.alpha(Theme.surface, 0.72) : Theme.transparent
|
||||
Image {
|
||||
anchors.centerIn: parent
|
||||
width: parent.size
|
||||
height: parent.size
|
||||
source: root.live ? root.iconFor(tile.win) : ""
|
||||
sourceSize: Qt.size(width * 2, height * 2)
|
||||
asynchronous: true
|
||||
}
|
||||
}
|
||||
}
|
||||
MouseArea {
|
||||
id: windowArea
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
acceptedButtons: Qt.LeftButton | Qt.MiddleButton
|
||||
cursorShape: tile.dragging ? Qt.ClosedHandCursor : Qt.PointingHandCursor
|
||||
drag.target: tile
|
||||
drag.threshold: 6
|
||||
onContainsMouseChanged: if (containsMouse) {
|
||||
root.select(slot.index);
|
||||
root.hoveredTitle = tile.win.title || tile.win.appId;
|
||||
} else if (root.hoveredTitle === (tile.win.title || tile.win.appId)) {
|
||||
root.hoveredTitle = "";
|
||||
}
|
||||
onPositionChanged: {
|
||||
if (drag.active && !tile.dragging)
|
||||
root.dragAddress = tile.win.address;
|
||||
if (!tile.dragging)
|
||||
return;
|
||||
const p = tile.mapToItem(gridArea, tile.width / 2, tile.height / 2);
|
||||
root.dropSlot = root.slotAt(p.x, p.y);
|
||||
}
|
||||
onReleased: {
|
||||
if (!tile.dragging)
|
||||
return;
|
||||
const target = root.dropSlot;
|
||||
root.dragAddress = "";
|
||||
root.dropSlot = -1;
|
||||
if (target >= 0 && target !== slot.index && HyprlandService.moveToWorkspace(tile.win.address, target + 1))
|
||||
return; // The window list update re-parents the tile.
|
||||
tile.x = Qt.binding(() => tile.rect ? tile.rect.x : 0);
|
||||
tile.y = Qt.binding(() => tile.rect ? tile.rect.y : 0);
|
||||
}
|
||||
onClicked: mouse => {
|
||||
if (mouse.button === Qt.MiddleButton) {
|
||||
HyprlandService.closeWindow(tile.win.address);
|
||||
return;
|
||||
}
|
||||
ShellState.overviewOpen = false;
|
||||
HyprlandService.focusWindow(tile.win.address);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Number chip, and the focus/selection rings.
|
||||
Rectangle {
|
||||
visible: slot.windows.length > 0
|
||||
x: 6
|
||||
y: parent.height - height - 6
|
||||
width: Math.max(height, chip.implicitWidth + 12)
|
||||
height: 20
|
||||
radius: 10
|
||||
color: slot.focused ? Theme.accent : Qt.alpha(Theme.surface, 0.72)
|
||||
Text {
|
||||
id: chip
|
||||
anchors.centerIn: parent
|
||||
text: slot.workspaceId
|
||||
color: slot.focused ? Theme.accentText : Theme.text
|
||||
font.pixelSize: 11
|
||||
font.weight: Font.DemiBold
|
||||
}
|
||||
}
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
anchors.margins: -3
|
||||
radius: root.thumbRadius + 3
|
||||
color: Theme.transparent
|
||||
border.width: slot.focused || slot.dropTarget ? 2 : slot.chosen || slot.shownElsewhere ? 1.5 : 1
|
||||
border.color: slot.focused || slot.dropTarget ? Theme.accent : slot.shownElsewhere ? Qt.alpha(Theme.accent, 0.6) : slot.chosen ? Qt.alpha(Theme.text, 0.55) : Theme.hairline
|
||||
Behavior on border.color {
|
||||
ColorAnimation {
|
||||
duration: Theme.duration / 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IpcHandler {
|
||||
target: "overview"
|
||||
function toggle(): void {
|
||||
ShellState.toggleOverview();
|
||||
}
|
||||
function open(): void {
|
||||
ShellState.openOverview();
|
||||
}
|
||||
function close(): void {
|
||||
ShellState.overviewOpen = false;
|
||||
}
|
||||
function status(): string {
|
||||
return JSON.stringify({
|
||||
opened: ShellState.overviewOpen,
|
||||
screen: root.screen ? root.screen.name : "",
|
||||
workspaces: root.layout.count,
|
||||
rows: root.layout.rows,
|
||||
columns: root.layout.columns,
|
||||
selected: root.selected + 1
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user