Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subclass windows in macos so they can be made resizable even with no decorations #408

Merged
2 changes: 2 additions & 0 deletions examples/window.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
extern crate winit;
use winit::os::macos::WindowBuilderExt;

fn main() {
let mut events_loop = winit::EventsLoop::new();

let _window = winit::WindowBuilder::new()
.with_title("A fantastic window!")
.with_decorations(false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we want that in the example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, that was just from my testing, I've removed it

.build(&events_loop)
.unwrap();

Expand Down
19 changes: 15 additions & 4 deletions src/platform/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,19 @@ impl Window2 {
NSWindowStyleMask::NSResizableWindowMask | NSWindowStyleMask::NSTitledWindowMask
} else {
// Window2 without a titlebar
NSWindowStyleMask::NSClosableWindowMask | NSWindowStyleMask::NSMiniaturizableWindowMask |
NSWindowStyleMask::NSResizableWindowMask |
NSWindowStyleMask::NSFullSizeContentViewWindowMask
NSWindowStyleMask::NSBorderlessWindowMask |
NSWindowStyleMask::NSResizableWindowMask
};

let window = IdRef::new(NSWindow::alloc(nil).initWithContentRect_styleMask_backing_defer_(
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();

let window: id = msg_send![Class::get("WinitWindow").unwrap(), alloc];

let window = IdRef::new(window.initWithContentRect_styleMask_backing_defer_(
frame,
masks,
appkit::NSBackingStoreBuffered,
Expand Down Expand Up @@ -760,3 +767,7 @@ impl Clone for IdRef {
IdRef(self.0)
}
}

extern fn yes(_: &Object, _: Sel) -> BOOL {
YES
}