Skip to content

RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process

ui: hoist the titlebar tab strip into the toolkit

Clauded57a2e3c2c86
diff --git a/src/chrome_tabs.zig b/src/chrome_tabs.zig
index 543b86d..55629f3 100644
--- a/src/chrome_tabs.zig
+++ b/src/chrome_tabs.zig
@@ -10,102 +10,18 @@ const chrome = @import("chrome.zig");
const window_chrome = @import("ui").window_chrome;
const Rect = button.Rect;
-pub const Tab = struct { id: u64, title: []const u8, active: bool, attention: bool };
-pub const Strip = struct {
- tabs: []const Tab = &.{},
- first: usize = 0,
- hover: u64 = 0,
- notice: @import("window_tabs.zig").Notice = .none,
-};
-pub const Hit = union(enum) { none, tab: u64, close: u64, plus, previous, next };
-pub fn key(target: Hit) u64 {
- return switch (target) {
- .none => 0,
- .tab => |id| id * 4,
- .close => |id| id * 4 + 1,
- .plus => 1,
- .previous => 2,
- .next => 3,
- };
-}
-pub const Geometry = struct {
- x: f32,
- y: f32,
- height: f32,
- width: f32,
- first: usize,
- count: usize,
- plus: Rect,
- previous: ?Rect,
- next: ?Rect,
- 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 };
- }
- pub fn close(g: Geometry, i: usize) Rect {
- const r = g.tab(i);
- const size = @min(22, g.height - 4);
- return .{ .x = r.x + r.w - size - 3, .y = r.y + (r.h - size) / 2, .w = size, .h = size };
- }
-};
-
-pub fn geometry(width: i32, density: f32, strip: Strip) Geometry {
- const height: f32 = @floatFromInt((chrome.Metrics{ .density = density }).titlebarHeight());
- const h = @max(18, height - 12 * density);
- const right = @as(f32, @floatFromInt(chrome.controlRectScaled(width, .minimize, density).x)) - 10 * density;
- var left: f32 = 8 * 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 };
- 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);
- const count = @min(strip.tabs.len, @max(1, @as(usize, @intFromFloat(@floor(space / @max(1, 85 * density + 4))))));
- const first = @min(strip.first, strip.tabs.len -| count);
- const tab_width = @max(1, @min(170 * density, space / @as(f32, @floatFromInt(@max(1, count))) - 4));
- const y = (height - h) / 2;
- 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 } };
-}
-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;
-}
-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 (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;
- for (strip.tabs[g.first..][0..g.count], 0..) |t, i| {
- if (contains(g.close(i), x, y)) return .{ .close = t.id };
- if (contains(g.tab(i), x, y)) return .{ .tab = t.id };
- }
- return .none;
-}
-
-pub fn hash(strip: Strip) u64 {
- return hashImpl(strip, true);
-}
-pub fn layoutHash(strip: Strip) u64 {
- return hashImpl(strip, false);
-}
-fn hashImpl(strip: Strip, include_titles: bool) u64 {
- if (strip.tabs.len == 0) return 0;
- var h = std.hash.Wyhash.init(0);
- h.update(std.mem.asBytes(&strip.first));
- h.update(std.mem.asBytes(&strip.hover));
- h.update(std.mem.asBytes(&strip.notice));
- for (strip.tabs) |t| {
- h.update(std.mem.asBytes(&t.id));
- if (include_titles) h.update(t.title);
- h.update(std.mem.asBytes(&t.active));
- h.update(std.mem.asBytes(&t.attention));
- }
- // The shared painter's palette is independent of the chrome palette.
- inline for (.{ "taskbar_surface", "taskbar_hover", "taskbar_border", "surface_hover", "danger", "window_fg", "radius", "taskbar_title_size", "chrome_round_buttons" }) |field| h.update(std.mem.asBytes(&@field(theme.global, field)));
- return h.final();
-}
+const title_tabs = @import("ui").widgets.title_tabs;
+// The model, geometry, hit testing and hashing live in the shared toolkit
+// (`ui/widgets/title_tabs.zig`); this file keeps the compositor's painter.
+pub const Tab = title_tabs.Tab;
+pub const Strip = title_tabs.Strip;
+pub const Hit = title_tabs.Hit;
+pub const key = title_tabs.key;
+pub const Geometry = title_tabs.Geometry;
+pub const geometry = title_tabs.geometry;
+pub const hit = title_tabs.hit;
+pub const hash = title_tabs.hash;
+pub const layoutHash = title_tabs.layoutHash;
pub fn paint(comptime C: type, pixels: []u32, width: i32, height: i32, logical_width: i32, density: f32, scale: f32, strip: Strip, icon: ?icon_service.Entry, clip: ?chrome.Rect) void {
if (strip.tabs.len == 0) return;
diff --git a/src/ui/AGENTS.md b/src/ui/AGENTS.md
index dbaffc4..9d5a13f 100644
--- a/src/ui/AGENTS.md
+++ b/src/ui/AGENTS.md
@@ -102,3 +102,9 @@ text and colours, secrets) are in the root `AGENTS.md` ("Shared UI").
`stale` region catching up what it missed; never answer a glow change with
`dirty` (a full, unpaced repaint at pointer rate). Hand-drawn content must
stay inside the rects a damage helper adds for it.
+* **The titlebar tab strip** (`widgets/title_tabs.zig`): model (`Tab`, `Strip`),
+ `geometry`, `hit`, the damage `hash`/`layoutHash` and `Drag` (press, motion,
+ release and the preview rectangle for a reorder). No painting: the compositor
+ paints it in `chrome_tabs.zig`. Tab ids are non-zero (0 means none in
+ `Strip.hover` and `Drag.id`). `Drag` reorders nothing itself; `release` returns
+ the final index for the owner to apply. Plan: `docs/plans/titlebar-tabs.md`.
diff --git a/src/ui/mod.zig b/src/ui/mod.zig
index c00a038..55d557c 100644
--- a/src/ui/mod.zig
+++ b/src/ui/mod.zig
@@ -31,6 +31,7 @@ pub const widgets = struct {
pub const swatch = @import("widgets/swatch.zig");
pub const stepper = @import("widgets/stepper.zig");
pub const arrangement = @import("widgets/arrangement.zig");
+ pub const title_tabs = @import("widgets/title_tabs.zig");
};
pub const anim = @import("anim.zig");
pub const cairo = @import("cairo.zig");
diff --git a/src/ui/widgets/title_tabs.zig b/src/ui/widgets/title_tabs.zig
new file mode 100644
index 0000000..e8e254c
--- /dev/null
+++ b/src/ui/widgets/title_tabs.zig
@@ -0,0 +1,209 @@
+//! The titlebar tab strip: model, geometry, hit testing, the damage hash and
+//! the drag-reorder arithmetic. No painting and no compositor imports: the
+//! compositor paints the strip into its retained chrome (`chrome_tabs.zig`),
+//! and a self-decorated app can paint the same geometry through Cairo.
+//! Tab ids are non-zero: `Strip.hover` and `Drag.id` use 0 for "none".
+const std = @import("std");
+const theme = @import("../theme.zig");
+const window_chrome = @import("../window_chrome.zig");
+const button = @import("button.zig");
+const Rect = button.Rect;
+
+/// What the strip says about a "+" that is still being served.
+pub const Notice = enum { none, opening, failed };
+
+pub const Tab = struct { id: u64, title: []const u8, active: bool, attention: bool };
+pub const Strip = struct {
+ tabs: []const Tab = &.{},
+ first: usize = 0,
+ hover: u64 = 0,
+ notice: Notice = .none,
+};
+pub const Hit = union(enum) { none, tab: u64, close: u64, plus, previous, next };
+pub fn key(target: Hit) u64 {
+ return switch (target) {
+ .none => 0,
+ .tab => |id| id * 4,
+ .close => |id| id * 4 + 1,
+ .plus => 1,
+ .previous => 2,
+ .next => 3,
+ };
+}
+pub const Geometry = struct {
+ x: f32,
+ y: f32,
+ height: f32,
+ width: f32,
+ first: usize,
+ count: usize,
+ plus: Rect,
+ previous: ?Rect,
+ next: ?Rect,
+ 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 };
+ }
+ pub fn close(g: Geometry, i: usize) Rect {
+ const r = g.tab(i);
+ const size = @min(22, g.height - 4);
+ return .{ .x = r.x + r.w - size - 3, .y = r.y + (r.h - size) / 2, .w = size, .h = size };
+ }
+};
+
+pub fn geometry(width: i32, density: f32, strip: Strip) Geometry {
+ const height: f32 = @floatFromInt((window_chrome.Metrics{ .density = density }).titlebarHeight());
+ 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 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 };
+ 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);
+ const count = @min(strip.tabs.len, @max(1, @as(usize, @intFromFloat(@floor(space / @max(1, 85 * density + 4))))));
+ const first = @min(strip.first, strip.tabs.len -| count);
+ const tab_width = @max(1, @min(170 * density, space / @as(f32, @floatFromInt(@max(1, count))) - 4));
+ const y = (height - h) / 2;
+ 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 } };
+}
+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;
+}
+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 (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;
+ for (strip.tabs[g.first..][0..g.count], 0..) |t, i| {
+ if (contains(g.close(i), x, y)) return .{ .close = t.id };
+ if (contains(g.tab(i), x, y)) return .{ .tab = t.id };
+ }
+ return .none;
+}
+
+pub fn hash(strip: Strip) u64 {
+ return hashImpl(strip, true);
+}
+pub fn layoutHash(strip: Strip) u64 {
+ return hashImpl(strip, false);
+}
+fn hashImpl(strip: Strip, include_titles: bool) u64 {
+ if (strip.tabs.len == 0) return 0;
+ var h = std.hash.Wyhash.init(0);
+ h.update(std.mem.asBytes(&strip.first));
+ h.update(std.mem.asBytes(&strip.hover));
+ h.update(std.mem.asBytes(&strip.notice));
+ for (strip.tabs) |t| {
+ h.update(std.mem.asBytes(&t.id));
+ if (include_titles) h.update(t.title);
+ h.update(std.mem.asBytes(&t.active));
+ h.update(std.mem.asBytes(&t.attention));
+ }
+ // The shared painter's palette is independent of the chrome palette.
+ inline for (.{ "taskbar_surface", "taskbar_hover", "taskbar_border", "surface_hover", "danger", "window_fg", "radius", "taskbar_title_size", "chrome_round_buttons" }) |field| h.update(std.mem.asBytes(&@field(theme.global, field)));
+ return h.final();
+}
+
+/// A press on a tab that may become a reorder. The owner feeds it the pointer
+/// (`press`, `motion`, `release`) and paints each visible tab at `rect`, so the
+/// dragged tab follows the pointer and its neighbours step aside. Nothing is
+/// reordered until `release` returns the final index; the owner then moves the
+/// tab (a window group, or an app told over the protocol).
+pub const Drag = struct {
+ /// Pointer travel, in logical pixels, before a press becomes a drag.
+ pub const threshold: f32 = 4;
+ pub const Move = struct { id: u64, index: usize };
+
+ /// The pressed tab; 0 while idle.
+ id: u64 = 0,
+ /// Its index among all tabs when pressed.
+ from: usize = 0,
+ press_x: f32 = 0,
+ /// Pointer x minus the tab's left edge at the press.
+ grab: f32 = 0,
+ x: f32 = 0,
+ moved: bool = false,
+
+ pub fn pressed(d: Drag) bool {
+ return d.id != 0;
+ }
+ /// True once the pointer has travelled past the threshold.
+ pub fn dragging(d: Drag) bool {
+ return d.id != 0 and d.moved;
+ }
+
+ /// Starts tracking a press on tab `id`, which must be one of the visible
+ /// tabs of `g`; returns false and tracks nothing otherwise.
+ pub fn press(d: *Drag, strip: Strip, g: Geometry, id: u64, x: f32) bool {
+ d.* = .{};
+ for (strip.tabs[g.first..][0..g.count], 0..) |t, i| {
+ if (t.id != id) continue;
+ d.* = .{ .id = id, .from = g.first + i, .press_x = x, .grab = x - g.tab(i).x, .x = x };
+ return true;
+ }
+ return false;
+ }
+
+ /// Follows the pointer; true when the preview changed and needs a repaint.
+ pub fn motion(d: *Drag, x: f32, density: f32) bool {
+ if (d.id == 0) return false;
+ d.x = x;
+ if (!d.moved) {
+ if (@abs(x - d.press_x) < threshold * density) return false;
+ d.moved = true;
+ }
+ return true;
+ }
+
+ /// The index, among all tabs, where the dragged tab would land now.
+ pub fn target(d: Drag, g: Geometry) usize {
+ if (g.count == 0) return d.from;
+ const pitch = g.width + 4;
+ const centre = d.x - d.grab + g.width / 2;
+ const slot = @floor((centre - g.x) / pitch);
+ const last: f32 = @floatFromInt(g.count - 1);
+ return g.first + @as(usize, @intFromFloat(std.math.clamp(slot, 0, last)));
+ }
+
+ /// Where to paint visible tab `i` (an index into the visible tabs): the
+ /// dragged tab under the pointer, the tabs it passes one step aside.
+ pub fn rect(d: Drag, g: Geometry, i: usize) Rect {
+ var r = g.tab(i);
+ if (!d.dragging() or g.count == 0) return r;
+ const pitch = g.width + 4;
+ const index = g.first + i;
+ const to = d.target(g);
+ if (index == d.from) {
+ const last: f32 = @floatFromInt(g.count - 1);
+ r.x = std.math.clamp(d.x - d.grab, g.x, g.x + last * pitch);
+ } else if (d.from < to and index > d.from and index <= to) {
+ r.x -= pitch;
+ } else if (to < d.from and index >= to and index < d.from) {
+ r.x += pitch;
+ }
+ return r;
+ }
+
+ /// Ends the press. The move to make, or null for a click, a drag that
+ /// ended where it began, or no press at all.
+ pub fn release(d: *Drag, g: Geometry) ?Move {
+ defer d.* = .{};
+ if (d.id == 0 or !d.moved) return null;
+ const to = d.target(g);
+ if (to == d.from) return null;
+ return .{ .id = d.id, .index = to };
+ }
+
+ pub fn cancel(d: *Drag) void {
+ d.* = .{};
+ }
+};
+
+test {
+ _ = @import("title_tabs_tests.zig");
+}
diff --git a/src/ui/widgets/title_tabs_tests.zig b/src/ui/widgets/title_tabs_tests.zig
new file mode 100644
index 0000000..e86481c
--- /dev/null
+++ b/src/ui/widgets/title_tabs_tests.zig
@@ -0,0 +1,155 @@
+const std = @import("std");
+const tt = @import("title_tabs.zig");
+
+const three = [_]tt.Tab{
+ .{ .id = 1, .title = "one", .active = true, .attention = false },
+ .{ .id = 2, .title = "two", .active = false, .attention = false },
+ .{ .id = 3, .title = "three", .active = false, .attention = true },
+};
+const retitled = [_]tt.Tab{
+ .{ .id = 1, .title = "uno", .active = true, .attention = false },
+ .{ .id = 2, .title = "two", .active = false, .attention = false },
+ .{ .id = 3, .title = "three", .active = false, .attention = true },
+};
+const width = 900;
+
+fn strip() tt.Strip {
+ return .{ .tabs = &three };
+}
+
+test "geometry lays three tabs side by side with the plus after them" {
+ const g = tt.geometry(width, 1, strip());
+ try std.testing.expectEqual(@as(usize, 3), g.count);
+ try std.testing.expectEqual(@as(usize, 0), g.first);
+ try std.testing.expect(g.previous == null and g.next == null);
+ try std.testing.expect(g.tab(1).x > g.tab(0).x + g.tab(0).w);
+ try std.testing.expect(g.plus.x >= g.tab(2).x + g.tab(2).w);
+}
+
+test "hit finds tabs, close buttons and the plus button" {
+ const s = strip();
+ const g = tt.geometry(width, 1, s);
+ for (three, 0..) |t, i| {
+ const r = g.tab(i);
+ try std.testing.expectEqual(tt.Hit{ .tab = t.id }, tt.hit(width, 1, s, r.x + 2, r.y + r.h / 2));
+ const c = g.close(i);
+ try std.testing.expectEqual(tt.Hit{ .close = t.id }, tt.hit(width, 1, s, c.x + c.w / 2, c.y + c.h / 2));
+ }
+ try std.testing.expectEqual(tt.Hit.plus, tt.hit(width, 1, s, g.plus.x + g.plus.w / 2, g.plus.y + g.plus.h / 2));
+ try std.testing.expectEqual(tt.Hit.none, tt.hit(width, 1, s, 0, 0));
+}
+
+test "an empty strip has no hits and no hash" {
+ const s: tt.Strip = .{};
+ try std.testing.expectEqual(tt.Hit.none, tt.hit(width, 1, s, 20, 20));
+ try std.testing.expectEqual(@as(u64, 0), tt.hash(s));
+}
+
+test "a retitled tab changes the hash but not the layout hash" {
+ const a = strip();
+ const b: tt.Strip = .{ .tabs = &retitled };
+ try std.testing.expect(tt.hash(a) != tt.hash(b));
+ try std.testing.expectEqual(tt.layoutHash(a), tt.layoutHash(b));
+}
+
+test "keys keep tabs, close buttons and controls apart" {
+ try std.testing.expect(tt.key(.{ .tab = 5 }) != tt.key(.{ .close = 5 }));
+ try std.testing.expectEqual(@as(u64, 0), tt.key(.none));
+ try std.testing.expect(tt.key(.plus) != tt.key(.previous));
+ try std.testing.expect(tt.key(.previous) != tt.key(.next));
+}
+
+test "a press stays a click until the pointer travels past the threshold" {
+ 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));
+ try std.testing.expect(!d.motion(x + 2, 1));
+ try std.testing.expect(!d.dragging());
+ try std.testing.expectEqual(@as(?tt.Drag.Move, null), d.release(g));
+ try std.testing.expect(!d.pressed());
+}
+
+test "press refuses a tab that is not visible" {
+ const s = strip();
+ const g = tt.geometry(width, 1, s);
+ var d: tt.Drag = .{};
+ try std.testing.expect(!d.press(s, g, 99, 10));
+ try std.testing.expect(!d.pressed());
+ try std.testing.expect(!d.motion(500, 1));
+}
+
+test "dragging one slot right moves the tab to the next index" {
+ const s = strip();
+ const g = tt.geometry(width, 1, s);
+ const pitch = g.width + 4;
+ const x = g.tab(0).x + g.width / 2;
+ var d: tt.Drag = .{};
+ try std.testing.expect(d.press(s, g, 1, x));
+ try std.testing.expect(d.motion(x + pitch, 1));
+ try std.testing.expect(d.dragging());
+ const move = d.release(g) orelse return error.TestExpectedMove;
+ try std.testing.expectEqual(@as(u64, 1), move.id);
+ try std.testing.expectEqual(@as(usize, 1), move.index);
+ try std.testing.expect(!d.pressed());
+}
+
+test "a drag past either end clamps to the first and last tab" {
+ const s = strip();
+ const g = tt.geometry(width, 1, s);
+ const pitch = g.width + 4;
+ const x = g.tab(1).x + g.width / 2;
+ var d: tt.Drag = .{};
+ try std.testing.expect(d.press(s, g, 2, x));
+ try std.testing.expect(d.motion(x + 10 * pitch, 1));
+ try std.testing.expectEqual(@as(usize, 2), (d.release(g) orelse return error.TestExpectedMove).index);
+ try std.testing.expect(d.press(s, g, 2, x));
+ try std.testing.expect(d.motion(x - 10 * pitch, 1));
+ try std.testing.expectEqual(@as(usize, 0), (d.release(g) orelse return error.TestExpectedMove).index);
+}
+
+test "a drag that ends where it began is not a move" {
+ const s = strip();
+ const g = tt.geometry(width, 1, s);
+ const x = g.tab(1).x + g.width / 2;
+ var d: tt.Drag = .{};
+ try std.testing.expect(d.press(s, g, 2, x));
+ try std.testing.expect(d.motion(x + 10, 1));
+ try std.testing.expect(d.dragging());
+ try std.testing.expectEqual(@as(?tt.Drag.Move, null), d.release(g));
+}
+
+test "the preview steps passed tabs aside and follows the pointer" {
+ const s = strip();
+ const g = tt.geometry(width, 1, s);
+ const pitch = g.width + 4;
+ const x = g.tab(0).x + g.width / 2;
+ var d: tt.Drag = .{};
+ try std.testing.expect(d.press(s, g, 1, x));
+ // Before the threshold nothing moves.
+ try std.testing.expectEqual(g.tab(1).x, d.rect(g, 1).x);
+ try std.testing.expect(d.motion(x + pitch, 1));
+ try std.testing.expectApproxEqAbs(g.tab(1).x, d.rect(g, 0).x, 0.01);
+ try std.testing.expectApproxEqAbs(g.tab(0).x, d.rect(g, 1).x, 0.01);
+ try std.testing.expectApproxEqAbs(g.tab(2).x, d.rect(g, 2).x, 0.01);
+ // Dragged the other way, the tabs before it step right.
+ var back: tt.Drag = .{};
+ const x2 = g.tab(2).x + g.width / 2;
+ try std.testing.expect(back.press(s, g, 3, x2));
+ try std.testing.expect(back.motion(x2 - pitch, 1));
+ try std.testing.expectApproxEqAbs(g.tab(2).x, back.rect(g, 1).x, 0.01);
+ try std.testing.expectApproxEqAbs(g.tab(0).x, back.rect(g, 0).x, 0.01);
+}
+
+test "the dragged tab never leaves the strip" {
+ const s = strip();
+ const g = tt.geometry(width, 1, s);
+ var d: tt.Drag = .{};
+ const x = g.tab(0).x + g.width / 2;
+ try std.testing.expect(d.press(s, g, 1, x));
+ try std.testing.expect(d.motion(-500, 1));
+ try std.testing.expectApproxEqAbs(g.x, d.rect(g, 0).x, 0.01);
+ try std.testing.expect(d.motion(5000, 1));
+ try std.testing.expectApproxEqAbs(g.tab(2).x, d.rect(g, 0).x, 0.01);
+}
diff --git a/src/window_tabs.zig b/src/window_tabs.zig
index 389bd2e..9b3e2df 100644
--- a/src/window_tabs.zig
+++ b/src/window_tabs.zig
@@ -13,7 +13,7 @@ loaded: bool = false,
pending: std.ArrayList(*Pending) = .empty,
pub const max_tabs = 128;
-pub const Notice = enum { none, opening, failed };
+pub const Notice = @import("ui").widgets.title_tabs.Notice;
const Pending = struct {
server: *Server,
group: u64,