initial macos code
This commit is contained in:
parent
c75d075bc6
commit
951ba2a595
|
@ -4,7 +4,8 @@ version = "0.1.0"
|
|||
authors = [
|
||||
"William Light <git@wrl.lhiaudio.com>",
|
||||
"Charles Saracco <crsaracco@gmail.com>",
|
||||
"Mirko Covizzi <mrkcvzz@gmail.com>"
|
||||
"Mirko Covizzi <mrkcvzz@gmail.com>",
|
||||
"Micah Johnston <micah@glowcoil.com>",
|
||||
]
|
||||
edition = "2018"
|
||||
|
||||
|
@ -16,4 +17,6 @@ xcb = { version = "0.9", features = ["thread", "xlib_xcb", "dri2"] }
|
|||
[target.'cfg(target_os="windows")'.dependencies]
|
||||
winapi = { version = "0.3.8", features = ["libloaderapi", "winuser", "windef", "minwindef", "guiddef", "combaseapi"] }
|
||||
|
||||
# [target.'cfg(target_os="macos")'.dependencies]
|
||||
[target.'cfg(target_os="macos")'.dependencies]
|
||||
cocoa = "0.20.1"
|
||||
objc = "0.2.7"
|
||||
|
|
10
examples/macos.rs
Normal file
10
examples/macos.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
fn main() {
|
||||
let window_open_options = baseview::WindowOpenOptions {
|
||||
title: "baseview",
|
||||
width: 512,
|
||||
height: 512,
|
||||
parent: baseview::Parent::None,
|
||||
};
|
||||
|
||||
baseview::Window::open(window_open_options);
|
||||
}
|
|
@ -6,6 +6,9 @@ use std::ffi::c_void;
|
|||
|
||||
mod x11;
|
||||
|
||||
mod macos;
|
||||
pub use macos::Window;
|
||||
|
||||
pub enum Parent {
|
||||
None,
|
||||
AsIfParented,
|
||||
|
|
46
src/macos.rs
Normal file
46
src/macos.rs
Normal file
|
@ -0,0 +1,46 @@
|
|||
use cocoa::appkit::{
|
||||
NSApp, NSApplication, NSApplicationActivateIgnoringOtherApps,
|
||||
NSApplicationActivationPolicyRegular, NSBackingStoreBuffered, NSRunningApplication, NSView,
|
||||
NSWindow, NSWindowStyleMask,
|
||||
};
|
||||
use cocoa::base::{nil, NO};
|
||||
use cocoa::foundation::{NSAutoreleasePool, NSPoint, NSRect, NSSize, NSString};
|
||||
|
||||
use crate::WindowOpenOptions;
|
||||
|
||||
pub struct Window;
|
||||
|
||||
impl Window {
|
||||
pub fn open(options: WindowOpenOptions) {
|
||||
unsafe {
|
||||
let _pool = NSAutoreleasePool::new(nil);
|
||||
|
||||
let app = NSApp();
|
||||
app.setActivationPolicy_(NSApplicationActivationPolicyRegular);
|
||||
|
||||
let rect = NSRect::new(
|
||||
NSPoint::new(0.0, 0.0),
|
||||
NSSize::new(options.width as f64, options.height as f64),
|
||||
);
|
||||
|
||||
let window = NSWindow::alloc(nil)
|
||||
.initWithContentRect_styleMask_backing_defer_(
|
||||
rect,
|
||||
NSWindowStyleMask::NSTitledWindowMask,
|
||||
NSBackingStoreBuffered,
|
||||
NO,
|
||||
)
|
||||
.autorelease();
|
||||
window.center();
|
||||
window.setTitle_(NSString::alloc(nil).init_str(options.title));
|
||||
window.makeKeyAndOrderFront_(nil);
|
||||
|
||||
let view = NSView::alloc(nil).init();
|
||||
window.setContentView_(view);
|
||||
|
||||
let current_app = NSRunningApplication::currentApplication(nil);
|
||||
current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps);
|
||||
app.run();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue