diff --git a/CHANGELOG.md b/CHANGELOG.md index aaaca49c..d2bc6e40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Unreleased +- Added subclass to macos windows so they can be made resizable even with no decorations. + # Version 0.11.3 (2018-03-28) - Added `set_min_dimensions` and `set_max_dimensions` methods to `Window`, and implemented on Windows, X11, Wayland, and OSX. diff --git a/src/platform/macos/window.rs b/src/platform/macos/window.rs index c2476744..5937dee1 100644 --- a/src/platform/macos/window.rs +++ b/src/platform/macos/window.rs @@ -414,10 +414,7 @@ impl Window2 { NSWindowStyleMask::NSTitledWindowMask } else if !attrs.decorations { // Window2 without a titlebar - NSWindowStyleMask::NSClosableWindowMask | - NSWindowStyleMask::NSMiniaturizableWindowMask | - NSWindowStyleMask::NSResizableWindowMask | - NSWindowStyleMask::NSFullSizeContentViewWindowMask + NSWindowStyleMask::NSBorderlessWindowMask } else if pl_attrs.titlebar_hidden { NSWindowStyleMask::NSBorderlessWindowMask | NSWindowStyleMask::NSResizableWindowMask @@ -442,7 +439,18 @@ impl Window2 { NSWindowStyleMask::NSTitledWindowMask }; - let window = IdRef::new(NSWindow::alloc(nil).initWithContentRect_styleMask_backing_defer_( + let winit_window = Class::get("WinitWindow").unwrap_or_else(|| { + let window_superclass = Class::get("NSWindow").unwrap(); + let mut decl = ClassDecl::new("WinitWindow", window_superclass).unwrap(); + decl.add_method(sel!(canBecomeMainWindow), yes as extern fn(&Object, Sel) -> BOOL); + decl.add_method(sel!(canBecomeKeyWindow), yes as extern fn(&Object, Sel) -> BOOL); + decl.register(); + Class::get("WinitWindow").unwrap() + }); + + let window: id = msg_send![winit_window, alloc]; + + let window = IdRef::new(window.initWithContentRect_styleMask_backing_defer_( frame, masks, appkit::NSBackingStoreBuffered, @@ -796,3 +804,7 @@ impl Clone for IdRef { IdRef(self.0) } } + +extern fn yes(_: &Object, _: Sel) -> BOOL { + YES +}