Posts

Post not yet marked as solved
0 Replies
217 Views
I am seeing an issue where CGDisplayCopyDisplayMode returns NULL for a monitor that was recently plugged in. We call CGGetOnlineDisplayList to get the list of displays. We then call CGDisplayCopyDisplayMode with the CGDirectDisplayId provided. However, in the case of a monitor that was recently plugged in it returns NULL. This is strange because CGDisplayIsOnline returns true and CGDisplayBounds returns correct values. The following sample app reproduces the issue: `void printDisplays() {   [NSApplication sharedApplication];   while (true) {     sleep(1);         CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, false);         CGDirectDisplayID displays[16];   CGDisplayCount displayCount;   CGError err = CGGetOnlineDisplayList(16, displays, &displayCount);   if (err != kCGErrorSuccess) {      return;   }   printf("cgdisplays cgdisplaycount \n\n");   for (uint32_t i = 0; i < displayCount; i++) {     CGDirectDisplayID cgDisplayID = displays[i];     printf("cgdisplay id %d \n", cgDisplayID);     CGRect rect = CGDisplayBounds(cgDisplayID);     printf("cgrect origin x %.2f, y %.2f \n", rect.origin.x, rect.origin.y);     printf("cgrect size width %.2f, height %.2f \n", rect.size.width, rect.size.height);           CGDisplayModeRef displayMode = CGDisplayCopyDisplayMode(cgDisplayID);     int pixelWidth = CGDisplayModeGetPixelWidth(displayMode);     int pixelHeight = CGDisplayModeGetPixelHeight(displayMode);     printf("cgdisplaymode pixelWidth %d, pixelHeight %d \n\n", pixelWidth, pixelHeight);   }     printf("\n\n\n");         }     }` However the addition of [NSApplication sharedApplication]; and CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, false); resolved the issue in the sample app, but did not resolve the issue in my real application. That is, the above code works because those lines were added, but adding the above lines in my application still return NULL.
Posted Last updated
.
Post not yet marked as solved
3 Replies
321 Views
Hi, I am finding that network access is lost from my application when the computer goes to sleep. When I receive kIOMessageSystemWillSleep, I want to send a message to another computer. But I am finding it does not always make it to the other end. Sometimes it only get sent when the computer wakes back up.
Posted Last updated
.
Post not yet marked as solved
2 Replies
291 Views
I am finding that NSScreen is returning the same number of monitors even after additional monitors are plugged in. Made a simple test app that can replicate the issue. Basically infinite loops and prints NSScreen counts and CGDisplay counts. Start the app printing “NSScreen = 1 CGDisplay = 1” Without stopping the app, plug in an additional monitor printing “NSScreen = 1 CGDisplay = 2” However the code should be printing “NSScreen = 2 CGDisplay = 2” On OS X 11, we see the same issue (NSScreen = 1 CGDisplay = 2) after plugging in the additional monitor. Test Code is here: main.cpp #include <iostream> #include "macScreen.h" int main(int argc, const char * argv[]) { getNSScreenCoordinates(); return 0; } macScreen.h #ifndef macScreen_h #define macScreen_h float getNSScreenCoordinates(); #endif /* macScreen_h */ macScreen.mm #import <Foundation/Foundation.h> #include <iostream> #include <Cocoa/Cocoa.h> #import <AppKit/NSScreen.h> #define MAX_NUM_DISPLAYS 255 float getNSScreenCoordinates() { NSArray<NSScreen *> *arr = [NSScreen screens]; NSUInteger numScreens = [arr count]; CGDirectDisplayID displays[MAX_NUM_DISPLAYS]; CGDisplayCount displayCount; CGGetOnlineDisplayList(MAX_NUM_DISPLAYS, displays, &displayCount); while(1) { std::cout << "cg num displays " << displayCount << "\n"; std::cout << "numscreens " << numScreens << "\n"; arr = [NSScreen screens]; numScreens = [arr count]; CGGetOnlineDisplayList(MAX_NUM_DISPLAYS, displays, &displayCount); } return 1; }
Posted Last updated
.