Gieta Laksmana
  • Blog
  • Profile
  • Projects
    • VR World Arcade
    • Punch For Fun
    • Spectrum
    • Dimension Battle
  • Resume

NSWindow.level shenanigans

11/18/2016

1 Comment

 
lately I had to deal with window layering and ordering is Swift. I had to make sure some windows are always on top of other windows. This can be done with window levels.

in objective-c I found that you can simply call [NSWindow setLevel] with defined values such as NSMainMenuWindowLevel. in Swift, these defines doesnt exist. we have to use CGWindowLevelKey enum

However, this enum is not a value we can use directly for NSWindow.level. We have to convert it to a usable value 
by using CGWindowLevelForKey(), which returned an Int32. Since NSWindow.level is an Int, we also have to cast it to Int.
    window.level = Int(CGWindowLevelForKey(.normalWindow))

Here's the list of the values of CGWindowLevelKey sorted from bottom to top. At the time of this writing, these values are generated with Swift 3.0.1 and macOS 10.12 SDK
​

baseWindow: -2147483648
minimumWindow: -2147483643
desktopWindow: -2147483623
desktopIconWindow: -2147483603
backstopMenu: -20
normalWindow: 0
floatingWindow: 3
tornOffMenuWindow: 3
modalPanelWindow: 8
utilityWindow: 19
dockWindow: 20
mainMenuWindow: 24
statusWindow: 25
popUpMenuWindow: 101
overlayWindow: 102
helpWindow: 200
draggingWindow: 500
numberOfWindowLevelKeys: 999
screenSaverWindow: 1000
assistiveTechHighWindow: 1500
cursorWindow: 2147483630
maximumWindow: 2147483631

1 Comment
Chris
3/17/2019 06:09:07 am

Awesome post and exactly what I'm looking to implement right now. Doesn't look as though NSWindow.Level is an Int (any longer), though - any ideas how to shim some of these crazy values into its new, weird enum type?!

Reply



Leave a Reply.

    Archives

    September 2018
    August 2018
    July 2018
    September 2017
    July 2017
    November 2016
    October 2016
    September 2016
    June 2016
    May 2016
    March 2016

    Categories

    All
    Shenanigans
    Software Engineering
    Swift
    Vr
    Xcode

    RSS Feed

Powered by Create your own unique website with customizable templates.