much nicer preview

This commit is contained in:
ari committed 2026-09-23 13:53:17 -04:00
1 parent d13bfda1f9
commit fbe56658b6
8 files changed
+311 -26

No files matched your search

+4
View File
@@ -25,7 +25,11 @@ def ws-ipc [fn: string] {
# Run the workspace manager
def "main workspace-manager" [
--daemon (-d) # detach from the terminal
--config (-c): string # path to JSON config, optional
] {
if $config != null {
$env.SKYG_WORKSPACE_MANAGER = ($config | path expand)
}
if $daemon {
qs -d -n -p $WS_PATH
} else {
+12
View File
@@ -0,0 +1,12 @@
{
"keys": {
"rename": "Ctrl+N",
"windows": "Ctrl+G"
},
"hints": {
"show": true,
"rename": "{key}: to switch here",
"windows": "{key}: to see windows",
"exitWindows": "{key} or Esc: to exit window carousel"
}
}
+151
View File
@@ -0,0 +1,151 @@
import QtQuick
import Quickshell
import Quickshell.Io
// Settings read from the JSON file named by SKYG_WORKSPACE_MANAGER.
// The file is optional. Anything missing or wrong falls back to the
// values in load(). The file is read again whenever it changes.
Item {
id: root
readonly property string configPath: Quickshell.env("SKYG_WORKSPACE_MANAGER") ?? ""
// Keys written as modifiers plus one key, like "Ctrl+N".
property string renameKey
property string windowsKey
property bool showHints
// "{key}" in a hint is replaced by its key.
property string renameHint
property string windowsHint
property string exitWindowsHint
readonly property string renameHintText: root.fillKey(root.renameHint, root.renameKey)
readonly property string windowsHintText: root.fillKey(root.windowsHint, root.windowsKey)
readonly property string exitWindowsHintText: root.fillKey(root.exitWindowsHint, root.windowsKey)
Component.onCompleted: root.load({})
function fillKey(hint: string, key: string): string {
return hint.split("{key}").join(key);
}
function warn(message: string): void {
console.warn("workspace-manager config: " + message);
}
// Parsed JSON, so the values stay untyped.
function textOr(value, fallback: string, name: string): string {
if (value === undefined)
return fallback;
if (typeof value !== "string") {
root.warn(name + " should be a string");
return fallback;
}
return value;
}
function boolOr(value, fallback: bool, name: string): bool {
if (value === undefined)
return fallback;
if (typeof value !== "boolean") {
root.warn(name + " should be true or false");
return fallback;
}
return value;
}
function keyOr(value, fallback: string, name: string): string {
const text = root.textOr(value, fallback, name);
if (root.keyOf(text) < 0) {
root.warn(name + ": \"" + text + "\" is not a key this understands");
return fallback;
}
return text;
}
function load(parsed): void {
const keys = parsed.keys ?? {};
const hints = parsed.hints ?? {};
root.renameKey = root.keyOr(keys.rename, "Ctrl+N", "keys.rename");
root.windowsKey = root.keyOr(keys.windows, "Ctrl+G", "keys.windows");
root.showHints = root.boolOr(hints.show, true, "hints.show");
root.renameHint = root.textOr(hints.rename, "{key}: to switch here", "hints.rename");
root.windowsHint = root.textOr(hints.windows, "{key}: to see windows", "hints.windows");
root.exitWindowsHint = root.textOr(hints.exitWindows, "{key} or Esc: to exit window carousel", "hints.exitWindows");
}
// ── keys ────────────────────────────────────────────────────────────
function modifiersOf(combo: string): int {
let mods = 0;
for (const part of combo.split("+")) {
const name = part.trim().toLowerCase();
if (name === "ctrl" || name === "control")
mods |= Qt.ControlModifier;
else if (name === "alt")
mods |= Qt.AltModifier;
else if (name === "shift")
mods |= Qt.ShiftModifier;
else if (name === "meta" || name === "super")
mods |= Qt.MetaModifier;
}
return mods;
}
// Qt key code of the one key that is not a modifier, or -1.
function keyOf(combo: string): int {
let code = -1;
for (const part of combo.split("+")) {
const name = part.trim().toUpperCase();
if (["CTRL", "CONTROL", "ALT", "SHIFT", "META", "SUPER"].includes(name))
continue;
if (code >= 0)
return -1;
// Qt codes for letters and digits match their ASCII codes.
if (/^[A-Z0-9]$/.test(name))
code = name.charCodeAt(0);
else if (/^F([1-9]|1[0-2])$/.test(name))
code = Qt.Key_F1 + Number(name.slice(1)) - 1;
else if (name === "SPACE")
code = Qt.Key_Space;
else if (name === "TAB")
code = Qt.Key_Tab;
else
return -1;
}
return code;
}
// Whether a key press is exactly this combo, with no extra modifiers.
function matches(event, combo: string): bool {
const code = root.keyOf(combo);
if (code < 0 || event.key !== code)
return false;
const known = Qt.ControlModifier | Qt.AltModifier | Qt.ShiftModifier | Qt.MetaModifier;
return (event.modifiers & known) === root.modifiersOf(combo);
}
FileView {
id: configFile
path: root.configPath
watchChanges: true
onFileChanged: configFile.reload()
onLoaded: {
try {
const parsed = JSON.parse(configFile.text());
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
throw new Error("expected a JSON object");
root.load(parsed);
} catch (error) {
root.warn(String(error));
root.load({});
}
}
onLoadFailed: {
if (root.configPath.length > 0)
root.warn("could not read " + root.configPath);
root.load({});
}
}
}
+55 -13
View File
@@ -9,6 +9,7 @@ PanelWindow {
required property bool shellOpen
required property Compositor compositor
required property Theme theme
required property Config config
// Focus the name field as soon as the carousel has its data.
required property bool renameOnOpen
// Open the window loop on the focused workspace as soon as the carousel
@@ -51,6 +52,12 @@ PanelWindow {
property int loopWorkspaceId: -1
// Escape folds the loop back into the carousel, instead of closing.
property bool canCollapse: true
// Half the shown height of a workspace right above or below the loop,
// after its shrink and its tilt.
readonly property real neighbourHalfHeight: {
const shrink = 1 - Math.min(root.theme.carouselScaleStep, root.theme.carouselMaxScaleReduction);
return root.theme.cardHeight / 2 * shrink * Math.cos(root.theme.loopTiltX * Math.PI / 180);
}
function workspaceIndexAt(index: int): int {
const list = root.workspaceIndices;
@@ -168,9 +175,7 @@ PanelWindow {
// ── window loop helpers ─────────────────────────────────────────────
function isWindowsKey(event): bool {
const mods = event.modifiers;
const ctrl = (mods & Qt.ControlModifier) && !(mods & Qt.AltModifier) && !(mods & Qt.MetaModifier);
return event.key === Qt.Key_B && ctrl;
return root.config.matches(event, root.config.windowsKey);
}
// Open the loop on the selected workspace. The other cards move away.
@@ -211,9 +216,7 @@ PanelWindow {
}
function isToggleRenameKey(event): bool {
const mods = event.modifiers;
const ctrl = (mods & Qt.ControlModifier) && !(mods & Qt.AltModifier) && !(mods & Qt.MetaModifier);
return event.key === Qt.Key_G && ctrl;
return root.config.matches(event, root.config.renameKey);
}
function applyRename(): void {
@@ -359,7 +362,7 @@ PanelWindow {
event.accepted = true;
}
// Ctrl+G toggles back to carousel.
// The rename key toggles back to carousel.
Keys.onShortcutOverride: event => {
if (root.isToggleRenameKey(event))
event.accepted = true;
@@ -397,6 +400,15 @@ PanelWindow {
}
}
}
KeyHint {
anchors.right: parent.right
anchors.top: parent.bottom
anchors.topMargin: root.theme.hintGap
theme: root.theme
hint: root.config.renameHintText
shown: root.config.showHints && !root.nameFieldActive
}
}
// ── carousel ────────────────────────────────────────────────────────
@@ -407,14 +419,14 @@ PanelWindow {
focus: root.visible
Keys.onPressed: event => {
// Ctrl+G toggles to rename mode.
// The rename key toggles to rename mode.
if (root.isToggleRenameKey(event)) {
root.enterRename();
event.accepted = true;
return;
}
// Ctrl+B opens or folds the window loop on the selected workspace.
// The windows key opens or folds the window loop on the selected workspace.
if (root.isWindowsKey(event)) {
if (root.windowsOpen)
root.collapseWindows();
@@ -547,7 +559,9 @@ PanelWindow {
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
width: root.theme.cardWidth
z: column.isCurrentColumn ? 1 : 0
// While the loop is open, the current column draws over it,
// so the workspace above stays visible over the back windows.
z: column.isCurrentColumn ? (root.windowsOpen ? 3 : 1) : 0
opacity: {
const fade = 1 - Math.min(Math.abs(column.columnIndex - root.monitorIndex) * root.theme.carouselMonitorFadeStep, root.theme.carouselMonitorMaxFade);
return root.windowsOpen && !column.isCurrentColumn ? fade * root.theme.loopHiddenFade : fade;
@@ -633,8 +647,16 @@ PanelWindow {
readonly property int distance: Math.abs(index - column.selectedWs)
// This card turns into the window loop.
readonly property bool opensLoop: root.windowsOpen && card.selected
// Cards above and below the loop move out of its way.
readonly property real spreadY: root.windowsOpen && column.isCurrentColumn ? Math.sign(index - column.selectedWs) * root.theme.loopSpreadY : 0
// Cards above and below the loop move so the nearest
// ones sit a small gap from the front window. Cards
// further out keep the normal step from those.
readonly property real spreadY: {
const steps = index - column.selectedWs;
if (!root.windowsOpen || !column.isCurrentColumn || steps === 0)
return 0;
const nearest = steps < 0 ? windowLoop.frontTop - root.theme.loopWorkspaceGap - root.neighbourHalfHeight : windowLoop.frontBottom + root.theme.loopWorkspaceGap + root.neighbourHalfHeight;
return nearest - Math.sign(steps) * root.theme.carouselStepY;
}
// They also lean back: the top edge away above the
// loop, the bottom edge away below it.
readonly property real tiltX: root.windowsOpen && column.isCurrentColumn ? -Math.sign(index - column.selectedWs) * root.theme.loopTiltX : 0
@@ -655,7 +677,14 @@ PanelWindow {
opacity: {
if (card.opensLoop)
return 0;
return root.windowsOpen ? card.baseOpacity * root.theme.loopHiddenFade : card.baseOpacity;
if (!root.windowsOpen)
return card.baseOpacity;
if (!column.isCurrentColumn)
return card.baseOpacity * root.theme.loopHiddenFade;
// The two right next to the loop skip the fade by distance.
if (card.distance === 1)
return root.theme.loopNeighbourFade;
return card.baseOpacity * root.theme.loopNeighbourFade;
}
scale: card.opensLoop ? 1 / root.theme.loopStartScale : card.baseScale
z: card.selected ? 1 : 0
@@ -683,6 +712,18 @@ PanelWindow {
onActivated: root.activateAt(column.columnIndex, index)
}
}
// Under the selected workspace, which always sits in the
// middle of the column and is as wide as it.
KeyHint {
anchors.right: parent.right
anchors.top: parent.verticalCenter
anchors.topMargin: root.theme.cardHeight / 2 + root.theme.hintGap
z: 3
theme: root.theme
hint: root.config.windowsHintText
shown: root.config.showHints && column.isCurrentColumn && !root.windowsOpen && column.workspaces.length > 0
}
}
}
@@ -695,6 +736,7 @@ PanelWindow {
theme: root.theme
workspaceId: root.loopWorkspaceId
expanded: root.windowsOpen
exitHint: root.config.showHints ? root.config.exitWindowsHintText : ""
onWindowChosen: root.requestClose()
}
}
+22
View File
@@ -0,0 +1,22 @@
import QtQuick
// A short line of text that names a key and what it does.
Text {
id: root
required property Theme theme
required property string hint
required property bool shown
color: root.theme.labelColor
font.pixelSize: root.theme.hintSize
text: root.hint
opacity: root.shown && root.hint.length > 0 ? 1 : 0
visible: root.opacity > 0
Behavior on opacity {
NumberAnimation {
duration: root.theme.hintFadeDuration
}
}
}
+17 -4
View File
@@ -61,7 +61,13 @@ QtObject {
readonly property real windowRowSpacing: 6
readonly property int maxWindowRows: 3
// ── window loop (Ctrl+B) ────────────────────────────────────────────
// Key hints. They sit under the rename bar, the selected workspace and
// the front window, this far below each.
readonly property real hintSize: 12
readonly property real hintGap: 8
readonly property int hintFadeDuration: 160
// ── window loop ─────────────────────────────────────────────────────
// Live previews on Hyprland.
readonly property bool livePreviews: true
@@ -72,11 +78,13 @@ QtObject {
readonly property bool snapshotPreviewsNiri: true
// While the loop is open, other monitors sit this far past its edge,
// and workspaces above and below move out by loopSpreadY.
// and workspaces above and below sit this far from the front window.
readonly property real loopEdgeGap: 40
readonly property real loopSpreadY: 60
// Extra fade on those cards while the loop is open.
readonly property real loopWorkspaceGap: 10
// Extra fade on those cards while the loop is open. The workspaces
// right above and below use loopNeighbourFade.
readonly property real loopHiddenFade: 0.75
readonly property real loopNeighbourFade: 0.9
// Tilt in degrees while the loop is open, so the other cards look part
// of the same 3D scene. Workspaces above and below lean back as if on a
// drum; other monitors turn to face the middle.
@@ -109,6 +117,11 @@ QtObject {
// Share of the screen width the loop may take on each side of center.
readonly property real loopMaxRadiusShare: 0.42
// About how far round the loop, in degrees, a card turns edge-on and
// flips to its inner face. It is moved to fall between two cards, so
// none rests edge-on. Bigger means flatter cards at the sides.
readonly property real loopFlipAngle: 120
// How strongly far cards shrink. Bigger means a flatter loop.
readonly property real loopFocalLength: 1400
// How far the back of the loop is raised, so it shows above the front.
+45 -9
View File
@@ -12,6 +12,8 @@ Item {
required property int workspaceId
// Shown and taking input. Fades and grows in when this turns on.
required property bool expanded
// Shown on the top edge of the front window, "" for none.
required property string exitHint
// A window was focused.
signal windowChosen
@@ -43,12 +45,27 @@ Item {
for (let i = 1; i <= 16; i++) {
const angle = i / 16 * Math.PI / 2;
const depthScale = focal / (focal + root.radius * (1 - Math.cos(angle)));
const edge = (root.radius * Math.sin(angle) + half * Math.cos(angle)) * depthScale;
const faceWidth = Math.abs(Math.cos(root.faceTurn(angle) * Math.PI / 180));
const edge = (root.radius * Math.sin(angle) + half * faceWidth) * depthScale;
widest = Math.max(widest, edge);
}
return widest;
}
// Top and bottom edges of the front window, from the middle of the view.
readonly property real frontTop: root.theme.loopBackLift / 2 - root.theme.loopCardHeight / 2
readonly property real frontBottom: root.theme.loopBackLift / 2 + root.theme.loopCardHeight / 2
// Where round the loop, in degrees, cards turn edge-on. Halfway between
// two cards, so none rests edge-on.
readonly property real flipAngle: {
if (root.count <= 1)
return 90;
const stepDegrees = 360 / root.count;
const flip = (Math.floor(root.theme.loopFlipAngle / stepDegrees) + 0.5) * stepDegrees;
return Math.min(flip, 180);
}
// Selected step. It is not wrapped, so the loop can keep turning the
// same way. Use selectedIndex for the position in the window list.
property int targetStep: 0
@@ -121,6 +138,19 @@ Item {
return steps * root.angleStep;
}
// How far a card at this angle (radians) turns, in degrees. It turns
// from facing the viewer at the front to edge-on at flipAngle, then on
// round to face the viewer again at the back, showing its inner face.
function faceTurn(angle: real): real {
const degrees = Math.abs(angle) * 180 / Math.PI;
const side = angle < 0 ? -1 : 1;
const flip = root.flipAngle;
if (degrees <= flip || flip >= 180)
return -side * 90 * degrees / flip;
const turn = 90 + 90 * (degrees - flip) / (180 - flip);
return -side * (turn - 180);
}
// Select the focused window, or the first one, and turn into place.
function seed(): void {
const list = root.windows;
@@ -197,14 +227,9 @@ Item {
readonly property real back: (1 - card.cosA) / 2
// Simple perspective: cards farther away get smaller.
readonly property real depthScale: root.theme.loopFocalLength / (root.theme.loopFocalLength + 2 * root.radius * card.back)
// Turn so each card lies along the loop. The front half
// shows the outer face, the back half the inner face.
readonly property real faceAngle: {
const degrees = card.angle * 180 / Math.PI;
if (card.cosA >= 0)
return -degrees;
return degrees > 0 ? 180 - degrees : -180 - degrees;
}
// Turn so each card roughly lies along the loop, less so
// at the sides, so they can still be seen.
readonly property real faceAngle: root.faceTurn(card.angle)
theme: root.theme
title: card.modelData.title
@@ -238,5 +263,16 @@ Item {
onActivated: root.activateAt(card.index)
}
}
// Under the front window. Cards stay below z 1.
KeyHint {
id: exitHintText
x: root.theme.loopCardWidth / 2 - exitHintText.width
y: root.theme.loopCardHeight / 2 + root.theme.hintGap
z: 2
theme: root.theme
hint: root.exitHint
shown: root.count > 0
}
}
}
+5
View File
@@ -22,6 +22,10 @@ ShellRoot {
id: theme
}
Config {
id: config
}
Component.onCompleted: {
if (compositor.kind === "")
console.warn("workspace-manager: neither niri nor Hyprland was detected");
@@ -73,6 +77,7 @@ ShellRoot {
shellOpen: shell.open
compositor: compositor
theme: theme
config: config
renameOnOpen: shell.renameOnOpen
openWindowsOnOpen: shell.openWindowsOnOpen
onRequestClose: shell.closeAll()