1
0
mirror of synced 2024-12-05 04:27:56 +01:00
ImHex/lib/libimhex/source/helpers/utils_macos.m

70 lines
2.0 KiB
Mathematica
Raw Normal View History

#if defined(OS_MACOS)
#include <CoreFoundation/CFBundle.h>
#include <ApplicationServices/ApplicationServices.h>
2022-06-30 15:28:51 +02:00
#include <Foundation/NSUserDefaults.h>
2022-06-30 15:20:13 +02:00
#include <Foundation/Foundation.h>
2023-02-08 13:51:56 +01:00
#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>
2023-05-14 21:50:58 +02:00
#import <Cocoa/Cocoa.h>
2023-05-14 20:20:22 +02:00
#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);
}
2023-05-14 22:03:04 +02:00
void openFile(const char *path);
2023-05-14 20:20:22 +02:00
2023-05-14 22:03:04 +02:00
void openWebpageMacos(const char *url) {
CFURLRef urlRef = CFURLCreateWithBytes(NULL, (uint8_t*)(url), strlen(url), kCFStringEncodingASCII, NULL);
LSOpenCFURLRef(urlRef, NULL);
CFRelease(urlRef);
}
2023-05-14 22:03:04 +02:00
bool isMacosSystemDarkModeEnabled(void) {
NSString * appleInterfaceStyle = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"];
if (appleInterfaceStyle && [appleInterfaceStyle length] > 0) {
return [[appleInterfaceStyle lowercaseString] containsString:@"dark"];
} else {
return false;
}
}
2023-05-14 22:03:04 +02:00
float getBackingScaleFactor(void) {
2023-02-08 13:51:56 +01:00
return [[NSScreen mainScreen] backingScaleFactor];
}
void setupMacosWindowStyle(GLFWwindow *window) {
NSWindow* cocoaWindow = glfwGetCocoaWindow(window);
cocoaWindow.titleVisibility = NSWindowTitleHidden;
}
2023-05-14 18:35:35 +02:00
@interface HexDocument : NSDocument
@end
@implementation HexDocument
2023-05-14 20:20:22 +02:00
- (BOOL) readFromURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError **)outError {
2023-05-14 22:03:04 +02:00
NSString* urlString = [url absoluteString];
const char* utf8String = [urlString UTF8String];
openFile(utf8String);
2023-05-14 20:20:22 +02:00
2023-05-14 18:35:35 +02:00
return YES;
}
@end
2023-01-04 14:55:58 +01:00
#endif