[client,common] fix -mouse-motion

* Move code to client/common to have it in place for all clients without
  modification
* Remember if a button was pressed and only suppress move events if no
  button is pressed.
This commit is contained in:
akallabeth
2025-06-18 11:25:40 +02:00
parent a845647627
commit 4dc6091fde
5 changed files with 38 additions and 16 deletions

View File

@@ -413,19 +413,13 @@ static BOOL xf_event_VisibilityNotify(xfContext* xfc, const XVisibilityEvent* ev
return TRUE;
}
BOOL xf_generic_MotionNotify(xfContext* xfc, int x, int y, int state, Window window, BOOL app)
BOOL xf_generic_MotionNotify(xfContext* xfc, int x, int y, Window window, BOOL app)
{
Window childWindow = None;
WINPR_ASSERT(xfc);
WINPR_ASSERT(xfc->common.context.settings);
if (!freerdp_settings_get_bool(xfc->common.context.settings, FreeRDP_MouseMotion))
{
if ((state & (Button1Mask | Button2Mask | Button3Mask)) == 0)
return TRUE;
}
if (app)
{
/* make sure window exists */
@@ -474,8 +468,7 @@ static BOOL xf_event_MotionNotify(xfContext* xfc, const XMotionEvent* event, BOO
(xfc->common.mouse_grabbed && freerdp_client_use_relative_mouse_events(&xfc->common)))
return TRUE;
return xf_generic_MotionNotify(xfc, event->x, event->y,
WINPR_ASSERTING_INT_CAST(int, event->state), event->window, app);
return xf_generic_MotionNotify(xfc, event->x, event->y, event->window, app);
}
BOOL xf_generic_ButtonEvent(xfContext* xfc, int x, int y, int button, Window window, BOOL app,

View File

@@ -37,7 +37,7 @@ void xf_event_SendClientEvent(xfContext* xfc, xfWindow* window, Atom atom, unsig
void xf_event_adjust_coordinates(xfContext* xfc, int* x, int* y);
void xf_adjust_coordinates_to_screen(xfContext* xfc, UINT32* x, UINT32* y);
BOOL xf_generic_MotionNotify(xfContext* xfc, int x, int y, int state, Window window, BOOL app);
BOOL xf_generic_MotionNotify(xfContext* xfc, int x, int y, Window window, BOOL app);
BOOL xf_generic_RawMotionNotify(xfContext* xfc, int x, int y, Window window, BOOL app);
BOOL xf_generic_ButtonEvent(xfContext* xfc, int x, int y, int button, Window window, BOOL app,
BOOL down);

View File

@@ -788,8 +788,8 @@ int xf_input_event(xfContext* xfc, WINPR_ATTR_UNUSED const XEvent* xevent, XIDev
if (xfc->xi_event)
{
xf_generic_MotionNotify(xfc, (int)event->event_x, (int)event->event_y,
event->detail, event->event, xfc->remote_app);
xf_generic_MotionNotify(xfc, (int)event->event_x, (int)event->event_y, event->event,
xfc->remote_app);
}
break;
case XI_RawButtonPress:

View File

@@ -1646,6 +1646,18 @@ static INLINE BOOL ainput_send_diff_event(rdpClientContext* cctx, UINT64 flags,
}
#endif
static bool button_pressed(const rdpClientContext* cctx)
{
WINPR_ASSERT(cctx);
for (size_t x = 0; x < ARRAYSIZE(cctx->pressed_buttons); x++)
{
const BOOL cur = cctx->pressed_buttons[x];
if (cur)
return true;
}
return false;
}
BOOL freerdp_client_send_button_event(rdpClientContext* cctx, BOOL relative, UINT16 mflags, INT32 x,
INT32 y)
{
@@ -1653,6 +1665,20 @@ BOOL freerdp_client_send_button_event(rdpClientContext* cctx, BOOL relative, UIN
WINPR_ASSERT(cctx);
if (mflags & PTR_FLAGS_BUTTON1)
cctx->pressed_buttons[0] = mflags & PTR_FLAGS_DOWN;
if (mflags & PTR_FLAGS_BUTTON2)
cctx->pressed_buttons[1] = mflags & PTR_FLAGS_DOWN;
if (mflags & PTR_FLAGS_BUTTON3)
cctx->pressed_buttons[2] = mflags & PTR_FLAGS_DOWN;
if (((mflags & PTR_FLAGS_MOVE) != 0) &&
!freerdp_settings_get_bool(cctx->context.settings, FreeRDP_MouseMotion))
{
if (!button_pressed(cctx))
return TRUE;
}
const BOOL haveRelative =
freerdp_settings_get_bool(cctx->context.settings, FreeRDP_HasRelativeMouseEvent);
if (relative && haveRelative)
@@ -1712,6 +1738,11 @@ BOOL freerdp_client_send_extended_button_event(rdpClientContext* cctx, BOOL rela
BOOL handled = FALSE;
WINPR_ASSERT(cctx);
if (mflags & PTR_XFLAGS_BUTTON1)
cctx->pressed_buttons[3] = mflags & PTR_XFLAGS_DOWN;
if (mflags & PTR_XFLAGS_BUTTON2)
cctx->pressed_buttons[4] = mflags & PTR_XFLAGS_DOWN;
const BOOL haveRelative =
freerdp_settings_get_bool(cctx->context.settings, FreeRDP_HasRelativeMouseEvent);
if (relative && haveRelative)

View File

@@ -144,7 +144,8 @@ extern "C"
ALIGN64 FreeRDP_PenDevice pens[FREERDP_MAX_PEN_DEVICES]; /**< (offset 9) */
ALIGN64 MIBClientWrapper* mibClientWrapper; /**< (offset 10) @since version 3.16.0 */
UINT64 reserved[129 - 11]; /**< (offset 11) */
ALIGN64 BOOL pressed_buttons[5]; /**< (offset 11) @since version 3.17.0 */
UINT64 reserved[129 - 16]; /**< (offset 16) */
};
/* Common client functions */
@@ -292,9 +293,6 @@ extern "C"
FREERDP_API BOOL freerdp_client_send_wheel_event(rdpClientContext* cctx, UINT16 mflags);
FREERDP_API BOOL freerdp_client_send_mouse_event(rdpClientContext* cctx, UINT64 mflags, INT32 x,
INT32 y);
/** @brief this function checks if relative mouse events are supported and enabled for this
* session.
*