[Windows] Window management fixes.

Fix popup menus having incorrect scale when main window is in full-screen mode and multiple monitors with different DPI are used.
Prevent mouse move code from accessing deleted window data (and creating zombie records in the windows map).
This commit is contained in:
bruvzg 2022-12-06 23:56:07 +02:00
parent c241f1c523
commit e1cff4be9b

View File

@ -2473,7 +2473,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
window_mouseover_id = INVALID_WINDOW_ID;
_send_window_event(windows[window_id], WINDOW_EVENT_MOUSE_EXIT);
} else if (window_mouseover_id != INVALID_WINDOW_ID) {
} else if (window_mouseover_id != INVALID_WINDOW_ID && windows.has(window_mouseover_id)) {
// This is reached during drag and drop, after dropping in a different window.
// Once-off notification, must call again.
track_mouse_leave_event(windows[window_mouseover_id].hWnd);
@ -2712,7 +2712,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
// Mouse enter.
if (mouse_mode != MOUSE_MODE_CAPTURED) {
if (window_mouseover_id != INVALID_WINDOW_ID) {
if (window_mouseover_id != INVALID_WINDOW_ID && windows.has(window_mouseover_id)) {
// Leave previous window.
_send_window_event(windows[window_mouseover_id], WINDOW_EVENT_MOUSE_EXIT);
}
@ -2814,7 +2814,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
}
DisplayServer::WindowID over_id = get_window_at_screen_position(mouse_get_position());
if (!Rect2(window_get_position(over_id), Point2(windows[over_id].width, windows[over_id].height)).has_point(mouse_get_position())) {
if (windows.has(over_id) && !Rect2(window_get_position(over_id), Point2(windows[over_id].width, windows[over_id].height)).has_point(mouse_get_position())) {
// Don't consider the windowborder as part of the window.
over_id = INVALID_WINDOW_ID;
}
@ -2822,12 +2822,12 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
// Mouse enter.
if (mouse_mode != MOUSE_MODE_CAPTURED) {
if (window_mouseover_id != INVALID_WINDOW_ID) {
if (window_mouseover_id != INVALID_WINDOW_ID && windows.has(window_mouseover_id)) {
// Leave previous window.
_send_window_event(windows[window_mouseover_id], WINDOW_EVENT_MOUSE_EXIT);
}
if (over_id != INVALID_WINDOW_ID) {
if (over_id != INVALID_WINDOW_ID && windows.has(over_id)) {
_send_window_event(windows[over_id], WINDOW_EVENT_MOUSE_ENTER);
}
}
@ -3520,7 +3520,7 @@ DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode,
DWORD dwExStyle;
DWORD dwStyle;
_get_window_style(window_id_counter == MAIN_WINDOW_ID, (p_mode == WINDOW_MODE_FULLSCREEN || p_mode == WINDOW_MODE_EXCLUSIVE_FULLSCREEN), p_mode == WINDOW_MODE_EXCLUSIVE_FULLSCREEN, p_flags & WINDOW_FLAG_BORDERLESS_BIT, !(p_flags & WINDOW_FLAG_RESIZE_DISABLED_BIT), p_mode == WINDOW_MODE_MAXIMIZED, (p_flags & WINDOW_FLAG_NO_FOCUS_BIT), dwStyle, dwExStyle);
_get_window_style(window_id_counter == MAIN_WINDOW_ID, (p_mode == WINDOW_MODE_FULLSCREEN || p_mode == WINDOW_MODE_EXCLUSIVE_FULLSCREEN), p_mode == WINDOW_MODE_EXCLUSIVE_FULLSCREEN, p_flags & WINDOW_FLAG_BORDERLESS_BIT, !(p_flags & WINDOW_FLAG_RESIZE_DISABLED_BIT), p_mode == WINDOW_MODE_MAXIMIZED, (p_flags & WINDOW_FLAG_NO_FOCUS_BIT) | (p_flags & WINDOW_FLAG_POPUP), dwStyle, dwExStyle);
RECT WindowRect;