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.
This commit is contained in:
Mitchell Hashimoto
2025-10-03 06:53:29 -07:00
committed by GitHub

View File

@@ -697,6 +697,19 @@ pub const Window = extern struct {
var it = tree.iterator(); var it = tree.iterator();
while (it.next()) |entry| { while (it.next()) |entry| {
const surface = entry.view; 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.signals.@"present-request".connect(
surface, surface,
*Self, *Self,