From 1e5c17dffad25874210a1087387e119d91da1a2c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 28 Oct 2022 10:02:32 -0700 Subject: [PATCH] Comment to show native access --- pkg/objc/property.zig | 8 ++++++++ src/Window.zig | 47 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/pkg/objc/property.zig b/pkg/objc/property.zig index 110516b0e..9adcb3c20 100644 --- a/pkg/objc/property.zig +++ b/pkg/objc/property.zig @@ -9,6 +9,14 @@ pub const Property = extern struct { pub fn getName(self: Property) [:0]const u8 { return std.mem.sliceTo(c.property_getName(self.value), 0); } + + /// Returns the value of a property attribute given the attribute name. + pub fn copyAttributeValue(self: Property, attr: [:0]const u8) ?[:0]u8 { + return std.mem.sliceTo( + c.property_copyAttributeValue(self.value, attr.ptr) orelse return null, + 0, + ); + } }; test { diff --git a/src/Window.zig b/src/Window.zig index 6ec16425d..fa409771f 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -24,6 +24,11 @@ const Config = @import("config.zig").Config; const input = @import("input.zig"); const DevMode = @import("DevMode.zig"); +// Get native API access on certain platforms so we can do more customization. +const glfwNative = glfw.Native(.{ + .cocoa = builtin.os.tag == .macos, +}); + const log = std.log.scoped(.window); // The preallocation size for the write request pool. This should be big @@ -173,6 +178,48 @@ pub fn create(alloc: Allocator, loop: libuv.Loop, config: *const Config) !*Windo errdefer window.destroy(); try Renderer.windowInit(window); + // TEST + // if (builtin.os.tag == .macos) { + // const id = glfwNative.getCocoaWindow(window) orelse unreachable; + // const nswindow = objc.Object.fromId(id); + // const NSWindow = nswindow.getClass().?; + // + // { + // const prop = NSWindow.getProperty("titlebarAppearsTransparent").?; + // const setter = if (prop.copyAttributeValue("S")) |val| setter: { + // defer objc.free(val); + // break :setter objc.sel(val); + // } else objc.sel("setTitlebarAppearsTransparent:"); + // + // nswindow.msgSend(void, setter, .{true}); + // } + // + // { + // const NSColor = objc.Class.getClass("NSColor").?; + // const nscolor = NSColor.msgSend( + // objc.Object, + // objc.sel("colorWithSRGBRed:green:blue:alpha:"), + // .{ + // 1.0, + // 0.0, + // 0.0, + // // @intToFloat(f32, config.background.r) / 255.0, + // // @intToFloat(f32, config.background.g) / 255.0, + // // @intToFloat(f32, config.background.b) / 255.0, + // 1.0, + // }, + // ); + // + // const prop = NSWindow.getProperty("backgroundColor").?; + // const setter = if (prop.copyAttributeValue("S")) |val| setter: { + // defer objc.free(val); + // break :setter objc.sel(val); + // } else objc.sel("setBackgroundColor:"); + // + // nswindow.msgSend(void, setter, .{nscolor}); + // } + // } + // Determine our DPI configurations so we can properly configure // font points to pixels and handle other high-DPI scaling factors. const content_scale = try window.getContentScale();