configs  Artifact [627bff5aee]

Artifact 627bff5aee7d4461734f6121b8d3ef4980400e80ed8dadce85e1a60a7591d01f:

  • File Set3000x2000Res.m — part of check-in [be1f62ff6d] at 2023-03-20 21:36:44 on branch trunk — Add small tool to set 3000x2000 resolution on Mac (user: js size: 1444)
  • File misc/Set3000x2000Res.m — part of check-in [5911601093] at 2023-04-01 11:15:08 on branch trunk — Create misc directory for non-config files (user: js size: 1444)

/*
 * 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;
}