mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/win32-vd_agent
synced 2026-01-07 11:08:57 +00:00
handle_mouse_event: fix off-by-one when normalizing mouse coordinates
Mouse coordinates can be 0..(width-1) and 0..(height-1) Normalization of mouse coordinates (for SendInput) was done against w,h and thus right-most and down-most coordinates could never be reached. Fix it by normalizing against (w-1) and (h-1). Also added protection against a case of 0 or 1 (for any of w,h) Fixes rhbz#1032037
This commit is contained in:
parent
259d6b5bdb
commit
5edf7433a4
@ -567,13 +567,15 @@ bool VDAgent::handle_mouse_event(VDAgentMouseState* state)
|
||||
ZeroMemory(&_input, sizeof(INPUT));
|
||||
_input.type = INPUT_MOUSE;
|
||||
if (state->x != _mouse_x || state->y != _mouse_y) {
|
||||
DWORD w = _desktop_layout->get_total_width();
|
||||
DWORD h = _desktop_layout->get_total_height();
|
||||
w = (w > 1) ? w-1 : 1; /* coordinates are 0..w-1, protect w==0 */
|
||||
h = (h > 1) ? h-1 : 1; /* coordinates are 0..h-1, protect h==0 */
|
||||
_mouse_x = state->x;
|
||||
_mouse_y = state->y;
|
||||
mouse_move = MOUSEEVENTF_MOVE;
|
||||
_input.mi.dx = (mode->get_pos_x() + _mouse_x) * 0xffff /
|
||||
_desktop_layout->get_total_width();
|
||||
_input.mi.dy = (mode->get_pos_y() + _mouse_y) * 0xffff /
|
||||
_desktop_layout->get_total_height();
|
||||
_input.mi.dx = (mode->get_pos_x() + _mouse_x) * 0xffff / w;
|
||||
_input.mi.dy = (mode->get_pos_y() + _mouse_y) * 0xffff / h;
|
||||
}
|
||||
if (state->buttons != _buttons_state) {
|
||||
buttons_change = get_buttons_change(_buttons_state, state->buttons, VD_AGENT_LBUTTON_MASK,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user