Add small tool to set 3000x2000 resolution on Mac
This commit is contained in:
parent
2e7aa5d15e
commit
ec539574da
1 changed files with 57 additions and 0 deletions
57
Set3000x2000Res.m
Normal file
57
Set3000x2000Res.m
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* This small program sets the resolution to 3000x2000 in HiDPI mode.
|
||||
*
|
||||
* Unfortunately, this is necessary because macOS does not allow selecting 3:2
|
||||
* resolutions as used by some travel displays.
|
||||
*
|
||||
* Compile with:
|
||||
* clang -framework CoreGraphics -framework Foundation Set3000x2000Res.m
|
||||
*/
|
||||
|
||||
#import <CoreGraphics/CoreGraphics.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
NSArray *allModes = (NSArray *)CGDisplayCopyAllDisplayModes(
|
||||
CGMainDisplayID(), (CFDictionaryRef)@{
|
||||
(NSString *)kCGDisplayShowDuplicateLowResolutionModes: @YES
|
||||
});
|
||||
CGDisplayModeRef pickedMode = NULL;
|
||||
for (id object in allModes) {
|
||||
CGDisplayModeRef mode = (CGDisplayModeRef)object;
|
||||
|
||||
if (CGDisplayModeGetWidth(mode) == 1500 &&
|
||||
CGDisplayModeGetHeight(mode) == 1000 &&
|
||||
CGDisplayModeGetRefreshRate(mode) == 60) {
|
||||
pickedMode = mode;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pickedMode == NULL) {
|
||||
NSLog(@"Mode not found!");
|
||||
return 1;
|
||||
}
|
||||
|
||||
CGDisplayConfigRef config;
|
||||
if (CGBeginDisplayConfiguration(&config) != kCGErrorSuccess) {
|
||||
NSLog(@"CGBeginDisplayConfiguration failed!");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (CGConfigureDisplayWithDisplayMode(config, CGMainDisplayID(),
|
||||
pickedMode, NULL) != kCGErrorSuccess) {
|
||||
NSLog(@"CGConfigureDisplayWithMode failed!");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (CGCompleteDisplayConfiguration(config, kCGConfigurePermanently) !=
|
||||
kCGErrorSuccess) {
|
||||
NSLog(@"CGCompleteDisplayConfiguration failed!");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue