summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
Diffstat (limited to 'platform')
-rw-r--r--platform/haiku/key_mapping_haiku.cpp2
-rw-r--r--platform/javascript/dom_keys.h2
-rw-r--r--platform/javascript/os_javascript.cpp121
-rw-r--r--platform/javascript/os_javascript.h5
-rw-r--r--platform/osx/os_osx.mm15
-rw-r--r--platform/uwp/joypad_uwp.cpp75
-rw-r--r--platform/uwp/joypad_uwp.h8
-rw-r--r--platform/windows/key_mapping_win.cpp2
-rw-r--r--platform/windows/os_windows.cpp6
-rw-r--r--platform/x11/key_mapping_x11.cpp4
-rw-r--r--platform/x11/os_x11.cpp4
11 files changed, 151 insertions, 93 deletions
diff --git a/platform/haiku/key_mapping_haiku.cpp b/platform/haiku/key_mapping_haiku.cpp
index 9df7b2f047..3db31fa3e4 100644
--- a/platform/haiku/key_mapping_haiku.cpp
+++ b/platform/haiku/key_mapping_haiku.cpp
@@ -83,7 +83,7 @@ static _HaikuTranslatePair _fn_to_keycode[] = {
static _HaikuTranslatePair _hb_to_keycode[] = {
{ KEY_BACKSPACE, B_BACKSPACE },
{ KEY_TAB, B_TAB },
- { KEY_RETURN, B_RETURN },
+ { KEY_ENTER, B_RETURN },
{ KEY_CAPSLOCK, B_CAPS_LOCK },
{ KEY_ESCAPE, B_ESCAPE },
{ KEY_SPACE, B_SPACE },
diff --git a/platform/javascript/dom_keys.h b/platform/javascript/dom_keys.h
index 979731d157..4b8b764c45 100644
--- a/platform/javascript/dom_keys.h
+++ b/platform/javascript/dom_keys.h
@@ -249,7 +249,7 @@ int dom2godot_scancode(int dom_keycode) {
case DOM_VK_RETURN:
case DOM_VK_ENTER: // unused according to MDN
- return KEY_RETURN;
+ return KEY_ENTER;
case DOM_VK_SHIFT: return KEY_SHIFT;
case DOM_VK_CONTROL: return KEY_CONTROL;
diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp
index 0708d46196..5513fca809 100644
--- a/platform/javascript/os_javascript.cpp
+++ b/platform/javascript/os_javascript.cpp
@@ -96,30 +96,18 @@ static EM_BOOL _browser_resize_callback(int event_type, const EmscriptenUiEvent
ERR_FAIL_COND_V(event_type != EMSCRIPTEN_EVENT_RESIZE, false);
OS_JavaScript *os = static_cast<OS_JavaScript *>(user_data);
-
- // the order in which _browser_resize_callback and
- // _fullscreen_change_callback are called is browser-dependent,
- // so try adjusting for fullscreen in both
- if (os->is_window_fullscreen() || os->is_window_maximized()) {
-
- OS::VideoMode vm = os->get_video_mode();
- vm.width = ui_event->windowInnerWidth;
- vm.height = ui_event->windowInnerHeight;
- os->set_video_mode(vm);
- emscripten_set_canvas_size(ui_event->windowInnerWidth, ui_event->windowInnerHeight);
- }
+ // The order of the fullscreen change event and the window size change
+ // event varies, even within just one browser, so defer handling
+ os->request_canvas_size_adjustment();
return false;
}
-static Size2 _windowed_size;
-
static EM_BOOL _fullscreen_change_callback(int event_type, const EmscriptenFullscreenChangeEvent *event, void *user_data) {
ERR_FAIL_COND_V(event_type != EMSCRIPTEN_EVENT_FULLSCREENCHANGE, false);
OS_JavaScript *os = static_cast<OS_JavaScript *>(user_data);
String id = String::utf8(event->id);
-
// empty id is canvas
if (id.empty() || id == "canvas") {
@@ -127,18 +115,8 @@ static EM_BOOL _fullscreen_change_callback(int event_type, const EmscriptenFulls
// this event property is the only reliable information on
// browser fullscreen state
vm.fullscreen = event->isFullscreen;
-
- if (event->isFullscreen) {
- vm.width = event->screenWidth;
- vm.height = event->screenHeight;
- os->set_video_mode(vm);
- emscripten_set_canvas_size(vm.width, vm.height);
- } else {
- os->set_video_mode(vm);
- if (!os->is_window_maximized()) {
- os->set_window_size(_windowed_size);
- }
- }
+ os->set_video_mode(vm);
+ os->request_canvas_size_adjustment();
}
return false;
}
@@ -719,14 +697,17 @@ Size2 OS_JavaScript::get_screen_size(int p_screen) const {
void OS_JavaScript::set_window_size(const Size2 p_size) {
- window_maximized = false;
+ windowed_size = p_size;
if (is_window_fullscreen()) {
+ window_maximized = false;
set_window_fullscreen(false);
+ } else if (is_window_maximized()) {
+ set_window_maximized(false);
+ } else {
+ video_mode.width = p_size.x;
+ video_mode.height = p_size.y;
+ emscripten_set_canvas_size(p_size.x, p_size.y);
}
- _windowed_size = p_size;
- video_mode.width = p_size.x;
- video_mode.height = p_size.y;
- emscripten_set_canvas_size(p_size.x, p_size.y);
}
Size2 OS_JavaScript::get_window_size() const {
@@ -739,20 +720,30 @@ Size2 OS_JavaScript::get_window_size() const {
void OS_JavaScript::set_window_maximized(bool p_enabled) {
window_maximized = p_enabled;
- if (p_enabled) {
-
- if (is_window_fullscreen()) {
- // _browser_resize callback will set canvas size
- set_window_fullscreen(false);
- } else {
- /* clang-format off */
- video_mode.width = EM_ASM_INT_V(return window.innerWidth);
- video_mode.height = EM_ASM_INT_V(return window.innerHeight);
- /* clang-format on */
- emscripten_set_canvas_size(video_mode.width, video_mode.height);
- }
- } else {
- set_window_size(_windowed_size);
+ if (is_window_fullscreen()) {
+ set_window_fullscreen(false);
+ return;
+ }
+ // Calling emscripten_enter_soft_fullscreen mutltiple times hides all
+ // page elements except the canvas permanently, so track state
+ if (p_enabled && !soft_fs_enabled) {
+
+ EmscriptenFullscreenStrategy strategy;
+ strategy.scaleMode = EMSCRIPTEN_FULLSCREEN_SCALE_STRETCH;
+ strategy.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_STDDEF;
+ strategy.filteringMode = EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT;
+ strategy.canvasResizedCallback = NULL;
+ emscripten_enter_soft_fullscreen(NULL, &strategy);
+ soft_fs_enabled = true;
+ video_mode.width = get_window_size().width;
+ video_mode.height = get_window_size().height;
+ } else if (!p_enabled) {
+
+ emscripten_exit_soft_fullscreen();
+ soft_fs_enabled = false;
+ video_mode.width = windowed_size.width;
+ video_mode.height = windowed_size.height;
+ emscripten_set_canvas_size(video_mode.width, video_mode.height);
}
}
@@ -766,9 +757,17 @@ void OS_JavaScript::set_window_fullscreen(bool p_enable) {
// _browser_resize_callback or _fullscreen_change_callback
EMSCRIPTEN_RESULT result;
if (p_enable) {
- /* clang-format off */
- EM_ASM(Module.requestFullscreen(false, false););
- /* clang-format on */
+ if (window_maximized) {
+ // soft fs during real fs can cause issues
+ set_window_maximized(false);
+ window_maximized = true;
+ }
+ EmscriptenFullscreenStrategy strategy;
+ strategy.scaleMode = EMSCRIPTEN_FULLSCREEN_SCALE_STRETCH;
+ strategy.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_STDDEF;
+ strategy.filteringMode = EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT;
+ strategy.canvasResizedCallback = NULL;
+ emscripten_request_fullscreen_strategy(NULL, false, &strategy);
} else {
result = emscripten_exit_fullscreen();
if (result != EMSCRIPTEN_RESULT_SUCCESS) {
@@ -782,6 +781,11 @@ bool OS_JavaScript::is_window_fullscreen() const {
return video_mode.fullscreen;
}
+void OS_JavaScript::request_canvas_size_adjustment() {
+
+ canvas_size_adjustment_requested = true;
+}
+
void OS_JavaScript::get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen) const {
Size2 screen = get_screen_size();
@@ -841,6 +845,17 @@ bool OS_JavaScript::main_loop_iterate() {
}
}
process_joypads();
+ if (canvas_size_adjustment_requested) {
+
+ if (video_mode.fullscreen || window_maximized) {
+ video_mode.width = get_window_size().width;
+ video_mode.height = get_window_size().height;
+ }
+ if (!video_mode.fullscreen) {
+ set_window_maximized(window_maximized);
+ }
+ canvas_size_adjustment_requested = false;
+ }
return Main::iteration();
}
@@ -857,7 +872,11 @@ void OS_JavaScript::process_accelerometer(const Vector3 &p_accelerometer) {
bool OS_JavaScript::has_touchscreen_ui_hint() const {
- return false; //???
+ /* clang-format off */
+ return EM_ASM_INT_V(
+ return 'ontouchstart' in window;
+ );
+ /* clang-format on */
}
void OS_JavaScript::main_loop_request_quit() {
@@ -980,6 +999,8 @@ OS_JavaScript::OS_JavaScript(const char *p_execpath, GetDataDirFunc p_get_data_d
main_loop = NULL;
gl_extensions = NULL;
window_maximized = false;
+ soft_fs_enabled = false;
+ canvas_size_adjustment_requested = false;
get_data_dir_func = p_get_data_dir_func;
FileAccessUnix::close_notification_func = _close_notification_funcs;
diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h
index 24e96e20dd..13c500b3dc 100644
--- a/platform/javascript/os_javascript.h
+++ b/platform/javascript/os_javascript.h
@@ -59,7 +59,10 @@ class OS_JavaScript : public OS_Unix {
const char *gl_extensions;
InputDefault *input;
+ Vector2 windowed_size;
bool window_maximized;
+ bool soft_fs_enabled;
+ bool canvas_size_adjustment_requested;
VideoMode video_mode;
CursorShape cursor_shape;
MainLoop *main_loop;
@@ -130,6 +133,8 @@ public:
virtual void set_window_fullscreen(bool p_enable);
virtual bool is_window_fullscreen() const;
+ void request_canvas_size_adjustment();
+
virtual String get_name();
virtual MainLoop *get_main_loop() const;
diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm
index 4a01532d89..b45647b8bb 100644
--- a/platform/osx/os_osx.mm
+++ b/platform/osx/os_osx.mm
@@ -518,7 +518,7 @@ static int translateKey(unsigned int key) {
/* 21 */ KEY_BRACELEFT,
/* 22 */ KEY_I,
/* 23 */ KEY_P,
- /* 24 */ KEY_RETURN,
+ /* 24 */ KEY_ENTER,
/* 25 */ KEY_L,
/* 26 */ KEY_J,
/* 27 */ KEY_APOSTROPHE,
@@ -558,7 +558,7 @@ static int translateKey(unsigned int key) {
/* 49 */ KEY_UNKNOWN, /* VolumeDown */
/* 4a */ KEY_UNKNOWN, /* Mute */
/* 4b */ KEY_KP_DIVIDE,
- /* 4c */ KEY_ENTER,
+ /* 4c */ KEY_KP_ENTER,
/* 4d */ KEY_UNKNOWN,
/* 4e */ KEY_KP_SUBTRACT,
/* 4f */ KEY_UNKNOWN,
@@ -1081,18 +1081,13 @@ void OS_OSX::warp_mouse_pos(const Point2 &p_to) {
mouse_y = p_to.y;
} else { //set OS position
- /* this code has not been tested, please be a kind soul and fix it if it fails! */
-
//local point in window coords
- NSPoint localPoint = { p_to.x, p_to.y };
-
- NSPoint pointInWindow = [window_view convertPoint:localPoint toView:nil];
- NSRect pointInWindowRect;
- pointInWindowRect.origin = pointInWindow;
+ const NSRect contentRect = [window_view frame];
+ NSRect pointInWindowRect = NSMakeRect(p_to.x / display_scale, contentRect.size.height - (p_to.y / display_scale) - 1, 0, 0);
NSPoint pointOnScreen = [[window_view window] convertRectToScreen:pointInWindowRect].origin;
//point in scren coords
- CGPoint lMouseWarpPos = { pointOnScreen.x, pointOnScreen.y };
+ CGPoint lMouseWarpPos = { pointOnScreen.x, CGDisplayBounds(CGMainDisplayID()).size.height - pointOnScreen.y };
//do the warping
CGEventSourceRef lEventRef = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
diff --git a/platform/uwp/joypad_uwp.cpp b/platform/uwp/joypad_uwp.cpp
index 34e36f7b66..f3d4eb99c8 100644
--- a/platform/uwp/joypad_uwp.cpp
+++ b/platform/uwp/joypad_uwp.cpp
@@ -29,6 +29,7 @@
/*************************************************************************/
#include "joypad_uwp.h"
+#include "core/os/os.h"
using namespace Windows::Gaming::Input;
using namespace Windows::Foundation;
@@ -45,27 +46,44 @@ void JoypadUWP::process_controllers() {
for (int i = 0; i < MAX_CONTROLLERS; i++) {
- if (!controllers[i].connected) break;
+ ControllerDevice &joy = controllers[i];
- switch (controllers[i].type) {
+ if (!joy.connected) break;
+
+ switch (joy.type) {
case ControllerType::GAMEPAD_CONTROLLER: {
- GamepadReading reading = ((Gamepad ^)controllers[i].controller_reference)->GetCurrentReading();
+ GamepadReading reading = ((Gamepad ^) joy.controller_reference)->GetCurrentReading();
int button_mask = (int)GamepadButtons::Menu;
for (int j = 0; j < 14; j++) {
- input->joy_button(controllers[i].id, j, (int)reading.Buttons & button_mask);
+ input->joy_button(joy.id, j, (int)reading.Buttons & button_mask);
button_mask *= 2;
}
- input->joy_axis(controllers[i].id, JOY_AXIS_0, axis_correct(reading.LeftThumbstickX));
- input->joy_axis(controllers[i].id, JOY_AXIS_1, axis_correct(reading.LeftThumbstickY, true));
- input->joy_axis(controllers[i].id, JOY_AXIS_2, axis_correct(reading.RightThumbstickX));
- input->joy_axis(controllers[i].id, JOY_AXIS_3, axis_correct(reading.RightThumbstickY, true));
- input->joy_axis(controllers[i].id, JOY_AXIS_4, axis_correct(reading.LeftTrigger, false, true));
- input->joy_axis(controllers[i].id, JOY_AXIS_5, axis_correct(reading.RightTrigger, false, true));
+ input->joy_axis(joy.id, JOY_AXIS_0, axis_correct(reading.LeftThumbstickX));
+ input->joy_axis(joy.id, JOY_AXIS_1, axis_correct(reading.LeftThumbstickY, true));
+ input->joy_axis(joy.id, JOY_AXIS_2, axis_correct(reading.RightThumbstickX));
+ input->joy_axis(joy.id, JOY_AXIS_3, axis_correct(reading.RightThumbstickY, true));
+ input->joy_axis(joy.id, JOY_AXIS_4, axis_correct(reading.LeftTrigger, false, true));
+ input->joy_axis(joy.id, JOY_AXIS_5, axis_correct(reading.RightTrigger, false, true));
+
+ uint64_t timestamp = input->get_joy_vibration_timestamp(joy.id);
+ if (timestamp > joy.ff_timestamp) {
+ Vector2 strength = input->get_joy_vibration_strength(joy.id);
+ float duration = input->get_joy_vibration_duration(joy.id);
+ if (strength.x == 0 && strength.y == 0) {
+ joypad_vibration_stop(i, timestamp);
+ } else {
+ joypad_vibration_start(i, strength.x, strength.y, duration, timestamp);
+ }
+ } else if (joy.vibrating && joy.ff_end_timestamp != 0) {
+ uint64_t current_time = OS::get_singleton()->get_ticks_usec();
+ if (current_time >= joy.ff_end_timestamp)
+ joypad_vibration_stop(i, current_time);
+ }
break;
}
@@ -122,15 +140,7 @@ void JoypadUWP::OnGamepadRemoved(Platform::Object ^ sender, Windows::Gaming::Inp
ERR_FAIL_COND(idx == -1);
- for (int i = idx + 1; i < MAX_CONTROLLERS - 1; i++) {
-
- if (!controllers[i].connected) {
- break;
- }
-
- controllers[i - 1] = controllers[i];
- }
- controllers[MAX_CONTROLLERS - 1] = ControllerDevice();
+ controllers[idx] = ControllerDevice();
input->joy_connection_changed(idx, false, "Xbox Controller");
}
@@ -144,3 +154,30 @@ InputDefault::JoyAxis JoypadUWP::axis_correct(double p_val, bool p_negate, bool
return jx;
}
+
+void JoypadUWP::joypad_vibration_start(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp) {
+ ControllerDevice &joy = controllers[p_device];
+ if (joy.connected) {
+ GamepadVibration vibration;
+ vibration.LeftMotor = p_strong_magnitude;
+ vibration.RightMotor = p_weak_magnitude;
+ ((Gamepad ^) joy.controller_reference)->Vibration = vibration;
+
+ joy.ff_timestamp = p_timestamp;
+ joy.ff_end_timestamp = p_duration == 0 ? 0 : p_timestamp + (uint64_t)(p_duration * 1000000.0);
+ joy.vibrating = true;
+ }
+}
+
+void JoypadUWP::joypad_vibration_stop(int p_device, uint64_t p_timestamp) {
+ ControllerDevice &joy = controllers[p_device];
+ if (joy.connected) {
+ GamepadVibration vibration;
+ vibration.LeftMotor = 0.0;
+ vibration.RightMotor = 0.0;
+ ((Gamepad ^) joy.controller_reference)->Vibration = vibration;
+
+ joy.ff_timestamp = p_timestamp;
+ joy.vibrating = false;
+ }
+}
diff --git a/platform/uwp/joypad_uwp.h b/platform/uwp/joypad_uwp.h
index 7337ffb3ce..c55e1e7ab7 100644
--- a/platform/uwp/joypad_uwp.h
+++ b/platform/uwp/joypad_uwp.h
@@ -62,11 +62,17 @@ private:
int id;
bool connected;
ControllerType type;
+ float ff_timestamp;
+ float ff_end_timestamp;
+ bool vibrating;
ControllerDevice() {
id = -1;
connected = false;
type = ControllerType::GAMEPAD_CONTROLLER;
+ ff_timestamp = 0.0f;
+ ff_end_timestamp = 0.0f;
+ vibrating = false;
}
};
@@ -78,6 +84,8 @@ private:
void OnGamepadRemoved(Platform::Object ^ sender, Windows::Gaming::Input::Gamepad ^ value);
InputDefault::JoyAxis axis_correct(double p_val, bool p_negate = false, bool p_trigger = false) const;
+ void joypad_vibration_start(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp);
+ void joypad_vibration_stop(int p_device, uint64_t p_timestamp);
};
#endif
diff --git a/platform/windows/key_mapping_win.cpp b/platform/windows/key_mapping_win.cpp
index bffacb3a82..83e2af72b2 100644
--- a/platform/windows/key_mapping_win.cpp
+++ b/platform/windows/key_mapping_win.cpp
@@ -44,7 +44,7 @@ static _WinTranslatePair _vk_to_keycode[] = {
//VK_CLEAR (0x0C)
- { KEY_RETURN, VK_RETURN }, //(0x0D)
+ { KEY_ENTER, VK_RETURN }, //(0x0D)
{ KEY_SHIFT, VK_SHIFT }, //(0x10)
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index da14d5c284..9cab19fffb 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -807,7 +807,7 @@ void OS_Windows::process_key_events() {
if ((ke.lParam & (1 << 24)) && (ke.wParam == VK_RETURN)) {
// Special case for Numpad Enter key
- k->set_scancode(KEY_ENTER);
+ k->set_scancode(KEY_KP_ENTER);
} else {
k->set_scancode(KeyMappingWindows::get_keysym(ke.wParam));
}
@@ -1192,10 +1192,6 @@ void OS_Windows::finalize() {
main_loop = NULL;
- for (int i = 0; i < get_audio_driver_count(); i++) {
- AudioDriverManager::get_driver(i)->finish();
- }
-
memdelete(joypad);
memdelete(input);
diff --git a/platform/x11/key_mapping_x11.cpp b/platform/x11/key_mapping_x11.cpp
index 1d7eb1692c..32a9806b22 100644
--- a/platform/x11/key_mapping_x11.cpp
+++ b/platform/x11/key_mapping_x11.cpp
@@ -44,7 +44,7 @@ static _XTranslatePair _xkeysym_to_keycode[] = {
{ XK_Tab, KEY_TAB },
{ XK_ISO_Left_Tab, KEY_BACKTAB },
{ XK_BackSpace, KEY_BACKSPACE },
- { XK_Return, KEY_RETURN },
+ { XK_Return, KEY_ENTER },
{ XK_Insert, KEY_INSERT },
{ XK_Delete, KEY_DELETE },
{ XK_Clear, KEY_DELETE },
@@ -78,7 +78,7 @@ static _XTranslatePair _xkeysym_to_keycode[] = {
{ XK_Help, KEY_HELP },
{ XK_KP_Space, KEY_SPACE },
{ XK_KP_Tab, KEY_TAB },
- { XK_KP_Enter, KEY_ENTER },
+ { XK_KP_Enter, KEY_KP_ENTER },
{ XK_Home, KEY_HOME },
{ XK_Left, KEY_LEFT },
{ XK_Up, KEY_UP },
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index 1dde328eda..ade3a0a0c5 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -529,10 +529,6 @@ void OS_X11::finalize() {
memdelete(main_loop);
main_loop = NULL;
- for (int i = 0; i < get_audio_driver_count(); i++) {
- AudioDriverManager::get_driver(i)->finish();
- }
-
/*
if (debugger_connection_console) {
memdelete(debugger_connection_console);