mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-12 09:58:03 +02:00
Cursor (macOS): migrates impl to pure C using CoreFoundation
This commit is contained in:
+1
-1
@@ -1023,7 +1023,7 @@ elseif(APPLE)
|
||||
src/detection/cpu/cpu_apple.c
|
||||
src/detection/cpucache/cpucache_apple.c
|
||||
src/detection/cpuusage/cpuusage_apple.c
|
||||
src/detection/cursor/cursor_apple.m
|
||||
src/detection/cursor/cursor_apple.c
|
||||
src/detection/disk/disk_bsd.c
|
||||
src/detection/dns/dns_apple.c
|
||||
src/detection/physicaldisk/physicaldisk_apple.c
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
#include "cursor.h"
|
||||
#include "common/apple/cf_helpers.h"
|
||||
|
||||
static bool appendColor(FFstrbuf* str, CFDictionaryRef dict) {
|
||||
double r, g, b, a;
|
||||
if (
|
||||
ffCfDictGetDouble(dict, CFSTR("red"), &r) ||
|
||||
ffCfDictGetDouble(dict, CFSTR("green"), &g) ||
|
||||
ffCfDictGetDouble(dict, CFSTR("blue"), &b) ||
|
||||
ffCfDictGetDouble(dict, CFSTR("alpha"), &a)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
r = r * 255 + .5;
|
||||
g = g * 255 + .5;
|
||||
b = b * 255 + .5;
|
||||
a = a * 255 + .5;
|
||||
|
||||
uint32_t color = ((uint32_t) r << 24) | ((uint32_t) g << 16) | ((uint32_t) b << 8) | ((uint32_t) a);
|
||||
|
||||
// clang-format off
|
||||
switch (color)
|
||||
{
|
||||
case 0x000000FF: ffStrbufAppendS(str, "Black"); break;
|
||||
case 0x0433FFFF: ffStrbufAppendS(str, "Blue"); break;
|
||||
case 0xAA7942FF: ffStrbufAppendS(str, "Brown"); break;
|
||||
case 0x00FDFFFF: ffStrbufAppendS(str, "Cyan"); break;
|
||||
case 0x00F900FF: ffStrbufAppendS(str, "Green"); break;
|
||||
case 0xFF40FFFF: ffStrbufAppendS(str, "Magenta"); break;
|
||||
case 0xFF9300FF: ffStrbufAppendS(str, "Orange"); break;
|
||||
case 0x942192FF: ffStrbufAppendS(str, "Purple"); break;
|
||||
case 0xFF2600FF: ffStrbufAppendS(str, "Red"); break;
|
||||
case 0xFFFB00FF: ffStrbufAppendS(str, "Yellow"); break;
|
||||
case 0xFFFFFFFF: ffStrbufAppendS(str, "White"); break;
|
||||
case 0x00000000: ffStrbufAppendS(str, "Transparent"); break;
|
||||
default: ffStrbufAppendF(str, "#%08X", color); break;
|
||||
}
|
||||
// clang-format on
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ffDetectCursor(FFCursorResult* result) {
|
||||
// Read via cfprefsd (equivalent to `defaults read com.apple.universalaccess <key>`)
|
||||
ffStrbufAppendS(&result->theme, "Fill - ");
|
||||
{
|
||||
FF_CFTYPE_AUTO_RELEASE CFTypeRef color = CFPreferencesCopyAppValue(CFSTR("cursorFill"), CFSTR("com.apple.universalaccess"));
|
||||
if (!color || CFGetTypeID(color) != CFDictionaryGetTypeID() || !appendColor(&result->theme, (CFDictionaryRef) color)) {
|
||||
ffStrbufAppendS(&result->theme, "Black");
|
||||
}
|
||||
}
|
||||
|
||||
ffStrbufAppendS(&result->theme, ", Outline - ");
|
||||
{
|
||||
FF_CFTYPE_AUTO_RELEASE CFTypeRef color = CFPreferencesCopyAppValue(CFSTR("cursorOutline"), CFSTR("com.apple.universalaccess"));
|
||||
if (!color || CFGetTypeID(color) != CFDictionaryGetTypeID() || !appendColor(&result->theme, (CFDictionaryRef) color)) {
|
||||
ffStrbufAppendS(&result->theme, "White");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
FF_CFTYPE_AUTO_RELEASE CFTypeRef mouseDriverCursorSize = CFPreferencesCopyAppValue(CFSTR("mouseDriverCursorSize"), CFSTR("com.apple.universalaccess"));
|
||||
double size = 32;
|
||||
if (mouseDriverCursorSize && ffCfNumGetDouble(mouseDriverCursorSize, &size) == nullptr) {
|
||||
ffStrbufAppendUInt(&result->size, (uint32_t) (size * 32 + 0.5));
|
||||
} else {
|
||||
ffStrbufAppendS(&result->size, "32");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
#include "cursor.h"
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
static void appendColor(FFstrbuf* str, NSDictionary* dict)
|
||||
{
|
||||
uint32_t r = (uint32_t) (((NSNumber*) dict[@"red"]).doubleValue * 255 + .5);
|
||||
uint32_t g = (uint32_t) (((NSNumber*) dict[@"green"]).doubleValue * 255 + .5);
|
||||
uint32_t b = (uint32_t) (((NSNumber*) dict[@"blue"]).doubleValue * 255 + .5);
|
||||
uint32_t a = (uint32_t) (((NSNumber*) dict[@"alpha"]).doubleValue * 255 + .5);
|
||||
uint32_t color = (r << 24) | (g << 16) | (b << 8) | a;
|
||||
|
||||
switch (color)
|
||||
{
|
||||
case 0x000000FF: ffStrbufAppendS(str, "Black"); return;
|
||||
case 0x0433FFFF: ffStrbufAppendS(str, "Blue"); return;
|
||||
case 0xAA7942FF: ffStrbufAppendS(str, "Brown"); return;
|
||||
case 0x00FDFFFF: ffStrbufAppendS(str, "Cyan"); return;
|
||||
case 0x00F900FF: ffStrbufAppendS(str, "Green"); return;
|
||||
case 0xFF40FFFF: ffStrbufAppendS(str, "Magenta"); return;
|
||||
case 0xFF9300FF: ffStrbufAppendS(str, "Orange"); return;
|
||||
case 0x942192FF: ffStrbufAppendS(str, "Purple"); return;
|
||||
case 0xFF2600FF: ffStrbufAppendS(str, "Red"); return;
|
||||
case 0xFFFB00FF: ffStrbufAppendS(str, "Yellow"); return;
|
||||
case 0xFFFFFFFF: ffStrbufAppendS(str, "White"); return;
|
||||
case 0x00000000: ffStrbufAppendS(str, "Transparent"); return;
|
||||
default: ffStrbufAppendF(str, "#%08X", color); return;
|
||||
}
|
||||
}
|
||||
|
||||
void ffDetectCursor(FFCursorResult* result)
|
||||
{
|
||||
NSError* error;
|
||||
NSString* fileName = [NSString stringWithFormat:@"file://%s/Library/Preferences/com.apple.universalaccess.plist", instance.state.platform.homeDir.chars];
|
||||
NSDictionary* dict = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:fileName]
|
||||
error:&error];
|
||||
if(error)
|
||||
{
|
||||
ffStrbufAppendS(&result->error, error.localizedDescription.UTF8String);
|
||||
return;
|
||||
}
|
||||
|
||||
NSDictionary* color;
|
||||
|
||||
ffStrbufAppendS(&result->theme, "Fill - ");
|
||||
if ((color = dict[@"cursorFill"]))
|
||||
appendColor(&result->theme, color);
|
||||
else
|
||||
ffStrbufAppendS(&result->theme, "Black");
|
||||
|
||||
ffStrbufAppendS(&result->theme, ", Outline - ");
|
||||
|
||||
if ((color = dict[@"cursorOutline"]))
|
||||
appendColor(&result->theme, color);
|
||||
else
|
||||
ffStrbufAppendS(&result->theme, "White");
|
||||
|
||||
NSNumber* mouseDriverCursorSize = dict[@"mouseDriverCursorSize"];
|
||||
if (mouseDriverCursorSize)
|
||||
ffStrbufAppendF(&result->size, "%d", (int) (mouseDriverCursorSize.doubleValue * 32 + 0.5));
|
||||
else
|
||||
ffStrbufAppendS(&result->size, "32");
|
||||
}
|
||||
Reference in New Issue
Block a user