Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git
river: wrap monotonic time > 2^32-1 milliseconds
(cherry picked from commit 6abcc68a198d0246077aaaed8af08db224f16775)
river/Cursor.zig | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/river/Cursor.zig b/river/Cursor.zig
index 8e542b1..e7b897c 100644
--- a/river/Cursor.zig
+++ b/river/Cursor.zig
@@ -705,10 +705,14 @@ pub fn updateState(cursor: *Cursor) void {
switch (cursor.mode) {
.passthrough, .drag => {
cursor.updateHovered();
-
- const now = posix.clock_gettime(posix.CLOCK.MONOTONIC) catch @panic("CLOCK_MONOTONIC not supported");
- const msec: u32 = @intCast(now.sec * std.time.ms_per_s +
- @divTrunc(now.nsec, std.time.ns_per_ms));
+ const now = posix.clock_gettime(.MONOTONIC) catch @panic("CLOCK_MONOTONIC not supported");
+ // 2^32-1 milliseconds is ~50 days, which is a realistic uptime.
+ // This means that we must wrap if the monotonic time is greater than
+ // 2^32-1 milliseconds and hope that clients don't get too confused.
+ const msec: u32 = @intCast(@rem(
+ now.sec *% std.time.ms_per_s +% @divTrunc(now.nsec, std.time.ns_per_ms),
+ math.maxInt(u32),
+ ));
cursor.passthrough(msec);
},
.ignore, .down, .op => {},