diff options
| author | Mitchell Hashimoto <mitchell.hashimoto@gmail.com> | 2024-01-09 09:21:15 -0800 |
|---|---|---|
| committer | Mitchell Hashimoto <mitchell.hashimoto@gmail.com> | 2024-01-09 09:21:15 -0800 |
| commit | 96d33fef20dbe2742ae718beccd6cc42719016ba (patch) | |
| tree | 53a91778fb3f92502658a67512704ccac3c1cad2 /src/renderer | |
| parent | 92697bad1240ac647b2bc7f471f87fb7f65f7305 (diff) | |
custom shader animation can be set to "always" to always remain active
Fixes #1225
The `custom-shader-animation` configuration can now be set to "always"
which keeps animation active even if the terminal is unfocused.
Diffstat (limited to 'src/renderer')
| -rw-r--r-- | src/renderer/Metal.zig | 5 | ||||
| -rw-r--r-- | src/renderer/OpenGL.zig | 4 | ||||
| -rw-r--r-- | src/renderer/Thread.zig | 32 | ||||
| -rw-r--r-- | src/renderer/message.zig | 36 |
4 files changed, 65 insertions, 12 deletions
diff --git a/src/renderer/Metal.zig b/src/renderer/Metal.zig index 9c17702e0..9e9fbaea4 100644 --- a/src/renderer/Metal.zig +++ b/src/renderer/Metal.zig @@ -155,7 +155,6 @@ pub const DerivedConfig = struct { invert_selection_fg_bg: bool, min_contrast: f32, custom_shaders: std.ArrayListUnmanaged([:0]const u8), - custom_shader_animation: bool, links: link.Set, pub fn init( @@ -218,7 +217,6 @@ pub const DerivedConfig = struct { null, .custom_shaders = custom_shaders, - .custom_shader_animation = config.@"custom-shader-animation", .links = links, .arena = arena, @@ -488,8 +486,7 @@ pub fn threadExit(self: *const Metal) void { /// True if our renderer has animations so that a higher frequency /// timer is used. pub fn hasAnimations(self: *const Metal) bool { - return self.custom_shader_state != null and - self.config.custom_shader_animation; + return self.custom_shader_state != null; } /// Returns the grid size for a given screen size. This is safe to call diff --git a/src/renderer/OpenGL.zig b/src/renderer/OpenGL.zig index 66fd966ee..af6910c0a 100644 --- a/src/renderer/OpenGL.zig +++ b/src/renderer/OpenGL.zig @@ -252,7 +252,6 @@ pub const DerivedConfig = struct { invert_selection_fg_bg: bool, min_contrast: f32, custom_shaders: std.ArrayListUnmanaged([:0]const u8), - custom_shader_animation: bool, links: link.Set, pub fn init( @@ -315,7 +314,6 @@ pub const DerivedConfig = struct { null, .custom_shaders = custom_shaders, - .custom_shader_animation = config.@"custom-shader-animation", .links = links, .arena = arena, @@ -558,7 +556,7 @@ pub fn threadExit(self: *const OpenGL) void { /// timer is used. pub fn hasAnimations(self: *const OpenGL) bool { const state = self.gl_state orelse return false; - return state.custom != null and self.config.custom_shader_animation; + return state.custom != null; } /// Callback when the focus changes for the terminal this is rendering. diff --git a/src/renderer/Thread.zig b/src/renderer/Thread.zig index 156d6cd6d..178dca14e 100644 --- a/src/renderer/Thread.zig +++ b/src/renderer/Thread.zig @@ -7,6 +7,7 @@ const builtin = @import("builtin"); const xev = @import("xev"); const renderer = @import("../renderer.zig"); const apprt = @import("../apprt.zig"); +const configpkg = @import("../config.zig"); const BlockingQueue = @import("../blocking_queue.zig").BlockingQueue; const tracy = @import("tracy"); const trace = tracy.trace; @@ -72,6 +73,9 @@ mailbox: *Mailbox, /// Mailbox to send messages to the app thread app_mailbox: App.Mailbox, +/// Configuration we need derived from the main config. +config: DerivedConfig, + flags: packed struct { /// This is true when a blinking cursor should be visible and false /// when it should not be visible. This is toggled on a timer by the @@ -82,11 +86,22 @@ flags: packed struct { has_inspector: bool = false, } = .{}, +pub const DerivedConfig = struct { + custom_shader_animation: configpkg.CustomShaderAnimation, + + pub fn init(config: *const configpkg.Config) DerivedConfig { + return .{ + .custom_shader_animation = config.@"custom-shader-animation", + }; + } +}; + /// Initialize the thread. This does not START the thread. This only sets /// up all the internal state necessary prior to starting the thread. It /// is up to the caller to start the thread with the threadMain entrypoint. pub fn init( alloc: Allocator, + config: *const configpkg.Config, surface: *apprt.Surface, renderer_impl: *renderer.Renderer, state: *renderer.State, @@ -122,6 +137,7 @@ pub fn init( return Thread{ .alloc = alloc, + .config = DerivedConfig.init(config), .loop = loop, .wakeup = wakeup_h, .stop = stop_h, @@ -199,6 +215,7 @@ fn startDrawTimer(self: *Thread) void { // If our renderer doesn't suppoort animations then we never run this. if (!@hasDecl(renderer.Renderer, "hasAnimations")) return; if (!self.renderer.hasAnimations()) return; + if (self.config.custom_shader_animation == .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. @@ -236,8 +253,10 @@ fn drainMailbox(self: *Thread) !void { try self.renderer.setFocus(v); if (!v) { - // Stop the draw timer - self.stopDrawTimer(); + if (self.config.custom_shader_animation != .always) { + // Stop the draw timer + self.stopDrawTimer(); + } // If we're not focused, then we stop the cursor blink if (self.cursor_c.state() == .active and @@ -308,8 +327,9 @@ fn drainMailbox(self: *Thread) !void { }, .change_config => |config| { - defer config.alloc.destroy(config.ptr); - try self.renderer.changeConfig(config.ptr); + defer message.deinit(); + try self.changeConfig(config.thread); + try self.renderer.changeConfig(config.impl); // Stop and start the draw timer to capture the new // hasAnimations value. @@ -322,6 +342,10 @@ fn drainMailbox(self: *Thread) !void { } } +fn changeConfig(self: *Thread, config: *const DerivedConfig) !void { + self.config = config.*; +} + fn wakeupCallback( self_: ?*Thread, _: *xev.Loop, diff --git a/src/renderer/message.zig b/src/renderer/message.zig index 3278a2c1c..73faa0ad7 100644 --- a/src/renderer/message.zig +++ b/src/renderer/message.zig @@ -1,6 +1,7 @@ const std = @import("std"); const assert = std.debug.assert; const Allocator = std.mem.Allocator; +const configpkg = @import("../config.zig"); const font = @import("../font/main.zig"); const renderer = @import("../renderer.zig"); const terminal = @import("../terminal/main.zig"); @@ -45,9 +46,42 @@ pub const Message = union(enum) { /// The derived configuration to update the renderer with. change_config: struct { alloc: Allocator, - ptr: *renderer.Renderer.DerivedConfig, + thread: *renderer.Thread.DerivedConfig, + impl: *renderer.Renderer.DerivedConfig, }, /// Activate or deactivate the inspector. inspector: bool, + + /// Initialize a change_config message. + pub fn initChangeConfig(alloc: Allocator, config: *const configpkg.Config) !Message { + const thread_ptr = try alloc.create(renderer.Thread.DerivedConfig); + errdefer alloc.destroy(thread_ptr); + const config_ptr = try alloc.create(renderer.Renderer.DerivedConfig); + errdefer alloc.destroy(config_ptr); + + thread_ptr.* = renderer.Thread.DerivedConfig.init(config); + config_ptr.* = try renderer.Renderer.DerivedConfig.init(alloc, config); + errdefer config_ptr.deinit(); + + return .{ + .change_config = .{ + .alloc = alloc, + .thread = thread_ptr, + .impl = config_ptr, + }, + }; + } + + pub fn deinit(self: *const Message) void { + switch (self.*) { + .change_config => |v| { + v.impl.deinit(); + v.alloc.destroy(v.impl); + v.alloc.destroy(v.thread); + }, + + else => {}, + } + } }; |
