Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix differences between Windows and linuxbsd Display Server #67903

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 33 additions & 12 deletions platform/windows/display_server_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2444,10 +2444,12 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
return 0; // Jump back.
}
case WM_MOUSELEAVE: {
old_invalid = true;
windows[window_id].mouse_outside = true;
if (window_mouseover_id == window_id) {
old_invalid = true;
window_mouseover_id = INVALID_WINDOW_ID;

_send_window_event(windows[window_id], WINDOW_EVENT_MOUSE_EXIT);
_send_window_event(windows[window_id], WINDOW_EVENT_MOUSE_EXIT);
}

} break;
case WM_INPUT: {
Expand Down Expand Up @@ -2678,17 +2680,21 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
}
}

if (windows[window_id].mouse_outside) {
if (window_mouseover_id != window_id) {
// Mouse enter.

if (mouse_mode != MOUSE_MODE_CAPTURED) {
if (window_mouseover_id != INVALID_WINDOW_ID) {
// Leave previous window.
_send_window_event(windows[window_mouseover_id], WINDOW_EVENT_MOUSE_EXIT);
}
_send_window_event(windows[window_id], WINDOW_EVENT_MOUSE_ENTER);
}

CursorShape c = cursor_shape;
cursor_shape = CURSOR_MAX;
cursor_set_shape(c);
windows[window_id].mouse_outside = false;
window_mouseover_id = window_id;

// Once-off notification, must call again.
track_mouse_leave_event(hWnd);
Expand Down Expand Up @@ -2779,17 +2785,29 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
}
}

if (windows[window_id].mouse_outside) {
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())) {
// Don't consider the windowborder as part of the window.
over_id = INVALID_WINDOW_ID;
}
if (window_mouseover_id != over_id) {
// Mouse enter.

if (mouse_mode != MOUSE_MODE_CAPTURED) {
_send_window_event(windows[window_id], WINDOW_EVENT_MOUSE_ENTER);
if (window_mouseover_id != INVALID_WINDOW_ID) {
// Leave previous window.
_send_window_event(windows[window_mouseover_id], WINDOW_EVENT_MOUSE_EXIT);
}

if (over_id != INVALID_WINDOW_ID) {
_send_window_event(windows[over_id], WINDOW_EVENT_MOUSE_ENTER);
}
}

CursorShape c = cursor_shape;
cursor_shape = CURSOR_MAX;
cursor_set_shape(c);
windows[window_id].mouse_outside = false;
window_mouseover_id = over_id;

// Once-off notification, must call again.
track_mouse_leave_event(hWnd);
Expand All @@ -2800,9 +2818,13 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
break;
}

DisplayServer::WindowID receiving_window_id = _get_focused_window_or_popup();
if (receiving_window_id == INVALID_WINDOW_ID) {
receiving_window_id = window_id;
}
Ref<InputEventMouseMotion> mm;
mm.instantiate();
mm->set_window_id(window_id);
mm->set_window_id(receiving_window_id);
mm->set_ctrl_pressed((wParam & MK_CONTROL) != 0);
mm->set_shift_pressed((wParam & MK_SHIFT) != 0);
mm->set_alt_pressed(alt_mem);
Expand Down Expand Up @@ -2859,9 +2881,8 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
mm->set_relative(Vector2(mm->get_position() - Vector2(old_x, old_y)));
old_x = mm->get_position().x;
old_y = mm->get_position().y;
if (windows[window_id].window_has_focus || window_get_active_popup() == window_id) {
Input::get_singleton()->parse_input_event(mm);
}

Input::get_singleton()->parse_input_event(mm);

} break;
case WM_LBUTTONDOWN:
Expand Down
3 changes: 2 additions & 1 deletion platform/windows/display_server_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ class DisplayServerWindows : public DisplayServer {
LPARAM lParam;
};

WindowID window_mouseover_id = INVALID_WINDOW_ID;

KeyEvent key_event_buffer[KEY_EVENT_BUFFER_SIZE];
int key_event_pos;

Expand Down Expand Up @@ -398,7 +400,6 @@ class DisplayServerWindows : public DisplayServer {

Size2 window_rect;
Point2 last_pos;
bool mouse_outside = true;

ObjectID instance_id;

Expand Down