diff --git a/gral_macos.m b/gral_macos.m index ab4221f..da8b874 100644 --- a/gral_macos.m +++ b/gral_macos.m @@ -125,7 +125,7 @@ void gral_image_delete(struct gral_image *image) { } struct gral_font *gral_font_create(struct gral_window *window, char const *name, float size) { - CFStringRef string = CFStringCreateWithCString(NULL, name, kCFStringEncodingUTF8); + CFStringRef string = CFStringCreateWithCString(kCFAllocatorDefault, name, kCFStringEncodingUTF8); CTFontRef font = CTFontCreateWithName(string, size, NULL); CFRelease(string); return (struct gral_font *)font; @@ -149,7 +149,7 @@ void gral_font_get_metrics(struct gral_window *window, struct gral_font *font, f } struct gral_text *gral_text_create(struct gral_window *window, char const *text, struct gral_font *font) { - CFStringRef string = CFStringCreateWithCString(NULL, text, kCFStringEncodingUTF8); + CFStringRef string = CFStringCreateWithCString(kCFAllocatorDefault, text, kCFStringEncodingUTF8); CFMutableDictionaryRef attributes = CFDictionaryCreateMutable(NULL, 1, &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFDictionarySetValue(attributes, kCTFontAttributeName, font); CFAttributedStringRef attributed_string = CFAttributedStringCreate(NULL, string, attributes); @@ -795,13 +795,29 @@ void gral_directory_remove(char const *path) { rmdir(path); } +static void event_stream_callback(ConstFSEventStreamRef streamRef, void *clientCallBackInfo, size_t numEvents, void *eventPaths, FSEventStreamEventFlags const *eventFlags, FSEventStreamEventId const *eventIds) { + for (size_t i = 0; i < numEvents; i++) { + + } +} + struct gral_directory_watcher *gral_directory_watch(char const *path, void (*callback)(void *user_data), void *user_data) { - // TODO: implement - return NULL; + CFStringRef string = CFStringCreateWithCString(kCFAllocatorDefault, path, kCFStringEncodingUTF8); + CFArrayRef paths = CFArrayCreate(kCFAllocatorDefault, &string, 1, &kCFTypeArrayCallBacks); + CFRelease(string); + FSEventStreamRef event_stream = FSEventStreamCreate(kCFAllocatorDefault, event_stream_callback, NULL, paths, kFSEventStreamEventIdSinceNow, 0.0, kFSEventStreamCreateFlagNone); + CFRelease(paths); + FSEventStreamScheduleWithRunLoop(event_stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); + FSEventStreamStart(event_stream); + return (struct gral_directory_watcher *)event_stream; } void gral_directory_watcher_delete(struct gral_directory_watcher *directory_watcher) { - // TODO: implement + FSEventStreamRef event_stream = (FSEventStreamRef)directory_watcher; + FSEventStreamStop(event_stream); + //FSEventStreamUnscheduleFromRunLoop(event_stream, ); + FSEventStreamInvalidate(event_stream); + FSEventStreamRelease(event_stream); }