diff --git a/src/apprt/gtk/class/application.zig b/src/apprt/gtk/class/application.zig index fa9b71eb7..667eeaf7c 100644 --- a/src/apprt/gtk/class/application.zig +++ b/src/apprt/gtk/class/application.zig @@ -1811,29 +1811,18 @@ pub const Application = extern struct { const t = glib.ext.VariantType.newFor(u64); defer glib.VariantType.free(t); - // Make sure that we've receiived a u64 from the system. + // Make sure that we've received a u64 from the system. if (glib.Variant.isOfType(parameter, t) == 0) { return; } - // Convert that u64 to pointer to a core surface. A value of zero - // means that there was no target surface for the notification so - // we don't focus any surface. - // - // This is admittedly SUPER SUS and we should instead do what we - // do on macOS which is generate a UUID per surface and then pass - // that around. But, we do validate the pointer below so at worst - // this may result in focusing the wrong surface if the pointer was - // reused for a surface. - const ptr_int = parameter.getUint64(); - if (ptr_int == 0) return; - const surface: *CoreSurface = @ptrFromInt(ptr_int); + // Convert the u64 to a core surface by using it as a surface ID. + // A value of zero means that there was no target surface for the + // notification so we don't focus any surface. + const surface_id = parameter.getUint64(); + if (surface_id == 0) return; + const surface = self.core().findSurfaceByID(surface_id) orelse return; - // Send a message through the core app mailbox rather than presenting the - // surface directly so that it can validate that the surface pointer is - // valid. We could get an invalid pointer if a desktop notification outlives - // a Ghostty instance and a new one starts up, or there are multiple Ghostty - // instances running. _ = self.core().mailbox.push( .{ .surface_message = .{ diff --git a/src/apprt/gtk/class/surface.zig b/src/apprt/gtk/class/surface.zig index f1e1c3907..d736a631d 100644 --- a/src/apprt/gtk/class/surface.zig +++ b/src/apprt/gtk/class/surface.zig @@ -1738,7 +1738,7 @@ pub const Surface = extern struct { defer icon.unref(); notification.setIcon(icon.as(gio.Icon)); - const pointer = glib.Variant.newUint64(@intFromPtr(core_surface)); + const pointer = glib.Variant.newUint64(core_surface.id); notification.setDefaultActionAndTargetValue( "app.present-surface", pointer,