From f17b425aac518acd7cb7cbc500b862656631a4a8 Mon Sep 17 00:00:00 2001 From: Leah Amelia Chen Date: Wed, 5 Aug 2026 14:24:55 +0800 Subject: [PATCH] surface: use id instead of intFromPtr intFromPtr was always a hack that we had to use before we had stable surface IDs, and it was always slightly unsafe. Let's do it properly this time. --- src/App.zig | 4 ++-- src/Surface.zig | 2 +- src/apprt/gtk/class/command_palette.zig | 6 ++---- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/App.zig b/src/App.zig index c87867ea9..cf7316e8c 100644 --- a/src/App.zig +++ b/src/App.zig @@ -476,8 +476,8 @@ pub fn performAllAction( // are logged but processing continues. .surface => for (self.surfaces.items) |surface| { _ = surface.core().performBindingAction(action) catch |err| { - log.warn("error performing binding action on surface ptr={X} err={}", .{ - @intFromPtr(surface), + log.warn("error performing binding action on surface id={x} err={}", .{ + surface.core().id, err, }); }; diff --git a/src/Surface.zig b/src/Surface.zig index a28b5ec2d..e934dc191 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -841,7 +841,7 @@ pub fn deinit(self: *Surface) void { self.alloc.destroy(self.renderer_state.mutex); self.config.deinit(); - log.info("surface closed addr={x}", .{@intFromPtr(self)}); + log.info("surface closed id={x}", .{self.id}); } /// Close this surface. This will trigger the runtime to start the diff --git a/src/apprt/gtk/class/command_palette.zig b/src/apprt/gtk/class/command_palette.zig index 0d66bbe94..3ec7dfa0d 100644 --- a/src/apprt/gtk/class/command_palette.zig +++ b/src/apprt/gtk/class/command_palette.zig @@ -581,10 +581,8 @@ const Command = extern struct { const priv = self.private(); priv.data = .{ - .jump = .{ - // TODO: Replace with surface id whenever Ghostty adds one - .sort_key = @intFromPtr(surface), - }, + // Surface should be initialized at this point. + .jump = .{ .sort_key = surface.core().?.id }, }; priv.data.jump.surface.set(surface);