RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
Add rediwm_titlebar_tabs_v1 and show published tabs in the titlebar
Claude8d64c816754c
diff --git a/build/protocols.zig b/build/protocols.zigindex 2eaa36f..bd4b542 100644--- a/build/protocols.zig+++ b/build/protocols.zig@@ -28,6 +28,7 @@ pub fn module(b: *std.Build) *std.Build.Module {scanner.addSystemProtocol("unstable/idle-inhibit/idle-inhibit-unstable-v1.xml");scanner.addSystemProtocol("unstable/xdg-decoration/xdg-decoration-unstable-v1.xml");scanner.addCustomProtocol(b.path("protocol/server-decoration.xml"));+ scanner.addCustomProtocol(b.path("protocol/rediwm-titlebar-tabs-v1.xml"));scanner.addCustomProtocol(b.path("protocol/virtual-keyboard-unstable-v1.xml"));scanner.addSystemProtocol("unstable/pointer-gestures/pointer-gestures-unstable-v1.xml");scanner.addSystemProtocol("unstable/xdg-output/xdg-output-unstable-v1.xml");@@ -56,6 +57,7 @@ pub fn module(b: *std.Build) *std.Build.Module {scanner.generate("wp_color_manager_v1", 2);scanner.generate("zxdg_decoration_manager_v1", 1);scanner.generate("org_kde_kwin_server_decoration_manager", 1);+ scanner.generate("rediwm_titlebar_tabs_manager_v1", 1);scanner.generate("zwp_virtual_keyboard_manager_v1", 1);scanner.generate("zwp_pointer_gestures_v1", 3);scanner.generate("zxdg_output_manager_v1", 3);diff --git a/docs/agent-notes/map.md b/docs/agent-notes/map.mdindex 7c17d1c..0877d34 100644--- a/docs/agent-notes/map.md+++ b/docs/agent-notes/map.md@@ -69,7 +69,8 @@ seam for other operating systems.| `Taskbar.zig` | `taskbar/` | the taskbar; value types in `taskbar/types.zig` || `Dock.zig` | `dock/` | the dock ([dock notes](dock.md)) |-Also in `src/`: `Shell.zig` (xdg-shell and decorations), `Popup.zig`,+Also in `src/`: `Shell.zig` (xdg-shell and decorations), `TitlebarTabs.zig` (client-published+titlebar tabs, `protocol/rediwm-titlebar-tabs-v1.xml`), `Popup.zig`,`LayerSurface.zig`, `Xwayland.zig` (+ `xwayland_*.zig`), `Switcher.zig`(Alt+Tab), `workspaces.zig`, `snap.zig`, `auto_tiling.zig`, `window_tabs.zig`.diff --git a/docs/plans/titlebar-tabs.md b/docs/plans/titlebar-tabs.mdindex 3794b53..f7cfeda 100644--- a/docs/plans/titlebar-tabs.md+++ b/docs/plans/titlebar-tabs.md@@ -72,66 +72,17 @@ branch Files work has landed on by then.## Protocol: `rediwm_titlebar_tabs_v1`-New file `protocol/rediwm-titlebar-tabs-v1.xml`, added in `build/protocols.zig`+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.-```xml-<protocol name="rediwm_titlebar_tabs_v1">- <interface name="rediwm_titlebar_tabs_manager_v1" version="1">- <request name="destroy" type="destructor"/>- <request name="get_titlebar_tabs">- <arg name="id" type="new_id" interface="rediwm_titlebar_tabs_v1"/>- <arg name="toplevel" type="object" interface="xdg_toplevel"/>- </request>- <enum name="error">- <entry name="already_constructed" value="0"/>- </enum>- </interface>-- <interface name="rediwm_titlebar_tabs_v1" version="1">- <request name="destroy" type="destructor"/>-- <!-- Pending state; nothing shows until commit. add_tab order is tab order. -->- <request name="add_tab">- <arg name="id" type="uint"/>- <arg name="title" type="string"/>- <arg name="icon_name" type="string" allow-null="true"/>- <arg name="flags" type="uint" enum="flags"/>- </request>- <request name="set_selected"><arg name="id" type="uint"/></request>- <request name="set_leading">- <arg name="icon_name" type="string" allow-null="true"/>- <arg name="label" type="string"/>- </request>- <request name="commit"/>-- <enum name="flags" bitfield="true">- <entry name="modified" value="1"/>- <entry name="attention" value="2"/>- </enum>- <enum name="error">- <entry name="duplicate_id" value="0"/>- <entry name="unknown_selected" value="1"/>- <entry name="too_many_tabs" value="2"/>- </enum>-- <!-- The user asked; the app changes its state and commits the result. -->- <event name="select"><arg name="id" type="uint"/></event>- <event name="close"><arg name="id" type="uint"/></event>- <event name="new_tab"/>- <event name="move">- <arg name="id" type="uint"/>- <arg name="index" type="uint"/>- </event>- <!-- Button rectangle in the toplevel surface's coordinates (y is negative:- the titlebar sits above the surface), so the app can anchor a popup. -->- <event name="leading_activated">- <arg name="x" type="int"/><arg name="y" type="int"/>- <arg name="width" type="int"/><arg name="height" type="int"/>- </event>- </interface>-</protocol>-```+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`,+`leading_activated(x, y, width, height)` and `move(id, index)`. The protocol is+unreleased, so these are added to version 1.Semantics:@@ -141,17 +92,18 @@ Semantics:* 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_name` is a freedesktop icon name resolved by the compositor's- `icon_service` at tab-icon size. Absent, the tab shows the app's own icon, as- today.+* `icon_name` is accepted and ignored for now: every tab shows the app's own+ icon, as the compositor's strip does today. Per-tab icons resolve through+ `icon_service` later.* 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, nodivergence. Hover and the drag preview are local to the compositor.* `move` is sent once, on release, with the final index. During the drag thecompositor paints the moved tab under the pointer and shifts its neighbours.-* The resource is bound to one `xdg_toplevel`; destroying either removes the strip.-* Only `modified` (a dot that never gives way to the close button, like the- Editor's today) and `attention` exist in v1.+* The resource is bound to one `wl_surface`; destroying it or the surface removes the strip.+* Only `modified` and `attention` exist in v1. The compositor shows `modified`+ as a bullet in front of the title (`\u2022 name`), so truncation never hides+ it.## Toolkit: `ui/widgets/title_tabs.zig`diff --git a/protocol/rediwm-titlebar-tabs-v1.xml b/protocol/rediwm-titlebar-tabs-v1.xmlnew file mode 100644index 0000000..5a0ad4f--- /dev/null+++ b/protocol/rediwm-titlebar-tabs-v1.xml@@ -0,0 +1,113 @@+<?xml version="1.0" encoding="UTF-8"?>+<protocol name="rediwm_titlebar_tabs_v1">+ <description summary="tabs in the compositor's titlebar">+ An application publishes the tabs of its window and the compositor paints+ them in the window's titlebar. The compositor draws and hit-tests the strip;+ the application owns the tabs and the user's actions come back as events.+ The strip only shows while the compositor draws the window's titlebar+ (server-side decorations). An application that has to draw its own titlebar+ draws its own tabs.++ Private to rediwm and its bundled applications.+ </description>++ <interface name="rediwm_titlebar_tabs_manager_v1" version="1">+ <description summary="titlebar tabs factory"/>++ <request name="destroy" type="destructor">+ <description summary="destroy the factory">+ Objects already created from it stay valid.+ </description>+ </request>++ <request name="get_titlebar_tabs">+ <description summary="create the tab strip for a toplevel's surface">+ The surface is, or will become, the surface of an xdg_toplevel. Like+ the KDE decoration manager this can be sent before the shell role is+ assigned. The strip is empty until the first commit.+ </description>+ <arg name="id" type="new_id" interface="rediwm_titlebar_tabs_v1"/>+ <arg name="surface" type="object" interface="wl_surface"/>+ </request>++ <enum name="error">+ <entry name="already_constructed" value="0"+ summary="the surface already has a tab strip"/>+ </enum>+ </interface>++ <interface name="rediwm_titlebar_tabs_v1" version="1">+ <description summary="a toplevel's titlebar tab strip">+ State is double-buffered: add_tab, set_selected and the like build a+ pending strip that replaces the shown one on commit. The pending state+ is empty again after every commit, so each commit describes the whole+ strip.+ </description>++ <enum name="error">+ <entry name="duplicate_id" value="0"+ summary="two tabs in one commit have the same id"/>+ <entry name="unknown_selected" value="1"+ summary="the selected id is not among the tabs"/>+ <entry name="too_many_tabs" value="2"+ summary="more than 128 tabs in one commit"/>+ <entry name="invalid_id" value="3"+ summary="tab ids must not be zero"/>+ </enum>++ <enum name="flags" bitfield="true">+ <entry name="modified" value="1"+ summary="the tab has unsaved changes; shown as a leading bullet"/>+ <entry name="attention" value="2"+ summary="the tab asks for attention"/>+ </enum>++ <request name="destroy" type="destructor">+ <description summary="remove the strip and destroy the object"/>+ </request>++ <request name="add_tab">+ <description summary="append a tab to the pending strip">+ Tabs show in the order they are added. Titles longer than 256 bytes+ are cut; a title that is not valid UTF-8 is replaced. The icon name+ is accepted and ignored in this version; every tab shows the+ application's icon.+ </description>+ <arg name="id" type="uint" summary="the application's id for the tab, not zero"/>+ <arg name="title" type="string"/>+ <arg name="icon_name" type="string" allow-null="true"/>+ <arg name="flags" type="uint" summary="a bitfield of flags"/>+ </request>++ <request name="set_selected">+ <description summary="select a tab in the pending strip">+ Required before a commit that adds tabs, and it must name one of them.+ </description>+ <arg name="id" type="uint"/>+ </request>++ <request name="commit">+ <description summary="show the pending strip">+ Replaces the shown strip. A commit with no tabs removes the strip and+ the titlebar goes back to showing the window's title.+ </description>+ </request>++ <event name="select">+ <description summary="the user selected a tab">+ The compositor does not change the selected tab itself: the+ application changes its state and commits the result.+ </description>+ <arg name="id" type="uint"/>+ </event>++ <event name="close">+ <description summary="the user asked to close a tab"/>+ <arg name="id" type="uint"/>+ </event>++ <event name="new_tab">+ <description summary="the user pressed the new tab button"/>+ </event>+ </interface>+</protocol>diff --git a/src/Server.zig b/src/Server.zigindex 15470cd..e98504c 100644--- a/src/Server.zig+++ b/src/Server.zig@@ -74,6 +74,7 @@ pub const CompositorError = error{XdgShellCreateFailed,XdgDecorationCreateFailed,KdeDecorationCreateFailed,+ TitlebarTabsCreateFailed,CompositorCreateFailed,SubcompositorCreateFailed,DataDeviceManagerCreateFailed,diff --git a/src/Shell.zig b/src/Shell.zigindex ac901b8..f399cb5 100644--- a/src/Shell.zig+++ b/src/Shell.zig@@ -8,6 +8,7 @@ const wl = @import("wayland").server.wl;const wlr = @import("wlroots");const KdeDecoration = @import("KdeDecoration.zig");+const TitlebarTabs = @import("TitlebarTabs.zig");const Decoration = @import("Decoration.zig");const Popup = @import("Popup.zig");const Server = @import("Server.zig");@@ -20,6 +21,7 @@ const log = std.log.scoped(.shell);server: *Server,kde_decorations: KdeDecoration.Manager,+titlebar_tabs: TitlebarTabs.Manager,xdg_shell: *wlr.XdgShell,xdg_decoration_manager: *wlr.XdgDecorationManagerV1,new_xdg_toplevel: wl.Listener(*wlr.XdgToplevel) = .init(newXdgToplevel),@@ -34,16 +36,19 @@ pub fn init(shell: *Shell, server: *Server) Server.CompositorError!void {shell.* = .{.server = server,.kde_decorations = undefined,+ .titlebar_tabs = undefined,.xdg_shell = xdg_shell,.xdg_decoration_manager = xdg_decoration_manager,};shell.kde_decorations.init(server) catch return error.KdeDecorationCreateFailed;+ shell.titlebar_tabs.init(server) catch return error.TitlebarTabsCreateFailed;shell.xdg_shell.events.new_toplevel.add(&shell.new_xdg_toplevel);shell.xdg_shell.events.new_popup.add(&shell.new_xdg_popup);shell.xdg_decoration_manager.events.new_toplevel_decoration.add(&shell.new_xdg_decoration);}pub fn deinit(shell: *Shell) void {+ shell.titlebar_tabs.deinit();shell.kde_decorations.deinit();shell.new_xdg_toplevel.link.remove();shell.new_xdg_popup.link.remove();diff --git a/src/TitlebarTabs.zig b/src/TitlebarTabs.zignew file mode 100644index 0000000..3d213bc--- /dev/null+++ b/src/TitlebarTabs.zig@@ -0,0 +1,261 @@+//! rediwm_titlebar_tabs_v1: an application publishes the tabs of its window and+//! the compositor paints them in the titlebar (`chrome_tabs.zig`, geometry and+//! hit testing in `ui/widgets/title_tabs.zig`). Like the KDE decoration+//! manager, the object belongs to a wl_surface and can precede its shell role.+//! The compositor never changes what is selected: clicks go back to the+//! application as events and the strip changes when it commits.+const std = @import("std");+const wl = @import("wayland").server.wl;+const rediwm = @import("wayland").server.rediwm;+const wlr = @import("wlroots");+const Server = @import("Server.zig");+const Toplevel = @import("Toplevel.zig");+const chrome_tabs = @import("chrome_tabs.zig");+const scene_data = @import("scene_data.zig");+const window_tabs = @import("window_tabs.zig");+const gpa = @import("main.zig").gpa;++const TitlebarTabs = @This();+const Resource = rediwm.TitlebarTabsV1;+const ManagerResource = rediwm.TitlebarTabsManagerV1;++pub const max_tabs = window_tabs.max_tabs;+/// Longest title kept, in bytes.+pub const max_title = 256;+pub const flag_modified: u32 = 1;+pub const flag_attention: u32 = 2;++const Item = struct {+ id: u32,+ /// What the strip shows: the title, behind a bullet when modified.+ title: []u8,+ attention: bool,+};++resource: *Resource,+surface: ?*wlr.Surface,+toplevel: ?*Toplevel = null,+link: wl.list.Link = undefined,+surface_destroy: wl.Listener(*wlr.Surface) = .init(handleSurfaceDestroy),+pending: std.ArrayList(Item) = .empty,+pending_selected: ?u32 = null,+items: std.ArrayList(Item) = .empty,+selected: u32 = 0,++pub const Manager = struct {+ global: *wl.Global,+ strips: wl.list.Head(TitlebarTabs, .link) = undefined,++ pub fn init(self: *Manager, server: *Server) !void {+ self.* = .{ .global = try wl.Global.create(server.wl_server, ManagerResource, 1, *Manager, self, bind) };+ self.strips.init();+ }++ pub fn deinit(self: *Manager) void {+ self.global.destroy();+ while (self.strips.first()) |strip| strip.resource.destroy();+ }++ /// Called for each new toplevel: adopts a strip created before the shell role.+ pub fn attach(self: *Manager, toplevel: *Toplevel) void {+ var it = self.strips.iterator(.forward);+ while (it.next()) |strip| {+ if (strip.surface == toplevel.surface()) {+ strip.toplevel = toplevel;+ toplevel.titlebar_tabs = strip;+ return;+ }+ }+ }++ fn bind(client: *wl.Client, self: *Manager, version: u32, id: u32) void {+ const resource = ManagerResource.create(client, version, id) catch {+ client.postNoMemory();+ return;+ };+ resource.setHandler(*Manager, handleRequest, null, self);+ }++ fn handleRequest(manager: *ManagerResource, request: ManagerResource.Request, self: *Manager) void {+ switch (request) {+ .destroy => manager.destroy(),+ .get_titlebar_tabs => |args| {+ const surface = wlr.Surface.fromWlSurface(args.surface);+ var it = self.strips.iterator(.forward);+ while (it.next()) |existing| {+ if (existing.surface == surface) {+ manager.postError(.already_constructed, "surface already has titlebar tabs");+ return;+ }+ }+ const strip = gpa.create(TitlebarTabs) catch {+ manager.getClient().postNoMemory();+ return;+ };+ const resource = Resource.create(manager.getClient(), 1, args.id) catch {+ gpa.destroy(strip);+ manager.getClient().postNoMemory();+ return;+ };+ strip.* = .{ .resource = resource, .surface = surface };+ self.strips.append(strip);+ surface.events.destroy.add(&strip.surface_destroy);+ resource.setHandler(*TitlebarTabs, handleStripRequest, handleDestroy, strip);+ // Only the exact toplevel surface may receive chrome. Never+ // walk popup parents or subsurface roots here.+ if (wlr.XdgSurface.tryFromWlrSurface(surface)) |xdg| {+ if (scene_data.xdgSceneTree(xdg)) |tree| {+ if (scene_data.SceneData.fromNodeOrParents(&tree.node)) |data| {+ if (data.role == .toplevel and data.role.toplevel.surface() == surface) {+ strip.toplevel = data.role.toplevel;+ data.role.toplevel.titlebar_tabs = strip;+ }+ }+ }+ }+ },+ }+ }+};++/// Whether a strip is shown (a committed list with at least one tab).+pub fn active(self: *const TitlebarTabs) bool {+ return self.items.items.len > 0;+}++/// The committed tabs into `storage` and `strip`; returns the index of the+/// selected tab (0 when none is).+pub fn fill(self: *const TitlebarTabs, storage: *[window_tabs.max_tabs]chrome_tabs.Tab, strip: *chrome_tabs.Strip) usize {+ var current: usize = 0;+ for (self.items.items, 0..) |item, i| {+ const is_selected = item.id == self.selected;+ storage[i] = .{ .id = item.id, .title = item.title, .active = is_selected, .attention = item.attention };+ if (is_selected) current = i;+ }+ strip.tabs = storage[0..self.items.items.len];+ return current;+}++pub fn sendSelect(self: *TitlebarTabs, id: u64) void {+ self.resource.sendSelect(@intCast(id));+}++pub fn sendClose(self: *TitlebarTabs, id: u64) void {+ self.resource.sendClose(@intCast(id));+}++pub fn sendNewTab(self: *TitlebarTabs) void {+ self.resource.sendNewTab();+}++/// Asks the application to select the neighbouring tab, wrapping around.+pub fn step(self: *TitlebarTabs, forward: bool) void {+ const n = self.items.items.len;+ if (n < 2) return;+ for (self.items.items, 0..) |item, i| {+ if (item.id != self.selected) continue;+ const next = if (forward) (i + 1) % n else (i + n - 1) % n;+ self.resource.sendSelect(self.items.items[next].id);+ return;+ }+}++fn handleStripRequest(resource: *Resource, request: Resource.Request, self: *TitlebarTabs) void {+ switch (request) {+ .destroy => resource.destroy(),+ .add_tab => |args| self.addTab(args.id, std.mem.span(args.title), args.flags),+ .set_selected => |args| self.pending_selected = args.id,+ .commit => self.commit(),+ }+}++fn addTab(self: *TitlebarTabs, id: u32, raw: []const u8, flags: u32) void {+ if (id == 0) {+ self.resource.postError(.invalid_id, "tab ids must not be zero");+ return;+ }+ if (self.pending.items.len >= max_tabs) {+ self.resource.postError(.too_many_tabs, "too many tabs");+ return;+ }+ for (self.pending.items) |item| {+ if (item.id == id) {+ self.resource.postError(.duplicate_id, "duplicate tab id");+ return;+ }+ }+ const title = displayTitle(raw, flags & flag_modified != 0) catch {+ self.resource.getClient().postNoMemory();+ return;+ };+ self.pending.append(gpa, .{ .id = id, .title = title, .attention = flags & flag_attention != 0 }) catch {+ gpa.free(title);+ self.resource.getClient().postNoMemory();+ };+}++/// The text a tab shows: cut to `max_title` bytes on a character boundary,+/// replaced when not valid UTF-8, behind a bullet when modified. A bullet+/// leads so that a long title never pushes it out of the tab.+fn displayTitle(raw: []const u8, modified: bool) std.mem.Allocator.Error![]u8 {+ var end = @min(raw.len, max_title);+ while (end > 0 and end < raw.len and (raw[end] & 0xC0) == 0x80) end -= 1;+ var text = raw[0..end];+ if (!std.unicode.utf8ValidateSlice(text)) text = "?";+ return std.fmt.allocPrint(gpa, "{s}{s}", .{ if (modified) "\u{2022} " else "", text });+}++fn commit(self: *TitlebarTabs) void {+ if (self.pending.items.len > 0) {+ const wanted = self.pending_selected orelse {+ self.resource.postError(.unknown_selected, "commit without a selected tab");+ return;+ };+ var found = false;+ for (self.pending.items) |item| {+ if (item.id == wanted) found = true;+ }+ if (!found) {+ self.resource.postError(.unknown_selected, "selected tab is not in the strip");+ return;+ }+ self.selected = wanted;+ }+ freeItems(&self.items);+ self.items.deinit(gpa);+ self.items = self.pending;+ self.pending = .empty;+ self.pending_selected = null;+ if (self.toplevel) |toplevel| toplevel.syncChrome(false, Toplevel.nowMs()) catch {};+}++fn freeItems(list: *std.ArrayList(Item)) void {+ for (list.items) |item| gpa.free(item.title);+ list.clearRetainingCapacity();+}++fn detach(self: *TitlebarTabs) void {+ if (self.toplevel) |toplevel| toplevel.titlebar_tabs = null;+ self.toplevel = null;+}++fn handleSurfaceDestroy(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {+ const self: *TitlebarTabs = @fieldParentPtr("surface_destroy", listener);+ self.surface_destroy.link.remove();+ self.surface = null;+ self.detach();+ // The protocol resource may outlive the wl_surface; leave it inert.+}++fn handleDestroy(_: *Resource, self: *TitlebarTabs) void {+ const toplevel = self.toplevel;+ self.detach();+ if (self.surface != null) self.surface_destroy.link.remove();+ self.link.remove();+ freeItems(&self.items);+ self.items.deinit(gpa);+ freeItems(&self.pending);+ self.pending.deinit(gpa);+ gpa.destroy(self);+ if (toplevel) |top| top.syncChrome(true, Toplevel.nowMs()) catch {};+}diff --git a/src/Toplevel.zig b/src/Toplevel.zigindex f8e37ac..5f885e0 100644--- a/src/Toplevel.zig+++ b/src/Toplevel.zig@@ -161,6 +161,8 @@ content_tree: *sn.Tree,scene_tree: *sn.Node,decoration: ?*Decoration = null,kde_decoration: ?*@import("KdeDecoration.zig") = null,+/// Tabs the client publishes for the titlebar (rediwm_titlebar_tabs_v1).+titlebar_tabs: ?*@import("TitlebarTabs.zig") = null,frame_data: scene_data.SceneData = undefined,chrome_data: scene_data.SceneData = undefined,@@ -598,6 +600,7 @@ pub const handleIdentityChanged = toplevel_lifecycle.handleIdentityChanged;// toplevel/tabs.zigpub const tabStrip = toplevel_tabs.tabStrip;+pub const hasTabStrip = toplevel_tabs.hasTabStrip;pub const tabAt = toplevel_tabs.tabAt;pub const hoverTab = toplevel_tabs.hoverTab;pub const stepTab = toplevel_tabs.stepTab;diff --git a/src/toplevel/chrome_actions.zig b/src/toplevel/chrome_actions.zigindex 6661237..389c165 100644--- a/src/toplevel/chrome_actions.zig+++ b/src/toplevel/chrome_actions.zig@@ -23,6 +23,18 @@ pub fn handleChromeClick(toplevel: *Toplevel, sx: f64, sy: f64, button: u32) voiconst hit = toplevel.tabAt(sx, sy);if (hit != .none) {if (button != Input.btn_left) return;+ // Tabs the client published: it owns them, so a click is a request.+ if (toplevel.titlebar_tabs) |published| if (published.active()) {+ switch (hit) {+ .tab => |id| published.sendSelect(id),+ .close => |id| published.sendClose(id),+ .plus => published.sendNewTab(),+ .previous => published.step(false),+ .next => published.step(true),+ .none => {},+ }+ return;+ };switch (hit) {.tab => |id| if (toplevel.server.findToplevelById(id)) |target| toplevel.server.world.focus(target),.close => |id| if (toplevel.server.findToplevelById(id)) |target| {diff --git a/src/toplevel/chrome_sync.zig b/src/toplevel/chrome_sync.zigindex a289dc9..fa5e52d 100644--- a/src/toplevel/chrome_sync.zig+++ b/src/toplevel/chrome_sync.zig@@ -158,9 +158,9 @@ pub fn syncChrome(toplevel: *Toplevel, rebuild_shadow: bool, now_ms: i64) !voidtoplevel.updateHeldIcon(icon);const hover = toplevel.hover_anim.value(now_ms);const chip_alpha = toplevel.chip_alpha.value(now_ms);- // Only a grouped window has tabs. Others skip the 4 KiB scratch, which+ // Only a grouped window or one with published tabs has a strip. Others skip the 4 KiB scratch, which// ReleaseSafe would fill on every client commit.- const tab_storage = if (toplevel.tab_group != 0) try gpa.create([@import("../window_tabs.zig").max_tabs]@import("../chrome_tabs.zig").Tab) else null;+ const tab_storage = if (toplevel.hasTabStrip()) try gpa.create([@import("../window_tabs.zig").max_tabs]@import("../chrome_tabs.zig").Tab) else null;defer if (tab_storage) |storage| gpa.destroy(storage);var state: chrome.ChromeState = .{.tabs = toplevel.tabStrip(tab_storage),diff --git a/src/toplevel/create.zig b/src/toplevel/create.zigindex 819383f..1c89f36 100644--- a/src/toplevel/create.zig+++ b/src/toplevel/create.zig@@ -130,6 +130,7 @@ pub fn create(server: *Server, xdg_toplevel: *wlr.XdgToplevel) !void {finishCreate(toplevel, nodes, scene_tree);scene_data.setXdgSceneTree(xdg_surface, hosted);server.shell.kde_decorations.attach(toplevel);+ server.shell.titlebar_tabs.attach(toplevel);switch (toplevel.backend) {.xdg => |*adapter| adapter.listen(),.xwayland, .placeholder, .shell => {},diff --git a/src/toplevel/lifecycle.zig b/src/toplevel/lifecycle.zigindex bfa165b..5d76abc 100644--- a/src/toplevel/lifecycle.zig+++ b/src/toplevel/lifecycle.zig@@ -370,6 +370,10 @@ pub fn destroy(toplevel: *Toplevel) void {decoration.toplevel = null;toplevel.kde_decoration = null;}+ if (toplevel.titlebar_tabs) |strip| {+ strip.toplevel = null;+ toplevel.titlebar_tabs = null;+ }toplevel.backend_gone = true;}if (toplevel.tryDeferDestroy()) return;@@ -431,6 +435,10 @@ pub fn destroyNow(toplevel: *Toplevel) void {decoration.toplevel = null;toplevel.kde_decoration = null;}+ if (toplevel.titlebar_tabs) |strip| {+ strip.toplevel = null;+ toplevel.titlebar_tabs = null;+ }toplevel.backend_gone = true;}toplevel.clearChromeCache();diff --git a/src/toplevel/tabs.zig b/src/toplevel/tabs.zigindex c3a1dc5..0bb7f02 100644--- a/src/toplevel/tabs.zig+++ b/src/toplevel/tabs.zig@@ -5,7 +5,14 @@ const Toplevel = @import("../Toplevel.zig");const geometry = @import("../geometry.zig");const nowMs = Toplevel.nowMs;-/// `storage` may be null for a window outside any tab group, which has no tabs.+/// Whether the window has a strip: it is in a compositor tab group, or its+/// client has published tabs (rediwm_titlebar_tabs_v1).+pub fn hasTabStrip(toplevel: *const Toplevel) bool {+ if (toplevel.titlebar_tabs) |published| if (published.active()) return true;+ return toplevel.tab_group != 0;+}++/// `storage` may be null for a window without a strip, which has no tabs.pub fn tabStrip(toplevel: *Toplevel, storage: ?*[@import("../window_tabs.zig").max_tabs]@import("../chrome_tabs.zig").Tab) @import("../chrome_tabs.zig").Strip {var strip: @import("../chrome_tabs.zig").Strip = .{ .first = toplevel.tab_first, .hover = toplevel.tab_hover, .notice = toplevel.tab_notice };const selected = if (storage) |tabs| fillTabs(toplevel, tabs, &strip) else 0;@@ -16,8 +23,10 @@ pub fn tabStrip(toplevel: *Toplevel, storage: ?*[@import("../window_tabs.zig").mreturn strip;}-/// The group's tabs into `storage`; returns the index of `toplevel`'s own tab.+/// The strip's tabs into `storage`; returns the index of the selected tab: the+/// group member `toplevel` itself, or what the client published as selected.fn fillTabs(toplevel: *Toplevel, storage: *[@import("../window_tabs.zig").max_tabs]@import("../chrome_tabs.zig").Tab, strip: *@import("../chrome_tabs.zig").Strip) usize {+ if (toplevel.titlebar_tabs) |published| if (published.active()) return published.fill(storage, strip);var members_storage: [@import("../window_tabs.zig").max_tabs]*Toplevel = undefined;const members = @import("../window_tabs.zig").members(toplevel, &members_storage);var selected: usize = 0;@@ -30,7 +39,7 @@ fn fillTabs(toplevel: *Toplevel, storage: *[@import("../window_tabs.zig").max_ta}pub fn tabAt(toplevel: *Toplevel, x: f64, y: f64) @import("../chrome_tabs.zig").Hit {- if (!toplevel.hasServerDecorations() or toplevel.tab_group == 0) return .none;+ if (!toplevel.hasServerDecorations() or !toplevel.hasTabStrip()) return .none;var storage: [@import("../window_tabs.zig").max_tabs]@import("../chrome_tabs.zig").Tab = undefined;return @import("../chrome_tabs.zig").hit(toplevel.chrome_width - toplevel.controlInsets().right, toplevel.chromeDensity(), toplevel.tabStrip(&storage), x, y);}@@ -43,6 +52,10 @@ pub fn hoverTab(toplevel: *Toplevel, x: f64, y: f64) void {}pub fn stepTab(toplevel: *Toplevel, forward: bool) void {+ if (toplevel.titlebar_tabs) |published| if (published.active()) {+ published.step(forward);+ return;+ };var storage: [@import("../window_tabs.zig").max_tabs]*Toplevel = undefined;const members = @import("../window_tabs.zig").members(toplevel, &storage);if (members.len < 2) return;