From 360485faf2447f01f176777cd5829087b3c0c5f8 Mon Sep 17 00:00:00 2001 From: syke99 Date: Thu, 24 Sep 2026 11:55:53 -0500 Subject: [PATCH] fix tray backend on MacOS This revision fixes an issue where the Unix tray backend is compiled for MacOS builds, so creating a tray fails with "Could not load AppIndicator libraries" and no tray icon ever appears. Unlike tray/cocoa/SDL_tray.m (`#ifdef SDL_PLATFORM_MACOS`) and tray/dummy/SDL_tray.c (`#ifdef SDL_TRAY_DUMMY`), tray/unix/SDL_tray.c carries no platform guard, so it provides SDL_CreateTray unconditionally wherever it is listed. Listing it in the `unix` source group therefore makes it the implementation MacOS gets, and the cocoa backend was not listed in any group at all. This fix adds SDL_tray.m to the `cocoa` source group and adds a new `unix_tray` source group to contain the unix tray backend, mirroring the `unix_dialog` split in #32. Verified on MacOS: a real NSStatusItem appears in the menu bar, its menu entries fire their callbacks, and SDL_HasActiveTrays correctly suppresses the quit-on-last-window-close behaviour so an app can outlive its window. --- src/linux.zig | 2 +- src/sdl.zon | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/linux.zig b/src/linux.zig index ab9051554..1c73739eb 100644 --- a/src/linux.zig +++ b/src/linux.zig @@ -512,7 +512,7 @@ pub fn build( // Add the platform specific SDL sources lib.root_module.addCSourceFiles(.{ - .files = &(sources.unix ++ sources.unix_dialog ++ sources.linux ++ sources.x11 ++ sources.pthread), + .files = &(sources.unix ++ sources.unix_dialog ++ sources.unix_tray ++ sources.linux ++ sources.x11 ++ sources.pthread), .root = upstream.path("src"), .flags = root.flags, }); diff --git a/src/sdl.zon b/src/sdl.zon index 67421bf38..dc74d5b28 100644 --- a/src/sdl.zon +++ b/src/sdl.zon @@ -456,6 +456,7 @@ "filesystem/cocoa/SDL_sysfilesystem.m", "locale/macos/SDL_syslocale.m", "misc/macos/SDL_sysurl.m", + "tray/cocoa/SDL_tray.m", "video/cocoa/SDL_cocoaclipboard.m", "video/cocoa/SDL_cocoaevents.m", "video/cocoa/SDL_cocoakeyboard.m", @@ -572,6 +573,8 @@ "core/unix/SDL_poll.c", "locale/unix/SDL_syslocale.c", "misc/unix/SDL_sysurl.c", + }, + .unix_tray = .{ "tray/unix/SDL_tray.c", }, .unix_dialog = .{