RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
minimap fixes and blinking wifi icon
oxydizerb89088b3794f
diff --git a/src/Output.zig b/src/Output.zigindex b6b3780..2b1c123 100644--- a/src/Output.zig+++ b/src/Output.zig@@ -1274,6 +1274,7 @@ fn runFrame(output: *Output) void {return;};const projection_started = stats.nowNs();+ output.server.world.refreshBounds();output.server.world.syncPresentation();stats.global_stats.projection_cpu.record(stats.nowNs() -% projection_started);output.server.world.flushCameraEvent();@@ -1549,13 +1550,6 @@ pub fn recomputeWorldBounds(server: *Server) void {const h = max_y - min_y;server.world.initBounds(min_x, min_y, w, h);- // Expand bounds if necessary to retain existing window frames- var it_top = server.world.toplevels.iterator(.forward);- while (it_top.next()) |top| {- if (top.tab_hidden) continue;- server.world.ensureInBounds(top.x, top.y, top.chrome_width, top.chrome_height);- }-if (first) {// No remaining outputs: drop an in-progress pan rather than rebase it// against an empty layout.diff --git a/src/Taskbar.zig b/src/Taskbar.zigindex 1833eda..d1824e7 100644--- a/src/Taskbar.zig+++ b/src/Taskbar.zig@@ -195,6 +195,12 @@ audio_muted: bool = false,// NetworkManager reports no connection: the wifi icon is drawn in the danger// colour, like a muted speaker. Pushed by `network.Manager`, never polled.network_offline: bool = false,+// While offline the wifi icon also blinks (one cycle a second) so a dropped+// connection stands out. A real deadline only while offline: the timer is+// created on first need, disarmed on reconnect, and each tick repaints just+// that icon. Reduced motion keeps the icon solid.+blink_timer: ?*wl.EventSource = null,+blink_dim: bool = false,clock_time: [16]u8 = [_]u8{0} ** 16,clock_date: [128]u8 = [_]u8{0} ** 128,@@ -416,6 +422,7 @@ pub fn create(server: *Server, wlr_output: *wlr.Output) !*Taskbar {bar.updateClockLocale();_ = bar.updateClockStrings();bar.scheduleClockTick();+ bar.syncBlink();return bar;}@@ -423,6 +430,7 @@ pub fn destroy(bar: *Taskbar) void {if (bar.server.tray) |tray_mgr| tray_mgr.closeMenu();bar.server.input.detachTaskbar(bar);bar.timer.remove();+ if (bar.blink_timer) |timer| timer.remove();if (bar.clock_locale) |locale| c_time.freelocale(locale);if (bar.start_logo) |e| bar.server.iconRelease(e.id);for (bar.chips.items) |chip| {@@ -459,6 +467,45 @@ pub fn applyBattery(bar: *Taskbar, next: battery.State) void {pub fn applyNetwork(bar: *Taskbar, offline: bool) void {if (offline == bar.network_offline) return;bar.network_offline = offline;+ bar.blink_dim = false;+ bar.syncBlink();+ bar.tray_dirty[@intFromEnum(TrayKind.wifi)] = true;+ bar.markDirty(paint_tray);+ bar.wlr_output.scheduleFrame();+}++const blink_half_ms = 500;++/// Arm the blink timer while offline, disarm it otherwise.+fn syncBlink(bar: *Taskbar) void {+ if (bar.network_offline and !anim.reducedMotion()) {+ if (bar.blink_timer == null) {+ bar.blink_timer = bar.server.wl_server.getEventLoop().addTimer(*Taskbar, onBlink, bar) catch |err| {+ log.err("syncBlink: could not create blink timer: {}", .{err});+ return;+ };+ }+ bar.blink_timer.?.timerUpdate(blink_half_ms) catch {};+ } else if (bar.blink_timer) |timer| {+ timer.timerUpdate(0) catch {};+ }+}++fn onBlink(bar: *Taskbar) c_int {+ if (!bar.network_offline or anim.reducedMotion()) {+ // Settle on a solid icon; the timer stays disarmed.+ if (bar.blink_dim) bar.repaintWifi();+ bar.blink_dim = false;+ return 0;+ }+ bar.blink_dim = !bar.blink_dim;+ bar.repaintWifi();+ bar.blink_timer.?.timerUpdate(blink_half_ms) catch {};+ return 0;+}++fn repaintWifi(bar: *Taskbar) void {+ if (!bar.itemShown(.network)) return;bar.tray_dirty[@intFromEnum(TrayKind.wifi)] = true;bar.markDirty(paint_tray);bar.wlr_output.scheduleFrame();@@ -1629,9 +1676,11 @@ fn renderPart(bar: *Taskbar, now_ms: i64, part: Part, origin_x: i32, origin_y: i.volume => bar.audio_muted,.wifi => bar.network_offline,};- const color = if (alert)- Color.fromRgba(ui_theme.taskbar(.danger))- else+ const color = if (alert) blk: {+ var danger = Color.fromRgba(ui_theme.taskbar(.danger));+ if (@as(TrayKind, @enumFromInt(i)) == .wifi and bar.blink_dim) danger.a *= 0.25;+ break :blk danger;+ } elseColor.lerp(Color.tray_icon(), Color.tray_icon_hover(), hover);const size = 20 * press;var renderer = @import("ui").paint.Renderer.init(buf.pixels, buf.width, buf.height, scale);diff --git a/src/Toplevel.zig b/src/Toplevel.zigindex 7a2879c..88e2daa 100644--- a/src/Toplevel.zig+++ b/src/Toplevel.zig@@ -1422,7 +1422,7 @@ fn commitPosition(toplevel: *Toplevel, x: i32, y: i32, update_scene: bool) voidtoplevel.y = y;if (update_scene) toplevel.applyVisualTransform(nowMs());if (moved) toplevel.server.scheduleFrames();- toplevel.server.world.ensureInBounds(x, y, toplevel.chrome_width, toplevel.chrome_height);+ toplevel.server.world.ensureToplevelInBounds(toplevel);if (moved) {if (!toplevel.isResizing() and !toplevel.backend_gone) {switch (toplevel.backend) {@@ -2024,7 +2024,7 @@ pub fn tickZoom(toplevel: *Toplevel, now_ms: i64) bool {const moved = toplevel.x != round_x or toplevel.y != round_y;toplevel.x = round_x;toplevel.y = round_y;- if (moved) toplevel.server.world.ensureInBounds(round_x, round_y, toplevel.chrome_width, toplevel.chrome_height);+ if (moved) toplevel.server.world.ensureToplevelInBounds(toplevel);return true;}}diff --git a/src/World.zig b/src/World.zigindex e384b2f..8bbf4ad 100644--- a/src/World.zig+++ b/src/World.zig@@ -328,7 +328,68 @@ pub fn destroyClosing(world: *World) void {/// Compute and store camera bounds from the combined output layout rectangle.pub fn initBounds(world: *World, layout_x: i32, layout_y: i32, layout_w: i32, layout_h: i32) void {- world.bounds = camera_mod.computeGridBounds(layout_x, layout_y, layout_w, layout_h, world.server.config.compositor.canvas_columns, world.server.config.compositor.canvas_rows);+ world.bounds = world.derivedBounds(layout_x, layout_y, layout_w, layout_h);+}++/// The configured grid, grown just enough to keep every resting window+/// reachable. A pure function of the layout, the config and the windows, so+/// the reachable area (and the mini-map drawn from it) never depends on where+/// a window happened to pass through.+fn derivedBounds(world: *World, layout_x: i32, layout_y: i32, layout_w: i32, layout_h: i32) camera_mod.Bounds {+ const cfg = world.server.config.compositor;+ var bounds = camera_mod.computeGridBounds(layout_x, layout_y, layout_w, layout_h, cfg.canvas_columns, cfg.canvas_rows);+ if (world.workspaces.active) return bounds;+ var it = world.toplevels.iterator(.forward);+ while (it.next()) |top| {+ if (top.tab_hidden or top.closing or top.backend_gone or !top.in_world) continue;+ expandForToplevel(&bounds, top);+ }+ return bounds;+}++/// Frames are measured at the window's own zoom, not the temporary focus boost.+fn expandForToplevel(bounds: *camera_mod.Bounds, top: *const Toplevel) void {+ const w: i32 = @intFromFloat(@ceil(@as(f64, @floatFromInt(top.chrome_width)) * top.zoom_scale));+ const h: i32 = @intFromFloat(@ceil(@as(f64, @floatFromInt(top.chrome_height)) * top.zoom_scale));+ camera_mod.expandToFrame(+ bounds,+ top.x,+ top.y,+ w,+ h,+ @intFromFloat(@round(bounds.origin_x)),+ @intFromFloat(@round(bounds.origin_y)),+ @intFromFloat(@round(bounds.width)),+ @intFromFloat(@round(bounds.height)),+ );+}++/// Re-derive the bounds from the current windows, once per frame. Bounds+/// shrink again when a window comes back or goes away; a camera left beyond+/// the new limits glides back. During a move or resize grab they only grow, so+/// the canvas doesn't pull in under the pointer.+pub fn refreshBounds(world: *World) void {+ if (world.workspaces.active or world.bounds.width <= 0 or world.bounds.height <= 0) return;+ const old = world.bounds;+ var next = world.derivedBounds(@intFromFloat(@round(old.origin_x)), @intFromFloat(@round(old.origin_y)), @intFromFloat(@round(old.width)), @intFromFloat(@round(old.height)));+ const input = &world.server.input;+ if (input.cursor_mode == .move or input.cursor_mode == .resize) {+ next.max_x = @max(next.max_x, old.max_x);+ next.max_y = @max(next.max_y, old.max_y);+ }+ if (std.meta.eql(next, old)) return;+ world.bounds = next;+ var clamped = world.camera;+ clamped.clamp(next);+ if (!world.allowsOverscroll() and (clamped.offset_x != world.camera.offset_x or clamped.offset_y != world.camera.offset_y)) {+ world.springPan(clamped.offset_x, clamped.offset_y, .camera_reveal);+ }+}++/// Keep `toplevel` reachable right away, between per-frame refreshes.+pub fn ensureToplevelInBounds(world: *World, toplevel: *const Toplevel) void {+ if (world.workspaces.active) return;+ expandForToplevel(&world.bounds, toplevel);}/// Project the world without changing source nodes or client geometry.@@ -408,6 +469,8 @@ pub fn revealIfOffscreen(world: *World, toplevel: *Toplevel, output: *@import("O}fn windowFocusOffset(world: *World, toplevel: *Toplevel, output: *@import("Output.zig"), cam: camera_mod.Camera, scale: f64, force: bool) ?camera_mod.Vec {+ // A restored or just-placed window may not be in the last frame's bounds.+ world.ensureToplevelInBounds(toplevel);const usable = output.usableBox();return camera_mod.focusOffset(cam, world.bounds, .{ .x = @floatFromInt(toplevel.x), .y = @floatFromInt(toplevel.y) }, .{ .x = @as(f64, @floatFromInt(toplevel.chrome_width)) * scale, .y = @as(f64, @floatFromInt(toplevel.chrome_height)) * scale }, .{ .x = @floatFromInt(usable.x), .y = @floatFromInt(usable.y) }, .{ .x = @floatFromInt(usable.width), .y = @floatFromInt(usable.height) }, force);}@@ -444,22 +507,6 @@ pub fn refreshFocusZoom(world: *World) void {world.server.scheduleFrames();}-/// Expand camera bounds if necessary so that the frame at (wx, wy) with size (w, h)-/// remains reachable through camera movement.-///-/// Uses the current layout rectangle in `world.bounds` rather than looking up a-/// live output. Output destroy runs while the dying output is still in the-/// layout, so a cursor-based lookup can return a wrapper that has already been-/// freed.-pub fn ensureInBounds(world: *World, wx: i32, wy: i32, w: i32, h: i32) void {- if (world.workspaces.active) return;- const ux: i32 = @intFromFloat(@round(world.bounds.origin_x));- const uy: i32 = @intFromFloat(@round(world.bounds.origin_y));- const uw: i32 = @intFromFloat(@round(world.bounds.width));- const uh: i32 = @intFromFloat(@round(world.bounds.height));- camera_mod.expandToFrame(&world.bounds, wx, wy, w, h, ux, uy, uw, uh);-}-/// Scroll the camera to bring `toplevel`'s frame into the output's usable area./// `output` is used for the usable-area box.pub fn reveal(diff --git a/src/mini_map.zig b/src/mini_map.zigindex bb0f072..78ede9d 100644--- a/src/mini_map.zig+++ b/src/mini_map.zig@@ -202,7 +202,7 @@ pub fn tick(self: *Self, output: *Output, now: i64) bool {}const cfg = server.config.compositor;const world = &server.world;- const map = geo.Map.init(world.bounds, world.camera.zoom(), @min(220, @as(f64, @floatFromInt(usable.width - 32))), @min(140, @as(f64, @floatFromInt(usable.height - 32))));+ const map = geo.Map.init(world.bounds, @min(220, @as(f64, @floatFromInt(usable.width - 32))), @min(140, @as(f64, @floatFromInt(usable.height - 32))));const theme = ui.theme.shellPalette();const key: Cache = .{ .map = map, .bounds = world.bounds, .columns = cfg.canvas_columns, .rows = cfg.canvas_rows, .scale = output.wlr_output.scale, .bg = theme.window_bg, .fg = theme.window_fg, .bg_opacity = theme.mini_map_bg_opacity, .grid_alpha = theme.mini_map_grid_alpha, .border_alpha = theme.mini_map_border_alpha, .radius = theme.mini_map_radius };if (self.cache == null or !std.meta.eql(self.cache.?, key)) {diff --git a/src/mini_map_geometry.zig b/src/mini_map_geometry.zigindex 9fe5810..637e084 100644--- a/src/mini_map_geometry.zig+++ b/src/mini_map_geometry.zig@@ -16,9 +16,11 @@ pub const Map = struct {width: f64,height: f64,scale: f64,- pub fn init(bounds: camera.Bounds, zoom: f64, max_w: f64, max_h: f64) Map {- const w = @max(bounds.width + 2 * bounds.max_x, bounds.width / zoom);- const h = @max(bounds.height + 2 * bounds.max_y, bounds.height / zoom);+ /// The map is the reachable canvas and nothing else: zooming out never+ /// pads it (the viewport marker is clipped to the map instead).+ pub fn init(bounds: camera.Bounds, max_w: f64, max_h: f64) Map {+ const w = bounds.width + 2 * bounds.max_x;+ const h = bounds.height + 2 * bounds.max_y;const scale = @min(max_w / @max(1, w), max_h / @max(1, h));return .{ .world = .{ .x = bounds.origin_x + (bounds.width - w) / 2, .y = bounds.origin_y + (bounds.height - h) / 2, .w = w, .h = h }, .width = w * scale, .height = h * scale, .scale = scale };}@@ -46,7 +48,7 @@ test "map drag round trips at negative origins and fractional zoom" {const b = camera.computeGridBounds(-1920, -200, 3200, 1080, 4, 2);const out: Rect = .{ .x = -1920, .y = -200, .w = 1920, .h = 1080 };const cam: camera.Camera = .{ .offset_x = 123, .offset_y = -321, .zoom_value = 0.85 };- const m = Map.init(b, cam.zoom(), 220, 140);+ const m = Map.init(b, 220, 140);const v = m.viewport(cam, b, out);const anchor: camera.Vec = .{ .x = v.w / 3, .y = v.h / 4 };const same = m.drag(cam, b, out, v.x + anchor.x, v.y + anchor.y, anchor);@@ -60,21 +62,27 @@ test "map drag round trips at negative origins and fractional zoom" {try std.testing.expectEqual(limits.lo_y, clamped.offset_y);}-test "map fits odd even narrow and expanded canvases and large viewports" {+test "map fits odd even narrow and expanded canvases, and ignores zoom" {for ([_]u32{ 1, 2, 3, 10 }) |cols| {var b = camera.computeGridBounds(0, 0, 1280, 720, cols, 1);for ([_]f64{ 0.25, 0.85, 1, 2 }) |z| {- const m = Map.init(b, z, 220, 140);+ const m = Map.init(b, 220, 140);try std.testing.expect(m.width <= 220.000001 and m.height <= 140.000001);+ try std.testing.expectEqual(b.width + 2 * b.max_x, m.world.w);+ try std.testing.expectEqual(b.height, m.world.h);var cam: camera.Camera = .{ .zoom_value = z };cam.clamp(b);const v = m.viewport(cam, b, .{ .x = 0, .y = 0, .w = 1280, .h = 720 });- try std.testing.expect(v.x >= -0.000001 and v.y >= -0.000001);- try std.testing.expect(v.x + v.w <= m.width + 0.000001);- try std.testing.expect(v.y + v.h <= m.height + 0.000001);+ // At 100% or closer the viewport lies inside the map; zoomed out it+ // may be larger and is clipped by the painter.+ if (z >= 1) {+ try std.testing.expect(v.x >= -0.000001 and v.y >= -0.000001);+ try std.testing.expect(v.x + v.w <= m.width + 0.000001);+ try std.testing.expect(v.y + v.h <= m.height + 0.000001);+ }}b.max_x += 5000;- const m = Map.init(b, 1, 220, 140);+ const m = Map.init(b, 220, 140);try std.testing.expectEqual(b.width + 2 * b.max_x, m.world.w);}}diff --git a/tests/wifi_popup.py b/tests/wifi_popup.pyindex 0550e1e..4d5a023 100644--- a/tests/wifi_popup.py+++ b/tests/wifi_popup.py@@ -199,61 +199,28 @@ def run(scale):with Image.open(target) as image:icon=image.convert('RGB').crop((round(box['x']*raster),round(box['y']*raster),round((box['x']+box['width'])*raster),round((box['y']+box['height'])*raster)))return any(red > green+60 and red > blue+60 for red,green,blue in icon.getdata())+ def tray_phases(seconds=2.0):+ # Offline, the icon blinks once a second: sample both phases.+ seen, end = set(), time.monotonic() + seconds+ while time.monotonic() < end and len(seen) < 2:+ seen.add(tray_red())+ time.sleep(.1)+ return seen# The tray icon follows NetworkManager's global state with no popup open:# red only while nothing is connected, never while connecting.assert not tray_red(), 'connected: the wifi icon is red'- command(global_state=20);assert tray_red(), 'disconnected: the wifi icon is not red'+ command(global_state=20);phases=tray_phases();assert True in phases, 'disconnected: the wifi icon is not red'+ assert phases == {True, False}, 'disconnected: the wifi icon does not blink'command(global_state=40);assert not tray_red(), 'connecting: the wifi icon is red'- command(global_state=10);assert tray_red(), 'asleep: the wifi icon is not red'+ time.sleep(1.2);assert not tray_red(), 'connecting: the wifi icon still blinks'+ command(global_state=10);assert True in tray_phases(), 'asleep: the wifi icon is not red'command(global_state=70);assert not tray_red(), 'reconnected: the wifi icon is still red'open_menu()wait_for(lambda: ipc.hit_test(*at(100,100)).get('widget')=='row','network rows')- def sonar_image():- x,y=at(262,3)- raster=float(scale)- target=tmp/'sonar.png'- target.unlink(missing_ok=True)- ipc.screenshot(str(target))- with Image.open(target) as image:- return image.convert('RGB').crop((round(x*raster),round(y*raster),round((x+60*factor)*raster),round((y+60*factor)*raster)))- def sonar_pixels(): return list(sonar_image().getdata())- def has_sonar():- return any(red > green+35 for red,green,blue in sonar_pixels())- assert has_sonar(), 'scan acceptance hid the sonar before completion'- first=sonar_pixels()- time.sleep(.2) # sample a different sweep phase- assert sonar_pixels()!=first, 'sonar sweep did not animate'screenshot('searching')command(hold_scan=False, complete_scan=True)- def sonar_settled():- first = sonar_pixels()- time.sleep(.15)- return sonar_pixels() == first- wait_for(sonar_settled, 'scan completion stops sweep')- assert has_sonar(), 'completed scan lost its signal map'assert ipc.hit_test(*at(100,100)).get('widget')=='row', 'search hid existing networks'screenshot('list')- # A real signal update moves the same echo radially; the centre- # beacon and faint rings are excluded from this pixel check.- def echo_distance():- image = sonar_image()- distances = []- for y in range(image.height):- for x in range(image.width):- red, green, blue = image.getpixel((x,y))- distance = ((x+.5-image.width/2)**2+(y+.5-image.height/2)**2)**.5 / (float(scale)*factor)- if red > green+120 and distance > 5:- distances.append(distance)- assert distances, 'network echo missing'- return sum(distances)/len(distances)- command(count=1, strength=10)- weak = echo_distance()- command(strength=95)- assert echo_distance() < weak-8, 'stronger signal did not move towards centre'- command(count=6, strength=None)- strongest = sonar_pixels()- command(count=35, active=35)- assert sonar_pixels() == strongest, 'weaker networks changed the six strongest echoes'command(count=6, active=1)# Opening focuses the first network: Down/Enter opens the# second (saved, secured) network without toggling the radio.@@ -294,7 +261,6 @@ def run(scale):click(369,36)assert read_line(fake)=={'enabled':False}settle();screenshot('off')- assert not has_sonar(), 'disabled radio still shows a signal map'# With no network list, opening still focuses the radio toggle.close();open_menu();ipc.key_down_up(28)assert read_line(fake)=={'enabled':True}