20 #include <freerdp/config.h>
22 #include "sdl_touch.hpp"
23 #include "sdl_freerdp.hpp"
25 #include <winpr/wtypes.h>
26 #include <winpr/assert.h>
28 #include <freerdp/freerdp.h>
29 #include <freerdp/gdi/gdi.h>
33 BOOL sdl_scale_coordinates(
SdlContext* sdl, Uint32 windowId, INT32* px, INT32* py,
34 BOOL fromLocalToRDP, BOOL applyOffset)
36 rdpGdi* gdi =
nullptr;
40 if (!sdl || !px || !py || !sdl->context()->gdi)
43 WINPR_ASSERT(sdl->context()->gdi);
44 WINPR_ASSERT(sdl->context()->settings);
46 gdi = sdl->context()->gdi;
55 for (
const auto& it : sdl->windows)
57 auto& window = it.second;
58 const auto id = window.id();
64 auto size = window.rect();
66 sx = size.w /
static_cast<double>(gdi->width);
67 sy = size.h /
static_cast<double>(gdi->height);
68 offset_x = window.offsetX();
69 offset_y = window.offsetY();
77 *px =
static_cast<INT32
>(*px * sx);
78 *py =
static_cast<INT32
>(*py * sy);
82 *px =
static_cast<INT32
>(*px / sx);
83 *py =
static_cast<INT32
>(*py / sy);
95 static BOOL sdl_get_touch_scaled(
SdlContext* sdl,
const SDL_TouchFingerEvent* ev, INT32* px,
96 INT32* py, BOOL local)
105 SDL_Window* window = SDL_GetWindowFromID(ev->windowID);
110 windowID = SDL_GetWindowID(window);
111 SDL_Surface* surface = SDL_GetWindowSurface(window);
116 *px =
static_cast<INT32
>(ev->x *
static_cast<float>(surface->w));
117 *py =
static_cast<INT32
>(ev->y *
static_cast<float>(surface->h));
118 return sdl_scale_coordinates(sdl, windowID, px, py, local, TRUE);
121 static BOOL send_mouse_wheel(
SdlContext* sdl, UINT16 flags, INT32 avalue)
126 flags |= PTR_FLAGS_WHEEL_NEGATIVE;
132 const UINT16 cval = (avalue > 0xFF) ? 0xFF :
static_cast<UINT16
>(avalue);
133 UINT16 cflags = flags | cval;
135 if (flags & PTR_FLAGS_WHEEL_NEGATIVE)
136 cflags = (flags & 0xFF00) | (0x100 - cval);
137 if (!freerdp_client_send_wheel_event(sdl->common(), cflags))
145 static UINT32 sdl_scale_pressure(
const float pressure)
147 const float val = pressure * 0x400;
152 return static_cast<UINT32
>(val);
155 BOOL sdl_handle_touch_up(
SdlContext* sdl,
const SDL_TouchFingerEvent* ev)
162 if (!sdl_get_touch_scaled(sdl, ev, &x, &y, TRUE))
164 return freerdp_client_handle_touch(sdl->common(), FREERDP_TOUCH_UP | FREERDP_TOUCH_HAS_PRESSURE,
165 static_cast<INT32
>(ev->fingerID),
166 sdl_scale_pressure(ev->pressure), x, y);
169 BOOL sdl_handle_touch_down(
SdlContext* sdl,
const SDL_TouchFingerEvent* ev)
176 if (!sdl_get_touch_scaled(sdl, ev, &x, &y, TRUE))
178 return freerdp_client_handle_touch(
179 sdl->common(), FREERDP_TOUCH_DOWN | FREERDP_TOUCH_HAS_PRESSURE,
180 static_cast<INT32
>(ev->fingerID), sdl_scale_pressure(ev->pressure), x, y);
183 BOOL sdl_handle_touch_motion(
SdlContext* sdl,
const SDL_TouchFingerEvent* ev)
190 if (!sdl_get_touch_scaled(sdl, ev, &x, &y, TRUE))
192 return freerdp_client_handle_touch(
193 sdl->common(), FREERDP_TOUCH_MOTION | FREERDP_TOUCH_HAS_PRESSURE,
194 static_cast<INT32
>(ev->fingerID), sdl_scale_pressure(ev->pressure), x, y);
197 BOOL sdl_handle_mouse_motion(
SdlContext* sdl,
const SDL_MouseMotionEvent* ev)
202 sdl->input.mouse_focus(ev->windowID);
203 const BOOL relative = freerdp_client_use_relative_mouse_events(sdl->common());
204 auto x =
static_cast<INT32
>(relative ? ev->xrel : ev->x);
205 auto y =
static_cast<INT32
>(relative ? ev->yrel : ev->y);
206 sdl_scale_coordinates(sdl, ev->windowID, &x, &y, TRUE, TRUE);
207 return freerdp_client_send_button_event(sdl->common(), relative, PTR_FLAGS_MOVE, x, y);
210 BOOL sdl_handle_mouse_wheel(
SdlContext* sdl,
const SDL_MouseWheelEvent* ev)
215 const BOOL flipped = (ev->direction == SDL_MOUSEWHEEL_FLIPPED);
216 const auto x =
static_cast<INT32
>(ev->x * (flipped ? -1 : 1) * 0x78);
217 const auto y =
static_cast<INT32
>(ev->y * (flipped ? -1 : 1) * 0x78);
222 flags |= PTR_FLAGS_WHEEL;
223 send_mouse_wheel(sdl, flags, y);
228 flags |= PTR_FLAGS_HWHEEL;
229 send_mouse_wheel(sdl, flags, x);
234 BOOL sdl_handle_mouse_button(
SdlContext* sdl,
const SDL_MouseButtonEvent* ev)
242 if (ev->type == SDL_EVENT_MOUSE_BUTTON_DOWN)
244 flags |= PTR_FLAGS_DOWN;
245 xflags |= PTR_XFLAGS_DOWN;
251 flags |= PTR_FLAGS_BUTTON1;
254 flags |= PTR_FLAGS_BUTTON3;
257 flags |= PTR_FLAGS_BUTTON2;
260 xflags |= PTR_XFLAGS_BUTTON1;
263 xflags |= PTR_XFLAGS_BUTTON2;
269 const BOOL relative = freerdp_client_use_relative_mouse_events(sdl->common());
270 auto x =
static_cast<INT32
>(relative ? 0 : ev->x);
271 auto y =
static_cast<INT32
>(relative ? 0 : ev->y);
272 sdl_scale_coordinates(sdl, ev->windowID, &x, &y, TRUE, TRUE);
273 if ((flags & (~PTR_FLAGS_DOWN)) != 0)
274 return freerdp_client_send_button_event(sdl->common(), relative, flags, x, y);
275 else if ((xflags & (~PTR_XFLAGS_DOWN)) != 0)
276 return freerdp_client_send_extended_button_event(sdl->common(), relative, xflags, x, y);
FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.