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.
|
|
|
|
*/
|
|
|
|
|
2013-05-09 05:51:16 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
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>
|
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"
|
|
|
|
|
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-04-26 06:04:35 +04:00
|
|
|
#define MAX_CONTACTS 2
|
|
|
|
|
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
|
|
|
|
|
2013-04-26 06:04:35 +04:00
|
|
|
typedef struct touch_contact
|
|
|
|
{
|
|
|
|
int id;
|
|
|
|
int count;
|
|
|
|
double pos_x;
|
|
|
|
double pos_y;
|
|
|
|
double last_x;
|
|
|
|
double last_y;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-04-26 06:04:35 +04:00
|
|
|
} touchContact;
|
|
|
|
|
|
|
|
touchContact contacts[MAX_CONTACTS];
|
|
|
|
|
|
|
|
int active_contacts;
|
2013-05-16 01:35:16 +04:00
|
|
|
int lastEvType;
|
2013-04-27 00:23:52 +04:00
|
|
|
XIDeviceEvent lastEvent;
|
2013-04-27 01:42:23 +04:00
|
|
|
double firstDist = -1.0;
|
2013-05-09 02:14:55 +04:00
|
|
|
double lastDist;
|
|
|
|
|
|
|
|
double z_vector;
|
2013-05-30 22:36:13 +04:00
|
|
|
double px_vector;
|
|
|
|
double py_vector;
|
|
|
|
|
2013-05-09 05:51:16 +04:00
|
|
|
int xinput_opcode;
|
|
|
|
int scale_cnt;
|
2013-04-27 00:23:52 +04:00
|
|
|
|
2013-06-26 02:47:41 +04:00
|
|
|
const char* xf_input_get_class_string(int class)
|
|
|
|
{
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
2013-06-26 04:41:32 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
int xf_input_init(xfContext* xfc, Window window)
|
2013-05-09 05:51:16 +04:00
|
|
|
{
|
|
|
|
int i, j;
|
2013-05-15 01:45:52 +04:00
|
|
|
int nmasks;
|
2013-05-09 05:51:16 +04:00
|
|
|
int ndevices;
|
|
|
|
int major = 2;
|
|
|
|
int minor = 2;
|
|
|
|
Status xstatus;
|
|
|
|
XIDeviceInfo* info;
|
2013-06-26 02:47:41 +04:00
|
|
|
XIEventMask evmasks[64];
|
2013-05-09 05:51:16 +04:00
|
|
|
int opcode, event, error;
|
2013-05-15 01:45:52 +04:00
|
|
|
BYTE masks[8][XIMaskLen(XI_LASTEVENT)];
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-06-05 22:59:24 +04:00
|
|
|
z_vector = 0;
|
|
|
|
px_vector = 0;
|
|
|
|
py_vector = 0;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-05-15 01:45:52 +04:00
|
|
|
nmasks = 0;
|
2013-05-15 19:39:28 +04:00
|
|
|
ndevices = 0;
|
2013-05-09 05:51:16 +04:00
|
|
|
active_contacts = 0;
|
|
|
|
ZeroMemory(contacts, sizeof(touchContact) * MAX_CONTACTS);
|
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;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XIQueryVersion(xfc->display, &major, &minor);
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-05-09 05:51:16 +04:00
|
|
|
if (major * 1000 + minor < 2002)
|
|
|
|
{
|
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;
|
|
|
|
}
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-06-18 05:54:38 +04:00
|
|
|
if (xfc->settings->MultiTouchInput)
|
|
|
|
xfc->use_xinput = TRUE;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
info = XIQueryDevice(xfc->display, XIAllDevices, &ndevices);
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-05-09 05:51:16 +04:00
|
|
|
for (i = 0; i < ndevices; i++)
|
|
|
|
{
|
2013-06-26 02:47:41 +04:00
|
|
|
BOOL touch = FALSE;
|
2013-05-09 05:51:16 +04:00
|
|
|
XIDeviceInfo* dev = &info[i];
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-05-09 05:51:16 +04:00
|
|
|
for (j = 0; j < dev->num_classes; j++)
|
|
|
|
{
|
|
|
|
XIAnyClassInfo* class = dev->classes[j];
|
2013-05-14 03:17:25 +04:00
|
|
|
XITouchClassInfo* t = (XITouchClassInfo*) class;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-06-26 02:47:41 +04:00
|
|
|
if ((class->type == XITouchClass) && (t->mode == XIDirectTouch) &&
|
2013-07-23 22:47:40 +04:00
|
|
|
(strcmp(dev->name, "Virtual core pointer") != 0))
|
2013-06-26 02:47:41 +04:00
|
|
|
{
|
|
|
|
touch = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-06-26 02:47:41 +04:00
|
|
|
for (j = 0; j < dev->num_classes; j++)
|
|
|
|
{
|
|
|
|
XIAnyClassInfo* class = dev->classes[j];
|
|
|
|
XITouchClassInfo* t = (XITouchClassInfo*) class;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-06-18 06:22:16 +04:00
|
|
|
if (xfc->settings->MultiTouchInput)
|
2013-06-26 02:47:41 +04:00
|
|
|
{
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_INFO(TAG, "%s (%d) \"%s\" id: %d",
|
|
|
|
xf_input_get_class_string(class->type),
|
|
|
|
class->type, dev->name, dev->deviceid);
|
2013-06-26 02:47:41 +04:00
|
|
|
}
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-05-15 01:45:52 +04:00
|
|
|
evmasks[nmasks].mask = masks[nmasks];
|
|
|
|
evmasks[nmasks].mask_len = sizeof(masks[0]);
|
|
|
|
ZeroMemory(masks[nmasks], sizeof(masks[0]));
|
|
|
|
evmasks[nmasks].deviceid = dev->deviceid;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-06-26 02:47:41 +04:00
|
|
|
if ((class->type == XITouchClass) && (t->mode == XIDirectTouch) &&
|
2013-07-23 22:47:40 +04:00
|
|
|
(strcmp(dev->name, "Virtual core pointer") != 0))
|
2013-06-26 02:47:41 +04:00
|
|
|
{
|
2013-06-18 06:22:16 +04:00
|
|
|
if (xfc->settings->MultiTouchInput)
|
2013-06-26 02:47:41 +04:00
|
|
|
{
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_INFO(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);
|
2013-06-26 02:47:41 +04:00
|
|
|
}
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-06-26 02:47:41 +04:00
|
|
|
XISetMask(masks[nmasks], XI_TouchBegin);
|
|
|
|
XISetMask(masks[nmasks], XI_TouchUpdate);
|
|
|
|
XISetMask(masks[nmasks], XI_TouchEnd);
|
|
|
|
nmasks++;
|
|
|
|
}
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-06-18 05:54:38 +04:00
|
|
|
if (xfc->use_xinput)
|
2013-06-26 02:47:41 +04:00
|
|
|
{
|
2013-06-28 21:46:58 +04:00
|
|
|
if (!touch && (class->type == XIButtonClass) && strcmp(dev->name, "Virtual core pointer"))
|
2013-06-26 02:47:41 +04:00
|
|
|
{
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_INFO(TAG, "%s button device (id: %d, mode: %d)",
|
|
|
|
dev->name,
|
|
|
|
dev->deviceid, t->mode);
|
2013-06-26 02:47:41 +04:00
|
|
|
XISetMask(masks[nmasks], XI_ButtonPress);
|
|
|
|
XISetMask(masks[nmasks], XI_ButtonRelease);
|
|
|
|
XISetMask(masks[nmasks], XI_Motion);
|
|
|
|
nmasks++;
|
|
|
|
}
|
|
|
|
}
|
2013-05-15 01:45:52 +04:00
|
|
|
}
|
|
|
|
}
|
2013-08-19 19:44:52 +04:00
|
|
|
XIFreeDeviceInfo(info);
|
|
|
|
|
2013-05-15 19:39:28 +04:00
|
|
|
if (nmasks > 0)
|
2013-06-13 02:57:25 +04:00
|
|
|
xstatus = XISelectEvents(xfc->display, window, evmasks, nmasks);
|
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
|
|
|
|
2013-05-16 01:35:16 +04:00
|
|
|
BOOL xf_input_is_duplicate(XGenericEventCookie* cookie)
|
2013-04-27 00:40:27 +04:00
|
|
|
{
|
2013-07-23 22:47:40 +04:00
|
|
|
XIDeviceEvent* event;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-07-23 22:47:40 +04:00
|
|
|
event = cookie->data;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
|
|
|
|
2013-05-09 05:51:16 +04:00
|
|
|
if ( (lastEvent.time == event->time) &&
|
2013-07-23 22:47:40 +04:00
|
|
|
(lastEvType == cookie->evtype) &&
|
|
|
|
(lastEvent.detail == event->detail) &&
|
|
|
|
(lastEvent.event_x == event->event_x) &&
|
|
|
|
(lastEvent.event_y == event->event_y) )
|
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;
|
|
|
|
}
|
|
|
|
|
2013-05-16 01:35:16 +04:00
|
|
|
void xf_input_save_last_event(XGenericEventCookie* cookie)
|
2013-04-27 00:40:27 +04:00
|
|
|
{
|
2013-07-23 22:47:40 +04:00
|
|
|
XIDeviceEvent* event;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-07-23 22:47:40 +04:00
|
|
|
event = cookie->data;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-07-23 22:47:40 +04:00
|
|
|
lastEvType = cookie->evtype;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-04-27 00:40:27 +04:00
|
|
|
lastEvent.time = event->time;
|
|
|
|
lastEvent.detail = event->detail;
|
|
|
|
lastEvent.event_x = event->event_x;
|
|
|
|
lastEvent.event_y = event->event_y;
|
|
|
|
}
|
|
|
|
|
2013-06-27 03:16:28 +04:00
|
|
|
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];
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-07-23 22:47:40 +04:00
|
|
|
double px;
|
|
|
|
double py;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-07-23 22:47:40 +04:00
|
|
|
double dist_x;
|
|
|
|
double dist_y;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-07-23 22:47:40 +04:00
|
|
|
if (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
|
|
|
|
2013-07-23 22:47:40 +04:00
|
|
|
dx[0] = contacts[0].pos_x - contacts[0].last_x;
|
|
|
|
dx[1] = contacts[1].pos_x - contacts[1].last_x;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-07-23 22:47:40 +04:00
|
|
|
dy[0] = contacts[0].pos_y - contacts[0].last_y;
|
|
|
|
dy[1] = contacts[1].pos_y - contacts[1].last_y;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
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];
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-07-23 22:47:40 +04:00
|
|
|
px_vector += px;
|
|
|
|
py_vector += py;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-07-23 22:47:40 +04:00
|
|
|
dist_x = fabs(contacts[0].pos_x - contacts[1].pos_x);
|
|
|
|
dist_y = fabs(contacts[0].pos_y - 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
|
|
|
{
|
2014-03-14 05:10:22 +04:00
|
|
|
if (px_vector > PAN_THRESHOLD)
|
2013-07-23 22:47:40 +04:00
|
|
|
{
|
|
|
|
{
|
|
|
|
PanningChangeEventArgs e;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-07-23 22:47:40 +04:00
|
|
|
EventArgsInit(&e, "xfreerdp");
|
2014-12-01 13:56:44 +03:00
|
|
|
e.dx = 5;
|
|
|
|
e.dy = 0;
|
2013-07-23 22:47:40 +04:00
|
|
|
PubSub_OnPanningChange(((rdpContext*) xfc)->pubSub, xfc, &e);
|
|
|
|
}
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-07-23 22:47:40 +04:00
|
|
|
px_vector = 0;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-07-23 22:47:40 +04:00
|
|
|
px_vector = 0;
|
|
|
|
py_vector = 0;
|
|
|
|
z_vector = 0;
|
|
|
|
}
|
2014-03-14 05:10:22 +04:00
|
|
|
else if (px_vector < -PAN_THRESHOLD)
|
2013-07-23 22:47:40 +04:00
|
|
|
{
|
|
|
|
{
|
|
|
|
PanningChangeEventArgs e;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-07-23 22:47:40 +04:00
|
|
|
EventArgsInit(&e, "xfreerdp");
|
2014-12-01 13:56:44 +03:00
|
|
|
e.dx = -5;
|
|
|
|
e.dy = 0;
|
2013-07-23 22:47:40 +04:00
|
|
|
PubSub_OnPanningChange(((rdpContext*) xfc)->pubSub, xfc, &e);
|
|
|
|
}
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-07-23 22:47:40 +04:00
|
|
|
px_vector = 0;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-07-23 22:47:40 +04:00
|
|
|
px_vector = 0;
|
|
|
|
py_vector = 0;
|
|
|
|
z_vector = 0;
|
|
|
|
}
|
2014-12-01 13:56:44 +03: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
|
|
|
{
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2014-03-14 05:10:22 +04:00
|
|
|
if (py_vector > PAN_THRESHOLD)
|
2013-07-23 22:47:40 +04:00
|
|
|
{
|
|
|
|
{
|
|
|
|
PanningChangeEventArgs e;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-07-23 22:47:40 +04:00
|
|
|
EventArgsInit(&e, "xfreerdp");
|
2014-12-01 13:56:44 +03:00
|
|
|
e.dx = 0;
|
|
|
|
e.dy = 5;
|
2013-07-23 22:47:40 +04:00
|
|
|
PubSub_OnPanningChange(((rdpContext*) xfc)->pubSub, xfc, &e);
|
|
|
|
}
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-07-23 22:47:40 +04:00
|
|
|
py_vector = 0;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-07-23 22:47:40 +04:00
|
|
|
px_vector = 0;
|
|
|
|
py_vector = 0;
|
|
|
|
z_vector = 0;
|
|
|
|
}
|
2014-03-14 05:10:22 +04:00
|
|
|
else if (py_vector < -PAN_THRESHOLD)
|
2013-07-23 22:47:40 +04:00
|
|
|
{
|
|
|
|
{
|
|
|
|
PanningChangeEventArgs e;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-07-23 22:47:40 +04:00
|
|
|
EventArgsInit(&e, "xfreerdp");
|
2014-12-01 13:56:44 +03:00
|
|
|
e.dx = 0;
|
|
|
|
e.dy = -5;
|
2013-07-23 22:47:40 +04:00
|
|
|
PubSub_OnPanningChange(((rdpContext*) xfc)->pubSub, xfc, &e);
|
|
|
|
}
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-07-23 22:47:40 +04:00
|
|
|
py_vector = 0;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-07-23 22:47:40 +04:00
|
|
|
px_vector = 0;
|
|
|
|
py_vector = 0;
|
|
|
|
z_vector = 0;
|
|
|
|
}
|
2013-06-01 01:07:51 +04:00
|
|
|
}
|
2013-05-30 22:36:13 +04:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
void xf_input_detect_pinch(xfContext* xfc)
|
2013-04-27 01:42:23 +04:00
|
|
|
{
|
|
|
|
double dist;
|
|
|
|
double zoom;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-05-09 05:51:16 +04:00
|
|
|
double delta;
|
2014-12-01 13:56:44 +03:00
|
|
|
ZoomingChangeEventArgs e;
|
|
|
|
|
2013-05-09 05:51:16 +04:00
|
|
|
if (active_contacts != 2)
|
2013-04-27 01:42:23 +04:00
|
|
|
{
|
|
|
|
firstDist = -1.0;
|
|
|
|
return;
|
|
|
|
}
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-05-09 05:51:16 +04:00
|
|
|
/* first calculate the distance */
|
2013-04-27 01:42:23 +04:00
|
|
|
dist = sqrt(pow(contacts[1].pos_x - contacts[0].last_x, 2.0) +
|
2013-07-23 22:47:40 +04:00
|
|
|
pow(contacts[1].pos_y - 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 */
|
|
|
|
if (firstDist <= 0)
|
2013-04-27 01:42:23 +04:00
|
|
|
{
|
|
|
|
firstDist = dist;
|
2013-05-09 05:51:16 +04:00
|
|
|
lastDist = firstDist;
|
|
|
|
scale_cnt = 0;
|
|
|
|
z_vector = 0;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-05-31 00:04:31 +04:00
|
|
|
px_vector = 0;
|
|
|
|
py_vector = 0;
|
|
|
|
z_vector = 0;
|
2013-04-27 01:42:23 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-09 05:51:16 +04:00
|
|
|
delta = lastDist - dist;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-06-01 01:07:51 +04:00
|
|
|
if(delta > 1.0)
|
2013-07-23 22:47:40 +04:00
|
|
|
delta = 1.0;
|
2013-06-01 01:07:51 +04: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 */
|
|
|
|
zoom = (dist / firstDist);
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-05-09 05:51:16 +04:00
|
|
|
z_vector += delta;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-05-09 05:51:16 +04:00
|
|
|
lastDist = dist;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-05-31 21:48:53 +04:00
|
|
|
if (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;
|
|
|
|
PubSub_OnZoomingChange(((rdpContext*) xfc)->pubSub, xfc, &e);
|
|
|
|
|
2013-05-09 05:51:16 +04:00
|
|
|
z_vector = 0;
|
2013-05-31 00:04:31 +04:00
|
|
|
px_vector = 0;
|
|
|
|
py_vector = 0;
|
|
|
|
z_vector = 0;
|
2013-05-09 05:51:16 +04:00
|
|
|
}
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-05-31 21:48:53 +04:00
|
|
|
if (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;
|
|
|
|
PubSub_OnZoomingChange(((rdpContext*) xfc)->pubSub, xfc, &e);
|
|
|
|
|
2013-05-09 05:51:16 +04:00
|
|
|
z_vector = 0;
|
2013-05-31 00:04:31 +04:00
|
|
|
px_vector = 0;
|
|
|
|
py_vector = 0;
|
|
|
|
z_vector = 0;
|
2013-05-09 05:51:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-26 02:58:22 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
void xf_input_touch_begin(xfContext* xfc, XIDeviceEvent* event)
|
2013-05-09 05:51:16 +04:00
|
|
|
{
|
|
|
|
int i;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-05-09 05:51:16 +04:00
|
|
|
for (i = 0; i < MAX_CONTACTS; i++)
|
|
|
|
{
|
|
|
|
if (contacts[i].id == 0)
|
2013-04-26 02:58:22 +04:00
|
|
|
{
|
2013-05-09 05:51:16 +04:00
|
|
|
contacts[i].id = event->detail;
|
|
|
|
contacts[i].count = 1;
|
|
|
|
contacts[i].pos_x = event->event_x;
|
|
|
|
contacts[i].pos_y = event->event_y;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-05-09 05:51:16 +04:00
|
|
|
active_contacts++;
|
|
|
|
break;
|
2013-04-26 02:58:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-26 03:38:13 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
void xf_input_touch_update(xfContext* xfc, 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
|
|
|
|
2013-05-09 05:51:16 +04:00
|
|
|
for (i = 0; i < MAX_CONTACTS; i++)
|
|
|
|
{
|
|
|
|
if (contacts[i].id == event->detail)
|
2013-04-26 03:38:13 +04:00
|
|
|
{
|
2013-05-09 05:51:16 +04:00
|
|
|
contacts[i].count++;
|
|
|
|
contacts[i].last_x = contacts[i].pos_x;
|
|
|
|
contacts[i].last_y = contacts[i].pos_y;
|
|
|
|
contacts[i].pos_x = event->event_x;
|
|
|
|
contacts[i].pos_y = event->event_y;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
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);
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-05-09 05:51:16 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-26 03:38:13 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
void xf_input_touch_end(xfContext* xfc, XIDeviceEvent* event)
|
2013-05-09 05:51:16 +04:00
|
|
|
{
|
|
|
|
int i;
|
2014-03-14 05:10:22 +04:00
|
|
|
|
2013-05-09 05:51:16 +04:00
|
|
|
for (i = 0; i < MAX_CONTACTS; i++)
|
|
|
|
{
|
|
|
|
if (contacts[i].id == event->detail)
|
|
|
|
{
|
|
|
|
contacts[i].id = 0;
|
|
|
|
contacts[i].count = 0;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-05-09 05:51:16 +04:00
|
|
|
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
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
int xf_input_handle_event_local(xfContext* xfc, XEvent* event)
|
2013-04-26 06:04:35 +04:00
|
|
|
{
|
2013-05-09 08:52:37 +04:00
|
|
|
XGenericEventCookie* cookie = &event->xcookie;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XGetEventData(xfc->display, cookie);
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if ((cookie->type == GenericEvent) && (cookie->extension == xfc->XInputOpcode))
|
2013-04-26 06:04:35 +04:00
|
|
|
{
|
2013-05-09 08:52:37 +04:00
|
|
|
switch (cookie->evtype)
|
2013-04-26 06:04:35 +04:00
|
|
|
{
|
2013-05-09 08:52:37 +04:00
|
|
|
case XI_TouchBegin:
|
2013-05-16 01:35:16 +04:00
|
|
|
if (xf_input_is_duplicate(cookie) == FALSE)
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_input_touch_begin(xfc, cookie->data);
|
2013-05-16 01:35:16 +04:00
|
|
|
xf_input_save_last_event(cookie);
|
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:
|
2013-05-16 01:35:16 +04:00
|
|
|
if (xf_input_is_duplicate(cookie) == FALSE)
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_input_touch_update(xfc, cookie->data);
|
2013-05-16 01:35:16 +04:00
|
|
|
xf_input_save_last_event(cookie);
|
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:
|
2013-05-16 01:35:16 +04:00
|
|
|
if (xf_input_is_duplicate(cookie) == FALSE)
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_input_touch_end(xfc, cookie->data);
|
2013-05-16 01:35:16 +04:00
|
|
|
xf_input_save_last_event(cookie);
|
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:
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_ERR(TAG, "unhandled xi type= %d", cookie->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
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XFreeEventData(xfc->display,cookie);
|
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-14 03:17:25 +04:00
|
|
|
char* xf_input_touch_state_string(DWORD flags)
|
2013-05-09 08:52:37 +04:00
|
|
|
{
|
2013-05-14 03:17:25 +04:00
|
|
|
if (flags & CONTACT_FLAG_DOWN)
|
|
|
|
return "TouchBegin";
|
|
|
|
else if (flags & CONTACT_FLAG_UPDATE)
|
|
|
|
return "TouchUpdate";
|
|
|
|
else if (flags & CONTACT_FLAG_UP)
|
|
|
|
return "TouchEnd";
|
|
|
|
else
|
|
|
|
return "TouchUnknown";
|
2013-05-09 08:52:37 +04:00
|
|
|
}
|
2013-04-26 23:27:08 +04:00
|
|
|
|
2013-08-04 00:13:39 +04:00
|
|
|
void xf_input_hide_cursor(xfContext* xfc)
|
|
|
|
{
|
|
|
|
#ifdef WITH_XCURSOR
|
|
|
|
if (!xfc->cursorHidden)
|
|
|
|
{
|
|
|
|
XcursorImage ci;
|
|
|
|
XcursorPixel xp = 0;
|
|
|
|
static Cursor nullcursor = None;
|
|
|
|
|
|
|
|
xf_lock_x11(xfc, FALSE);
|
|
|
|
|
|
|
|
ZeroMemory(&ci, sizeof(ci));
|
|
|
|
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;
|
|
|
|
|
|
|
|
xf_unlock_x11(xfc, FALSE);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void xf_input_show_cursor(xfContext* xfc)
|
|
|
|
{
|
|
|
|
#ifdef WITH_XCURSOR
|
|
|
|
xf_lock_x11(xfc, FALSE);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
xf_unlock_x11(xfc, FALSE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
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;
|
2013-06-07 02:14:59 +04:00
|
|
|
int contactId;
|
2013-06-13 02:57:25 +04:00
|
|
|
RdpeiClientContext* rdpei = xfc->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;
|
|
|
|
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);
|
|
|
|
|
2013-06-07 02:14:59 +04:00
|
|
|
if (evtype == XI_TouchBegin)
|
2013-05-14 09:06:25 +04:00
|
|
|
{
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_DBG(TAG, "TouchBegin: %d", touchId);
|
2013-06-07 02:14:59 +04:00
|
|
|
contactId = rdpei->TouchBegin(rdpei, touchId, x, y);
|
2013-05-14 09:06:25 +04:00
|
|
|
}
|
2013-06-07 02:14:59 +04:00
|
|
|
else if (evtype == XI_TouchUpdate)
|
2013-05-14 09:06:25 +04:00
|
|
|
{
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_DBG(TAG, "TouchUpdate: %d", touchId);
|
2013-06-07 02:14:59 +04:00
|
|
|
contactId = rdpei->TouchUpdate(rdpei, touchId, x, y);
|
2013-05-14 09:06:25 +04:00
|
|
|
}
|
2013-06-07 02:14:59 +04:00
|
|
|
else if (evtype == XI_TouchEnd)
|
2013-05-14 09:06:25 +04:00
|
|
|
{
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_DBG(TAG, "TouchEnd: %d", touchId);
|
2013-06-07 02:14:59 +04:00
|
|
|
contactId = rdpei->TouchEnd(rdpei, touchId, x, y);
|
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;
|
|
|
|
}
|
|
|
|
|
2013-06-18 05:54:38 +04:00
|
|
|
int xf_input_event(xfContext* xfc, XIDeviceEvent* event, int evtype)
|
|
|
|
{
|
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:
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-06-18 05:54:38 +04:00
|
|
|
xf_generic_ButtonPress(xfc, (int) event->event_x, (int) event->event_y,
|
2013-07-23 22:47:40 +04:00
|
|
|
event->detail, event->event, xfc->remote_app);
|
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:
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-06-18 05:54:38 +04:00
|
|
|
xf_generic_ButtonRelease(xfc, (int) event->event_x, (int) event->event_y,
|
2013-07-23 22:47:40 +04:00
|
|
|
event->detail, event->event, xfc->remote_app);
|
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:
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-06-18 05:54:38 +04:00
|
|
|
xf_generic_MotionNotify(xfc, (int) event->event_x, (int) event->event_y,
|
2013-07-23 22:47:40 +04:00
|
|
|
event->detail, event->event, xfc->remote_app);
|
2013-06-18 05:54:38 +04:00
|
|
|
break;
|
|
|
|
}
|
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
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
int xf_input_handle_event_remote(xfContext* xfc, XEvent* event)
|
2013-04-26 06:04:35 +04:00
|
|
|
{
|
2013-05-09 08:52:37 +04:00
|
|
|
XGenericEventCookie* cookie = &event->xcookie;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XGetEventData(xfc->display, cookie);
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if ((cookie->type == GenericEvent) && (cookie->extension == xfc->XInputOpcode))
|
2013-05-09 08:52:37 +04:00
|
|
|
{
|
|
|
|
switch (cookie->evtype)
|
2013-04-26 06:04:35 +04:00
|
|
|
{
|
2013-05-09 08:52:37 +04:00
|
|
|
case XI_TouchBegin:
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_input_touch_remote(xfc, cookie->data, XI_TouchBegin);
|
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:
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_input_touch_remote(xfc, cookie->data, XI_TouchUpdate);
|
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:
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_input_touch_remote(xfc, cookie->data, XI_TouchEnd);
|
2013-04-26 06:04:35 +04:00
|
|
|
break;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-05-09 08:52:37 +04:00
|
|
|
default:
|
2013-06-18 05:54:38 +04:00
|
|
|
xf_input_event(xfc, cookie->data, cookie->evtype);
|
2013-05-09 08:52:37 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XFreeEventData(xfc->display,cookie);
|
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-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
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
int xf_input_handle_event(xfContext* xfc, XEvent* event)
|
2013-05-09 08:52:37 +04:00
|
|
|
{
|
2013-05-11 01:51:09 +04:00
|
|
|
#ifdef WITH_XI
|
2013-06-28 04:26:31 +04:00
|
|
|
if (xfc->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
|
|
|
}
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2013-06-26 04:41:32 +04:00
|
|
|
if (xfc->settings->MultiTouchGestures)
|
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
|
|
|
}
|
2013-05-06 23:43:34 +04:00
|
|
|
#endif
|
2014-09-12 19:13:01 +04:00
|
|
|
|
2013-05-11 00:56:24 +04:00
|
|
|
return 0;
|
2013-05-09 08:52:37 +04:00
|
|
|
}
|