I'm trying to find (can be undocumented, or old way) to know which mission control desktop (or if the application is full screen which desktop is it) is my application window running on.
I have successfully used CGSCopySpaces, although I'm unable to get their names by calling CGSSpaceCopyName() on them, It just returns null for each individual desktop. So since I cannot properly get their names, the most reliable way would be to tell which desktop / which desktop is my application present on. Does macOS private functionality provide a way to do so? From what I can tell, workspaces are different from spaces, even ID wise.
I'm aware that macOS internals change time to time, and more than windows internals do from what I'm starting to experience with It, but I have seen applications use these APIs still until the day, and they should be valid.
See code below:
CFArrayRef desktops = CGSCopySpaces(CGSMainConnectionID(), kCGSAllSpacesMask);
if (desktops == NULL) {
std::cerr << "Failed to retrieve desktops" << std::endl;
return;
}
CFIndex desktopCount = CFArrayGetCount(desktops);
CGSSpaceID activeSpace = CGSGetActiveSpace(CGSMainConnectionID());
CGSSpaceType spaceType = CGSSpaceGetType(CGSMainConnectionID(), activeSpace);
CFStringRef spaceName = CGSSpaceCopyName(CGSMainConnectionID(), activeSpace);
for (CFIndex i = 0; i < desktopCount; ++i) {
CGSSpaceID desktopID = (CGSSpaceID)(uintptr_t)CFArrayGetValueAtIndex(desktops, i);
spaceName = CGSSpaceCopyName(CGSMainConnectionID(), desktopID);
std::cout << "Desktop " << i + 1 << " (ID: " << desktopID << ") " << std::endl;
CFShow(spaceName);