selector
This commit is contained in:
1 parent
52ba041313
commit
bb7fc1cb44
14 files changed
+1387
-1
No files matched your search
@@ -6,13 +6,16 @@ A small collection of desktop tools built with [Quickshell](https://quickshell.o
|
||||
for Wayland compositors that speak [niri](https://github.com/YaLTeR/niri) or
|
||||
[Hyprland](https://hyprland.org/).
|
||||
|
||||
It ships two apps:
|
||||
It ships three apps:
|
||||
|
||||
- **app-carousel** — a full-screen launcher carousel. Apps sit in a row; the
|
||||
one in the middle is selected. Configure it with a JSON file.
|
||||
- **workspace-manager** — a workspace overview. A carousel of workspace cards
|
||||
(with a live list of their windows), a bar for renaming the current
|
||||
workspace, and a 3D "window loop" for picking a window.
|
||||
- **workspace-badge** — a small box in each bottom corner of every
|
||||
monitor showing the active workspace's name and color. Click one to rename
|
||||
the workspace or pick a color.
|
||||
|
||||
Everything here is QML. Talking to the compositor goes through its command
|
||||
line tools (`niri msg`, `hyprctl`), so the code is the same on both.
|
||||
@@ -66,6 +69,9 @@ SKYG_APP_CAROUSEL=/path/to/app-carousel.json qs -p ./app-carousel
|
||||
|
||||
# workspace manager
|
||||
qs -n -p ./workspace-manager
|
||||
|
||||
# workspace badge
|
||||
qs -n -p ./workspace-badge
|
||||
```
|
||||
|
||||
---
|
||||
@@ -86,6 +92,9 @@ qs -n -p ./workspace-manager
|
||||
| `skygqts workspace-manager goto` | Opens the workspace carousel |
|
||||
| `skygqts workspace-manager windows` | Opens the window loop for the focused workspace |
|
||||
| `skygqts workspace-manager rename` | Opens the carousel with the name field focused |
|
||||
| `skygqts workspace-badge` | Shows the workspace badge on every monitor |
|
||||
| `skygqts workspace-badge --daemon` | Same, but detached from the terminal |
|
||||
| `skygqts workspace-badge edit` | Opens the badge editor on the focused monitor |
|
||||
|
||||
The last four talk to an already-running workspace manager over IPC, so start
|
||||
it as a daemon first (for example from your compositor's startup):
|
||||
@@ -112,6 +121,8 @@ qs ipc -p ./workspace-manager call workspace goTo
|
||||
qs ipc -p ./workspace-manager call workspace openWindowSelection
|
||||
qs ipc -p ./workspace-manager call workspace openWorkspaceRename
|
||||
|
||||
qs ipc -p ./workspace-badge call badge edit
|
||||
|
||||
qs ipc -p ./app-carousel call launcher toggle
|
||||
qs ipc -p ./app-carousel call launcher open
|
||||
qs ipc -p ./app-carousel call launcher close
|
||||
@@ -290,12 +301,49 @@ These are toggled by the `livePreviews`, `snapshotPreviewsHyprland`, and
|
||||
|
||||
---
|
||||
|
||||
## Workspace badge
|
||||
|
||||
```sh
|
||||
skygqts workspace-badge --daemon
|
||||
```
|
||||
|
||||
Two small glass boxes, one in each bottom corner of every monitor. Both
|
||||
show the name of the workspace active on that monitor (or its number when it
|
||||
has no name), on a background of that workspace's color. Each box has a round
|
||||
top corner facing into the screen and curves where it runs into the screen
|
||||
edges, as if it grows out of the corner.
|
||||
|
||||
Click either box to open the editor in the middle of the screen:
|
||||
|
||||
- **Rename workspace** — Enter or OK applies the name. An empty name clears
|
||||
it (on Hyprland it goes back to the number).
|
||||
- **Color** — pick a swatch, drag along the hue strip, or type a hex value
|
||||
like `#7aa2f7`. Below it, the **Opacity** slider sets how solid the badge
|
||||
background is (80% by default). The badge changes right away.
|
||||
|
||||
Escape or a click anywhere else closes it.
|
||||
|
||||
Colors and opacity are saved per workspace in
|
||||
`$XDG_STATE_HOME/skygqts/workspace-colors.json` (or
|
||||
`~/.local/state/skygqts/...`), as entries like
|
||||
`{ "color": "#ffd60a", "opacity": 0.8 }`. Named workspaces are saved by name,
|
||||
and the entry moves along when you rename one from the badge. Unnamed
|
||||
workspaces are saved by id; niri gives out new ids after a restart, so name a
|
||||
workspace if its color should stick.
|
||||
|
||||
On niri, renaming a workspace that has no name first focuses its monitor,
|
||||
because niri can only point at an unnamed workspace through the focused
|
||||
monitor.
|
||||
|
||||
---
|
||||
|
||||
## Theming
|
||||
|
||||
Colors, sizes, and animation timings live in one place per app:
|
||||
|
||||
- `app-carousel/Theme.qml`
|
||||
- `workspace-manager/Theme.qml`
|
||||
- `workspace-badge/Theme.qml`
|
||||
|
||||
Edit those files to restyle the carousel, glass effect, hints, and window
|
||||
loop.
|
||||
@@ -305,6 +353,7 @@ loop.
|
||||
```
|
||||
app-carousel/ # launcher: shell.qml, config, theme, cards
|
||||
workspace-manager/ # overview: carousel, rename bar, window loop, compositor bridge
|
||||
workspace-badge/ # corner badge: name, color, rename and color editor
|
||||
skygqts.nu # the `skygqts` CLI (Nushell)
|
||||
package.nix # package definition
|
||||
flake.nix # flake: package, overlay, dev shell
|
||||
|
||||
@@ -17,6 +17,7 @@ stdenvNoCC.mkDerivation {
|
||||
fileset = lib.fileset.unions [
|
||||
./app-carousel
|
||||
./workspace-manager
|
||||
./workspace-badge
|
||||
./skygqts.nu
|
||||
];
|
||||
};
|
||||
@@ -30,6 +31,7 @@ stdenvNoCC.mkDerivation {
|
||||
mkdir -p $out/share/skygqts
|
||||
cp -r app-carousel $out/share/skygqts/
|
||||
cp -r workspace-manager $out/share/skygqts/
|
||||
cp -r workspace-badge $out/share/skygqts/
|
||||
cp skygqts.nu $out/share/skygqts/
|
||||
mkdir -p $out/bin
|
||||
makeWrapper ${lib.getExe nushell} $out/bin/skygqts \
|
||||
|
||||
+18
@@ -56,3 +56,21 @@ def "main workspace-manager windows" [] {
|
||||
def "main workspace-manager rename" [] {
|
||||
ws-ipc "openWorkspaceRename"
|
||||
}
|
||||
|
||||
const BADGE_PATH = $REPO_ROOT | path join "workspace-badge"
|
||||
|
||||
# Run the workspace badge: a small box in the corner of each monitor
|
||||
def "main workspace-badge" [
|
||||
--daemon (-d) # detach from the terminal
|
||||
] {
|
||||
if $daemon {
|
||||
qs -d -n -p $BADGE_PATH
|
||||
} else {
|
||||
qs -n -p $BADGE_PATH
|
||||
}
|
||||
}
|
||||
|
||||
# Open the badge editor on the focused monitor
|
||||
def "main workspace-badge edit" [] {
|
||||
qs ipc -p $BADGE_PATH call badge edit
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
|
||||
// One monitor's badges, one in each bottom corner, and the editor they open.
|
||||
Scope {
|
||||
id: root
|
||||
|
||||
required property ShellScreen modelData
|
||||
required property Compositor compositor
|
||||
required property ColorStore store
|
||||
required property Theme theme
|
||||
|
||||
// The workspace active on this monitor, or null when unknown.
|
||||
// An entry from Compositor.outputs, so this stays untyped.
|
||||
readonly property var info: root.compositor.outputs[root.modelData.name] ?? null
|
||||
readonly property int wsId: root.info ? root.info.id : -1
|
||||
readonly property int wsIdx: root.info ? root.info.idx : -1
|
||||
readonly property string wsName: root.info ? root.info.name : ""
|
||||
// Workspaces without a name show their number.
|
||||
readonly property string label: root.wsName.length > 0 ? root.wsName : String(root.wsIdx)
|
||||
readonly property string colorKey: root.store.keyFor(root.wsId, root.wsName)
|
||||
readonly property color wsColor: root.store.colorFor(root.colorKey)
|
||||
readonly property real wsOpacity: root.store.opacityFor(root.colorKey)
|
||||
// Rough brightness of the color, so the text can stay readable on it.
|
||||
readonly property bool lightColor: 0.299 * root.wsColor.r + 0.587 * root.wsColor.g + 0.114 * root.wsColor.b > 0.6
|
||||
|
||||
function openEditor(): void {
|
||||
if (!root.info)
|
||||
return;
|
||||
popup.openFor(root.modelData.name, root.wsId, root.wsName, root.colorKey);
|
||||
}
|
||||
|
||||
BadgeBox {
|
||||
screen: root.modelData
|
||||
visible: root.info !== null
|
||||
theme: root.theme
|
||||
leftSide: false
|
||||
label: root.label
|
||||
boxColor: root.wsColor
|
||||
boxOpacity: root.wsOpacity
|
||||
textColor: root.lightColor ? root.theme.badgeTextOnLight : root.theme.badgeTextOnDark
|
||||
onClicked: root.openEditor()
|
||||
}
|
||||
|
||||
BadgeBox {
|
||||
screen: root.modelData
|
||||
visible: root.info !== null
|
||||
theme: root.theme
|
||||
leftSide: true
|
||||
label: root.label
|
||||
boxColor: root.wsColor
|
||||
boxOpacity: root.wsOpacity
|
||||
textColor: root.lightColor ? root.theme.badgeTextOnLight : root.theme.badgeTextOnDark
|
||||
onClicked: root.openEditor()
|
||||
}
|
||||
|
||||
EditPopup {
|
||||
id: popup
|
||||
screen: root.modelData
|
||||
compositor: root.compositor
|
||||
store: root.store
|
||||
theme: root.theme
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Wayland
|
||||
|
||||
// One badge in a bottom corner of the screen. leftSide picks the corner.
|
||||
PanelWindow {
|
||||
id: root
|
||||
|
||||
required property Theme theme
|
||||
required property bool leftSide
|
||||
required property string label
|
||||
required property color boxColor
|
||||
// Opacity of boxColor behind the text, 0 to 1.
|
||||
required property real boxOpacity
|
||||
required property color textColor
|
||||
|
||||
signal clicked
|
||||
|
||||
color: "transparent"
|
||||
|
||||
anchors {
|
||||
bottom: true
|
||||
left: root.leftSide
|
||||
right: !root.leftSide
|
||||
}
|
||||
|
||||
margins {
|
||||
bottom: root.theme.badgeMargin
|
||||
left: root.theme.badgeMargin
|
||||
right: root.theme.badgeMargin
|
||||
}
|
||||
|
||||
// One flare bigger than the box, so the curves fit.
|
||||
implicitWidth: body.width + root.theme.badgeFlare
|
||||
implicitHeight: body.height + root.theme.badgeFlare
|
||||
|
||||
exclusionMode: ExclusionMode.Ignore
|
||||
WlrLayershell.namespace: "quickshell:workspace-badge"
|
||||
WlrLayershell.layer: WlrLayer.Top
|
||||
WlrLayershell.keyboardFocus: WlrKeyboardFocus.None
|
||||
|
||||
// Only the box takes clicks. The space around the curves lets them through.
|
||||
mask: Region {
|
||||
item: body
|
||||
}
|
||||
|
||||
FlareGlass {
|
||||
anchors.fill: parent
|
||||
theme: root.theme
|
||||
tint: Qt.rgba(root.boxColor.r, root.boxColor.g, root.boxColor.b, root.boxOpacity)
|
||||
radius: root.theme.badgeRadius
|
||||
flare: root.theme.badgeFlare
|
||||
leftSide: root.leftSide
|
||||
}
|
||||
|
||||
Item {
|
||||
id: body
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.left: root.leftSide ? parent.left : undefined
|
||||
anchors.right: root.leftSide ? undefined : parent.right
|
||||
width: nameText.width + root.theme.badgePadding * 2
|
||||
height: root.theme.badgeHeight
|
||||
|
||||
Text {
|
||||
id: nameText
|
||||
anchors.centerIn: parent
|
||||
width: Math.min(nameText.implicitWidth, root.theme.badgeMaxNameWidth)
|
||||
text: root.label
|
||||
color: root.textColor
|
||||
font.pixelSize: root.theme.badgeFontSize
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: root.clicked()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
import QtQuick
|
||||
|
||||
// Preset swatches, a hue strip and a hex field. It only reports the
|
||||
// picked color; saving it is up to whoever uses it.
|
||||
Item {
|
||||
id: root
|
||||
|
||||
required property Theme theme
|
||||
required property color current
|
||||
|
||||
signal picked(color value)
|
||||
|
||||
implicitHeight: column.implicitHeight
|
||||
|
||||
Component.onCompleted: root.showHex()
|
||||
|
||||
// Leave the field alone while it is being typed in.
|
||||
onCurrentChanged: {
|
||||
if (!hexField.activeFocus)
|
||||
root.showHex();
|
||||
}
|
||||
|
||||
function showHex(): void {
|
||||
hexField.text = root.current.toString();
|
||||
}
|
||||
|
||||
// Keeps the current saturation and brightness, but not so low that
|
||||
// the hue would be lost in grey or black.
|
||||
function pickHue(x: real): void {
|
||||
const hue = Math.max(0, Math.min(0.999, x / hueBar.width));
|
||||
const saturation = Math.max(root.current.hsvSaturation, 0.5);
|
||||
const value = Math.max(root.current.hsvValue, 0.6);
|
||||
root.picked(Qt.hsva(hue, saturation, value, 1));
|
||||
}
|
||||
|
||||
function pickHex(text: string): void {
|
||||
const hex = text.trim().replace(/^#?/, "#");
|
||||
if (/^#[0-9a-fA-F]{6}$/.test(hex))
|
||||
root.picked(hex);
|
||||
}
|
||||
|
||||
Column {
|
||||
id: column
|
||||
width: root.width
|
||||
spacing: root.theme.popupSpacing
|
||||
|
||||
Grid {
|
||||
columns: root.theme.swatchColumns
|
||||
spacing: root.theme.swatchSpacing
|
||||
|
||||
Repeater {
|
||||
model: root.theme.swatches
|
||||
|
||||
delegate: Rectangle {
|
||||
id: swatch
|
||||
|
||||
required property color modelData
|
||||
readonly property bool chosen: Qt.colorEqual(swatch.modelData, root.current)
|
||||
|
||||
width: root.theme.swatchSize
|
||||
height: root.theme.swatchSize
|
||||
radius: root.theme.swatchSize / 2
|
||||
color: swatch.modelData
|
||||
border.width: swatch.chosen ? 2 : 1
|
||||
border.color: swatch.chosen ? root.theme.textColor : root.theme.glassRimBottom
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: root.picked(swatch.modelData)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: hueBar
|
||||
width: parent.width
|
||||
height: root.theme.hueHeight
|
||||
radius: root.theme.hueHeight / 2
|
||||
|
||||
gradient: Gradient {
|
||||
orientation: Gradient.Horizontal
|
||||
GradientStop {
|
||||
position: 0
|
||||
color: "#ff0000"
|
||||
}
|
||||
GradientStop {
|
||||
position: 1 / 6
|
||||
color: "#ffff00"
|
||||
}
|
||||
GradientStop {
|
||||
position: 2 / 6
|
||||
color: "#00ff00"
|
||||
}
|
||||
GradientStop {
|
||||
position: 3 / 6
|
||||
color: "#00ffff"
|
||||
}
|
||||
GradientStop {
|
||||
position: 4 / 6
|
||||
color: "#0000ff"
|
||||
}
|
||||
GradientStop {
|
||||
position: 5 / 6
|
||||
color: "#ff00ff"
|
||||
}
|
||||
GradientStop {
|
||||
position: 1
|
||||
color: "#ff0000"
|
||||
}
|
||||
}
|
||||
|
||||
// Marks the current hue. Greys have no hue, so it hides for them.
|
||||
Rectangle {
|
||||
width: 4
|
||||
height: parent.height + 4
|
||||
radius: 2
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
x: Math.max(0, root.current.hsvHue) * (hueBar.width - width)
|
||||
visible: root.current.hsvHue >= 0
|
||||
color: root.theme.textColor
|
||||
border.width: 1
|
||||
border.color: root.theme.buttonText
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onPressed: mouse => root.pickHue(mouse.x)
|
||||
onPositionChanged: mouse => root.pickHue(mouse.x)
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
width: parent.width
|
||||
height: root.theme.fieldHeight
|
||||
|
||||
Rectangle {
|
||||
id: preview
|
||||
width: parent.height
|
||||
height: parent.height
|
||||
radius: root.theme.cornerRadius / 2
|
||||
color: root.current
|
||||
border.width: 1
|
||||
border.color: root.theme.glassRimTop
|
||||
}
|
||||
|
||||
Item {
|
||||
anchors.left: preview.right
|
||||
anchors.leftMargin: root.theme.popupSpacing
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: parent.bottom
|
||||
|
||||
Glass {
|
||||
anchors.fill: parent
|
||||
theme: root.theme
|
||||
radius: root.theme.cornerRadius / 2
|
||||
tint: root.theme.fieldBg
|
||||
selected: hexField.activeFocus
|
||||
shadow: false
|
||||
}
|
||||
|
||||
TextInput {
|
||||
id: hexField
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: root.theme.fieldPadding
|
||||
anchors.rightMargin: root.theme.fieldPadding
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
color: root.theme.textColor
|
||||
font.pixelSize: root.theme.fontSize
|
||||
font.family: "monospace"
|
||||
maximumLength: 7
|
||||
selectByMouse: true
|
||||
selectionColor: root.theme.fieldBorder
|
||||
selectedTextColor: root.theme.buttonText
|
||||
clip: true
|
||||
|
||||
onTextEdited: root.pickHex(hexField.text)
|
||||
// Tidy up a half-typed value when done.
|
||||
onEditingFinished: root.showHex()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
|
||||
// Workspace colors and badge opacity, saved to a JSON file so they last
|
||||
// across restarts.
|
||||
// Workspaces with a name are stored by name. Ones without are stored by id,
|
||||
// which niri does not keep across restarts.
|
||||
Item {
|
||||
id: root
|
||||
|
||||
// Color and opacity of a workspace that has none saved.
|
||||
required property color fallback
|
||||
required property real fallbackOpacity
|
||||
|
||||
readonly property string stateDir: {
|
||||
const dir = Quickshell.env("XDG_STATE_HOME");
|
||||
return (dir ? dir : Quickshell.env("HOME") + "/.local/state") + "/skygqts";
|
||||
}
|
||||
|
||||
// Key -> { color: "#rrggbb", opacity: 0.8 }. Older files hold just the
|
||||
// color string. Read from JSON, so this stays an untyped object.
|
||||
property var colors: ({})
|
||||
|
||||
function keyFor(id: int, name: string): string {
|
||||
return name.length > 0 ? "name:" + name : "id:" + id;
|
||||
}
|
||||
|
||||
// The saved entry for a key, as an object. A JSON value, so untyped.
|
||||
function entry(key: string): var {
|
||||
const value = root.colors[key];
|
||||
if (typeof value === "string")
|
||||
return {
|
||||
color: value
|
||||
};
|
||||
if (value && typeof value === "object")
|
||||
return value;
|
||||
return {};
|
||||
}
|
||||
|
||||
function colorFor(key: string): color {
|
||||
const value = root.entry(key).color;
|
||||
return typeof value === "string" && value.length > 0 ? value : root.fallback;
|
||||
}
|
||||
|
||||
function opacityFor(key: string): real {
|
||||
const value = root.entry(key).opacity;
|
||||
return typeof value === "number" && value >= 0 && value <= 1 ? value : root.fallbackOpacity;
|
||||
}
|
||||
|
||||
// Change part of an entry and keep the rest.
|
||||
function update(key: string, change): void {
|
||||
const next = Object.assign({}, root.colors);
|
||||
next[key] = Object.assign({}, root.entry(key), change);
|
||||
root.colors = next;
|
||||
root.save();
|
||||
}
|
||||
|
||||
function setColor(key: string, value: color): void {
|
||||
root.update(key, {
|
||||
color: value.toString()
|
||||
});
|
||||
}
|
||||
|
||||
function setOpacity(key: string, value: real): void {
|
||||
root.update(key, {
|
||||
opacity: value
|
||||
});
|
||||
}
|
||||
|
||||
// Carry the color and opacity over when a workspace is renamed.
|
||||
function move(from: string, to: string): void {
|
||||
if (from === to || !(from in root.colors))
|
||||
return;
|
||||
const next = Object.assign({}, root.colors);
|
||||
next[to] = next[from];
|
||||
delete next[from];
|
||||
root.colors = next;
|
||||
root.save();
|
||||
}
|
||||
|
||||
function save(): void {
|
||||
file.setText(JSON.stringify(root.colors, null, 2) + "\n");
|
||||
}
|
||||
|
||||
// Make sure the folder exists before the first save.
|
||||
Process {
|
||||
running: true
|
||||
command: ["mkdir", "-p", root.stateDir]
|
||||
}
|
||||
|
||||
FileView {
|
||||
id: file
|
||||
path: root.stateDir + "/workspace-colors.json"
|
||||
// A missing file just means no colors yet.
|
||||
printErrors: false
|
||||
|
||||
onLoaded: {
|
||||
try {
|
||||
const parsed = JSON.parse(file.text());
|
||||
root.colors = parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
||||
} catch (e) {
|
||||
console.warn("workspace-badge: could not read saved colors:", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,257 @@
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import Quickshell.Hyprland
|
||||
|
||||
// Tracks the active workspace on each monitor and renames workspaces.
|
||||
// Reads go through the command line tools, like the workspace manager.
|
||||
Item {
|
||||
id: root
|
||||
|
||||
// "niri", "hyprland" or "" when neither was detected.
|
||||
readonly property string kind: {
|
||||
if (Quickshell.env("NIRI_SOCKET"))
|
||||
return "niri";
|
||||
if (Quickshell.env("HYPRLAND_INSTANCE_SIGNATURE"))
|
||||
return "hyprland";
|
||||
return "";
|
||||
}
|
||||
|
||||
// Output name -> { id, idx, name } of the workspace active there.
|
||||
// Built from parsed JSON, so this stays an untyped object.
|
||||
property var outputs: ({})
|
||||
// Name of the focused output, empty when unknown.
|
||||
property string focusedOutput: ""
|
||||
|
||||
property bool refreshQueued: false
|
||||
// Argv lists waiting to run, one after another. A list of lists, so untyped.
|
||||
property var actionQueue: []
|
||||
|
||||
Component.onCompleted: {
|
||||
if (root.kind === "niri")
|
||||
niriEvents.running = true;
|
||||
root.refresh();
|
||||
}
|
||||
|
||||
function asString(value): string {
|
||||
if (value === null || value === undefined)
|
||||
return "";
|
||||
return String(value);
|
||||
}
|
||||
|
||||
function asNumber(value, fallback: int): int {
|
||||
const number = Number(value);
|
||||
return Number.isFinite(number) ? number : fallback;
|
||||
}
|
||||
|
||||
function refresh(): void {
|
||||
if (root.kind === "")
|
||||
return;
|
||||
if (query.running) {
|
||||
root.refreshQueued = true;
|
||||
return;
|
||||
}
|
||||
if (root.kind === "niri")
|
||||
query.command = ["niri", "msg", "--json", "workspaces"];
|
||||
else
|
||||
query.command = ["hyprctl", "-j", "monitors"];
|
||||
query.running = true;
|
||||
}
|
||||
|
||||
// niri may wrap replies as {"Ok": {"Workspaces": [...]}}.
|
||||
function unwrap(parsed): var {
|
||||
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
||||
return parsed;
|
||||
if ("Err" in parsed) {
|
||||
console.warn("workspace-badge: compositor error:", parsed.Err);
|
||||
return [];
|
||||
}
|
||||
if (!("Ok" in parsed))
|
||||
return parsed;
|
||||
const inner = parsed.Ok;
|
||||
if (inner && typeof inner === "object" && !Array.isArray(inner)) {
|
||||
const keys = Object.keys(inner);
|
||||
if (keys.length === 1)
|
||||
return inner[keys[0]];
|
||||
}
|
||||
return inner;
|
||||
}
|
||||
|
||||
function parseNiri(list): void {
|
||||
const map = {};
|
||||
let focused = "";
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
const ws = list[i];
|
||||
if (ws.is_active !== true)
|
||||
continue;
|
||||
const output = root.asString(ws.output);
|
||||
if (output.length === 0)
|
||||
continue;
|
||||
map[output] = {
|
||||
id: root.asNumber(ws.id, -1),
|
||||
idx: root.asNumber(ws.idx, -1),
|
||||
name: root.asString(ws.name)
|
||||
};
|
||||
if (ws.is_focused === true)
|
||||
focused = output;
|
||||
}
|
||||
root.outputs = map;
|
||||
root.focusedOutput = focused;
|
||||
}
|
||||
|
||||
function parseHyprland(list): void {
|
||||
const map = {};
|
||||
let focused = "";
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
const mon = list[i];
|
||||
const output = root.asString(mon.name);
|
||||
if (output.length === 0)
|
||||
continue;
|
||||
const active = mon.activeWorkspace ?? {};
|
||||
const id = root.asNumber(active.id, -1);
|
||||
const name = root.asString(active.name);
|
||||
map[output] = {
|
||||
id: id,
|
||||
idx: id,
|
||||
// Hyprland uses the id as the name when there is none.
|
||||
name: name === String(id) ? "" : name
|
||||
};
|
||||
if (mon.focused === true)
|
||||
focused = output;
|
||||
}
|
||||
root.outputs = map;
|
||||
root.focusedOutput = focused;
|
||||
}
|
||||
|
||||
// Names that are only digits would be read by niri as an index.
|
||||
function niriCanUseName(name: string): bool {
|
||||
return name.length > 0 && !/^\d+$/.test(name);
|
||||
}
|
||||
|
||||
// Rename the workspace that is active on this output. An empty name
|
||||
// clears it.
|
||||
function rename(output: string, id: int, oldName: string, newName: string): void {
|
||||
const name = newName.trim();
|
||||
if (root.kind === "niri") {
|
||||
if (root.niriCanUseName(oldName)) {
|
||||
if (name.length > 0)
|
||||
root.runAll([["niri", "msg", "action", "set-workspace-name", "--workspace", oldName, name]]);
|
||||
else
|
||||
root.runAll([["niri", "msg", "action", "unset-workspace-name", oldName]]);
|
||||
return;
|
||||
}
|
||||
if (oldName.length === 0 && name.length === 0)
|
||||
return;
|
||||
// No name to point at, and niri has no way to point at an id,
|
||||
// so focus the monitor and rename its active workspace.
|
||||
const step = name.length > 0 ? ["niri", "msg", "action", "set-workspace-name", name] : ["niri", "msg", "action", "unset-workspace-name"];
|
||||
root.runAll([["niri", "msg", "action", "focus-monitor", output], step]);
|
||||
} else if (root.kind === "hyprland") {
|
||||
if (id < 0)
|
||||
return;
|
||||
const idText = String(id);
|
||||
// Hyprland has no "clear name", so fall back to the numeric id.
|
||||
root.runAll([["hyprctl", "dispatch", "renameworkspace", idText, name.length > 0 ? name : idText]]);
|
||||
}
|
||||
}
|
||||
|
||||
function runAll(commands): void {
|
||||
root.actionQueue = root.actionQueue.concat(commands);
|
||||
if (!action.running)
|
||||
root.runNext();
|
||||
}
|
||||
|
||||
function runNext(): void {
|
||||
if (root.actionQueue.length === 0) {
|
||||
refreshTimer.restart();
|
||||
return;
|
||||
}
|
||||
action.command = root.actionQueue[0];
|
||||
root.actionQueue = root.actionQueue.slice(1);
|
||||
action.running = true;
|
||||
}
|
||||
|
||||
// Many events can arrive at once, so wait a moment and read once.
|
||||
Timer {
|
||||
id: refreshTimer
|
||||
interval: 50
|
||||
onTriggered: root.refresh()
|
||||
}
|
||||
|
||||
Process {
|
||||
id: query
|
||||
running: false
|
||||
|
||||
onExited: {
|
||||
if (!root.refreshQueued)
|
||||
return;
|
||||
root.refreshQueued = false;
|
||||
refreshTimer.restart();
|
||||
}
|
||||
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
let parsed = null;
|
||||
try {
|
||||
parsed = root.unwrap(JSON.parse(this.text));
|
||||
} catch (e) {
|
||||
console.warn("workspace-badge: could not read workspace data:", e);
|
||||
return;
|
||||
}
|
||||
const list = Array.isArray(parsed) ? parsed : [];
|
||||
if (root.kind === "niri")
|
||||
root.parseNiri(list);
|
||||
else
|
||||
root.parseHyprland(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
id: action
|
||||
running: false
|
||||
|
||||
onExited: root.runNext()
|
||||
|
||||
stderr: StdioCollector {
|
||||
onStreamFinished: {
|
||||
if (this.text.trim().length > 0)
|
||||
console.warn("workspace-badge:", this.text.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// niri: one JSON event per line. Read again on any workspace change.
|
||||
Process {
|
||||
id: niriEvents
|
||||
running: false
|
||||
command: ["niri", "msg", "--json", "event-stream"]
|
||||
|
||||
onExited: niriRetry.start()
|
||||
|
||||
stdout: SplitParser {
|
||||
onRead: data => {
|
||||
if (data.startsWith("{\"Workspace"))
|
||||
refreshTimer.restart();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Start the niri event stream again if it stops, e.g. after niri restarts.
|
||||
Timer {
|
||||
id: niriRetry
|
||||
interval: 2000
|
||||
onTriggered: niriEvents.running = true
|
||||
}
|
||||
|
||||
// Hyprland: read again on workspace and monitor events.
|
||||
Connections {
|
||||
target: root.kind === "hyprland" ? Hyprland : null
|
||||
|
||||
function onRawEvent(event: HyprlandEvent): void {
|
||||
const name = event.name;
|
||||
if (name.indexOf("workspace") >= 0 || name.startsWith("monitor") || name.startsWith("focusedmon"))
|
||||
refreshTimer.restart();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Wayland
|
||||
|
||||
// Opens in the middle of one monitor when a badge is clicked: a box to
|
||||
// rename the workspace and a box to pick its color and opacity.
|
||||
// Clicking anywhere else or pressing Escape closes it.
|
||||
PanelWindow {
|
||||
id: root
|
||||
|
||||
required property Compositor compositor
|
||||
required property ColorStore store
|
||||
required property Theme theme
|
||||
|
||||
// The workspace being edited. Copied in openFor() so a refresh while
|
||||
// the popup is open does not swap it for another one.
|
||||
property string output
|
||||
property int wsId
|
||||
property string wsName
|
||||
property string colorKey
|
||||
|
||||
// Hidden until a badge is clicked.
|
||||
visible: false
|
||||
color: "transparent"
|
||||
|
||||
anchors {
|
||||
top: true
|
||||
bottom: true
|
||||
left: true
|
||||
right: true
|
||||
}
|
||||
|
||||
exclusionMode: ExclusionMode.Ignore
|
||||
WlrLayershell.namespace: "quickshell:workspace-badge-editor"
|
||||
WlrLayershell.layer: WlrLayer.Overlay
|
||||
WlrLayershell.keyboardFocus: root.visible ? WlrKeyboardFocus.Exclusive : WlrKeyboardFocus.None
|
||||
|
||||
function openFor(output: string, id: int, name: string, key: string): void {
|
||||
root.output = output;
|
||||
root.wsId = id;
|
||||
root.wsName = name;
|
||||
root.colorKey = key;
|
||||
nameField.text = name;
|
||||
root.visible = true;
|
||||
Qt.callLater(() => {
|
||||
nameField.forceActiveFocus();
|
||||
nameField.selectAll();
|
||||
});
|
||||
}
|
||||
|
||||
function close(): void {
|
||||
root.visible = false;
|
||||
}
|
||||
|
||||
// Color and opacity are saved as they are picked; only the name waits for this.
|
||||
function accept(): void {
|
||||
const name = nameField.text.trim();
|
||||
if (name !== root.wsName) {
|
||||
root.compositor.rename(root.output, root.wsId, root.wsName, name);
|
||||
root.store.move(root.colorKey, root.store.keyFor(root.wsId, name));
|
||||
}
|
||||
root.close();
|
||||
}
|
||||
|
||||
// Clicks that miss both boxes land here.
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: root.close()
|
||||
}
|
||||
|
||||
FocusScope {
|
||||
anchors.centerIn: parent
|
||||
width: Math.min(root.theme.popupMaxWidth, parent.width - root.theme.popupMargin * 2)
|
||||
height: boxes.implicitHeight
|
||||
focus: true
|
||||
|
||||
Keys.onEscapePressed: event => {
|
||||
root.close();
|
||||
event.accepted = true;
|
||||
}
|
||||
|
||||
Column {
|
||||
id: boxes
|
||||
width: parent.width
|
||||
spacing: root.theme.popupGap
|
||||
|
||||
// ── rename box ──────────────────────────────────────────────
|
||||
|
||||
Item {
|
||||
width: parent.width
|
||||
height: renameColumn.implicitHeight + root.theme.popupPadding * 2
|
||||
|
||||
// Keeps clicks on the box from closing the popup.
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
}
|
||||
|
||||
Glass {
|
||||
anchors.fill: parent
|
||||
theme: root.theme
|
||||
radius: root.theme.cornerRadius
|
||||
tint: root.theme.panelBg
|
||||
selected: false
|
||||
shadow: false
|
||||
}
|
||||
|
||||
Column {
|
||||
id: renameColumn
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
anchors.margins: root.theme.popupPadding
|
||||
spacing: root.theme.popupSpacing
|
||||
|
||||
Text {
|
||||
text: "Rename workspace"
|
||||
color: root.theme.labelColor
|
||||
font.pixelSize: root.theme.labelSize
|
||||
}
|
||||
|
||||
Row {
|
||||
width: parent.width
|
||||
spacing: root.theme.popupSpacing
|
||||
|
||||
Item {
|
||||
width: parent.width - okButton.width - parent.spacing
|
||||
height: root.theme.fieldHeight
|
||||
|
||||
Glass {
|
||||
anchors.fill: parent
|
||||
theme: root.theme
|
||||
radius: root.theme.cornerRadius / 2
|
||||
tint: root.theme.fieldBg
|
||||
selected: nameField.activeFocus
|
||||
shadow: false
|
||||
}
|
||||
|
||||
TextInput {
|
||||
id: nameField
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: root.theme.fieldPadding
|
||||
anchors.rightMargin: root.theme.fieldPadding
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
color: root.theme.textColor
|
||||
font.pixelSize: root.theme.fontSize
|
||||
selectByMouse: true
|
||||
selectionColor: root.theme.fieldBorder
|
||||
selectedTextColor: root.theme.buttonText
|
||||
clip: true
|
||||
|
||||
onAccepted: root.accept()
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: okButton
|
||||
width: root.theme.buttonWidth
|
||||
height: root.theme.fieldHeight
|
||||
radius: root.theme.cornerRadius / 2
|
||||
color: okArea.pressed ? Qt.darker(root.theme.buttonBg, 1.2) : root.theme.buttonBg
|
||||
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
text: "OK"
|
||||
color: root.theme.buttonText
|
||||
font.pixelSize: root.theme.fontSize
|
||||
font.bold: true
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: okArea
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: root.accept()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ── color box ───────────────────────────────────────────────
|
||||
|
||||
Item {
|
||||
width: parent.width
|
||||
height: colorColumn.implicitHeight + root.theme.popupPadding * 2
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
}
|
||||
|
||||
Glass {
|
||||
anchors.fill: parent
|
||||
theme: root.theme
|
||||
radius: root.theme.cornerRadius
|
||||
tint: root.theme.panelBg
|
||||
selected: false
|
||||
shadow: false
|
||||
}
|
||||
|
||||
Column {
|
||||
id: colorColumn
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
anchors.margins: root.theme.popupPadding
|
||||
spacing: root.theme.popupSpacing
|
||||
|
||||
Text {
|
||||
text: "Color"
|
||||
color: root.theme.labelColor
|
||||
font.pixelSize: root.theme.labelSize
|
||||
}
|
||||
|
||||
ColorPicker {
|
||||
width: parent.width
|
||||
theme: root.theme
|
||||
current: root.store.colorFor(root.colorKey)
|
||||
onPicked: value => root.store.setColor(root.colorKey, value)
|
||||
}
|
||||
|
||||
Text {
|
||||
text: "Opacity"
|
||||
color: root.theme.labelColor
|
||||
font.pixelSize: root.theme.labelSize
|
||||
}
|
||||
|
||||
OpacitySlider {
|
||||
width: parent.width
|
||||
theme: root.theme
|
||||
baseColor: root.store.colorFor(root.colorKey)
|
||||
value: root.store.opacityFor(root.colorKey)
|
||||
onPicked: value => root.store.setOpacity(root.colorKey, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import QtQuick
|
||||
|
||||
// The corner badge shape: a round top corner facing into the screen, and
|
||||
// concave curves where the box runs into the screen edges, as if it grows
|
||||
// out of the corner. Drawn for the bottom-right corner; leftSide flips it.
|
||||
// Only the shape is drawn here; put the content on top of it.
|
||||
Item {
|
||||
id: root
|
||||
|
||||
required property Theme theme
|
||||
required property color tint
|
||||
// Round corner at the top, on the side facing into the screen.
|
||||
required property real radius
|
||||
// Size of the curves that run into the screen edges. The box itself
|
||||
// starts this far in from the left and top of this item.
|
||||
required property real flare
|
||||
required property bool leftSide
|
||||
|
||||
// Flip only the drawing, not the text that sits on top of it.
|
||||
transform: Scale {
|
||||
origin.x: root.width / 2
|
||||
xScale: root.leftSide ? -1 : 1
|
||||
}
|
||||
|
||||
Canvas {
|
||||
id: shape
|
||||
|
||||
readonly property color fill: root.tint
|
||||
|
||||
anchors.fill: parent
|
||||
|
||||
onWidthChanged: shape.requestPaint()
|
||||
onHeightChanged: shape.requestPaint()
|
||||
onFillChanged: shape.requestPaint()
|
||||
|
||||
onPaint: {
|
||||
const ctx = shape.getContext("2d");
|
||||
ctx.reset();
|
||||
const w = shape.width;
|
||||
const h = shape.height;
|
||||
if (w <= 0 || h <= 0)
|
||||
return;
|
||||
const f = Math.min(root.flare, w / 2, h / 2);
|
||||
const r = Math.min(root.radius, (w - f) / 2, (h - f) / 2);
|
||||
|
||||
// The edges facing into the screen: from the bottom edge, up the
|
||||
// inner side, round the top corner, and across to the right edge.
|
||||
function innerEdges() {
|
||||
ctx.moveTo(0, h);
|
||||
ctx.arcTo(f, h, f, h - f, f);
|
||||
ctx.lineTo(f, f + r);
|
||||
ctx.arcTo(f, f, f + r, f, r);
|
||||
ctx.lineTo(w - f, f);
|
||||
ctx.arcTo(w, f, w, 0, f);
|
||||
}
|
||||
|
||||
ctx.beginPath();
|
||||
innerEdges();
|
||||
ctx.lineTo(w, h);
|
||||
ctx.closePath();
|
||||
ctx.fillStyle = shape.fill;
|
||||
ctx.fill();
|
||||
|
||||
// Shine over the top half, like light on curved glass.
|
||||
const shine = ctx.createLinearGradient(0, f, 0, h);
|
||||
shine.addColorStop(0, root.theme.glassShine);
|
||||
shine.addColorStop(0.55, "rgba(255, 255, 255, 0)");
|
||||
ctx.fillStyle = shine;
|
||||
ctx.fill();
|
||||
|
||||
// The rim, only along the edges facing into the screen.
|
||||
const rim = ctx.createLinearGradient(0, 0, 0, h);
|
||||
rim.addColorStop(0, root.theme.glassRimTop);
|
||||
rim.addColorStop(1, root.theme.glassRimBottom);
|
||||
ctx.beginPath();
|
||||
innerEdges();
|
||||
ctx.strokeStyle = rim;
|
||||
ctx.lineWidth = 1;
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
import QtQuick
|
||||
import QtQuick.Effects
|
||||
|
||||
// A see-through glass panel: a light tint, a soft shine over the top half,
|
||||
// a rim that catches the light along the top and a shadow underneath.
|
||||
// It only draws the glass; put the content on top of it.
|
||||
Item {
|
||||
id: root
|
||||
|
||||
required property Theme theme
|
||||
required property real radius
|
||||
required property color tint
|
||||
// Blue tint and a glowing blue rim.
|
||||
required property bool selected
|
||||
// Soft shadow underneath. Off where the window is too small to hold it.
|
||||
required property bool shadow
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
radius: root.radius
|
||||
color: root.selected ? root.theme.glassSelectedTint : root.tint
|
||||
antialiasing: true
|
||||
|
||||
// A GPU shadow instead of a hand-drawn one, so it stays cheap even
|
||||
// with many glass panels on screen and animating at once.
|
||||
layer.enabled: root.shadow
|
||||
layer.effect: MultiEffect {
|
||||
shadowEnabled: true
|
||||
shadowColor: root.theme.glassShadow
|
||||
shadowVerticalOffset: root.theme.glassShadowOffset
|
||||
shadowBlur: 1.0
|
||||
blurMax: root.theme.glassShadowBlur
|
||||
}
|
||||
}
|
||||
|
||||
// Shine over the top half, like light on curved glass.
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
radius: root.radius
|
||||
antialiasing: true
|
||||
gradient: Gradient {
|
||||
GradientStop {
|
||||
position: 0
|
||||
color: root.theme.glassShine
|
||||
}
|
||||
GradientStop {
|
||||
position: 0.55
|
||||
color: Qt.rgba(1, 1, 1, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The rim, bright at the top and fading down. No blur here, so this
|
||||
// stays a small, cheap stroke.
|
||||
Canvas {
|
||||
id: edge
|
||||
|
||||
readonly property color rimTop: root.selected ? root.theme.fieldBorder : root.theme.glassRimTop
|
||||
readonly property color rimBottom: root.selected ? root.theme.glassSelectedRimBottom : root.theme.glassRimBottom
|
||||
readonly property real rimWidth: root.selected ? 2 : 1
|
||||
|
||||
anchors.fill: parent
|
||||
|
||||
onWidthChanged: edge.requestPaint()
|
||||
onHeightChanged: edge.requestPaint()
|
||||
onRimTopChanged: edge.requestPaint()
|
||||
onRimBottomChanged: edge.requestPaint()
|
||||
onRimWidthChanged: edge.requestPaint()
|
||||
|
||||
onPaint: {
|
||||
const ctx = edge.getContext("2d");
|
||||
ctx.reset();
|
||||
const w = edge.width;
|
||||
const h = edge.height;
|
||||
const r = Math.min(root.radius, w / 2, h / 2);
|
||||
if (w <= 0 || h <= 0)
|
||||
return;
|
||||
|
||||
const half = edge.rimWidth / 2;
|
||||
const rim = ctx.createLinearGradient(0, 0, 0, h);
|
||||
rim.addColorStop(0, edge.rimTop);
|
||||
rim.addColorStop(1, edge.rimBottom);
|
||||
ctx.strokeStyle = rim;
|
||||
ctx.lineWidth = edge.rimWidth;
|
||||
ctx.beginPath();
|
||||
ctx.roundedRect(half, half, w - edge.rimWidth, h - edge.rimWidth, r - half, r - half);
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import QtQuick
|
||||
|
||||
// A slider for the badge opacity, from 0% to 100% in steps of 5%. It only
|
||||
// reports the picked value; saving it is up to whoever uses it.
|
||||
Item {
|
||||
id: root
|
||||
|
||||
required property Theme theme
|
||||
// The color shown along the track, from clear to solid.
|
||||
required property color baseColor
|
||||
required property real value
|
||||
|
||||
signal picked(real value)
|
||||
|
||||
implicitHeight: root.theme.hueHeight
|
||||
|
||||
function pickAt(x: real): void {
|
||||
const share = Math.max(0, Math.min(1, x / track.width));
|
||||
root.picked(Math.round(share * 20) / 20);
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: track
|
||||
anchors.left: parent.left
|
||||
anchors.right: percent.left
|
||||
anchors.rightMargin: root.theme.popupSpacing
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
height: root.theme.hueHeight
|
||||
radius: root.theme.hueHeight / 2
|
||||
color: root.theme.fieldBg
|
||||
border.width: 1
|
||||
border.color: root.theme.glassRimBottom
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
radius: parent.radius
|
||||
|
||||
gradient: Gradient {
|
||||
orientation: Gradient.Horizontal
|
||||
GradientStop {
|
||||
position: 0
|
||||
color: Qt.rgba(root.baseColor.r, root.baseColor.g, root.baseColor.b, 0)
|
||||
}
|
||||
GradientStop {
|
||||
position: 1
|
||||
color: Qt.rgba(root.baseColor.r, root.baseColor.g, root.baseColor.b, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Marks the current value.
|
||||
Rectangle {
|
||||
width: 4
|
||||
height: parent.height + 4
|
||||
radius: 2
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
x: root.value * (track.width - width)
|
||||
color: root.theme.textColor
|
||||
border.width: 1
|
||||
border.color: root.theme.buttonText
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onPressed: mouse => root.pickAt(mouse.x)
|
||||
onPositionChanged: mouse => root.pickAt(mouse.x)
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
id: percent
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
// Fixed width so the track does not jump as the number changes.
|
||||
width: root.theme.buttonWidth
|
||||
horizontalAlignment: Text.AlignRight
|
||||
text: Math.round(root.value * 100) + "%"
|
||||
color: root.theme.textColor
|
||||
font.pixelSize: root.theme.fontSize
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import QtQuick
|
||||
|
||||
QtObject {
|
||||
readonly property color textColor: "#ffffff"
|
||||
readonly property color labelColor: "#d4b94a"
|
||||
readonly property color panelBg: "#b80d0d0d"
|
||||
readonly property color fieldBg: "#80000000"
|
||||
readonly property color fieldBorder: "#ffd60a"
|
||||
readonly property color buttonBg: "#ffd60a"
|
||||
readonly property color buttonText: "#000000"
|
||||
|
||||
// ── glass ───────────────────────────────────────────────────────────
|
||||
|
||||
// Same look as the workspace manager. See Glass.qml.
|
||||
readonly property color glassRimTop: "#8cffffff"
|
||||
readonly property color glassRimBottom: "#14ffffff"
|
||||
readonly property color glassShine: "#29ffffff"
|
||||
readonly property color glassSelectedTint: "#66332b00"
|
||||
readonly property color glassSelectedRimBottom: "#80ffd60a"
|
||||
readonly property color glassShadow: "#59000000"
|
||||
readonly property real glassShadowBlur: 24
|
||||
readonly property real glassShadowOffset: 8
|
||||
|
||||
readonly property real cornerRadius: 10
|
||||
|
||||
// ── badge ───────────────────────────────────────────────────────────
|
||||
|
||||
// Color of a workspace that has not been given one yet.
|
||||
readonly property color defaultColor: "#0a0a0a"
|
||||
// Opacity of the workspace color behind the badge, 0 to 1, for
|
||||
// workspaces that have none saved. It can be changed in the editor.
|
||||
readonly property real badgeOpacity: 0.8
|
||||
// Badge text on dark and on light workspace colors.
|
||||
readonly property color badgeTextOnDark: "#ffd60a"
|
||||
readonly property color badgeTextOnLight: "#000000"
|
||||
readonly property real badgeHeight: 34
|
||||
// Round top corner on the side facing into the screen.
|
||||
readonly property real badgeRadius: 14
|
||||
// Size of the curves where the badge runs into the screen edges.
|
||||
readonly property real badgeFlare: 12
|
||||
// Space between the badge and the screen edges. 0 sits it in the corner.
|
||||
readonly property real badgeMargin: 0
|
||||
readonly property real badgePadding: 12
|
||||
readonly property real badgeFontSize: 14
|
||||
// Longer names are cut off with "…".
|
||||
readonly property real badgeMaxNameWidth: 220
|
||||
|
||||
// ── editor ──────────────────────────────────────────────────────────
|
||||
|
||||
// The editor sits in the middle of the screen, at most this wide.
|
||||
readonly property real popupMaxWidth: 400
|
||||
// Space between the two editor boxes.
|
||||
readonly property real popupGap: 10
|
||||
// Smallest space between the editor and the screen edges.
|
||||
readonly property real popupMargin: 10
|
||||
readonly property real popupPadding: 14
|
||||
readonly property real popupSpacing: 10
|
||||
readonly property real labelSize: 13
|
||||
readonly property real fontSize: 15
|
||||
readonly property real fieldHeight: 34
|
||||
readonly property real fieldPadding: 10
|
||||
readonly property real buttonWidth: 56
|
||||
|
||||
readonly property real swatchSize: 26
|
||||
readonly property real swatchSpacing: 8
|
||||
readonly property int swatchColumns: 8
|
||||
readonly property real hueHeight: 18
|
||||
|
||||
readonly property list<color> swatches: [
|
||||
"#fff3b0", "#ffe066", "#ffd60a", "#f5c518", "#ffb703", "#e0a800", "#c99700", "#ff9f1c",
|
||||
"#000000", "#1c1c1c", "#2e2e2e", "#4a4a4a", "#e8e8e8", "#db4b4b", "#4fa84a", "#4a90e2"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
|
||||
// A small box in the bottom-right corner of each monitor with the active
|
||||
// workspace's name and color. Click it to rename the workspace or pick
|
||||
// another color.
|
||||
ShellRoot {
|
||||
id: shell
|
||||
|
||||
Theme {
|
||||
id: badgeTheme
|
||||
}
|
||||
|
||||
Compositor {
|
||||
id: badgeCompositor
|
||||
}
|
||||
|
||||
ColorStore {
|
||||
id: colorStore
|
||||
fallback: badgeTheme.defaultColor
|
||||
fallbackOpacity: badgeTheme.badgeOpacity
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
if (badgeCompositor.kind === "")
|
||||
console.warn("workspace-badge: neither niri nor Hyprland was detected");
|
||||
}
|
||||
|
||||
Variants {
|
||||
id: badges
|
||||
model: Quickshell.screens
|
||||
|
||||
delegate: Component {
|
||||
Badge {
|
||||
compositor: badgeCompositor
|
||||
store: colorStore
|
||||
theme: badgeTheme
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IpcHandler {
|
||||
target: "badge"
|
||||
|
||||
// Open the editor on the focused monitor.
|
||||
function edit(): void {
|
||||
const list = badges.instances;
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
if (list[i].modelData.name === badgeCompositor.focusedOutput) {
|
||||
list[i].openEditor();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user