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>
167 lines
7.1 KiB
QML
167 lines
7.1 KiB
QML
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()
|
|
}
|
|
}
|
|
}
|