简体   繁体   中英

macOS CGConfigureDisplayOrigin doesn't work as expected

I have multiple monitors and try to change the main display using Quarz Display APIs, my function is

int setDisplayOrigin(CGDirectDisplayID display, int x, int y) {
    CGDisplayConfigRef cfg;
    auto ret = CGBeginDisplayConfiguration(&cfg);
    if (ret != kCGErrorSuccess) return ret;
    ret = CGConfigureDisplayOrigin(cfg, display, x, y);
    if (ret != kCGErrorSuccess) return ret;
    ret = CGCompleteDisplayConfiguration(cfg, kCGConfigureForAppOnly);
    return ret;
}

to set specific monitor as the main one, I call this function with both 0 with x and y

setDisplayOrigin(directDisplayID, 0, 0)

macOS did rearrange the displays, but the related display won't have origin with (0, 0) when I check its bounds again, and every returned value was successful (KCGErrorSuccess)

Thanks the hint from Ken, reposition the current main display and then set the target display's origin to (0, 0) which is the way to make it work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM