Preview a workspace live when hovering it in the bar

The bar popout shows the hovered workspace as on its monitor: the
wallpaper and a live capture of each window where it sits. A click on it
switches there. The focused workspace is not previewed. Settings -> Bar
-> Preview on hover turns it off (bar.workspaces.preview).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mxandClaude Opus 5.5 committed 2026-11-26 00:01:44 +01:00
1 parent 84c2385cfa
commit eb81d51c07
9 files changed
+231 -8

No files matched your search

+26 -3
View File
@@ -5,6 +5,8 @@ import Quickshell.Wayland
import Quickshell.Widgets
import "../components"
import "../core"
import "../overview"
import "../services"
import "../theme"
// Bar hover popout. HyprGlass shapes glass from the layer box, so the surface is
// sized to the card and its geometry animates to morph between anchors.
@@ -16,7 +18,7 @@ PanelWindow {
readonly property var anchorWindow: anchorItem ? anchorItem.QsWindow.window : null
readonly property string kind: PopoutState.kind
// The hovered window's Wayland toplevel; falls back to the focused one.
readonly property var toplevel: PopoutState.payload || ToplevelManager.activeToplevel
readonly property var toplevel: kind === "window" ? PopoutState.payload || ToplevelManager.activeToplevel : null
// Anchors may name a wider placement item (the tray pill, the window list)
// so the drawer stays put while the pointer moves between its entries.
readonly property var anchorObject: anchorItem
@@ -26,8 +28,9 @@ PanelWindow {
readonly property point windowPoint: placementItem && anchorWindow ? placementItem.mapToItem(anchorWindow.contentItem, 0, 0) : Qt.point(0, 0)
readonly property point anchorPoint: Qt.point(windowPoint.x + windowOffsetX, windowPoint.y)
readonly property real availableWidth: screen ? screen.width : 1280
readonly property real targetWidth: Math.ceil(root.kind === "window" ? windowCard.implicitWidth : tip.implicitWidth)
readonly property real targetHeight: Math.ceil(root.kind === "window" ? windowCard.implicitHeight : tip.implicitHeight)
readonly property Item card: kind === "window" ? windowCard : kind === "workspace" ? workspaceCard : tip
readonly property real targetWidth: Math.ceil(card.implicitWidth)
readonly property real targetHeight: Math.ceil(card.implicitHeight)
readonly property real targetX: BarDrawers.clampX(anchorPoint.x + (placementItem ? placementItem.width / 2 : 0), targetWidth + 2 * BarDrawers.ear, availableWidth)
// Morph only while the drawer is out; a cold open grows in place.
readonly property bool morph: drawer.progress > 0.05 && Theme.duration > 0
@@ -111,6 +114,26 @@ PanelWindow {
}
}
}
// A hovered workspace in the bar, live.
WorkspacePreview {
id: workspaceCard
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
workspaceId: root.kind === "workspace" ? PopoutState.payload || 0 : 0
live: root.active && root.kind === "workspace"
opacity: root.kind === "workspace" ? 1 : 0
visible: opacity > 0
Behavior on opacity {
NumberAnimation {
duration: Theme.duration / 2
}
}
onChosen: {
const id = workspaceId;
PopoutState.close();
HyprlandService.focusWorkspace(id);
}
}
Column {
id: windowCard
objectName: "windowPreview"
+26 -1
View File
@@ -19,6 +19,10 @@ GlassPill {
// Workspaces shown on other monitors get a faint outline.
readonly property var visibleIds: Hyprland.monitors.values.map(m => m.activeWorkspace ? m.activeWorkspace.id : 0).filter(id => id > 0 && id !== activeId)
readonly property int count: ConfigService.data.bar.workspaces.count
// Hovering a workspace shows it live in the bar popout (off for copies,
// like the one in Settings).
property bool hoverPreview: true
readonly property bool previews: hoverPreview && ConfigService.data.bar.workspaces.preview !== false
readonly property string notchStyle: entry && entry.notch && ConfigService.data.notch ? ConfigService.data.notch.workspaceStyle : "bar"
readonly property string style: notchStyle && notchStyle !== "bar" ? notchStyle : ConfigService.data.bar.workspaces.style || "numbers"
readonly property bool textual: style === "numbers" || style === "roman" || style === "kanji"
@@ -205,12 +209,33 @@ GlassPill {
}
}
}
// The focused workspace is already on screen; the rest preview.
HoverHandler {
enabled: root.previews
onHoveredChanged: {
if (hovered)
PopoutState.hover(slot, slot.active ? "" : "workspace", "", slot.index + 1);
else
PopoutState.unhover(slot);
}
}
Connections {
target: slot
function onActiveChanged() {
if (slot.active && PopoutState.anchor === slot)
PopoutState.close();
}
}
MouseArea {
id: pelletArea
anchors.fill: parent
hoverEnabled: root.pacman
cursorShape: Qt.PointingHandCursor
onClicked: Hyprland.dispatch("hl.dsp.focus({ workspace = '" + (slot.index + 1) + "' })")
onClicked: {
if (PopoutState.anchor === slot)
PopoutState.close();
Hyprland.dispatch("hl.dsp.focus({ workspace = '" + (slot.index + 1) + "' })");
}
}
}
}
+2 -1
View File
@@ -59,7 +59,8 @@
},
"workspaces": {
"count": 9,
"style": "numbers"
"style": "numbers",
"preview": true
},
"cava": {
"bars": 12,
+1 -1
View File
@@ -68,7 +68,7 @@ Singleton {
available: true,
group: "shell",
icon: "󰕮",
keywords: ["Bar height", "Margin", "Modules", "Show date", "24-hour time", "Show seconds", "Workspace count", "Workspace style", "Pacman", "Roman numerals", "Kanji", "Clock"]
keywords: ["Bar height", "Margin", "Modules", "Show date", "24-hour time", "Show seconds", "Workspace count", "Workspace style", "Preview on hover", "Pacman", "Roman numerals", "Kanji", "Clock"]
},
{
id: "notch",
+166
View File
@@ -0,0 +1,166 @@
pragma ComponentBehavior: Bound
import QtQuick
import Quickshell
import Quickshell.Hyprland
import Quickshell.Wayland
import Quickshell.Widgets
import "../services"
import "../theme"
import "OverviewLogic.js" as Logic
import "../services/AppMatching.js" as Matching
// A live miniature of one workspace, laid out as on its monitor: the
// wallpaper, then each window's live capture where it sits. Shown by the bar
// popout while a workspace in the bar is hovered; a click goes there.
Column {
id: root
property int workspaceId: 0
property bool live: false
// Thumbnail width; the height follows the monitor's aspect.
property real thumbWidth: 440
signal chosen
readonly property var workspace: Hyprland.workspaces.values.find(w => w.id === workspaceId) || null
readonly property string monitorName: workspace && workspace.monitor ? workspace.monitor.name : (Hyprland.focusedMonitor ? Hyprland.focusedMonitor.name : "")
readonly property var monitor: Quickshell.screens.find(s => s.name === monitorName) || null
readonly property real aspect: monitor && monitor.height > 0 ? monitor.width / monitor.height : 16 / 9
// Portrait monitors keep the same longest side.
readonly property real frameWidth: aspect >= 1 ? thumbWidth : Math.round(thumbWidth * aspect)
readonly property real frameHeight: Math.round(frameWidth / aspect)
readonly property var windows: live ? HyprlandService.windows.filter(w => w.workspace === workspaceId).sort((a, b) => (a.floating - b.floating) || (a.active - b.active)) : []
padding: 12
spacing: 10
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");
}
// Window geometry is not pushed on resize; read it fresh for each preview.
onWorkspaceIdChanged: if (live)
HyprlandService.refresh()
onLiveChanged: if (live)
HyprlandService.refresh()
Item {
width: root.frameWidth
height: header.implicitHeight
Text {
id: header
anchors.left: parent.left
anchors.right: count.left
anchors.rightMargin: 10
text: "Workspace " + root.workspaceId
color: Theme.text
font.pixelSize: 13
font.weight: Font.DemiBold
elide: Text.ElideRight
}
Text {
id: count
anchors.right: parent.right
anchors.baseline: header.baseline
text: root.windows.length === 0 ? "Empty" : root.windows.length === 1 ? "1 window" : root.windows.length + " windows"
color: Theme.textSecondary
font.pixelSize: 11
}
}
ClippingRectangle {
id: frame
objectName: "workspacePreview"
width: root.frameWidth
height: root.frameHeight
radius: Math.max(8, Theme.radius * 0.55)
color: Theme.surfaceVariant
border.width: 1
border.color: Theme.hairline
Image {
anchors.fill: parent
source: root.live ? root.wallpaperFor(root.monitorName) : ""
sourceSize: Qt.size(Math.round(root.frameWidth * 1.5), Math.round(root.frameHeight * 1.5))
fillMode: Image.PreserveAspectCrop
asynchronous: true
opacity: status === Image.Ready ? 0.6 : 0
Behavior on opacity {
NumberAnimation {
duration: Theme.duration
}
}
}
Text {
anchors.centerIn: parent
visible: !root.windows.length
text: root.workspaceId
color: Qt.alpha(Theme.text, 0.35)
font.pixelSize: root.frameHeight * 0.38
font.weight: Font.DemiBold
}
// Keyed by address so title changes keep each live capture.
Repeater {
model: ScriptModel {
values: root.windows
objectProp: "address"
}
delegate: Item {
id: tile
required property var modelData
readonly property var win: root.windows.find(w => w.address === modelData.address) || modelData
readonly property var rect: Logic.project(win, root.monitor ? {
x: root.monitor.x,
y: root.monitor.y,
width: root.monitor.width,
height: root.monitor.height
} : null, root.frameWidth, root.frameHeight)
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
ClippingRectangle {
anchors.fill: parent
anchors.margins: 1
radius: 6
color: Qt.alpha(Theme.surface, 0.6)
border.width: 1
border.color: tileHover.hovered ? Theme.accent : Theme.hairline
ScreencopyView {
id: capture
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 capture arrives, a badge after.
Image {
readonly property real size: capture.hasContent ? Math.min(22, Math.max(14, Math.min(tile.width, tile.height) * 0.26)) : Math.min(36, Math.min(tile.width, tile.height) * 0.5)
visible: size >= 12
width: size
height: size
x: capture.hasContent ? parent.width - width - 4 : (parent.width - width) / 2
y: capture.hasContent ? parent.height - height - 4 : (parent.height - height) / 2
source: root.live ? root.iconFor(tile.win) : ""
sourceSize: Qt.size(width * 2, height * 2)
asynchronous: true
}
}
HoverHandler {
id: tileHover
}
}
}
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: root.chosen()
}
}
}
+1
View File
@@ -24,6 +24,7 @@ function validate(c) {
if (typeof c.animation.reducedMotion !== "boolean" || !Number.isFinite(c.animation.duration) || c.animation.duration < 0 || c.animation.duration > 1000) throw Error("Invalid animation settings");
if (!Number.isFinite(c.bar.height) || c.bar.height < 32 || c.bar.height > 80 || !Number.isFinite(c.bar.margin) || c.bar.margin < 0 || c.bar.margin > 100) throw Error("Invalid bar geometry");
if(!Number.isInteger(c.bar.workspaces.count) || c.bar.workspaces.count<1 || c.bar.workspaces.count>20 || !["numbers","roman","kanji","dots","pacman"].includes(c.bar.workspaces.style) || ["showDate","use24Hour","showSeconds"].some(k=>typeof c.bar.clock[k]!=="boolean"))throw Error("Invalid bar module options");
if(typeof c.bar.workspaces.preview!=="boolean")throw Error("Invalid workspace preview toggle");
const cava=c.bar.cava;
if(!cava || !Number.isInteger(cava.bars) || cava.bars<4 || cava.bars>24 || !["bars","mirror"].includes(cava.style) || typeof cava.hideWhenIdle!=="boolean")throw Error("Invalid bar visualizer preferences");
const validModules = list => {
+7
View File
@@ -139,6 +139,12 @@ SettingsPage {
setting: "bar.workspaces.style"
choices: ["numbers", "roman", "kanji", "dots", "pacman"]
}
PreferenceToggle {
label: "Preview on hover"
description: "Hovering a workspace shows its windows live; click the preview to go there"
icon: "󰕮"
setting: "bar.workspaces.preview"
}
SettingRow {
title: "Preview"
description: "Live workspaces; the outline marks a workspace shown on another monitor"
@@ -151,6 +157,7 @@ SettingsPage {
Bar.WorkspacesModule {
id: preview
objectName: "workspacesPreview"
hoverPreview: false
barScreen: ScreenService.active
transformOrigin: Item.TopLeft
scale: Math.min(1, previewBox.width / width)