RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
Plan: tabs in the titlebar
Status: draft, 2026-11-22. Nothing is built or compiled; this was written from a
read of master (deefb71) in a sandbox without Zig 0.17, so every file and line
reference below is from reading, not from a build. The decisions are proposals
except the three marked chosen.
Scope: a tab strip drawn in the window titlebar, fed by the app, shared by every
rediwm-* program. First user is rediwm-editor; rediwm-files follows once its
per-folder state is split out of App. Out of scope: dragging a tab out into a
new window (needs xdg-toplevel-drag), tabs for third-party apps (their window
groups in window_tabs.zig keep working as they do), pinned tabs.
Branch: feat/titlebar-tabs, cut from master, independent of the Files
branches. Phases 1-4 touch no file under src/files, so the branch can land
first; Files adopts the shared client helper afterwards (phase 5) on whatever
branch Files work has landed on by then.
Decisions
- Chosen: the compositor paints the strip, the app publishes it. The titlebar
is server-side for
rediwm-*apps, so the compositor owns those pixels. An app that painted its own strip would have to self-decorate and duplicate the frame, the window controls, the shape rule ("every ring pixel needs body content beneath it") and the theme knobs (chrome_height,chrome_control_gap,chrome_round_buttons, ...). A small private protocol avoids all of that. - Chosen: first pass is the mechanism plus the Editor. Files needs a per-tab view split first (see "Files, later").
- Chosen: the Editor's menu button takes the leading slot (where the mockup shows the app icon).
- The toolkit owns behaviour, each surface keeps its painter. Model,
geometry, hit testing, overflow and drag-reorder move into
ui. The compositor keeps its Renderer painter. A Cairo painter for the self-decorated fallback is a later step, the same split the scrollbar uses (Lookshared;paint/cairo.drawScrollbarper surface). - Full state on every commit, not deltas. A strip is at most 128 tabs of short
strings; resending it removes a whole class of drift bugs. The compositor
already diffs by hash (
chrome_tabs.hash/layoutHash) and repaints only changed titles.
What the code says
chrome_tabs.zig(151 lines) already has the model (Tab,Strip,Hit),geometry,hit,hash/layoutHashand the painter. Its only compositor imports arechrome(which just re-exportswindow_chrome'sMetricsandcontrolRectScaled),icon_service,taskbar/chip_styleandwindow_tabs.Notice. The model, geometry, hit and hash code can move touialmost verbatim; the painter stays.- The strip's only producer is
toplevel/tabs.zig(tabStrip,fillTabs), which reads compositor window groups (window_tabs.members). Its consumers:toplevel/chrome_actions.zig:23(click),input/motion.zig:457(hover),input/buttons.zig:445(resize-edge exclusion),input/axis.zig:97(wheel) andtoplevel/chrome_sync.zig:161(allocation, gated ontab_group != 0). window_tabs.enabledreturns false for any app id startingrediwm-, so a published strip and a compositor window group can never both apply to a window.chrome.zig:506and:551draw the app icon only whentabs.len == 0: today a strip replaces the icon. The mockup shows both.- Tab ids are
u64inchrome_tabs.Tab(window ids today). The Editor'sTab.idis ausizecounter (next_id), unique for the process. - The Editor draws its own strip in
top = 40px of content (editor/app_paint.zig:225-248, geometry inapp_controls.zig:111-169, press handling inapp_input.zig:113-129), withtab_max/min176/112 px against the compositor's 170/85. Under SSD it reserves 80 px on the right for+and the menu; under CSD (has_titlebar, set inclient_window.zig:204,221) the menu lives in the fallback header (client_render.zig:109). - Editor drafts store unsaved tabs "in order" (
editor/drafts.zigheader), so a reorder must rewrite that order. KdeDecoration.zigis a short, complete model for a Zig-implemented custom global with per-surface resources; the new global follows its shape.- No rediwm-private protocol exists for chrome;
build/protocols.ziglists standard, wlr and a few custom XMLs underprotocol/.
Protocol: rediwm_titlebar_tabs_v1
The XML is protocol/rediwm-titlebar-tabs-v1.xml, added in build/protocols.zig
with addCustomProtocol and generate("rediwm_titlebar_tabs_manager_v1", 1).
The factory request takes a wl_surface, not an xdg_toplevel, like the KDE
decoration manager: the compositor resolves the toplevel from the surface and
attach adopts a strip created before the shell role exists.
Landed first (phase 2): add_tab(id, title, icon_name, flags),
set_selected, commit and the events select, close, new_tab. Still to
add with the leading slot and drag (phase 2c): set_leading_button(enabled) (shows the app icon),
leading_activated(x, y, width, height) and move(id, index). The protocol is
unreleased, so these are added to version 1.
Semantics:
commitreplaces the shown strip atomically from the pending list. An empty list removes the strip and the titlebar returns to its title row. A non-empty list needsset_selectednaming one of its ids, elseunknown_selected.- Bounds, checked on the compositor: at most
window_tabs.max_tabs(128) tabs; titles and icon names are cut at 256 / 128 bytes and must be valid UTF-8 (invalid ones are replaced, not fatal); ids unique per commit. icon_nameis accepted and ignored for now: every tab shows the app's own icon, as the compositor's strip does today. Per-tab icons resolve throughicon_servicelater.- The compositor never changes the selected tab on its own. A click sends
select; the strip updates when the app commits. One frame of latency, no divergence. Hover and the drag preview are local to the compositor. moveis sent once, on release, with the final index. During the drag the compositor paints the moved tab under the pointer and shifts its neighbours.- The resource is bound to one
wl_surface; destroying it or the surface removes the strip. - Only
modifiedandattentionexist in v1. The compositor showsmodifiedas a bullet in front of the title (\u2022 name), so truncation never hides it.
Toolkit: ui/widgets/title_tabs.zig
Pure, no compositor imports, with tests in ui/title_tabs_tests.zig (reached
from the module's test block):
Tab,Strip,Hit,keyfromchrome_tabs.zig.Tab.idstaysu64,flagsreplacesattention,titleandicon_nameare slices owned by the caller.Noticestays in the compositor: the strip takes an optionalbusylabel instead.geometry(width, density, strip, leading): as today, with a leading slot (icon or button,22 * densitywide plus gap) before the first tab.hit,hash,layoutHashunchanged in meaning.Drag: a state machine (press-> pending until 4 * density px -> dragging ->releasereturns the insertion index). It takes the geometry, so it is testable without a window.- Hover/close-button rule as one function: close button on the active and the hovered tab, never both a close button and a modified dot on one tab.
chrome_tabs.zig keeps paint and the compositor's Strip adapter.
Compositor
src/titlebar_tabs.zig: the global and per-toplevel resource (shape ofKdeDecoration.zig).Toplevelgainstitlebar_tabs: ?*TitlebarTabs, cleared on toplevel and resource destruction.toplevel/tabs.zig:tabStrippicks the published strip when present;tabAtdrops itstab_group == 0gate for it.stepTaband the wheel (input/axis.zig:97) sendselectfor the neighbouring id instead of focusing a window.toplevel/chrome_actions.zig:handleChromeClickdispatches.tab,.close,.plusand.previous/.nextby source: window group as today, otherwiseselect,close,new_tab,select. A press on a tab startsDraginstead of acting on press for published strips, so a click is decided on release. Middle click on a tab sendsclose.input/motion.zigandinput/buttons.zig: feed the drag from pointer motion and release; the resize-edge exclusion already usestabAt, so it holds.toplevel/chrome_sync.zig:161: allocate tab storage when either source has tabs; a published strip is copied to a per-resource buffer first so the immutable-buffer rule inchrome.zigis respected.chrome.zig: draw the icon (or leave the leading slot to the button) with a strip present;chrome_tabs.geometrystarts after it.- Leading slot: a ghost
button.paintbutton. The compositor cannot know whether the app's popup is open, so v1 has no selected state for it. - IPC: add published tabs and the leading button as nodes under the window's
window/<id>entry inipc/handlers_widgets.zig(which already builds that node), so the integration suites can click them.
Editor (src/editor)
- New
app_tabs_publish.zig: builds the pending list fromApp.tabs(id =Tab.id, title =tab.name(),modified=tab.doc.modified()), commits when a hash of (ids, titles, flags, selected) changes. Called from the loop inmain.zigbeside thetitle_changedhandling. - Events:
select->findTab,selected = i,changed().close-> select thencloseSelected()(keeps the unsaved-work prompt).new_tab->act(.new).move-> reorderApp.tabskeepingselectedon the same tab, then rewrite the draft order.leading_activated->toggleMenuwith a left-anchored variant (it takes the right edge today). - When the compositor offers the protocol and the window is SSD:
topstops being a constant (app.zig:35) and becomes 0 (viewTop,tabRight, the find-bar offset inapp_paint.zig:161, the press testpy < topinapp_input.zig:113,ime.sync), the in-content strip and itstab_scroll,revealTabandscrollTabsare skipped, andHoverloses.close/.new/.menu. - Self-decorated fallback (no global,
force_csd, or a client-side decoration mode) keeps today's strip unchanged. Replacing it with the toolkit widget inrenderTitlebaris a follow-up and the first step toward Files. - Shared client helper:
ui/client_tabs.zig(bind, double-buffered commit, event vtableselect/close/new/move/leading) so Files adds no protocol code.
Look: differences from the mockup
- Icon, then tabs, then
+, then the window controls: needs the leading slot. - The mockup shows a close button only on the active tab; the compositor paints one on every tab today. The rule above (active and hovered) matches the mockup.
- The active tab has an accent top bar in the mockup; the compositor's tab uses
the taskbar chip look. Decide whether the strip keeps the chip look (matches
the taskbar) or gets a dedicated tab look (matches the mockup); it is a
chip_style.lookcall either way. - Tab width: one constant pair for everything (the compositor's 170/85 scaled by density) instead of the Editor's 176/112 px.
Files, later
App holds every piece of per-folder state directly (items, history,
loading, active_request_id, selection, scroll, sort_mode, list_view,
column widths, ...). Tabs need a per-tab view. Proposal: each tab keeps only
path, history, sort, scroll and selection and re-lists on activation; only the
active tab owns items and the worker request. That avoids N watchers, N
workers and N thumbnail caches. Tab title is the folder name; icon_name is the
folder icon. This touches files/app.zig and the retained-hover paths that other
branches are changing, so it should start from whichever branch those land on.
Phases and gates
- Hoist model/geometry/hit/hash/
Dragintoui/widgets/title_tabs.zig, add its tests. Gate: the existingchrome_tests.zigtab raster test ("tab title updates preserve neighbouring pixels and match a full raster") and the window-tabs integration suites pass unchanged; compositor output is byte-identical. - Protocol and compositor: XML,
titlebar_tabs.zig, strip source, click, hover, wheel, drag, IPC exposure. Gate: a headless test client publishes a strip and drives select/close/new/move through the IPC harness. - Editor on the helper. Gate:
zig build test(editor roots), editor integration suites, a drafts-order test formove, manual SSD andREDIWM_EDITOR_FORCE_CSDruns. - CSD fallback via the toolkit (Cairo painter, chip look moved to
ui). - Files per-tab view, then publish through the same helper.
Before finishing each phase: Debug and -Doptimize=ReleaseSafe builds, zig build test, and the integration tests for what was touched (root AGENTS.md).
Risks and open questions
- Latency: select and close round-trip through the app. At one commit per change this should be under a frame, but a busy app (large file save) delays the highlight. If it shows, the compositor can highlight optimistically until the next commit.
- Trust: any client may bind the global, but a strip is only ever drawn in that client's own titlebar, like its title. Bounds above cover memory.
- Third-party apps (browsers) could use the same protocol later; v1 is kept small enough for that.
- Open: keep the chip look or add a tab look; whether
modifiedshould also tint the tab; whether double-click on empty strip space should still maximize (it does today, since only tabs and buttons count as controls).
Phase 2c notes
- Drag state lives on
Toplevel.tab_drag;Input.tab_dragonly records which window is pressed. A press decides nothing: release selects (no travel) or sendsmove(travel past 4 px). A drag never also selects. - After release the dragged tab snaps back until the app commits the new order (one frame of flicker; an optimistic preview can come later if latency shows).
- Middle click on a published tab sends
close. - IPC exposure of published tabs is deferred.
Phase 6 (proposal): tear a tab off, merge it into another window
Goal: pull a tab out of the strip and it becomes a window; drop it on another window's strip and it joins that window. Not built; written down so the protocol stays compatible.
What decides the shape
- The compositor does not own tab content. It can only tell the app what the
user did; the app moves the content. So both gestures are events, like
move. - Merge is limited to windows of one client (one
wl_client). The app then owns both models and moves the tab in memory. Merging across processes needs a data-offer style handshake (opaque token, app-id match, the target asking the source for the payload); not needed while each app is one process. - The editor is one process per display (
editor/instance.zigforwards open requests to the primary), with oneClientand oneApp. A second editor window means the editor must become multi-window: oneApp+Clientper toplevel, one shared display connection, drafts keyed by window. This is the large part of the work and is independent of the compositor side.
Protocol (version 2 of rediwm_titlebar_tabs_v1)
- event
tear_off(id, x, y): the button came up outside every strip.x,yare the pointer in output layout coordinates. The app opens a new toplevel holding the tab and removes the tab from its strip (commits). - event
drop_on(id, target, index): the button came up over another strip of the same client.targetis that strip's object (anobjectargument, so the compositor can only name strips of this client);indexis the slot, counted as inmove. The app moves the tab to the target and commits both. - Placement: the compositor remembers
{client, x, y, expires}when it sendstear_offand applies it to the next new toplevel of that client within about two seconds, so the window opens with its tab under the pointer. - Both only ask, like
select: nothing changes until the app commits. If the app does nothing, the tab snaps back.
Compositor
Draggains a state beyond "dragging in the strip": once the pointer leaves the strip's band by more than the titlebar height (and has no neighbour strip below it), the drag is out. The strip stops previewing and the cursor becomesgrabbing.- While out, hit-test the toplevel under the pointer. If it is the same client
and the pointer is in its titlebar, that strip shows an insertion marker
(
Strip.drop_index, part of the hash) atDrag.targetcomputed against its geometry. - Release: over a same-client strip, send
drop_on; anywhere else, sendtear_off; Escape or losing the press cancels. No ghost tab at first (cursor and drop marker only); a small retained-buffer ghost can follow. - Tabs are only draggable out when the app says so (a
set_tab_flagscapability or a per-tab flag), so a one-tab window does not tear itself off into the same window.
Editor and Files
- Editor: multi-window refactor first (own phase), then
tear_offcreates a window,drop_onmoves theTabbetweenApps. The tab keeps its document, undo history and draft name, so no text is rewritten. - Files: a tab is a folder view, cheap to move once per-tab state is split
from
App(the Files phase already needs it).
As built in 6a
- Version 2 adds
set_detachable(enabled)(a client opts in; the default is off so an app that ignores the events never starts a drag-out),tear_offanddrop_on. The manager is version 2; strips take the manager's version. tear_offis not sent for the last tab of a strip.drop_onis only sent between strips of onewl_client.Drag.outis set when the pointer is more than half a titlebar above or one and a half below the strip; while out, the strip shows no reorder preview. The target strip shows a gap and an accent marker (Strip.drop_index).- Placement:
Manager.tear_offremembers the client and pointer for two seconds;lifecycle.zigopens the client's next toplevel with its tab area under the pointer. - Client helper:
Handler.tear_off/Handler.drop_onare optional; providing either turnsset_detachableon.
Phases
6a. Protocol v2, compositor drag states, drop marker, placement hint, tests on
Drag geometry and a headless client that receives both events.
6b. Editor multi-window (no tab gesture yet): open a second window from the
menu; drafts and the single-instance socket handle several windows.
6c. Editor tear_off / drop_on.
6d. Files.