GTK: propagate config updates to the GTK apprt surfaces (#5866)

This will be needed to the convert GTK apprt surfaces to a DerivedConfig
model rather than accessing the global config stored in the app. It's a
no-op for now, but I have a PR in the works to update the resize overlay
that will take advantage of this.
This commit is contained in:
Jeffrey C. Ollie
2025-02-22 17:19:13 -06:00
committed by GitHub
3 changed files with 21 additions and 0 deletions

View File

@ -914,6 +914,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

@ -704,6 +704,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

@ -32,6 +32,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
@ -109,6 +113,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,
@ -362,6 +367,13 @@ pub fn updateConfig(
self: *Window,
config: *const configpkg.Config,
) !void {
// avoid multiple reconfigs when we have many surfaces contained in this
// 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;
self.last_config = this_config;
self.config = DerivedConfig.init(config);
// We always resync our appearance whenever the config changes.