How does windowing system work on MacOS? [closed]

Solution 1:

Macs have their own windowing system called AppKit which is not based on X11. You can certainly install X11 and use it but it's not how most Mac apps work. Creating a window from the ground up with no frameworks is going to take some work, and is maybe better suited for Stack Overflow. Even there though, this is such a rare need that you might have trouble getting an answer.

If you want to get into the real low-level details of making things work, resources exist, though you can no doubt Google as well as me. One good starting point might be the New OSX Book site.

A simple example with minimal framework code might look like this:

import Foundation
import AppKit

let aWindow = NSWindow(
    contentRect: NSMakeRect(0, 0, 400, 210), 
    styleMask: [.titled, .closable], 
    backing: .buffered, 
    defer: false)
aWindow.makeKeyAndOrderFront(nil)

RunLoop.current.run()