mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-25 14:51:30 +11:00
honor the passed-in MonitorID when using with_fullscreen() in cocoa backend
This commit is contained in:
parent
9914d826b8
commit
70776fab41
|
@ -8,6 +8,7 @@ use libc;
|
||||||
use Api;
|
use Api;
|
||||||
use BuilderAttribs;
|
use BuilderAttribs;
|
||||||
use GlRequest;
|
use GlRequest;
|
||||||
|
use NativeMonitorID;
|
||||||
|
|
||||||
use cocoa::base::{Class, id, YES, NO, NSUInteger, nil, objc_allocateClassPair, class, objc_registerClassPair};
|
use cocoa::base::{Class, id, YES, NO, NSUInteger, nil, objc_allocateClassPair, class, objc_registerClassPair};
|
||||||
use cocoa::base::{selector, msg_send, msg_send_stret, class_addMethod, class_addIvar};
|
use cocoa::base::{selector, msg_send, msg_send_stret, class_addMethod, class_addIvar};
|
||||||
|
@ -406,15 +407,41 @@ impl Window {
|
||||||
|
|
||||||
fn create_window(dimensions: (u32, u32), title: &str, monitor: Option<MonitorID>) -> Option<IdRef> {
|
fn create_window(dimensions: (u32, u32), title: &str, monitor: Option<MonitorID>) -> Option<IdRef> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let frame = if monitor.is_some() {
|
let screen = monitor.map(|monitor_id| {
|
||||||
let screen = NSScreen::mainScreen(nil);
|
let native_id = match monitor_id.get_native_identifier() {
|
||||||
NSScreen::frame(screen)
|
NativeMonitorID::Numeric(num) => num,
|
||||||
} else {
|
_ => panic!("OS X monitors should always have a numeric native ID")
|
||||||
|
};
|
||||||
|
let matching_screen = {
|
||||||
|
let screens = NSScreen::screens(nil);
|
||||||
|
let count: NSUInteger = msg_send()(screens, selector("count"));
|
||||||
|
let key = IdRef::new(NSString::alloc(nil).init_str("NSScreenNumber"));
|
||||||
|
let mut matching_screen: Option<id> = None;
|
||||||
|
for i in range(0, count) {
|
||||||
|
let screen = msg_send()(screens, selector("objectAtIndex:"), i as NSUInteger);
|
||||||
|
let device_description = NSScreen::deviceDescription(screen);
|
||||||
|
let value = msg_send()(device_description, selector("objectForKey:"), *key);
|
||||||
|
if value != nil {
|
||||||
|
let screen_number: NSUInteger = msg_send()(value, selector("unsignedIntValue"));
|
||||||
|
if screen_number as u32 == native_id {
|
||||||
|
matching_screen = Some(screen);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
matching_screen
|
||||||
|
};
|
||||||
|
matching_screen.unwrap_or(NSScreen::mainScreen(nil))
|
||||||
|
});
|
||||||
|
let frame = match screen {
|
||||||
|
Some(screen) => NSScreen::frame(screen),
|
||||||
|
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 = if monitor.is_some() {
|
let masks = if screen.is_some() {
|
||||||
NSBorderlessWindowMask as NSUInteger
|
NSBorderlessWindowMask as NSUInteger
|
||||||
} else {
|
} else {
|
||||||
NSTitledWindowMask as NSUInteger |
|
NSTitledWindowMask as NSUInteger |
|
||||||
|
@ -436,7 +463,7 @@ impl Window {
|
||||||
let title = IdRef::new(NSString::alloc(nil).init_str(title));
|
let title = IdRef::new(NSString::alloc(nil).init_str(title));
|
||||||
window.setTitle_(*title);
|
window.setTitle_(*title);
|
||||||
window.setAcceptsMouseMovedEvents_(YES);
|
window.setAcceptsMouseMovedEvents_(YES);
|
||||||
if monitor.is_some() {
|
if screen.is_some() {
|
||||||
window.setLevel_(NSMainMenuWindowLevel as i64 + 1);
|
window.setLevel_(NSMainMenuWindowLevel as i64 + 1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Reference in a new issue