Skip to content

Instantly share code, notes, and snippets.

@Aayush9029
Created June 3, 2025 20:55
Show Gist options
  • Select an option

  • Save Aayush9029/75863e4f50805cfd866e1ca5a703a080 to your computer and use it in GitHub Desktop.

Select an option

Save Aayush9029/75863e4f50805cfd866e1ca5a703a080 to your computer and use it in GitHub Desktop.
NSWindow AppKit that is pretty
let windowStyles: NSWindow.StyleMask = [.titled, .utilityWindow, .hudWindow]
let windowRect = NSRect.init(x: 0, y: 0, width: 600, height: 400)
let window = NSPanel.init(contentRect: windowRect, styleMask: windowStyles, backing: .buffered, defer: true)
window.title = "Title"
window.titleVisibility = .hidden
window.titlebarAppearsTransparent = true
let view = NSView()
window.contentView = view
window.contentView?.wantsLayer = true
window.contentView?.layer?.cornerRadius = 0.0
window.contentView?.layer?.borderWidth = 0.0
window.isOpaque = false
window.alphaValue = 1.0
window.isMovableByWindowBackground = true
window.toolbarStyle = .automatic
window.animationBehavior = .utilityWindow
window.center()
window.makeKeyAndOrderFront(nil)
NSApp.activate(ignoringOtherApps: true)
@Aayush9029
Copy link
Author

let windowStyles: NSWindow.StyleMask = [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView]
let windowRect = NSRect.init(x: 0, y: 0, width: 600, height: 400)
let window = NSWindow.init(contentRect: windowRect, styleMask: windowStyles, backing: .buffered, defer: true)
window.title = "Title"
window.titleVisibility = .visible
window.titlebarAppearsTransparent = true
window.toolbar = NSToolbar.init(identifier: "toolbar")
window.toolbar?.showsBaselineSeparator = false
window.toolbar?.insertItem(withItemIdentifier: .print, at: 0)
window.toolbar?.insertItem(withItemIdentifier: .flexibleSpace, at: 0)
window.toolbar?.insertItem(withItemIdentifier: .showColors, at: 0)
window.toolbar?.insertItem(withItemIdentifier: .showFonts, at: 0)
let view = NSVisualEffectView()
view.blendingMode = .behindWindow
view.state = .active
window.contentView = view
window.contentView?.wantsLayer = true
window.contentView?.layer?.borderColor = .red
window.contentView?.layer?.cornerRadius = 0.0
window.contentView?.layer?.borderWidth = 0.0
window.alphaValue = 1.0
window.isMovableByWindowBackground = true
window.toolbarStyle = .automatic
window.animationBehavior = .utilityWindow
window.center()
window.makeKeyAndOrderFront(nil)
NSApp.activate(ignoringOtherApps: true)

CleanShot 2025-06-03 at 16 56 15@2x

@Aayush9029
Copy link
Author

let windowStyles: NSWindow.StyleMask = [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView]
let windowRect = NSRect.init(x: 0, y: 0, width: 600, height: 400)
let window = NSWindow.init(contentRect: windowRect, styleMask: windowStyles, backing: .buffered, defer: true)
window.title = "Title"
window.titleVisibility = .visible
window.titlebarAppearsTransparent = true
let view = NSVisualEffectView()
view.blendingMode = .behindWindow
view.state = .active
window.contentView = view
window.contentView?.wantsLayer = true
window.contentView?.layer?.borderColor = .red
window.contentView?.layer?.cornerRadius = 0.0
window.contentView?.layer?.borderWidth = 0.0
window.alphaValue = 1.0
window.isMovableByWindowBackground = true
window.toolbarStyle = .automatic
window.animationBehavior = .utilityWindow
window.center()
window.makeKeyAndOrderFront(nil)
NSApp.activate(ignoringOtherApps: true)

CleanShot 2025-06-03 at 16 56 54@2x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment