diff options
author | Juan Linietsky <reduzio@gmail.com> | 2020-03-14 13:06:39 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2020-03-26 15:49:43 +0100 |
commit | c7b4dcae2f3b75ad7146e36f196893731f403144 (patch) | |
tree | d6223521b246aa36d0e0b78d6ed626fa2a0e3769 /platform/windows | |
parent | 441f1a5fe9a3bf0e4e5dab578f793500b1ff6e3d (diff) |
Open sub-windows as embedded if the OS does not support them
Diffstat (limited to 'platform/windows')
-rw-r--r-- | platform/windows/display_server_windows.cpp | 57 | ||||
-rw-r--r-- | platform/windows/display_server_windows.h | 4 |
2 files changed, 45 insertions, 16 deletions
diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index e2c78da5a9..b895632848 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -420,6 +420,10 @@ DisplayServer::WindowID DisplayServerWindows::create_sub_window(WindowMode p_mod } } + ShowWindow(windows[window_id].hWnd, SW_SHOW); // Show The Window + SetForegroundWindow(windows[window_id].hWnd); // Slightly Higher Priority + SetFocus(windows[window_id].hWnd); // Sets Keyboard Focus To + return window_id; } void DisplayServerWindows::delete_sub_window(WindowID p_window) { @@ -449,12 +453,12 @@ void DisplayServerWindows::delete_sub_window(WindowID p_window) { windows.erase(p_window); } -void DisplayServerWindows::window_set_resize_callback(const Callable &p_callable, WindowID p_window) { +void DisplayServerWindows::window_set_rect_changed_callback(const Callable &p_callable, WindowID p_window) { _THREAD_SAFE_METHOD_ ERR_FAIL_COND(!windows.has(p_window)); - windows[p_window].resize_callback = p_callable; + windows[p_window].rect_changed_callback = p_callable; } void DisplayServerWindows::window_set_window_event_callback(const Callable &p_callable, WindowID p_window) { @@ -757,20 +761,32 @@ void DisplayServerWindows::_update_window_style(WindowID p_window, bool p_repain ERR_FAIL_COND(!windows.has(p_window)); WindowData &wd = windows[p_window]; + DWORD style = 0; + DWORD style_ex = WS_EX_WINDOWEDGE; + if (p_window == MAIN_WINDOW_ID) { + style_ex |= WS_EX_APPWINDOW; + } + if (wd.fullscreen || wd.borderless) { - SetWindowLongPtr(wd.hWnd, GWL_STYLE, WS_SYSMENU | WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE); + style = WS_SYSMENU | WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE; + if (wd.borderless) { + style_ex |= WS_EX_TOOLWINDOW; + } } else { if (wd.resizable) { if (p_maximized) { - SetWindowLongPtr(wd.hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_MAXIMIZE); + style = WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_MAXIMIZE; } else { - SetWindowLongPtr(wd.hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE); + style = GWL_STYLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE; } } else { - SetWindowLongPtr(wd.hWnd, GWL_STYLE, WS_CAPTION | WS_MINIMIZEBOX | WS_POPUPWINDOW | WS_VISIBLE); + style = WS_CAPTION | WS_MINIMIZEBOX | WS_POPUPWINDOW | WS_VISIBLE; } } + SetWindowLongPtr(wd.hWnd, GWL_STYLE, style); + SetWindowLongPtr(wd.hWnd, GWL_EXSTYLE, style_ex); + SetWindowPos(wd.hWnd, wd.always_on_top ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE); if (p_repaint) { @@ -2208,6 +2224,15 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA int x = LOWORD(lParam); int y = HIWORD(lParam); windows[window_id].last_pos = Point2(x, y); + + if (!windows[window_id].rect_changed_callback.is_null()) { + + Variant size = Rect2i(windows[window_id].last_pos.x, windows[window_id].last_pos.y, windows[window_id].width, windows[window_id].height); + Variant *sizep = &size; + Variant ret; + Callable::CallError ce; + windows[window_id].rect_changed_callback.call((const Variant **)&sizep, 1, ret, ce); + } } } break; @@ -2232,13 +2257,13 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA } } - if (!windows[window_id].resize_callback.is_null()) { + if (!windows[window_id].rect_changed_callback.is_null()) { - Variant size = Size2(windows[window_id].width, windows[window_id].height); + Variant size = Rect2i(windows[window_id].last_pos.x, windows[window_id].last_pos.y, windows[window_id].width, windows[window_id].height); Variant *sizep = &size; Variant ret; Callable::CallError ce; - windows[window_id].resize_callback.call((const Variant **)&sizep, 1, ret, ce); + windows[window_id].rect_changed_callback.call((const Variant **)&sizep, 1, ret, ce); } if (wParam == SIZE_MAXIMIZED) { @@ -2541,9 +2566,13 @@ DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode, DWORD dwExStyle; DWORD dwStyle; - dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; + dwExStyle = WS_EX_WINDOWEDGE; dwStyle = WS_OVERLAPPEDWINDOW; + if (window_id_counter == MAIN_WINDOW_ID) { + dwExStyle |= WS_EX_APPWINDOW; + } + RECT WindowRect; WindowRect.left = p_rect.position.x; @@ -2594,10 +2623,6 @@ DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode, DragAcceptFiles(wd.hWnd, true); - ShowWindow(wd.hWnd, SW_SHOW); // Show The Window - SetForegroundWindow(wd.hWnd); // Slightly Higher Priority - SetFocus(wd.hWnd); // Sets Keyboard Focus To - // IME wd.im_himc = ImmGetContext(wd.hWnd); ImmReleaseContext(wd.hWnd, wd.im_himc); @@ -2743,6 +2768,10 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win } } + ShowWindow(windows[MAIN_WINDOW_ID].hWnd, SW_SHOW); // Show The Window + SetForegroundWindow(windows[MAIN_WINDOW_ID].hWnd); // Slightly Higher Priority + SetFocus(windows[MAIN_WINDOW_ID].hWnd); // Sets Keyboard Focus To + #if defined(VULKAN_ENABLED) if (rendering_driver == "vulkan") { diff --git a/platform/windows/display_server_windows.h b/platform/windows/display_server_windows.h index 0c07e6283c..ba9eef886b 100644 --- a/platform/windows/display_server_windows.h +++ b/platform/windows/display_server_windows.h @@ -200,7 +200,7 @@ class DisplayServerWindows : public DisplayServer { bool layered_window = false; - Callable resize_callback; + Callable rect_changed_callback; Callable event_callback; Callable input_event_callback; Callable input_text_callback; @@ -293,7 +293,7 @@ public: virtual WindowID create_sub_window(WindowMode p_mode, uint32_t p_flags, const Rect2i &p_rect = Rect2i()); virtual void delete_sub_window(WindowID p_window); - virtual void window_set_resize_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID); + virtual void window_set_rect_changed_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID); virtual void window_set_window_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID); virtual void window_set_input_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID); |