The CGWindowLevel.h
file defines the constants that are used to set the window level and the largest value that can be used as window level is 20. But, if you retrieve the window list using the call CGWindowListCopyWindowInfo
, you can observe that the value of kCGWindowLayer
is more than 20 (25, 103 etc).
Aren't kCGWindowLayer and window level same?
If they are not same, how do I get the window level for the windows that are obtained using CGWindowListCopyWindowInfo
?
If they are same, why do we get value >20?
No. kCGWindowLayer and window level are not same. You cannot get window level directly. But you can do a trick as below.
It appears that
kCGWindowLayer
does refer to a window level, though I haven't found any documentation saying that.You seem to think that window levels can be at most 20 because of the enumeration from
kCGBaseWindowLevelKey
tokCGAssistiveTechHighWindowLevelKey
, that last one having the value 20. But these are not window levels, they are keys that can be used to look up window levels usingCGWindowLevelForKey
. For example,kCGStatusWindowLevelKey
has the value 9, butkCGStatusWindowLevel
is defined asCGWindowLevelForKey(kCGStatusWindowLevelKey)
, and the value of that turns out to be 25.