RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
lock screen
oxydizera3f4a316bc85
diff --git a/src/osd.zig b/src/osd.zigindex 36ff631..0cbdaf9 100644--- a/src/osd.zig+++ b/src/osd.zig@@ -27,6 +27,17 @@ pub fn show(server: *Server, state: State) void {}pub fn showOn(server: *Server, output: *Output, state: State) void {+ if (server.locker) |lock| if (lock.greeter == null and lock.client == null) {+ switch (state.kind) {+ .volume, .brightness => {+ var outputs = server.outputs.iterator(.forward);+ while (outputs.next()) |other| other.osd.hide();+ lock.showControl(if (state.kind == .volume) .volume else .brightness);+ return;+ },+ else => {},+ }+ };var it = server.outputs.iterator(.forward);while (it.next()) |other| if (other != output) other.osd.hide();output.osd.present(output, state, true) catch |err| std.log.warn("OSD: {}", .{err});diff --git a/src/session/AGENTS.md b/src/session/AGENTS.mdindex 80b1267..2920daf 100644--- a/src/session/AGENTS.md+++ b/src/session/AGENTS.md@@ -17,4 +17,8 @@ ext-session-lock) are in the root `AGENTS.md`.raster (`View.controls_node`), so a drag never re-rasters the clock, avatarand field. A row exists only while its backend reports(`Lock.controlsChanged` from the audio wake and the brightness helper's- result); a drag shows its own value until release. Events only, no timer.+ result); a drag shows its own value until release. Only the row selected by+ pointer use or hardware feedback is painted; both pointer regions retain+ their positions. Hardware volume/brightness OSDs use `Lock.showControl`+ rather than drawing another overlay. Backend reports alone don't reveal+ controls. The clock timer also handles their idle timeout; no polling.diff --git a/src/session/lock.zig b/src/session/lock.zigindex 4d072c9..2f3848c 100644--- a/src/session/lock.zig+++ b/src/session/lock.zig@@ -368,19 +368,32 @@ pub const Lock = struct {const previous_brightness = self.controls.brightness;if (self.controls.refresh(self.server)) {self.server.scheduleFrames();- if (self.controls.volume != previous_volume or self.controls.muted != previous_muted or self.controls.brightness != previous_brightness) {- self.showControls();- }+ const active_changed = if (self.controls.active) |kind| switch (kind) {+ .volume => self.controls.volume != previous_volume or self.controls.muted != previous_muted,+ .brightness => self.controls.brightness != previous_brightness,+ } else false;+ if (self.controls_visible and active_changed) self.showControls(self.controls.active.?);}}- fn showControls(self: *Lock) void {+ /// Hardware feedback selects the same row as pointer use, including when+ /// a key leaves the value unchanged at its limit.+ pub fn showControl(self: *Lock, kind: lock_controls.Kind) void {+ if (self.greeter != null) return;+ if (self.controls.refresh(self.server)) self.server.scheduleFrames();+ self.showControls(kind);+ }++ fn showControls(self: *Lock, requested: lock_controls.Kind) void {if (self.greeter != null or self.controls.height() == 0) return;+ const kind = if (self.controls.drag) |drag| drag.kind else requested;+ const selected = self.controls.select(kind);+ if (self.controls.active != kind) return;const newly_visible = !self.controls_visible;self.controls_visible = true;self.controls_hide_at = anim.nowMs() + 2500;self.scheduleClock();- if (newly_visible) self.server.scheduleFrames();+ if (newly_visible or selected) self.server.scheduleFrames();}/// The control under a layout point, with its track's left edge and@@ -406,7 +419,7 @@ pub const Lock = struct {return;}const at = self.controlsAt(x, y);- if (at != null) self.showControls();+ if (at) |found| self.showControls(found.hit.kind);const hit: ?lock_controls.Hit = if (at) |found| found.hit else null;if (self.controls.setHover(hit)) self.server.scheduleFrames();}@@ -649,7 +662,7 @@ pub const Lock = struct {pub fn click(self: *Lock, x: f64, y: f64) void {if (self.controlsAt(x, y)) |at| {- self.showControls();+ self.showControls(at.hit.kind);switch (at.hit.part) {.icon => if (at.hit.kind == .volume) lock_controls.toggleMute(self.server),.track => self.controls.beginDrag(self.server, at.hit.kind, at.left, at.span, @floatCast(x)),@@ -1090,7 +1103,7 @@ test "lock raster scales to small outputs and renders a solid accent unlock buttvar lock = Lock{ .server = undefined, .timer = undefined, .controls_visible = true };@memcpy(lock.name[0..11], "Alex Morgan");@memcpy(lock.user[0..10], "alexmorgan");- lock.controls = .{ .has_volume = true, .volume = 0.5, .has_brightness = true, .brightness = 0.25 };+ lock.controls = .{ .has_volume = true, .volume = 0.5, .has_brightness = true, .brightness = 0.25, .active = .volume };const scene = try wlr.Scene.create();defer scene.tree.node.destroy();var view = try View.create(&scene.tree);diff --git a/src/session/lock_controls.zig b/src/session/lock_controls.zigindex 1e46bca..9e6db4a 100644--- a/src/session/lock_controls.zig+++ b/src/session/lock_controls.zig@@ -9,8 +9,9 @@//! row exists only while its backend reports one: no default sink, no//! backlight, no row. A drag shows its own value until release, then the//! backend's report takes over again.-//! The block is hidden at rest and appears on pointer use or a hardware value-//! change, then hides again after a short idle timeout.+//! The block is hidden at rest. Only the row used by the pointer or hardware+//! keys appears, then hides again after a short idle timeout. Both pointer+//! regions keep their positions so switching rows never moves a drag target.//!//! Everything here is in the block's design units (the lock's 600x900//! canvas) except the drag's track, which is kept in layout pixels so a drag@@ -48,6 +49,7 @@ pub const Controls = struct {has_volume: bool = false,brightness: f32 = 1,has_brightness: bool = false,+ active: ?Kind = null,hover: ?Kind = null,drag: ?Drag = null,/// Bumped by anything the block draws differently; `lock.View` compares.@@ -123,6 +125,13 @@ pub const Controls = struct {return true;}+ pub fn select(self: *Controls, kind: Kind) bool {+ if (self.slot(kind) == null or self.active == kind) return false;+ self.active = kind;+ self.revision +%= 1;+ return true;+ }+/// Starts dragging `kind`'s track, whose left edge and width are given/// in layout pixels, with the pointer at `x` (layout pixels).pub fn beginDrag(self: *Controls, server: *Server, kind: Kind, left: f32, span: f32, x: f32) void {@@ -164,6 +173,7 @@ pub const Controls = struct {pub fn paint(self: *const Controls, r: *ui.paint.Renderer) void {const t = r.palette orelse ui.theme.global;for ([_]Kind{ .volume, .brightness }) |kind| {+ if (self.active != kind) continue;const i = self.slot(kind) orelse continue;const top = rowY(i);const value = if (kind == .volume) self.volume else self.brightness;@@ -218,6 +228,7 @@ test "lock controls rows are compacted to the backends that exist" {var c = Controls{};try std.testing.expectEqual(@as(f32, 0), c.height());try std.testing.expectEqual(@as(?Hit, null), c.pick(60, 10));+ try std.testing.expect(!c.select(.volume));c.has_brightness = true;try std.testing.expectEqual(@as(f32, 32), c.height());try std.testing.expectEqual(Kind.brightness, c.pick(60, 10).?.kind);@@ -225,6 +236,24 @@ test "lock controls rows are compacted to the backends that exist" {try std.testing.expectEqual(@as(f32, 72), c.height());try std.testing.expectEqual(Kind.volume, c.pick(60, 10).?.kind);try std.testing.expectEqual(Kind.brightness, c.pick(60, 50).?.kind);++ // Reserve both pointer regions, but paint only the control being used.+ var pixels: [260 * 72]u32 = @splat(0);+ var renderer = ui.paint.Renderer.init(&pixels, 260, 72, 1);+ c.paint(&renderer);+ try std.testing.expect(std.mem.allEqual(u32, &pixels, 0));+ const before = c.revision;+ try std.testing.expect(c.select(.volume));+ try std.testing.expect(!c.select(.volume));+ try std.testing.expectEqual(before + 1, c.revision);+ c.paint(&renderer);+ try std.testing.expect(!std.mem.allEqual(u32, pixels[0 .. 260 * 32], 0));+ try std.testing.expect(std.mem.allEqual(u32, pixels[260 * 32 ..], 0));+ @memset(&pixels, 0);+ try std.testing.expect(c.select(.brightness));+ c.paint(&renderer);+ try std.testing.expect(std.mem.allEqual(u32, pixels[0 .. 260 * 40], 0));+ try std.testing.expect(!std.mem.allEqual(u32, pixels[260 * 40 ..], 0));}test "lock controls: the icon, the track and the gaps are told apart" {