Skip to content

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

file switcher update

oxydizer662d41de48fb
diff --git a/src/Input.zig b/src/Input.zig
index 9a1ee35..2870508 100644
--- a/src/Input.zig
+++ b/src/Input.zig
@@ -208,6 +208,9 @@ active_buttons: u32 = 0,
desktop_grab: bool = false,
/// Releases belong to the map even if a modal transition cancels its grab.
mini_map_buttons: u32 = 0,
+/// A click can accept/cancel the switcher mid-press; its matching release
+/// must still be swallowed rather than reaching whatever is now focused.
+switcher_buttons: u32 = 0,
/// Last known (surface-local, world) correspondence for whichever ordinary
/// client surface currently holds pointer focus, refreshed on every real
/// hit. Lets passthroughMotion's implicit grab (see below) keep reporting
diff --git a/src/Switcher.zig b/src/Switcher.zig
index 182f8e3..b6ecc6c 100644
--- a/src/Switcher.zig
+++ b/src/Switcher.zig
@@ -36,6 +36,10 @@ pub const Card = struct {
fill: ?*sn.Rect = null,
group: usize = 0,
member: usize = 0,
+ /// Circular style only: this card's animated distance from the front of
+ /// its group's stack, so bringing a different member forward (`Tab`)
+ /// slides the stack into place instead of snapping.
+ stack: Anim = .{},
};
pub const Trigger = enum { alt, ctrl };
@@ -51,6 +55,15 @@ width: i32 = 0,
scale: f32 = 1,
style: @import("config").types.SwitcherStyle = .linear,
circle: circular.State = .{},
+/// The card under the pointer, recomputed every tick from the last known
+/// cursor position so it tracks reflow (scroll offset, Tab) even when the
+/// mouse itself hasn't moved since.
+hovered: ?usize = null,
+last_cursor_x: f64 = 0,
+last_cursor_y: f64 = 0,
+/// Linear style only: a single reusable ring repositioned over whichever
+/// card is hovered, distinct from the fixed Tab-selection outline.
+hover_outline: ?*sn.Buffer = null,
pub fn active(self: *const Self) bool {
return self.tree != null;
@@ -105,6 +118,8 @@ fn open(self: *Self, server: *Server) !void {
const box = output.usableBox();
if (box.width < 260 or box.height < height) return;
self.output = output;
+ self.last_cursor_x = server.input.cursor.x;
+ self.last_cursor_y = server.input.cursor.y;
self.style = server.config.compositor.switcher_style;
self.circle.enabled = self.style == .circular and circular.layout.diameter(box.width, box.height) >= 360 and @import("chrome.zig").polygonsReady();
self.width = if (self.circle.enabled) circular.layout.diameter(box.width, box.height) else @min(1500, box.width - 32);
@@ -156,6 +171,14 @@ fn open(self: *Self, server: *Server) !void {
r.fillRect(1, 1, card_w + 6, 162, .{ .color = .{ 0, 0, 0, 0 }, .radius = theme.global.switcher_selection_radius, .border_width = 2, .border_color = theme.global.switcher_selected_border });
const node = try self.makeNode(&outline.base, card_w + 8, 164);
node.node.setPosition(@divTrunc(self.width - card_w, 2) - 4, 24);
+ // A second, subtler ring reused across frames and just repositioned over
+ // whichever card the pointer sits on; unlike `outline` it isn't fixed.
+ const hover = try PanelBuffer.create(card_w + 8, 164, self.scale);
+ defer hover.base.drop();
+ r = Renderer.init(hover.pixels, hover.width, hover.height, self.scale);
+ r.fillRect(1, 1, card_w + 6, 162, .{ .color = .{ 0, 0, 0, 0 }, .radius = theme.global.switcher_selection_radius, .border_width = 2, .border_color = theme.global.border_hover });
+ self.hover_outline = try self.makeNode(&hover.base, card_w + 8, 164);
+ self.hover_outline.?.node.setEnabled(false);
_ = self.tick(output, @import("Taskbar.zig").nowMs());
}
@@ -201,10 +224,14 @@ pub fn tick(self: *Self, output: *Output, now: i64) bool {
return false;
}
}
+ // Recomputed every frame (not just on pointer motion) so Tab reflowing
+ // the layout under a stationary mouse still tracks the right card.
+ self.hovered = self.hit(output, now, self.last_cursor_x, self.last_cursor_y);
if (self.circle.enabled) return circular.tick(self, output, now);
self.background.?.setOpacity(output.server.config.compositor.switcher_opacity);
self.tree.?.node.setPosition(box.x + @divTrunc(box.width - self.width, 2), box.y + @divTrunc(box.height - height, 2));
const offset: i32 = @intFromFloat(@round(self.scroll.value(now)));
+ var hover_shown = false;
for (self.cards.items, 0..) |*card, i| {
refreshIcon(self, card);
@@ -212,7 +239,14 @@ pub fn tick(self: *Self, output: *Output, now: i64) bool {
place(card.label.?, card.label_source, x, 28, card_w, card_h, self.width);
place(card.icon, card.icon_source, x + 92, 156, 40, 40, self.width);
if (card.pw > 0) if (card.preview) |preview| place(preview, card.source, x + @divTrunc(card_w - card.pw, 2), 36 + @divTrunc(140 - card.ph, 2), card.pw, card.ph, self.width);
+ // The fixed selection outline already marks this card; a second ring
+ // on top of it would just look like a doubled border.
+ if (self.hovered == i and i != self.selected) {
+ self.hover_outline.?.node.setPosition(x - 4, 24);
+ hover_shown = true;
+ }
}
+ self.hover_outline.?.node.setEnabled(hover_shown);
_ = self.scroll.sampleChanged(now, anim.quantum_px);
return !self.scroll.settled(now);
}
@@ -287,6 +321,56 @@ pub fn frameDone(self: *Self, output: *Output, when: *const std.posix.timespec)
}
}
+/// Pointer moved while the switcher is up: only schedules a frame (which
+/// recomputes `hovered` in `tick`) when that would actually change it, so
+/// jiggling the mouse over empty space stays idle.
+pub fn motion(self: *Self, x: f64, y: f64) void {
+ if (!self.active()) return;
+ const output = self.output orelse return;
+ self.last_cursor_x = x;
+ self.last_cursor_y = y;
+ const now = @import("Taskbar.zig").nowMs();
+ if (self.hit(output, now, x, y) == self.hovered) return;
+ output.wlr_output.scheduleFrame();
+}
+
+/// A left click on a card jumps straight to it, same as Tab-ing there and
+/// releasing the modifier; anything else (a miss, another button) cancels,
+/// matching the switcher's prior any-click-dismisses behavior.
+pub fn press(self: *Self, server: *Server, x: f64, y: f64, button: u32) void {
+ if (!self.active()) return;
+ if (button == 0x110) {
+ if (self.output) |output| {
+ const now = @import("Taskbar.zig").nowMs();
+ if (self.hit(output, now, x, y)) |index| {
+ self.selected = index;
+ self.accept(server);
+ return;
+ }
+ }
+ }
+ self.cancel();
+}
+
+fn hit(self: *Self, output: *Output, now: i64, x: f64, y: f64) ?usize {
+ const box = output.usableBox();
+ const lx = x - @as(f64, @floatFromInt(box.x + @divTrunc(box.width - self.width, 2)));
+ if (self.circle.enabled) {
+ const ly = y - @as(f64, @floatFromInt(box.y + @divTrunc(box.height - self.width, 2)));
+ return circular.hit(self, now, lx, ly);
+ }
+ const ly = y - @as(f64, @floatFromInt(box.y + @divTrunc(box.height - height, 2)));
+ if (ly < 28 or ly >= 28 + card_h) return null;
+ const offset: f64 = self.scroll.value(now);
+ for (0..self.cards.items.len) |i| {
+ const cx: f64 = @floatFromInt(@divTrunc(self.width - card_w, 2) + @as(i32, @intCast(i * stride)));
+ const left = @max(cx - offset, 16);
+ const right = @min(cx - offset + card_w, @as(f64, @floatFromInt(self.width - 16)));
+ if (lx >= left and lx < right) return i;
+ }
+ return null;
+}
+
pub fn accept(self: *Self, server: *Server) void {
if (!self.active()) return;
const id = self.cards.items[self.selected].id;
diff --git a/src/input/buttons.zig b/src/input/buttons.zig
index 9d10ec7..e6adbce 100644
--- a/src/input/buttons.zig
+++ b/src/input/buttons.zig
@@ -76,6 +76,10 @@ pub fn processButton(
input.tray_buttons &= ~screenshot_bit;
return;
}
+ if (state == .released and input.switcher_buttons & screenshot_bit != 0) {
+ input.switcher_buttons &= ~screenshot_bit;
+ return;
+ }
if (input.window_menu.node != null) {
if (state == .pressed) {
input.tray_buttons |= screenshot_bit;
@@ -132,7 +136,10 @@ pub fn processButton(
}
}
if (input.server.switcher.active()) {
- if (state == .released) input.server.switcher.cancel();
+ if (state == .pressed) {
+ input.switcher_buttons |= screenshot_bit;
+ input.server.switcher.press(input.server, input.cursor.x, input.cursor.y, button);
+ }
return;
}
if (input.server.world.mini_map.dragging or
diff --git a/src/input/motion.zig b/src/input/motion.zig
index 73cf406..96d2706 100644
--- a/src/input/motion.zig
+++ b/src/input/motion.zig
@@ -181,7 +181,11 @@ pub fn updateDockReveal(input: *Input) void {
}
pub fn processCursorMotion(input: *Input, time_msec: u32) void {
- if (input.server.locker != null or input.server.polkit_dialog != null or input.server.switcher.active()) return;
+ if (input.server.locker != null or input.server.polkit_dialog != null) return;
+ if (input.server.switcher.active()) {
+ input.server.switcher.motion(input.cursor.x, input.cursor.y);
+ return;
+ }
defer input.updateGrabBorderGlow();
input.positionDragIcon();
input.drag_dodge.motion();
diff --git a/src/switcher/circular.zig b/src/switcher/circular.zig
index c0d98cf..1f94467 100644
--- a/src/switcher/circular.zig
+++ b/src/switcher/circular.zig
@@ -31,6 +31,11 @@ pub const State = struct {
hub_icon_source: ?*wlr.Buffer = null,
hub_storage: ?*wlr.Buffer = null,
hub_key: ?u64 = null,
+ /// The window-count badge, now drawn over the focused window's own
+ /// sector instead of inside the hub (see `updateBadge`).
+ badge: ?*sn.Buffer = null,
+ badge_storage: ?*wlr.Buffer = null,
+ badge_key: ?usize = null,
/// The group the selected card belonged to last frame, so entering a
/// different group (including the very first selection) can be told
/// apart from cycling within the one already open.
@@ -41,6 +46,7 @@ pub const State = struct {
pub fn deinit(self: *State) void {
if (self.hub_storage) |buffer| buffer.unlock();
+ if (self.badge_storage) |buffer| buffer.unlock();
for (self.groups.items) |*group| group.members.deinit(gpa);
self.groups.deinit(gpa);
}
@@ -96,12 +102,19 @@ pub fn open(self: *Switcher, server: *Server) !void {
try group.members.append(gpa, index);
group.count += 1;
}
+ // Seed every card's animated stack slot at its resting depth so an
+ // unselected group's cascade renders correctly without having to wait
+ // for a `select()` retarget (which only ever touches the group it enters).
+ for (self.cards.items) |*card| card.stack.cancel(@floatFromInt(stackDepth(self, card)));
self.circle.hub = try self.tree.?.createSceneBuffer(null);
self.circle.hub.?.setFilterMode(.bilinear);
self.circle.hub.?.point_accepts_input = Switcher.ignoreInput;
self.circle.hub_icon = try self.tree.?.createSceneBuffer(null);
self.circle.hub_icon.?.setFilterMode(.bilinear);
self.circle.hub_icon.?.point_accepts_input = Switcher.ignoreInput;
+ self.circle.badge = try self.tree.?.createSceneBuffer(null);
+ self.circle.badge.?.setFilterMode(.bilinear);
+ self.circle.badge.?.point_accepts_input = Switcher.ignoreInput;
}
fn groupFor(self: *Switcher, server: *Server, raw: []const u8, index: usize) !usize {
@@ -140,15 +153,24 @@ pub fn advance(self: *Switcher, reverse: bool) void {
}
pub fn select(self: *Switcher, opening: bool) void {
+ const now = @import("../Taskbar.zig").nowMs();
const card = self.cards.items[self.selected];
const group = &self.circle.groups.items[card.group];
group.front = self.selected;
+ // Advancing the front shifts every member of this group by exactly one
+ // stack slot (`stackDepth` is relative to `front`), so retargeting all of
+ // them here slides the newly-front card's preview over the old one
+ // instead of popping straight to the new arrangement.
+ for (group.members.items) |member_index| {
+ const member = &self.cards.items[member_index];
+ member.stack.retargetTo(now, @floatFromInt(stackDepth(self, member)), ui.anim.curveFor(.switcher_scroll));
+ }
const entering_group = opening or self.circle.current_group != card.group;
if (entering_group) {
self.circle.current_group = card.group;
if (group.count > 1) {
self.circle.expand.cancel(0);
- self.circle.expand.retargetTo(@import("../Taskbar.zig").nowMs(), 1, ui.anim.curveFor(.switcher_scroll));
+ self.circle.expand.retargetTo(now, 1, ui.anim.curveFor(.switcher_scroll));
} else {
self.circle.expand.cancel(0);
}
@@ -161,7 +183,7 @@ pub fn select(self: *Switcher, opening: bool) void {
} else {
// Cross the twelve-o'clock seam by the shorter arc.
const delta = @mod(target - self.scroll.to + std.math.pi, tau) - std.math.pi;
- self.scroll.retargetTo(@import("../Taskbar.zig").nowMs(), self.scroll.to + delta, ui.anim.curveFor(.switcher_scroll));
+ self.scroll.retargetTo(now, self.scroll.to + delta, ui.anim.curveFor(.switcher_scroll));
}
self.circle.page = page;
// Only restack on selection. Repeating this every frame would damage an
@@ -175,6 +197,7 @@ pub fn select(self: *Switcher, opening: bool) void {
}
self.circle.hub.?.node.raiseToTop();
self.circle.hub_icon.?.node.raiseToTop();
+ self.circle.badge.?.node.raiseToTop();
}
fn stackDepth(self: *const Switcher, card: *const Switcher.Card) usize {
@@ -183,6 +206,44 @@ fn stackDepth(self: *const Switcher, card: *const Switcher.Card) usize {
return (card.member + group.count - front.member) % group.count;
}
+/// Pure geometry hit test mirroring `tick`'s placement math (without
+/// touching scene nodes), so pointer motion/clicks landing between frames
+/// still match exactly what's on screen. `lx`/`ly` are local to the
+/// switcher's own tree. Prefers whichever matching card sits topmost in its
+/// group's stack (`depth`'s raise-to-top order in `select`), since a deeper
+/// member's sector mostly sits behind the one in front of it.
+pub fn hit(self: *Switcher, now: i64, lx: f64, ly: f64) ?usize {
+ const slots = @min(page_size, self.circle.groups.items.len - self.circle.page * page_size);
+ if (slots == 0) return null;
+ const arc = layout.span(slots);
+ const rotation: f64 = self.scroll.value(now);
+ const selected_group = self.cards.items[self.selected].group;
+ const expand: f64 = @floatCast(self.circle.expand.value(now));
+ var best: ?usize = null;
+ var best_depth: f64 = std.math.inf(f64);
+ for (self.cards.items, 0..) |*card, i| {
+ const depth: f64 = card.stack.value(now);
+ if (card.group / page_size != self.circle.page or depth >= 3 or depth >= best_depth) continue;
+ const angle = @as(f64, @floatFromInt(card.group % page_size)) * tau / @as(f64, @floatFromInt(slots)) - rotation;
+ const progress = if (card.group == selected_group) expand else 0;
+ const sector = layout.makeSector(self.width, angle, arc, depth, progress);
+ if (inSector(sector, lx, ly)) {
+ best = i;
+ best_depth = depth;
+ }
+ }
+ return best;
+}
+
+fn inSector(sector: layout.Sector, lx: f64, ly: f64) bool {
+ const dx = lx - @as(f64, @floatFromInt(sector.x)) - sector.arc.center[0];
+ const dy = ly - @as(f64, @floatFromInt(sector.y)) - sector.arc.center[1];
+ const radius = @sqrt(dx * dx + dy * dy);
+ if (radius < sector.arc.radii[0] or radius > sector.arc.radii[1] or radius == 0) return false;
+ const dot = (dx / radius) * sector.arc.axis[0] + (dy / radius) * sector.arc.axis[1];
+ return dot >= sector.arc.half_angle[0] - 1e-9;
+}
+
pub fn tick(self: *Switcher, output: *Output, now: i64) bool {
const box = output.usableBox();
self.tree.?.node.setPosition(box.x + @divTrunc(box.width - self.width, 2), box.y + @divTrunc(box.height - self.width, 2));
@@ -192,26 +253,31 @@ pub fn tick(self: *Switcher, output: *Output, now: i64) bool {
const rotation: f64 = self.scroll.value(now);
const selected_group = self.cards.items[self.selected].group;
const expand: f64 = @floatCast(self.circle.expand.value(now));
- for (self.cards.items) |*card| {
- const depth = stackDepth(self, card);
+ var stack_settled = true;
+ for (self.cards.items, 0..) |*card, i| {
+ const depth: f64 = card.stack.value(now);
+ stack_settled = stack_settled and card.stack.settled(now);
const visible = card.group / page_size == self.circle.page and depth < 3;
card.tree.?.node.setEnabled(visible);
if (!visible) continue;
const angle = @as(f64, @floatFromInt(card.group % page_size)) * tau / @as(f64, @floatFromInt(slots)) - rotation;
const progress = if (card.group == selected_group) expand else 0;
const sector = layout.makeSector(self.width, angle, arc, depth, progress);
- placeCard(self, card, sector, depth, progress);
- if (card.id == self.cards.items[self.selected].id) self.refreshIcon(card);
+ placeCard(self, card, sector, depth, progress, self.hovered == i and i != self.selected);
+ if (card.id == self.cards.items[self.selected].id) {
+ self.refreshIcon(card);
+ updateBadge(self, card, sector) catch |err| std.log.warn("circular switcher badge: {}", .{err});
+ }
}
paintHub(self, output.server) catch |err| std.log.warn("circular switcher label: {}", .{err});
_ = self.scroll.sampleChanged(now, ui.anim.quantum_px);
_ = self.circle.expand.sampleChanged(now, ui.anim.quantum_px);
- return !self.scroll.settled(now) or !self.circle.expand.settled(now);
+ return !self.scroll.settled(now) or !self.circle.expand.settled(now) or !stack_settled;
}
-fn placeCard(self: *Switcher, card: *Switcher.Card, sector: layout.Sector, depth: usize, progress: f64) void {
+fn placeCard(self: *Switcher, card: *Switcher.Card, sector: layout.Sector, depth: f64, progress: f64, hovered: bool) void {
const selected = self.cards.items[self.selected].id == card.id;
- const color = if (selected) theme.global.switcher_selected_border else theme.global.switcher_item_border;
+ const color = if (selected) theme.global.switcher_selected_border else if (hovered) theme.global.border_hover else theme.global.switcher_item_border;
const tree = card.tree.?;
tree.node.setPosition(sector.x, sector.y);
card.fill.?.setSize(sector.width, sector.height);
@@ -219,7 +285,7 @@ fn placeCard(self: *Switcher, card: *Switcher.Card, sector: layout.Sector, depth
.width = sector.width,
.height = sector.height,
.radii = @splat(0),
- .border = if (selected) 2 else 1,
+ .border = if (selected or hovered) 2 else 1,
.border_color = col.Straight.fromRgba(color).premultiply().rgba,
.sector = sector.arc,
.sector_texture_height = if (card.pw > 0) layout.previewHeight(sector, card.aspect) else 0,
@@ -241,6 +307,45 @@ fn placeCard(self: *Switcher, card: *Switcher.Card, sector: layout.Sector, depth
preview.setDestSize(sector.width, sector.height);
}
+/// The window-count badge for a multi-window group, held over the focused
+/// card's own sector rather than inside the hub. Positioned at the sector's
+/// inner, hub-facing edge (its angular bisector at `radii[0]`) so it reads as
+/// part of the window being focused, closest to where the hub's arrow points.
+fn updateBadge(self: *Switcher, card: *Switcher.Card, sector: layout.Sector) !void {
+ const badge = self.circle.badge.?;
+ const group = self.circle.groups.items[card.group];
+ if (group.count <= 1) {
+ badge.node.setEnabled(false);
+ return;
+ }
+ badge.node.setEnabled(true);
+ const s: f32 = @max(0.75, @min(1, @as(f32, @floatFromInt(self.width)) / 600));
+ const d: f32 = 22 * s * 1.3;
+ if (self.circle.badge_key != group.count) {
+ const px: i32 = @intFromFloat(@ceil(d));
+ const image = try PanelBuffer.create(px, px, self.scale);
+ defer image.base.drop();
+ var r = ui.paint.Renderer.init(image.pixels, image.width, image.height, self.scale);
+ r.fillRect(0, 0, d, d, .{ .color = theme.global.switcher_selected_border, .radius = d / 2, .border_width = 1, .border_color = theme.global.switcher_item_bg });
+ var badge_buf: [8]u8 = undefined;
+ const badge_text = std.fmt.bufPrint(&badge_buf, "{d}", .{group.count}) catch "";
+ const font_size = 11 * 1.3 * s;
+ const text_width = ui.text.measureWidthF(badge_text, .manrope_heavy, font_size, self.scale) catch d;
+ const text_height = font_size + 6;
+ r.drawText(d / 2 - text_width / 2, d / 2 - text_height / 2, text_width + 4, text_height, .{ .content = badge_text, .font_size = font_size, .weight = 700, .color = theme.global.on_accent });
+ badge.setBuffer(&image.base);
+ _ = image.base.lock();
+ if (self.circle.badge_storage) |old| old.unlock();
+ self.circle.badge_storage = &image.base;
+ badge.setDestSize(px, px);
+ self.circle.badge_key = group.count;
+ }
+ const inner_x = sector.arc.center[0] + sector.arc.axis[0] * sector.arc.radii[0];
+ const inner_y = sector.arc.center[1] + sector.arc.axis[1] * sector.arc.radii[0];
+ const half_d: f64 = @floatCast(d / 2);
+ badge.node.setPosition(sector.x + @as(i32, @intFromFloat(inner_x - half_d)), sector.y + @as(i32, @intFromFloat(inner_y - half_d)));
+}
+
fn paintHub(self: *Switcher, server: *Server) !void {
const card = &self.cards.items[self.selected];
const tl = server.findToplevelById(card.id) orelse return;
@@ -280,21 +385,6 @@ fn paintHub(self: *Switcher, server: *Server) !void {
var count_buf: [64]u8 = undefined;
const count = std.fmt.bufPrint(&count_buf, "{d} / {d}", .{ card.member + 1, group.count }) catch "";
centered(&r, d, d / 2 + 24 * s, count, theme.global.switcher_app_size * text_scale, theme.global.switcher_fg);
- // The stack's total window count, as a small badge inside the hub disc
- // itself (up and to the right of centre) rather than floating outside
- // the wheel next to the sector.
- if (group.count > 1) {
- const badge_d = 22 * s;
- const reach = d / 2 * 0.72;
- const badge_cx = d / 2 + reach * 0.7;
- const badge_cy = d / 2 - reach * 0.7;
- var badge_buf: [8]u8 = undefined;
- const badge_text = std.fmt.bufPrint(&badge_buf, "{d}", .{group.count}) catch "";
- const font_size = 11 * text_scale;
- const text_width = ui.text.measureWidthF(badge_text, .manrope_heavy, font_size, self.scale) catch badge_d;
- r.fillRect(badge_cx - badge_d / 2, badge_cy - badge_d / 2, badge_d, badge_d, .{ .color = theme.global.switcher_selected_border, .radius = badge_d / 2, .border_width = 1, .border_color = theme.global.switcher_item_bg });
- r.drawText(badge_cx - text_width / 2, badge_cy - font_size / 2 - 1, text_width + 4, font_size + 6, .{ .content = badge_text, .font_size = font_size, .weight = 700, .color = theme.global.on_accent });
- }
if (self.circle.groups.items.len > page_size) {
const pages = (self.circle.groups.items.len + page_size - 1) / page_size;
const shown = @min(5, pages);
diff --git a/src/switcher/layout.zig b/src/switcher/layout.zig
index 0ec1211..ee4dec5 100644
--- a/src/switcher/layout.zig
+++ b/src/switcher/layout.zig
@@ -24,11 +24,13 @@ pub fn span(group_count: usize) f64 {
/// `progress` is 0 for a group's ordinary idle stack (a thin 14px cascade)
/// rising to 1 while the switcher eases the *selected* group open, so its
/// windows fan out far enough to read individually. Callers pass 0 for any
-/// group that is not currently selected.
-pub fn makeSector(size: i32, angle: f64, arc: f64, depth: usize, progress: f64) Sector {
+/// group that is not currently selected. `depth` is fractional while a card
+/// is sliding to a new stack slot (`Switcher.Card.stack`); callers pass a
+/// whole number for an otherwise-idle card.
+pub fn makeSector(size: i32, angle: f64, arc: f64, depth: f64, progress: f64) Sector {
const center = @as(f64, @floatFromInt(size)) / 2;
const step = 14 + 46 * std.math.clamp(progress, 0, 1);
- const offset = @as(f64, @floatFromInt(@min(depth, 2))) * step;
+ const offset = @min(depth, 2) * step;
const inner = @as(f64, @floatFromInt(size)) * 0.18 + offset;
const outer = center - 36 + offset;
const axis: [2]f64 = .{ @sin(angle), -@cos(angle) };
diff --git a/src/switcher/layout_tests.zig b/src/switcher/layout_tests.zig
index 15c3d8d..faf6768 100644
--- a/src/switcher/layout_tests.zig
+++ b/src/switcher/layout_tests.zig
@@ -22,7 +22,7 @@ test "exact circular arcs stay within the preview bounds throughout rotation" {
for (0..32) |step| {
const angle = 2 * std.math.pi * @as(f64, @floatFromInt(step)) / 32;
const arc = layout.span(count);
- const sector = layout.makeSector(size, angle, arc, depth, 0);
+ const sector = layout.makeSector(size, angle, arc, @floatFromInt(depth), 0);
try testing.expect(sector.width > 0 and sector.height > 0);
try testing.expect(sector.x >= 0 and sector.y >= 0);
try testing.expect(sector.x + sector.width <= size);