#if defined(OS_MACOS) #include #include #include #include #include #include #include #include #define GLFW_EXPOSE_NATIVE_COCOA #include #include #import #import void errorMessageMacos(const char *cMessage) { CFStringRef strMessage = CFStringCreateWithCString(NULL, cMessage, kCFStringEncodingUTF8); CFUserNotificationDisplayAlert(0, kCFUserNotificationStopAlertLevel, NULL, NULL, NULL, strMessage, NULL, NULL, NULL, NULL, NULL); } void openFile(const char *path); void openWebpageMacos(const char *url) { CFURLRef urlRef = CFURLCreateWithBytes(NULL, (uint8_t*)(url), strlen(url), kCFStringEncodingASCII, NULL); LSOpenCFURLRef(urlRef, NULL); CFRelease(urlRef); } bool isMacosSystemDarkModeEnabled(void) { NSString * appleInterfaceStyle = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"]; if (appleInterfaceStyle && [appleInterfaceStyle length] > 0) { return [[appleInterfaceStyle lowercaseString] containsString:@"dark"]; } else { return false; } } float getBackingScaleFactor(void) { return [[NSScreen mainScreen] backingScaleFactor]; } void setupMacosWindowStyle(GLFWwindow *window, bool borderlessWindowMode) { NSWindow* cocoaWindow = glfwGetCocoaWindow(window); cocoaWindow.titleVisibility = NSWindowTitleHidden; if (borderlessWindowMode) { cocoaWindow.titlebarAppearsTransparent = YES; cocoaWindow.styleMask |= NSWindowStyleMaskFullSizeContentView; [cocoaWindow setOpaque:NO]; [cocoaWindow setHasShadow:YES]; [cocoaWindow setBackgroundColor:[NSColor colorWithWhite: 0 alpha: 0.001f]]; } } bool isMacosFullScreenModeEnabled(GLFWwindow *window) { NSWindow* cocoaWindow = glfwGetCocoaWindow(window); return (cocoaWindow.styleMask & NSWindowStyleMaskFullScreen) == NSWindowStyleMaskFullScreen; } @interface HexDocument : NSDocument @end @implementation HexDocument - (BOOL) readFromURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError **)outError { NSString* urlString = [url absoluteString]; const char* utf8String = [urlString UTF8String]; const char *prefix = "file://"; if (strncmp(utf8String, prefix, strlen(prefix)) == 0) utf8String += strlen(prefix); openFile(utf8String); return YES; } @end #endif