summaryrefslogtreecommitdiff
path: root/platform/osx/os_osx.mm
diff options
context:
space:
mode:
Diffstat (limited to 'platform/osx/os_osx.mm')
-rw-r--r--platform/osx/os_osx.mm68
1 files changed, 64 insertions, 4 deletions
diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm
index d0cc115f0e..65a168285d 100644
--- a/platform/osx/os_osx.mm
+++ b/platform/osx/os_osx.mm
@@ -88,6 +88,15 @@ static void get_key_modifier_state(unsigned int p_osx_state, Ref<InputEventWithM
state->set_metakey((p_osx_state & NSEventModifierFlagCommand));
}
+static void push_to_key_event_buffer(const OS_OSX::KeyEvent &p_event) {
+
+ Vector<OS_OSX::KeyEvent> &buffer = OS_OSX::singleton->key_event_buffer;
+ if (OS_OSX::singleton->key_event_pos >= buffer.size()) {
+ buffer.resize(1 + OS_OSX::singleton->key_event_pos);
+ }
+ buffer[OS_OSX::singleton->key_event_pos++] = p_event;
+}
+
static int mouse_x = 0;
static int mouse_y = 0;
static int prev_mouse_x = 0;
@@ -144,6 +153,13 @@ static Vector2 get_mouse_pos(NSEvent *event) {
@implementation GodotApplicationDelegate
+- (BOOL)application:(NSApplication *)sender openFile:(NSString *)filename {
+ // Note: called before main loop init!
+ char *utfs = strdup([filename UTF8String]);
+ OS_OSX::singleton->open_with_filename.parse_utf8(utfs);
+ return YES;
+}
+
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
if (OS_OSX::singleton->get_main_loop())
OS_OSX::singleton->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_QUIT_REQUEST);
@@ -439,7 +455,7 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
ke.scancode = 0;
ke.unicode = codepoint;
- OS_OSX::singleton->key_event_buffer[OS_OSX::singleton->key_event_pos++] = ke;
+ push_to_key_event_buffer(ke);
}
[self cancelComposition];
}
@@ -798,7 +814,7 @@ static int translateKey(unsigned int key) {
ke.scancode = latin_keyboard_keycode_convert(translateKey([event keyCode]));
ke.unicode = 0;
- OS_OSX::singleton->key_event_buffer[OS_OSX::singleton->key_event_pos++] = ke;
+ push_to_key_event_buffer(ke);
}
if ((OS_OSX::singleton->im_position.x != 0) && (OS_OSX::singleton->im_position.y != 0))
@@ -851,7 +867,7 @@ static int translateKey(unsigned int key) {
ke.scancode = latin_keyboard_keycode_convert(translateKey(key));
ke.unicode = 0;
- OS_OSX::singleton->key_event_buffer[OS_OSX::singleton->key_event_pos++] = ke;
+ push_to_key_event_buffer(ke);
}
}
@@ -867,7 +883,7 @@ static int translateKey(unsigned int key) {
ke.scancode = latin_keyboard_keycode_convert(translateKey([event keyCode]));
ke.unicode = 0;
- OS_OSX::singleton->key_event_buffer[OS_OSX::singleton->key_event_pos++] = ke;
+ push_to_key_event_buffer(ke);
}
}
@@ -947,6 +963,30 @@ void OS_OSX::set_ime_intermediate_text_callback(ImeCallback p_callback, void *p_
}
}
+String OS_OSX::get_unique_id() const {
+
+ static String serial_number;
+
+ if (serial_number.empty()) {
+ io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice"));
+ CFStringRef serialNumberAsCFString = NULL;
+ if (platformExpert) {
+ serialNumberAsCFString = (CFStringRef)IORegistryEntryCreateCFProperty(platformExpert, CFSTR(kIOPlatformSerialNumberKey), kCFAllocatorDefault, 0);
+ IOObjectRelease(platformExpert);
+ }
+
+ NSString *serialNumberAsNSString = nil;
+ if (serialNumberAsCFString) {
+ serialNumberAsNSString = [NSString stringWithString:(NSString *)serialNumberAsCFString];
+ CFRelease(serialNumberAsCFString);
+ }
+
+ serial_number = [serialNumberAsNSString UTF8String];
+ }
+
+ return serial_number;
+}
+
void OS_OSX::set_ime_position(const Point2 &p_pos) {
im_position = p_pos;
}
@@ -1829,6 +1869,12 @@ Size2 OS_OSX::get_window_size() const {
return window_size;
};
+Size2 OS_OSX::get_real_window_size() const {
+
+ NSRect frame = [window_object frame];
+ return Size2(frame.size.width, frame.size.height);
+}
+
void OS_OSX::set_window_size(const Size2 p_size) {
Size2 size = p_size;
@@ -2322,6 +2368,20 @@ OS_OSX::OS_OSX() {
Vector<Logger *> loggers;
loggers.push_back(memnew(OSXTerminalLogger));
_set_logger(memnew(CompositeLogger(loggers)));
+
+ //process application:openFile: event
+ while (true) {
+ NSEvent *event = [NSApp
+ nextEventMatchingMask:NSEventMaskAny
+ untilDate:[NSDate distantPast]
+ inMode:NSDefaultRunLoopMode
+ dequeue:YES];
+
+ if (event == nil)
+ break;
+
+ [NSApp sendEvent:event];
+ }
}
bool OS_OSX::_check_internal_feature_support(const String &p_feature) {