mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-24 22:31:30 +11:00
Merge pull request #103 from DavidPartouche/cocoa_fullscreen
Added fullscreen support to osx
This commit is contained in:
commit
bb200a73f0
10
Cargo.toml
10
Cargo.toml
|
@ -24,14 +24,8 @@ git = "https://github.com/DavidPartouche/rust-cocoa"
|
|||
[target.x86_64-apple-darwin.dependencies.cocoa]
|
||||
git = "https://github.com/DavidPartouche/rust-cocoa"
|
||||
|
||||
[target.i686-apple-darwin.dependencies.core_foundation]
|
||||
git = "https://github.com/DavidPartouche/rust-core-foundation"
|
||||
|
||||
[target.x86_64-apple-darwin.dependencies.core_foundation]
|
||||
git = "https://github.com/DavidPartouche/rust-core-foundation"
|
||||
|
||||
[target.i686-apple-darwin.dependencies.core_graphics]
|
||||
git = "https://github.com/DavidPartouche/rust-core-graphics"
|
||||
git = "https://github.com/servo/rust-core-graphics"
|
||||
|
||||
[target.x86_64-apple-darwin.dependencies.core_graphics]
|
||||
git = "https://github.com/DavidPartouche/rust-core-graphics"
|
||||
git = "https://github.com/servo/rust-core-graphics"
|
||||
|
|
|
@ -49,25 +49,25 @@ impl Deref<Window> for HeadlessContext {
|
|||
#[cfg(feature = "window")]
|
||||
impl Window {
|
||||
pub fn new(builder: WindowBuilder) -> Result<Window, CreationError> {
|
||||
Window::new_impl(builder.dimensions, builder.title.as_slice(), true)
|
||||
Window::new_impl(builder.dimensions, builder.title.as_slice(), builder.monitor, true)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "headless")]
|
||||
impl HeadlessContext {
|
||||
pub fn new(builder: HeadlessRendererBuilder) -> Result<HeadlessContext, CreationError> {
|
||||
Window::new_impl(Some(builder.dimensions), "", false)
|
||||
Window::new_impl(Some(builder.dimensions), "", None, false)
|
||||
.map(|w| HeadlessContext(w))
|
||||
}
|
||||
}
|
||||
|
||||
impl Window {
|
||||
fn new_impl(dimensions: Option<(uint, uint)>, title: &str, visible: bool) -> Result<Window, CreationError> {
|
||||
fn new_impl(dimensions: Option<(uint, uint)>, title: &str, monitor: Option<MonitorID>, visible: bool) -> Result<Window, CreationError> {
|
||||
let app = match Window::create_app() {
|
||||
Some(app) => app,
|
||||
None => { return Err(OsError(format!("Couldn't create NSApplication"))); },
|
||||
};
|
||||
let window = match Window::create_window(dimensions.unwrap_or((800, 600)), title) {
|
||||
let window = match Window::create_window(dimensions.unwrap_or((800, 600)), title, monitor) {
|
||||
Some(window) => window,
|
||||
None => { return Err(OsError(format!("Couldn't create NSWindow"))); },
|
||||
};
|
||||
|
@ -108,16 +108,26 @@ impl Window {
|
|||
}
|
||||
}
|
||||
|
||||
fn create_window(dimensions: (uint, uint), title: &str) -> Option<id> {
|
||||
fn create_window(dimensions: (uint, uint), title: &str, monitor: Option<MonitorID>) -> Option<id> {
|
||||
unsafe {
|
||||
let (width, height) = dimensions;
|
||||
let scr_frame = NSRect::new(NSPoint::new(0., 0.), NSSize::new(width as f64, height as f64));
|
||||
let scr_frame = match monitor {
|
||||
Some(_) => NSScreen::mainScreen(nil).frame(),
|
||||
None => {
|
||||
let (width, height) = dimensions;
|
||||
NSRect::new(NSPoint::new(0., 0.), NSSize::new(width as f64, height as f64))
|
||||
}
|
||||
};
|
||||
|
||||
let masks = match monitor {
|
||||
Some(_) => NSBorderlessWindowMask as NSUInteger,
|
||||
None => NSTitledWindowMask as NSUInteger | NSClosableWindowMask as NSUInteger | NSMiniaturizableWindowMask as NSUInteger,
|
||||
};
|
||||
|
||||
let window = NSWindow::alloc(nil).initWithContentRect_styleMask_backing_defer_(
|
||||
scr_frame,
|
||||
NSTitledWindowMask as NSUInteger | NSClosableWindowMask as NSUInteger | NSMiniaturizableWindowMask as NSUInteger,
|
||||
masks,
|
||||
NSBackingStoreBuffered,
|
||||
false
|
||||
false,
|
||||
);
|
||||
|
||||
if window == nil {
|
||||
|
@ -127,6 +137,9 @@ impl Window {
|
|||
window.setTitle_(title);
|
||||
window.center();
|
||||
window.setAcceptsMouseMovedEvents_(true);
|
||||
if monitor.is_some() {
|
||||
window.setLevel_(NSMainMenuWindowLevel as i64 + 1);
|
||||
}
|
||||
Some(window)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue