2013-04-26 02:58:22 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* X11 Input
|
|
|
|
*
|
|
|
|
* Copyright 2013 Corey Clayton <can.of.tuna@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-02-16 13:20:38 +03:00
|
|
|
#include <freerdp/config.h>
|
2013-05-09 05:51:16 +04:00
|
|
|
|
2013-08-04 00:13:39 +04:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
|
|
|
|
#ifdef WITH_XCURSOR
|
|
|
|
#include <X11/Xcursor/Xcursor.h>
|
|
|
|
#endif
|
|
|
|
|
2013-05-09 05:51:16 +04:00
|
|
|
#ifdef WITH_XI
|
|
|
|
#include <X11/extensions/XInput2.h>
|
|
|
|
#endif
|
|
|
|
|
2013-04-26 06:04:35 +04:00
|
|
|
#include <math.h>
|
2021-09-01 10:44:11 +03:00
|
|
|
#include <float.h>
|
|
|
|
#include <limits.h>
|
2013-04-26 02:58:22 +04:00
|
|
|
|
2013-06-26 02:47:41 +04:00
|
|
|
#include "xf_event.h"
|
2013-04-26 02:58:22 +04:00
|
|
|
#include "xf_input.h"
|
|
|
|
|
2021-09-01 10:44:11 +03:00
|
|
|
#include <winpr/assert.h>
|
2023-08-25 12:26:08 +03:00
|
|
|
#include <winpr/wtypes.h>
|
2014-09-12 19:13:01 +04:00
|
|
|
#include <freerdp/log.h>
|
|
|
|
#define TAG CLIENT_TAG("x11")
|
|
|
|
|
2013-05-06 23:43:34 +04:00
|
|
|
#ifdef WITH_XI
|
|
|
|
|
2013-05-31 21:48:53 +04:00
|
|
|
#define PAN_THRESHOLD 50
|
|
|
|
#define ZOOM_THRESHOLD 10
|
|
|
|
|
2013-06-11 23:01:08 +04:00
|
|
|
#define MIN_FINGER_DIST 5
|
|
|
|
|
2022-01-21 19:18:18 +03:00
|
|
|
static int xf_input_event(xfContext* xfc, const XEvent* xevent, XIDeviceEvent* event, int evtype);
|
2022-01-19 15:29:26 +03:00
|
|
|
|
2021-06-17 10:21:20 +03:00
|
|
|
static const char* xf_input_get_class_string(int class)
|
2013-06-26 02:47:41 +04:00
|
|
|
{
|
|
|
|
if (class == XIKeyClass)
|
|
|
|
return "XIKeyClass";
|
|
|
|
else if (class == XIButtonClass)
|
|
|
|
return "XIButtonClass";
|
|
|
|
else if (class == XIValuatorClass)
|
|
|
|
return "XIValuatorClass";
|
|
|
|
else if (class == XIScrollClass)
|
|
|
|
return "XIScrollClass";
|
|
|
|
else if (class == XITouchClass)
|
|
|
|
return "XITouchClass";
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-06-26 02:47:41 +04:00
|
|
|
return "XIUnknownClass";
|
|
|
|
}
|
|
|
|
|
2022-01-22 15:29:28 +03:00
|
|
|
static BOOL register_input_events(xfContext* xfc, Window window)
|
|
|
|
{
|
2023-06-05 13:16:57 +03:00
|
|
|
int ndevices = 0;
|
2022-01-22 15:29:28 +03:00
|
|
|
int nmasks = 0;
|
|
|
|
XIEventMask evmasks[64] = { 0 };
|
|
|
|
BYTE masks[8][XIMaskLen(XI_LASTEVENT)] = { 0 };
|
|
|
|
|
|
|
|
WINPR_ASSERT(xfc);
|
|
|
|
|
2023-06-05 13:16:57 +03:00
|
|
|
rdpSettings* settings = xfc->common.context.settings;
|
2022-01-22 15:29:28 +03:00
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
2023-06-05 13:16:57 +03:00
|
|
|
XIDeviceInfo* info = XIQueryDevice(xfc->display, XIAllDevices, &ndevices);
|
2022-01-22 15:29:28 +03:00
|
|
|
|
2023-06-05 13:16:57 +03:00
|
|
|
for (int i = 0; i < MIN(ndevices, 64); i++)
|
2022-01-22 15:29:28 +03:00
|
|
|
{
|
|
|
|
BOOL used = FALSE;
|
|
|
|
XIDeviceInfo* dev = &info[i];
|
|
|
|
|
|
|
|
evmasks[nmasks].mask = masks[nmasks];
|
|
|
|
evmasks[nmasks].mask_len = sizeof(masks[0]);
|
|
|
|
evmasks[nmasks].deviceid = dev->deviceid;
|
|
|
|
|
|
|
|
/* Ignore virtual core pointer */
|
|
|
|
if (strcmp(dev->name, "Virtual core pointer") == 0)
|
|
|
|
continue;
|
|
|
|
|
2023-06-05 13:16:57 +03:00
|
|
|
for (int j = 0; j < dev->num_classes; j++)
|
2022-01-22 15:29:28 +03:00
|
|
|
{
|
|
|
|
const XIAnyClassInfo* class = dev->classes[j];
|
|
|
|
|
|
|
|
switch (class->type)
|
|
|
|
{
|
|
|
|
case XITouchClass:
|
|
|
|
if (settings->MultiTouchInput)
|
|
|
|
{
|
2022-04-27 22:02:18 +03:00
|
|
|
const XITouchClassInfo* t = (const XITouchClassInfo*)class;
|
2022-01-22 15:29:28 +03:00
|
|
|
if (t->mode == XIDirectTouch)
|
|
|
|
{
|
2022-03-03 12:48:15 +03:00
|
|
|
WLog_DBG(
|
2022-01-22 15:29:28 +03:00
|
|
|
TAG,
|
|
|
|
"%s %s touch device (id: %d, mode: %d), supporting %d touches.",
|
|
|
|
dev->name, (t->mode == XIDirectTouch) ? "direct" : "dependent",
|
|
|
|
dev->deviceid, t->mode, t->num_touches);
|
|
|
|
XISetMask(masks[nmasks], XI_TouchBegin);
|
|
|
|
XISetMask(masks[nmasks], XI_TouchUpdate);
|
|
|
|
XISetMask(masks[nmasks], XI_TouchEnd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XIButtonClass:
|
|
|
|
{
|
2022-04-27 22:02:18 +03:00
|
|
|
const XIButtonClassInfo* t = (const XIButtonClassInfo*)class;
|
2022-03-03 12:48:15 +03:00
|
|
|
WLog_DBG(TAG, "%s button device (id: %d, mode: %d)", dev->name, dev->deviceid,
|
|
|
|
t->num_buttons);
|
2022-01-22 15:29:28 +03:00
|
|
|
XISetMask(masks[nmasks], XI_ButtonPress);
|
|
|
|
XISetMask(masks[nmasks], XI_ButtonRelease);
|
|
|
|
XISetMask(masks[nmasks], XI_Motion);
|
|
|
|
used = TRUE;
|
2023-06-21 09:57:47 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case XIValuatorClass:
|
|
|
|
{
|
|
|
|
const XIValuatorClassInfo* t = (const XIValuatorClassInfo*)class;
|
|
|
|
char* name = t->label ? XGetAtomName(xfc->display, t->label) : NULL;
|
|
|
|
|
|
|
|
WLog_DBG(TAG, "%s device (id: %d) valuator %d label %s range %f - %f",
|
|
|
|
dev->name, dev->deviceid, t->number, name ? name : "None", t->min,
|
|
|
|
t->max);
|
2023-07-03 10:55:45 +03:00
|
|
|
free(name);
|
2023-06-21 09:57:47 +03:00
|
|
|
|
2023-06-21 21:08:12 +03:00
|
|
|
if (t->number == 2)
|
2023-06-21 09:57:47 +03:00
|
|
|
{
|
|
|
|
double max_pressure = t->max;
|
2023-06-22 11:29:22 +03:00
|
|
|
|
2023-09-13 11:03:30 +03:00
|
|
|
char devName[200];
|
|
|
|
strncpy(devName, dev->name, 200);
|
|
|
|
devName[200 - 1] = '\0';
|
|
|
|
CharLowerBuffA(devName, (DWORD)strlen(devName));
|
2023-09-10 09:23:22 +03:00
|
|
|
|
|
|
|
if (strstr(devName, "eraser") != NULL)
|
2023-06-21 09:57:47 +03:00
|
|
|
{
|
2023-09-10 09:23:22 +03:00
|
|
|
if (freerdp_client_handle_pen(&xfc->common,
|
|
|
|
FREERDP_PEN_REGISTER |
|
|
|
|
FREERDP_PEN_IS_INVERTED |
|
|
|
|
FREERDP_PEN_HAS_PRESSURE,
|
|
|
|
dev->deviceid, max_pressure))
|
|
|
|
WLog_DBG(TAG, "registered eraser");
|
2023-06-21 09:57:47 +03:00
|
|
|
}
|
2023-09-10 09:23:22 +03:00
|
|
|
else if (strstr(devName, "stylus") != NULL ||
|
|
|
|
strstr(devName, "pen") != NULL)
|
2023-06-21 09:57:47 +03:00
|
|
|
{
|
2023-09-10 09:23:22 +03:00
|
|
|
if (freerdp_client_handle_pen(
|
|
|
|
&xfc->common, FREERDP_PEN_REGISTER | FREERDP_PEN_HAS_PRESSURE,
|
|
|
|
dev->deviceid, max_pressure))
|
|
|
|
WLog_DBG(TAG, "registered pen");
|
2023-06-21 09:57:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2022-01-22 15:29:28 +03:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (used)
|
|
|
|
nmasks++;
|
|
|
|
}
|
|
|
|
|
|
|
|
XIFreeDeviceInfo(info);
|
|
|
|
|
|
|
|
if (nmasks > 0)
|
|
|
|
{
|
|
|
|
Status xstatus = XISelectEvents(xfc->display, window, evmasks, nmasks);
|
|
|
|
if (xstatus != 0)
|
|
|
|
WLog_WARN(TAG, "XISelectEvents returned %d", xstatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL register_raw_events(xfContext* xfc, Window window)
|
|
|
|
{
|
|
|
|
XIEventMask mask;
|
|
|
|
unsigned char mask_bytes[XIMaskLen(XI_LASTEVENT)] = { 0 };
|
|
|
|
rdpSettings* settings;
|
|
|
|
|
|
|
|
WINPR_ASSERT(xfc);
|
|
|
|
|
|
|
|
settings = xfc->common.context.settings;
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
|
|
|
if (freerdp_settings_get_bool(settings, FreeRDP_MouseUseRelativeMove))
|
|
|
|
{
|
|
|
|
XISetMask(mask_bytes, XI_RawMotion);
|
|
|
|
XISetMask(mask_bytes, XI_RawButtonPress);
|
|
|
|
XISetMask(mask_bytes, XI_RawButtonRelease);
|
|
|
|
|
|
|
|
mask.deviceid = XIAllMasterDevices;
|
|
|
|
mask.mask_len = sizeof(mask_bytes);
|
|
|
|
mask.mask = mask_bytes;
|
|
|
|
|
|
|
|
XISelectEvents(xfc->display, window, &mask, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-06-23 05:42:14 +03:00
|
|
|
static BOOL register_device_events(xfContext* xfc, Window window)
|
|
|
|
{
|
|
|
|
XIEventMask mask;
|
|
|
|
unsigned char mask_bytes[XIMaskLen(XI_LASTEVENT)] = { 0 };
|
|
|
|
rdpSettings* settings;
|
|
|
|
|
|
|
|
WINPR_ASSERT(xfc);
|
|
|
|
|
|
|
|
settings = xfc->common.context.settings;
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
|
|
|
XISetMask(mask_bytes, XI_DeviceChanged);
|
|
|
|
XISetMask(mask_bytes, XI_HierarchyChanged);
|
|
|
|
|
|
|
|
mask.deviceid = XIAllDevices;
|
|
|
|
mask.mask_len = sizeof(mask_bytes);
|
|
|
|
mask.mask = mask_bytes;
|
|
|
|
|
|
|
|
XISelectEvents(xfc->display, window, &mask, 1);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
int xf_input_init(xfContext* xfc, Window window)
|
2013-05-09 05:51:16 +04:00
|
|
|
{
|
2022-01-19 15:29:26 +03:00
|
|
|
int major = XI_2_Major;
|
|
|
|
int minor = XI_2_Minor;
|
2023-06-05 13:16:57 +03:00
|
|
|
int opcode = 0, event = 0, error = 0;
|
2021-09-01 10:44:11 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(xfc);
|
|
|
|
|
2023-06-05 13:16:57 +03:00
|
|
|
rdpSettings* settings = xfc->common.context.settings;
|
2022-01-19 11:27:39 +03:00
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
2021-09-01 10:44:11 +03:00
|
|
|
xfc->firstDist = -1.0;
|
|
|
|
xfc->z_vector = 0;
|
|
|
|
xfc->px_vector = 0;
|
|
|
|
xfc->py_vector = 0;
|
|
|
|
xfc->active_contacts = 0;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (!XQueryExtension(xfc->display, "XInputExtension", &opcode, &event, &error))
|
2013-05-09 05:51:16 +04:00
|
|
|
{
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_WARN(TAG, "XInput extension not available.");
|
2013-05-09 05:51:16 +04:00
|
|
|
return -1;
|
|
|
|
}
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->XInputOpcode = opcode;
|
|
|
|
XIQueryVersion(xfc->display, &major, &minor);
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2022-01-19 15:29:26 +03:00
|
|
|
if ((major < XI_2_Major) || ((major == XI_2_Major) && (minor < 2)))
|
2013-05-09 05:51:16 +04:00
|
|
|
{
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_WARN(TAG, "Server does not support XI 2.2");
|
2013-05-09 05:51:16 +04:00
|
|
|
return -1;
|
|
|
|
}
|
2022-01-19 15:29:26 +03:00
|
|
|
else
|
2013-05-09 05:51:16 +04:00
|
|
|
{
|
2022-01-22 15:29:28 +03:00
|
|
|
int scr = DefaultScreen(xfc->display);
|
|
|
|
Window root = RootWindow(xfc->display, scr);
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2022-01-22 15:29:28 +03:00
|
|
|
if (!register_raw_events(xfc, root))
|
|
|
|
return -1;
|
|
|
|
if (!register_input_events(xfc, window))
|
|
|
|
return -1;
|
2023-06-23 05:42:14 +03:00
|
|
|
if (!register_device_events(xfc, window))
|
|
|
|
return -1;
|
2021-06-30 11:19:16 +03:00
|
|
|
}
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-05-15 19:39:28 +04:00
|
|
|
return 0;
|
2013-05-09 05:51:16 +04:00
|
|
|
}
|
2013-05-08 05:42:49 +04:00
|
|
|
|
2021-09-01 10:44:11 +03:00
|
|
|
static BOOL xf_input_is_duplicate(xfContext* xfc, const XGenericEventCookie* cookie)
|
2013-04-27 00:40:27 +04:00
|
|
|
{
|
2020-02-27 10:50:04 +03:00
|
|
|
const XIDeviceEvent* event;
|
2021-09-01 10:44:11 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(xfc);
|
|
|
|
WINPR_ASSERT(cookie);
|
|
|
|
|
2013-07-23 22:47:40 +04:00
|
|
|
event = cookie->data;
|
2021-09-01 10:44:11 +03:00
|
|
|
WINPR_ASSERT(event);
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2021-09-01 10:44:11 +03:00
|
|
|
if ((xfc->lastEvent.time == event->time) && (xfc->lastEvType == cookie->evtype) &&
|
|
|
|
(xfc->lastEvent.detail == event->detail) &&
|
|
|
|
(fabs(xfc->lastEvent.event_x - event->event_x) < DBL_EPSILON) &&
|
|
|
|
(fabs(xfc->lastEvent.event_y - event->event_y) < DBL_EPSILON))
|
2013-04-27 00:40:27 +04:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-04-27 00:40:27 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-09-01 10:44:11 +03:00
|
|
|
static void xf_input_save_last_event(xfContext* xfc, const XGenericEventCookie* cookie)
|
2013-04-27 00:40:27 +04:00
|
|
|
{
|
2020-02-27 10:50:04 +03:00
|
|
|
const XIDeviceEvent* event;
|
2021-09-01 10:44:11 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(xfc);
|
|
|
|
WINPR_ASSERT(cookie);
|
|
|
|
|
2013-07-23 22:47:40 +04:00
|
|
|
event = cookie->data;
|
2021-09-01 10:44:11 +03:00
|
|
|
WINPR_ASSERT(event);
|
|
|
|
|
|
|
|
xfc->lastEvType = cookie->evtype;
|
|
|
|
xfc->lastEvent.time = event->time;
|
|
|
|
xfc->lastEvent.detail = event->detail;
|
|
|
|
xfc->lastEvent.event_x = event->event_x;
|
|
|
|
xfc->lastEvent.event_y = event->event_y;
|
2013-04-27 00:40:27 +04:00
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static void xf_input_detect_pan(xfContext* xfc)
|
2013-05-30 22:36:13 +04:00
|
|
|
{
|
2013-07-23 22:47:40 +04:00
|
|
|
double dx[2];
|
|
|
|
double dy[2];
|
|
|
|
double px;
|
|
|
|
double py;
|
|
|
|
double dist_x;
|
|
|
|
double dist_y;
|
2021-09-01 10:44:11 +03:00
|
|
|
rdpContext* ctx;
|
|
|
|
|
|
|
|
WINPR_ASSERT(xfc);
|
2022-01-19 11:27:39 +03:00
|
|
|
ctx = &xfc->common.context;
|
2021-09-01 10:44:11 +03:00
|
|
|
WINPR_ASSERT(ctx);
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2021-09-01 10:44:11 +03:00
|
|
|
if (xfc->active_contacts != 2)
|
2013-06-01 01:07:51 +04:00
|
|
|
{
|
2013-07-23 22:47:40 +04:00
|
|
|
return;
|
2013-06-01 01:07:51 +04:00
|
|
|
}
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2021-09-01 10:44:11 +03:00
|
|
|
dx[0] = xfc->contacts[0].pos_x - xfc->contacts[0].last_x;
|
|
|
|
dx[1] = xfc->contacts[1].pos_x - xfc->contacts[1].last_x;
|
|
|
|
dy[0] = xfc->contacts[0].pos_y - xfc->contacts[0].last_y;
|
|
|
|
dy[1] = xfc->contacts[1].pos_y - xfc->contacts[1].last_y;
|
2013-07-23 22:47:40 +04:00
|
|
|
px = fabs(dx[0]) < fabs(dx[1]) ? dx[0] : dx[1];
|
|
|
|
py = fabs(dy[0]) < fabs(dy[1]) ? dy[0] : dy[1];
|
2021-09-01 10:44:11 +03:00
|
|
|
xfc->px_vector += px;
|
|
|
|
xfc->py_vector += py;
|
|
|
|
dist_x = fabs(xfc->contacts[0].pos_x - xfc->contacts[1].pos_x);
|
|
|
|
dist_y = fabs(xfc->contacts[0].pos_y - xfc->contacts[1].pos_y);
|
2014-03-14 05:10:22 +04:00
|
|
|
|
|
|
|
if (dist_y > MIN_FINGER_DIST)
|
2013-06-01 01:07:51 +04:00
|
|
|
{
|
2021-09-01 10:44:11 +03:00
|
|
|
if (xfc->px_vector > PAN_THRESHOLD)
|
2013-07-23 22:47:40 +04:00
|
|
|
{
|
|
|
|
{
|
|
|
|
PanningChangeEventArgs e;
|
|
|
|
EventArgsInit(&e, "xfreerdp");
|
2014-12-01 13:56:44 +03:00
|
|
|
e.dx = 5;
|
|
|
|
e.dy = 0;
|
2018-02-14 12:14:33 +03:00
|
|
|
PubSub_OnPanningChange(ctx->pubSub, xfc, &e);
|
2013-07-23 22:47:40 +04:00
|
|
|
}
|
2021-09-01 10:44:11 +03:00
|
|
|
xfc->px_vector = 0;
|
|
|
|
xfc->py_vector = 0;
|
|
|
|
xfc->z_vector = 0;
|
2013-07-23 22:47:40 +04:00
|
|
|
}
|
2021-09-01 10:44:11 +03:00
|
|
|
else if (xfc->px_vector < -PAN_THRESHOLD)
|
2013-07-23 22:47:40 +04:00
|
|
|
{
|
|
|
|
{
|
|
|
|
PanningChangeEventArgs e;
|
|
|
|
EventArgsInit(&e, "xfreerdp");
|
2014-12-01 13:56:44 +03:00
|
|
|
e.dx = -5;
|
|
|
|
e.dy = 0;
|
2018-02-14 12:14:33 +03:00
|
|
|
PubSub_OnPanningChange(ctx->pubSub, xfc, &e);
|
2013-07-23 22:47:40 +04:00
|
|
|
}
|
2021-09-01 10:44:11 +03:00
|
|
|
xfc->px_vector = 0;
|
|
|
|
xfc->py_vector = 0;
|
|
|
|
xfc->z_vector = 0;
|
2013-07-23 22:47:40 +04:00
|
|
|
}
|
2013-06-01 01:07:51 +04:00
|
|
|
}
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2014-03-14 05:10:22 +04:00
|
|
|
if (dist_x > MIN_FINGER_DIST)
|
2013-06-01 01:07:51 +04:00
|
|
|
{
|
2021-09-01 10:44:11 +03:00
|
|
|
if (xfc->py_vector > PAN_THRESHOLD)
|
2013-07-23 22:47:40 +04:00
|
|
|
{
|
|
|
|
{
|
|
|
|
PanningChangeEventArgs e;
|
|
|
|
EventArgsInit(&e, "xfreerdp");
|
2014-12-01 13:56:44 +03:00
|
|
|
e.dx = 0;
|
|
|
|
e.dy = 5;
|
2018-02-14 12:14:33 +03:00
|
|
|
PubSub_OnPanningChange(ctx->pubSub, xfc, &e);
|
2013-07-23 22:47:40 +04:00
|
|
|
}
|
2021-09-01 10:44:11 +03:00
|
|
|
xfc->py_vector = 0;
|
|
|
|
xfc->px_vector = 0;
|
|
|
|
xfc->z_vector = 0;
|
2013-07-23 22:47:40 +04:00
|
|
|
}
|
2021-09-01 10:44:11 +03:00
|
|
|
else if (xfc->py_vector < -PAN_THRESHOLD)
|
2013-07-23 22:47:40 +04:00
|
|
|
{
|
|
|
|
{
|
|
|
|
PanningChangeEventArgs e;
|
|
|
|
EventArgsInit(&e, "xfreerdp");
|
2014-12-01 13:56:44 +03:00
|
|
|
e.dx = 0;
|
|
|
|
e.dy = -5;
|
2018-02-14 12:14:33 +03:00
|
|
|
PubSub_OnPanningChange(ctx->pubSub, xfc, &e);
|
2013-07-23 22:47:40 +04:00
|
|
|
}
|
2021-09-01 10:44:11 +03:00
|
|
|
xfc->py_vector = 0;
|
|
|
|
xfc->px_vector = 0;
|
|
|
|
xfc->z_vector = 0;
|
2013-07-23 22:47:40 +04:00
|
|
|
}
|
2013-06-01 01:07:51 +04:00
|
|
|
}
|
2013-05-30 22:36:13 +04:00
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static void xf_input_detect_pinch(xfContext* xfc)
|
2013-04-27 01:42:23 +04:00
|
|
|
{
|
|
|
|
double dist;
|
2013-05-09 05:51:16 +04:00
|
|
|
double delta;
|
2014-12-01 13:56:44 +03:00
|
|
|
ZoomingChangeEventArgs e;
|
2021-09-01 10:44:11 +03:00
|
|
|
rdpContext* ctx;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2021-09-01 10:44:11 +03:00
|
|
|
WINPR_ASSERT(xfc);
|
2022-01-19 11:27:39 +03:00
|
|
|
ctx = &xfc->common.context;
|
2021-09-01 10:44:11 +03:00
|
|
|
WINPR_ASSERT(ctx);
|
|
|
|
|
|
|
|
if (xfc->active_contacts != 2)
|
2013-04-27 01:42:23 +04:00
|
|
|
{
|
2021-09-01 10:44:11 +03:00
|
|
|
xfc->firstDist = -1.0;
|
2013-04-27 01:42:23 +04:00
|
|
|
return;
|
|
|
|
}
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-05-09 05:51:16 +04:00
|
|
|
/* first calculate the distance */
|
2021-09-01 10:44:11 +03:00
|
|
|
dist = sqrt(pow(xfc->contacts[1].pos_x - xfc->contacts[0].last_x, 2.0) +
|
|
|
|
pow(xfc->contacts[1].pos_y - xfc->contacts[0].last_y, 2.0));
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-05-09 05:51:16 +04:00
|
|
|
/* if this is the first 2pt touch */
|
2021-09-01 10:44:11 +03:00
|
|
|
if (xfc->firstDist <= 0)
|
2013-04-27 01:42:23 +04:00
|
|
|
{
|
2021-09-01 10:44:11 +03:00
|
|
|
xfc->firstDist = dist;
|
|
|
|
xfc->lastDist = xfc->firstDist;
|
|
|
|
xfc->z_vector = 0;
|
|
|
|
xfc->px_vector = 0;
|
|
|
|
xfc->py_vector = 0;
|
2013-04-27 01:42:23 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-09-01 10:44:11 +03:00
|
|
|
delta = xfc->lastDist - dist;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2016-08-03 15:16:20 +03:00
|
|
|
if (delta > 1.0)
|
2013-07-23 22:47:40 +04:00
|
|
|
delta = 1.0;
|
2016-08-03 15:16:20 +03:00
|
|
|
|
|
|
|
if (delta < -1.0)
|
2013-07-23 22:47:40 +04:00
|
|
|
delta = -1.0;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-05-09 05:51:16 +04:00
|
|
|
/* compare the current distance to the first one */
|
2021-09-01 10:44:11 +03:00
|
|
|
xfc->z_vector += delta;
|
|
|
|
xfc->lastDist = dist;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2021-09-01 10:44:11 +03:00
|
|
|
if (xfc->z_vector > ZOOM_THRESHOLD)
|
2013-04-26 02:58:22 +04:00
|
|
|
{
|
2013-06-18 08:39:48 +04:00
|
|
|
EventArgsInit(&e, "xfreerdp");
|
2014-12-01 13:56:44 +03:00
|
|
|
e.dx = e.dy = -10;
|
2018-02-14 12:14:33 +03:00
|
|
|
PubSub_OnZoomingChange(ctx->pubSub, xfc, &e);
|
2021-09-01 10:44:11 +03:00
|
|
|
xfc->z_vector = 0;
|
|
|
|
xfc->px_vector = 0;
|
|
|
|
xfc->py_vector = 0;
|
2013-05-09 05:51:16 +04:00
|
|
|
}
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2021-09-01 10:44:11 +03:00
|
|
|
if (xfc->z_vector < -ZOOM_THRESHOLD)
|
2013-05-09 05:51:16 +04:00
|
|
|
{
|
2013-06-18 08:39:48 +04:00
|
|
|
EventArgsInit(&e, "xfreerdp");
|
2014-12-01 13:56:44 +03:00
|
|
|
e.dx = e.dy = 10;
|
2018-02-14 12:14:33 +03:00
|
|
|
PubSub_OnZoomingChange(ctx->pubSub, xfc, &e);
|
2021-09-01 10:44:11 +03:00
|
|
|
xfc->z_vector = 0;
|
|
|
|
xfc->px_vector = 0;
|
|
|
|
xfc->py_vector = 0;
|
2013-05-09 05:51:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-26 02:58:22 +04:00
|
|
|
|
2021-09-01 10:44:11 +03:00
|
|
|
static void xf_input_touch_begin(xfContext* xfc, const XIDeviceEvent* event)
|
2013-05-09 05:51:16 +04:00
|
|
|
{
|
|
|
|
int i;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2019-02-07 19:53:21 +03:00
|
|
|
WINPR_UNUSED(xfc);
|
2013-05-09 05:51:16 +04:00
|
|
|
for (i = 0; i < MAX_CONTACTS; i++)
|
|
|
|
{
|
2021-09-01 10:44:11 +03:00
|
|
|
if (xfc->contacts[i].id == 0)
|
2013-04-26 02:58:22 +04:00
|
|
|
{
|
2021-09-01 10:44:11 +03:00
|
|
|
xfc->contacts[i].id = event->detail;
|
|
|
|
xfc->contacts[i].count = 1;
|
|
|
|
xfc->contacts[i].pos_x = event->event_x;
|
|
|
|
xfc->contacts[i].pos_y = event->event_y;
|
|
|
|
xfc->active_contacts++;
|
2013-05-09 05:51:16 +04:00
|
|
|
break;
|
2013-04-26 02:58:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-26 03:38:13 +04:00
|
|
|
|
2021-09-01 10:44:11 +03:00
|
|
|
static void xf_input_touch_update(xfContext* xfc, const XIDeviceEvent* event)
|
2013-04-26 03:38:13 +04:00
|
|
|
{
|
2013-05-09 05:51:16 +04:00
|
|
|
int i;
|
2014-03-14 05:10:22 +04:00
|
|
|
|
2021-09-01 10:44:11 +03:00
|
|
|
WINPR_ASSERT(xfc);
|
|
|
|
WINPR_ASSERT(event);
|
|
|
|
|
2013-05-09 05:51:16 +04:00
|
|
|
for (i = 0; i < MAX_CONTACTS; i++)
|
|
|
|
{
|
2021-09-01 10:44:11 +03:00
|
|
|
if (xfc->contacts[i].id == event->detail)
|
2013-04-26 03:38:13 +04:00
|
|
|
{
|
2021-09-01 10:44:11 +03:00
|
|
|
xfc->contacts[i].count++;
|
|
|
|
xfc->contacts[i].last_x = xfc->contacts[i].pos_x;
|
|
|
|
xfc->contacts[i].last_y = xfc->contacts[i].pos_y;
|
|
|
|
xfc->contacts[i].pos_x = event->event_x;
|
|
|
|
xfc->contacts[i].pos_y = event->event_y;
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_input_detect_pinch(xfc);
|
2013-06-26 04:41:32 +04:00
|
|
|
xf_input_detect_pan(xfc);
|
2013-05-09 05:51:16 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-26 03:38:13 +04:00
|
|
|
|
2021-09-01 10:44:11 +03:00
|
|
|
static void xf_input_touch_end(xfContext* xfc, const XIDeviceEvent* event)
|
2013-05-09 05:51:16 +04:00
|
|
|
{
|
|
|
|
int i;
|
2014-03-14 05:10:22 +04:00
|
|
|
|
2019-02-07 19:53:21 +03:00
|
|
|
WINPR_UNUSED(xfc);
|
2013-05-09 05:51:16 +04:00
|
|
|
for (i = 0; i < MAX_CONTACTS; i++)
|
|
|
|
{
|
2021-09-01 10:44:11 +03:00
|
|
|
if (xfc->contacts[i].id == event->detail)
|
2013-05-09 05:51:16 +04:00
|
|
|
{
|
2021-09-01 10:44:11 +03:00
|
|
|
xfc->contacts[i].id = 0;
|
|
|
|
xfc->contacts[i].count = 0;
|
|
|
|
xfc->active_contacts--;
|
2014-09-12 19:13:01 +04:00
|
|
|
break;
|
2013-04-26 03:38:13 +04:00
|
|
|
}
|
2013-05-09 05:51:16 +04:00
|
|
|
}
|
2013-04-26 03:38:13 +04:00
|
|
|
}
|
2013-04-26 06:04:35 +04:00
|
|
|
|
2020-02-27 10:50:04 +03:00
|
|
|
static int xf_input_handle_event_local(xfContext* xfc, const XEvent* event)
|
2013-04-26 06:04:35 +04:00
|
|
|
{
|
2022-06-23 08:57:38 +03:00
|
|
|
union
|
|
|
|
{
|
2020-02-27 10:50:04 +03:00
|
|
|
const XGenericEventCookie* cc;
|
|
|
|
XGenericEventCookie* vc;
|
|
|
|
} cookie;
|
|
|
|
cookie.cc = &event->xcookie;
|
|
|
|
XGetEventData(xfc->display, cookie.vc);
|
|
|
|
|
|
|
|
if ((cookie.cc->type == GenericEvent) && (cookie.cc->extension == xfc->XInputOpcode))
|
2013-04-26 06:04:35 +04:00
|
|
|
{
|
2020-02-27 10:50:04 +03:00
|
|
|
switch (cookie.cc->evtype)
|
2013-04-26 06:04:35 +04:00
|
|
|
{
|
2013-05-09 08:52:37 +04:00
|
|
|
case XI_TouchBegin:
|
2021-09-01 10:44:11 +03:00
|
|
|
if (xf_input_is_duplicate(xfc, cookie.cc) == FALSE)
|
2020-02-27 10:50:04 +03:00
|
|
|
xf_input_touch_begin(xfc, cookie.cc->data);
|
2016-08-03 15:16:20 +03:00
|
|
|
|
2021-09-01 10:44:11 +03:00
|
|
|
xf_input_save_last_event(xfc, cookie.cc);
|
2013-05-09 08:52:37 +04:00
|
|
|
break;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-05-09 08:52:37 +04:00
|
|
|
case XI_TouchUpdate:
|
2021-09-01 10:44:11 +03:00
|
|
|
if (xf_input_is_duplicate(xfc, cookie.cc) == FALSE)
|
2020-02-27 10:50:04 +03:00
|
|
|
xf_input_touch_update(xfc, cookie.cc->data);
|
2016-08-03 15:16:20 +03:00
|
|
|
|
2021-09-01 10:44:11 +03:00
|
|
|
xf_input_save_last_event(xfc, cookie.cc);
|
2013-05-09 08:52:37 +04:00
|
|
|
break;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-05-09 08:52:37 +04:00
|
|
|
case XI_TouchEnd:
|
2021-09-01 10:44:11 +03:00
|
|
|
if (xf_input_is_duplicate(xfc, cookie.cc) == FALSE)
|
2020-02-27 10:50:04 +03:00
|
|
|
xf_input_touch_end(xfc, cookie.cc->data);
|
2016-08-03 15:16:20 +03:00
|
|
|
|
2021-09-01 10:44:11 +03:00
|
|
|
xf_input_save_last_event(xfc, cookie.cc);
|
2013-05-09 08:52:37 +04:00
|
|
|
break;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-05-09 08:52:37 +04:00
|
|
|
default:
|
2022-01-21 19:18:18 +03:00
|
|
|
xf_input_event(xfc, event, cookie.cc->data, cookie.cc->evtype);
|
2013-05-09 08:52:37 +04:00
|
|
|
break;
|
2013-04-26 06:04:35 +04:00
|
|
|
}
|
|
|
|
}
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2020-02-27 10:50:04 +03:00
|
|
|
XFreeEventData(xfc->display, cookie.vc);
|
2013-05-09 08:52:37 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2013-04-26 06:04:35 +04:00
|
|
|
|
2017-05-12 12:11:41 +03:00
|
|
|
#ifdef WITH_DEBUG_X11
|
2017-02-20 20:31:58 +03:00
|
|
|
static char* xf_input_touch_state_string(DWORD flags)
|
2013-05-09 08:52:37 +04:00
|
|
|
{
|
2020-12-27 18:12:18 +03:00
|
|
|
if (flags & RDPINPUT_CONTACT_FLAG_DOWN)
|
|
|
|
return "RDPINPUT_CONTACT_FLAG_DOWN";
|
|
|
|
else if (flags & RDPINPUT_CONTACT_FLAG_UPDATE)
|
|
|
|
return "RDPINPUT_CONTACT_FLAG_UPDATE";
|
|
|
|
else if (flags & RDPINPUT_CONTACT_FLAG_UP)
|
|
|
|
return "RDPINPUT_CONTACT_FLAG_UP";
|
|
|
|
else if (flags & RDPINPUT_CONTACT_FLAG_INRANGE)
|
|
|
|
return "RDPINPUT_CONTACT_FLAG_INRANGE";
|
|
|
|
else if (flags & RDPINPUT_CONTACT_FLAG_INCONTACT)
|
|
|
|
return "RDPINPUT_CONTACT_FLAG_INCONTACT";
|
|
|
|
else if (flags & RDPINPUT_CONTACT_FLAG_CANCELED)
|
|
|
|
return "RDPINPUT_CONTACT_FLAG_CANCELED";
|
2013-05-14 03:17:25 +04:00
|
|
|
else
|
2020-12-27 18:12:18 +03:00
|
|
|
return "RDPINPUT_CONTACT_FLAG_UNKNOWN";
|
2013-05-09 08:52:37 +04:00
|
|
|
}
|
2017-05-12 12:11:41 +03:00
|
|
|
#endif
|
2013-04-26 23:27:08 +04:00
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static void xf_input_hide_cursor(xfContext* xfc)
|
2013-08-04 00:13:39 +04:00
|
|
|
{
|
|
|
|
#ifdef WITH_XCURSOR
|
2016-08-03 15:16:20 +03:00
|
|
|
|
2013-08-04 00:13:39 +04:00
|
|
|
if (!xfc->cursorHidden)
|
|
|
|
{
|
2022-10-13 17:25:36 +03:00
|
|
|
XcursorImage ci = { 0 };
|
2013-08-04 00:13:39 +04:00
|
|
|
XcursorPixel xp = 0;
|
|
|
|
static Cursor nullcursor = None;
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_lock_x11(xfc);
|
2013-08-04 00:13:39 +04:00
|
|
|
ci.version = XCURSOR_IMAGE_VERSION;
|
|
|
|
ci.size = sizeof(ci);
|
|
|
|
ci.width = ci.height = 1;
|
|
|
|
ci.xhot = ci.yhot = 0;
|
|
|
|
ci.pixels = &xp;
|
|
|
|
nullcursor = XcursorImageLoadCursor(xfc->display, &ci);
|
|
|
|
|
|
|
|
if ((xfc->window) && (nullcursor != None))
|
|
|
|
XDefineCursor(xfc->display, xfc->window->handle, nullcursor);
|
|
|
|
|
|
|
|
xfc->cursorHidden = TRUE;
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_unlock_x11(xfc);
|
2013-08-04 00:13:39 +04:00
|
|
|
}
|
2016-08-03 15:16:20 +03:00
|
|
|
|
2013-08-04 00:13:39 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static void xf_input_show_cursor(xfContext* xfc)
|
2013-08-04 00:13:39 +04:00
|
|
|
{
|
|
|
|
#ifdef WITH_XCURSOR
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_lock_x11(xfc);
|
2013-08-04 00:13:39 +04:00
|
|
|
|
|
|
|
if (xfc->cursorHidden)
|
|
|
|
{
|
|
|
|
if (xfc->window)
|
|
|
|
{
|
|
|
|
if (!xfc->pointer)
|
|
|
|
XUndefineCursor(xfc->display, xfc->window->handle);
|
|
|
|
else
|
|
|
|
XDefineCursor(xfc->display, xfc->window->handle, xfc->pointer->cursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
xfc->cursorHidden = FALSE;
|
|
|
|
}
|
|
|
|
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_unlock_x11(xfc);
|
2013-08-04 00:13:39 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static int xf_input_touch_remote(xfContext* xfc, XIDeviceEvent* event, int evtype)
|
2013-05-09 08:52:37 +04:00
|
|
|
{
|
2013-05-14 03:17:25 +04:00
|
|
|
int x, y;
|
|
|
|
int touchId;
|
2022-01-19 13:05:55 +03:00
|
|
|
RdpeiClientContext* rdpei = xfc->common.rdpei;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-05-14 03:17:25 +04:00
|
|
|
if (!rdpei)
|
|
|
|
return 0;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-08-04 00:13:39 +04:00
|
|
|
xf_input_hide_cursor(xfc);
|
2013-05-14 03:17:25 +04:00
|
|
|
touchId = event->detail;
|
2019-11-06 17:24:51 +03:00
|
|
|
x = (int)event->event_x;
|
|
|
|
y = (int)event->event_y;
|
2014-12-01 13:56:44 +03:00
|
|
|
xf_event_adjust_coordinates(xfc, &x, &y);
|
|
|
|
|
2022-01-19 15:29:26 +03:00
|
|
|
switch (evtype)
|
2013-05-14 09:06:25 +04:00
|
|
|
{
|
2022-01-19 15:29:26 +03:00
|
|
|
case XI_TouchBegin:
|
2022-12-30 13:25:28 +03:00
|
|
|
freerdp_client_handle_touch(&xfc->common, FREERDP_TOUCH_DOWN, touchId, 0, x, y);
|
2022-01-19 15:29:26 +03:00
|
|
|
break;
|
|
|
|
case XI_TouchUpdate:
|
2022-12-30 13:25:28 +03:00
|
|
|
freerdp_client_handle_touch(&xfc->common, FREERDP_TOUCH_MOTION, touchId, 0, x, y);
|
2022-01-19 15:29:26 +03:00
|
|
|
break;
|
|
|
|
case XI_TouchEnd:
|
2022-12-30 13:25:28 +03:00
|
|
|
freerdp_client_handle_touch(&xfc->common, FREERDP_TOUCH_UP, touchId, 0, x, y);
|
2022-01-19 15:29:26 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2013-05-14 09:06:25 +04:00
|
|
|
}
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-05-09 08:52:37 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-09-11 09:05:35 +03:00
|
|
|
static BOOL xf_input_pen_remote(xfContext* xfc, XIDeviceEvent* event, int evtype, int deviceid)
|
2023-06-21 09:57:47 +03:00
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
RdpeiClientContext* rdpei = xfc->common.rdpei;
|
|
|
|
|
|
|
|
if (!rdpei)
|
2023-09-11 09:05:35 +03:00
|
|
|
return FALSE;
|
2023-06-21 09:57:47 +03:00
|
|
|
|
|
|
|
xf_input_hide_cursor(xfc);
|
|
|
|
x = (int)event->event_x;
|
|
|
|
y = (int)event->event_y;
|
|
|
|
xf_event_adjust_coordinates(xfc, &x, &y);
|
|
|
|
|
|
|
|
double pressure = 0.0;
|
|
|
|
double* val = event->valuators.values;
|
|
|
|
for (int i = 0; i < MIN(event->valuators.mask_len * 8, 3); i++)
|
|
|
|
{
|
|
|
|
if (XIMaskIsSet(event->valuators.mask, i))
|
|
|
|
{
|
|
|
|
double value = *val++;
|
|
|
|
if (i == 2)
|
|
|
|
pressure = value;
|
|
|
|
}
|
|
|
|
}
|
2023-06-22 11:29:22 +03:00
|
|
|
|
2023-09-11 09:05:35 +03:00
|
|
|
UINT32 flags = FREERDP_PEN_HAS_PRESSURE;
|
|
|
|
if ((evtype == XI_ButtonPress) || (evtype == XI_ButtonRelease))
|
|
|
|
{
|
|
|
|
WLog_DBG(TAG, "pen button %d", event->detail);
|
|
|
|
switch (event->detail)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
flags |= FREERDP_PEN_BARREL_PRESSED;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-21 09:57:47 +03:00
|
|
|
switch (evtype)
|
|
|
|
{
|
|
|
|
case XI_ButtonPress:
|
2023-09-11 09:05:35 +03:00
|
|
|
flags |= FREERDP_PEN_PRESS;
|
|
|
|
if (!freerdp_client_handle_pen(&xfc->common, flags, deviceid, x, y, pressure))
|
2023-06-22 11:29:22 +03:00
|
|
|
return FALSE;
|
2023-06-21 09:57:47 +03:00
|
|
|
break;
|
|
|
|
case XI_Motion:
|
2023-09-11 09:05:35 +03:00
|
|
|
flags |= FREERDP_PEN_MOTION;
|
|
|
|
if (!freerdp_client_handle_pen(&xfc->common, flags, deviceid, x, y, pressure))
|
2023-06-22 11:29:22 +03:00
|
|
|
return FALSE;
|
2023-06-21 09:57:47 +03:00
|
|
|
break;
|
|
|
|
case XI_ButtonRelease:
|
2023-09-11 09:05:35 +03:00
|
|
|
flags |= FREERDP_PEN_RELEASE;
|
|
|
|
if (!freerdp_client_handle_pen(&xfc->common, flags, deviceid, x, y, pressure))
|
2023-06-22 11:29:22 +03:00
|
|
|
return FALSE;
|
2023-06-21 09:57:47 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2023-09-11 09:05:35 +03:00
|
|
|
return TRUE;
|
2023-06-21 09:57:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int xf_input_pens_unhover(xfContext* xfc)
|
|
|
|
{
|
2023-06-22 11:29:22 +03:00
|
|
|
WINPR_ASSERT(xfc);
|
2023-06-21 09:57:47 +03:00
|
|
|
|
2023-06-22 11:29:22 +03:00
|
|
|
freerdp_client_pen_cancel_all(&xfc->common);
|
2023-06-21 21:08:12 +03:00
|
|
|
return 0;
|
2023-06-21 09:57:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-21 19:18:18 +03:00
|
|
|
int xf_input_event(xfContext* xfc, const XEvent* xevent, XIDeviceEvent* event, int evtype)
|
2013-06-18 05:54:38 +04:00
|
|
|
{
|
2022-01-22 15:29:28 +03:00
|
|
|
const rdpSettings* settings;
|
2022-01-21 19:18:18 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(xfc);
|
|
|
|
WINPR_ASSERT(xevent);
|
|
|
|
WINPR_ASSERT(event);
|
|
|
|
|
2022-01-22 15:29:28 +03:00
|
|
|
settings = xfc->common.context.settings;
|
|
|
|
WINPR_ASSERT(settings);
|
2022-01-21 19:18:18 +03:00
|
|
|
|
2022-10-03 14:34:59 +03:00
|
|
|
xfWindow* window = xfc->window;
|
|
|
|
if (window)
|
|
|
|
{
|
|
|
|
if (xf_floatbar_is_locked(window->floatbar))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-08-04 00:13:39 +04:00
|
|
|
xf_input_show_cursor(xfc);
|
|
|
|
|
2013-06-18 05:54:38 +04:00
|
|
|
switch (evtype)
|
|
|
|
{
|
|
|
|
case XI_ButtonPress:
|
2022-01-22 15:29:28 +03:00
|
|
|
xfc->xi_event = TRUE;
|
2022-02-18 10:49:56 +03:00
|
|
|
xf_generic_ButtonEvent(xfc, (int)event->event_x, (int)event->event_y, event->detail,
|
|
|
|
event->event, xfc->remote_app, TRUE);
|
2013-06-18 05:54:38 +04:00
|
|
|
break;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-06-18 05:54:38 +04:00
|
|
|
case XI_ButtonRelease:
|
2022-01-22 15:29:28 +03:00
|
|
|
xfc->xi_event = TRUE;
|
2022-02-18 10:49:56 +03:00
|
|
|
xf_generic_ButtonEvent(xfc, (int)event->event_x, (int)event->event_y, event->detail,
|
|
|
|
event->event, xfc->remote_app, FALSE);
|
2013-06-18 05:54:38 +04:00
|
|
|
break;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-06-18 05:54:38 +04:00
|
|
|
case XI_Motion:
|
2022-01-22 15:29:28 +03:00
|
|
|
xfc->xi_event = TRUE;
|
2022-02-18 10:49:56 +03:00
|
|
|
xf_generic_MotionNotify(xfc, (int)event->event_x, (int)event->event_y, event->detail,
|
|
|
|
event->event, xfc->remote_app);
|
2013-06-18 05:54:38 +04:00
|
|
|
break;
|
2022-01-19 15:29:26 +03:00
|
|
|
case XI_RawButtonPress:
|
|
|
|
case XI_RawButtonRelease:
|
2022-01-26 16:21:53 +03:00
|
|
|
xfc->xi_rawevent = xfc->common.mouse_grabbed &&
|
2022-01-22 15:29:28 +03:00
|
|
|
freerdp_settings_get_bool(settings, FreeRDP_MouseUseRelativeMove);
|
|
|
|
|
|
|
|
if (xfc->xi_rawevent)
|
|
|
|
{
|
|
|
|
const XIRawEvent* ev = (const XIRawEvent*)event;
|
|
|
|
xf_generic_RawButtonEvent(xfc, ev->detail, xfc->remote_app,
|
|
|
|
evtype == XI_RawButtonPress);
|
|
|
|
}
|
2022-02-18 10:49:56 +03:00
|
|
|
break;
|
2022-01-19 15:29:26 +03:00
|
|
|
case XI_RawMotion:
|
2022-01-26 16:21:53 +03:00
|
|
|
xfc->xi_rawevent = xfc->common.mouse_grabbed &&
|
2022-01-22 15:29:28 +03:00
|
|
|
freerdp_settings_get_bool(settings, FreeRDP_MouseUseRelativeMove);
|
|
|
|
|
|
|
|
if (xfc->xi_rawevent)
|
|
|
|
{
|
|
|
|
const XIRawEvent* ev = (const XIRawEvent*)event;
|
|
|
|
double x = 0.0;
|
|
|
|
double y = 0.0;
|
|
|
|
if (XIMaskIsSet(ev->valuators.mask, 0))
|
|
|
|
x = ev->raw_values[0];
|
|
|
|
if (XIMaskIsSet(ev->valuators.mask, 1))
|
|
|
|
y = ev->raw_values[1];
|
|
|
|
|
|
|
|
xf_generic_RawMotionNotify(xfc, (int)x, (int)y, event->event, xfc->remote_app);
|
|
|
|
}
|
2022-02-18 10:49:56 +03:00
|
|
|
break;
|
2023-06-23 05:42:14 +03:00
|
|
|
case XI_DeviceChanged:
|
|
|
|
{
|
|
|
|
const XIDeviceChangedEvent* ev = (const XIDeviceChangedEvent*)event;
|
|
|
|
if (ev->reason != XIDeviceChange)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO:
|
|
|
|
* 1. Register only changed devices.
|
|
|
|
* 2. Both `XIDeviceChangedEvent` and `XIHierarchyEvent` have no target
|
|
|
|
* `Window` which is used to register xinput events. So assume
|
|
|
|
* `xfc->window` created by `xf_CreateDesktopWindow` is the same
|
|
|
|
* `Window` we registered.
|
|
|
|
*/
|
|
|
|
if (xfc->window)
|
|
|
|
register_input_events(xfc, xfc->window->handle);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XI_HierarchyChanged:
|
|
|
|
if (xfc->window)
|
|
|
|
register_input_events(xfc, xfc->window->handle);
|
|
|
|
break;
|
|
|
|
|
2022-01-19 15:29:26 +03:00
|
|
|
default:
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_WARN(TAG, "Unhandled event %d: Event was registered but is not handled!", evtype);
|
2022-01-19 15:29:26 +03:00
|
|
|
break;
|
2013-06-18 05:54:38 +04:00
|
|
|
}
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-05-09 08:52:37 +04:00
|
|
|
return 0;
|
2013-04-26 06:04:35 +04:00
|
|
|
}
|
2013-05-09 08:52:37 +04:00
|
|
|
|
2020-02-27 10:50:04 +03:00
|
|
|
static int xf_input_handle_event_remote(xfContext* xfc, const XEvent* event)
|
2013-04-26 06:04:35 +04:00
|
|
|
{
|
2022-06-23 08:57:38 +03:00
|
|
|
union
|
|
|
|
{
|
2020-02-27 10:50:04 +03:00
|
|
|
const XGenericEventCookie* cc;
|
|
|
|
XGenericEventCookie* vc;
|
|
|
|
} cookie;
|
|
|
|
cookie.cc = &event->xcookie;
|
|
|
|
XGetEventData(xfc->display, cookie.vc);
|
|
|
|
|
|
|
|
if ((cookie.cc->type == GenericEvent) && (cookie.cc->extension == xfc->XInputOpcode))
|
2013-05-09 08:52:37 +04:00
|
|
|
{
|
2020-02-27 10:50:04 +03:00
|
|
|
switch (cookie.cc->evtype)
|
2013-04-26 06:04:35 +04:00
|
|
|
{
|
2013-05-09 08:52:37 +04:00
|
|
|
case XI_TouchBegin:
|
2023-06-21 09:57:47 +03:00
|
|
|
xf_input_pens_unhover(xfc);
|
2023-08-25 12:26:08 +03:00
|
|
|
/* fallthrough */
|
2023-07-31 17:49:24 +03:00
|
|
|
WINPR_FALLTHROUGH
|
2013-05-09 08:52:37 +04:00
|
|
|
case XI_TouchUpdate:
|
2023-08-25 12:26:08 +03:00
|
|
|
/* fallthrough */
|
2023-07-31 17:49:24 +03:00
|
|
|
WINPR_FALLTHROUGH
|
2013-05-09 08:52:37 +04:00
|
|
|
case XI_TouchEnd:
|
2022-01-19 15:29:26 +03:00
|
|
|
xf_input_touch_remote(xfc, cookie.cc->data, cookie.cc->evtype);
|
2013-04-26 06:04:35 +04:00
|
|
|
break;
|
2023-06-21 09:57:47 +03:00
|
|
|
case XI_ButtonPress:
|
2023-08-25 12:26:08 +03:00
|
|
|
/* fallthrough */
|
2023-07-31 17:49:24 +03:00
|
|
|
WINPR_FALLTHROUGH
|
2023-06-21 09:57:47 +03:00
|
|
|
case XI_Motion:
|
2023-08-25 12:26:08 +03:00
|
|
|
/* fallthrough */
|
2023-07-31 17:49:24 +03:00
|
|
|
WINPR_FALLTHROUGH
|
2023-06-21 09:57:47 +03:00
|
|
|
case XI_ButtonRelease:
|
|
|
|
{
|
|
|
|
WLog_DBG(TAG, "checking for pen");
|
|
|
|
XIDeviceEvent* deviceEvent = (XIDeviceEvent*)cookie.cc->data;
|
|
|
|
int deviceid = deviceEvent->deviceid;
|
2023-06-22 11:29:22 +03:00
|
|
|
|
|
|
|
if (freerdp_client_is_pen(&xfc->common, deviceid))
|
2023-06-21 09:57:47 +03:00
|
|
|
{
|
2023-09-11 09:05:35 +03:00
|
|
|
if (!xf_input_pen_remote(xfc, cookie.cc->data, cookie.cc->evtype, deviceid))
|
|
|
|
{
|
|
|
|
// XXX: don't show cursor
|
|
|
|
xf_input_event(xfc, event, cookie.cc->data, cookie.cc->evtype);
|
|
|
|
}
|
2023-06-21 09:57:47 +03:00
|
|
|
break;
|
2023-06-22 11:29:22 +03:00
|
|
|
}
|
2023-06-21 09:57:47 +03:00
|
|
|
}
|
2023-08-25 12:26:08 +03:00
|
|
|
/* fallthrough */
|
2023-07-31 17:49:24 +03:00
|
|
|
WINPR_FALLTHROUGH
|
2013-05-09 08:52:37 +04:00
|
|
|
default:
|
2023-06-21 09:57:47 +03:00
|
|
|
xf_input_pens_unhover(xfc);
|
2022-01-21 19:18:18 +03:00
|
|
|
xf_input_event(xfc, event, cookie.cc->data, cookie.cc->evtype);
|
2013-05-09 08:52:37 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2020-02-27 10:50:04 +03:00
|
|
|
XFreeEventData(xfc->display, cookie.vc);
|
2013-05-09 08:52:37 +04:00
|
|
|
return 0;
|
2013-04-26 06:04:35 +04:00
|
|
|
}
|
|
|
|
|
2013-05-11 01:51:09 +04:00
|
|
|
#else
|
2013-04-26 06:04:35 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
int xf_input_init(xfContext* xfc, Window window)
|
2013-05-11 01:51:09 +04:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2013-04-26 06:04:35 +04:00
|
|
|
|
2013-05-11 01:51:09 +04:00
|
|
|
#endif
|
2013-04-26 06:04:35 +04:00
|
|
|
|
2020-02-27 10:50:04 +03:00
|
|
|
int xf_input_handle_event(xfContext* xfc, const XEvent* event)
|
2013-05-09 08:52:37 +04:00
|
|
|
{
|
2013-05-11 01:51:09 +04:00
|
|
|
#ifdef WITH_XI
|
2022-01-19 11:27:39 +03:00
|
|
|
const rdpSettings* settings;
|
|
|
|
WINPR_ASSERT(xfc);
|
|
|
|
|
|
|
|
settings = xfc->common.context.settings;
|
|
|
|
WINPR_ASSERT(settings);
|
2016-08-03 15:16:20 +03:00
|
|
|
|
2022-01-19 11:27:39 +03:00
|
|
|
if (settings->MultiTouchInput)
|
2013-05-09 08:52:37 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
return xf_input_handle_event_remote(xfc, event);
|
2013-05-09 08:52:37 +04:00
|
|
|
}
|
2022-01-19 15:29:26 +03:00
|
|
|
else if (settings->MultiTouchGestures)
|
|
|
|
{
|
|
|
|
return xf_input_handle_event_local(xfc, event);
|
|
|
|
}
|
|
|
|
else
|
2014-03-14 05:10:22 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
return xf_input_handle_event_local(xfc, event);
|
2014-03-14 05:10:22 +04:00
|
|
|
}
|
2014-09-12 19:13:01 +04:00
|
|
|
|
2022-04-28 00:26:28 +03:00
|
|
|
#else
|
2013-05-11 00:56:24 +04:00
|
|
|
return 0;
|
2022-04-28 00:26:28 +03:00
|
|
|
#endif
|
2013-05-09 08:52:37 +04:00
|
|
|
}
|