Skip to content

Commit 53522b8

Browse files
Glipticrockorager
authored andcommitted
fix: Realtime timers break during computer suspend. Inverted condition in checkTimers.
1 parent 0f46f49 commit 53522b8

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

src/vxfw/App.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub fn run(self: *App, widget: vxfw.Widget, opts: Options) anyerror!void {
9696
defer focus_handler.deinit(self.allocator);
9797

9898
// Timestamp of our next frame
99-
var next_frame = std.Io.Timestamp.now(self.io, .real);
99+
var next_frame = std.Io.Timestamp.now(self.io, .awake);
100100

101101
// Create our event context
102102
var ctx: vxfw.EventContext = .{
@@ -111,14 +111,14 @@ pub fn run(self: *App, widget: vxfw.Widget, opts: Options) anyerror!void {
111111
defer ctx.cmds.deinit(self.allocator);
112112

113113
while (true) {
114-
const now = std.Io.Timestamp.now(self.io, .real);
114+
const now = std.Io.Timestamp.now(self.io, .awake);
115115
const duration = now.durationTo(next_frame);
116116
if (duration.nanoseconds <= 0) {
117117
// Deadline exceeded. Schedule the next frame
118118
next_frame = now.addDuration(tick);
119119
} else {
120120
// Sleep until the deadline
121-
try self.io.sleep(duration, .real);
121+
try self.io.sleep(duration, .awake);
122122
next_frame = next_frame.addDuration(tick);
123123
}
124124

@@ -297,13 +297,13 @@ fn handleCommand(self: *App, cmds: *vxfw.CommandList) Allocator.Error!void {
297297
}
298298

299299
fn checkTimers(self: *App, ctx: *vxfw.EventContext) anyerror!void {
300-
const now: std.Io.Timestamp = .now(self.io, .real);
300+
const now: std.Io.Timestamp = .now(self.io, .awake);
301301

302302
// timers are always sorted descending
303303
while (self.timers.pop()) |tick| {
304304
const duration = now.durationTo(tick.deadline);
305-
if (duration.nanoseconds < 0) {
306-
// re-add the timer
305+
if (duration.nanoseconds > 0) {
306+
// re-add the timer as no more timers will trigger now
307307
try self.timers.append(self.allocator, tick);
308308
break;
309309
}

src/vxfw/vxfw.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub const Tick = struct {
6262
}
6363

6464
pub fn in(io: std.Io, ms: u32, widget: Widget) Command {
65-
const now: std.Io.Timestamp = .now(io, .real);
65+
const now: std.Io.Timestamp = .now(io, .awake);
6666
const deadline = now.addDuration(.fromMilliseconds(ms));
6767
return .{
6868
.tick = .{

0 commit comments

Comments
 (0)