CGWindowListCopyWindowInfo, kCGWindowLayer and window level

限于喜欢 提交于 2019-12-04 10:49:33

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 to kCGAssistiveTechHighWindowLevelKey, 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 using CGWindowLevelForKey. For example, kCGStatusWindowLevelKey has the value 9, but kCGStatusWindowLevel is defined as CGWindowLevelForKey(kCGStatusWindowLevelKey), and the value of that turns out to be 25.

No. kCGWindowLayer and window level are not same. You cannot get window level directly. But you can do a trick as below.

        CFArrayRef windowArray = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
        NSMutableArray *windowsInMap = [NSMutableArray arrayWithCapacity:64];
        NSArray*  windows = (NSArray*)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
        NSUInteger count = [windows count];
        for (NSUInteger i = 0; i < count; i++)
        {
            NSDictionary*   nswindowsdescription = [windows objectAtIndex:i];
            NSNumber* windowid = (NSNumber*)[nswindowsdescription objectForKey:@"kCGWindowNumber"];
            if(windowid)
            {
                       // Entried will be in front to back order.
            }
        }
        CFRelease(windowArray);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!