From a39aa7e89daf9eb734be631520b7d1e1c1b1f06e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 25 Nov 2024 15:12:14 -0800 Subject: [PATCH] apprt/gtk: only show config reload toast if app config changes This resolves the toast showing up every time the surface config changes which can be relatively frequent under certain circumstances such as theme changes. --- src/apprt/gtk/App.zig | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/apprt/gtk/App.zig b/src/apprt/gtk/App.zig index 0cee1938e..bb5309333 100644 --- a/src/apprt/gtk/App.zig +++ b/src/apprt/gtk/App.zig @@ -462,7 +462,7 @@ pub fn performAction( .equalize_splits => self.equalizeSplits(target), .goto_split => self.gotoSplit(target, value), .open_config => try configpkg.edit.open(self.core_app.alloc), - .config_change => self.configChange(value.config), + .config_change => self.configChange(target, value.config), .reload_config => try self.reloadConfig(target, value), .inspector => self.controlInspector(target, value), .desktop_notification => self.showDesktopNotification(target, value), @@ -818,18 +818,32 @@ fn showDesktopNotification( c.g_application_send_notification(g_app, n.body.ptr, notification); } -fn configChange(self: *App, new_config: *const Config) void { +fn configChange( + self: *App, + target: apprt.Target, + new_config: *const Config, +) void { _ = new_config; - self.syncConfigChanges() catch |err| { - log.warn("error handling configuration changes err={}", .{err}); - }; + switch (target) { + // We don't do anything for surface config change events. There + // is nothing to sync with regards to a surface today. + .surface => {}, - if (adwaita.enabled(&self.config)) { - if (self.core_app.focusedSurface()) |core_surface| { - const surface = core_surface.rt_surface; - if (surface.container.window()) |window| window.onConfigReloaded(); - } + .app => { + self.syncConfigChanges() catch |err| { + log.warn("error handling configuration changes err={}", .{err}); + }; + + // App changes needs to show a toast that our configuration + // has reloaded. + if (adwaita.enabled(&self.config)) { + if (self.core_app.focusedSurface()) |core_surface| { + const surface = core_surface.rt_surface; + if (surface.container.window()) |window| window.onConfigReloaded(); + } + } + }, } }