简体   繁体   English

macOS CGConfigureDisplayOrigin 无法按预期工作

[英]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我有多个显示器并尝试使用 Quarz Display API 更改主显示器,我的 function 是

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要将特定监视器设置为主监视器,我将其称为 function,其中 0 和 x 和 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) macOS 确实重新排列了显示,但是当我再次检查它的边界时,相关的显示不会以 (0, 0) 为原点,并且每个返回的值都是成功的 (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.感谢 Ken 的提示,重新定位当前主显示器,然后将目标显示器的原点设置为 (0, 0),这是使其工作的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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