summaryrefslogtreecommitdiff
path: root/platform/osx
diff options
context:
space:
mode:
Diffstat (limited to 'platform/osx')
-rw-r--r--platform/osx/SCsub1
-rw-r--r--platform/osx/detect.py6
-rw-r--r--platform/osx/joypad_osx.cpp20
-rw-r--r--platform/osx/joypad_osx.h3
-rw-r--r--platform/osx/os_osx.h3
-rw-r--r--platform/osx/os_osx.mm39
-rw-r--r--platform/osx/semaphore_osx.cpp107
-rw-r--r--platform/osx/semaphore_osx.h59
8 files changed, 43 insertions, 195 deletions
diff --git a/platform/osx/SCsub b/platform/osx/SCsub
index d764ac4b50..0a4e0a45e1 100644
--- a/platform/osx/SCsub
+++ b/platform/osx/SCsub
@@ -9,7 +9,6 @@ files = [
'crash_handler_osx.mm',
'os_osx.mm',
'godot_main_osx.mm',
- 'semaphore_osx.cpp',
'dir_access_osx.mm',
'joypad_osx.cpp',
'vulkan_context_osx.mm',
diff --git a/platform/osx/detect.py b/platform/osx/detect.py
index 12ca5c10dc..b2f4032f66 100644
--- a/platform/osx/detect.py
+++ b/platform/osx/detect.py
@@ -151,13 +151,13 @@ def configure(env):
env.Prepend(CPPPATH=['#platform/osx'])
env.Append(CPPDEFINES=['OSX_ENABLED', 'UNIX_ENABLED', 'APPLE_STYLE_KEYS', 'COREAUDIO_ENABLED', 'COREMIDI_ENABLED'])
- env.Append(LINKFLAGS=['-framework', 'Cocoa', '-framework', 'Carbon', '-framework', 'AudioUnit', '-framework', 'CoreAudio', '-framework', 'CoreMIDI', '-framework', 'IOKit', '-framework', 'ForceFeedback', '-framework', 'CoreVideo', '-framework', 'AVFoundation', '-framework', 'CoreMedia'])
+ env.AppendUnique(FRAMEWORKS=['Cocoa', 'Carbon', 'AudioUnit', 'CoreAudio', 'CoreMIDI', 'IOKit', 'ForceFeedback', 'CoreVideo', 'AVFoundation', 'CoreMedia'])
env.Append(LIBS=['pthread', 'z'])
env.Append(CPPDEFINES=['VULKAN_ENABLED'])
- env.Append(LINKFLAGS=['-framework', 'Metal', '-framework', 'QuartzCore', '-framework', 'IOSurface'])
+ env.AppendUnique(FRAMEWORKS=['Metal', 'QuartzCore', 'IOSurface'])
if (env['use_static_mvk']):
- env.Append(LINKFLAGS=['-framework', 'MoltenVK'])
+ env.AppendUnique(FRAMEWORKS=['MoltenVK'])
env['builtin_vulkan'] = False
elif not env['builtin_vulkan']:
env.Append(LIBS=['vulkan'])
diff --git a/platform/osx/joypad_osx.cpp b/platform/osx/joypad_osx.cpp
index 13ece678f3..e9f46fb5a4 100644
--- a/platform/osx/joypad_osx.cpp
+++ b/platform/osx/joypad_osx.cpp
@@ -208,9 +208,8 @@ void joypad::add_hid_elements(CFArrayRef p_array) {
CFArrayApplyFunction(p_array, range, hid_element_added, this);
}
-static void joypad_removed_callback(void *ctx, IOReturn result, void *sender) {
- int id = (intptr_t)ctx;
- self->_device_removed(id);
+static void joypad_removed_callback(void *ctx, IOReturn res, void *sender, IOHIDDeviceRef ioHIDDeviceObject) {
+ self->_device_removed(res, ioHIDDeviceObject);
}
static void joypad_added_callback(void *ctx, IOReturn res, void *sender, IOHIDDeviceRef ioHIDDeviceObject) {
@@ -261,16 +260,15 @@ void JoypadOSX::_device_added(IOReturn p_res, IOHIDDeviceRef p_device) {
#endif
device_list.push_back(new_joypad);
}
- IOHIDDeviceRegisterRemovalCallback(p_device, joypad_removed_callback, (void *)(intptr_t)new_joypad.id);
IOHIDDeviceScheduleWithRunLoop(p_device, CFRunLoopGetCurrent(), GODOT_JOY_LOOP_RUN_MODE);
}
-void JoypadOSX::_device_removed(int p_id) {
+void JoypadOSX::_device_removed(IOReturn p_res, IOHIDDeviceRef p_device) {
- int device = get_joy_index(p_id);
+ int device = get_joy_ref(p_device);
ERR_FAIL_COND(device == -1);
- input->joy_connection_changed(p_id, false, "");
+ input->joy_connection_changed(device_list[device].id, false, "");
device_list.write[device].free();
device_list.remove(device);
}
@@ -516,6 +514,13 @@ int JoypadOSX::get_joy_index(int p_id) const {
return -1;
}
+int JoypadOSX::get_joy_ref(IOHIDDeviceRef p_device) const {
+ for (int i = 0; i < device_list.size(); i++) {
+ if (device_list[i].device_ref == p_device) return i;
+ }
+ return -1;
+}
+
bool JoypadOSX::have_device(IOHIDDeviceRef p_device) const {
for (int i = 0; i < device_list.size(); i++) {
if (device_list[i].device_ref == p_device) {
@@ -558,6 +563,7 @@ void JoypadOSX::config_hid_manager(CFArrayRef p_matching_array) const {
IOHIDManagerSetDeviceMatchingMultiple(hid_manager, p_matching_array);
IOHIDManagerRegisterDeviceMatchingCallback(hid_manager, joypad_added_callback, NULL);
+ IOHIDManagerRegisterDeviceRemovalCallback(hid_manager, joypad_removed_callback, NULL);
IOHIDManagerScheduleWithRunLoop(hid_manager, runloop, GODOT_JOY_LOOP_RUN_MODE);
while (CFRunLoopRunInMode(GODOT_JOY_LOOP_RUN_MODE, 0, TRUE) == kCFRunLoopRunHandledSource) {
diff --git a/platform/osx/joypad_osx.h b/platform/osx/joypad_osx.h
index 388251016b..2c076b3680 100644
--- a/platform/osx/joypad_osx.h
+++ b/platform/osx/joypad_osx.h
@@ -103,6 +103,7 @@ private:
bool configure_joypad(IOHIDDeviceRef p_device_ref, joypad *p_joy);
int get_joy_index(int p_id) const;
+ int get_joy_ref(IOHIDDeviceRef p_device) const;
void poll_joypads() const;
void setup_joypad_objects();
@@ -115,7 +116,7 @@ public:
void process_joypads();
void _device_added(IOReturn p_res, IOHIDDeviceRef p_device);
- void _device_removed(int p_id);
+ void _device_removed(IOReturn p_res, IOHIDDeviceRef p_device);
JoypadOSX();
~JoypadOSX();
diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h
index 75a56bd82c..3140d9bac4 100644
--- a/platform/osx/os_osx.h
+++ b/platform/osx/os_osx.h
@@ -69,7 +69,8 @@ public:
bool pressed;
bool echo;
bool raw;
- uint32_t scancode;
+ uint32_t keycode;
+ uint32_t physical_keycode;
uint32_t unicode;
};
diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm
index f2e5f9369c..4c70beee00 100644
--- a/platform/osx/os_osx.mm
+++ b/platform/osx/os_osx.mm
@@ -44,7 +44,6 @@
#endif
#include "main/main.h"
-#include "semaphore_osx.h"
#include "servers/visual/visual_server_raster.h"
#include "servers/visual/visual_server_wrap_mt.h"
@@ -157,7 +156,8 @@ static NSCursor *cursorFromSelector(SEL selector, SEL fallback = nil) {
get_key_modifier_state([event modifierFlags], k);
k->set_pressed(true);
- k->set_scancode(KEY_PERIOD);
+ k->set_keycode(KEY_PERIOD);
+ k->set_physical_keycode(KEY_PERIOD);
k->set_echo([event isARepeat]);
OS_OSX::singleton->push_input(k);
@@ -635,7 +635,8 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
ke.pressed = true;
ke.echo = false;
ke.raw = false; // IME input event
- ke.scancode = 0;
+ ke.keycode = 0;
+ ke.physical_keycode = 0;
ke.unicode = codepoint;
push_to_key_event_buffer(ke);
@@ -1158,7 +1159,8 @@ static int remapKey(unsigned int key, unsigned int state) {
ke.osx_state = [event modifierFlags];
ke.pressed = true;
ke.echo = [event isARepeat];
- ke.scancode = remapKey([event keyCode], [event modifierFlags]);
+ ke.keycode = remapKey([event keyCode], [event modifierFlags]);
+ ke.physical_keycode = translateKey([event keyCode]);
ke.raw = true;
ke.unicode = [characters characterAtIndex:i];
@@ -1170,7 +1172,8 @@ static int remapKey(unsigned int key, unsigned int state) {
ke.osx_state = [event modifierFlags];
ke.pressed = true;
ke.echo = [event isARepeat];
- ke.scancode = remapKey([event keyCode], [event modifierFlags]);
+ ke.keycode = remapKey([event keyCode], [event modifierFlags]);
+ ke.physical_keycode = translateKey([event keyCode]);
ke.raw = false;
ke.unicode = 0;
@@ -1228,7 +1231,8 @@ static int remapKey(unsigned int key, unsigned int state) {
}
ke.osx_state = mod;
- ke.scancode = remapKey(key, mod);
+ ke.keycode = remapKey(key, mod);
+ ke.physical_keycode = translateKey(key);
ke.unicode = 0;
push_to_key_event_buffer(ke);
@@ -1250,7 +1254,8 @@ static int remapKey(unsigned int key, unsigned int state) {
ke.osx_state = [event modifierFlags];
ke.pressed = false;
ke.echo = [event isARepeat];
- ke.scancode = remapKey([event keyCode], [event modifierFlags]);
+ ke.keycode = remapKey([event keyCode], [event modifierFlags]);
+ ke.physical_keycode = translateKey([event keyCode]);
ke.raw = true;
ke.unicode = [characters characterAtIndex:i];
@@ -1262,7 +1267,8 @@ static int remapKey(unsigned int key, unsigned int state) {
ke.osx_state = [event modifierFlags];
ke.pressed = false;
ke.echo = [event isARepeat];
- ke.scancode = remapKey([event keyCode], [event modifierFlags]);
+ ke.keycode = remapKey([event keyCode], [event modifierFlags]);
+ ke.physical_keycode = translateKey([event keyCode]);
ke.raw = true;
ke.unicode = 0;
@@ -1457,8 +1463,6 @@ void OS_OSX::initialize_core() {
DirAccess::make_default<DirAccessOSX>(DirAccess::ACCESS_RESOURCES);
DirAccess::make_default<DirAccessOSX>(DirAccess::ACCESS_USERDATA);
DirAccess::make_default<DirAccessOSX>(DirAccess::ACCESS_FILESYSTEM);
-
- SemaphoreOSX::make_default();
}
static bool keyboard_layout_dirty = true;
@@ -2845,32 +2849,35 @@ void OS_OSX::process_key_events() {
get_key_modifier_state(ke.osx_state, k);
k->set_pressed(ke.pressed);
k->set_echo(ke.echo);
- k->set_scancode(ke.scancode);
+ k->set_keycode(ke.keycode);
+ k->set_physical_keycode(ke.physical_keycode);
k->set_unicode(ke.unicode);
push_input(k);
} else {
// IME input
- if ((i == 0 && ke.scancode == 0) || (i > 0 && key_event_buffer[i - 1].scancode == 0)) {
+ if ((i == 0 && ke.keycode == 0) || (i > 0 && key_event_buffer[i - 1].keycode == 0)) {
k.instance();
get_key_modifier_state(ke.osx_state, k);
k->set_pressed(ke.pressed);
k->set_echo(ke.echo);
- k->set_scancode(0);
+ k->set_keycode(0);
+ k->set_physical_keycode(0);
k->set_unicode(ke.unicode);
push_input(k);
}
- if (ke.scancode != 0) {
+ if (ke.keycode != 0) {
k.instance();
get_key_modifier_state(ke.osx_state, k);
k->set_pressed(ke.pressed);
k->set_echo(ke.echo);
- k->set_scancode(ke.scancode);
+ k->set_keycode(ke.keycode);
+ k->set_physical_keycode(ke.physical_keycode);
- if (i + 1 < key_event_pos && key_event_buffer[i + 1].scancode == 0) {
+ if (i + 1 < key_event_pos && key_event_buffer[i + 1].keycode == 0) {
k->set_unicode(key_event_buffer[i + 1].unicode);
}
diff --git a/platform/osx/semaphore_osx.cpp b/platform/osx/semaphore_osx.cpp
deleted file mode 100644
index e4e5991637..0000000000
--- a/platform/osx/semaphore_osx.cpp
+++ /dev/null
@@ -1,107 +0,0 @@
-/*************************************************************************/
-/* semaphore_osx.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-
-#include "semaphore_osx.h"
-
-#include <fcntl.h>
-#include <unistd.h>
-
-void cgsem_init(cgsem_t *cgsem) {
- int flags, fd, i;
-
- pipe(cgsem->pipefd);
-
- /* Make the pipes FD_CLOEXEC to allow them to close should we call
- * execv on restart. */
- for (i = 0; i < 2; i++) {
- fd = cgsem->pipefd[i];
- flags = fcntl(fd, F_GETFD, 0);
- flags |= FD_CLOEXEC;
- fcntl(fd, F_SETFD, flags);
- }
-}
-
-void cgsem_post(cgsem_t *cgsem) {
- const char buf = 1;
-
- write(cgsem->pipefd[1], &buf, 1);
-}
-
-void cgsem_wait(cgsem_t *cgsem) {
- char buf;
-
- read(cgsem->pipefd[0], &buf, 1);
-}
-
-void cgsem_destroy(cgsem_t *cgsem) {
- close(cgsem->pipefd[1]);
- close(cgsem->pipefd[0]);
-}
-
-#include "core/os/memory.h"
-
-#include <errno.h>
-
-Error SemaphoreOSX::wait() {
-
- cgsem_wait(&sem);
- return OK;
-}
-
-Error SemaphoreOSX::post() {
-
- cgsem_post(&sem);
-
- return OK;
-}
-int SemaphoreOSX::get() const {
-
- return 0;
-}
-
-SemaphoreOld *SemaphoreOSX::create_semaphore_osx() {
-
- return memnew(SemaphoreOSX);
-}
-
-void SemaphoreOSX::make_default() {
-
- create_func = create_semaphore_osx;
-}
-
-SemaphoreOSX::SemaphoreOSX() {
-
- cgsem_init(&sem);
-}
-
-SemaphoreOSX::~SemaphoreOSX() {
-
- cgsem_destroy(&sem);
-}
diff --git a/platform/osx/semaphore_osx.h b/platform/osx/semaphore_osx.h
deleted file mode 100644
index 9aa2b47bc8..0000000000
--- a/platform/osx/semaphore_osx.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*************************************************************************/
-/* semaphore_osx.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-
-#ifndef SEMAPHORE_OSX_H
-#define SEMAPHORE_OSX_H
-
-struct cgsem {
- int pipefd[2];
-};
-
-typedef struct cgsem cgsem_t;
-
-#include "core/os/semaphore.h"
-
-class SemaphoreOSX : public SemaphoreOld {
-
- mutable cgsem_t sem;
-
- static SemaphoreOld *create_semaphore_osx();
-
-public:
- virtual Error wait();
- virtual Error post();
- virtual int get() const;
-
- static void make_default();
- SemaphoreOSX();
-
- ~SemaphoreOSX();
-};
-
-#endif // SEMAPHORE_OSX_H