kettle11 / kapp

A pure Rust window and input library for Windows, Mac, and Web. (Work in progress)
Apache License 2.0
56 stars 4 forks source link

makeKeyAndOrderFront not working on Big Sur #45

Closed kettle11 closed 3 years ago

kettle11 commented 3 years ago

Launched windows remain behind all windows. Investigation is needed to figure out why.

Does this impact other windowing libraries?

kainjinez commented 3 years ago

I also experience the same but nothing found on the internet. Please update if you can find a solution for this. Thanks.

kettle11 commented 3 years ago

@kainjinez Thanks for letting me know that I'm not the only one! I'll update this issue if I find a fix.

kainjinez commented 3 years ago

Actually, I just found your issue not by using your app. My app is running in the background & users have to click an icon on taskbar. I'm using below code and it works for Catalina and older, not this Big Sur.

NSApp.windows.last?.makeKeyAndOrderFront(nil)
NSApp.activate(ignoringOtherApps: true)

I'll update here also if i find out any.

kettle11 commented 3 years ago

Fixed in 1f7a9b32e22ecf4bf7919beab5b3a43d047f635f

The key line was let () = msg_send![ns_application, activateIgnoringOtherApps:YES];

I believe this will make it so if the app takes a while to launch it will always steal focus at the end, even if the user has started using another app. This is acceptable for now, but isn't perfect.

kainjinez commented 3 years ago

Any solution for Swift? I also found an acceptable solution for my single screen app. I get all windows in NSApp and check if any is NSWindow then call makeKeyAndOrderFront() function.