8000 macos: add an option to launch in the background by benface · Pull Request #679 · not-fl3/miniquad · GitHub
[go: up one dir, main page]

Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ pub struct Platform {
/// Whether to automatically setup the panic hook for Android.
/// Set this to false if your app does its own panic_hook setup to avoid conflicts.
pub android_panic_hook: bool,

/// If `true`, on macOS the app starts without activating, showing no Dock icon and
/// leaving the menu bar alone, and its window opens behind other windows without
/// becoming key. Meant for windows nobody interacts with, such as one a tool only
/// screenshots.
pub macos_launch_in_background: bool,
}

impl Default for Platform {
Expand All @@ -197,6 +203,7 @@ impl Default for Platform {
wayland_decorations: WaylandDecorations::default(),
linux_wm_class: "miniquad-application",
android_panic_hook: true,
macos_launch_in_background: false,
}
}
}
Expand Down
23 changes: 15 additions & 8 deletions src/native/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1341,15 +1341,18 @@ 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 in_background = conf.platform.macos_launch_in_background;
// Starting out marked as activated skips the activation on the first update.
(*app_delegate_instance).set_ivar("activated", in_background);

let ns_app: ObjcId = msg_send![class!(NSApplication), sharedApplication];
let () = msg_send![ns_app, setDelegate: app_delegate_instance];
let () = msg_send![
ns_app,
setActivationPolicy: NSApplicationActivationPolicy::NSApplicationActivationPolicyRegular
as i64
];
let activation_policy = if in_background {
NSApplicationActivationPolicy::NSApplicationActivationPolicyAccessory
} else {
NSApplicationActivationPolicy::NSApplicationActivationPolicyRegular
};
let () = msg_send![ns_app, setActivationPolicy: activation_policy as i64];

if let Some(icon) = &conf.icon {
set_icon(ns_app, icon);
Expand Down Expand Up @@ -1437,8 +1440,12 @@ where
let () = msg_send![window, toggleFullScreen: nil];
}

msg_send_![window, orderFront: nil];
let () = msg_send![window, makeKeyAndOrderFront: nil];
if in_background {
msg_send_![window, orderBack: nil];
} else {
msg_send_![window, orderFront: nil];
let () = msg_send![window, makeKeyAndOrderFront: nil];
}

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

Expand Down
Loading
0