From d1fa93300642cdf8f8ed5b4f759d3960982f267a Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Tue, 18 Feb 2025 23:18:47 -0600 Subject: [PATCH 1/2] gtk: forward config updates to GTK apprt surfaces --- src/apprt/gtk/App.zig | 3 +++ src/apprt/gtk/Surface.zig | 6 ++++++ src/apprt/gtk/Window.zig | 12 ++++++++++++ 3 files changed, 21 insertions(+) diff --git a/src/apprt/gtk/App.zig b/src/apprt/gtk/App.zig index 227c36ec4..ea3be6d5f 100644 --- a/src/apprt/gtk/App.zig +++ b/src/apprt/gtk/App.zig @@ -892,6 +892,9 @@ fn configChange( ) void { switch (target) { .surface => |surface| surface: { + surface.rt_surface.updateConfig(new_config) catch |err| { + log.err("unable to update surface config: {}", .{err}); + }; const window = surface.rt_surface.container.window() orelse break :surface; window.updateConfig(new_config) catch |err| { log.warn("error updating config for window err={}", .{err}); diff --git a/src/apprt/gtk/Surface.zig b/src/apprt/gtk/Surface.zig index 9a8c4513d..5cbba1ba1 100644 --- a/src/apprt/gtk/Surface.zig +++ b/src/apprt/gtk/Surface.zig @@ -682,6 +682,12 @@ pub fn deinit(self: *Surface) void { self.resize_overlay.deinit(); } +/// Update our local copy of any configuration that we use. +pub fn updateConfig(self: *Surface, config: *const configpkg.Config) !void { + _ = self; + _ = config; +} + // unref removes the long-held reference to the gl_area and kicks off the // deinit/destroy process for this surface. pub fn unref(self: *Surface) void { diff --git a/src/apprt/gtk/Window.zig b/src/apprt/gtk/Window.zig index 3b415435a..a0b9516c6 100644 --- a/src/apprt/gtk/Window.zig +++ b/src/apprt/gtk/Window.zig @@ -31,6 +31,10 @@ const log = std.log.scoped(.gtk); app: *App, +/// Used to deduplicate updateConfig invocations +last_config: usize, + +/// Local copy of any configuration config: DerivedConfig, /// Our window @@ -107,6 +111,7 @@ pub fn init(self: *Window, app: *App) !void { // Set up our own state self.* = .{ .app = app, + .last_config = @intFromPtr(&app.config), .config = DerivedConfig.init(&app.config), .window = undefined, .headerbar = undefined, @@ -355,6 +360,13 @@ pub fn updateConfig( self: *Window, config: *const configpkg.Config, ) !void { + // avoid multiple reconfigs when we have many surfaces contained in this + // surface using the integer value of config as a simple marker to know if + // we've "seen" this particular config before + const this_config = @intFromPtr(config); + if (self.last_config == this_config) return; + self.last_config = this_config; + self.config = DerivedConfig.init(config); // We always resync our appearance whenever the config changes. From 2697061e5b2d80fa5e8b65cc1966299886cb4b35 Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Tue, 18 Feb 2025 23:28:10 -0600 Subject: [PATCH 2/2] gtk: fix comment in Window.updateConfig --- src/apprt/gtk/Window.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apprt/gtk/Window.zig b/src/apprt/gtk/Window.zig index a0b9516c6..8a6ebc71c 100644 --- a/src/apprt/gtk/Window.zig +++ b/src/apprt/gtk/Window.zig @@ -361,7 +361,7 @@ pub fn updateConfig( config: *const configpkg.Config, ) !void { // avoid multiple reconfigs when we have many surfaces contained in this - // surface using the integer value of config as a simple marker to know if + // window using the integer value of config as a simple marker to know if // we've "seen" this particular config before const this_config = @intFromPtr(config); if (self.last_config == this_config) return;