Comment to show native access

This commit is contained in:
Mitchell Hashimoto
2022-10-28 10:02:32 -07:00
parent 71042b6f1b
commit 1e5c17dffa
2 changed files with 55 additions and 0 deletions

View File

@ -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 {

View File

@ -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();