每次当前可查看的系统窗口发生可见变化时,我都需要调用一个方法。例如,我得到了完整的可见窗口列表:
CFArrayRef openWindows =(CGWindowListCreate(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID));
这将返回一个数组,例如:
{
kCGWindowAlpha = 1;
kCGWindowBounds = {
Height = 713;
Width = 1279;
X = 1;
Y = 22;
};
kCGWindowIsOnscreen = 1;
kCGWindowLayer = 0;
kCGWindowMemoryUsage = 3772468;
kCGWindowName = "Stack Overflow";
kCGWindowNumber = 7138;
kCGWindowOwnerName = "Google Chrome";
kCGWindowOwnerPID = 49972;
kCGWindowSharingState = 1;
kCGWindowStoreType = 2;
}
由于 kCGWindowMemoryUsage 值不断变化,我不能简单地将以前存储的 CFArrayRef 与当前进行比较。