diff options
Diffstat (limited to 'platform/windows/os_windows.cpp')
-rw-r--r-- | platform/windows/os_windows.cpp | 118 |
1 files changed, 57 insertions, 61 deletions
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 739fcbacda..bdf459fd83 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -58,11 +58,8 @@ static const WORD MAX_CONSOLE_LINES = 1500; extern "C" { -#ifdef _MSC_VER -_declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; -#else -__attribute__((visibility("default"))) DWORD NvOptimusEnablement = 0x00000001; -#endif +__declspec(dllexport) DWORD NvOptimusEnablement = 1; +__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; } // Workaround mingw-w64 < 4.0 bug @@ -303,19 +300,17 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { case WM_SETFOCUS: { window_has_focus = true; - // Re-capture cursor if we're in one of the capture modes - if (mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED) { - SetCapture(hWnd); - } + + // Restore mouse mode + _set_mouse_mode_impl(mouse_mode); + break; } case WM_KILLFOCUS: { window_has_focus = false; - // Release capture if we're in one of the capture modes - if (mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED) { - ReleaseCapture(); - } + // Release capture unconditionally because it can be set due to dragging, in addition to captured mode + ReleaseCapture(); // Release every touch to avoid sticky points for (Map<int, Vector2>::Element *E = touch_state.front(); E; E = E->next()) { @@ -337,15 +332,7 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) alt_mem = false; control_mem = false; shift_mem = false; - if (mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED) { - RECT clipRect; - GetClientRect(hWnd, &clipRect); - ClientToScreen(hWnd, (POINT *)&clipRect.left); - ClientToScreen(hWnd, (POINT *)&clipRect.right); - ClipCursor(&clipRect); - SetCapture(hWnd); - } - } else { + } else { // WM_INACTIVE main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT); alt_mem = false; }; @@ -705,12 +692,14 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) if (uMsg != WM_MOUSEWHEEL && uMsg != WM_MOUSEHWHEEL) { if (mb->is_pressed()) { - if (++pressrc > 0) + if (++pressrc > 0 && mouse_mode != MOUSE_MODE_CAPTURED) SetCapture(hWnd); } else { if (--pressrc <= 0) { - ReleaseCapture(); + if (mouse_mode != MOUSE_MODE_CAPTURED) { + ReleaseCapture(); + } pressrc = 0; } } @@ -763,7 +752,7 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) RECT r; GetWindowRect(hWnd, &r); - dib_size = Size2(r.right - r.left, r.bottom - r.top); + dib_size = Size2i(r.right - r.left, r.bottom - r.top); BITMAPINFO bmi; ZeroMemory(&bmi, sizeof(BITMAPINFO)); @@ -773,7 +762,7 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 32; bmi.bmiHeader.biCompression = BI_RGB; - bmi.bmiHeader.biSizeImage = dib_size.x, dib_size.y * 4; + bmi.bmiHeader.biSizeImage = dib_size.x * dib_size.y * 4; hBitmap = CreateDIBSection(hDC_dib, &bmi, DIB_RGB_COLORS, (void **)&dib_data, NULL, 0x0); SelectObject(hDC_dib, hBitmap); @@ -1050,7 +1039,6 @@ static int QueryDpiForMonitor(HMONITOR hmon, _MonitorDpiType dpiType = MDT_Defau UINT x = 0, y = 0; HRESULT hr = E_FAIL; - bool bSet = false; if (hmon && (Shcore != (HMODULE)INVALID_HANDLE_VALUE)) { hr = getDPIForMonitor(hmon, dpiType /*MDT_Effective_DPI*/, &x, &y); if (SUCCEEDED(hr) && (x > 0) && (y > 0)) { @@ -1204,7 +1192,14 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); - char *windowid = getenv("GODOT_WINDOWID"); + char *windowid; +#ifdef MINGW_ENABLED + windowid = getenv("GODOT_WINDOWID"); +#else + size_t len; + _dupenv_s(&windowid, &len, "GODOT_WINDOWID"); +#endif + if (windowid) { // strtoull on mingw @@ -1213,6 +1208,7 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int #else hWnd = (HWND)_strtoui64(windowid, NULL, 0); #endif + free(windowid); SetLastError(0); user_proc = (WNDPROC)GetWindowLongPtr(hWnd, GWLP_WNDPROC); SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)(WNDPROC)::WndProc); @@ -1221,7 +1217,7 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int printf("Error setting WNDPROC: %li\n", le); }; - LONG_PTR proc = GetWindowLongPtr(hWnd, GWLP_WNDPROC); + GetWindowLongPtr(hWnd, GWLP_WNDPROC); RECT rect; if (!GetClientRect(hWnd, &rect)) { @@ -1327,24 +1323,9 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int visual_server = memnew(VisualServerRaster); if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) { - visual_server = memnew(VisualServerWrapMT(visual_server, get_render_thread_mode() == RENDER_SEPARATE_THREAD)); } - /* - DEVMODE dmScreenSettings; // Device Mode - memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // Makes Sure Memory's Cleared - dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The Devmode Structure - dmScreenSettings.dmPelsWidth = width; // Selected Screen Width - dmScreenSettings.dmPelsHeight = height; // Selected Screen Height - dmScreenSettings.dmBitsPerPel = bits; // Selected Bits Per Pixel - dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; - if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL) - - - - - */ visual_server->init(); input = memnew(InputDefault); @@ -1527,18 +1508,27 @@ void OS_Windows::set_mouse_mode(MouseMode p_mode) { if (mouse_mode == p_mode) return; + + _set_mouse_mode_impl(p_mode); + mouse_mode = p_mode; - if (mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED) { +} + +void OS_Windows::_set_mouse_mode_impl(MouseMode p_mode) { + + if (p_mode == MOUSE_MODE_CAPTURED || p_mode == MOUSE_MODE_CONFINED) { RECT clipRect; GetClientRect(hWnd, &clipRect); ClientToScreen(hWnd, (POINT *)&clipRect.left); ClientToScreen(hWnd, (POINT *)&clipRect.right); ClipCursor(&clipRect); - center = Point2i(video_mode.width / 2, video_mode.height / 2); - POINT pos = { (int)center.x, (int)center.y }; - ClientToScreen(hWnd, &pos); - if (mouse_mode == MOUSE_MODE_CAPTURED) + if (p_mode == MOUSE_MODE_CAPTURED) { + center = Point2i(video_mode.width / 2, video_mode.height / 2); + POINT pos = { (int)center.x, (int)center.y }; + ClientToScreen(hWnd, &pos); SetCursorPos(pos.x, pos.y); + SetCapture(hWnd); + } } else { ReleaseCapture(); ClipCursor(NULL); @@ -1552,7 +1542,6 @@ void OS_Windows::set_mouse_mode(MouseMode p_mode) { set_cursor_shape(c); } } - OS_Windows::MouseMode OS_Windows::get_mouse_mode() const { return mouse_mode; @@ -1720,14 +1709,18 @@ void OS_Windows::set_window_position(const Point2 &p_position) { Size2 OS_Windows::get_window_size() const { RECT r; - GetClientRect(hWnd, &r); - return Vector2(r.right - r.left, r.bottom - r.top); + if (GetClientRect(hWnd, &r)) { // Only area inside of window border + return Size2(r.right - r.left, r.bottom - r.top); + } + return Size2(); } Size2 OS_Windows::get_real_window_size() const { RECT r; - GetWindowRect(hWnd, &r); - return Vector2(r.right - r.left, r.bottom - r.top); + if (GetWindowRect(hWnd, &r)) { // Includes area of the window border + return Size2(r.right - r.left, r.bottom - r.top); + } + return Size2(); } void OS_Windows::set_window_size(const Size2 p_size) { @@ -2266,7 +2259,6 @@ void OS_Windows::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shap ERR_FAIL_COND(!image.is_valid()); UINT image_size = texture_size.width * texture_size.height; - UINT size = sizeof(UINT) * image_size; // Create the BITMAP with alpha channel COLORREF *buffer = (COLORREF *)memalloc(sizeof(COLORREF) * image_size); @@ -2546,7 +2538,16 @@ void OS_Windows::set_icon(const Ref<Image> &p_icon) { bool OS_Windows::has_environment(const String &p_var) const { +#ifdef MINGW_ENABLED return _wgetenv(p_var.c_str()) != NULL; +#else + wchar_t *env; + size_t len; + _wdupenv_s(&env, &len, p_var.c_str()); + const bool has_env = env != NULL; + free(env); + return has_env; +#endif }; String OS_Windows::get_environment(const String &p_var) const { @@ -2729,11 +2730,6 @@ void OS_Windows::run() { main_loop->init(); - uint64_t last_ticks = get_ticks_usec(); - - int frames = 0; - uint64_t frame = 0; - while (!force_quit) { process_events(); // get rid of pending events @@ -2926,7 +2922,7 @@ bool OS_Windows::is_disable_crash_handler() const { Error OS_Windows::move_to_trash(const String &p_path) { SHFILEOPSTRUCTW sf; WCHAR *from = new WCHAR[p_path.length() + 2]; - wcscpy(from, p_path.c_str()); + wcscpy_s(from, p_path.length() + 1, p_path.c_str()); from[p_path.length() + 1] = 0; sf.hwnd = hWnd; |