76 lines
2.4 KiB
Objective-C
76 lines
2.4 KiB
Objective-C
#if defined(OS_MACOS)
|
|
|
|
#include <CoreFoundation/CFBundle.h>
|
|
#include <ApplicationServices/ApplicationServices.h>
|
|
#include <Foundation/NSUserDefaults.h>
|
|
#include <Foundation/Foundation.h>
|
|
#include <AppKit/NSScreen.h>
|
|
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
|
|
#define GLFW_EXPOSE_NATIVE_COCOA
|
|
#include <GLFW/glfw3.h>
|
|
#include <GLFW/glfw3native.h>
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
#import <Foundation/Foundation.h>
|
|
|
|
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) {
|
|
NSWindow* cocoaWindow = glfwGetCocoaWindow(window);
|
|
cocoaWindow.titleVisibility = NSWindowTitleHidden;
|
|
|
|
NSVisualEffectView *visualEffectView = [[NSVisualEffectView alloc] init];
|
|
[visualEffectView setMaterial:NSVisualEffectMaterialAppearanceBased];
|
|
[visualEffectView setBlendingMode:NSVisualEffectBlendingModeBehindWindow];
|
|
|
|
[cocoaWindow.contentView addSubview:visualEffectView positioned:NSWindowBelow relativeTo:nil];
|
|
}
|
|
|
|
@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];
|
|
|
|
openFile(utf8String);
|
|
|
|
return YES;
|
|
}
|
|
|
|
@end
|
|
|
|
#endif
|