Skip to content

Commit

Permalink
macOS: implement the directory watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
eyelash committed Sep 6, 2024
1 parent 54ace5f commit 0118fed
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions gral_macos.m
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,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;
Expand All @@ -160,7 +160,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);
Expand Down Expand Up @@ -784,13 +784,25 @@ void gral_directory_remove(char const *path) {
rmdir(path);
}

static void directory_watcher_callback(CFFileDescriptorRef fdref, CFOptionFlags, void *info) {
struct kevent event;
}

struct gral_directory_watcher *gral_directory_watch(char const *path, void (*callback)(void *user_data), void *user_data) {
// TODO: implement
return NULL;
int fd = kqueue();
struct kevent event;
EV_SET(&event, open(path, O_EVTONLY), EVFILT_VNODE, EV_ADD, NOTE_WRITE | NOTE_DELETE, 0, NULL);
kevent(fd, &event, 1, NULL, 0, NULL);
CFFileDescriptorRef fdref = CFFileDescriptorCreate(kCFAllocatorDefault, fd, TRUE, &directory_watcher_callback, NULL);
CFFileDescriptorEnableCallBacks(fdref, kCFFileDescriptorReadCallBack);
CFRunLoopSourceRef source = CFFileDescriptorCreateRunLoopSource(kCFAllocatorDefault, fdref, 0);
CFRunLoopAddSource(CFRunLoopGetMain(), source, kCFRunLoopDefaultMode);
CFRelease(source);
return fdref;
}

void gral_directory_watcher_delete(struct gral_directory_watcher *directory_watcher) {
// TODO: implement

}


Expand Down

0 comments on commit 0118fed

Please sign in to comment.