configs  Check-in [be1f62ff6d]

Overview
Comment:Add small tool to set 3000x2000 resolution on Mac
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: be1f62ff6d86db56cfda7f56d44917db19063e01be8a50b7bfd6b1eb763d152d
User & Date: js 2023-03-20 21:36:44
Context
2023-03-20
21:38
Merge accidental fork check-in: 2ff958f020 user: js tags: trunk
21:36
Add small tool to set 3000x2000 resolution on Mac check-in: be1f62ff6d user: js tags: trunk
2023-03-19
12:10
Add LaunchAgent for Element Web check-in: 787cd2705a user: js tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added Set3000x2000Res.m.



















































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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;
}