Skip to content

fix dialog backend on MacOS - #32

Merged
MasonRemaley merged 1 commit into
allyourcodebase:mainfrom
nmacholl:nick/fix_macos_cocoa
Sep 17, 2026
Merged

MasonRemaley merged 1 commit into
allyourcodebase:mainfrom
nmacholl:nick/fix_macos_cocoa

Conversation

@nmacholl

Copy link
Copy Markdown

Overview
This revision fixes an issue where the Unix dialog backend is compiled for MacOS builds causing OS dialog windows to fail.

Here is an example error:
File dialog driver unsupported (supported values for SDL_HINT_FILE_DIALOG_DRIVER are 'zenity' and 'portal')

Resolution
This revision delivers two changes. First, SDL_cocoadialog.m is added to the cocoa source group and a new unix_dialog group is added containing the Unix dialog backends. Second, the unix_dialog group is added to the C source files in src/linux.zig to make the Linux build whole.

Verification
Verified with a small example program, which fails with the above error prior to this fix, but opens dialogs correctly after.

const std = @import("std");
const sdl = @import("sdl3");

var done: bool = false;

fn dialogCallback(
    userdata: ?*anyopaque,
    filelist: [*c]const [*c]const u8,
    filter: c_int,
) callconv(.c) void {
    _ = userdata;
    _ = filter;
    if (filelist == null) {
        std.debug.print("dialog failed: {s}\n", .{sdl.SDL_GetError()});
    } else if (filelist[0] == null) {
        std.debug.print("dialog canceled\n", .{});
    } else {
        std.debug.print("selected: {s}\n", .{filelist[0]});
    }
    done = true;
}

pub fn main() void {
    if (!sdl.SDL_Init(sdl.SDL_INIT_VIDEO)) {
        std.debug.panic("{s}", .{sdl.SDL_GetError()});
    }
    defer sdl.SDL_Quit();

    const window = sdl.SDL_CreateWindow("dialog example", 640, 480, 0) orelse {
        std.debug.panic("{s}", .{sdl.SDL_GetError()});
    };
    defer sdl.SDL_DestroyWindow(window);

    sdl.SDL_ShowOpenFileDialog(dialogCallback, null, window, null, 0, null, false);

    while (!done) {
        var event: sdl.SDL_Event = undefined;
        while (sdl.SDL_PollEvent(&event)) {
            if (event.type == sdl.SDL_EVENT_QUIT) return;
        }
        sdl.SDL_Delay(16);
    }
}

This revision fixes an issue where the Unix dialog
backend is compiled for MacOS builds causing OS
dialog windows to fail.

This fix adds SDL_cocoadialog.m to the `cocoa`
source group and adds a new `unix_dialog` source
group to contain the unix, portal, and zenity
dialog backends.
@nmacholl
nmacholl force-pushed the nick/fix_macos_cocoa branch from b6f84de to a432799 Compare September 17, 2026 03:53
@MasonRemaley

MasonRemaley commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the PR! I was tempted to suggest that we just move these files to .linux, but I guess these do work on other Unix systems. It looks like the way you've structured it matches the upstream CMakeLists.txt which is probably a good idea.

@MasonRemaley
MasonRemaley merged commit a526920 into allyourcodebase:main Sep 17, 2026
@nmacholl
nmacholl deleted the nick/fix_macos_cocoa branch September 18, 2026 00:34
@syke99 syke99 mentioned this pull request Sep 24, 2026
MasonRemaley pushed a commit that referenced this pull request Sep 24, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants