Improve quit timers.

Instead of "polling" to see if a quit timer has expired, start a single
timer that expires after the confiugred delay when no more surfaces are
open. That timer can be cancelled if necessary.
This commit is contained in:
Jeffrey C. Ollie
2024-08-01 14:49:02 -05:00
parent 3d6ca14dc6
commit ec0f90d1b6
3 changed files with 62 additions and 41 deletions

View File

@@ -134,6 +134,8 @@ pub fn updateConfig(self: *App, config: *const Config) !void {
/// The surface must be from the pool.
pub fn addSurface(self: *App, rt_surface: *apprt.Surface) !void {
try self.surfaces.append(self.alloc, rt_surface);
if (@hasDecl(apprt.App, "cancelQuitTimer")) rt_surface.app.cancelQuitTimer();
}
/// Delete the surface from the known surface list. This will NOT call the
@@ -158,6 +160,8 @@ pub fn deleteSurface(self: *App, rt_surface: *apprt.Surface) void {
i += 1;
}
if (@hasDecl(apprt.App, "startQuitTimer") and self.surfaces.items.len == 0) rt_surface.app.startQuitTimer();
}
/// The last focused surface. This is only valid while on the main thread