From 5ac0d2d072494b36bdb825765de2e6a41fec001a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benoi=CC=82t=20Rouleau?= Date: Fri, 9 Oct 2026 16:40:52 -0400 Subject: [PATCH] macos: add an option to launch in the background A macOS app always came to the front: `run` set the regular activation policy, which gives the app a Dock icon and the menu bar, ordered its window front and made it key, and `application_did_update` activated the app on its first update, ignoring other apps. An app that only renders off-screen, or that a tool launches only to screenshot its window, took the user's focus each time it ran. `Platform::macos_launch_in_background` keeps it out of the way: the app gets the accessory activation policy, so no Dock icon and no menu bar, it skips the first-update activation, and its window goes to the back without becoming key. The window stays on screen, so it keeps drawing and can still be captured with `screencapture -l`. Co-Authored-By: Claude Opus 5.5 Co-authored-by: multica-agent --- src/conf.rs | 7 +++++++ src/native/macos.rs | 23 +++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/conf.rs b/src/conf.rs index 13cdc7541..ca54337e4 100644 --- a/src/conf.rs +++ b/src/conf.rs @@ -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 { @@ -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, } } } diff --git a/src/native/macos.rs b/src/native/macos.rs index b8d01fdef..426d0f4f2 100644 --- a/src/native/macos.rs +++ b/src/native/macos.rs @@ -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); @@ -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];