gtk: forward config updates to GTK apprt surfaces

This commit is contained in:
Jeffrey C. Ollie
2025-02-18 23:18:47 -06:00
parent 38908e0126
commit d1fa933006
3 changed files with 21 additions and 0 deletions

View File

@ -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});

View File

@ -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 {

View File

@ -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.