Skip to content

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

circular switcher updates

oxydizer66604ca777bc
diff --git a/docs/wiki/Configuration.md b/docs/wiki/Configuration.md
index 20e37f1..b659ebd 100644
--- a/docs/wiki/Configuration.md
+++ b/docs/wiki/Configuration.md
@@ -189,6 +189,12 @@ time and date (`clock_bold` and `clock_italic` in `[theme]`, or
Drag lift uses a gentle spring around the grab point and returns smoothly on
release. Its timing can be adjusted with `[animations.window_drag]`.
+The `circular` switcher's hub appears first and the windows grow out of it
+when it opens, and collapse back into the hub the same way when it closes;
+timing is `[animations.switcher_open]` and `[animations.switcher_close]`. Like
+every other animation, Appearance's **Animations** switch and **Reduced
+motion** make both instant.
+
## Outputs
```toml
diff --git a/src/Switcher.zig b/src/Switcher.zig
index b6ecc6c..0e24ee7 100644
--- a/src/Switcher.zig
+++ b/src/Switcher.zig
@@ -82,6 +82,11 @@ pub fn triggerHeld(self: *const Self, server: *Server) bool {
}
pub fn step(self: *Self, server: *Server, reverse: bool, trigger: Trigger) void {
+ // A still-fading-out instance can only be here because a new gesture
+ // (the previous one already ended via `dismiss`) just started: finish
+ // the old teardown now so `opening` below sees a clean slate, rather
+ // than silently dropping this Tab or stepping a zombie instance.
+ if (self.circle.closing) self.cancel();
const opening = !self.active();
if (opening) {
self.trigger = trigger;
@@ -226,7 +231,8 @@ pub fn tick(self: *Self, output: *Output, now: i64) bool {
}
// 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);
+ // Suppressed while closing: nothing should light up as it collapses.
+ self.hovered = if (self.circle.closing) null else 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));
@@ -325,7 +331,7 @@ pub fn frameDone(self: *Self, output: *Output, when: *const std.posix.timespec)
/// 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;
+ if (!self.active() or self.circle.closing) return;
const output = self.output orelse return;
self.last_cursor_x = x;
self.last_cursor_y = y;
@@ -338,7 +344,7 @@ pub fn motion(self: *Self, x: f64, y: f64) void {
/// 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 (!self.active() or self.circle.closing) return;
if (button == 0x110) {
if (self.output) |output| {
const now = @import("Taskbar.zig").nowMs();
@@ -349,7 +355,7 @@ pub fn press(self: *Self, server: *Server, x: f64, y: f64, button: u32) void {
}
}
}
- self.cancel();
+ self.dismiss();
}
fn hit(self: *Self, output: *Output, now: i64, x: f64, y: f64) ?usize {
@@ -372,16 +378,39 @@ fn hit(self: *Self, output: *Output, now: i64, x: f64, y: f64) ?usize {
}
pub fn accept(self: *Self, server: *Server) void {
- if (!self.active()) return;
+ if (!self.active() or self.circle.closing) return;
const id = self.cards.items[self.selected].id;
const output = self.output;
- self.cancel();
+ self.dismiss();
if (server.findToplevelById(id)) |tl| {
if (tl.minimized) tl.restore() else server.world.focus(tl);
if (output) |out| server.world.navigateTo(tl, out);
}
}
+/// Ends the switcher the way the user asked for it to end: releasing the
+/// modifier, Escape, or a click (through `accept`/`press`). The circular
+/// style plays its close animation first (`circular.beginClose`); `tick`
+/// finishes the real teardown once it settles, which `Anim.settled` reports
+/// as already true this same call when animations are off, reduced, or the
+/// linear style has nothing to animate, so this still closes synchronously
+/// then. A forced teardown (output loss, session lock, a card's window
+/// gone, ...) must stay instant and calls `cancel` directly instead.
+pub fn dismiss(self: *Self) void {
+ if (!self.active()) return;
+ if (self.circle.closing or !self.circle.enabled) {
+ self.cancel();
+ return;
+ }
+ const now = @import("Taskbar.zig").nowMs();
+ circular.beginClose(self, now);
+ if (self.circle.appear.settled(now)) {
+ self.cancel();
+ return;
+ }
+ self.output.?.wlr_output.scheduleFrame();
+}
+
pub fn cancel(self: *Self) void {
if (self.tree) |tree| tree.node.destroy();
self.circle.deinit();
diff --git a/src/ipc/animations.zig b/src/ipc/animations.zig
index d67bc6c..4c49ce3 100644
--- a/src/ipc/animations.zig
+++ b/src/ipc/animations.zig
@@ -36,6 +36,9 @@ pub fn snapshot(server: *Server, allocator: std.mem.Allocator) ![]const protocol
if (server.switcher.active()) {
try appendLive(allocator, &list, "switcher.scroll", server.switcher.scroll, now_ms);
+ if (server.switcher.circle.enabled) {
+ try appendLive(allocator, &list, "switcher.appear", server.switcher.circle.appear, now_ms);
+ }
}
if (server.notifications) |mgr| {
diff --git a/src/keyboard/process.zig b/src/keyboard/process.zig
index c811766..25c8d9a 100644
--- a/src/keyboard/process.zig
+++ b/src/keyboard/process.zig
@@ -230,7 +230,7 @@ pub fn processKey(keyboard: *Keyboard, time_msec: u32, event_keycode: u32, state
}
if (keyboard.server.switcher.active()) {
keyboard.stopSwitcherRepeat();
- if (sym == xkb.Keysym.Escape) keyboard.server.switcher.cancel();
+ if (sym == xkb.Keysym.Escape) keyboard.server.switcher.dismiss();
if (sym == xkb.Keysym.Return) keyboard.server.switcher.accept(keyboard.server);
if (event_keycode < keyboard.switcher_consumed.len) keyboard.switcher_consumed[event_keycode] = true;
return;
diff --git a/src/switcher/circular.zig b/src/switcher/circular.zig
index 1f94467..ec947e8 100644
--- a/src/switcher/circular.zig
+++ b/src/switcher/circular.zig
@@ -43,10 +43,26 @@ pub const State = struct {
/// 0 = idle stack, 1 = the selected group's windows fanned fully open.
/// Retargeted in `select` whenever `current_group` changes.
expand: Anim = .{},
+ /// 0 = nothing shown, 1 = fully open. Runs once from 0->1 in `open`
+ /// (the hub appears, then windows grow out of it) and, while `closing`,
+ /// back from 1->0 before `tick` actually tears the switcher down.
+ appear: Anim = .{},
+ /// Set by `Switcher.dismiss` for an animated close; `tick` finishes the
+ /// real `Switcher.cancel` once `appear` settles at 0. Forced teardowns
+ /// (`Switcher.cancel` called directly, e.g. on output loss or session
+ /// lock) ignore this and tear down synchronously instead.
+ closing: bool = false,
+ /// The hub's arrow, in radians clockwise from "points up at the
+ /// selected card" (always true at rest, since the selection sits at
+ /// twelve o'clock). Swings to point at whatever's hovered (`updateArrow`).
+ arrow_angle: Anim = .{},
+ hub_arrow: ?*sn.Buffer = null,
+ hub_arrow_storage: ?*wlr.Buffer = null,
pub fn deinit(self: *State) void {
if (self.hub_storage) |buffer| buffer.unlock();
if (self.badge_storage) |buffer| buffer.unlock();
+ if (self.hub_arrow_storage) |buffer| buffer.unlock();
for (self.groups.items) |*group| group.members.deinit(gpa);
self.groups.deinit(gpa);
}
@@ -115,6 +131,34 @@ pub fn open(self: *Switcher, server: *Server) !void {
self.circle.badge = try self.tree.?.createSceneBuffer(null);
self.circle.badge.?.setFilterMode(.bilinear);
self.circle.badge.?.point_accepts_input = Switcher.ignoreInput;
+ self.circle.hub_arrow = try self.tree.?.createSceneBuffer(null);
+ self.circle.hub_arrow.?.setFilterMode(.bilinear);
+ self.circle.hub_arrow.?.point_accepts_input = Switcher.ignoreInput;
+ self.circle.appear.retargetTo(@import("../Taskbar.zig").nowMs(), 1, ui.anim.curveFor(.switcher_open));
+}
+
+/// Called from `Switcher.dismiss` for a normal, user-driven close (releasing
+/// the modifier, Escape, accepting a selection). Plays the open animation in
+/// reverse; `tick` finishes the real teardown once it settles. Forced
+/// teardowns keep calling `Switcher.cancel` directly and skip this.
+pub fn beginClose(self: *Switcher, now: i64) void {
+ self.circle.closing = true;
+ self.circle.appear.retargetTo(now, 0, ui.anim.curveFor(.switcher_close));
+ self.hovered = null;
+}
+
+/// 0 while the hub is still fading in (or has already faded past, on close)
+/// and windows have not started growing; 1 once they should be fully grown.
+/// The 0.15 head start is the "hub appears first" beat the cards wait out.
+fn cardGrowth(appear: f64) f64 {
+ return std.math.clamp((appear - 0.15) / 0.85, 0, 1);
+}
+
+/// The hub, its icon, the badge and the backdrop disc fade in over the first
+/// third of `appear` and are the last things to fade out on close, so cards
+/// visibly grow out of the hub both ways.
+fn hubFade(appear: f64) f32 {
+ return @floatCast(std.math.clamp(appear / 0.3, 0, 1));
}
fn groupFor(self: *Switcher, server: *Server, raw: []const u8, index: usize) !usize {
@@ -198,6 +242,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();
+ self.circle.hub_arrow.?.node.raiseToTop();
}
fn stackDepth(self: *const Switcher, card: *const Switcher.Card) usize {
@@ -219,6 +264,7 @@ pub fn hit(self: *Switcher, now: i64, lx: f64, ly: f64) ?usize {
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));
+ const growth = cardGrowth(self.circle.appear.value(now));
var best: ?usize = null;
var best_depth: f64 = std.math.inf(f64);
for (self.cards.items, 0..) |*card, i| {
@@ -226,7 +272,7 @@ pub fn hit(self: *Switcher, now: i64, lx: f64, ly: f64) ?usize {
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);
+ const sector = layout.makeSector(self.width, angle, arc, depth, progress, growth);
if (inSector(sector, lx, ly)) {
best = i;
best_depth = depth;
@@ -245,9 +291,19 @@ fn inSector(sector: layout.Sector, lx: f64, ly: f64) bool {
}
pub fn tick(self: *Switcher, output: *Output, now: i64) bool {
+ // The close animation finishes here rather than in `Switcher.dismiss`:
+ // it needs a frame boundary to keep sampling `appear` against, and this
+ // is the one place already called every frame while the switcher lives.
+ if (self.circle.closing and self.circle.appear.settled(now)) {
+ self.cancel();
+ return false;
+ }
const box = output.usableBox();
self.tree.?.node.setPosition(box.x + @divTrunc(box.width - self.width, 2), box.y + @divTrunc(box.height - self.width, 2));
- if (self.background) |bg| bg.setOpacity(theme.global.window_bg[3]);
+ const appear: f64 = self.circle.appear.value(now);
+ const growth = cardGrowth(appear);
+ const fade = hubFade(appear);
+ if (self.background) |bg| bg.setOpacity(theme.global.window_bg[3] * fade);
const slots = @min(page_size, self.circle.groups.items.len - self.circle.page * page_size);
const arc = layout.span(slots);
const rotation: f64 = self.scroll.value(now);
@@ -262,7 +318,7 @@ pub fn tick(self: *Switcher, output: *Output, now: i64) bool {
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);
+ const sector = layout.makeSector(self.width, angle, arc, depth, progress, growth);
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);
@@ -270,14 +326,23 @@ pub fn tick(self: *Switcher, output: *Output, now: i64) bool {
}
}
paintHub(self, output.server) catch |err| std.log.warn("circular switcher label: {}", .{err});
+ updateArrow(self, now);
+ self.circle.hub.?.setOpacity(fade);
+ self.circle.hub_icon.?.setOpacity(fade);
+ self.circle.badge.?.setOpacity(fade);
+ self.circle.hub_arrow.?.setOpacity(fade);
_ = 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) or !stack_settled;
+ _ = self.circle.appear.sampleChanged(now, ui.anim.quantum_px);
+ return !self.scroll.settled(now) or !self.circle.expand.settled(now) or !stack_settled or !self.circle.appear.settled(now) or
+ !self.circle.arrow_angle.settled(now);
}
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 if (hovered) theme.global.border_hover else theme.global.switcher_item_border;
+ // Hover reads as "click here to land on this one", the same promise the
+ // selected sector's own border makes, so both share its colour.
+ const color = if (selected or hovered) theme.global.switcher_selected_border else theme.global.switcher_item_border;
const tree = card.tree.?;
tree.node.setPosition(sector.x, sector.y);
card.fill.?.setSize(sector.width, sector.height);
@@ -371,10 +436,6 @@ fn paintHub(self: *Switcher, server: *Server) !void {
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_item_bg, .radius = d / 2, .border_width = 1, .border_color = theme.global.switcher_border });
- // The selected sector always settles at twelve o'clock (layout.zig),
- // so a fixed upward arrow always points at it; no need to rotate it.
- const arrow_size = 28 * s;
- r.drawIcon(d / 2 - arrow_size / 2, 2 * s, arrow_size, arrow_size, .{ .id = .caret_up, .color = theme.global.switcher_selected_border });
centered(&r, d, d / 2 - 22 * s, tl.title(), theme.global.switcher_title_size * text_scale, theme.global.switcher_fg);
var workspace_buf: [128]u8 = undefined;
const workspace = if (server.world.workspaces.active)
@@ -404,6 +465,63 @@ fn paintHub(self: *Switcher, server: *Server) !void {
}
}
+/// The hub's arrow: normally points up at the selected card (always eased to
+/// twelve o'clock by `select`'s own rotation), but swings to point at
+/// whatever's hovered instead, so the pointer previews where a click would
+/// land. Drawn as its own node rather than baked into the hub's cached
+/// image (`paintHub`'s `hub_key`): the angle can change every frame, on
+/// pointer motion alone, independently of anything that invalidates that key.
+fn updateArrow(self: *Switcher, now: i64) void {
+ const slots = @min(page_size, self.circle.groups.items.len - self.circle.page * page_size);
+ const rotation: f64 = self.scroll.value(now);
+ const target: f64 = blk: {
+ const h = self.hovered orelse break :blk 0;
+ const card = self.cards.items[h];
+ if (card.group / page_size != self.circle.page or slots == 0) break :blk 0;
+ break :blk @as(f64, @floatFromInt(card.group % page_size)) * tau / @as(f64, @floatFromInt(slots)) - rotation;
+ };
+ // Cross the twelve-o'clock seam by the shorter arc, same trick `select`
+ // uses for the wheel's own rotation.
+ const current: f64 = self.circle.arrow_angle.to;
+ const delta = @mod(target - current + std.math.pi, tau) - std.math.pi;
+ self.circle.arrow_angle.retargetTo(now, @floatCast(current + delta), ui.anim.curveFor(.switcher_scroll));
+ // ~0.03 rad (~1.7 deg) of play before a 14px-radius glyph visibly moves.
+ if (!self.circle.arrow_angle.sampleChanged(now, 0.03)) return;
+
+ const size: i32 = @intFromFloat(@as(f32, @floatFromInt(self.width)) * 0.36 - 16);
+ const x = @divTrunc(self.width - size, 2);
+ const s: f32 = @min(1, @as(f32, @floatFromInt(size)) / 210);
+ const d: f32 = @floatFromInt(size);
+ const arrow_size = 28 * s;
+ // Generous padding: a square rotated about its own center at any angle
+ // still fits a canvas 1.5x its side.
+ const canvas: i32 = @intFromFloat(@ceil(arrow_size * 1.5));
+ const image = PanelBuffer.create(canvas, canvas, self.scale) catch return;
+ defer image.base.drop();
+ var r = ui.paint.Renderer.init(image.pixels, image.width, image.height, self.scale);
+ const off = (@as(f32, @floatFromInt(canvas)) - arrow_size) / 2;
+ r.drawIcon(off, off, arrow_size, arrow_size, .{
+ .id = .caret_up,
+ .color = theme.global.switcher_selected_border,
+ .rotation = self.circle.arrow_angle.value(now),
+ });
+ self.circle.hub_arrow.?.setBuffer(&image.base);
+ _ = image.base.lock();
+ if (self.circle.hub_arrow_storage) |old| old.unlock();
+ self.circle.hub_arrow_storage = &image.base;
+ self.circle.hub_arrow.?.setDestSize(canvas, canvas);
+ // The pivot is where the old baked-in, fixed-up arrow's box center sat:
+ // `(d/2, 2*s + arrow_size/2)` inside the hub image, which itself sits at
+ // switcher-tree-local `(x, x)`.
+ const pivot_x = @as(f32, @floatFromInt(x)) + d / 2;
+ const pivot_y = @as(f32, @floatFromInt(x)) + 2 * s + arrow_size / 2;
+ const half_canvas: f32 = @as(f32, @floatFromInt(canvas)) / 2;
+ self.circle.hub_arrow.?.node.setPosition(
+ @as(i32, @intFromFloat(@round(pivot_x - half_canvas))),
+ @as(i32, @intFromFloat(@round(pivot_y - half_canvas))),
+ );
+}
+
fn centered(r: *ui.paint.Renderer, width: f32, y: f32, value: []const u8, size: f32, color: [4]f32) void {
const x = @max(12, ui.paint.centeredTextX(0, width, value, size));
r.drawText(x, y, width - x - 12, size + 8, .{ .content = value, .font_size = size, .color = color });
diff --git a/src/switcher/layout.zig b/src/switcher/layout.zig
index ee4dec5..46b77a2 100644
--- a/src/switcher/layout.zig
+++ b/src/switcher/layout.zig
@@ -26,13 +26,18 @@ pub fn span(group_count: usize) f64 {
/// windows fan out far enough to read individually. Callers pass 0 for any
/// 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 {
+/// whole number for an otherwise-idle card. `growth` is 1 once the switcher's
+/// open/close animation has settled; below that it shrinks the sector's
+/// outer radius toward `inner` so the card reads as still emerging from (or
+/// collapsing into) the hub. `growth >= 1` takes the exact pre-existing path
+/// so resting geometry is bit-for-bit unchanged.
+pub fn makeSector(size: i32, angle: f64, arc: f64, depth: f64, progress: f64, growth: f64) Sector {
const center = @as(f64, @floatFromInt(size)) / 2;
const step = 14 + 46 * std.math.clamp(progress, 0, 1);
const offset = @min(depth, 2) * step;
const inner = @as(f64, @floatFromInt(size)) * 0.18 + offset;
- const outer = center - 36 + offset;
+ const full_outer = center - 36 + offset;
+ const outer = if (growth >= 1) full_outer else inner + (full_outer - inner) * @max(growth, 0);
const axis: [2]f64 = .{ @sin(angle), -@cos(angle) };
const half: [2]f64 = .{ @cos(arc / 2), @sin(arc / 2) };
var left: f64 = std.math.inf(f64);
diff --git a/src/switcher/layout_tests.zig b/src/switcher/layout_tests.zig
index faf6768..7fcbbf5 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, @floatFromInt(depth), 0);
+ const sector = layout.makeSector(size, angle, arc, @floatFromInt(depth), 0, 1);
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);
@@ -48,26 +48,26 @@ test "exact circular arcs stay within the preview bounds throughout rotation" {
}
test "stack offsets remain concentric and stop at two layers" {
- const front = layout.makeSector(720, 0.43, layout.span(5), 0, 0);
- const back = layout.makeSector(720, 0.43, layout.span(5), 2, 0);
+ const front = layout.makeSector(720, 0.43, layout.span(5), 0, 0, 1);
+ const back = layout.makeSector(720, 0.43, layout.span(5), 2, 0, 1);
try testing.expectApproxEqAbs(@as(f64, 28), back.arc.radii[0] - front.arc.radii[0], 1e-8);
try testing.expectApproxEqAbs(@as(f64, 28), back.arc.radii[1] - front.arc.radii[1], 1e-8);
- try testing.expectEqualDeep(back, layout.makeSector(720, 0.43, layout.span(5), 100, 0));
+ try testing.expectEqualDeep(back, layout.makeSector(720, 0.43, layout.span(5), 100, 0, 1));
}
test "expand progress widens the stack without moving the front layer" {
- const front = layout.makeSector(720, 0.43, layout.span(5), 0, 1);
- const front_idle = layout.makeSector(720, 0.43, layout.span(5), 0, 0);
+ const front = layout.makeSector(720, 0.43, layout.span(5), 0, 1, 1);
+ const front_idle = layout.makeSector(720, 0.43, layout.span(5), 0, 0, 1);
try testing.expectEqualDeep(front_idle, front);
- const back_idle = layout.makeSector(720, 0.43, layout.span(5), 2, 0);
- const back_open = layout.makeSector(720, 0.43, layout.span(5), 2, 1);
+ const back_idle = layout.makeSector(720, 0.43, layout.span(5), 2, 0, 1);
+ const back_open = layout.makeSector(720, 0.43, layout.span(5), 2, 1, 1);
try testing.expectApproxEqAbs(@as(f64, 120), back_open.arc.radii[0] - front.arc.radii[0], 1e-8);
try testing.expect(back_open.arc.radii[0] - front.arc.radii[0] > back_idle.arc.radii[0] - front_idle.arc.radii[0]);
}
test "radial previews fit the full top edge and crop only below it" {
const arc = layout.span(4);
- const front = layout.makeSector(720, 0, arc, 0, 0);
+ const front = layout.makeSector(720, 0, arc, 0, 0, 1);
const height = layout.previewHeight(front, 0.2);
try testing.expectApproxEqAbs(front.arc.radii[1] * arc / 0.2, height, 1e-8);
const depth = front.arc.radii[1] - front.arc.radii[0];
@@ -76,7 +76,7 @@ test "radial previews fit the full top edge and crop only below it" {
try testing.expect(depth / height < 0.1);
for (0..32) |step| {
const angle = 2 * std.math.pi * @as(f64, @floatFromInt(step)) / 32;
- const rotated = layout.makeSector(720, angle, arc, 0, 0);
+ const rotated = layout.makeSector(720, angle, arc, 0, 0, 1);
try testing.expectApproxEqAbs(height, layout.previewHeight(rotated, 0.2), 1e-8);
}
// Shallow windows retain their natural height; empty space after their
diff --git a/src/ui/anim.zig b/src/ui/anim.zig
index cf66263..d834970 100644
--- a/src/ui/anim.zig
+++ b/src/ui/anim.zig
@@ -110,6 +110,8 @@ pub const Target = enum {
taskbar_flip,
start_button,
switcher_scroll,
+ switcher_open,
+ switcher_close,
wheel_scroll,
osd_level,
toast_slide,
@@ -181,6 +183,10 @@ pub fn defaultSpec(target: Target) TargetSpec {
.taskbar_press => .{ .curve = .{ .duration = .{ .ms = 90, .ease = .out_cubic } } },
.taskbar_flip, .toast_flip => .{ .curve = .{ .spring = springs.taskbar_flip } },
.switcher_scroll => .{ .curve = .{ .spring = springs.switcher_scroll } },
+ // Circular style only: the hub appears first and windows grow out of
+ // it (reversed on close); kept short since it plays on every gesture.
+ .switcher_open => .{ .curve = .{ .duration = .{ .ms = 150, .ease = .out_cubic } } },
+ .switcher_close => .{ .curve = .{ .duration = .{ .ms = 110, .ease = .out_cubic } } },
.wheel_scroll => .{ .curve = .{ .spring = springs.wheel_scroll } },
.osd_level => .{ .curve = .{ .spring = springs.osd_level } },
.toast_slide => .{ .curve = .{ .spring = springs.toast_slide } },
diff --git a/src/ui/layout.zig b/src/ui/layout.zig
index abd8c4b..d4b1f88 100644
--- a/src/ui/layout.zig
+++ b/src/ui/layout.zig
@@ -194,6 +194,9 @@ pub const IconStyle = struct {
id: IconId,
color: [4]f32,
stroke_width: ?f32 = null,
+ /// Radians, clockwise, about the icon box's own center. 0 costs nothing
+ /// extra; used by the circular switcher's hub arrow.
+ rotation: f32 = 0,
};
pub const ImageData = struct {
diff --git a/src/ui/paint.zig b/src/ui/paint.zig
index 066c8e3..9c8aacc 100644
--- a/src/ui/paint.zig
+++ b/src/ui/paint.zig
@@ -503,13 +503,25 @@ pub const Renderer = struct {
const side = @min(w, h) * s;
const left = cx - side / 2;
const top = cy - side / 2;
+ // Sample the glyph's own (unrotated) coordinate frame at the point
+ // that would land on this destination pixel after rotating by
+ // `style.rotation`, i.e. rotate the sample backwards.
+ const rot = style.rotation;
+ const cos_r = @cos(-rot);
+ const sin_r = @sin(-rot);
var py = y0;
while (py < y1) : (py += 1) {
var px = x0;
while (px < x1) : (px += 1) {
- const sx = @as(f32, @floatFromInt(px)) + 0.5;
- const sy = @as(f32, @floatFromInt(py)) + 0.5;
+ var sx = @as(f32, @floatFromInt(px)) + 0.5;
+ var sy = @as(f32, @floatFromInt(py)) + 0.5;
+ if (rot != 0) {
+ const dx = sx - cx;
+ const dy = sy - cy;
+ sx = cx + dx * cos_r - dy * sin_r;
+ sy = cy + dx * sin_r + dy * cos_r;
+ }
const cov = if (mask) |m|
m.sample((sx - left) / side * @as(f32, @floatFromInt(m.size)) - 0.5, (sy - top) / side * @as(f32, @floatFromInt(m.size)) - 0.5)
else