apprt/glfw: move darwin enabled const out to top-level

pull/6699/head
Mitchell Hashimoto 2025-03-12 12:45:30 -07:00
parent 18084a3e61
commit 1f6aa0e90d
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
1 changed files with 10 additions and 8 deletions

View File

@ -29,6 +29,10 @@ const glfwNative = glfw.Native(.{
.x11 = builtin.os.tag == .linux,
});
/// True if darwin-specific logic is enabled
const darwin_enabled = builtin.target.os.tag.isDarwin() and
build_config.artifact == .exe;
const log = std.log.scoped(.glfw);
pub const App = struct {
@ -40,7 +44,7 @@ pub const App = struct {
quit: bool = false,
/// Mac-specific state.
darwin: if (Darwin.enabled) Darwin else void,
darwin: if (darwin_enabled) Darwin else void,
pub const Options = struct {};
@ -66,8 +70,8 @@ pub const App = struct {
glfw.setErrorCallback(glfwErrorCallback);
// Mac-specific state. For example, on Mac we enable window tabbing.
var darwin = if (Darwin.enabled) try Darwin.init() else {};
errdefer if (Darwin.enabled) darwin.deinit();
var darwin = if (darwin_enabled) try Darwin.init() else {};
errdefer if (darwin_enabled) darwin.deinit();
// Load our configuration
var config = try Config.load(core_app.alloc);
@ -338,7 +342,7 @@ pub const App = struct {
/// Create a new tab in the parent surface.
fn newTab(self: *App, parent_: ?*CoreSurface) !void {
if (!Darwin.enabled) {
if (comptime !darwin_enabled) {
log.warn("tabbing is not supported on this platform", .{});
return;
}
@ -439,8 +443,6 @@ pub const App = struct {
/// Mac and the artifact is a standalone exe. We don't target libs because
/// the embedded API doesn't do windowing.
const Darwin = struct {
const enabled = builtin.target.os.tag.isDarwin() and build_config.artifact == .exe;
tabbing_id: *macos.foundation.String,
pub fn init() !Darwin {
@ -554,7 +556,7 @@ pub const Surface = struct {
}
// On Mac, enable window tabbing
if (App.Darwin.enabled) {
if (comptime darwin_enabled) {
const NSWindowTabbingMode = enum(usize) { automatic = 0, preferred = 1, disallowed = 2 };
const nswindow = objc.Object.fromId(glfwNative.getCocoaWindow(win).?);
@ -630,7 +632,7 @@ pub const Surface = struct {
// Clean up our core surface so that all the rendering and IO stop.
self.core_surface.deinit();
if (App.Darwin.enabled) {
if (comptime darwin_enabled) {
const nswindow = objc.Object.fromId(glfwNative.getCocoaWindow(self.window).?);
const tabgroup = nswindow.getProperty(objc.Object, "tabGroup");
const windows = tabgroup.getProperty(objc.Object, "windows");