RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
titlebar tabs: leading button, drag reorder, middle-click close
Claude775d3c5534bd
diff --git a/docs/plans/titlebar-tabs.md b/docs/plans/titlebar-tabs.mdindex f7cfeda..d324385 100644--- a/docs/plans/titlebar-tabs.md+++ b/docs/plans/titlebar-tabs.md@@ -80,7 +80,7 @@ decoration manager: the compositor resolves the toplevel from the surface andLanded 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`,+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 isunreleased, so these are added to version 1.@@ -229,3 +229,14 @@ test`, and the integration tests for what was touched (root `AGENTS.md`).* Open: keep the chip look or add a tab look; whether `modified` should also tintthe tab; whether double-click on empty strip space should still maximize (itdoes today, since only tabs and buttons count as controls).++## Phase 2c notes++* Drag state lives on `Toplevel.tab_drag`; `Input.tab_drag` only records which+ window is pressed. A press decides nothing: release selects (no travel) or+ sends `move` (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.diff --git a/protocol/rediwm-titlebar-tabs-v1.xml b/protocol/rediwm-titlebar-tabs-v1.xmlindex 5a0ad4f..cd3d808 100644--- a/protocol/rediwm-titlebar-tabs-v1.xml+++ b/protocol/rediwm-titlebar-tabs-v1.xml@@ -86,6 +86,16 @@<arg name="id" type="uint"/></request>+ <request name="set_leading_button">+ <description summary="show the application's icon as a button before the tabs">+ The button shows the application's own icon. Pressing it sends+ leading_activated, typically to open the application's menu. Part of+ the pending state like the tabs, so it takes effect on commit; it+ stays off until set.+ </description>+ <arg name="enabled" type="uint" summary="0 hides the button, anything else shows it"/>+ </request>+<request name="commit"><description summary="show the pending strip">Replaces the shown strip. A commit with no tabs removes the strip and@@ -109,5 +119,29 @@<event name="new_tab"><description summary="the user pressed the new tab button"/></event>++ <event name="move">+ <description summary="the user dragged a tab to a new place">+ Sent once, when the button is released. The index is the position the+ tab takes among all the tabs once it is removed from its old place+ and inserted at the new one (0 is the first). Like select, it only+ asks: the strip changes when the application commits the new order.+ While the drag lasts the compositor previews the move on its own.+ </description>+ <arg name="id" type="uint"/>+ <arg name="index" type="uint"/>+ </event>++ <event name="leading_activated">+ <description summary="the user pressed the leading button">+ The button's rectangle is in the surface's coordinates. The titlebar+ sits above the surface, so y is negative. The application can anchor+ a popup menu to it.+ </description>+ <arg name="x" type="int"/>+ <arg name="y" type="int"/>+ <arg name="width" type="int"/>+ <arg name="height" type="int"/>+ </event></interface></protocol>diff --git a/src/Input.zig b/src/Input.zigindex 50df206..a8abac0 100644--- a/src/Input.zig+++ b/src/Input.zig@@ -215,6 +215,8 @@ hovered_toplevel: ?*Toplevel = null,glow_toplevel: ?*Toplevel = null,hovered_taskbar: ?*Taskbar = null,taskbar_drag: ?TaskbarDragSession = null,+/// The window whose published tab is pressed (a click, or a reorder once the pointer travels).+tab_drag: ?*Toplevel = null,tray_buttons: u32 = 0,taskbar_close_buttons: u32 = 0,hovered_toast: ?*@import("notifications/toast.zig").Toast = null,@@ -527,6 +529,7 @@ pub fn detachOutput(input: *Input, output: *Output) void {pub fn detachToplevel(input: *Input, toplevel: *Toplevel) void {if (input.window_menu.references(toplevel)) input.window_menu.close();+ if (input.tab_drag == toplevel) input.tab_drag = null;if (input.taskbar_drag) |session| {if (session.window_id == toplevel.id) {input.taskbar_drag = null;diff --git a/src/TitlebarTabs.zig b/src/TitlebarTabs.zigindex 3d213bc..8d789d4 100644--- a/src/TitlebarTabs.zig+++ b/src/TitlebarTabs.zig@@ -39,8 +39,10 @@ link: wl.list.Link = undefined,surface_destroy: wl.Listener(*wlr.Surface) = .init(handleSurfaceDestroy),pending: std.ArrayList(Item) = .empty,pending_selected: ?u32 = null,+pending_leading: bool = false,items: std.ArrayList(Item) = .empty,selected: u32 = 0,+leading: bool = false,pub const Manager = struct {global: *wl.Global,@@ -123,6 +125,14 @@ pub fn active(self: *const TitlebarTabs) bool {return self.items.items.len > 0;}+/// Whether the committed strip has a tab with this id.+pub fn has(self: *const TitlebarTabs, id: u64) bool {+ for (self.items.items) |item| {+ if (item.id == id) return true;+ }+ return false;+}+/// 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 {@@ -133,6 +143,7 @@ pub fn fill(self: *const TitlebarTabs, storage: *[window_tabs.max_tabs]chrome_taif (is_selected) current = i;}strip.tabs = storage[0..self.items.items.len];+ strip.leading = self.leading;return current;}@@ -148,6 +159,21 @@ pub fn sendNewTab(self: *TitlebarTabs) void {self.resource.sendNewTab();}+pub fn sendMove(self: *TitlebarTabs, id: u64, index: usize) void {+ self.resource.sendMove(@intCast(id), @intCast(index));+}++/// `rect` is in the frame's coordinates (the titlebar's top left corner is+/// the origin); the client wants them relative to its surface.+pub fn sendLeadingActivated(self: *TitlebarTabs, x: f32, y: f32, width: f32, height: f32, surface_x: i32, surface_y: i32) void {+ self.resource.sendLeadingActivated(+ @as(i32, @intFromFloat(@round(x))) - surface_x,+ @as(i32, @intFromFloat(@round(y))) - surface_y,+ @intFromFloat(@round(width)),+ @intFromFloat(@round(height)),+ );+}+/// Asks the application to select the neighbouring tab, wrapping around.pub fn step(self: *TitlebarTabs, forward: bool) void {const n = self.items.items.len;@@ -165,6 +191,7 @@ fn handleStripRequest(resource: *Resource, request: Resource.Request, self: *Tit.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,+ .set_leading_button => |args| self.pending_leading = args.enabled != 0,.commit => self.commit(),}}@@ -226,6 +253,8 @@ fn commit(self: *TitlebarTabs) void {self.items = self.pending;self.pending = .empty;self.pending_selected = null;+ self.leading = self.pending_leading;+ self.pending_leading = false;if (self.toplevel) |toplevel| toplevel.syncChrome(false, Toplevel.nowMs()) catch {};}diff --git a/src/Toplevel.zig b/src/Toplevel.zigindex 5f885e0..e998d16 100644--- a/src/Toplevel.zig+++ b/src/Toplevel.zig@@ -180,6 +180,8 @@ tab_restore: ?RestoreGeometry = null,tab_notice: @import("window_tabs.zig").Notice = .none,tab_first: usize = 0,tab_hover: u64 = 0,+/// A press on a published tab: a click until the pointer travels, then a reorder.+tab_drag: @import("ui").widgets.title_tabs.Drag = .{},/// Digest of the last window record sent to IPC subscribers; most commits/// only change pixels, and `events.onWindowChanged` skips those.@@ -604,3 +606,7 @@ pub const hasTabStrip = toplevel_tabs.hasTabStrip;pub const tabAt = toplevel_tabs.tabAt;pub const hoverTab = toplevel_tabs.hoverTab;pub const stepTab = toplevel_tabs.stepTab;+pub const tabPress = toplevel_tabs.tabPress;+pub const tabMotion = toplevel_tabs.tabMotion;+pub const tabRelease = toplevel_tabs.tabRelease;+pub const activateLeading = toplevel_tabs.activateLeading;diff --git a/src/chrome_tabs.zig b/src/chrome_tabs.zigindex 55629f3..76c49b9 100644--- a/src/chrome_tabs.zig+++ b/src/chrome_tabs.zig@@ -30,8 +30,10 @@ pub fn paint(comptime C: type, pixels: []u32, width: i32, height: i32, logical_wif (clip) |c| renderer.damage_clip = .{ .x = @floatFromInt(c.x), .y = @floatFromInt(c.y), .w = @floatFromInt(c.w), .h = @floatFromInt(c.h) };const clip_left: usize = if (clip) |c| @intFromFloat(@max(0, @round(@as(f32, @floatFromInt(c.x)) * scale))) else 0;const clip_right: usize = if (clip) |c| @intFromFloat(@max(0, @round(@as(f32, @floatFromInt(c.x + c.w)) * scale))) else @intCast(width);- for (strip.tabs[g.first..][0..g.count], 0..) |t, i| {- const rect = g.tab(i);+ // The tab being dragged is painted last, over its neighbours.+ for ([_]bool{ false, true }) |dragged_pass| for (strip.tabs[g.first..][0..g.count], 0..) |t, i| {+ if ((strip.drag.dragging() and t.id == strip.drag.id) != dragged_pass) continue;+ const rect = strip.drag.rect(g, i);const radius = window_chrome.cornerRadius(theme.global.chrome_round_buttons, rect.w, rect.h, theme.global.radius * density * 0.8);const look = style.look(C, t.active, t.attention, if (strip.hover == key(.{ .tab = t.id })) 1 else 0, 0);const x0: usize = @max(clip_left, @as(usize, @intFromFloat(@max(0, @floor(rect.x * scale)))));@@ -49,13 +51,21 @@ pub fn paint(comptime C: type, pixels: []u32, width: i32, height: i32, logical_wrenderer.drawImageCover(left, rect.y + (rect.h - size) / 2, size, size, 0, .{ .pixels = image.pixels, .width = image.size, .height = image.size });} else renderer.drawIcon(left, rect.y + (rect.h - size) / 2, size, size, .{ .id = .generic, .color = theme.global.window_fg });left += size + 6 * density;- const close = g.close(i);+ var close = g.close(i);+ close.x += rect.x - g.tab(i).x;renderer.drawText(left, rect.y, @max(0, close.x - left - 3), rect.h, .{.content = if (t.active and strip.notice != .none) (if (strip.notice == .opening) "Opening…" else "No new window; retry +") else t.title,.font_size = theme.global.taskbar_title_size * density,.color = theme.global.window_fg,});button.paint(&renderer, close, .{ .variant = .chrome, .size = .sm, .icon = .close, .icon_scale = 0.39, .label = i18n.tr("Close tab") }, .{ .pointer = if (strip.hover == key(.{ .close = t.id })) .hover else .idle });+ };+ if (g.leading) |r| {+ button.paint(&renderer, r, .{ .variant = .ghost, .size = .sm, .radius = navigationRadius(r) }, .{ .pointer = if (strip.hover == key(.leading)) .hover else .idle });+ const side = @min(20 * density, r.h - 6);+ if (icon) |image| {+ renderer.drawImageCover(r.x + (r.w - side) / 2, r.y + (r.h - side) / 2, side, side, 0, .{ .pixels = image.pixels, .width = image.size, .height = image.size });+ } else renderer.drawIcon(r.x + (r.w - side) / 2, r.y + (r.h - side) / 2, side, side, .{ .id = .generic, .color = theme.global.window_fg });}button.paint(&renderer, g.plus, .{ .variant = .ghost, .size = .sm, .icon = .plus, .label = i18n.tr("New tab"), .radius = navigationRadius(g.plus) }, .{ .pointer = if (strip.notice == .opening) .disabled else if (strip.hover == key(.plus)) .hover else .idle });if (g.previous) |r| button.paint(&renderer, r, .{ .variant = .ghost, .size = .sm, .icon = .chevron_left, .radius = navigationRadius(r) }, .{ .pointer = if (strip.hover == key(.previous)) .hover else .idle });diff --git a/src/input/buttons.zig b/src/input/buttons.zigindex 240f0a2..e2bbd5a 100644--- a/src/input/buttons.zig+++ b/src/input/buttons.zig@@ -209,6 +209,16 @@ pub fn processButton(}}+ // A published tab is selected on release, unless the press became a reorder.+ if (state == .released and button == btn_left) {+ if (input.tab_drag) |toplevel| {+ input.tab_drag = null;+ toplevel.tabRelease();+ input.processCursorMotion(time_msec);+ return;+ }+ }+if (input.tiling_grab) |session| {if (state == .released and button == session.button) {input.finishTilingGrab(true);@@ -452,6 +462,10 @@ pub fn processClientButton(res.toplevel.toggleMaximize();return;}+ if (res.toplevel.tabPress(res.sx, res.sy, local.x)) {+ input.tab_drag = res.toplevel;+ return;+ }}res.toplevel.handleChromeClick(res.sx, res.sy, button);return;diff --git a/src/input/motion.zig b/src/input/motion.zigindex ee8de1b..b47d285 100644--- a/src/input/motion.zig+++ b/src/input/motion.zig@@ -274,6 +274,12 @@ pub fn processCursorMotion(input: *Input, time_msec: u32) void {}pub fn passthroughMotion(input: *Input, time_msec: u32) void {+ if (input.tab_drag) |toplevel| {+ const local = toplevel.frameLocal(input.cursor.x, input.cursor.y);+ if (toplevel.tabMotion(local.x)) input.setNamedCursor("grabbing");+ if (!toplevel.tab_drag.pressed()) input.tab_drag = null;+ return;+ }if (input.taskbar_drag) |*session| {if (!session.dragging and @import("../taskbar/pointer.zig").dragThresholdCrossed(session.press_x,diff --git a/src/toplevel/chrome_actions.zig b/src/toplevel/chrome_actions.zigindex 389c165..1df5b56 100644--- a/src/toplevel/chrome_actions.zig+++ b/src/toplevel/chrome_actions.zig@@ -22,19 +22,27 @@ 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.+ // (A left press on a tab itself is tracked from the button handler, so+ // it can become a reorder; this is the fallback and the other buttons.)if (toplevel.titlebar_tabs) |published| if (published.active()) {+ if (button == Input.btn_middle) {+ if (hit == .tab) published.sendClose(hit.tab);+ return;+ }+ if (button != Input.btn_left) return;switch (hit) {.tab => |id| published.sendSelect(id),.close => |id| published.sendClose(id),.plus => published.sendNewTab(),.previous => published.step(false),.next => published.step(true),+ .leading => toplevel.activateLeading(),.none => {},}return;};+ if (button != Input.btn_left) return;switch (hit) {.tab => |id| if (toplevel.server.findToplevelById(id)) |target| toplevel.server.world.focus(target),.close => |id| if (toplevel.server.findToplevelById(id)) |target| {@@ -44,7 +52,7 @@ pub fn handleChromeClick(toplevel: *Toplevel, sx: f64, sy: f64, button: u32) voi.plus => toplevel.server.window_tabs.launch(toplevel),.previous => toplevel.stepTab(false),.next => toplevel.stepTab(true),- .none => {},+ .leading, .none => {},}return;}diff --git a/src/toplevel/tabs.zig b/src/toplevel/tabs.zigindex 0bb7f02..7dc6976 100644--- a/src/toplevel/tabs.zig+++ b/src/toplevel/tabs.zig@@ -14,7 +14,7 @@ pub fn hasTabStrip(toplevel: *const Toplevel) bool {/// `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 };+ var strip: @import("../chrome_tabs.zig").Strip = .{ .first = toplevel.tab_first, .hover = toplevel.tab_hover, .notice = toplevel.tab_notice, .drag = toplevel.tab_drag };const selected = if (storage) |tabs| fillTabs(toplevel, tabs, &strip) else 0;const geom = @import("../chrome_tabs.zig").geometry(toplevel.chrome_width, toplevel.chromeDensity(), strip);if (selected < strip.first) strip.first = selected;@@ -66,3 +66,68 @@ pub fn stepTab(toplevel: *Toplevel, forward: bool) void {return;}}++/// A left press on a tab of a published strip. Whether it is a click or a+/// reorder depends on where the pointer goes, so nothing is sent yet:+/// `tabRelease` does. `lx` is the pointer's x in the frame's coordinates.+/// False when the press is not on such a tab, and nothing is tracked.+pub fn tabPress(toplevel: *Toplevel, sx: f64, sy: f64, lx: f64) bool {+ const chrome_tabs = @import("../chrome_tabs.zig");+ const published = toplevel.titlebar_tabs orelse return false;+ if (!published.active()) return false;+ const id = switch (toplevel.tabAt(sx, sy)) {+ .tab => |id| id,+ else => return false,+ };+ var storage: [@import("../window_tabs.zig").max_tabs]chrome_tabs.Tab = undefined;+ const strip = toplevel.tabStrip(&storage);+ const g = chrome_tabs.geometry(toplevel.chrome_width, toplevel.chromeDensity(), strip);+ return toplevel.tab_drag.press(strip, g, id, @floatCast(lx));+}++/// The pointer moved while a tab is pressed; true once that is a reorder. A+/// strip that changed under the press (the tab is gone, or the strip) ends it.+pub fn tabMotion(toplevel: *Toplevel, lx: f64) bool {+ if (!toplevel.tab_drag.pressed()) return false;+ const alive = if (toplevel.titlebar_tabs) |published| published.active() and published.has(toplevel.tab_drag.id) else false;+ if (!alive) {+ const was_dragging = toplevel.tab_drag.dragging();+ toplevel.tab_drag.cancel();+ if (was_dragging) toplevel.syncChrome(false, nowMs()) catch {};+ return false;+ }+ if (toplevel.tab_drag.motion(@floatCast(lx), toplevel.chromeDensity())) toplevel.syncChrome(false, nowMs()) catch {};+ return toplevel.tab_drag.dragging();+}++/// The button came up: a press that never travelled selects the tab, a+/// reorder that ended elsewhere asks the client to move it. The client+/// commits the result; until then the strip shows the old order.+pub fn tabRelease(toplevel: *Toplevel) void {+ if (!toplevel.tab_drag.pressed()) return;+ const chrome_tabs = @import("../chrome_tabs.zig");+ const id = toplevel.tab_drag.id;+ const dragged = toplevel.tab_drag.dragging();+ if (toplevel.titlebar_tabs) |published| if (published.active() and published.has(id)) {+ var storage: [@import("../window_tabs.zig").max_tabs]chrome_tabs.Tab = undefined;+ const strip = toplevel.tabStrip(&storage);+ const g = chrome_tabs.geometry(toplevel.chrome_width, toplevel.chromeDensity(), strip);+ if (toplevel.tab_drag.release(g)) |move| {+ published.sendMove(move.id, move.index);+ } else if (!dragged) published.sendSelect(id);+ };+ toplevel.tab_drag.cancel();+ if (dragged) toplevel.syncChrome(false, nowMs()) catch {};+}++/// The leading button was pressed: tell the client where it is, in its+/// surface's coordinates, so a menu can open under it.+pub fn activateLeading(toplevel: *Toplevel) void {+ const chrome_tabs = @import("../chrome_tabs.zig");+ const published = toplevel.titlebar_tabs orelse return;+ var storage: [@import("../window_tabs.zig").max_tabs]chrome_tabs.Tab = undefined;+ const strip = toplevel.tabStrip(&storage);+ const g = chrome_tabs.geometry(toplevel.chrome_width, toplevel.chromeDensity(), strip);+ const r = g.leading orelse return;+ published.sendLeadingActivated(r.x, r.y, r.w, r.h, toplevel.borderWidth(), toplevel.titlebarHeight());+}diff --git a/src/ui/widgets/title_tabs.zig b/src/ui/widgets/title_tabs.zigindex e8e254c..29011c0 100644--- a/src/ui/widgets/title_tabs.zig+++ b/src/ui/widgets/title_tabs.zig@@ -18,8 +18,12 @@ pub const Strip = struct {first: usize = 0,hover: u64 = 0,notice: Notice = .none,+ /// A button before the first tab: the application's icon, opening its menu.+ leading: bool = false,+ /// A reorder in progress; the painter follows it (`Drag.rect`).+ drag: Drag = .{},};-pub const Hit = union(enum) { none, tab: u64, close: u64, plus, previous, next };+pub const Hit = union(enum) { none, tab: u64, close: u64, plus, previous, next, leading };pub fn key(target: Hit) u64 {return switch (target) {.none => 0,@@ -28,6 +32,8 @@ pub fn key(target: Hit) u64 {.plus => 1,.previous => 2,.next => 3,+ // Tabs are id * 4 and their close buttons id * 4 + 1.+ .leading => 6,};}pub const Geometry = struct {@@ -40,6 +46,7 @@ pub const Geometry = struct {plus: Rect,previous: ?Rect,next: ?Rect,+ leading: ?Rect = null,pub fn tab(g: Geometry, i: usize) Rect {return .{ .x = g.x + @as(f32, @floatFromInt(i)) * (g.width + 4), .y = g.y, .w = g.width, .h = g.height };}@@ -55,9 +62,11 @@ pub fn geometry(width: i32, density: f32, strip: Strip) Geometry {const h = @max(18, height - 12 * density);const right = @as(f32, @floatFromInt(window_chrome.controlRectScaled(width, .minimize, density).x)) - 10 * density;var left: f32 = 8 * density;+ const leading: ?Rect = if (strip.leading) .{ .x = left, .y = (height - h) / 2, .w = h, .h = h } else null;+ if (leading != null) left += h + 4 * density;const plus_size = @min(26 * density, h);const available = @max(0, right - left - plus_size - 8);- if (available < 50 * density) return .{ .x = left, .y = (height - h) / 2, .height = h, .width = 0, .first = 0, .count = 0, .plus = .{ .x = left, .y = (height - plus_size) / 2, .w = @max(0, @min(plus_size, right - left)), .h = plus_size }, .previous = null, .next = null };+ if (available < 50 * density) return .{ .x = left, .y = (height - h) / 2, .height = h, .width = 0, .first = 0, .count = 0, .plus = .{ .x = left, .y = (height - plus_size) / 2, .w = @max(0, @min(plus_size, right - left)), .h = plus_size }, .previous = null, .next = null, .leading = leading };const overflow = @as(f32, @floatFromInt(strip.tabs.len)) * (85 * density + 4) > available;const arrow_size = if (overflow) @min(22 * density, h) else 0;const space = @max(1, available - 2 * arrow_size);@@ -68,7 +77,7 @@ pub fn geometry(width: i32, density: f32, strip: Strip) Geometry {const previous: ?Rect = if (overflow) .{ .x = left, .y = y, .w = arrow_size, .h = h } else null;left += arrow_size;const end = left + @as(f32, @floatFromInt(count)) * (tab_width + 4);- return .{ .x = left, .y = y, .height = h, .width = tab_width, .first = first, .count = count, .previous = previous, .next = if (overflow) .{ .x = end, .y = y, .w = arrow_size, .h = h } else null, .plus = .{ .x = end + arrow_size, .y = (height - plus_size) / 2, .w = plus_size, .h = plus_size } };+ return .{ .x = left, .y = y, .height = h, .width = tab_width, .first = first, .count = count, .previous = previous, .next = if (overflow) .{ .x = end, .y = y, .w = arrow_size, .h = h } else null, .plus = .{ .x = end + arrow_size, .y = (height - plus_size) / 2, .w = plus_size, .h = plus_size }, .leading = leading };}fn contains(r: Rect, x: f64, y: f64) bool {return x >= r.x and x < r.x + r.w and y >= r.y and y < r.y + r.h;@@ -76,6 +85,7 @@ fn contains(r: Rect, x: f64, y: f64) bool {pub fn hit(width: i32, density: f32, strip: Strip, x: f64, y: f64) Hit {if (strip.tabs.len == 0) return .none;const g = geometry(width, density, strip);+ if (g.leading) |r| if (contains(r, x, y)) return .leading;if (contains(g.plus, x, y)) return .plus;if (g.previous) |r| if (contains(r, x, y)) return .previous;if (g.next) |r| if (contains(r, x, y)) return .next;@@ -98,6 +108,14 @@ fn hashImpl(strip: Strip, include_titles: bool) u64 {h.update(std.mem.asBytes(&strip.first));h.update(std.mem.asBytes(&strip.hover));h.update(std.mem.asBytes(&strip.notice));+ h.update(std.mem.asBytes(&strip.leading));+ // Only a drag that has begun changes what is painted.+ const dragging = strip.drag.dragging();+ h.update(std.mem.asBytes(&dragging));+ if (dragging) {+ h.update(std.mem.asBytes(&strip.drag.id));+ h.update(std.mem.asBytes(&strip.drag.x));+ }for (strip.tabs) |t| {h.update(std.mem.asBytes(&t.id));if (include_titles) h.update(t.title);diff --git a/src/ui/widgets/title_tabs_tests.zig b/src/ui/widgets/title_tabs_tests.zigindex e86481c..343f646 100644--- a/src/ui/widgets/title_tabs_tests.zig+++ b/src/ui/widgets/title_tabs_tests.zig@@ -153,3 +153,48 @@ test "the dragged tab never leaves the strip" {try std.testing.expect(d.motion(5000, 1));try std.testing.expectApproxEqAbs(g.tab(2).x, d.rect(g, 0).x, 0.01);}++test "a leading button takes the first slot and the tabs start after it" {+ const plain = tt.geometry(width, 1, strip());+ var s = strip();+ s.leading = true;+ const g = tt.geometry(width, 1, s);+ const lead = g.leading orelse return error.TestExpectedLeading;+ try std.testing.expect(plain.leading == null);+ try std.testing.expect(g.tab(0).x >= lead.x + lead.w);+ try std.testing.expectEqual(tt.Hit.leading, tt.hit(width, 1, s, lead.x + lead.w / 2, lead.y + lead.h / 2));+ // Without the button the same point is not a hit.+ try std.testing.expect(tt.hit(width, 1, strip(), lead.x + lead.w / 2, lead.y + lead.h / 2) != .leading);+ try std.testing.expect(tt.hash(s) != tt.hash(strip()));+}++test "keys stay distinct with the leading button" {+ try std.testing.expect(tt.key(.leading) != 0);+ for ([_]u64{ 1, 2, 3, 4, 5, 6 }) |id| {+ try std.testing.expect(tt.key(.leading) != tt.key(.{ .tab = id }));+ try std.testing.expect(tt.key(.leading) != tt.key(.{ .close = id }));+ }+ try std.testing.expect(tt.key(.leading) != tt.key(.plus));+ try std.testing.expect(tt.key(.leading) != tt.key(.previous));+ try std.testing.expect(tt.key(.leading) != tt.key(.next));+}++test "a drag in progress changes the hash and a bare press does not" {+ const s = strip();+ const g = tt.geometry(width, 1, s);+ const x = g.tab(0).x + g.width / 2;+ var d: tt.Drag = .{};+ try std.testing.expect(d.press(s, g, 1, x));+ var pressed = s;+ pressed.drag = d;+ try std.testing.expectEqual(tt.hash(s), tt.hash(pressed));+ try std.testing.expect(d.motion(x + 20, 1));+ var moving = s;+ moving.drag = d;+ try std.testing.expect(tt.hash(s) != tt.hash(moving));+ try std.testing.expect(tt.layoutHash(s) != tt.layoutHash(moving));+ try std.testing.expect(d.motion(x + 30, 1));+ var later = s;+ later.drag = d;+ try std.testing.expect(tt.hash(moving) != tt.hash(later));+}