From 4464e6ec1f22d5d3abbb11c9c76555bab8a33335 Mon Sep 17 00:00:00 2001 From: Micah Johnston Date: Sun, 6 Sep 2020 11:18:46 -0500 Subject: [PATCH] get macos building --- src/macos/window.rs | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/macos/window.rs b/src/macos/window.rs index 8cc8a71..ebc67d1 100644 --- a/src/macos/window.rs +++ b/src/macos/window.rs @@ -1,3 +1,6 @@ +use std::ffi::c_void; +use std::sync::mpsc; + use cocoa::appkit::{ NSApp, NSApplication, NSApplicationActivateIgnoringOtherApps, NSApplicationActivationPolicyRegular, NSBackingStoreBuffered, NSRunningApplication, NSView, @@ -6,19 +9,19 @@ use cocoa::appkit::{ use cocoa::base::{nil, NO}; use cocoa::foundation::{NSAutoreleasePool, NSPoint, NSRect, NSSize, NSString}; -use crate::{AppWindow, Event, MouseButtonID, MouseScroll, WindowOpenOptions}; +use raw_window_handle::{macos::MacOSHandle, HasRawWindowHandle, RawWindowHandle}; + +use crate::{ + AppWindow, Event, MouseButtonID, MouseScroll, RawWindow, WindowInfo, WindowOpenOptions, +}; pub struct Window { app_window: A, app_message_rx: mpsc::Receiver, } -impl Window { - pub fn open( - options: WindowOpenOptions, - app_window: A, - app_message_rx: mpsc::Receiver, - ) -> Self { +impl Window { + pub fn open(options: WindowOpenOptions, app_message_rx: mpsc::Receiver) -> Self { unsafe { let _pool = NSAutoreleasePool::new(nil); @@ -45,6 +48,22 @@ impl Window { let view = NSView::alloc(nil).init(); window.setContentView_(view); + let raw_window = RawWindow { + raw_window_handle: RawWindowHandle::MacOS(MacOSHandle { + ns_window: window as *mut c_void, + ns_view: app as *mut c_void, + ..raw_window_handle::macos::MacOSHandle::empty() + }), + }; + + let window_info = WindowInfo { + width: options.width as u32, + height: options.height as u32, + scale: 1.0, + }; + + let app_window = A::build(raw_window, &window_info); + let current_app = NSRunningApplication::currentApplication(nil); current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps); app.run();