From 24f883904d4e3d54a10a25c2d053eeb47fe6f14f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 3 Oct 2025 06:53:29 -0700 Subject: [PATCH] gtk: fix duplicate signal handlers (#9001) Signal handlers are connected to surface objects in two spots - when a tab is added to a page and when the split tree changes. This resulted in duplicate signal handlers being added for each surface. This was most noticeable when copying the selection to the clipboard - you would see two "Copied to clipboard" toasts. Ensure that there is only one signal handler by removing any old ones before adding the new ones. --- src/apprt/gtk/class/window.zig | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/apprt/gtk/class/window.zig b/src/apprt/gtk/class/window.zig index c0dd6ab1f..8efff8729 100644 --- a/src/apprt/gtk/class/window.zig +++ b/src/apprt/gtk/class/window.zig @@ -697,6 +697,19 @@ pub const Window = extern struct { var it = tree.iterator(); while (it.next()) |entry| { const surface = entry.view; + // Before adding any new signal handlers, disconnect any that we may + // have added before. Otherwise we may get multiple handlers for the + // same signal. + _ = gobject.signalHandlersDisconnectMatched( + surface.as(gobject.Object), + .{ .data = true }, + 0, + 0, + null, + null, + self, + ); + _ = Surface.signals.@"present-request".connect( surface, *Self,