mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-11 21:31:29 +11:00
Merge pull request #209 from bjz/osx-window
Remove unnecessary inner method in OSX window constructor
This commit is contained in:
commit
0d114c72b3
|
@ -32,9 +32,9 @@ fn main() {
|
||||||
run(window3, (1.0, 0.0, 0.0, 1.0));
|
run(window3, (1.0, 0.0, 0.0, 1.0));
|
||||||
});
|
});
|
||||||
|
|
||||||
t1.join();
|
let _ = t1.join();
|
||||||
t2.join();
|
let _ = t2.join();
|
||||||
t3.join();
|
let _ = t3.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "window")]
|
#[cfg(feature = "window")]
|
||||||
|
|
|
@ -64,17 +64,6 @@ pub struct Window {
|
||||||
is_closed: Cell<bool>,
|
is_closed: Cell<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "window")]
|
|
||||||
impl Window {
|
|
||||||
pub fn new(builder: BuilderAttribs) -> Result<Window, CreationError> {
|
|
||||||
if builder.sharing.is_some() {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
Window::new_impl(builder.dimensions, builder.title.as_slice(), builder.monitor, builder.vsync, builder.visible, builder.gl_version)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "window")]
|
#[cfg(feature = "window")]
|
||||||
unsafe impl Send for Window {}
|
unsafe impl Send for Window {}
|
||||||
#[cfg(feature = "window")]
|
#[cfg(feature = "window")]
|
||||||
|
@ -137,13 +126,20 @@ extern fn window_did_resize(this: id, _: id) -> id {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
fn new_impl(dimensions: Option<(u32, u32)>, title: &str, monitor: Option<MonitorID>,
|
#[cfg(feature = "window")]
|
||||||
vsync: bool, visible: bool, gl_version: Option<(u32, u32)>) -> Result<Window, CreationError> {
|
pub fn new(builder: BuilderAttribs) -> Result<Window, CreationError> {
|
||||||
|
if builder.sharing.is_some() {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
let app = match Window::create_app() {
|
let app = match Window::create_app() {
|
||||||
Some(app) => app,
|
Some(app) => app,
|
||||||
None => { return Err(OsError(format!("Couldn't create NSApplication"))); },
|
None => { return Err(OsError(format!("Couldn't create NSApplication"))); },
|
||||||
};
|
};
|
||||||
let window = match Window::create_window(dimensions.unwrap_or((800, 600)), title, monitor) {
|
let window = match Window::create_window(builder.dimensions.unwrap_or((800, 600)),
|
||||||
|
&*builder.title,
|
||||||
|
builder.monitor)
|
||||||
|
{
|
||||||
Some(window) => window,
|
Some(window) => window,
|
||||||
None => { return Err(OsError(format!("Couldn't create NSWindow"))); },
|
None => { return Err(OsError(format!("Couldn't create NSWindow"))); },
|
||||||
};
|
};
|
||||||
|
@ -152,14 +148,14 @@ impl Window {
|
||||||
None => { return Err(OsError(format!("Couldn't create NSView"))); },
|
None => { return Err(OsError(format!("Couldn't create NSView"))); },
|
||||||
};
|
};
|
||||||
|
|
||||||
let context = match Window::create_context(view, vsync, gl_version) {
|
let context = match Window::create_context(view, builder.vsync, builder.gl_version) {
|
||||||
Some(context) => context,
|
Some(context) => context,
|
||||||
None => { return Err(OsError(format!("Couldn't create OpenGL context"))); },
|
None => { return Err(OsError(format!("Couldn't create OpenGL context"))); },
|
||||||
};
|
};
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
app.activateIgnoringOtherApps_(true);
|
app.activateIgnoringOtherApps_(true);
|
||||||
if visible {
|
if builder.visible {
|
||||||
window.makeKeyAndOrderFront_(nil);
|
window.makeKeyAndOrderFront_(nil);
|
||||||
} else {
|
} else {
|
||||||
window.makeKeyWindow();
|
window.makeKeyWindow();
|
||||||
|
@ -212,27 +208,25 @@ impl Window {
|
||||||
|
|
||||||
fn create_window(dimensions: (u32, u32), title: &str, monitor: Option<MonitorID>) -> Option<id> {
|
fn create_window(dimensions: (u32, u32), title: &str, monitor: Option<MonitorID>) -> Option<id> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let scr_frame = match monitor {
|
let frame = if monitor.is_some() {
|
||||||
Some(_) => {
|
|
||||||
let screen = NSScreen::mainScreen(nil);
|
let screen = NSScreen::mainScreen(nil);
|
||||||
NSScreen::frame(screen)
|
NSScreen::frame(screen)
|
||||||
}
|
} else {
|
||||||
None => {
|
|
||||||
let (width, height) = dimensions;
|
let (width, height) = dimensions;
|
||||||
NSRect::new(NSPoint::new(0., 0.), NSSize::new(width as f64, height as f64))
|
NSRect::new(NSPoint::new(0., 0.), NSSize::new(width as f64, height as f64))
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let masks = match monitor {
|
let masks = if monitor.is_some() {
|
||||||
Some(_) => NSBorderlessWindowMask as NSUInteger,
|
NSBorderlessWindowMask as NSUInteger
|
||||||
None => NSTitledWindowMask as NSUInteger |
|
} else {
|
||||||
|
NSTitledWindowMask as NSUInteger |
|
||||||
NSClosableWindowMask as NSUInteger |
|
NSClosableWindowMask as NSUInteger |
|
||||||
NSMiniaturizableWindowMask as NSUInteger |
|
NSMiniaturizableWindowMask as NSUInteger |
|
||||||
NSResizableWindowMask as NSUInteger,
|
NSResizableWindowMask as NSUInteger
|
||||||
};
|
};
|
||||||
|
|
||||||
let window = NSWindow::alloc(nil).initWithContentRect_styleMask_backing_defer_(
|
let window = NSWindow::alloc(nil).initWithContentRect_styleMask_backing_defer_(
|
||||||
scr_frame,
|
frame,
|
||||||
masks,
|
masks,
|
||||||
NSBackingStoreBuffered,
|
NSBackingStoreBuffered,
|
||||||
false,
|
false,
|
||||||
|
|
Loading…
Reference in a new issue