Commit Graph
7 Commits
Author SHA1 Message Date
Milad Alizadeh 71ba77c989 Tighten --help
75 lines to 51. The format section had grown into prose that explained
the same thing twice, and two of the three examples were variations on
one idea, so one worked example survives.

The samples were also taken verbatim from the machine this was developed
on — a real toplevel identifier, a real output name, real app ids — which
reads like configuration rather than illustration. They are generic now.
2026-08-23 16:29:50 +01:00
Milad Alizadeh 3d54b368d2 Make wlgrid a chooser only, and say what each format is
--focus and sway::focus are gone. Showing the grid and reporting the
choice is the whole job; deciding what the choice means belongs to
whoever called it, and keeping that decision here only invited more of
it (focus which way? move? swap? scratchpad?). The sway IPC connection
is now scoped to building the list and closed before the overlay maps.

--help no longer just names the three formats, it shows them. Each gets
a real sample line, what every column means, and where the format is
meant to be used: tsv for `IFS=$'\t' read` or cut, json for jq, portal
for xdg-desktop-portal-wlr's simple chooser, with the config stanza to
paste. Plus worked examples of focusing a window, handling either kind
of pick, and screenshotting one with grim -T.
2026-08-23 14:07:11 +01:00
Milad Alizadeh 6d8ae655b9 Say why the overlay closed, and document focusing both kinds of tile
--verbose now reports whether the overlay was picked from, cancelled, or
closed by the compositor. Chasing a "keys do nothing" symptom that turned
out to be a locked session, that distinction was the piece of information
I kept lacking: an exit code of 1 cannot tell a cancel from a surface the
compositor took away.

README now shows the two commands a caller needs — [con_id=N] focus for a
window, focus output NAME for a display — and that --focus runs them.
2026-08-23 13:26:54 +01:00
Milad Alizadeh 5b1f0f74e8 Add display tiles, three output formats, and hjkl
Displays are capture sources too — ext-image-capture-source-v1 makes one
from a wl_output just as it does from a toplevel handle — so they are now
tiles as well, appended after the windows and labelled "NAME · display".
They are snapshot-only: a live display tile contains this overlay, which
contains the display tile, and refreshing that never settles while
costing a whole screen per frame. They also only get one buffer for the
same reason, which is worth ~29MB here.

The bigger change is what wlgrid reports. It was focusing the pick itself
and printing only under --print, which suits a keybinding and nothing
else. Now it is a chooser: it always reports the pick, never acts unless
asked (--focus), exits 1 when cancelled, and can say it three ways.

--format portal emits what xdg-desktop-portal-wlr's simple chooser reads
("Monitor: NAME" / "Window: <foreign-toplevel identifier>"), so wlgrid
can be the picker behind getDisplayMedia, with live previews of windows
and displays. That contract is also why tsv carries both identifiers: the
portal and grim -T want the toplevel identifier, sway scripting wants the
con_id. --format json gives the whole record for jq.

Navigation also takes hjkl, and --help now describes every flag with its
default plus the output formats.
2026-08-23 12:33:25 +01:00
Milad Alizadeh 33d75222cf Make the previews live
Capture sessions stay open and tiles refresh, so the grid shows what the
windows are actually doing rather than a snapshot from when it opened.
--live all|current|none picks how much of that happens, --fps caps it.

Three things keep it cheap:

The protocol is damage-driven. After a session's first frame the
compositor only produces another once the content changes, so a request
left outstanding on an idle window costs nothing. Measured with one
animating window out of ten: 52,52,1,1,1,1,1,1,13,1 frames over 4s — the
static windows delivered their first frame and then nothing.

The overlay's own wl_surface.frame callbacks are the clock, so refreshes
stop when it isn't being presented and no timer or poll loop is needed.
Per-tile throttling on top of that measured 12.1/s at --fps 12.

Each window gets two buffers, since a capture must not write into one the
compositor is reading, and wl_buffer.release says which is free. That
release is the whole contract: with wl_shm the compositor copies the
pixels at commit and hands the buffer straight back, so the slot on
screen is usually free too. Waiting for it to stop being the displayed
slot instead — which is what this first did — deadlocks after two frames,
with both slots stuck busy (687 blocked attempts, 2 frames per tile).

Live mode doubles the shm handed to the compositor (110MB for ten windows
here, against 55MB with --live none); our own RSS is unaffected because
those pages are still never mapped. --verbose now reports frames, ticks,
releases, blocked attempts and pool size, which is what localised the
release bug.
2026-08-23 10:54:06 +01:00
Milad Alizadeh 2cd076699d Label the tiles
"title · app" centred under each thumbnail, in the same font the rofi
theme used (Berkeley Mono at pango's "small"), with the selected tile's
label inverted onto the yellow the way rofi's element background did.
Long titles are ellipsised to the cell width.

Text comes from cosmic-text, which brings real shaping. The catch is
cost: building a font system and rasterising the first glyphs takes
~55ms, nearly doubling a 65ms startup. But the capture phase is ~55ms of
sitting blocked while the compositor copies pixels, so labels are shaped
on a worker thread started before the captures and joined after them.
The measured labels phase is now 0.0ms — it costs nothing in wall clock.

Two thirds of that font cost was FontSystem::new() scanning all 1793
system faces, which even new_with_fonts() does. So the database is built
by hand: the user's own font directories first, since they are small,
and the full system scan only when the family isn't found there. An
unknown family still resolves, because that fallback is exactly the
system scan (verified: --font "No Such Font" renders in Noto).

--hide-labels restores the icon-only grid, and --font/--font-size make
the family and size settable. Adds a test that a label actually puts
pixels on the surface, one for ellipsising, and one pinning the label row
into the element geometry.
2026-08-23 10:39:37 +01:00
Milad Alizadeh dbfc06519a Add wlgrid: a window-thumbnail grid overlay for wlroots
A switcher to replace a wlthumbs + rofi pipeline, with the same look
(gruvbox, ceil(sqrt(n)) columns capped at 4, 16:9 tiles, a yellow
selection filling the element padding) but no thumbnails anywhere.

Each window is captured straight into a wl_shm buffer that is handed to
its own wl_subsurface, with wp_viewporter giving the compositor the
rectangle to scale it into. So there is no PNG encode, no scaler, no
full-resolution bitmap in this process, and the capture buffers are never
even mapped here — the compositor writes those pages and samples them
again for display. Opens in ~65ms for 8 windows (55ms of which is the
compositor reading pixels back out of the GPU) and holds ~9MB of RSS.

All capture sessions are opened before a single roundtrip and every frame
goes in flight together, the same batching wlthumbs uses, because the
readback is bandwidth-bound rather than latency-bound.

sway remains the source of truth: the window list, the con_ids and the
focusing all come from its IPC socket, joined to the Wayland side by
foreign_toplevel_identifier. Navigation reads raw evdev keycodes so it is
layout-independent, which does mean virtual-keyboard clients that invent
their own keymap can't drive it; that resolves when filtering brings xkb.

Labels, type-to-filter and live previews are next.
2026-08-23 10:07:09 +01:00