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

How to show modal window in AppKit #806

Open
onmyway133 opened this issue Jun 24, 2021 · 0 comments
Open

How to show modal window in AppKit #806

onmyway133 opened this issue Jun 24, 2021 · 0 comments

Comments

@onmyway133
Copy link
Owner

onmyway133 commented Jun 24, 2021

Use runModal

https://developer.apple.com/documentation/appkit/nsapplication/1428590-runmodalsession

Blocks main queue

A loop that uses this method is similar in some ways to a modal event loop run with runModal(for:), except with this method your code can do some additional work between method invocations. When you invoke this method, events for the NSWindow object of this session are dispatched as normal. This method returns when there are no more events. You must invoke this method frequently enough in your loop that the window remains responsive to events. However, you should not invoke this method in a tight loop because it returns immediately if there are no events, and consequently you could end up polling for events rather than blocking.

Use beginModalSession

https://developer.apple.com/documentation/appkit/nsapplication/1428418-beginmodalsession

In a modal session, the app receives mouse events only if they occur in aWindow. The window is made key, and if not already visible is placed onscreen using the NSWindow method center().

Need to call runModalSession and end with endModalSession

Use just NSWindow

Make key and order front regardless

let window = NSWindow(contentViewController: NSHostingController(rootView: view))
window.level = .floating
window.makeKeyAndOrderFront(nil)
window.orderFrontRegardless()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant