Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/native/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,35 @@ impl Modifiers {
}
}
}

pub fn define_app_delegate() -> *const Class {
extern "C" fn application_did_update(this: &mut Object, _: Sel, _: ObjcId) {
unsafe {
let activated: bool = *this.get_ivar("activated");
if !activated {
this.set_ivar("activated", true);
let ns_app: ObjcId = msg_send![class!(NSRunningApplication), currentApplication];
let options =
NSApplicationActivationOptions::NSApplicationActivateIgnoringOtherApps;
msg_send_![ns_app, activateWithOptions: options];
}
}
}

let superclass = class!(NSObject);
let mut decl = ClassDecl::new("NSAppDelegate", superclass).unwrap();
unsafe {
decl.add_method(
sel!(applicationShouldTerminateAfterLastWindowClosed:),
yes1 as extern "C" fn(&Object, Sel, ObjcId) -> BOOL,
);
decl.add_method(
sel!(applicationDidUpdate:),
application_did_update as extern "C" fn(&mut Object, Sel, ObjcId),
);
}

decl.add_ivar::<bool>("activated");
decl.register()
}

Expand Down Expand Up @@ -1033,6 +1053,7 @@ where

let app_delegate_class = define_app_delegate();
let app_delegate_instance: ObjcId = msg_send![app_delegate_class, new];
(*app_delegate_instance).set_ivar("activated", false);

let ns_app: ObjcId = msg_send![class!(NSApplication), sharedApplication];
let () = msg_send![ns_app, setDelegate: app_delegate_instance];
Expand Down Expand Up @@ -1124,7 +1145,6 @@ where
}

msg_send_![window, orderFront: nil];
let () = msg_send![ns_app, activateIgnoringOtherApps: YES];
let () = msg_send![window, makeKeyAndOrderFront: nil];

let () = msg_send![ns_app, finishLaunching];
Expand Down
Loading