mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-14 19:45:49 +00:00
renderer: keep a draw timer on when we have an inspector
This commit is contained in:
@@ -254,7 +254,7 @@ fn threadMain_(self: *Thread) !void {
|
||||
);
|
||||
|
||||
// Start the draw timer
|
||||
self.startDrawTimer();
|
||||
self.syncDrawTimer();
|
||||
|
||||
// Run
|
||||
log.debug("starting renderer thread", .{});
|
||||
@@ -292,11 +292,33 @@ fn setQosClass(self: *const Thread) void {
|
||||
}
|
||||
}
|
||||
|
||||
fn startDrawTimer(self: *Thread) void {
|
||||
// If our renderer doesn't support animations then we never run this.
|
||||
if (!@hasDecl(rendererpkg.Renderer, "hasAnimations")) return;
|
||||
if (!self.renderer.hasAnimations()) return;
|
||||
if (self.config.custom_shader_animation == .false) return;
|
||||
fn syncDrawTimer(self: *Thread) void {
|
||||
skip: {
|
||||
// If we have an inspector, we always run the draw timer.
|
||||
if (self.flags.has_inspector) break :skip;
|
||||
|
||||
// If our renderer supports animations and has them, then we
|
||||
// always have a draw timer.
|
||||
if (@hasDecl(rendererpkg.Renderer, "hasAnimations") and
|
||||
self.renderer.hasAnimations())
|
||||
{
|
||||
break :skip;
|
||||
}
|
||||
|
||||
// If our config says to always animate, we do so.
|
||||
switch (self.config.custom_shader_animation) {
|
||||
// Always animate
|
||||
.always => break :skip,
|
||||
// Only when focused
|
||||
.true => if (self.flags.focused) break :skip,
|
||||
// Never animate
|
||||
.false => {},
|
||||
}
|
||||
|
||||
// We're skipping the draw timer. Stop it on the next iteration.
|
||||
self.draw_active = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Set our active state so it knows we're running. We set this before
|
||||
// even checking the active state in case we have a pending shutdown.
|
||||
@@ -316,11 +338,6 @@ fn startDrawTimer(self: *Thread) void {
|
||||
);
|
||||
}
|
||||
|
||||
fn stopDrawTimer(self: *Thread) void {
|
||||
// This will stop the draw on the next iteration.
|
||||
self.draw_active = false;
|
||||
}
|
||||
|
||||
/// Drain the mailbox.
|
||||
fn drainMailbox(self: *Thread) !void {
|
||||
// There's probably a more elegant way to do this...
|
||||
@@ -377,12 +394,10 @@ fn drainMailbox(self: *Thread) !void {
|
||||
// Set it on the renderer
|
||||
try self.renderer.setFocus(v);
|
||||
|
||||
if (!v) {
|
||||
if (self.config.custom_shader_animation != .always) {
|
||||
// Stop the draw timer
|
||||
self.stopDrawTimer();
|
||||
}
|
||||
// We always resync our draw timer (may disable it)
|
||||
self.syncDrawTimer();
|
||||
|
||||
if (!v) {
|
||||
// If we're not focused, then we stop the cursor blink
|
||||
if (self.cursor_c.state() == .active and
|
||||
self.cursor_c_cancel.state() == .dead)
|
||||
@@ -397,9 +412,6 @@ fn drainMailbox(self: *Thread) !void {
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Start the draw timer
|
||||
self.startDrawTimer();
|
||||
|
||||
// If we're focused, we immediately show the cursor again
|
||||
// and then restart the timer.
|
||||
if (self.cursor_c.state() != .active) {
|
||||
@@ -446,8 +458,7 @@ fn drainMailbox(self: *Thread) !void {
|
||||
|
||||
// Stop and start the draw timer to capture the new
|
||||
// hasAnimations value.
|
||||
self.stopDrawTimer();
|
||||
self.startDrawTimer();
|
||||
self.syncDrawTimer();
|
||||
},
|
||||
|
||||
.search_viewport_matches => |v| {
|
||||
@@ -466,7 +477,12 @@ fn drainMailbox(self: *Thread) !void {
|
||||
self.renderer.search_matches_dirty = true;
|
||||
},
|
||||
|
||||
.inspector => |v| self.flags.has_inspector = v,
|
||||
.inspector => |v| {
|
||||
self.flags.has_inspector = v;
|
||||
// Reset our draw timer state, which might change due
|
||||
// to the inspector change.
|
||||
self.syncDrawTimer();
|
||||
},
|
||||
|
||||
.macos_display_id => |v| {
|
||||
if (@hasDecl(rendererpkg.Renderer, "setMacOSDisplayID")) {
|
||||
|
||||
Reference in New Issue
Block a user