From 8a14f213252fca606e2ceaef4d5598fb40c91db2 Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Sun, 24 Aug 2025 12:00:20 -0500 Subject: [PATCH] gtk-ng: fix setting/unsetting of urgency - Don't set urgency on windows that are the topmost window. - Turn off urgency on windows that become the topmost window. Fixes #8373 --- src/apprt/gtk-ng/class/window.zig | 24 ++++++++++++++++++++++-- src/apprt/gtk-ng/ui/1.5/window.blp | 1 + 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/apprt/gtk-ng/class/window.zig b/src/apprt/gtk-ng/class/window.zig index 30fa43dae..117fac540 100644 --- a/src/apprt/gtk-ng/class/window.zig +++ b/src/apprt/gtk-ng/class/window.zig @@ -987,6 +987,22 @@ pub const Window = extern struct { }; } + fn propIsActive( + _: *gtk.Window, + _: *gobject.ParamSpec, + self: *Self, + ) callconv(.c) void { + // Don't change urgency if we're not the active window. + if (self.as(gtk.Window).isActive() == 0) return; + + self.winproto().setUrgent(false) catch |err| { + log.warn( + "winproto failed to reset urgency={}", + .{err}, + ); + }; + } + fn propGdkSurfaceWidth( _: *gdk.Surface, _: *gobject.ParamSpec, @@ -1765,10 +1781,13 @@ pub const Window = extern struct { native.beep(); } - if (config.@"bell-features".attention) { + if (config.@"bell-features".attention) attention: { + // Dont set urgency if the window is already active. + if (self.as(gtk.Window).isActive() != 0) break :attention; + // Request user attention self.winproto().setUrgent(true) catch |err| { - log.warn("failed to request user attention={}", .{err}); + log.warn("winproto failed to set urgency={}", .{err}); }; } } @@ -1912,6 +1931,7 @@ pub const Window = extern struct { class.bindTemplateCallback("notify_selected_page", &tabViewSelectedPage); class.bindTemplateCallback("notify_config", &propConfig); class.bindTemplateCallback("notify_fullscreened", &propFullscreened); + class.bindTemplateCallback("notify_is_active", &propIsActive); class.bindTemplateCallback("notify_maximized", &propMaximized); class.bindTemplateCallback("notify_menu_active", &propMenuActive); class.bindTemplateCallback("notify_quick_terminal", &propQuickTerminal); diff --git a/src/apprt/gtk-ng/ui/1.5/window.blp b/src/apprt/gtk-ng/ui/1.5/window.blp index b09c0d9b3..a63da6792 100644 --- a/src/apprt/gtk-ng/ui/1.5/window.blp +++ b/src/apprt/gtk-ng/ui/1.5/window.blp @@ -10,6 +10,7 @@ template $GhosttyWindow: Adw.ApplicationWindow { realize => $realize(); notify::config => $notify_config(); notify::fullscreened => $notify_fullscreened(); + notify::is-active => $notify_is_active(); notify::maximized => $notify_maximized(); notify::quick-terminal => $notify_quick_terminal(); notify::scale-factor => $notify_scale_factor();