Add OS detection

This commit is contained in:
Lea Anthony 2021-04-12 06:25:15 +10:00
commit 1344638c52
No known key found for this signature in database
GPG key ID: 33DAF7BB90A58405
2 changed files with 13 additions and 0 deletions

View file

@ -83,6 +83,11 @@ void ShowMouse() {
msg_reg(c("NSCursor"), s("unhide"));
}
OSVersion getOSVersion() {
id processInfo = msg_reg(c("NSProcessInfo"), s("processInfo"));
return GET_OSVERSION(processInfo);
}
struct Application {
// Cocoa data

View file

@ -11,6 +11,12 @@
#include "hashmap.h"
#include "stdlib.h"
typedef struct {
long maj;
long min;
long patch;
} OSVersion;
// Macros to make it slightly more sane
#define msg objc_msgSend
#define msg_reg ((id(*)(id, SEL))objc_msgSend)
@ -37,11 +43,13 @@
#if defined (__aarch64__)
#define GET_FRAME(receiver) ((CGRect(*)(id, SEL))objc_msgSend)(receiver, s("frame"))
#define GET_BOUNDS(receiver) ((CGRect(*)(id, SEL))objc_msgSend)(receiver, s("bounds"))
#define GET_OSVERSION(receiver) ((OSVersion(*)(id, SEL))objc_msgSend)(processInfo, s("operatingSystemVersion"));
#endif
#if defined (__x86_64__)
#define GET_FRAME(receiver) ((CGRect(*)(id, SEL))objc_msgSend_stret)(receiver, s("frame"))
#define GET_BOUNDS(receiver) ((CGRect(*)(id, SEL))objc_msgSend_stret)(receiver, s("bounds"))
#define GET_OSVERSION(receiver) ((OSVersion(*)(id, SEL))objc_msgSend_stret)(processInfo, s("operatingSystemVersion"));
#endif
#define GET_BACKINGSCALEFACTOR(receiver) ((CGFloat(*)(id, SEL))objc_msgSend)(receiver, s("backingScaleFactor"))