Skip to content

Commit

Permalink
Fix confined mouse mode not updating on resize
Browse files Browse the repository at this point in the history
  • Loading branch information
RedMser committed Jan 10, 2023
1 parent fcba87e commit 951349c
Showing 1 changed file with 9 additions and 36 deletions.
45 changes: 9 additions & 36 deletions platform/windows/display_server_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -974,15 +974,6 @@ void DisplayServerWindows::window_set_current_screen(int p_screen, WindowID p_wi
wpos.y = CLAMP(wpos.y, srect.position.y, srect.position.y + srect.size.height - wsize.height / 3);
window_set_position(wpos, p_window);
}

// Don't let the mouse leave the window when resizing to a smaller resolution.
if (mouse_mode == MOUSE_MODE_CONFINED || mouse_mode == MOUSE_MODE_CONFINED_HIDDEN) {
RECT crect;
GetClientRect(wd.hWnd, &crect);
ClientToScreen(wd.hWnd, (POINT *)&crect.left);
ClientToScreen(wd.hWnd, (POINT *)&crect.right);
ClipCursor(&crect);
}
}

Point2i DisplayServerWindows::window_get_position(WindowID p_window) const {
Expand Down Expand Up @@ -1060,15 +1051,6 @@ void DisplayServerWindows::window_set_position(const Point2i &p_position, Window
AdjustWindowRectEx(&rc, style, false, exStyle);
MoveWindow(wd.hWnd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, TRUE);

// Don't let the mouse leave the window when moved.
if (mouse_mode == MOUSE_MODE_CONFINED || mouse_mode == MOUSE_MODE_CONFINED_HIDDEN) {
RECT rect;
GetClientRect(wd.hWnd, &rect);
ClientToScreen(wd.hWnd, (POINT *)&rect.left);
ClientToScreen(wd.hWnd, (POINT *)&rect.right);
ClipCursor(&rect);
}

wd.last_pos = p_position;
_update_real_mouse_position(p_window);
}
Expand Down Expand Up @@ -1210,15 +1192,6 @@ void DisplayServerWindows::window_set_size(const Size2i p_size, WindowID p_windo
}

MoveWindow(wd.hWnd, rect.left, rect.top, w, h, TRUE);

// Don't let the mouse leave the window when resizing to a smaller resolution.
if (mouse_mode == MOUSE_MODE_CONFINED || mouse_mode == MOUSE_MODE_CONFINED_HIDDEN) {
RECT crect;
GetClientRect(wd.hWnd, &crect);
ClientToScreen(wd.hWnd, (POINT *)&crect.left);
ClientToScreen(wd.hWnd, (POINT *)&crect.right);
ClipCursor(&crect);
}
}

Size2i DisplayServerWindows::window_get_size(WindowID p_window) const {
Expand Down Expand Up @@ -1406,15 +1379,6 @@ void DisplayServerWindows::window_set_mode(WindowMode p_mode, WindowID p_window)
SystemParametersInfoA(SPI_SETMOUSETRAILS, 0, 0, 0);
}
}

// Don't let the mouse leave the window when resizing to a smaller resolution.
if (mouse_mode == MOUSE_MODE_CONFINED || mouse_mode == MOUSE_MODE_CONFINED_HIDDEN) {
RECT crect;
GetClientRect(wd.hWnd, &crect);
ClientToScreen(wd.hWnd, (POINT *)&crect.left);
ClientToScreen(wd.hWnd, (POINT *)&crect.right);
ClipCursor(&crect);
}
}

DisplayServer::WindowMode DisplayServerWindows::window_get_mode(WindowID p_window) const {
Expand Down Expand Up @@ -3278,6 +3242,15 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
Callable::CallError ce;
window.rect_changed_callback.callp(args, 1, ret, ce);
}

// Update cursor clip region after window rect has changed.
if (mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED || mouse_mode == MOUSE_MODE_CONFINED_HIDDEN) {
RECT crect;
GetClientRect(window.hWnd, &crect);
ClientToScreen(window.hWnd, (POINT *)&crect.left);
ClientToScreen(window.hWnd, (POINT *)&crect.right);
ClipCursor(&crect);
}
}

// Return here to prevent WM_MOVE and WM_SIZE from being sent
Expand Down

0 comments on commit 951349c

Please sign in to comment.