Skip to content

Instantly share code, notes, and snippets.

@t0rr3sp3dr0
Last active June 7, 2025 00:28
Show Gist options
  • Save t0rr3sp3dr0/331086dcb271cb4f98f18cf7fb282736 to your computer and use it in GitHub Desktop.
Save t0rr3sp3dr0/331086dcb271cb4f98f18cf7fb282736 to your computer and use it in GitHub Desktop.
clang -framework CoreGraphics ./AlignTwoDisplaysHorizontally.c
#include <CoreGraphics/CoreGraphics.h>
int main() {
CGDirectDisplayID displays[2];
CGGetOnlineDisplayList(2, displays, NULL);
CGDirectDisplayID st;
CGDirectDisplayID nd;
if (CGDisplayIsMain(displays[0])) {
st = displays[0];
nd = displays[1];
} else {
st = displays[1];
nd = displays[0];
}
CGDisplayConfigRef configRef;
CGBeginDisplayConfiguration(&configRef);
CGConfigureDisplayOrigin(configRef, st, 0, 0);
CGConfigureDisplayOrigin(configRef, nd, (CGDisplayBounds(st).size.width - CGDisplayBounds(nd).size.width) / 2, CGDisplayBounds(st).size.height);
CGCompleteDisplayConfiguration(configRef, kCGConfigurePermanently);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment