summaryrefslogtreecommitdiff
path: root/platform/osx
diff options
context:
space:
mode:
Diffstat (limited to 'platform/osx')
-rw-r--r--platform/osx/SCsub2
-rw-r--r--platform/osx/crash_handler_osx.h2
-rw-r--r--platform/osx/crash_handler_osx.mm4
-rw-r--r--platform/osx/export/export.cpp4
-rw-r--r--platform/osx/os_osx.h5
-rw-r--r--platform/osx/os_osx.mm106
-rw-r--r--platform/osx/power_osx.cpp16
-rw-r--r--platform/osx/power_osx.h13
-rw-r--r--platform/osx/semaphore_osx.cpp (renamed from platform/osx/sem_osx.cpp)5
-rw-r--r--platform/osx/semaphore_osx.h (renamed from platform/osx/sem_osx.h)8
10 files changed, 108 insertions, 57 deletions
diff --git a/platform/osx/SCsub b/platform/osx/SCsub
index dc407eee9e..d2952ebdc0 100644
--- a/platform/osx/SCsub
+++ b/platform/osx/SCsub
@@ -10,7 +10,7 @@ files = [
'crash_handler_osx.mm',
'os_osx.mm',
'godot_main_osx.mm',
- 'sem_osx.cpp',
+ 'semaphore_osx.cpp',
'dir_access_osx.mm',
'joypad_osx.cpp',
'power_osx.cpp',
diff --git a/platform/osx/crash_handler_osx.h b/platform/osx/crash_handler_osx.h
index dead90ca90..6a72ce8ae9 100644
--- a/platform/osx/crash_handler_osx.h
+++ b/platform/osx/crash_handler_osx.h
@@ -45,4 +45,4 @@ public:
~CrashHandler();
};
-#endif
+#endif // CRASH_HANDLER_OSX_H
diff --git a/platform/osx/crash_handler_osx.mm b/platform/osx/crash_handler_osx.mm
index 6684898085..ed8a955ae5 100644
--- a/platform/osx/crash_handler_osx.mm
+++ b/platform/osx/crash_handler_osx.mm
@@ -28,9 +28,11 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+#include "crash_handler_osx.h"
+
+#include "core/os/os.h"
#include "core/project_settings.h"
#include "main/main.h"
-#include "os_osx.h"
#include <string.h>
#include <unistd.h>
diff --git a/platform/osx/export/export.cpp b/platform/osx/export/export.cpp
index b8f6977b39..5e94bc457b 100644
--- a/platform/osx/export/export.cpp
+++ b/platform/osx/export/export.cpp
@@ -425,6 +425,10 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
}
}
+ if (!DirAccess::exists(p_path.get_base_dir())) {
+ return ERR_FILE_BAD_PATH;
+ }
+
FileAccess *src_f = NULL;
zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h
index 927c8c9b00..dfe7b27bd0 100644
--- a/platform/osx/os_osx.h
+++ b/platform/osx/os_osx.h
@@ -34,7 +34,7 @@
#include "core/os/input.h"
#include "crash_handler_osx.h"
#include "drivers/coreaudio/audio_driver_coreaudio.h"
-#include "drivers/coremidi/core_midi.h"
+#include "drivers/coremidi/midi_driver_coremidi.h"
#include "drivers/unix/os_unix.h"
#include "joypad_osx.h"
#include "main/input_default.h"
@@ -43,6 +43,7 @@
#include "servers/visual/rasterizer.h"
#include "servers/visual/visual_server_wrap_mt.h"
#include "servers/visual_server.h"
+
#include <AppKit/AppKit.h>
#include <AppKit/NSCursor.h>
#include <ApplicationServices/ApplicationServices.h>
@@ -132,7 +133,7 @@ public:
String im_text;
Point2 im_selection;
- power_osx *power_manager;
+ PowerOSX *power_manager;
CrashHandler crash_handler;
diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm
index 3f80d19fa1..7d2116ba7e 100644
--- a/platform/osx/os_osx.mm
+++ b/platform/osx/os_osx.mm
@@ -37,7 +37,7 @@
#include "drivers/gles2/rasterizer_gles2.h"
#include "drivers/gles3/rasterizer_gles3.h"
#include "main/main.h"
-#include "sem_osx.h"
+#include "semaphore_osx.h"
#include "servers/visual/visual_server_raster.h"
#include <mach-o/dyld.h>
@@ -102,8 +102,6 @@ static void push_to_key_event_buffer(const OS_OSX::KeyEvent &p_event) {
static int mouse_x = 0;
static int mouse_y = 0;
-static int prev_mouse_x = 0;
-static int prev_mouse_y = 0;
static int button_mask = 0;
static bool mouse_down_control = false;
@@ -282,7 +280,9 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
NSWindow *window = (NSWindow *)[notification object];
CGFloat newBackingScaleFactor = [window backingScaleFactor];
CGFloat oldBackingScaleFactor = [[[notification userInfo] objectForKey:@"NSBackingPropertyOldScaleFactorKey"] doubleValue];
- [OS_OSX::singleton->window_view setWantsBestResolutionOpenGLSurface:YES];
+ if (OS_OSX::singleton->is_hidpi_allowed()) {
+ [OS_OSX::singleton->window_view setWantsBestResolutionOpenGLSurface:YES];
+ }
if (newBackingScaleFactor != oldBackingScaleFactor) {
//Set new display scale and window size
@@ -599,12 +599,13 @@ static void _mouseDownEvent(NSEvent *event, int index, int mask, bool pressed) {
Ref<InputEventMouseButton> mb;
mb.instance();
-
+ const CGFloat backingScaleFactor = [[event window] backingScaleFactor];
+ const Vector2 pos = get_mouse_pos([event locationInWindow], backingScaleFactor);
get_key_modifier_state([event modifierFlags], mb);
mb->set_button_index(index);
mb->set_pressed(pressed);
- mb->set_position(Vector2(mouse_x, mouse_y));
- mb->set_global_position(Vector2(mouse_x, mouse_y));
+ mb->set_position(pos);
+ mb->set_global_position(pos);
mb->set_button_mask(button_mask);
if (index == BUTTON_LEFT && pressed) {
mb->set_doubleclick([event clickCount] == 2);
@@ -640,8 +641,6 @@ static void _mouseDownEvent(NSEvent *event, int index, int mask, bool pressed) {
mm.instance();
mm->set_button_mask(button_mask);
- prev_mouse_x = mouse_x;
- prev_mouse_y = mouse_y;
const CGFloat backingScaleFactor = [[event window] backingScaleFactor];
const Vector2 pos = get_mouse_pos([event locationInWindow], backingScaleFactor);
mm->set_position(pos);
@@ -763,9 +762,41 @@ static void _mouseDownEvent(NSEvent *event, int index, int mask, bool pressed) {
[super updateTrackingAreas];
}
+static bool isNumpadKey(unsigned int key) {
+
+ static const unsigned int table[] = {
+ 0x41, /* kVK_ANSI_KeypadDecimal */
+ 0x43, /* kVK_ANSI_KeypadMultiply */
+ 0x45, /* kVK_ANSI_KeypadPlus */
+ 0x47, /* kVK_ANSI_KeypadClear */
+ 0x4b, /* kVK_ANSI_KeypadDivide */
+ 0x4c, /* kVK_ANSI_KeypadEnter */
+ 0x4e, /* kVK_ANSI_KeypadMinus */
+ 0x51, /* kVK_ANSI_KeypadEquals */
+ 0x52, /* kVK_ANSI_Keypad0 */
+ 0x53, /* kVK_ANSI_Keypad1 */
+ 0x54, /* kVK_ANSI_Keypad2 */
+ 0x55, /* kVK_ANSI_Keypad3 */
+ 0x56, /* kVK_ANSI_Keypad4 */
+ 0x57, /* kVK_ANSI_Keypad5 */
+ 0x58, /* kVK_ANSI_Keypad6 */
+ 0x59, /* kVK_ANSI_Keypad7 */
+ 0x5b, /* kVK_ANSI_Keypad8 */
+ 0x5c, /* kVK_ANSI_Keypad9 */
+ 0x5f, /* kVK_JIS_KeypadComma */
+ 0x00
+ };
+ for (int i = 0; table[i] != 0; i++) {
+ if (key == table[i])
+ return true;
+ }
+ return false;
+}
+
// Translates a OS X keycode to a Godot keycode
//
static int translateKey(unsigned int key) {
+
// Keyboard symbol translation table
static const unsigned int table[128] = {
/* 00 */ KEY_A,
@@ -778,7 +809,7 @@ static int translateKey(unsigned int key) {
/* 07 */ KEY_X,
/* 08 */ KEY_C,
/* 09 */ KEY_V,
- /* 0a */ KEY_UNKNOWN,
+ /* 0a */ KEY_SECTION, /* ISO Section */
/* 0b */ KEY_B,
/* 0c */ KEY_Q,
/* 0d */ KEY_W,
@@ -832,7 +863,7 @@ static int translateKey(unsigned int key) {
/* 3d */ KEY_ALT,
/* 3e */ KEY_CONTROL,
/* 3f */ KEY_UNKNOWN, /* Function */
- /* 40 */ KEY_UNKNOWN,
+ /* 40 */ KEY_UNKNOWN, /* F17 */
/* 41 */ KEY_KP_PERIOD,
/* 42 */ KEY_UNKNOWN,
/* 43 */ KEY_KP_MULTIPLY,
@@ -840,16 +871,16 @@ static int translateKey(unsigned int key) {
/* 45 */ KEY_KP_ADD,
/* 46 */ KEY_UNKNOWN,
/* 47 */ KEY_NUMLOCK, /* Really KeypadClear... */
- /* 48 */ KEY_UNKNOWN, /* VolumeUp */
- /* 49 */ KEY_UNKNOWN, /* VolumeDown */
- /* 4a */ KEY_UNKNOWN, /* Mute */
+ /* 48 */ KEY_VOLUMEUP, /* VolumeUp */
+ /* 49 */ KEY_VOLUMEDOWN, /* VolumeDown */
+ /* 4a */ KEY_VOLUMEMUTE, /* Mute */
/* 4b */ KEY_KP_DIVIDE,
/* 4c */ KEY_KP_ENTER,
/* 4d */ KEY_UNKNOWN,
/* 4e */ KEY_KP_SUBTRACT,
- /* 4f */ KEY_UNKNOWN,
- /* 50 */ KEY_UNKNOWN,
- /* 51 */ KEY_EQUAL, //wtf equal?
+ /* 4f */ KEY_UNKNOWN, /* F18 */
+ /* 50 */ KEY_UNKNOWN, /* F19 */
+ /* 51 */ KEY_EQUAL, /* KeypadEqual */
/* 52 */ KEY_KP_0,
/* 53 */ KEY_KP_1,
/* 54 */ KEY_KP_2,
@@ -858,27 +889,27 @@ static int translateKey(unsigned int key) {
/* 57 */ KEY_KP_5,
/* 58 */ KEY_KP_6,
/* 59 */ KEY_KP_7,
- /* 5a */ KEY_UNKNOWN,
+ /* 5a */ KEY_UNKNOWN, /* F20 */
/* 5b */ KEY_KP_8,
/* 5c */ KEY_KP_9,
- /* 5d */ KEY_UNKNOWN,
- /* 5e */ KEY_UNKNOWN,
- /* 5f */ KEY_UNKNOWN,
+ /* 5d */ KEY_YEN, /* JIS Yen */
+ /* 5e */ KEY_UNDERSCORE, /* JIS Underscore */
+ /* 5f */ KEY_COMMA, /* JIS KeypadComma */
/* 60 */ KEY_F5,
/* 61 */ KEY_F6,
/* 62 */ KEY_F7,
/* 63 */ KEY_F3,
/* 64 */ KEY_F8,
/* 65 */ KEY_F9,
- /* 66 */ KEY_UNKNOWN,
+ /* 66 */ KEY_UNKNOWN, /* JIS Eisu */
/* 67 */ KEY_F11,
- /* 68 */ KEY_UNKNOWN,
+ /* 68 */ KEY_UNKNOWN, /* JIS Kana */
/* 69 */ KEY_F13,
/* 6a */ KEY_F16,
/* 6b */ KEY_F14,
/* 6c */ KEY_UNKNOWN,
/* 6d */ KEY_F10,
- /* 6e */ KEY_UNKNOWN,
+ /* 6e */ KEY_MENU,
/* 6f */ KEY_F12,
/* 70 */ KEY_UNKNOWN,
/* 71 */ KEY_F15,
@@ -969,6 +1000,9 @@ static const _KeyCodeMap _keycodes[55] = {
static int remapKey(unsigned int key) {
+ if (isNumpadKey(key))
+ return translateKey(key);
+
TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardInputSource();
if (!currentKeyboard)
return translateKey(key);
@@ -1094,6 +1128,7 @@ static int remapKey(unsigned int key) {
inline void sendScrollEvent(int button, double factor, int modifierFlags) {
unsigned int mask = 1 << (button - 1);
+ Vector2 mouse_pos = Vector2(mouse_x, mouse_y);
Ref<InputEventMouseButton> sc;
sc.instance();
@@ -1102,14 +1137,18 @@ inline void sendScrollEvent(int button, double factor, int modifierFlags) {
sc->set_button_index(button);
sc->set_factor(factor);
sc->set_pressed(true);
- Vector2 mouse_pos = Vector2(mouse_x, mouse_y);
sc->set_position(mouse_pos);
sc->set_global_position(mouse_pos);
button_mask |= mask;
sc->set_button_mask(button_mask);
OS_OSX::singleton->push_input(sc);
+ sc.instance();
+ sc->set_button_index(button);
+ sc->set_factor(factor);
sc->set_pressed(false);
+ sc->set_position(mouse_pos);
+ sc->set_global_position(mouse_pos);
button_mask &= ~mask;
sc->set_button_mask(button_mask);
OS_OSX::singleton->push_input(sc);
@@ -1418,7 +1457,7 @@ Error OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
RasterizerGLES3::make_current();
break;
} else {
- if (GLOBAL_GET("rendering/quality/driver/driver_fallback") == "Best" || editor) {
+ if (GLOBAL_GET("rendering/quality/driver/fallback_to_gles2") || editor) {
p_video_driver = VIDEO_DRIVER_GLES2;
gles3 = false;
continue;
@@ -1459,7 +1498,7 @@ Error OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
input = memnew(InputDefault);
joypad_osx = memnew(JoypadOSX);
- power_manager = memnew(power_osx);
+ power_manager = memnew(PowerOSX);
_ensure_user_data_dir();
@@ -2231,12 +2270,12 @@ Size2 OS_OSX::get_window_size() const {
Size2 OS_OSX::get_real_window_size() const {
NSRect frame = [window_object frame];
- return Size2(frame.size.width, frame.size.height);
+ return Size2(frame.size.width, frame.size.height) * _display_scale();
}
void OS_OSX::set_window_size(const Size2 p_size) {
- Size2 size = p_size;
+ Size2 size = p_size / _display_scale();
if (get_borderless_window() == false) {
// NSRect used by setFrame includes the title bar, so add it to our size.y
@@ -2322,7 +2361,8 @@ bool OS_OSX::is_window_maximized() const {
void OS_OSX::move_window_to_foreground() {
- [window_object orderFrontRegardless];
+ [[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
+ [window_object makeKeyAndOrderFront:nil];
}
void OS_OSX::set_window_always_on_top(bool p_enabled) {
@@ -2526,6 +2566,8 @@ void OS_OSX::process_events() {
[autoreleasePool drain];
autoreleasePool = [[NSAutoreleasePool alloc] init];
+
+ input->flush_accumulated_events();
}
void OS_OSX::process_key_events() {
@@ -2568,7 +2610,7 @@ void OS_OSX::process_key_events() {
void OS_OSX::push_input(const Ref<InputEvent> &p_event) {
Ref<InputEvent> ev = p_event;
- input->parse_input_event(ev);
+ input->accumulate_input_event(ev);
}
void OS_OSX::force_process_input() {
@@ -2809,7 +2851,7 @@ OS_OSX::OS_OSX() {
}
bool OS_OSX::_check_internal_feature_support(const String &p_feature) {
- return p_feature == "pc" || p_feature == "s3tc";
+ return p_feature == "pc";
}
void OS_OSX::disable_crash_handler() {
diff --git a/platform/osx/power_osx.cpp b/platform/osx/power_osx.cpp
index a7cf9d831f..04d423d8c5 100644
--- a/platform/osx/power_osx.cpp
+++ b/platform/osx/power_osx.cpp
@@ -67,7 +67,7 @@ Adapted from corresponding SDL 2.0 code.
CFDictionaryGetValueIfPresent(dict, CFSTR(k), (const void **)v)
/* Note that AC power sources also include a laptop battery it is charging. */
-void power_osx::checkps(CFDictionaryRef dict, bool *have_ac, bool *have_battery, bool *charging) {
+void PowerOSX::checkps(CFDictionaryRef dict, bool *have_ac, bool *have_battery, bool *charging) {
CFStringRef strval; /* don't CFRelease() this. */
CFBooleanRef bval;
CFNumberRef numval;
@@ -169,7 +169,7 @@ void power_osx::checkps(CFDictionaryRef dict, bool *have_ac, bool *have_battery,
#undef STRMATCH
// CODE CHUNK IMPORTED FROM SDL 2.0
-bool power_osx::GetPowerInfo_MacOSX() {
+bool PowerOSX::GetPowerInfo_MacOSX() {
CFTypeRef blob = IOPSCopyPowerSourcesInfo();
nsecs_left = -1;
@@ -211,14 +211,14 @@ bool power_osx::GetPowerInfo_MacOSX() {
return true; /* always the definitive answer on Mac OS X. */
}
-bool power_osx::UpdatePowerInfo() {
+bool PowerOSX::UpdatePowerInfo() {
if (GetPowerInfo_MacOSX()) {
return true;
}
return false;
}
-OS::PowerState power_osx::get_power_state() {
+OS::PowerState PowerOSX::get_power_state() {
if (UpdatePowerInfo()) {
return power_state;
} else {
@@ -226,7 +226,7 @@ OS::PowerState power_osx::get_power_state() {
}
}
-int power_osx::get_power_seconds_left() {
+int PowerOSX::get_power_seconds_left() {
if (UpdatePowerInfo()) {
return nsecs_left;
} else {
@@ -234,7 +234,7 @@ int power_osx::get_power_seconds_left() {
}
}
-int power_osx::get_power_percent_left() {
+int PowerOSX::get_power_percent_left() {
if (UpdatePowerInfo()) {
return percent_left;
} else {
@@ -242,11 +242,11 @@ int power_osx::get_power_percent_left() {
}
}
-power_osx::power_osx() :
+PowerOSX::PowerOSX() :
nsecs_left(-1),
percent_left(-1),
power_state(OS::POWERSTATE_UNKNOWN) {
}
-power_osx::~power_osx() {
+PowerOSX::~PowerOSX() {
}
diff --git a/platform/osx/power_osx.h b/platform/osx/power_osx.h
index 0f18f9f691..40d0d40fd4 100644
--- a/platform/osx/power_osx.h
+++ b/platform/osx/power_osx.h
@@ -28,15 +28,16 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifndef PLATFORM_OSX_POWER_OSX_H_
-#define PLATFORM_OSX_POWER_OSX_H_
+#ifndef POWER_OSX_H
+#define POWER_OSX_H
#include "core/os/file_access.h"
#include "core/os/os.h"
#include "dir_access_osx.h"
+
#include <CoreFoundation/CoreFoundation.h>
-class power_osx {
+class PowerOSX {
private:
int nsecs_left;
@@ -47,12 +48,12 @@ private:
bool UpdatePowerInfo();
public:
- power_osx();
- virtual ~power_osx();
+ PowerOSX();
+ virtual ~PowerOSX();
OS::PowerState get_power_state();
int get_power_seconds_left();
int get_power_percent_left();
};
-#endif /* PLATFORM_OSX_POWER_OSX_H_ */
+#endif // POWER_OSX_H
diff --git a/platform/osx/sem_osx.cpp b/platform/osx/semaphore_osx.cpp
index 4c3bad4379..fe7d19bd9e 100644
--- a/platform/osx/sem_osx.cpp
+++ b/platform/osx/semaphore_osx.cpp
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* sem_osx.cpp */
+/* semaphore_osx.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -28,7 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "sem_osx.h"
+#include "semaphore_osx.h"
#include <fcntl.h>
#include <unistd.h>
@@ -66,6 +66,7 @@ void cgsem_destroy(cgsem_t *cgsem) {
}
#include "core/os/memory.h"
+
#include <errno.h>
Error SemaphoreOSX::wait() {
diff --git a/platform/osx/sem_osx.h b/platform/osx/semaphore_osx.h
index 563bdfdcb1..c8e7c45227 100644
--- a/platform/osx/sem_osx.h
+++ b/platform/osx/semaphore_osx.h
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* sem_osx.h */
+/* semaphore_osx.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -28,8 +28,8 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifndef SEM_OSX_H
-#define SEM_OSX_H
+#ifndef SEMAPHORE_OSX_H
+#define SEMAPHORE_OSX_H
struct cgsem {
int pipefd[2];
@@ -56,4 +56,4 @@ public:
~SemaphoreOSX();
};
-#endif
+#endif // SEMAPHORE_OSX_H