ohmu
·
2026-10-15
1#include "cursor.h"
2#include "common/apple/cf_helpers.h"
3
4static bool appendColor(FFstrbuf* str, CFDictionaryRef dict) {
5 double r, g, b, a;
6 if (
7 ffCfDictGetDouble(dict, CFSTR("red"), &r) ||
8 ffCfDictGetDouble(dict, CFSTR("green"), &g) ||
9 ffCfDictGetDouble(dict, CFSTR("blue"), &b) ||
10 ffCfDictGetDouble(dict, CFSTR("alpha"), &a)) {
11 return false;
12 }
13
14 r = r * 255 + .5;
15 g = g * 255 + .5;
16 b = b * 255 + .5;
17 a = a * 255 + .5;
18
19 uint32_t color = ((uint32_t) r << 24) | ((uint32_t) g << 16) | ((uint32_t) b << 8) | ((uint32_t) a);
20
21 // clang-format off
22 switch (color)
23 {
24 case 0x000000FF: ffStrbufAppendS(str, "Black"); break;
25 case 0x0433FFFF: ffStrbufAppendS(str, "Blue"); break;
26 case 0xAA7942FF: ffStrbufAppendS(str, "Brown"); break;
27 case 0x00FDFFFF: ffStrbufAppendS(str, "Cyan"); break;
28 case 0x00F900FF: ffStrbufAppendS(str, "Green"); break;
29 case 0xFF40FFFF: ffStrbufAppendS(str, "Magenta"); break;
30 case 0xFF9300FF: ffStrbufAppendS(str, "Orange"); break;
31 case 0x942192FF: ffStrbufAppendS(str, "Purple"); break;
32 case 0xFF2600FF: ffStrbufAppendS(str, "Red"); break;
33 case 0xFFFB00FF: ffStrbufAppendS(str, "Yellow"); break;
34 case 0xFFFFFFFF: ffStrbufAppendS(str, "White"); break;
35 case 0x00000000: ffStrbufAppendS(str, "Transparent"); break;
36 default: ffStrbufAppendF(str, "#%08X", color); break;
37 }
38 // clang-format on
39
40 return true;
41}
42
43void ffDetectCursor(FFCursorResult* result) {
44 // Read via cfprefsd (equivalent to `defaults read com.apple.universalaccess <key>`)
45 ffStrbufAppendS(&result->theme, "Fill - ");
46 {
47 FF_CFTYPE_AUTO_RELEASE CFTypeRef color = CFPreferencesCopyAppValue(CFSTR("cursorFill"), CFSTR("com.apple.universalaccess"));
48 if (!color || CFGetTypeID(color) != CFDictionaryGetTypeID() || !appendColor(&result->theme, (CFDictionaryRef) color)) {
49 ffStrbufAppendS(&result->theme, "Black");
50 }
51 }
52
53 ffStrbufAppendS(&result->theme, ", Outline - ");
54 {
55 FF_CFTYPE_AUTO_RELEASE CFTypeRef color = CFPreferencesCopyAppValue(CFSTR("cursorOutline"), CFSTR("com.apple.universalaccess"));
56 if (!color || CFGetTypeID(color) != CFDictionaryGetTypeID() || !appendColor(&result->theme, (CFDictionaryRef) color)) {
57 ffStrbufAppendS(&result->theme, "White");
58 }
59 }
60
61 {
62 FF_CFTYPE_AUTO_RELEASE CFTypeRef mouseDriverCursorSize = CFPreferencesCopyAppValue(CFSTR("mouseDriverCursorSize"), CFSTR("com.apple.universalaccess"));
63 double size = 32;
64 if (mouseDriverCursorSize && ffCfNumGetDouble(mouseDriverCursorSize, &size) == nullptr) {
65 ffStrbufAppendUInt(&result->size, (uint32_t) (size * 32 + 0.5));
66 } else {
67 ffStrbufAppendS(&result->size, "32");
68 }
69 }
70}