fix(display): skip mirror/extend if already in requested state
mirror_displays() now checks CGDisplayMirrorsDisplay() for each secondary before calling CGBeginDisplayConfiguration — avoids a needless display reconfiguration (and potential flicker) when already mirrored. extend_displays() already had this check; no change needed there.
This commit is contained in:
Binary file not shown.
@@ -31,6 +31,17 @@ static int mirror_displays(void) {
|
||||
|
||||
CGDirectDisplayID mainID = CGMainDisplayID();
|
||||
|
||||
// Idempotency: if every secondary is already mirroring mainID, nothing to do.
|
||||
CGDisplayCount alreadyMirrored = 0;
|
||||
for (CGDisplayCount i = 0; i < numOnline; i++) {
|
||||
if (onlineDspys[i] != mainID && CGDisplayMirrorsDisplay(onlineDspys[i]) == mainID)
|
||||
alreadyMirrored++;
|
||||
}
|
||||
if (alreadyMirrored == numOnline - 1) {
|
||||
printf("Displays already mirrored.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
CGDisplayConfigRef config;
|
||||
CGError err = CGBeginDisplayConfiguration(&config);
|
||||
if (err != kCGErrorSuccess) {
|
||||
|
||||
Reference in New Issue
Block a user