Skip to content

Instantly share code, notes, and snippets.

@kotleni
Created October 19, 2022 20:03
Show Gist options
  • Save kotleni/3c61bcc7a797f539d3bd02cbf4b919ce to your computer and use it in GitHub Desktop.
Save kotleni/3c61bcc7a797f539d3bd02cbf4b919ce to your computer and use it in GitHub Desktop.
Kotlin AppKit usage example (MacOS)
import platform.AppKit.*
import platform.Foundation.NSMakeRect
import platform.Foundation.NSNotification
import platform.Foundation.NSRect
import platform.darwin.NSObject
fun main() {
val app = NSApplication.sharedApplication()
app.delegate = MyAppDelegate()
app.setActivationPolicy(NSApplicationActivationPolicy.NSApplicationActivationPolicyRegular)
app.activateIgnoringOtherApps(true)
app.run()
}
class MyAppDelegate(): NSObject(), NSApplicationDelegateProtocol {
private val window: NSWindow
init {
val rect = NSMakeRect(0.0, 0.0, 600.0, 400.0)
window = NSWindow(
contentRect = rect,
styleMask = NSWindowStyleMaskClosable,
backing = NSBackingStoreBuffered,
defer = false
)
window.title = "Window"
window.movableByWindowBackground = true
}
override fun applicationWillFinishLaunching(notification: NSNotification) {
window.makeKeyAndOrderFront(null)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment