diff --git a/CMakeLists.txt b/CMakeLists.txt index 3483fac01..c2ffcfead 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -462,7 +462,7 @@ elseif(APPLE) src/detection/chassis/chassis_nosupport.c src/detection/cpu/cpu_apple.c src/detection/cpuUsage/cpuUsage_apple.c - src/detection/cursor/cursor_nosupport.c + src/detection/cursor/cursor_apple.m src/detection/disk/disk_apple.m src/detection/disk/disk_bsd.c src/detection/displayserver/displayserver_apple.c diff --git a/src/detection/cursor/cursor_apple.m b/src/detection/cursor/cursor_apple.m new file mode 100644 index 000000000..3873e979a --- /dev/null +++ b/src/detection/cursor/cursor_apple.m @@ -0,0 +1,52 @@ +#include "cursor.h" + +#import + +static void appendColor(FFstrbuf* str, NSDictionary* color) +{ + int r = (int) (((NSNumber*) [color valueForKey:@"red"]).doubleValue * 255); + int g = (int) (((NSNumber*) [color valueForKey:@"green"]).doubleValue * 255); + int b = (int) (((NSNumber*) [color valueForKey:@"blue"]).doubleValue * 255); + int a = (int) (((NSNumber*) [color valueForKey:@"alpha"]).doubleValue * 255); + + if (r == 255 && g == 255 && b == 255 && a == 255) + ffStrbufAppendS(str, "White"); + else if (r == 0 && g == 0 && b == 0 && a == 255) + ffStrbufAppendS(str, "Black"); + else + ffStrbufAppendF(str, "#%02X%02X%02X%02X", r, g, b, a); +} + +void ffDetectCursor(const FFinstance* instance, 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 valueForKey:@"cursorFill"])) + appendColor(&result->theme, color); + else + ffStrbufAppendS(&result->theme, "Black"); + + ffStrbufAppendS(&result->theme, ", Outline - "); + + if ((color = [dict valueForKey:@"cursorOutline"])) + appendColor(&result->theme, color); + else + ffStrbufAppendS(&result->theme, "White"); + + NSNumber* mouseDriverCursorSize = [dict valueForKey:@"mouseDriverCursorSize"]; + if (mouseDriverCursorSize) + ffStrbufAppendF(&result->size, "%d", (int) (mouseDriverCursorSize.doubleValue * 32)); + else + ffStrbufAppendS(&result->size, "32"); +}