summaryrefslogtreecommitdiff
path: root/platform/windows
diff options
context:
space:
mode:
Diffstat (limited to 'platform/windows')
-rw-r--r--platform/windows/crash_handler_windows.cpp4
-rw-r--r--platform/windows/crash_handler_windows.h4
-rw-r--r--platform/windows/detect.py20
-rw-r--r--platform/windows/display_server_windows.cpp84
-rw-r--r--platform/windows/display_server_windows.h10
-rw-r--r--platform/windows/export/export.cpp4
-rw-r--r--platform/windows/export/export.h4
-rw-r--r--platform/windows/export/export_plugin.cpp14
-rw-r--r--platform/windows/export/export_plugin.h11
-rw-r--r--platform/windows/gl_manager_windows.cpp4
-rw-r--r--platform/windows/gl_manager_windows.h4
-rw-r--r--platform/windows/godot_windows.cpp4
-rw-r--r--platform/windows/joypad_windows.cpp46
-rw-r--r--platform/windows/joypad_windows.h6
-rw-r--r--platform/windows/key_mapping_windows.cpp321
-rw-r--r--platform/windows/key_mapping_windows.h4
-rw-r--r--platform/windows/lang_table.h4
-rw-r--r--platform/windows/os_windows.cpp204
-rw-r--r--platform/windows/os_windows.h9
-rw-r--r--platform/windows/platform_config.h4
-rw-r--r--platform/windows/vulkan_context_win.cpp4
-rw-r--r--platform/windows/vulkan_context_win.h4
-rw-r--r--platform/windows/windows_terminal_logger.cpp4
-rw-r--r--platform/windows/windows_terminal_logger.h4
24 files changed, 390 insertions, 391 deletions
diff --git a/platform/windows/crash_handler_windows.cpp b/platform/windows/crash_handler_windows.cpp
index 1b4dae207f..71e9d9acbd 100644
--- a/platform/windows/crash_handler_windows.cpp
+++ b/platform/windows/crash_handler_windows.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 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 */
diff --git a/platform/windows/crash_handler_windows.h b/platform/windows/crash_handler_windows.h
index 5cdc6d3e05..ec8de3ffab 100644
--- a/platform/windows/crash_handler_windows.h
+++ b/platform/windows/crash_handler_windows.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 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 */
diff --git a/platform/windows/detect.py b/platform/windows/detect.py
index e9ecc99ef5..249a0d2e79 100644
--- a/platform/windows/detect.py
+++ b/platform/windows/detect.py
@@ -65,7 +65,7 @@ def get_opts():
# Vista support dropped after EOL due to GH-10243
("target_win_version", "Targeted Windows version, >= 0x0601 (Windows 7)", "0x0601"),
BoolVariable("debug_symbols", "Add debugging symbols to release/release_debug builds", True),
- EnumVariable("windows_subsystem", "Windows subsystem", "default", ("default", "console", "gui")),
+ EnumVariable("windows_subsystem", "Windows subsystem", "gui", ("gui", "console")),
BoolVariable("separate_debug_symbols", "Create a separate file containing debugging symbols", False),
("msvc_version", "MSVC version to use. Ignored if VCINSTALLDIR is set in shell env.", None),
BoolVariable("use_mingw", "Use the Mingw compiler, even if MSVC is installed.", False),
@@ -178,15 +178,6 @@ def configure_msvc(env, manual_msvc_config):
# Build type
- if env["tests"]:
- env["windows_subsystem"] = "console"
- elif env["windows_subsystem"] == "default":
- # Default means we use console for debug, gui for release.
- if "debug" in env["target"]:
- env["windows_subsystem"] = "console"
- else:
- env["windows_subsystem"] = "gui"
-
if env["target"] == "release":
if env["optimize"] == "speed": # optimize for speed (default)
env.Append(CCFLAGS=["/O2"])
@@ -326,15 +317,6 @@ def configure_mingw(env):
## Build type
- if env["tests"]:
- env["windows_subsystem"] = "console"
- elif env["windows_subsystem"] == "default":
- # Default means we use console for debug, gui for release.
- if "debug" in env["target"]:
- env["windows_subsystem"] = "console"
- else:
- env["windows_subsystem"] = "gui"
-
if env["target"] == "release":
env.Append(CCFLAGS=["-msse2"])
diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp
index 899cf5dfad..bcddae45d8 100644
--- a/platform/windows/display_server_windows.cpp
+++ b/platform/windows/display_server_windows.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 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 */
@@ -59,6 +59,15 @@ static String format_error_message(DWORD id) {
return msg;
}
+static void track_mouse_leave_event(HWND hWnd) {
+ TRACKMOUSEEVENT tme;
+ tme.cbSize = sizeof(TRACKMOUSEEVENT);
+ tme.dwFlags = TME_LEAVE;
+ tme.hwndTrack = hWnd;
+ tme.dwHoverTime = HOVER_DEFAULT;
+ TrackMouseEvent(&tme);
+}
+
bool DisplayServerWindows::has_feature(Feature p_feature) const {
switch (p_feature) {
case FEATURE_SUBWINDOWS:
@@ -68,7 +77,6 @@ bool DisplayServerWindows::has_feature(Feature p_feature) const {
case FEATURE_CLIPBOARD:
case FEATURE_CURSOR_SHAPE:
case FEATURE_CUSTOM_CURSOR_SHAPE:
- case FEATURE_CONSOLE_WINDOW:
case FEATURE_IME:
case FEATURE_WINDOW_TRANSPARENCY:
case FEATURE_HIDPI:
@@ -666,8 +674,20 @@ void DisplayServerWindows::window_set_current_screen(int p_screen, WindowID p_wi
ERR_FAIL_COND(!windows.has(p_window));
ERR_FAIL_INDEX(p_screen, get_screen_count());
- Vector2 ofs = window_get_position(p_window) - screen_get_position(window_get_current_screen(p_window));
- window_set_position(ofs + screen_get_position(p_screen), p_window);
+ const WindowData &wd = windows[p_window];
+ if (wd.fullscreen) {
+ int cs = window_get_current_screen(p_window);
+ if (cs == p_screen) {
+ return;
+ }
+ Point2 pos = screen_get_position(p_screen);
+ Size2 size = screen_get_size(p_screen);
+
+ MoveWindow(wd.hWnd, pos.x, pos.y, size.width, size.height, TRUE);
+ } else {
+ Vector2 ofs = window_get_position(p_window) - screen_get_position(window_get_current_screen(p_window));
+ window_set_position(ofs + screen_get_position(p_screen), p_window);
+ }
}
Point2i DisplayServerWindows::window_get_position(WindowID p_window) const {
@@ -1198,23 +1218,6 @@ void DisplayServerWindows::window_set_ime_position(const Point2i &p_pos, WindowI
ImmReleaseContext(wd.hWnd, himc);
}
-void DisplayServerWindows::console_set_visible(bool p_enabled) {
- _THREAD_SAFE_METHOD_
-
- if (console_visible == p_enabled) {
- return;
- }
- if (!((OS_Windows *)OS::get_singleton())->_is_win11_terminal()) {
- // GetConsoleWindow is not supported by the Windows Terminal.
- ShowWindow(GetConsoleWindow(), p_enabled ? SW_SHOW : SW_HIDE);
- console_visible = p_enabled;
- }
-}
-
-bool DisplayServerWindows::is_console_visible() const {
- return console_visible;
-}
-
void DisplayServerWindows::cursor_set_shape(CursorShape p_shape) {
_THREAD_SAFE_METHOD_
@@ -1976,6 +1979,9 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
// Run a timer to prevent event catching warning if the focused window is closing.
windows[window_id].focus_timer_id = SetTimer(windows[window_id].hWnd, 2, USER_TIMER_MINIMUM, (TIMERPROC) nullptr);
}
+ if (wParam != WA_INACTIVE) {
+ track_mouse_leave_event(hWnd);
+ }
return 0; // Return to the message loop.
} break;
case WM_GETMINMAXINFO: {
@@ -2067,7 +2073,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
mm->set_position(c);
mm->set_global_position(c);
Input::get_singleton()->set_mouse_position(c);
- mm->set_speed(Vector2(0, 0));
+ mm->set_velocity(Vector2(0, 0));
if (raw->data.mouse.usFlags == MOUSE_MOVE_RELATIVE) {
mm->set_relative(Vector2(raw->data.mouse.lLastX, raw->data.mouse.lLastY));
@@ -2172,7 +2178,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
}
Input::get_singleton()->set_mouse_position(mm->get_position());
- mm->set_speed(Input::get_singleton()->get_last_mouse_speed());
+ mm->set_velocity(Input::get_singleton()->get_last_mouse_velocity());
if (old_invalid) {
old_x = mm->get_position().x;
@@ -2260,12 +2266,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
outside = false;
// Once-off notification, must call again.
- TRACKMOUSEEVENT tme;
- tme.cbSize = sizeof(TRACKMOUSEEVENT);
- tme.dwFlags = TME_LEAVE;
- tme.hwndTrack = hWnd;
- tme.dwHoverTime = HOVER_DEFAULT;
- TrackMouseEvent(&tme);
+ track_mouse_leave_event(hWnd);
}
// Don't calculate relative mouse movement if we don't have focus in CAPTURED mode.
@@ -2319,7 +2320,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
}
Input::get_singleton()->set_mouse_position(mm->get_position());
- mm->set_speed(Input::get_singleton()->get_last_mouse_speed());
+ mm->set_velocity(Input::get_singleton()->get_last_mouse_velocity());
if (old_invalid) {
old_x = mm->get_position().x;
@@ -2366,12 +2367,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
outside = false;
// Once-off notification, must call again.
- TRACKMOUSEEVENT tme;
- tme.cbSize = sizeof(TRACKMOUSEEVENT);
- tme.dwFlags = TME_LEAVE;
- tme.hwndTrack = hWnd;
- tme.dwHoverTime = HOVER_DEFAULT;
- TrackMouseEvent(&tme);
+ track_mouse_leave_event(hWnd);
}
// Don't calculate relative mouse movement if we don't have focus in CAPTURED mode.
@@ -2425,7 +2421,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
}
Input::get_singleton()->set_mouse_position(mm->get_position());
- mm->set_speed(Input::get_singleton()->get_last_mouse_speed());
+ mm->set_velocity(Input::get_singleton()->get_last_mouse_velocity());
if (old_invalid) {
old_x = mm->get_position().x;
@@ -2817,6 +2813,9 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
case WM_DEVICECHANGE: {
joypad->probe_joypads();
} break;
+ case WM_DESTROY: {
+ Input::get_singleton()->flush_buffered_events();
+ } break;
case WM_SETCURSOR: {
if (LOWORD(lParam) == HTCLIENT) {
if (windows[window_id].window_has_focus && (mouse_mode == MOUSE_MODE_HIDDEN || mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED_HIDDEN)) {
@@ -3126,14 +3125,6 @@ DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode,
#endif
RegisterTouchWindow(wd.hWnd, 0);
-
- TRACKMOUSEEVENT tme;
- tme.cbSize = sizeof(TRACKMOUSEEVENT);
- tme.dwFlags = TME_LEAVE;
- tme.hwndTrack = wd.hWnd;
- tme.dwHoverTime = HOVER_DEFAULT;
- TrackMouseEvent(&tme);
-
DragAcceptFiles(wd.hWnd, true);
if ((tablet_get_current_driver() == "wintab") && wintab_available) {
@@ -3246,7 +3237,6 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win
shift_mem = false;
control_mem = false;
meta_mem = false;
- console_visible = IsWindowVisible(GetConsoleWindow());
hInstance = ((OS_Windows *)OS::get_singleton())->get_hinstance();
pressrc = 0;
diff --git a/platform/windows/display_server_windows.h b/platform/windows/display_server_windows.h
index fec449ebce..3593dc1a05 100644
--- a/platform/windows/display_server_windows.h
+++ b/platform/windows/display_server_windows.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 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 */
@@ -414,7 +414,6 @@ class DisplayServerWindows : public DisplayServer {
bool use_raw_input = false;
bool drop_events = false;
bool in_dispatch_input_event = false;
- bool console_visible = false;
WNDCLASSEXW wc;
@@ -477,7 +476,7 @@ public:
virtual void window_attach_instance_id(ObjectID p_instance, WindowID p_window = MAIN_WINDOW_ID) override;
virtual ObjectID window_get_attached_instance_id(WindowID p_window = MAIN_WINDOW_ID) const override;
- virtual void gl_window_make_current(DisplayServer::WindowID p_window_id);
+ virtual void gl_window_make_current(DisplayServer::WindowID p_window_id) override;
virtual void window_set_rect_changed_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override;
@@ -529,9 +528,6 @@ public:
virtual void window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window = MAIN_WINDOW_ID) override;
virtual DisplayServer::VSyncMode window_get_vsync_mode(WindowID p_vsync_mode) const override;
- virtual void console_set_visible(bool p_enabled) override;
- virtual bool is_console_visible() const override;
-
virtual void cursor_set_shape(CursorShape p_shape) override;
virtual CursorShape cursor_get_shape() const override;
virtual void cursor_set_custom_image(const RES &p_cursor, CursorShape p_shape = CURSOR_ARROW, const Vector2 &p_hotspot = Vector2()) override;
diff --git a/platform/windows/export/export.cpp b/platform/windows/export/export.cpp
index 4ff42f3f62..17a24c08bf 100644
--- a/platform/windows/export/export.cpp
+++ b/platform/windows/export/export.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 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 */
diff --git a/platform/windows/export/export.h b/platform/windows/export/export.h
index 110e1439e2..09399f2bee 100644
--- a/platform/windows/export/export.h
+++ b/platform/windows/export/export.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 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 */
diff --git a/platform/windows/export/export_plugin.cpp b/platform/windows/export/export_plugin.cpp
index 5a1cdb0962..68762db3a9 100644
--- a/platform/windows/export/export_plugin.cpp
+++ b/platform/windows/export/export_plugin.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 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 */
@@ -54,13 +54,19 @@ Error EditorExportPlatformWindows::export_project(const Ref<EditorExportPreset>
return err;
}
+bool EditorExportPlatformWindows::get_export_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const {
+ // This option is not supported by "osslsigncode", used on non-Windows host.
+ if (!OS::get_singleton()->has_feature("windows") && p_option == "codesign/identity_type") {
+ return false;
+ }
+ return true;
+}
+
void EditorExportPlatformWindows::get_export_options(List<ExportOption> *r_options) {
EditorExportPlatformPC::get_export_options(r_options);
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/enable"), false));
-#ifdef WINDOWS_ENABLED
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/identity_type", PROPERTY_HINT_ENUM, "Select automatically,Use PKCS12 file (specify *.PFX/*.P12 file),Use certificate store (specify SHA1 hash)"), 0));
-#endif
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/identity", PROPERTY_HINT_GLOBAL_FILE, "*.pfx,*.p12"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/password"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/timestamp"), true));
diff --git a/platform/windows/export/export_plugin.h b/platform/windows/export/export_plugin.h
index 11d3826410..351333aa42 100644
--- a/platform/windows/export/export_plugin.h
+++ b/platform/windows/export/export_plugin.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 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 */
@@ -43,9 +43,10 @@ class EditorExportPlatformWindows : public EditorExportPlatformPC {
Error _code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path);
public:
- virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
- virtual Error sign_shared_object(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path);
- virtual void get_export_options(List<ExportOption> *r_options);
+ virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0) override;
+ virtual Error sign_shared_object(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path) override;
+ virtual void get_export_options(List<ExportOption> *r_options) override;
+ virtual bool get_export_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const override;
};
#endif
diff --git a/platform/windows/gl_manager_windows.cpp b/platform/windows/gl_manager_windows.cpp
index fe98f8b0ba..74b5f48502 100644
--- a/platform/windows/gl_manager_windows.cpp
+++ b/platform/windows/gl_manager_windows.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 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 */
diff --git a/platform/windows/gl_manager_windows.h b/platform/windows/gl_manager_windows.h
index 9733a57420..6423c54855 100644
--- a/platform/windows/gl_manager_windows.h
+++ b/platform/windows/gl_manager_windows.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 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 */
diff --git a/platform/windows/godot_windows.cpp b/platform/windows/godot_windows.cpp
index 22e2e5f7e5..7819ab9a32 100644
--- a/platform/windows/godot_windows.cpp
+++ b/platform/windows/godot_windows.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 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 */
diff --git a/platform/windows/joypad_windows.cpp b/platform/windows/joypad_windows.cpp
index f76749ec54..b0dd86a4b7 100644
--- a/platform/windows/joypad_windows.cpp
+++ b/platform/windows/joypad_windows.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 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 */
@@ -448,33 +448,27 @@ void JoypadWindows::post_hat(int p_device, DWORD p_dpad) {
input->joy_hat(p_device, dpad_val);
};
-Input::JoyAxisValue JoypadWindows::axis_correct(int p_val, bool p_xinput, bool p_trigger, bool p_negate) const {
- Input::JoyAxisValue jx;
+float JoypadWindows::axis_correct(int p_val, bool p_xinput, bool p_trigger, bool p_negate) const {
if (Math::abs(p_val) < MIN_JOY_AXIS) {
- jx.min = p_trigger ? 0 : -1;
- jx.value = 0.0f;
- return jx;
+ return p_trigger ? -1.0f : 0.0f;
}
- if (p_xinput) {
- if (p_trigger) {
- jx.min = 0;
- jx.value = (float)p_val / MAX_TRIGGER;
- return jx;
- }
- jx.min = -1;
- if (p_val < 0) {
- jx.value = (float)p_val / MAX_JOY_AXIS;
- } else {
- jx.value = (float)p_val / (MAX_JOY_AXIS - 1);
- }
- if (p_negate) {
- jx.value = -jx.value;
- }
- return jx;
+ if (!p_xinput) {
+ return (float)p_val / MAX_JOY_AXIS;
+ }
+ if (p_trigger) {
+ // Convert to a value between -1.0f and 1.0f.
+ return 2.0f * p_val / MAX_TRIGGER - 1.0f;
+ }
+ float value;
+ if (p_val < 0) {
+ value = (float)p_val / MAX_JOY_AXIS;
+ } else {
+ value = (float)p_val / (MAX_JOY_AXIS - 1);
+ }
+ if (p_negate) {
+ value = -value;
}
- jx.min = -1;
- jx.value = (float)p_val / MAX_JOY_AXIS;
- return jx;
+ return value;
}
void JoypadWindows::joypad_vibration_start_xinput(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp) {
diff --git a/platform/windows/joypad_windows.h b/platform/windows/joypad_windows.h
index 757fb54fb3..0e3d03fa52 100644
--- a/platform/windows/joypad_windows.h
+++ b/platform/windows/joypad_windows.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 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 */
@@ -132,7 +132,7 @@ private:
void joypad_vibration_start_xinput(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp);
void joypad_vibration_stop_xinput(int p_device, uint64_t p_timestamp);
- Input::JoyAxisValue axis_correct(int p_val, bool p_xinput = false, bool p_trigger = false, bool p_negate = false) const;
+ float axis_correct(int p_val, bool p_xinput = false, bool p_trigger = false, bool p_negate = false) const;
XInputGetState_t xinput_get_state;
XInputSetState_t xinput_set_state;
};
diff --git a/platform/windows/key_mapping_windows.cpp b/platform/windows/key_mapping_windows.cpp
index 65ee5dd46b..e32dc0d1a6 100644
--- a/platform/windows/key_mapping_windows.cpp
+++ b/platform/windows/key_mapping_windows.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 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 */
@@ -32,117 +32,134 @@
#include <stdio.h>
+// This provides translation from Windows virtual key codes to Godot and back.
+// See WinUser.h and the below for documentation:
+// https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
+
struct _WinTranslatePair {
Key keysym;
unsigned int keycode;
};
static _WinTranslatePair _vk_to_keycode[] = {
- { Key::BACKSPACE, VK_BACK }, // (0x08) // backspace
- { Key::TAB, VK_TAB }, //(0x09)
-
- //VK_CLEAR (0x0C)
-
- { Key::ENTER, VK_RETURN }, //(0x0D)
-
- { Key::SHIFT, VK_SHIFT }, //(0x10)
-
- { Key::CTRL, VK_CONTROL }, //(0x11)
-
- { Key::ALT, VK_MENU }, //(0x12)
-
- { Key::PAUSE, VK_PAUSE }, //(0x13)
+ // VK_LBUTTON (0x01)
+ // VK_RBUTTON (0x02)
+ // VK_CANCEL (0x03)
+ // VK_MBUTTON (0x04)
+ // VK_XBUTTON1 (0x05)
+ // VK_XBUTTON2 (0x06)
+ // We have no mappings for the above, as we only map keyboard buttons here.
- { Key::CAPSLOCK, VK_CAPITAL }, //(0x14)
+ // 0x07 is undefined.
- { Key::ESCAPE, VK_ESCAPE }, //(0x1B)
+ { Key::BACKSPACE, VK_BACK }, // (0x08)
+ { Key::TAB, VK_TAB }, // (0x09)
- { Key::SPACE, VK_SPACE }, //(0x20)
+ // 0x0A-0B are reserved.
- { Key::PAGEUP, VK_PRIOR }, //(0x21)
+ { Key::CLEAR, VK_CLEAR }, // (0x0C)
+ { Key::ENTER, VK_RETURN }, // (0x0D)
- { Key::PAGEDOWN, VK_NEXT }, //(0x22)
+ // 0x0E-0F are undefined.
- { Key::END, VK_END }, //(0x23)
+ { Key::SHIFT, VK_SHIFT }, // (0x10)
+ { Key::CTRL, VK_CONTROL }, // (0x11)
+ { Key::ALT, VK_MENU }, // (0x12)
+ { Key::PAUSE, VK_PAUSE }, // (0x13)
+ { Key::CAPSLOCK, VK_CAPITAL }, // (0x14)
- { Key::HOME, VK_HOME }, //(0x24)
+ // 0x15-1A are IME keys. We have no mapping.
- { Key::LEFT, VK_LEFT }, //(0x25)
+ { Key::ESCAPE, VK_ESCAPE }, // (0x1B)
- { Key::UP, VK_UP }, //(0x26)
-
- { Key::RIGHT, VK_RIGHT }, //(0x27)
+ // 0x1C-1F are IME keys. We have no mapping.
+ { Key::SPACE, VK_SPACE }, // (0x20)
+ { Key::PAGEUP, VK_PRIOR }, // (0x21)
+ { Key::PAGEDOWN, VK_NEXT }, // (0x22)
+ { Key::END, VK_END }, // (0x23)
+ { Key::HOME, VK_HOME }, // (0x24)
+ { Key::LEFT, VK_LEFT }, // (0x25)
+ { Key::UP, VK_UP }, // (0x26)
+ { Key::RIGHT, VK_RIGHT }, // (0x27)
{ Key::DOWN, VK_DOWN }, // (0x28)
- //VK_SELECT (0x29)
+ // VK_SELECT (0x29)
+ // Old select key, e.g. on Digital Equipment Corporation keyboards.
+ // Old and uncommon, we have no mapping.
{ Key::PRINT, VK_PRINT }, // (0x2A)
+ // Old IBM key, modern keyboards use VK_SNAPSHOT. Map to VK_SNAPSHOT.
- //VK_EXECUTE (0x2B)
+ // VK_EXECUTE (0x2B)
+ // Old and uncommon, we have no mapping.
{ Key::PRINT, VK_SNAPSHOT }, // (0x2C)
-
{ Key::INSERT, VK_INSERT }, // (0x2D)
-
{ Key::KEY_DELETE, VK_DELETE }, // (0x2E)
{ Key::HELP, VK_HELP }, // (0x2F)
-
- { Key::KEY_0, (0x30) }, ////0 key
- { Key::KEY_1, (0x31) }, ////1 key
- { Key::KEY_2, (0x32) }, ////2 key
- { Key::KEY_3, (0x33) }, ////3 key
- { Key::KEY_4, (0x34) }, ////4 key
- { Key::KEY_5, (0x35) }, ////5 key
- { Key::KEY_6, (0x36) }, ////6 key
- { Key::KEY_7, (0x37) }, ////7 key
- { Key::KEY_8, (0x38) }, ////8 key
- { Key::KEY_9, (0x39) }, ////9 key
- { Key::A, (0x41) }, ////A key
- { Key::B, (0x42) }, ////B key
- { Key::C, (0x43) }, ////C key
- { Key::D, (0x44) }, ////D key
- { Key::E, (0x45) }, ////E key
- { Key::F, (0x46) }, ////F key
- { Key::G, (0x47) }, ////G key
- { Key::H, (0x48) }, ////H key
- { Key::I, (0x49) }, ////I key
- { Key::J, (0x4A) }, ////J key
- { Key::K, (0x4B) }, ////K key
- { Key::L, (0x4C) }, ////L key
- { Key::M, (0x4D) }, ////M key
- { Key::N, (0x4E) }, ////N key
- { Key::O, (0x4F) }, ////O key
- { Key::P, (0x50) }, ////P key
- { Key::Q, (0x51) }, ////Q key
- { Key::R, (0x52) }, ////R key
- { Key::S, (0x53) }, ////S key
- { Key::T, (0x54) }, ////T key
- { Key::U, (0x55) }, ////U key
- { Key::V, (0x56) }, ////V key
- { Key::W, (0x57) }, ////W key
- { Key::X, (0x58) }, ////X key
- { Key::Y, (0x59) }, ////Y key
- { Key::Z, (0x5A) }, ////Z key
-
- { (Key)KeyModifierMask::META, VK_LWIN }, //(0x5B)
- { (Key)KeyModifierMask::META, VK_RWIN }, //(0x5C)
- { Key::MENU, VK_APPS }, //(0x5D)
- { Key::STANDBY, VK_SLEEP }, //(0x5F)
- { Key::KP_0, VK_NUMPAD0 }, //(0x60)
- { Key::KP_1, VK_NUMPAD1 }, //(0x61)
- { Key::KP_2, VK_NUMPAD2 }, //(0x62)
- { Key::KP_3, VK_NUMPAD3 }, //(0x63)
- { Key::KP_4, VK_NUMPAD4 }, //(0x64)
- { Key::KP_5, VK_NUMPAD5 }, //(0x65)
- { Key::KP_6, VK_NUMPAD6 }, //(0x66)
- { Key::KP_7, VK_NUMPAD7 }, //(0x67)
- { Key::KP_8, VK_NUMPAD8 }, //(0x68)
- { Key::KP_9, VK_NUMPAD9 }, //(0x69)
+ // Old and uncommon, but we have a mapping.
+
+ { Key::KEY_0, (0x30) }, // 0 key.
+ { Key::KEY_1, (0x31) }, // 1 key.
+ { Key::KEY_2, (0x32) }, // 2 key.
+ { Key::KEY_3, (0x33) }, // 3 key.
+ { Key::KEY_4, (0x34) }, // 4 key.
+ { Key::KEY_5, (0x35) }, // 5 key.
+ { Key::KEY_6, (0x36) }, // 6 key.
+ { Key::KEY_7, (0x37) }, // 7 key.
+ { Key::KEY_8, (0x38) }, // 8 key.
+ { Key::KEY_9, (0x39) }, // 9 key.
+ // 0x3A-40 are undefined.
+ { Key::A, (0x41) }, // A key.
+ { Key::B, (0x42) }, // B key.
+ { Key::C, (0x43) }, // C key.
+ { Key::D, (0x44) }, // D key.
+ { Key::E, (0x45) }, // E key.
+ { Key::F, (0x46) }, // F key.
+ { Key::G, (0x47) }, // G key.
+ { Key::H, (0x48) }, // H key.
+ { Key::I, (0x49) }, // I key
+ { Key::J, (0x4A) }, // J key.
+ { Key::K, (0x4B) }, // K key.
+ { Key::L, (0x4C) }, // L key.
+ { Key::M, (0x4D) }, // M key.
+ { Key::N, (0x4E) }, // N key.
+ { Key::O, (0x4F) }, // O key.
+ { Key::P, (0x50) }, // P key.
+ { Key::Q, (0x51) }, // Q key.
+ { Key::R, (0x52) }, // R key.
+ { Key::S, (0x53) }, // S key.
+ { Key::T, (0x54) }, // T key.
+ { Key::U, (0x55) }, // U key.
+ { Key::V, (0x56) }, // V key.
+ { Key::W, (0x57) }, // W key.
+ { Key::X, (0x58) }, // X key.
+ { Key::Y, (0x59) }, // Y key.
+ { Key::Z, (0x5A) }, // Z key.
+
+ { (Key)KeyModifierMask::META, VK_LWIN }, // (0x5B)
+ { (Key)KeyModifierMask::META, VK_RWIN }, // (0x5C)
+ { Key::MENU, VK_APPS }, // (0x5D)
+ // 0x5E is reserved.
+ { Key::STANDBY, VK_SLEEP }, // (0x5F)
+ { Key::KP_0, VK_NUMPAD0 }, // (0x60)
+ { Key::KP_1, VK_NUMPAD1 }, // (0x61)
+ { Key::KP_2, VK_NUMPAD2 }, // (0x62)
+ { Key::KP_3, VK_NUMPAD3 }, // (0x63)
+ { Key::KP_4, VK_NUMPAD4 }, // (0x64)
+ { Key::KP_5, VK_NUMPAD5 }, // (0x65)
+ { Key::KP_6, VK_NUMPAD6 }, // (0x66)
+ { Key::KP_7, VK_NUMPAD7 }, // (0x67)
+ { Key::KP_8, VK_NUMPAD8 }, // (0x68)
+ { Key::KP_9, VK_NUMPAD9 }, // (0x69)
{ Key::KP_MULTIPLY, VK_MULTIPLY }, // (0x6A)
{ Key::KP_ADD, VK_ADD }, // (0x6B)
- //VK_SEPARATOR (0x6C)
+ { Key::KP_PERIOD, VK_SEPARATOR }, // (0x6C)
+ // VK_SEPERATOR (key 0x6C) is not found on US keyboards.
+ // It is used on some Brazilian and Far East keyboards.
+ // We don't have a direct mapping, map to period.
{ Key::KP_SUBTRACT, VK_SUBTRACT }, // (0x6D)
{ Key::KP_PERIOD, VK_DECIMAL }, // (0x6E)
{ Key::KP_DIVIDE, VK_DIVIDE }, // (0x6F)
@@ -162,8 +179,17 @@ static _WinTranslatePair _vk_to_keycode[] = {
{ Key::F14, VK_F14 }, // (0x7D)
{ Key::F15, VK_F15 }, // (0x7E)
{ Key::F16, VK_F16 }, // (0x7F)
+ // We have no mappings for F17-F24. (0x80-87)
+ // 0x88-8F are reserved for UI navigation.
{ Key::NUMLOCK, VK_NUMLOCK }, // (0x90)
{ Key::SCROLLLOCK, VK_SCROLL }, // (0x91)
+
+ { Key::EQUAL, VK_OEM_NEC_EQUAL }, // (0x92)
+ // OEM NEC PC-9800 numpad '=' key.
+
+ // 0x93-96 are OEM specific (e.g. used by Fujitsu/OASYS), we have no mappings.
+ // 0x97-9F are unassigned.
+
{ Key::SHIFT, VK_LSHIFT }, // (0xA0)
{ Key::SHIFT, VK_RSHIFT }, // (0xA1)
{ Key::CTRL, VK_LCONTROL }, // (0xA2)
@@ -172,70 +198,124 @@ static _WinTranslatePair _vk_to_keycode[] = {
{ Key::MENU, VK_RMENU }, // (0xA5)
{ Key::BACK, VK_BROWSER_BACK }, // (0xA6)
-
{ Key::FORWARD, VK_BROWSER_FORWARD }, // (0xA7)
-
{ Key::REFRESH, VK_BROWSER_REFRESH }, // (0xA8)
-
{ Key::STOP, VK_BROWSER_STOP }, // (0xA9)
-
{ Key::SEARCH, VK_BROWSER_SEARCH }, // (0xAA)
-
{ Key::FAVORITES, VK_BROWSER_FAVORITES }, // (0xAB)
-
{ Key::HOMEPAGE, VK_BROWSER_HOME }, // (0xAC)
-
{ Key::VOLUMEMUTE, VK_VOLUME_MUTE }, // (0xAD)
-
{ Key::VOLUMEDOWN, VK_VOLUME_DOWN }, // (0xAE)
-
{ Key::VOLUMEUP, VK_VOLUME_UP }, // (0xAF)
-
{ Key::MEDIANEXT, VK_MEDIA_NEXT_TRACK }, // (0xB0)
-
{ Key::MEDIAPREVIOUS, VK_MEDIA_PREV_TRACK }, // (0xB1)
-
{ Key::MEDIASTOP, VK_MEDIA_STOP }, // (0xB2)
- //VK_MEDIA_PLAY_PAUSE (0xB3)
+ { Key::MEDIAPLAY, VK_MEDIA_PLAY_PAUSE }, // (0xB3)
+ // Media button play/pause toggle.
+ // Map to media play (there is no other 'play' mapping on Windows).
{ Key::LAUNCHMAIL, VK_LAUNCH_MAIL }, // (0xB4)
-
{ Key::LAUNCHMEDIA, VK_LAUNCH_MEDIA_SELECT }, // (0xB5)
-
{ Key::LAUNCH0, VK_LAUNCH_APP1 }, // (0xB6)
-
{ Key::LAUNCH1, VK_LAUNCH_APP2 }, // (0xB7)
+ // 0xB8-B9 are reserved.
+
{ Key::SEMICOLON, VK_OEM_1 }, // (0xBA)
+ // Misc. character, can vary by keyboard/region.
+ // Windows 2000/XP: For US standard keyboards, the ';:' key.
- { Key::EQUAL, VK_OEM_PLUS }, // (0xBB) // Windows 2000/XP: For any country/region, the '+' key
- { Key::COMMA, VK_OEM_COMMA }, // (0xBC) // Windows 2000/XP: For any country/region, the ',' key
- { Key::MINUS, VK_OEM_MINUS }, // (0xBD) // Windows 2000/XP: For any country/region, the '-' key
- { Key::PERIOD, VK_OEM_PERIOD }, // (0xBE) // Windows 2000/XP: For any country/region, the '.' key
- { Key::SLASH, VK_OEM_2 }, // (0xBF) //Windows 2000/XP: For the US standard keyboard, the '/?' key
+ { Key::EQUAL, VK_OEM_PLUS }, // (0xBB)
+ // Windows 2000/XP: For any country/region, the '+' key.
+ { Key::COMMA, VK_OEM_COMMA }, // (0xBC)
+ // Windows 2000/XP: For any country/region, the ',' key.
+ { Key::MINUS, VK_OEM_MINUS }, // (0xBD)
+ // Windows 2000/XP: For any country/region, the '-' key.
+ { Key::PERIOD, VK_OEM_PERIOD }, // (0xBE)
+ // Windows 2000/XP: For any country/region, the '.' key.
+
+ { Key::SLASH, VK_OEM_2 }, // (0xBF)
+ // Windows 2000/XP: For US standard keyboards, the '/?' key.
{ Key::QUOTELEFT, VK_OEM_3 }, // (0xC0)
- { Key::BRACELEFT, VK_OEM_4 }, // (0xDB)
+ // Windows 2000/XP: For US standard keyboards, the '`~' key.
+
+ // 0xC1-D7 are reserved. 0xD8-DA are unassigned.
+ // TODO: 0xC3-DA may be used for old gamepads? Maybe we want to support this? See WinUser.h.
+
+ { Key::BRACKETLEFT, VK_OEM_4 }, // (0xDB)
+ // Misc. character, can vary by keyboard/region.
+ // Windows 2000/XP: For US standard keyboards, the '[{' key.
+
{ Key::BACKSLASH, VK_OEM_5 }, // (0xDC)
- { Key::BRACERIGHT, VK_OEM_6 }, // (0xDD)
+ // Misc. character, can vary by keyboard/region.
+ // Windows 2000/XP: For US standard keyboards, the '\|' key.
+
+ { Key::BRACKETRIGHT, VK_OEM_6 }, // (0xDD)
+ // Misc. character, can vary by keyboard/region.
+ // Windows 2000/XP: For US standard keyboards, the ']}' key.
+
{ Key::APOSTROPHE, VK_OEM_7 }, // (0xDE)
- /*
-{VK_OEM_8 (0xDF)
-{VK_OEM_102 (0xE2) // Windows 2000/XP: Either the angle bracket key or the backslash key on the RT 102-key keyboard
-*/
- //{ Key::PLAY, VK_PLAY},// (0xFA)
+ // Misc. character, can vary by keyboard/region.
+ // Windows 2000/XP: For US standard keyboards, single quote/double quote.
+
+ // VK_OEM_8 (0xDF)
+ // Misc. character, can vary by keyboard/region. We have no mapping.
+
+ // 0xE0 is reserved. 0xE1 is OEM specific, we have no mapping.
+
+ // VK_OEM_102 (0xE2)
+ // Either angle bracket or backslash key on the RT 102-key keyboard.
+ // Old and uncommon, we have no mapping.
+
+ { Key::HELP, VK_ICO_HELP }, // (0xE3)
+ // OEM (ICO) help key. Map to help.
+
+ // 0xE4 is OEM (e.g. ICO) specific, we have no mapping.
+
+ // VK_PROCESSKEY (0xE5)
+ // For IME, we have no mapping.
+
+ { Key::CLEAR, VK_ICO_CLEAR }, // (0xE6)
+ // OEM (ICO) clear key. Map to clear.
+
+ // VK_PACKET (0xE7)
+ // Used to pass Unicode characters as if they were keystrokes.
+ // See Win32 API docs. We have no mapping.
+
+ // 0xE8 is unassigned, 0xE9-F5 are OEM (Nokia/Ericsson) specific, we have no mappings.
+
+ { Key::ESCAPE, VK_ATTN }, // (0xF6)
+ // Old IBM 'ATTN' key used on midrange computers, e.g. AS/400, map to Escape.
+
+ { Key::TAB, VK_CRSEL }, // (0xF7)
+ // Old IBM 3270 'CrSel' (cursor select) key, used to select data fields, map to Tab.
+
+ // VK_EXSEL (0xF7)
+ // Old IBM 3270 extended selection key. No mapping.
+
+ // VK_EREOF (0xF8)
+ // Old IBM 3270 erase to end of field key. No mapping.
+
+ { Key::MEDIAPLAY, VK_PLAY }, // (0xFA)
+ // Old IBM 3270 'Play' key. Map to media play.
+
+ // VK_ZOOM (0xFB)
+ // Old IBM 3290 'Zoom' key. No mapping.
+
+ // VK_NONAME (0xFC)
+ // Reserved. No mapping.
+
+ // VK_PA1 (0xFD)
+ // Old IBM 3270 PA1 key. No mapping.
+
+ { Key::CLEAR, VK_OEM_CLEAR }, // (0xFE)
+ // OEM specific clear key. Unclear how it differs from normal clear. Map to clear.
{ Key::UNKNOWN, 0 }
};
-/*
-VK_ZOOM (0xFB)
-VK_NONAME (0xFC)
-VK_PA1 (0xFD)
-VK_OEM_CLEAR (0xFE)
-*/
-
static _WinTranslatePair _scancode_to_keycode[] = {
{ Key::ESCAPE, 0x01 },
{ Key::KEY_1, 0x02 },
@@ -320,7 +400,6 @@ static _WinTranslatePair _scancode_to_keycode[] = {
{ Key::PAGEDOWN, 0x51 },
{ Key::INSERT, 0x52 },
{ Key::KEY_DELETE, 0x53 },
- //{ Key::???, 0x56 }, //NON US BACKSLASH
{ Key::F11, 0x57 },
{ Key::F12, 0x58 },
{ Key::META, 0x5B },
@@ -336,8 +415,6 @@ static _WinTranslatePair _scancode_to_keycode[] = {
Key KeyMappingWindows::get_keysym(unsigned int p_code) {
for (int i = 0; _vk_to_keycode[i].keysym != Key::UNKNOWN; i++) {
if (_vk_to_keycode[i].keycode == p_code) {
- //printf("outcode: %x\n",_vk_to_keycode[i].keysym);
-
return _vk_to_keycode[i].keysym;
}
}
diff --git a/platform/windows/key_mapping_windows.h b/platform/windows/key_mapping_windows.h
index 0454be7310..393432fa39 100644
--- a/platform/windows/key_mapping_windows.h
+++ b/platform/windows/key_mapping_windows.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 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 */
diff --git a/platform/windows/lang_table.h b/platform/windows/lang_table.h
index 51583cc11e..5b022853e8 100644
--- a/platform/windows/lang_table.h
+++ b/platform/windows/lang_table.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 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 */
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index bb6a077a5d..06b8fea681 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 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 */
@@ -52,8 +52,6 @@
#include <regstr.h>
#include <shlobj.h>
-static const WORD MAX_CONSOLE_LINES = 1500;
-
extern "C" {
__declspec(dllexport) DWORD NvOptimusEnablement = 1;
__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
@@ -86,65 +84,17 @@ static String format_error_message(DWORD id) {
}
void RedirectIOToConsole() {
- int hConHandle;
-
- intptr_t lStdHandle;
-
- CONSOLE_SCREEN_BUFFER_INFO coninfo;
-
- FILE *fp;
-
- // allocate a console for this app
-
- AllocConsole();
-
- // set the screen buffer to be big enough to let us scroll text
-
- GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
-
- coninfo.dwSize.Y = MAX_CONSOLE_LINES;
-
- SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);
-
- // redirect unbuffered STDOUT to the console
-
- lStdHandle = (intptr_t)GetStdHandle(STD_OUTPUT_HANDLE);
-
- hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
-
- fp = _fdopen(hConHandle, "w");
-
- *stdout = *fp;
-
- setvbuf(stdout, nullptr, _IONBF, 0);
-
- // redirect unbuffered STDIN to the console
-
- lStdHandle = (intptr_t)GetStdHandle(STD_INPUT_HANDLE);
+ if (AttachConsole(ATTACH_PARENT_PROCESS)) {
+ FILE *fpstdin = stdin;
+ FILE *fpstdout = stdout;
+ FILE *fpstderr = stderr;
- hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
+ freopen_s(&fpstdin, "CONIN$", "r", stdin);
+ freopen_s(&fpstdout, "CONOUT$", "w", stdout);
+ freopen_s(&fpstderr, "CONOUT$", "w", stderr);
- fp = _fdopen(hConHandle, "r");
-
- *stdin = *fp;
-
- setvbuf(stdin, nullptr, _IONBF, 0);
-
- // redirect unbuffered STDERR to the console
-
- lStdHandle = (intptr_t)GetStdHandle(STD_ERROR_HANDLE);
-
- hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
-
- fp = _fdopen(hConHandle, "w");
-
- *stderr = *fp;
-
- setvbuf(stderr, nullptr, _IONBF, 0);
-
- // make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog
-
- // point to console as well
+ printf("\n"); // Make sure our output is starting from the new line.
+ }
}
BOOL WINAPI HandlerRoutine(_In_ DWORD dwCtrlType) {
@@ -172,7 +122,9 @@ void OS_Windows::initialize_debugging() {
void OS_Windows::initialize() {
crash_handler.initialize();
- //RedirectIOToConsole();
+#ifndef WINDOWS_SUBSYSTEM_CONSOLE
+ RedirectIOToConsole();
+#endif
FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_RESOURCES);
FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_USERDATA);
@@ -184,12 +136,8 @@ void OS_Windows::initialize() {
NetSocketPosix::make_default();
// We need to know how often the clock is updated
- if (!QueryPerformanceFrequency((LARGE_INTEGER *)&ticks_per_second))
- ticks_per_second = 1000;
- // If timeAtGameStart is 0 then we get the time since
- // the start of the computer when we call GetGameTime()
- ticks_start = 0;
- ticks_start = get_ticks_usec();
+ QueryPerformanceFrequency((LARGE_INTEGER *)&ticks_per_second);
+ QueryPerformanceCounter((LARGE_INTEGER *)&ticks_start);
// set minimum resolution for periodic timers, otherwise Sleep(n) may wait at least as
// long as the windows scheduler resolution (~16-30ms) even for calls like Sleep(1)
@@ -369,8 +317,10 @@ uint64_t OS_Windows::get_ticks_usec() const {
uint64_t ticks;
// This is the number of clock ticks since start
- if (!QueryPerformanceCounter((LARGE_INTEGER *)&ticks))
- ticks = (UINT64)timeGetTime();
+ QueryPerformanceCounter((LARGE_INTEGER *)&ticks);
+ // Subtract the ticks at game start to get
+ // the ticks since the game started
+ ticks -= ticks_start;
// Divide by frequency to get the time in seconds
// original calculation shown below is subject to overflow
@@ -390,9 +340,6 @@ uint64_t OS_Windows::get_ticks_usec() const {
// seconds
time += seconds * 1000000L;
- // Subtract the time at game start to get
- // the time since the game started
- time -= ticks_start;
return time;
}
@@ -406,78 +353,87 @@ String OS_Windows::_quote_command_line_argument(const String &p_text) const {
return p_text;
}
-Error OS_Windows::execute(const String &p_path, const List<String> &p_arguments, String *r_pipe, int *r_exitcode, bool read_stderr, Mutex *p_pipe_mutex) {
+Error OS_Windows::execute(const String &p_path, const List<String> &p_arguments, String *r_pipe, int *r_exitcode, bool read_stderr, Mutex *p_pipe_mutex, bool p_open_console) {
String path = p_path.replace("/", "\\");
String command = _quote_command_line_argument(path);
for (const String &E : p_arguments) {
command += " " + _quote_command_line_argument(E);
}
+ ProcessInfo pi;
+ ZeroMemory(&pi.si, sizeof(pi.si));
+ pi.si.cb = sizeof(pi.si);
+ ZeroMemory(&pi.pi, sizeof(pi.pi));
+ LPSTARTUPINFOW si_w = (LPSTARTUPINFOW)&pi.si;
+
+ bool inherit_handles = false;
+ HANDLE pipe[2] = { nullptr, nullptr };
if (r_pipe) {
+ // Create pipe for StdOut and StdErr.
+ SECURITY_ATTRIBUTES sa;
+ sa.nLength = sizeof(SECURITY_ATTRIBUTES);
+ sa.bInheritHandle = true;
+ sa.lpSecurityDescriptor = nullptr;
+
+ ERR_FAIL_COND_V(!CreatePipe(&pipe[0], &pipe[1], &sa, 0), ERR_CANT_FORK);
+ ERR_FAIL_COND_V(!SetHandleInformation(pipe[0], HANDLE_FLAG_INHERIT, 0), ERR_CANT_FORK); // Read handle is for host process only and should not be inherited.
+
+ pi.si.dwFlags |= STARTF_USESTDHANDLES;
+ pi.si.hStdOutput = pipe[1];
if (read_stderr) {
- command += " 2>&1"; // Include stderr
+ pi.si.hStdError = pipe[1];
}
- // Add extra quotes around the full command, to prevent it from stripping quotes in the command,
- // because _wpopen calls command as "cmd.exe /c command", instead of executing it directly
- command = _quote_command_line_argument(command);
-
- FILE *f = _wpopen((LPCWSTR)(command.utf16().get_data()), L"r");
- ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, "Cannot create pipe from command: " + command);
- char buf[65535];
- while (fgets(buf, 65535, f)) {
+ inherit_handles = true;
+ }
+ DWORD creaton_flags = NORMAL_PRIORITY_CLASS;
+ if (p_open_console) {
+ creaton_flags |= CREATE_NEW_CONSOLE;
+ } else {
+ creaton_flags |= CREATE_NO_WINDOW;
+ }
+
+ int ret = CreateProcessW(nullptr, (LPWSTR)(command.utf16().ptrw()), nullptr, nullptr, inherit_handles, creaton_flags, nullptr, nullptr, si_w, &pi.pi);
+ if (!ret && r_pipe) {
+ CloseHandle(pipe[0]); // Cleanup pipe handles.
+ CloseHandle(pipe[1]);
+ }
+ ERR_FAIL_COND_V_MSG(ret == 0, ERR_CANT_FORK, "Could not create child process: " + command);
+
+ if (r_pipe) {
+ CloseHandle(pipe[1]); // Close pipe write handle (only child process is writing).
+ char buf[4096];
+ DWORD read = 0;
+ for (;;) { // Read StdOut and StdErr from pipe.
+ bool success = ReadFile(pipe[0], buf, 4096, &read, NULL);
+ if (!success || read == 0) {
+ break;
+ }
if (p_pipe_mutex) {
p_pipe_mutex->lock();
}
- (*r_pipe) += String::utf8(buf);
+ (*r_pipe) += String::utf8(buf, read);
if (p_pipe_mutex) {
p_pipe_mutex->unlock();
}
- }
- int rv = _pclose(f);
-
- if (r_exitcode) {
- *r_exitcode = rv;
- }
- return OK;
+ };
+ CloseHandle(pipe[0]); // Close pipe read handle.
+ } else {
+ WaitForSingleObject(pi.pi.hProcess, INFINITE);
}
- ProcessInfo pi;
- ZeroMemory(&pi.si, sizeof(pi.si));
- pi.si.cb = sizeof(pi.si);
- ZeroMemory(&pi.pi, sizeof(pi.pi));
- LPSTARTUPINFOW si_w = (LPSTARTUPINFOW)&pi.si;
-
- DWORD dwCreationFlags = NORMAL_PRIORITY_CLASS;
-#ifndef DEBUG_ENABLED
- dwCreationFlags |= CREATE_NO_WINDOW;
-#endif
-
- int ret = CreateProcessW(nullptr, (LPWSTR)(command.utf16().ptrw()), nullptr, nullptr, false, dwCreationFlags, nullptr, nullptr, si_w, &pi.pi);
- ERR_FAIL_COND_V_MSG(ret == 0, ERR_CANT_FORK, "Could not create child process: " + command);
-
- WaitForSingleObject(pi.pi.hProcess, INFINITE);
if (r_exitcode) {
DWORD ret2;
GetExitCodeProcess(pi.pi.hProcess, &ret2);
*r_exitcode = ret2;
}
+
CloseHandle(pi.pi.hProcess);
CloseHandle(pi.pi.hThread);
return OK;
};
-bool OS_Windows::_is_win11_terminal() const {
- HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
- DWORD dwMode = 0;
- if (GetConsoleMode(hStdOut, &dwMode)) {
- return ((dwMode & ENABLE_VIRTUAL_TERMINAL_PROCESSING) == ENABLE_VIRTUAL_TERMINAL_PROCESSING);
- } else {
- return false;
- }
-}
-
-Error OS_Windows::create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id) {
+Error OS_Windows::create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id, bool p_open_console) {
String path = p_path.replace("/", "\\");
String command = _quote_command_line_argument(path);
for (const String &E : p_arguments) {
@@ -490,16 +446,14 @@ Error OS_Windows::create_process(const String &p_path, const List<String> &p_arg
ZeroMemory(&pi.pi, sizeof(pi.pi));
LPSTARTUPINFOW si_w = (LPSTARTUPINFOW)&pi.si;
- DWORD dwCreationFlags = NORMAL_PRIORITY_CLASS;
-#ifndef DEBUG_ENABLED
- dwCreationFlags |= CREATE_NO_WINDOW;
-#endif
- if (p_path == get_executable_path() && GetConsoleWindow() != nullptr && _is_win11_terminal()) {
- // Open a new terminal as a workaround for Windows Terminal bug.
- dwCreationFlags |= CREATE_NEW_CONSOLE;
+ DWORD creaton_flags = NORMAL_PRIORITY_CLASS;
+ if (p_open_console) {
+ creaton_flags |= CREATE_NEW_CONSOLE;
+ } else {
+ creaton_flags |= CREATE_NO_WINDOW;
}
- int ret = CreateProcessW(nullptr, (LPWSTR)(command.utf16().ptrw()), nullptr, nullptr, false, dwCreationFlags, nullptr, nullptr, si_w, &pi.pi);
+ int ret = CreateProcessW(nullptr, (LPWSTR)(command.utf16().ptrw()), nullptr, nullptr, false, creaton_flags, nullptr, nullptr, si_w, &pi.pi);
ERR_FAIL_COND_V_MSG(ret == 0, ERR_CANT_FORK, "Could not create child process: " + command);
ProcessID pid = pi.pi.dwProcessId;
diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h
index 086f63eb3e..28baa855b4 100644
--- a/platform/windows/os_windows.h
+++ b/platform/windows/os_windows.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 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 */
@@ -128,8 +128,8 @@ public:
virtual void delay_usec(uint32_t p_usec) const override;
virtual uint64_t get_ticks_usec() const override;
- virtual Error execute(const String &p_path, const List<String> &p_arguments, String *r_pipe = nullptr, int *r_exitcode = nullptr, bool read_stderr = false, Mutex *p_pipe_mutex = nullptr) override;
- virtual Error create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id = nullptr) override;
+ virtual Error execute(const String &p_path, const List<String> &p_arguments, String *r_pipe = nullptr, int *r_exitcode = nullptr, bool read_stderr = false, Mutex *p_pipe_mutex = nullptr, bool p_open_console = false) override;
+ virtual Error create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id = nullptr, bool p_open_console = false) override;
virtual Error kill(const ProcessID &p_pid) override;
virtual int get_process_id() const override;
@@ -157,7 +157,6 @@ public:
void run();
- bool _is_win11_terminal() const;
virtual bool _check_internal_feature_support(const String &p_feature) override;
virtual void disable_crash_handler() override;
diff --git a/platform/windows/platform_config.h b/platform/windows/platform_config.h
index dace0f86af..8e80f8cacb 100644
--- a/platform/windows/platform_config.h
+++ b/platform/windows/platform_config.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 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 */
diff --git a/platform/windows/vulkan_context_win.cpp b/platform/windows/vulkan_context_win.cpp
index db5e6466be..07c41395fb 100644
--- a/platform/windows/vulkan_context_win.cpp
+++ b/platform/windows/vulkan_context_win.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 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 */
diff --git a/platform/windows/vulkan_context_win.h b/platform/windows/vulkan_context_win.h
index 61e66b8ae0..e68f0125ca 100644
--- a/platform/windows/vulkan_context_win.h
+++ b/platform/windows/vulkan_context_win.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 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 */
diff --git a/platform/windows/windows_terminal_logger.cpp b/platform/windows/windows_terminal_logger.cpp
index d4148630f0..0d5f0e617c 100644
--- a/platform/windows/windows_terminal_logger.cpp
+++ b/platform/windows/windows_terminal_logger.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 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 */
diff --git a/platform/windows/windows_terminal_logger.h b/platform/windows/windows_terminal_logger.h
index 86b65ae30a..1045f12201 100644
--- a/platform/windows/windows_terminal_logger.h
+++ b/platform/windows/windows_terminal_logger.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 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 */