Patterns
Reusable recipes. Each pattern solves a recurring shape of problem. Combine them.
All patterns here are validated against Quickshell v0.3.0. When bumping versions, re-check each against the latest quickshell.org/docs/<version>/guide/ (see getting-fresh-docs.md).
P1. Per-monitor instantiation
import Quickshell
Variants {
model: Quickshell.screens
delegate: Component {
PanelWindow {
required property var modelData
screen: modelData
// ... rest of bar
}
}
}
modelData is the per-iteration value. Always mark it required so qmlls catches missing bindings. Quickshell.screens is a list<ShellScreen> — each has name, width, height, scale. Variants survives monitor hot-plug: when a screen disconnects, its instance is destroyed; when it reconnects, a fresh one is created.
Source: docs/v0.3.0/guide/introduction/ → Reusable components · Variants type · ShellScreen type
P2. Live-updating clock
PanelWindow {
SystemClock { id: clock; precision: SystemClock.Seconds }
Text { text: Qt.formatTime(clock.date, "HH:mm:ss") }
}
SystemClock is not a singleton — you must instantiate it. clock.date is a reactive JS Date; format it with Qt.formatTime / Qt.formatDate / Qt.formatDateTime. Updates trigger within 50ms of the system clock changing.
Source: SystemClock type · quickshell-mirror/quickshell src/wayland/screencopy/systemclock.* @ v0.3.0 (reference impl)
P3. Run a shell command, capture output
import Quickshell.Io
Process {
id: proc
command: ["wpctl", "get-volume", "@DEFAULT_AUDIO_SINK@"]
running: true
stdout: StdioCollector {
onStreamFinished: lastOutput.text = this.text
}
}
StdioCollector is a Property-like that becomes the full output string after the process closes stdout. One process, many widgets — don't spawn per widget (memory + startup cost).
Source: docs/v0.3.0/guide/introduction/ → Running a process · Process type · StdioCollector type
P4. Long-running stream, regex match per line
import Quickshell.Io
Process {
command: ["some-streaming-tool"]
running: true
stdout: SplitParser {
property var pattern: /focusedmon>>(.+),/
onRead: msg => {
const m = pattern.exec(msg)
if (m) doStuff(m[1])
}
}
}
SplitParser splits on newlines by default; you can override with split. Each line fires onRead(line). Use this for any event-stream consumer (Hyprland socket, log tailer, status feed).
Source: SplitParser type · quickshell-examples/focus_following_panel (canonical example)
P5. Bind a service object's state
import Quickshell.Services.Pipewire
PwObjectTracker { objects: [ Pipewire.defaultAudioSink ] }
Text {
text: `vol: ${(Pipewire.defaultAudioSink?.audio.volume ?? 0) * 100 | 0}%`
}
PwObjectTracker is a sentinel — it does nothing visible, but its presence keeps the object alive in the service's internal model. Without it, the binding can drop to null. Pattern: every time you read a non-singleton service object, declare a tracker for it. Same for Mpris.players, UPower.devices, Bluetooth.adapters.
The ?. optional chain is the safe way to read state that might not be present yet (e.g. before the service has connected).
Source: docs/v0.3.0/guide/ → Not "one process per widget" (FAQ) · Pipewire type · PwObjectTracker type
P6. React to a service signal
import Quickshell.Services.Pipewire
Connections {
target: Pipewire.defaultAudioSink?.audio
function onVolumeChanged() { flashOsd() }
}
Connections is the idiomatic way to listen to a target's signals. The target must be live — wrap with ?. and use the target: binding (not a static target: assignment) to make it reactive. The handler name follows on<SignalName> convention.
Source: quickshell-examples/volume-osd (canonical Connections + Pipewire example)
P7. Show a window only when a condition holds
// Cheap: always in memory, just hides
Item { visible: showIt }
// Frees memory: builds only when active
LazyLoader { active: showIt; PanelWindow { ... } }
Use LazyLoader for windows and other non-Item roots. The OSD-on-volume-change pattern is exactly this:
LazyLoader {
active: showOsd
PanelWindow { /* the OSD UI */ }
}
The window is destroyed when active flips to false. Good for rare/expensive UI.
Source: docs/v0.3.0/guide/faq/ → Reduce memory usage · LazyLoader type · quickshell-examples/volume-osd (canonical example)
P8. Click-through overlay
PanelWindow {
color: "transparent"
mask: Region {} // empty = no input
}
The Region input mask is the only correct way to make a panel ignore clicks while still rendering. For a window that should be opaque to clicks, leave mask unset.
Source: Region type · quickshell-examples/activate_linux (mask: Region {} example) · quickshell-examples/volume-osd (OSD with click-through)
P9. System icon
import Quickshell.Widgets
IconImage {
source: Quickshell.iconPath("audio-volume-high-symbolic")
implicitSize: 24
}
Quickshell.iconPath looks up the name in the current icon theme. Three variants: missing icon → purple/black square (default), fallback to a name, or empty string. If the purple square bugs you, use the empty-string overload and source !== "" to gate the IconImage.
Source: Quickshell.iconPath method · IconImage type · docs/v0.3.0/guide/faq/ → Get rid of the purple/black icons
P10. Custom file-bound properties (config-as-code)
import Quickshell.Io
JsonAdapter {
id: config
path: Qt.resolvedUrl("config.json")
// adapter is auto-generated; properties become QML properties
}
JsonAdapter reads a JSON file at startup and exposes its top-level keys as reactive QML properties. Edits to the file are picked up on next reload. Use this for user-tweakable config (theme, layout offsets, monitor list).
Source: JsonAdapter type
P11. Multi-file shell
~/.config/quickshell/mybar/
├── shell.qml # entry, contains the Variants
├── Bar.qml # the bar component (implicit import)
├── Clock.qml # implicit import
└── widgets/
└── Volume.qml # import via: import qs.widgets as W
Inside shell.qml:
import qs.widgets as W
import "."
// or use the implicit Bar / Clock from this directory
Variants {
model: Quickshell.screens
delegate: Bar { screen: modelData }
}
Rules:
*.qmlnext toshell.qmlwith PascalCase name → implicitly importable.widgets/*.qmletc. → import withimport qs.widgets as W(LSP-friendly, v0.2.0+).import "relative/path"works but loses LSP coverage; preferqs.*.
Source: docs/v0.3.0/guide/qml-language/ → Implicit imports · docs/v0.3.0/guide/qml-language/ → Manual imports (qs.*)
P12. Version-gate a feature
import Quickshell
pragma ComponentBehavior: bound
Loader {
active: Quickshell.hasVersion("0.3.0")
sourceComponent: someNewFeature
}
Quickshell.hasVersion is the API; the #pragma-style preprocessor (different syntax) lets you gate by version at parse time. Use these when you want the same shell.qml to work across quickshell releases.
Source: Quickshell.hasVersion method · docs/v0.3.0/guide/advanced/ → If/Endif preprocessor
P13. Reuse state across components
Put the state in the Scope root:
Scope {
id: root
property string currentWallpaper: "/path/to/wp"
property int volumeStep: 5
Variants { model: Quickshell.screens; delegate: Component { Bar { ... } } }
LazyLoader { active: showMixer; Mixer { ... } }
}
Components declared inside Scope can reach root.foo by id. If you find yourself passing the same property into 4+ components, hoist it to Scope.
Source: Scope type · quickshell-examples/volume-osd (canonical Scope example)
P14. Custom re-usable component file
// MyButton.qml (PascalCase, placed in same dir as shell.qml or imported via qs.*)
import QtQuick
import QtQuick.Controls
Button {
property string iconName: ""
property var onActivate: () => {}
icon.name: iconName
onClicked: onActivate()
}
Consume from shell.qml (auto-imported) or import qs.widgets as W; W.MyButton { ... }. Components are just Item-like root objects — anything that's a QML object can be a component.
Source: docs/v0.3.0/guide/qml-language/ → Creating types · quickshell-examples/wlogout (canonical multi-file component example)
P15. Hide the reload popup
If you have your own reloader indicator, you can disable the built-in one (v0.3.0+):
import Quickshell
ShellRoot {
// The default reload popup is added automatically.
// To replace it, add a ReloadPopup from your own module path.
// (See official examples/reload-popup.)
}
The default reload popup shows on every file save. For noisier iteration, replace it with a smaller indicator or disable via QuickshellSettings.
Source: quickshell-examples/reload-popup · quickshell.org/docs/v0.3.0/guide/advanced/ → Environment (QS_NO_RELOAD_POPUP)
P16. Process IPC (call into quickshell from outside)
import Quickshell.Io
IpcHandler {
target: "myShell" // becomes the IPC namespace
function toggleBar(): void {
showBar = !showBar
}
}
Call it from the shell:
qs -c mybar ipc call myShell toggleBar
Use this for keybind triggers, scripts, and external automation.
Source: IpcHandler type · docs/v0.3.0/guide/faq/ → Open/close windows with commands · docs/v0.3.0/guide/advanced/ → IPC signal listener (v0.3.0+)