24 #include <linux/input.h>
26 #include <winpr/assert.h>
28 #include <freerdp/config.h>
29 #include <freerdp/locale/keyboard.h>
30 #if defined(CHANNEL_RDPEI_CLIENT)
31 #include <freerdp/client/rdpei.h>
33 #include <uwac/uwac.h>
35 #include "wlfreerdp.h"
36 #include "wlf_input.h"
38 static BOOL scale_signed_coordinates(rdpContext* context, int32_t* x, int32_t* y,
44 WINPR_ASSERT(context);
47 WINPR_ASSERT(*x >= 0);
48 WINPR_ASSERT(*y >= 0);
52 rc = wlf_scale_coordinates(context, &ux, &uy, fromLocalToRDP);
53 WINPR_ASSERT(ux < INT32_MAX);
54 WINPR_ASSERT(uy < INT32_MAX);
60 BOOL wlf_handle_pointer_enter(freerdp* instance,
const UwacPointerEnterLeaveEvent* ev)
64 rdpClientContext* cctx = NULL;
72 if (!wlf_scale_coordinates(instance->context, &x, &y, TRUE))
75 WINPR_ASSERT(x <= UINT16_MAX);
76 WINPR_ASSERT(y <= UINT16_MAX);
77 cctx = (rdpClientContext*)instance->context;
78 return freerdp_client_send_button_event(cctx, FALSE, PTR_FLAGS_MOVE, x, y);
81 BOOL wlf_handle_pointer_motion(freerdp* instance,
const UwacPointerMotionEvent* ev)
85 rdpClientContext* cctx = NULL;
90 cctx = (rdpClientContext*)instance->context;
96 if (!wlf_scale_coordinates(instance->context, &x, &y, TRUE))
99 WINPR_ASSERT(x <= UINT16_MAX);
100 WINPR_ASSERT(y <= UINT16_MAX);
101 return freerdp_client_send_button_event(cctx, FALSE, PTR_FLAGS_MOVE, x, y);
104 BOOL wlf_handle_pointer_buttons(freerdp* instance,
const UwacPointerButtonEvent* ev)
106 rdpClientContext* cctx = NULL;
112 if (!instance || !ev)
115 cctx = (rdpClientContext*)instance->context;
121 if (!wlf_scale_coordinates(instance->context, &x, &y, TRUE))
124 if (ev->state == WL_POINTER_BUTTON_STATE_PRESSED)
126 flags |= PTR_FLAGS_DOWN;
127 xflags |= PTR_XFLAGS_DOWN;
133 flags |= PTR_FLAGS_BUTTON1;
137 flags |= PTR_FLAGS_BUTTON2;
141 flags |= PTR_FLAGS_BUTTON3;
145 xflags |= PTR_XFLAGS_BUTTON1;
149 xflags |= PTR_XFLAGS_BUTTON2;
156 WINPR_ASSERT(x <= UINT16_MAX);
157 WINPR_ASSERT(y <= UINT16_MAX);
159 if ((flags & ~PTR_FLAGS_DOWN) != 0)
160 return freerdp_client_send_button_event(cctx, FALSE, flags, x, y);
162 if ((xflags & ~PTR_XFLAGS_DOWN) != 0)
163 return freerdp_client_send_extended_button_event(cctx, FALSE, xflags, x, y);
168 BOOL wlf_handle_pointer_axis(freerdp* instance,
const UwacPointerAxisEvent* ev)
171 if (!instance || !instance->context || !ev)
175 return ArrayList_Append(context->events, ev);
178 BOOL wlf_handle_pointer_axis_discrete(freerdp* instance,
const UwacPointerAxisEvent* ev)
181 if (!instance || !instance->context || !ev)
185 return ArrayList_Append(context->events, ev);
188 static BOOL wlf_handle_wheel(freerdp* instance, uint32_t x, uint32_t y, uint32_t axis,
191 rdpClientContext* cctx = NULL;
193 int32_t direction = 0;
194 uint32_t avalue = (uint32_t)abs(value);
196 WINPR_ASSERT(instance);
198 cctx = (rdpClientContext*)instance->context;
201 if (!wlf_scale_coordinates(instance->context, &x, &y, TRUE))
207 case WL_POINTER_AXIS_VERTICAL_SCROLL:
208 flags |= PTR_FLAGS_WHEEL;
210 flags |= PTR_FLAGS_WHEEL_NEGATIVE;
213 case WL_POINTER_AXIS_HORIZONTAL_SCROLL:
214 flags |= PTR_FLAGS_HWHEEL;
216 flags |= PTR_FLAGS_WHEEL_NEGATIVE;
231 const UINT16 cval = (avalue > 0xFF) ? 0xFF : (UINT16)avalue;
232 UINT16 cflags = flags | cval;
234 if (flags & PTR_FLAGS_WHEEL_NEGATIVE)
235 cflags = (flags & 0xFF00) | (0x100 - cval);
236 if (!freerdp_client_send_wheel_event(cctx, cflags))
244 BOOL wlf_handle_pointer_frame(freerdp* instance,
const UwacPointerFrameEvent* ev)
249 enum wl_pointer_axis_source source = WL_POINTER_AXIS_SOURCE_CONTINUOUS;
251 if (!instance || !ev || !instance->context)
256 for (
size_t x = 0; x < ArrayList_Count(context->events); x++)
258 UwacEvent* cev = ArrayList_GetItem(context->events, x);
261 if (cev->type == UWAC_EVENT_POINTER_SOURCE)
264 source = cev->mouse_source.axis_source;
271 for (
size_t x = 0; x < ArrayList_Count(context->events); x++)
273 UwacEvent* cev = ArrayList_GetItem(context->events, x);
280 case WL_POINTER_AXIS_SOURCE_WHEEL:
281 #if defined(WL_POINTER_AXIS_SOURCE_WHEEL_TILT_SINCE_VERSION)
282 case WL_POINTER_AXIS_SOURCE_WHEEL_TILT:
284 if (cev->type == UWAC_EVENT_POINTER_AXIS_DISCRETE)
287 int32_t val = cev->mouse_axis.value * 0x78;
289 if (!wlf_handle_wheel(instance, cev->mouse_axis.x, cev->mouse_axis.y,
290 cev->mouse_axis.axis, val))
295 case WL_POINTER_AXIS_SOURCE_FINGER:
296 case WL_POINTER_AXIS_SOURCE_CONTINUOUS:
297 if (cev->type == UWAC_EVENT_POINTER_AXIS)
299 double dval = wl_fixed_to_double(cev->mouse_axis.value);
300 int32_t val = (int32_t)(dval * 0x78 / 10.0);
301 if (!wlf_handle_wheel(instance, cev->mouse_axis.x, cev->mouse_axis.y,
302 cev->mouse_axis.axis, val))
311 ArrayList_Clear(context->events);
315 BOOL wlf_handle_pointer_source(freerdp* instance,
const UwacPointerSourceEvent* ev)
318 if (!instance || !instance->context || !ev)
322 return ArrayList_Append(context->events, ev);
325 BOOL wlf_handle_key(freerdp* instance,
const UwacKeyEvent* ev)
327 rdpInput* input = NULL;
328 DWORD rdp_scancode = 0;
330 if (!instance || !ev)
333 WINPR_ASSERT(instance->context);
335 ev->raw_key == KEY_RIGHTCTRL)
336 wlf_handle_ungrab_key(instance, ev);
338 input = instance->context->input;
339 rdp_scancode = freerdp_keyboard_get_rdp_scancode_from_x11_keycode(ev->raw_key + 8);
341 if (rdp_scancode == RDP_SCANCODE_UNKNOWN)
344 return freerdp_input_send_keyboard_event_ex(input, ev->pressed, ev->repeated, rdp_scancode);
347 BOOL wlf_handle_ungrab_key(freerdp* instance,
const UwacKeyEvent* ev)
350 if (!instance || !instance->context || !ev)
355 return UwacSeatInhibitShortcuts(context->seat,
false) == UWAC_SUCCESS;
358 BOOL wlf_keyboard_enter(freerdp* instance,
const UwacKeyboardEnterLeaveEvent* ev)
360 if (!instance || !ev)
363 ((
wlfContext*)instance->context)->focusing = TRUE;
367 BOOL wlf_keyboard_modifiers(freerdp* instance,
const UwacKeyboardModifiersEvent* ev)
369 rdpInput* input = NULL;
370 UINT16 syncFlags = 0;
373 if (!instance || !ev)
379 input = instance->context->input;
384 if (ev->modifiers & UWAC_MOD_CAPS_MASK)
385 syncFlags |= KBD_SYNC_CAPS_LOCK;
386 if (ev->modifiers & UWAC_MOD_NUM_MASK)
387 syncFlags |= KBD_SYNC_NUM_LOCK;
392 ((
wlfContext*)instance->context)->focusing = FALSE;
394 return freerdp_input_send_focus_in_event(input, syncFlags) &&
395 freerdp_client_send_button_event(&wlf->common, FALSE, PTR_FLAGS_MOVE, 0, 0);
398 BOOL wlf_handle_touch_up(freerdp* instance,
const UwacTouchUp* ev)
403 WINPR_ASSERT(instance);
412 if (!scale_signed_coordinates(instance->context, &x, &y, TRUE))
415 return freerdp_client_handle_touch(&wlf->common, FREERDP_TOUCH_UP, ev->id, 0, x, y);
418 BOOL wlf_handle_touch_down(freerdp* instance,
const UwacTouchDown* ev)
423 WINPR_ASSERT(instance);
432 if (!scale_signed_coordinates(instance->context, &x, &y, TRUE))
435 return freerdp_client_handle_touch(&wlf->common, FREERDP_TOUCH_DOWN, ev->id, 0, x, y);
438 BOOL wlf_handle_touch_motion(freerdp* instance,
const UwacTouchMotion* ev)
443 WINPR_ASSERT(instance);
452 if (!scale_signed_coordinates(instance->context, &x, &y, TRUE))
455 return freerdp_client_handle_touch(&wlf->common, FREERDP_TOUCH_MOTION, 0, ev->id, x, y);
FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.