2013-03-20 00:52:07 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* Input Virtual Channel Extension
|
|
|
|
*
|
|
|
|
* Copyright 2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2015-06-09 13:46:10 +03:00
|
|
|
* Copyright 2015 Thincast Technologies GmbH
|
|
|
|
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
2013-03-20 00:52:07 +04:00
|
|
|
*
|
|
|
|
* 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-03-20 00:52:07 +04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2024-10-14 16:50:38 +03:00
|
|
|
#include <stdint.h>
|
2013-03-20 00:52:07 +04:00
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
2013-06-12 00:15:46 +04:00
|
|
|
#include <winpr/synch.h>
|
|
|
|
#include <winpr/thread.h>
|
2013-05-09 07:18:42 +04:00
|
|
|
#include <winpr/stream.h>
|
2013-05-14 03:17:25 +04:00
|
|
|
#include <winpr/sysinfo.h>
|
2013-03-20 00:52:07 +04:00
|
|
|
#include <winpr/cmdline.h>
|
2013-06-12 00:15:46 +04:00
|
|
|
#include <winpr/collections.h>
|
2013-03-20 00:52:07 +04:00
|
|
|
|
|
|
|
#include <freerdp/addin.h>
|
2015-07-15 10:50:35 +03:00
|
|
|
#include <freerdp/freerdp.h>
|
2022-06-14 01:51:00 +03:00
|
|
|
#include <freerdp/client/channels.h>
|
2013-03-20 00:52:07 +04:00
|
|
|
|
2013-05-09 07:18:42 +04:00
|
|
|
#include "rdpei_common.h"
|
2013-03-20 00:52:07 +04:00
|
|
|
|
|
|
|
#include "rdpei_main.h"
|
|
|
|
|
2024-09-25 13:41:19 +03:00
|
|
|
#define RDPEI_TAG CHANNELS_TAG("rdpei.client")
|
|
|
|
|
2013-05-15 01:45:52 +04:00
|
|
|
/**
|
|
|
|
* Touch Input
|
|
|
|
* http://msdn.microsoft.com/en-us/library/windows/desktop/dd562197/
|
|
|
|
*
|
|
|
|
* Windows Touch Input
|
|
|
|
* http://msdn.microsoft.com/en-us/library/windows/desktop/dd317321/
|
|
|
|
*
|
|
|
|
* Input: Touch injection sample
|
|
|
|
* http://code.msdn.microsoft.com/windowsdesktop/Touch-Injection-Sample-444d9bf7
|
|
|
|
*
|
|
|
|
* Pointer Input Message Reference
|
|
|
|
* http://msdn.microsoft.com/en-us/library/hh454916/
|
|
|
|
*
|
|
|
|
* POINTER_INFO Structure
|
|
|
|
* http://msdn.microsoft.com/en-us/library/hh454907/
|
|
|
|
*
|
|
|
|
* POINTER_TOUCH_INFO Structure
|
|
|
|
* http://msdn.microsoft.com/en-us/library/hh454910/
|
|
|
|
*/
|
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
#define MAX_CONTACTS 64
|
|
|
|
#define MAX_PEN_CONTACTS 4
|
2013-05-14 03:17:25 +04:00
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2013-03-20 00:52:07 +04:00
|
|
|
{
|
2022-06-21 09:09:00 +03:00
|
|
|
GENERIC_DYNVC_PLUGIN base;
|
2013-05-14 03:17:25 +04:00
|
|
|
|
2014-12-27 23:20:29 +03:00
|
|
|
RdpeiClientContext* context;
|
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
UINT32 version;
|
2021-05-20 15:11:43 +03:00
|
|
|
UINT32 features; /* SC_READY_MULTIPEN_INJECTION_SUPPORTED */
|
2013-05-15 01:45:52 +04:00
|
|
|
UINT16 maxTouchContacts;
|
2013-05-14 03:17:25 +04:00
|
|
|
UINT64 currentFrameTime;
|
|
|
|
UINT64 previousFrameTime;
|
2020-11-11 10:54:46 +03:00
|
|
|
RDPINPUT_CONTACT_POINT contactPoints[MAX_CONTACTS];
|
2013-06-12 00:15:46 +04:00
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
UINT64 currentPenFrameTime;
|
|
|
|
UINT64 previousPenFrameTime;
|
|
|
|
UINT16 maxPenContacts;
|
|
|
|
RDPINPUT_PEN_CONTACT_POINT penContactPoints[MAX_PEN_CONTACTS];
|
|
|
|
|
|
|
|
CRITICAL_SECTION lock;
|
2015-07-15 10:50:35 +03:00
|
|
|
rdpContext* rdpcontext;
|
2024-09-25 13:41:19 +03:00
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
HANDLE thread;
|
2024-09-25 13:41:19 +03:00
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
HANDLE event;
|
2024-09-25 13:41:19 +03:00
|
|
|
UINT64 lastPollEventTime;
|
2022-09-12 22:28:31 +03:00
|
|
|
BOOL running;
|
2024-09-25 13:41:19 +03:00
|
|
|
BOOL async;
|
2022-02-14 16:59:22 +03:00
|
|
|
} RDPEI_PLUGIN;
|
2013-03-20 00:52:07 +04:00
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2020-11-11 10:54:46 +03:00
|
|
|
static UINT rdpei_send_frame(RdpeiClientContext* context, RDPINPUT_TOUCH_FRAME* frame);
|
2013-06-12 00:15:46 +04:00
|
|
|
|
2020-01-23 12:50:37 +03:00
|
|
|
#ifdef WITH_DEBUG_RDPEI
|
|
|
|
static const char* rdpei_eventid_string(UINT16 event)
|
|
|
|
{
|
|
|
|
switch (event)
|
|
|
|
{
|
|
|
|
case EVENTID_SC_READY:
|
|
|
|
return "EVENTID_SC_READY";
|
|
|
|
case EVENTID_CS_READY:
|
|
|
|
return "EVENTID_CS_READY";
|
|
|
|
case EVENTID_TOUCH:
|
|
|
|
return "EVENTID_TOUCH";
|
|
|
|
case EVENTID_SUSPEND_TOUCH:
|
|
|
|
return "EVENTID_SUSPEND_TOUCH";
|
|
|
|
case EVENTID_RESUME_TOUCH:
|
|
|
|
return "EVENTID_RESUME_TOUCH";
|
|
|
|
case EVENTID_DISMISS_HOVERING_CONTACT:
|
|
|
|
return "EVENTID_DISMISS_HOVERING_CONTACT";
|
2020-11-11 10:54:46 +03:00
|
|
|
case EVENTID_PEN:
|
|
|
|
return "EVENTID_PEN";
|
2020-01-23 12:50:37 +03:00
|
|
|
default:
|
|
|
|
return "EVENTID_UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2013-05-09 07:18:42 +04:00
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
static RDPINPUT_CONTACT_POINT* rdpei_contact(RDPEI_PLUGIN* rdpei, INT32 externalId, BOOL active)
|
|
|
|
{
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT16 i = 0; i < rdpei->maxTouchContacts; i++)
|
2020-11-11 10:54:46 +03:00
|
|
|
{
|
|
|
|
RDPINPUT_CONTACT_POINT* contactPoint = &rdpei->contactPoints[i];
|
|
|
|
|
|
|
|
if (!contactPoint->active && active)
|
|
|
|
continue;
|
|
|
|
else if (!contactPoint->active && !active)
|
|
|
|
{
|
|
|
|
contactPoint->contactId = i;
|
|
|
|
contactPoint->externalId = externalId;
|
|
|
|
contactPoint->active = TRUE;
|
|
|
|
return contactPoint;
|
|
|
|
}
|
|
|
|
else if (contactPoint->externalId == externalId)
|
|
|
|
{
|
|
|
|
return contactPoint;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-20 13:30:14 +03:00
|
|
|
static UINT rdpei_add_frame(RdpeiClientContext* context)
|
2013-06-12 00:15:46 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
RDPEI_PLUGIN* rdpei = NULL;
|
2020-11-11 10:54:46 +03:00
|
|
|
RDPINPUT_TOUCH_FRAME frame = { 0 };
|
|
|
|
RDPINPUT_CONTACT_DATA contacts[MAX_CONTACTS] = { 0 };
|
|
|
|
|
|
|
|
if (!context || !context->handle)
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
|
|
|
rdpei = (RDPEI_PLUGIN*)context->handle;
|
|
|
|
frame.contacts = contacts;
|
2013-06-12 00:15:46 +04:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT16 i = 0; i < rdpei->maxTouchContacts; i++)
|
2013-06-12 00:15:46 +04:00
|
|
|
{
|
2020-11-11 10:54:46 +03:00
|
|
|
RDPINPUT_CONTACT_POINT* contactPoint = &rdpei->contactPoints[i];
|
|
|
|
RDPINPUT_CONTACT_DATA* contact = &contactPoint->data;
|
2013-06-12 00:15:46 +04:00
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
if (contactPoint->dirty)
|
2013-06-12 00:15:46 +04:00
|
|
|
{
|
2020-11-11 10:54:46 +03:00
|
|
|
contacts[frame.contactCount] = *contact;
|
2013-06-12 00:15:46 +04:00
|
|
|
rdpei->contactPoints[i].dirty = FALSE;
|
2020-11-11 10:54:46 +03:00
|
|
|
frame.contactCount++;
|
2013-06-12 00:15:46 +04:00
|
|
|
}
|
2020-11-11 10:54:46 +03:00
|
|
|
else if (contactPoint->active)
|
2013-06-12 00:15:46 +04:00
|
|
|
{
|
2020-11-30 15:40:15 +03:00
|
|
|
if (contact->contactFlags & RDPINPUT_CONTACT_FLAG_DOWN)
|
2013-06-12 00:15:46 +04:00
|
|
|
{
|
2020-11-30 15:40:15 +03:00
|
|
|
contact->contactFlags = RDPINPUT_CONTACT_FLAG_UPDATE;
|
|
|
|
contact->contactFlags |= RDPINPUT_CONTACT_FLAG_INRANGE;
|
|
|
|
contact->contactFlags |= RDPINPUT_CONTACT_FLAG_INCONTACT;
|
2013-06-12 00:15:46 +04:00
|
|
|
}
|
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
contacts[frame.contactCount] = *contact;
|
|
|
|
frame.contactCount++;
|
|
|
|
}
|
2020-11-30 15:40:15 +03:00
|
|
|
if (contact->contactFlags & RDPINPUT_CONTACT_FLAG_UP)
|
2020-11-11 10:54:46 +03:00
|
|
|
{
|
|
|
|
contactPoint->active = FALSE;
|
|
|
|
contactPoint->externalId = 0;
|
|
|
|
contactPoint->contactId = 0;
|
2013-06-12 00:15:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
if (frame.contactCount > 0)
|
|
|
|
{
|
|
|
|
UINT error = rdpei_send_frame(context, &frame);
|
|
|
|
if (error != CHANNEL_RC_OK)
|
|
|
|
{
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(rdpei->base.log, WLOG_ERROR,
|
|
|
|
"rdpei_send_frame failed with error %" PRIu32 "!", error);
|
2020-11-11 10:54:46 +03:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
2015-06-09 13:46:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-06-12 00:15:46 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2022-06-14 01:51:00 +03:00
|
|
|
static UINT rdpei_send_pdu(GENERIC_CHANNEL_CALLBACK* callback, wStream* s, UINT16 eventId,
|
2024-10-14 16:50:38 +03:00
|
|
|
size_t pduLength)
|
2013-05-09 08:21:33 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT status = 0;
|
2021-06-21 14:59:41 +03:00
|
|
|
|
2024-09-25 13:41:19 +03:00
|
|
|
if (!callback || !s || !callback->channel || !callback->channel->Write)
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
2024-10-14 16:50:38 +03:00
|
|
|
if (pduLength > UINT32_MAX)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2024-09-25 13:41:19 +03:00
|
|
|
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*)callback->plugin;
|
|
|
|
if (!rdpei)
|
2020-11-11 10:54:46 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
2013-05-09 08:21:33 +04:00
|
|
|
Stream_SetPosition(s, 0);
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, eventId); /* eventId (2 bytes) */
|
2024-10-14 16:50:38 +03:00
|
|
|
Stream_Write_UINT32(s, (UINT32)pduLength); /* pduLength (4 bytes) */
|
2013-05-09 08:21:33 +04:00
|
|
|
Stream_SetPosition(s, Stream_Length(s));
|
2019-11-06 17:24:51 +03:00
|
|
|
status = callback->channel->Write(callback->channel, (UINT32)Stream_Length(s), Stream_Buffer(s),
|
|
|
|
NULL);
|
2013-05-15 03:26:01 +04:00
|
|
|
#ifdef WITH_DEBUG_RDPEI
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(rdpei->base.log, WLOG_DEBUG,
|
|
|
|
"rdpei_send_pdu: eventId: %" PRIu16 " (%s) length: %" PRIu32 " status: %" PRIu32 "",
|
|
|
|
eventId, rdpei_eventid_string(eventId), pduLength, status);
|
2013-05-15 03:26:01 +04:00
|
|
|
#endif
|
2013-05-09 08:21:33 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
static UINT rdpei_write_pen_frame(wStream* s, const RDPINPUT_PEN_FRAME* frame)
|
|
|
|
{
|
|
|
|
if (!s || !frame)
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
|
|
|
if (!rdpei_write_2byte_unsigned(s, frame->contactCount))
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
if (!rdpei_write_8byte_unsigned(s, frame->frameOffset))
|
|
|
|
return ERROR_OUTOFMEMORY;
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT16 x = 0; x < frame->contactCount; x++)
|
2020-11-11 10:54:46 +03:00
|
|
|
{
|
|
|
|
const RDPINPUT_PEN_CONTACT* contact = &frame->contacts[x];
|
|
|
|
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 1))
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
Stream_Write_UINT8(s, contact->deviceId);
|
|
|
|
if (!rdpei_write_2byte_unsigned(s, contact->fieldsPresent))
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
if (!rdpei_write_4byte_signed(s, contact->x))
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
if (!rdpei_write_4byte_signed(s, contact->y))
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
if (!rdpei_write_4byte_unsigned(s, contact->contactFlags))
|
|
|
|
return ERROR_OUTOFMEMORY;
|
2020-11-30 15:40:15 +03:00
|
|
|
if (contact->fieldsPresent & RDPINPUT_PEN_CONTACT_PENFLAGS_PRESENT)
|
2020-11-11 10:54:46 +03:00
|
|
|
{
|
|
|
|
if (!rdpei_write_4byte_unsigned(s, contact->penFlags))
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
2020-11-30 15:40:15 +03:00
|
|
|
if (contact->fieldsPresent & RDPINPUT_PEN_CONTACT_PRESSURE_PRESENT)
|
2020-11-11 10:54:46 +03:00
|
|
|
{
|
|
|
|
if (!rdpei_write_4byte_unsigned(s, contact->pressure))
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
2020-11-30 15:40:15 +03:00
|
|
|
if (contact->fieldsPresent & RDPINPUT_PEN_CONTACT_ROTATION_PRESENT)
|
2020-11-11 10:54:46 +03:00
|
|
|
{
|
|
|
|
if (!rdpei_write_2byte_unsigned(s, contact->rotation))
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
2020-11-30 15:40:15 +03:00
|
|
|
if (contact->fieldsPresent & RDPINPUT_PEN_CONTACT_TILTX_PRESENT)
|
2020-11-11 10:54:46 +03:00
|
|
|
{
|
|
|
|
if (!rdpei_write_2byte_signed(s, contact->tiltX))
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
2020-11-30 15:40:15 +03:00
|
|
|
if (contact->fieldsPresent & RDPINPUT_PEN_CONTACT_TILTY_PRESENT)
|
2020-11-11 10:54:46 +03:00
|
|
|
{
|
|
|
|
if (!rdpei_write_2byte_signed(s, contact->tiltY))
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return CHANNEL_RC_OK;
|
|
|
|
}
|
|
|
|
|
2024-10-14 16:50:38 +03:00
|
|
|
static UINT rdpei_send_pen_event_pdu(GENERIC_CHANNEL_CALLBACK* callback, size_t frameOffset,
|
|
|
|
const RDPINPUT_PEN_FRAME* frames, size_t count)
|
2020-11-11 10:54:46 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT status = 0;
|
|
|
|
wStream* s = NULL;
|
2020-11-11 10:54:46 +03:00
|
|
|
|
2024-09-25 13:41:19 +03:00
|
|
|
WINPR_ASSERT(callback);
|
|
|
|
|
2024-10-14 16:50:38 +03:00
|
|
|
if (frameOffset > UINT32_MAX)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
if (count > UINT16_MAX)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2024-09-25 13:41:19 +03:00
|
|
|
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*)callback->plugin;
|
|
|
|
if (!rdpei)
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
if (!frames || (count == 0))
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
|
|
|
s = Stream_New(NULL, 64);
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
{
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(rdpei->base.log, WLOG_ERROR, "Stream_New failed!");
|
2020-11-11 10:54:46 +03:00
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Seek(s, RDPINPUT_HEADER_LENGTH);
|
|
|
|
/**
|
|
|
|
* the time that has elapsed (in milliseconds) from when the oldest touch frame
|
|
|
|
* was generated to when it was encoded for transmission by the client.
|
|
|
|
*/
|
2024-10-14 16:50:38 +03:00
|
|
|
rdpei_write_4byte_unsigned(s,
|
|
|
|
(UINT32)frameOffset); /* encodeTime (FOUR_BYTE_UNSIGNED_INTEGER) */
|
|
|
|
rdpei_write_2byte_unsigned(s, (UINT16)count); /* (frameCount) TWO_BYTE_UNSIGNED_INTEGER */
|
2020-11-11 10:54:46 +03:00
|
|
|
|
2024-10-14 16:50:38 +03:00
|
|
|
for (size_t x = 0; x < count; x++)
|
2020-11-11 10:54:46 +03:00
|
|
|
{
|
|
|
|
if ((status = rdpei_write_pen_frame(s, &frames[x])))
|
|
|
|
{
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(rdpei->base.log, WLOG_ERROR,
|
|
|
|
"rdpei_write_pen_frame failed with error %" PRIu32 "!", status);
|
2020-11-11 10:54:46 +03:00
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Stream_SealLength(s);
|
|
|
|
|
|
|
|
status = rdpei_send_pdu(callback, s, EVENTID_PEN, Stream_Length(s));
|
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT rdpei_send_pen_frame(RdpeiClientContext* context, RDPINPUT_PEN_FRAME* frame)
|
|
|
|
{
|
|
|
|
const UINT64 currentTime = GetTickCount64();
|
2024-01-23 18:49:54 +03:00
|
|
|
RDPEI_PLUGIN* rdpei = NULL;
|
|
|
|
GENERIC_CHANNEL_CALLBACK* callback = NULL;
|
|
|
|
UINT error = 0;
|
2020-11-11 10:54:46 +03:00
|
|
|
|
|
|
|
if (!context)
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
rdpei = (RDPEI_PLUGIN*)context->handle;
|
2022-06-21 09:09:00 +03:00
|
|
|
if (!rdpei || !rdpei->base.listener_callback)
|
2020-11-11 10:54:46 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2021-06-21 14:59:41 +03:00
|
|
|
if (!rdpei || !rdpei->rdpcontext)
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
if (freerdp_settings_get_bool(rdpei->rdpcontext->settings, FreeRDP_SuspendInput))
|
|
|
|
return CHANNEL_RC_OK;
|
2020-11-11 10:54:46 +03:00
|
|
|
|
2022-06-21 09:09:00 +03:00
|
|
|
callback = rdpei->base.listener_callback->channel_callback;
|
2021-05-31 11:08:50 +03:00
|
|
|
/* Just ignore the event if the channel is not connected */
|
|
|
|
if (!callback)
|
|
|
|
return CHANNEL_RC_OK;
|
2020-11-11 10:54:46 +03:00
|
|
|
|
|
|
|
if (!rdpei->previousPenFrameTime && !rdpei->currentPenFrameTime)
|
|
|
|
{
|
|
|
|
rdpei->currentPenFrameTime = currentTime;
|
|
|
|
frame->frameOffset = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rdpei->currentPenFrameTime = currentTime;
|
|
|
|
frame->frameOffset = rdpei->currentPenFrameTime - rdpei->previousPenFrameTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((error = rdpei_send_pen_event_pdu(callback, frame->frameOffset, frame, 1)))
|
|
|
|
return error;
|
|
|
|
|
|
|
|
rdpei->previousPenFrameTime = rdpei->currentPenFrameTime;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT rdpei_add_pen_frame(RdpeiClientContext* context)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
RDPEI_PLUGIN* rdpei = NULL;
|
2020-11-11 10:54:46 +03:00
|
|
|
RDPINPUT_PEN_FRAME penFrame = { 0 };
|
|
|
|
RDPINPUT_PEN_CONTACT penContacts[MAX_PEN_CONTACTS] = { 0 };
|
|
|
|
|
|
|
|
if (!context || !context->handle)
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
|
|
|
rdpei = (RDPEI_PLUGIN*)context->handle;
|
|
|
|
|
|
|
|
penFrame.contacts = penContacts;
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT16 i = 0; i < rdpei->maxPenContacts; i++)
|
2020-11-11 10:54:46 +03:00
|
|
|
{
|
|
|
|
RDPINPUT_PEN_CONTACT_POINT* contact = &(rdpei->penContactPoints[i]);
|
|
|
|
|
|
|
|
if (contact->dirty)
|
|
|
|
{
|
|
|
|
penContacts[penFrame.contactCount++] = contact->data;
|
|
|
|
contact->dirty = FALSE;
|
|
|
|
}
|
|
|
|
else if (contact->active)
|
|
|
|
{
|
2020-11-30 15:40:15 +03:00
|
|
|
if (contact->data.contactFlags & RDPINPUT_CONTACT_FLAG_DOWN)
|
2020-11-11 10:54:46 +03:00
|
|
|
{
|
2020-11-30 15:40:15 +03:00
|
|
|
contact->data.contactFlags = RDPINPUT_CONTACT_FLAG_UPDATE;
|
|
|
|
contact->data.contactFlags |= RDPINPUT_CONTACT_FLAG_INRANGE;
|
|
|
|
contact->data.contactFlags |= RDPINPUT_CONTACT_FLAG_INCONTACT;
|
2020-11-11 10:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
penContacts[penFrame.contactCount++] = contact->data;
|
|
|
|
}
|
2023-06-21 09:57:47 +03:00
|
|
|
if (contact->data.contactFlags & RDPINPUT_CONTACT_FLAG_CANCELED)
|
2020-11-11 10:54:46 +03:00
|
|
|
{
|
|
|
|
contact->externalId = 0;
|
|
|
|
contact->active = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (penFrame.contactCount > 0)
|
|
|
|
return rdpei_send_pen_frame(context, &penFrame);
|
|
|
|
return CHANNEL_RC_OK;
|
|
|
|
}
|
|
|
|
|
2024-09-25 13:41:19 +03:00
|
|
|
static UINT rdpei_update(wLog* log, RdpeiClientContext* context)
|
2020-11-11 10:54:46 +03:00
|
|
|
{
|
|
|
|
UINT error = rdpei_add_frame(context);
|
|
|
|
if (error != CHANNEL_RC_OK)
|
|
|
|
{
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(log, WLOG_ERROR, "rdpei_add_frame failed with error %" PRIu32 "!", error);
|
2020-11-11 10:54:46 +03:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rdpei_add_pen_frame(context);
|
|
|
|
}
|
|
|
|
|
2024-09-25 13:41:19 +03:00
|
|
|
static BOOL rdpei_poll_run_unlocked(rdpContext* context, void* userdata)
|
|
|
|
{
|
|
|
|
RDPEI_PLUGIN* rdpei = userdata;
|
|
|
|
WINPR_ASSERT(rdpei);
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
|
|
|
|
const UINT64 now = GetTickCount64();
|
|
|
|
|
|
|
|
/* Send an event every ~20ms */
|
|
|
|
if ((now < rdpei->lastPollEventTime) || (now - rdpei->lastPollEventTime < 20ULL))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
rdpei->lastPollEventTime = now;
|
|
|
|
|
|
|
|
const UINT error = rdpei_update(rdpei->base.log, rdpei->context);
|
|
|
|
|
|
|
|
(void)ResetEvent(rdpei->event);
|
|
|
|
|
|
|
|
if (error != CHANNEL_RC_OK)
|
|
|
|
{
|
|
|
|
WLog_Print(rdpei->base.log, WLOG_ERROR, "rdpei_add_frame failed with error %" PRIu32 "!",
|
|
|
|
error);
|
|
|
|
setChannelError(context, error, "rdpei_add_frame reported an error");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL rdpei_poll_run(rdpContext* context, void* userdata)
|
|
|
|
{
|
|
|
|
RDPEI_PLUGIN* rdpei = userdata;
|
|
|
|
WINPR_ASSERT(rdpei);
|
|
|
|
|
|
|
|
EnterCriticalSection(&rdpei->lock);
|
|
|
|
BOOL rc = rdpei_poll_run_unlocked(context, userdata);
|
|
|
|
LeaveCriticalSection(&rdpei->lock);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
static DWORD WINAPI rdpei_periodic_update(LPVOID arg)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
DWORD status = 0;
|
2020-11-11 10:54:46 +03:00
|
|
|
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*)arg;
|
|
|
|
UINT error = CHANNEL_RC_OK;
|
2024-01-23 18:49:54 +03:00
|
|
|
RdpeiClientContext* context = NULL;
|
2020-11-11 10:54:46 +03:00
|
|
|
|
|
|
|
if (!rdpei)
|
|
|
|
{
|
|
|
|
error = ERROR_INVALID_PARAMETER;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2022-06-21 09:09:00 +03:00
|
|
|
context = rdpei->context;
|
2020-11-11 10:54:46 +03:00
|
|
|
|
|
|
|
if (!context)
|
|
|
|
{
|
|
|
|
error = ERROR_INVALID_PARAMETER;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2022-09-12 22:28:31 +03:00
|
|
|
while (rdpei->running)
|
2020-11-11 10:54:46 +03:00
|
|
|
{
|
|
|
|
status = WaitForSingleObject(rdpei->event, 20);
|
|
|
|
|
|
|
|
if (status == WAIT_FAILED)
|
|
|
|
{
|
|
|
|
error = GetLastError();
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(rdpei->base.log, WLOG_ERROR,
|
|
|
|
"WaitForMultipleObjects failed with error %" PRIu32 "!", error);
|
2020-11-11 10:54:46 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-09-25 13:41:19 +03:00
|
|
|
error = rdpei_poll_run(rdpei->rdpcontext, rdpei);
|
2020-11-11 10:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
|
|
|
if (error && rdpei && rdpei->rdpcontext)
|
|
|
|
setChannelError(rdpei->rdpcontext, error, "rdpei_schedule_thread reported an error");
|
|
|
|
|
2022-09-12 22:28:31 +03:00
|
|
|
if (rdpei)
|
|
|
|
rdpei->running = FALSE;
|
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
ExitThread(error);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2022-06-14 01:51:00 +03:00
|
|
|
static UINT rdpei_send_cs_ready_pdu(GENERIC_CHANNEL_CALLBACK* callback)
|
2013-05-09 08:21:33 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT status = 0;
|
|
|
|
wStream* s = NULL;
|
2021-05-20 15:11:43 +03:00
|
|
|
UINT32 flags = 0;
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 pduLength = 0;
|
|
|
|
RDPEI_PLUGIN* rdpei = NULL;
|
2020-11-11 10:54:46 +03:00
|
|
|
|
|
|
|
if (!callback || !callback->plugin)
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
rdpei = (RDPEI_PLUGIN*)callback->plugin;
|
2021-05-20 15:11:43 +03:00
|
|
|
|
|
|
|
flags |= CS_READY_FLAGS_SHOW_TOUCH_VISUALS & rdpei->context->clientFeaturesMask;
|
2020-11-11 10:54:46 +03:00
|
|
|
if (rdpei->version > RDPINPUT_PROTOCOL_V10)
|
2021-05-20 15:11:43 +03:00
|
|
|
flags |= CS_READY_FLAGS_DISABLE_TIMESTAMP_INJECTION & rdpei->context->clientFeaturesMask;
|
|
|
|
if (rdpei->features & SC_READY_MULTIPEN_INJECTION_SUPPORTED)
|
|
|
|
flags |= CS_READY_FLAGS_ENABLE_MULTIPEN_INJECTION & rdpei->context->clientFeaturesMask;
|
|
|
|
|
2013-05-09 08:21:33 +04:00
|
|
|
pduLength = RDPINPUT_HEADER_LENGTH + 10;
|
|
|
|
s = Stream_New(NULL, pduLength);
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2015-06-09 13:46:10 +03:00
|
|
|
if (!s)
|
|
|
|
{
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(rdpei->base.log, WLOG_ERROR, "Stream_New failed!");
|
2015-06-09 13:46:10 +03:00
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2013-05-09 08:21:33 +04:00
|
|
|
|
2016-09-26 13:12:37 +03:00
|
|
|
Stream_Seek(s, RDPINPUT_HEADER_LENGTH);
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT32(s, flags); /* flags (4 bytes) */
|
2020-11-11 10:54:46 +03:00
|
|
|
Stream_Write_UINT32(s, rdpei->version); /* protocolVersion (4 bytes) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, rdpei->maxTouchContacts); /* maxTouchContacts (2 bytes) */
|
2013-05-09 08:21:33 +04:00
|
|
|
Stream_SealLength(s);
|
|
|
|
status = rdpei_send_pdu(callback, s, EVENTID_CS_READY, pduLength);
|
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2024-09-25 13:41:19 +03:00
|
|
|
#if defined(WITH_DEBUG_RDPEI)
|
|
|
|
static void rdpei_print_contact_flags(wLog* log, UINT32 contactFlags)
|
2013-05-15 01:45:52 +04:00
|
|
|
{
|
2020-11-30 15:40:15 +03:00
|
|
|
if (contactFlags & RDPINPUT_CONTACT_FLAG_DOWN)
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(log, WLOG_DEBUG, " RDPINPUT_CONTACT_FLAG_DOWN");
|
2014-09-12 18:19:32 +04:00
|
|
|
|
2020-11-30 15:40:15 +03:00
|
|
|
if (contactFlags & RDPINPUT_CONTACT_FLAG_UPDATE)
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(log, WLOG_DEBUG, " RDPINPUT_CONTACT_FLAG_UPDATE");
|
2014-09-12 18:19:32 +04:00
|
|
|
|
2020-11-30 15:40:15 +03:00
|
|
|
if (contactFlags & RDPINPUT_CONTACT_FLAG_UP)
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(log, WLOG_DEBUG, " RDPINPUT_CONTACT_FLAG_UP");
|
2014-09-12 18:19:32 +04:00
|
|
|
|
2020-11-30 15:40:15 +03:00
|
|
|
if (contactFlags & RDPINPUT_CONTACT_FLAG_INRANGE)
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(log, WLOG_DEBUG, " RDPINPUT_CONTACT_FLAG_INRANGE");
|
2014-09-12 18:19:32 +04:00
|
|
|
|
2020-11-30 15:40:15 +03:00
|
|
|
if (contactFlags & RDPINPUT_CONTACT_FLAG_INCONTACT)
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(log, WLOG_DEBUG, " RDPINPUT_CONTACT_FLAG_INCONTACT");
|
2014-09-12 18:19:32 +04:00
|
|
|
|
2020-11-30 15:40:15 +03:00
|
|
|
if (contactFlags & RDPINPUT_CONTACT_FLAG_CANCELED)
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(log, WLOG_DEBUG, " RDPINPUT_CONTACT_FLAG_CANCELED");
|
2013-05-15 01:45:52 +04:00
|
|
|
}
|
2024-09-25 13:41:19 +03:00
|
|
|
#endif
|
2013-05-15 01:45:52 +04:00
|
|
|
|
2024-08-29 16:10:27 +03:00
|
|
|
static INT16 bounded(INT32 val)
|
|
|
|
{
|
|
|
|
if (val < INT16_MIN)
|
|
|
|
return INT16_MIN;
|
|
|
|
if (val > INT16_MAX)
|
|
|
|
return INT16_MAX;
|
|
|
|
return (INT16)val;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2024-09-25 13:41:19 +03:00
|
|
|
static UINT rdpei_write_touch_frame(wLog* log, wStream* s, RDPINPUT_TOUCH_FRAME* frame)
|
2013-05-09 08:21:33 +04:00
|
|
|
{
|
2013-07-11 22:04:20 +04:00
|
|
|
int rectSize = 2;
|
2024-01-23 18:49:54 +03:00
|
|
|
RDPINPUT_CONTACT_DATA* contact = NULL;
|
2020-11-11 10:54:46 +03:00
|
|
|
if (!s || !frame)
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
2013-05-15 03:26:01 +04:00
|
|
|
#ifdef WITH_DEBUG_RDPEI
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(log, WLOG_DEBUG, "contactCount: %" PRIu32 "", frame->contactCount);
|
|
|
|
WLog_Print(log, WLOG_DEBUG, "frameOffset: 0x%016" PRIX64 "", frame->frameOffset);
|
2013-05-15 03:26:01 +04:00
|
|
|
#endif
|
2016-09-26 13:12:37 +03:00
|
|
|
rdpei_write_2byte_unsigned(s,
|
|
|
|
frame->contactCount); /* contactCount (TWO_BYTE_UNSIGNED_INTEGER) */
|
2013-06-12 00:15:46 +04:00
|
|
|
/**
|
|
|
|
* the time offset from the previous frame (in microseconds).
|
|
|
|
* If this is the first frame being transmitted then this field MUST be set to zero.
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
rdpei_write_8byte_unsigned(s, frame->frameOffset *
|
|
|
|
1000); /* frameOffset (EIGHT_BYTE_UNSIGNED_INTEGER) */
|
2013-05-09 08:21:33 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, (size_t)frame->contactCount * 64))
|
2015-06-09 13:46:10 +03:00
|
|
|
{
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(log, WLOG_ERROR, "Stream_EnsureRemainingCapacity failed!");
|
2015-06-09 13:46:10 +03:00
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2013-05-09 08:21:33 +04:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 index = 0; index < frame->contactCount; index++)
|
2013-05-09 08:21:33 +04:00
|
|
|
{
|
|
|
|
contact = &frame->contacts[index];
|
2013-07-11 22:04:20 +04:00
|
|
|
contact->fieldsPresent |= CONTACT_DATA_CONTACTRECT_PRESENT;
|
2024-08-29 16:10:27 +03:00
|
|
|
contact->contactRectLeft = bounded(contact->x - rectSize);
|
|
|
|
contact->contactRectTop = bounded(contact->y - rectSize);
|
|
|
|
contact->contactRectRight = bounded(contact->x + rectSize);
|
|
|
|
contact->contactRectBottom = bounded(contact->y + rectSize);
|
2013-05-15 03:26:01 +04:00
|
|
|
#ifdef WITH_DEBUG_RDPEI
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(log, WLOG_DEBUG, "contact[%" PRIu32 "].contactId: %" PRIu32 "", index,
|
|
|
|
contact->contactId);
|
|
|
|
WLog_Print(log, WLOG_DEBUG, "contact[%" PRIu32 "].fieldsPresent: %" PRIu32 "", index,
|
|
|
|
contact->fieldsPresent);
|
|
|
|
WLog_Print(log, WLOG_DEBUG, "contact[%" PRIu32 "].x: %" PRId32 "", index, contact->x);
|
|
|
|
WLog_Print(log, WLOG_DEBUG, "contact[%" PRIu32 "].y: %" PRId32 "", index, contact->y);
|
|
|
|
WLog_Print(log, WLOG_DEBUG, "contact[%" PRIu32 "].contactFlags: 0x%08" PRIX32 "", index,
|
|
|
|
contact->contactFlags);
|
|
|
|
rdpei_print_contact_flags(log, contact->contactFlags);
|
2013-05-15 03:26:01 +04:00
|
|
|
#endif
|
2013-05-14 09:06:25 +04:00
|
|
|
Stream_Write_UINT8(s, contact->contactId); /* contactId (1 byte) */
|
|
|
|
/* fieldsPresent (TWO_BYTE_UNSIGNED_INTEGER) */
|
2013-05-09 08:21:33 +04:00
|
|
|
rdpei_write_2byte_unsigned(s, contact->fieldsPresent);
|
2013-05-14 09:06:25 +04:00
|
|
|
rdpei_write_4byte_signed(s, contact->x); /* x (FOUR_BYTE_SIGNED_INTEGER) */
|
|
|
|
rdpei_write_4byte_signed(s, contact->y); /* y (FOUR_BYTE_SIGNED_INTEGER) */
|
|
|
|
/* contactFlags (FOUR_BYTE_UNSIGNED_INTEGER) */
|
2013-05-09 08:21:33 +04:00
|
|
|
rdpei_write_4byte_unsigned(s, contact->contactFlags);
|
|
|
|
|
|
|
|
if (contact->fieldsPresent & CONTACT_DATA_CONTACTRECT_PRESENT)
|
|
|
|
{
|
2013-05-14 09:06:25 +04:00
|
|
|
/* contactRectLeft (TWO_BYTE_SIGNED_INTEGER) */
|
2013-05-09 08:21:33 +04:00
|
|
|
rdpei_write_2byte_signed(s, contact->contactRectLeft);
|
2013-05-14 09:06:25 +04:00
|
|
|
/* contactRectTop (TWO_BYTE_SIGNED_INTEGER) */
|
2013-05-09 08:21:33 +04:00
|
|
|
rdpei_write_2byte_signed(s, contact->contactRectTop);
|
2013-05-14 09:06:25 +04:00
|
|
|
/* contactRectRight (TWO_BYTE_SIGNED_INTEGER) */
|
2013-05-09 08:21:33 +04:00
|
|
|
rdpei_write_2byte_signed(s, contact->contactRectRight);
|
2013-05-14 09:06:25 +04:00
|
|
|
/* contactRectBottom (TWO_BYTE_SIGNED_INTEGER) */
|
2013-05-09 08:21:33 +04:00
|
|
|
rdpei_write_2byte_signed(s, contact->contactRectBottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (contact->fieldsPresent & CONTACT_DATA_ORIENTATION_PRESENT)
|
|
|
|
{
|
2013-05-14 09:06:25 +04:00
|
|
|
/* orientation (FOUR_BYTE_UNSIGNED_INTEGER) */
|
2013-05-09 08:21:33 +04:00
|
|
|
rdpei_write_4byte_unsigned(s, contact->orientation);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (contact->fieldsPresent & CONTACT_DATA_PRESSURE_PRESENT)
|
|
|
|
{
|
2013-05-14 09:06:25 +04:00
|
|
|
/* pressure (FOUR_BYTE_UNSIGNED_INTEGER) */
|
2013-05-09 08:21:33 +04:00
|
|
|
rdpei_write_4byte_unsigned(s, contact->pressure);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-09 13:46:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-05-09 08:21:33 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2022-06-14 01:51:00 +03:00
|
|
|
static UINT rdpei_send_touch_event_pdu(GENERIC_CHANNEL_CALLBACK* callback,
|
2019-11-20 13:30:14 +03:00
|
|
|
RDPINPUT_TOUCH_FRAME* frame)
|
2013-05-09 08:21:33 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT status = 0;
|
2022-01-13 11:22:24 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(callback);
|
|
|
|
|
2024-10-14 16:50:38 +03:00
|
|
|
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*)callback->plugin;
|
2021-06-21 14:59:41 +03:00
|
|
|
if (!rdpei || !rdpei->rdpcontext)
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
if (freerdp_settings_get_bool(rdpei->rdpcontext->settings, FreeRDP_SuspendInput))
|
|
|
|
return CHANNEL_RC_OK;
|
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
if (!frame)
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
2021-06-21 14:59:41 +03:00
|
|
|
|
2024-10-14 16:50:38 +03:00
|
|
|
size_t pduLength = 64ULL + (64ULL * frame->contactCount);
|
|
|
|
wStream* s = Stream_New(NULL, pduLength);
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2015-06-09 13:46:10 +03:00
|
|
|
if (!s)
|
|
|
|
{
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(rdpei->base.log, WLOG_ERROR, "Stream_New failed!");
|
2015-06-09 13:46:10 +03:00
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2013-05-09 08:21:33 +04:00
|
|
|
|
2016-09-26 13:12:37 +03:00
|
|
|
Stream_Seek(s, RDPINPUT_HEADER_LENGTH);
|
2013-06-12 00:15:46 +04:00
|
|
|
/**
|
|
|
|
* the time that has elapsed (in milliseconds) from when the oldest touch frame
|
|
|
|
* was generated to when it was encoded for transmission by the client.
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
rdpei_write_4byte_unsigned(
|
|
|
|
s, (UINT32)frame->frameOffset); /* encodeTime (FOUR_BYTE_UNSIGNED_INTEGER) */
|
|
|
|
rdpei_write_2byte_unsigned(s, 1); /* (frameCount) TWO_BYTE_UNSIGNED_INTEGER */
|
2013-05-09 08:21:33 +04:00
|
|
|
|
2024-09-25 13:41:19 +03:00
|
|
|
status = rdpei_write_touch_frame(rdpei->base.log, s, frame);
|
|
|
|
if (status)
|
2015-06-09 13:46:10 +03:00
|
|
|
{
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(rdpei->base.log, WLOG_ERROR,
|
|
|
|
"rdpei_write_touch_frame failed with error %" PRIu32 "!", status);
|
2015-06-09 13:46:10 +03:00
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
return status;
|
|
|
|
}
|
2013-05-09 08:21:33 +04:00
|
|
|
|
|
|
|
Stream_SealLength(s);
|
2024-10-14 16:50:38 +03:00
|
|
|
status = rdpei_send_pdu(callback, s, EVENTID_TOUCH, Stream_Length(s));
|
2013-05-09 08:21:33 +04:00
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2022-06-14 01:51:00 +03:00
|
|
|
static UINT rdpei_recv_sc_ready_pdu(GENERIC_CHANNEL_CALLBACK* callback, wStream* s)
|
2013-05-09 07:18:42 +04:00
|
|
|
{
|
2020-11-11 10:54:46 +03:00
|
|
|
UINT32 features = 0;
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 protocolVersion = 0;
|
2020-11-11 10:54:46 +03:00
|
|
|
|
|
|
|
if (!callback || !callback->plugin)
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
2024-09-25 13:41:19 +03:00
|
|
|
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*)callback->plugin;
|
2020-11-11 10:54:46 +03:00
|
|
|
|
2024-09-25 13:41:19 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(rdpei->base.log, s, 4))
|
2020-11-11 10:54:46 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2013-05-09 07:18:42 +04:00
|
|
|
Stream_Read_UINT32(s, protocolVersion); /* protocolVersion (4 bytes) */
|
2020-11-11 10:54:46 +03:00
|
|
|
|
|
|
|
if (protocolVersion >= RDPINPUT_PROTOCOL_V300)
|
|
|
|
{
|
2024-09-25 13:41:19 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(rdpei->base.log, s, 4))
|
2020-11-11 10:54:46 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2021-05-20 15:11:43 +03:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (Stream_GetRemainingLength(s) >= 4)
|
2020-11-11 10:54:46 +03:00
|
|
|
Stream_Read_UINT32(s, features);
|
|
|
|
|
|
|
|
if (rdpei->version > protocolVersion)
|
|
|
|
rdpei->version = protocolVersion;
|
|
|
|
rdpei->features = features;
|
2013-07-11 22:04:20 +04:00
|
|
|
#if 0
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2013-07-11 22:04:20 +04:00
|
|
|
if (protocolVersion != RDPINPUT_PROTOCOL_V10)
|
2013-05-09 07:18:42 +04:00
|
|
|
{
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(rdpei->base.log, WLOG_ERROR, "Unknown [MS-RDPEI] protocolVersion: 0x%08"PRIX32"", protocolVersion);
|
2013-05-09 07:18:42 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-09-26 13:12:37 +03:00
|
|
|
#endif
|
2015-06-09 13:46:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-05-09 07:18:42 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2022-06-14 01:51:00 +03:00
|
|
|
static UINT rdpei_recv_suspend_touch_pdu(GENERIC_CHANNEL_CALLBACK* callback, wStream* s)
|
2013-05-09 08:21:33 +04:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2020-11-11 10:54:46 +03:00
|
|
|
|
|
|
|
WINPR_UNUSED(s);
|
|
|
|
|
|
|
|
if (!callback || !callback->plugin)
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
2024-09-25 13:41:19 +03:00
|
|
|
|
|
|
|
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*)callback->plugin;
|
|
|
|
RdpeiClientContext* context = rdpei->context;
|
2020-11-11 10:54:46 +03:00
|
|
|
if (!rdpei)
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
2024-09-25 13:41:19 +03:00
|
|
|
IFCALLRET(context->SuspendTouch, error, context);
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2015-06-09 13:46:10 +03:00
|
|
|
if (error)
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(rdpei->base.log, WLOG_ERROR,
|
|
|
|
"rdpei->SuspendTouch failed with error %" PRIu32 "!", error);
|
2014-02-07 22:16:41 +04:00
|
|
|
|
2015-06-09 13:46:10 +03:00
|
|
|
return error;
|
2013-05-09 08:21:33 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2022-06-14 01:51:00 +03:00
|
|
|
static UINT rdpei_recv_resume_touch_pdu(GENERIC_CHANNEL_CALLBACK* callback, wStream* s)
|
2013-05-09 08:21:33 +04:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2024-09-25 13:41:19 +03:00
|
|
|
if (!s || !callback)
|
2020-11-11 10:54:46 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2024-09-25 13:41:19 +03:00
|
|
|
|
|
|
|
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*)callback->plugin;
|
2020-11-11 10:54:46 +03:00
|
|
|
if (!rdpei)
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
2024-09-25 13:41:19 +03:00
|
|
|
RdpeiClientContext* context = (RdpeiClientContext*)callback->plugin->pInterface;
|
|
|
|
if (!context)
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
|
|
|
IFCALLRET(context->ResumeTouch, error, context);
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2015-06-09 13:46:10 +03:00
|
|
|
if (error)
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(rdpei->base.log, WLOG_ERROR, "rdpei->ResumeTouch failed with error %" PRIu32 "!",
|
|
|
|
error);
|
2014-02-07 22:16:41 +04:00
|
|
|
|
2015-06-09 13:46:10 +03:00
|
|
|
return error;
|
2013-05-09 08:21:33 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2022-06-14 01:51:00 +03:00
|
|
|
static UINT rdpei_recv_pdu(GENERIC_CHANNEL_CALLBACK* callback, wStream* s)
|
2013-05-09 07:18:42 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT16 eventId = 0;
|
|
|
|
UINT32 pduLength = 0;
|
|
|
|
UINT error = 0;
|
2022-06-21 09:09:00 +03:00
|
|
|
|
2024-09-25 13:41:19 +03:00
|
|
|
if (!callback || !s)
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
|
|
|
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*)callback->plugin;
|
|
|
|
if (!rdpei)
|
2020-11-11 10:54:46 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2022-06-21 09:09:00 +03:00
|
|
|
|
2024-09-25 13:41:19 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(rdpei->base.log, s, 6))
|
2020-04-15 18:21:46 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT16(s, eventId); /* eventId (2 bytes) */
|
2013-05-09 07:18:42 +04:00
|
|
|
Stream_Read_UINT32(s, pduLength); /* pduLength (4 bytes) */
|
2013-05-15 03:26:01 +04:00
|
|
|
#ifdef WITH_DEBUG_RDPEI
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(rdpei->base.log, WLOG_DEBUG,
|
|
|
|
"rdpei_recv_pdu: eventId: %" PRIu16 " (%s) length: %" PRIu32 "", eventId,
|
|
|
|
rdpei_eventid_string(eventId), pduLength);
|
2013-05-15 03:26:01 +04:00
|
|
|
#endif
|
2013-05-09 07:18:42 +04:00
|
|
|
|
2024-09-25 13:41:19 +03:00
|
|
|
if ((pduLength < 6) || !Stream_CheckAndLogRequiredLengthWLog(rdpei->base.log, s, pduLength - 6))
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
2013-05-09 07:18:42 +04:00
|
|
|
switch (eventId)
|
|
|
|
{
|
|
|
|
case EVENTID_SC_READY:
|
2015-06-09 13:46:10 +03:00
|
|
|
if ((error = rdpei_recv_sc_ready_pdu(callback, s)))
|
|
|
|
{
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(rdpei->base.log, WLOG_ERROR,
|
|
|
|
"rdpei_recv_sc_ready_pdu failed with error %" PRIu32 "!", error);
|
2015-06-09 13:46:10 +03:00
|
|
|
return error;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2015-06-09 13:46:10 +03:00
|
|
|
if ((error = rdpei_send_cs_ready_pdu(callback)))
|
|
|
|
{
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(rdpei->base.log, WLOG_ERROR,
|
|
|
|
"rdpei_send_cs_ready_pdu failed with error %" PRIu32 "!", error);
|
2015-06-09 13:46:10 +03:00
|
|
|
return error;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2013-05-09 07:18:42 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EVENTID_SUSPEND_TOUCH:
|
2015-06-09 13:46:10 +03:00
|
|
|
if ((error = rdpei_recv_suspend_touch_pdu(callback, s)))
|
|
|
|
{
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(rdpei->base.log, WLOG_ERROR,
|
|
|
|
"rdpei_recv_suspend_touch_pdu failed with error %" PRIu32 "!", error);
|
2015-06-09 13:46:10 +03:00
|
|
|
return error;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2013-05-09 07:18:42 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EVENTID_RESUME_TOUCH:
|
2015-06-09 13:46:10 +03:00
|
|
|
if ((error = rdpei_recv_resume_touch_pdu(callback, s)))
|
|
|
|
{
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(rdpei->base.log, WLOG_ERROR,
|
|
|
|
"rdpei_recv_resume_touch_pdu failed with error %" PRIu32 "!", error);
|
2015-06-09 13:46:10 +03:00
|
|
|
return error;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2013-05-09 07:18:42 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-06-09 13:46:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-05-09 07:18:42 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT rdpei_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, wStream* data)
|
2013-03-20 00:52:07 +04:00
|
|
|
{
|
2022-06-23 08:57:38 +03:00
|
|
|
GENERIC_CHANNEL_CALLBACK* callback = (GENERIC_CHANNEL_CALLBACK*)pChannelCallback;
|
2019-11-06 17:24:51 +03:00
|
|
|
return rdpei_recv_pdu(callback, data);
|
2013-03-20 00:52:07 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT rdpei_on_close(IWTSVirtualChannelCallback* pChannelCallback)
|
2013-03-20 00:52:07 +04:00
|
|
|
{
|
2022-06-23 08:57:38 +03:00
|
|
|
GENERIC_CHANNEL_CALLBACK* callback = (GENERIC_CHANNEL_CALLBACK*)pChannelCallback;
|
2021-05-31 11:08:50 +03:00
|
|
|
if (callback)
|
|
|
|
{
|
|
|
|
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*)callback->plugin;
|
2022-06-21 09:09:00 +03:00
|
|
|
if (rdpei && rdpei->base.listener_callback)
|
2021-05-31 11:08:50 +03:00
|
|
|
{
|
2022-06-21 09:09:00 +03:00
|
|
|
if (rdpei->base.listener_callback->channel_callback == callback)
|
|
|
|
rdpei->base.listener_callback->channel_callback = NULL;
|
2021-05-31 11:08:50 +03:00
|
|
|
}
|
|
|
|
}
|
2013-03-20 00:52:07 +04:00
|
|
|
free(callback);
|
2015-06-09 13:46:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-03-20 00:52:07 +04:00
|
|
|
}
|
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
/**
|
|
|
|
* Channel Client Interface
|
|
|
|
*/
|
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
static UINT32 rdpei_get_version(RdpeiClientContext* context)
|
2013-05-14 00:07:42 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
RDPEI_PLUGIN* rdpei = NULL;
|
2020-11-11 10:54:46 +03:00
|
|
|
if (!context || !context->handle)
|
|
|
|
return -1;
|
|
|
|
rdpei = (RDPEI_PLUGIN*)context->handle;
|
2013-05-14 03:17:25 +04:00
|
|
|
return rdpei->version;
|
|
|
|
}
|
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
static UINT32 rdpei_get_features(RdpeiClientContext* context)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
RDPEI_PLUGIN* rdpei = NULL;
|
2020-11-11 10:54:46 +03:00
|
|
|
if (!context || !context->handle)
|
|
|
|
return -1;
|
|
|
|
rdpei = (RDPEI_PLUGIN*)context->handle;
|
|
|
|
return rdpei->features;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2020-11-11 10:54:46 +03:00
|
|
|
UINT rdpei_send_frame(RdpeiClientContext* context, RDPINPUT_TOUCH_FRAME* frame)
|
2013-05-14 03:17:25 +04:00
|
|
|
{
|
2021-05-31 11:08:50 +03:00
|
|
|
UINT64 currentTime = GetTickCount64();
|
2019-11-06 17:24:51 +03:00
|
|
|
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*)context->handle;
|
2024-01-23 18:49:54 +03:00
|
|
|
GENERIC_CHANNEL_CALLBACK* callback = NULL;
|
|
|
|
UINT error = 0;
|
2021-05-31 11:08:50 +03:00
|
|
|
|
2022-06-21 09:09:00 +03:00
|
|
|
callback = rdpei->base.listener_callback->channel_callback;
|
2021-05-31 11:08:50 +03:00
|
|
|
|
|
|
|
/* Just ignore the event if the channel is not connected */
|
|
|
|
if (!callback)
|
|
|
|
return CHANNEL_RC_OK;
|
2013-05-14 09:06:25 +04:00
|
|
|
|
2013-05-14 03:17:25 +04:00
|
|
|
if (!rdpei->previousFrameTime && !rdpei->currentFrameTime)
|
|
|
|
{
|
2013-05-15 03:26:01 +04:00
|
|
|
rdpei->currentFrameTime = currentTime;
|
2020-11-11 10:54:46 +03:00
|
|
|
frame->frameOffset = 0;
|
2013-05-14 03:17:25 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-15 03:26:01 +04:00
|
|
|
rdpei->currentFrameTime = currentTime;
|
2020-11-11 10:54:46 +03:00
|
|
|
frame->frameOffset = rdpei->currentFrameTime - rdpei->previousFrameTime;
|
2013-05-14 03:17:25 +04:00
|
|
|
}
|
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
if ((error = rdpei_send_touch_event_pdu(callback, frame)))
|
2015-06-09 13:46:10 +03:00
|
|
|
{
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(rdpei->base.log, WLOG_ERROR,
|
|
|
|
"rdpei_send_touch_event_pdu failed with error %" PRIu32 "!", error);
|
2015-06-09 13:46:10 +03:00
|
|
|
return error;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2013-05-14 03:17:25 +04:00
|
|
|
rdpei->previousFrameTime = rdpei->currentFrameTime;
|
2015-06-09 13:46:10 +03:00
|
|
|
return error;
|
2013-05-14 03:17:25 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-12-18 13:31:40 +03:00
|
|
|
static UINT rdpei_add_contact(RdpeiClientContext* context, const RDPINPUT_CONTACT_DATA* contact)
|
2013-05-14 03:17:25 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
RDPINPUT_CONTACT_POINT* contactPoint = NULL;
|
|
|
|
RDPEI_PLUGIN* rdpei = NULL;
|
2020-11-11 10:54:46 +03:00
|
|
|
if (!context || !contact || !context->handle)
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
2019-12-18 13:31:40 +03:00
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
rdpei = (RDPEI_PLUGIN*)context->handle;
|
2019-12-18 13:31:40 +03:00
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
EnterCriticalSection(&rdpei->lock);
|
|
|
|
contactPoint = &rdpei->contactPoints[contact->contactId];
|
|
|
|
contactPoint->data = *contact;
|
|
|
|
contactPoint->dirty = TRUE;
|
2024-09-16 05:50:45 +03:00
|
|
|
(void)SetEvent(rdpei->event);
|
2020-11-11 10:54:46 +03:00
|
|
|
LeaveCriticalSection(&rdpei->lock);
|
2019-12-18 13:31:40 +03:00
|
|
|
|
2015-06-09 13:46:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-05-15 01:45:52 +04:00
|
|
|
}
|
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
static UINT rdpei_touch_process(RdpeiClientContext* context, INT32 externalId, UINT32 contactFlags,
|
2021-05-20 15:11:43 +03:00
|
|
|
INT32 x, INT32 y, INT32* contactId, UINT32 fieldFlags, va_list ap)
|
2013-05-15 01:45:52 +04:00
|
|
|
{
|
2019-12-18 13:31:40 +03:00
|
|
|
INT64 contactIdlocal = -1;
|
2024-01-23 18:49:54 +03:00
|
|
|
RDPINPUT_CONTACT_POINT* contactPoint = NULL;
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2013-05-15 01:45:52 +04:00
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
if (!context || !contactId || !context->handle)
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
2013-06-07 02:14:59 +04:00
|
|
|
|
2024-08-29 16:10:27 +03:00
|
|
|
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*)context->handle;
|
2020-11-11 10:54:46 +03:00
|
|
|
/* Create a new contact point in an empty slot */
|
|
|
|
EnterCriticalSection(&rdpei->lock);
|
2024-08-29 16:10:27 +03:00
|
|
|
const BOOL begin = (contactFlags & RDPINPUT_CONTACT_FLAG_DOWN) != 0;
|
2020-11-11 10:54:46 +03:00
|
|
|
contactPoint = rdpei_contact(rdpei, externalId, !begin);
|
|
|
|
if (contactPoint)
|
|
|
|
contactIdlocal = contactPoint->contactId;
|
|
|
|
LeaveCriticalSection(&rdpei->lock);
|
2013-05-14 09:06:25 +04:00
|
|
|
|
2024-10-14 16:50:38 +03:00
|
|
|
if (contactIdlocal > UINT32_MAX)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2015-06-09 13:46:10 +03:00
|
|
|
if (contactIdlocal >= 0)
|
2013-06-07 02:14:59 +04:00
|
|
|
{
|
2020-11-11 10:54:46 +03:00
|
|
|
RDPINPUT_CONTACT_DATA contact = { 0 };
|
2013-06-07 02:14:59 +04:00
|
|
|
contact.x = x;
|
|
|
|
contact.y = y;
|
2024-10-14 16:50:38 +03:00
|
|
|
contact.contactId = (UINT32)contactIdlocal;
|
2020-11-11 10:54:46 +03:00
|
|
|
contact.contactFlags = contactFlags;
|
2021-05-20 15:11:43 +03:00
|
|
|
contact.fieldsPresent = fieldFlags;
|
|
|
|
|
|
|
|
if (fieldFlags & CONTACT_DATA_CONTACTRECT_PRESENT)
|
|
|
|
{
|
|
|
|
contact.contactRectLeft = va_arg(ap, INT32);
|
|
|
|
contact.contactRectTop = va_arg(ap, INT32);
|
|
|
|
contact.contactRectRight = va_arg(ap, INT32);
|
|
|
|
contact.contactRectBottom = va_arg(ap, INT32);
|
|
|
|
}
|
|
|
|
if (fieldFlags & CONTACT_DATA_ORIENTATION_PRESENT)
|
|
|
|
{
|
|
|
|
UINT32 p = va_arg(ap, UINT32);
|
|
|
|
if (p >= 360)
|
|
|
|
{
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(rdpei->base.log, WLOG_WARN,
|
|
|
|
"TouchContact %" PRId64 ": Invalid orientation value %" PRIu32
|
|
|
|
"degree, clamping to 359 degree",
|
|
|
|
contactIdlocal, p);
|
2021-05-20 15:11:43 +03:00
|
|
|
p = 359;
|
|
|
|
}
|
2021-06-01 17:15:41 +03:00
|
|
|
contact.orientation = p;
|
2021-05-20 15:11:43 +03:00
|
|
|
}
|
|
|
|
if (fieldFlags & CONTACT_DATA_PRESSURE_PRESENT)
|
|
|
|
{
|
|
|
|
UINT32 p = va_arg(ap, UINT32);
|
|
|
|
if (p > 1024)
|
|
|
|
{
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(rdpei->base.log, WLOG_WARN,
|
|
|
|
"TouchContact %" PRId64 ": Invalid pressure value %" PRIu32
|
|
|
|
", clamping to 1024",
|
|
|
|
contactIdlocal, p);
|
2021-05-20 15:11:43 +03:00
|
|
|
p = 1024;
|
|
|
|
}
|
|
|
|
contact.pressure = p;
|
|
|
|
}
|
|
|
|
|
2015-06-09 13:46:10 +03:00
|
|
|
error = context->AddContact(context, &contact);
|
2013-06-07 02:14:59 +04:00
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
if (contactId)
|
2024-08-29 17:13:43 +03:00
|
|
|
*contactId = (INT32)contactIdlocal;
|
2015-06-09 13:46:10 +03:00
|
|
|
return error;
|
2013-05-15 01:45:52 +04:00
|
|
|
}
|
2021-11-08 13:55:30 +03:00
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT rdpei_touch_begin(RdpeiClientContext* context, INT32 externalId, INT32 x, INT32 y,
|
|
|
|
INT32* contactId)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT rc = 0;
|
2021-06-16 15:33:26 +03:00
|
|
|
va_list ap = { 0 };
|
|
|
|
rc = rdpei_touch_process(context, externalId,
|
|
|
|
RDPINPUT_CONTACT_FLAG_DOWN | RDPINPUT_CONTACT_FLAG_INRANGE |
|
|
|
|
RDPINPUT_CONTACT_FLAG_INCONTACT,
|
|
|
|
x, y, contactId, 0, ap);
|
|
|
|
return rc;
|
2020-11-11 10:54:46 +03:00
|
|
|
}
|
2013-05-14 09:06:25 +04:00
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2020-11-11 10:54:46 +03:00
|
|
|
static UINT rdpei_touch_update(RdpeiClientContext* context, INT32 externalId, INT32 x, INT32 y,
|
|
|
|
INT32* contactId)
|
2013-05-15 01:45:52 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT rc = 0;
|
2021-06-16 15:33:26 +03:00
|
|
|
va_list ap = { 0 };
|
|
|
|
rc = rdpei_touch_process(context, externalId,
|
|
|
|
RDPINPUT_CONTACT_FLAG_UPDATE | RDPINPUT_CONTACT_FLAG_INRANGE |
|
|
|
|
RDPINPUT_CONTACT_FLAG_INCONTACT,
|
|
|
|
x, y, contactId, 0, ap);
|
|
|
|
return rc;
|
2020-11-11 10:54:46 +03:00
|
|
|
}
|
2013-05-14 09:06:25 +04:00
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT rdpei_touch_end(RdpeiClientContext* context, INT32 externalId, INT32 x, INT32 y,
|
|
|
|
INT32* contactId)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT error = 0;
|
2021-06-16 15:33:26 +03:00
|
|
|
va_list ap = { 0 };
|
|
|
|
error = rdpei_touch_process(context, externalId,
|
|
|
|
RDPINPUT_CONTACT_FLAG_UPDATE | RDPINPUT_CONTACT_FLAG_INRANGE |
|
|
|
|
RDPINPUT_CONTACT_FLAG_INCONTACT,
|
|
|
|
x, y, contactId, 0, ap);
|
2020-11-11 10:54:46 +03:00
|
|
|
if (error != CHANNEL_RC_OK)
|
|
|
|
return error;
|
2021-06-16 15:33:26 +03:00
|
|
|
error =
|
|
|
|
rdpei_touch_process(context, externalId, RDPINPUT_CONTACT_FLAG_UP, x, y, contactId, 0, ap);
|
|
|
|
return error;
|
2021-05-20 15:11:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT rdpei_touch_cancel(RdpeiClientContext* context, INT32 externalId, INT32 x, INT32 y,
|
|
|
|
INT32* contactId)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT rc = 0;
|
2021-06-16 15:33:26 +03:00
|
|
|
va_list ap = { 0 };
|
|
|
|
rc = rdpei_touch_process(context, externalId,
|
|
|
|
RDPINPUT_CONTACT_FLAG_UP | RDPINPUT_CONTACT_FLAG_CANCELED, x, y,
|
|
|
|
contactId, 0, ap);
|
|
|
|
return rc;
|
2021-05-20 15:11:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static UINT rdpei_touch_raw_event(RdpeiClientContext* context, INT32 externalId, INT32 x, INT32 y,
|
|
|
|
INT32* contactId, UINT32 flags, UINT32 fieldFlags, ...)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT rc = 0;
|
2021-05-20 15:11:43 +03:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fieldFlags);
|
|
|
|
rc = rdpei_touch_process(context, externalId, flags, x, y, contactId, fieldFlags, ap);
|
|
|
|
va_end(ap);
|
|
|
|
return rc;
|
2020-11-11 10:54:46 +03:00
|
|
|
}
|
2013-06-07 02:14:59 +04:00
|
|
|
|
2023-06-22 17:04:34 +03:00
|
|
|
static UINT rdpei_touch_raw_event_va(RdpeiClientContext* context, INT32 externalId, INT32 x,
|
|
|
|
INT32 y, INT32* contactId, UINT32 flags, UINT32 fieldFlags,
|
|
|
|
va_list args)
|
|
|
|
{
|
|
|
|
return rdpei_touch_process(context, externalId, flags, x, y, contactId, fieldFlags, args);
|
|
|
|
}
|
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
static RDPINPUT_PEN_CONTACT_POINT* rdpei_pen_contact(RDPEI_PLUGIN* rdpei, INT32 externalId,
|
|
|
|
BOOL active)
|
|
|
|
{
|
|
|
|
if (!rdpei)
|
|
|
|
return NULL;
|
2013-05-15 01:45:52 +04:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 x = 0; x < rdpei->maxPenContacts; x++)
|
2020-11-11 10:54:46 +03:00
|
|
|
{
|
|
|
|
RDPINPUT_PEN_CONTACT_POINT* contact = &rdpei->penContactPoints[x];
|
|
|
|
if (active)
|
2013-05-15 01:45:52 +04:00
|
|
|
{
|
2020-11-11 10:54:46 +03:00
|
|
|
if (contact->active)
|
|
|
|
{
|
|
|
|
if (contact->externalId == externalId)
|
|
|
|
return contact;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!contact->active)
|
|
|
|
{
|
|
|
|
contact->externalId = externalId;
|
|
|
|
contact->active = TRUE;
|
|
|
|
return contact;
|
|
|
|
}
|
2013-05-15 03:26:01 +04:00
|
|
|
}
|
2013-05-14 03:17:25 +04:00
|
|
|
}
|
2020-11-11 10:54:46 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
2013-05-14 03:17:25 +04:00
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
static UINT rdpei_add_pen(RdpeiClientContext* context, INT32 externalId,
|
|
|
|
const RDPINPUT_PEN_CONTACT* contact)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
RDPEI_PLUGIN* rdpei = NULL;
|
|
|
|
RDPINPUT_PEN_CONTACT_POINT* contactPoint = NULL;
|
2020-11-11 10:54:46 +03:00
|
|
|
|
|
|
|
if (!context || !contact || !context->handle)
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
|
|
|
rdpei = (RDPEI_PLUGIN*)context->handle;
|
|
|
|
|
|
|
|
EnterCriticalSection(&rdpei->lock);
|
|
|
|
contactPoint = rdpei_pen_contact(rdpei, externalId, TRUE);
|
|
|
|
if (contactPoint)
|
2013-06-07 02:14:59 +04:00
|
|
|
{
|
2020-11-11 10:54:46 +03:00
|
|
|
contactPoint->data = *contact;
|
|
|
|
contactPoint->dirty = TRUE;
|
2024-09-16 05:50:45 +03:00
|
|
|
(void)SetEvent(rdpei->event);
|
2020-11-11 10:54:46 +03:00
|
|
|
}
|
|
|
|
LeaveCriticalSection(&rdpei->lock);
|
|
|
|
|
|
|
|
return CHANNEL_RC_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT rdpei_pen_process(RdpeiClientContext* context, INT32 externalId, UINT32 contactFlags,
|
2023-06-22 17:24:45 +03:00
|
|
|
UINT32 fieldFlags, INT32 x, INT32 y, va_list ap)
|
2020-11-11 10:54:46 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
RDPINPUT_PEN_CONTACT_POINT* contactPoint = NULL;
|
|
|
|
RDPEI_PLUGIN* rdpei = NULL;
|
2020-11-11 10:54:46 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
|
|
|
|
|
|
|
if (!context || !context->handle)
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
|
|
|
rdpei = (RDPEI_PLUGIN*)context->handle;
|
|
|
|
|
|
|
|
EnterCriticalSection(&rdpei->lock);
|
2023-09-10 16:09:54 +03:00
|
|
|
// Start a new contact only when it is not active.
|
|
|
|
contactPoint = rdpei_pen_contact(rdpei, externalId, TRUE);
|
2023-06-22 17:24:45 +03:00
|
|
|
if (!contactPoint)
|
|
|
|
{
|
2023-09-10 16:09:54 +03:00
|
|
|
const UINT32 mask = RDPINPUT_CONTACT_FLAG_INRANGE;
|
|
|
|
if ((contactFlags & mask) == mask)
|
2023-06-22 17:24:45 +03:00
|
|
|
{
|
|
|
|
contactPoint = rdpei_pen_contact(rdpei, externalId, FALSE);
|
|
|
|
}
|
|
|
|
}
|
2020-11-11 10:54:46 +03:00
|
|
|
LeaveCriticalSection(&rdpei->lock);
|
|
|
|
if (contactPoint != NULL)
|
|
|
|
{
|
|
|
|
RDPINPUT_PEN_CONTACT contact = { 0 };
|
|
|
|
|
2013-06-07 02:14:59 +04:00
|
|
|
contact.x = x;
|
|
|
|
contact.y = y;
|
2020-11-11 10:54:46 +03:00
|
|
|
contact.fieldsPresent = fieldFlags;
|
|
|
|
|
|
|
|
contact.contactFlags = contactFlags;
|
2020-11-30 15:40:15 +03:00
|
|
|
if (fieldFlags & RDPINPUT_PEN_CONTACT_PENFLAGS_PRESENT)
|
2020-11-11 10:54:46 +03:00
|
|
|
contact.penFlags = va_arg(ap, UINT32);
|
2020-11-30 15:40:15 +03:00
|
|
|
if (fieldFlags & RDPINPUT_PEN_CONTACT_PRESSURE_PRESENT)
|
2020-11-11 10:54:46 +03:00
|
|
|
contact.pressure = va_arg(ap, UINT32);
|
2020-11-30 15:40:15 +03:00
|
|
|
if (fieldFlags & RDPINPUT_PEN_CONTACT_ROTATION_PRESENT)
|
2020-11-11 10:54:46 +03:00
|
|
|
contact.rotation = va_arg(ap, UINT32);
|
2020-11-30 15:40:15 +03:00
|
|
|
if (fieldFlags & RDPINPUT_PEN_CONTACT_TILTX_PRESENT)
|
2020-11-11 10:54:46 +03:00
|
|
|
contact.tiltX = va_arg(ap, INT32);
|
2020-11-30 15:40:15 +03:00
|
|
|
if (fieldFlags & RDPINPUT_PEN_CONTACT_TILTY_PRESENT)
|
2020-11-11 10:54:46 +03:00
|
|
|
contact.tiltY = va_arg(ap, INT32);
|
|
|
|
|
|
|
|
error = context->AddPen(context, externalId, &contact);
|
2013-06-07 02:14:59 +04:00
|
|
|
}
|
|
|
|
|
2015-06-09 13:46:10 +03:00
|
|
|
return error;
|
2013-05-15 01:45:52 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2020-11-11 10:54:46 +03:00
|
|
|
static UINT rdpei_pen_begin(RdpeiClientContext* context, INT32 externalId, UINT32 fieldFlags,
|
|
|
|
INT32 x, INT32 y, ...)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT error = 0;
|
2020-11-11 10:54:46 +03:00
|
|
|
va_list ap;
|
2013-05-15 01:45:52 +04:00
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
va_start(ap, y);
|
|
|
|
error = rdpei_pen_process(context, externalId,
|
2020-11-30 15:40:15 +03:00
|
|
|
RDPINPUT_CONTACT_FLAG_DOWN | RDPINPUT_CONTACT_FLAG_INRANGE |
|
|
|
|
RDPINPUT_CONTACT_FLAG_INCONTACT,
|
2023-06-22 17:24:45 +03:00
|
|
|
fieldFlags, x, y, ap);
|
2020-11-11 10:54:46 +03:00
|
|
|
va_end(ap);
|
2013-05-15 01:45:52 +04:00
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
return error;
|
|
|
|
}
|
2013-06-07 02:14:59 +04:00
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT rdpei_pen_update(RdpeiClientContext* context, INT32 externalId, UINT32 fieldFlags,
|
|
|
|
INT32 x, INT32 y, ...)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT error = 0;
|
2020-11-11 10:54:46 +03:00
|
|
|
va_list ap;
|
2013-06-07 02:37:52 +04:00
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
va_start(ap, y);
|
|
|
|
error = rdpei_pen_process(context, externalId,
|
2020-11-30 15:40:15 +03:00
|
|
|
RDPINPUT_CONTACT_FLAG_UPDATE | RDPINPUT_CONTACT_FLAG_INRANGE |
|
|
|
|
RDPINPUT_CONTACT_FLAG_INCONTACT,
|
2023-06-22 17:24:45 +03:00
|
|
|
fieldFlags, x, y, ap);
|
2020-11-11 10:54:46 +03:00
|
|
|
va_end(ap);
|
|
|
|
return error;
|
|
|
|
}
|
2013-06-07 02:14:59 +04:00
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT rdpei_pen_end(RdpeiClientContext* context, INT32 externalId, UINT32 fieldFlags, INT32 x,
|
|
|
|
INT32 y, ...)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT error = 0;
|
2020-11-11 10:54:46 +03:00
|
|
|
va_list ap;
|
2023-06-21 09:57:47 +03:00
|
|
|
va_start(ap, y);
|
|
|
|
error = rdpei_pen_process(context, externalId,
|
|
|
|
RDPINPUT_CONTACT_FLAG_UP | RDPINPUT_CONTACT_FLAG_INRANGE, fieldFlags,
|
2023-06-22 17:24:45 +03:00
|
|
|
x, y, ap);
|
2023-06-21 09:57:47 +03:00
|
|
|
va_end(ap);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT rdpei_pen_hover_begin(RdpeiClientContext* context, INT32 externalId, UINT32 fieldFlags,
|
|
|
|
INT32 x, INT32 y, ...)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT error = 0;
|
2023-06-21 09:57:47 +03:00
|
|
|
va_list ap;
|
2020-11-11 10:54:46 +03:00
|
|
|
|
|
|
|
va_start(ap, y);
|
|
|
|
error = rdpei_pen_process(context, externalId,
|
2023-06-21 09:57:47 +03:00
|
|
|
RDPINPUT_CONTACT_FLAG_UPDATE | RDPINPUT_CONTACT_FLAG_INRANGE,
|
2023-06-22 17:24:45 +03:00
|
|
|
fieldFlags, x, y, ap);
|
2021-06-16 15:33:26 +03:00
|
|
|
va_end(ap);
|
2023-06-21 09:57:47 +03:00
|
|
|
|
2020-11-11 10:54:46 +03:00
|
|
|
return error;
|
2013-05-14 00:07:42 +04:00
|
|
|
}
|
|
|
|
|
2023-06-21 09:57:47 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT rdpei_pen_hover_update(RdpeiClientContext* context, INT32 externalId, UINT32 fieldFlags,
|
|
|
|
INT32 x, INT32 y, ...)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT error = 0;
|
2023-06-21 09:57:47 +03:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, y);
|
|
|
|
error = rdpei_pen_process(context, externalId,
|
|
|
|
RDPINPUT_CONTACT_FLAG_UPDATE | RDPINPUT_CONTACT_FLAG_INRANGE,
|
2023-06-22 17:24:45 +03:00
|
|
|
fieldFlags, x, y, ap);
|
2023-06-21 09:57:47 +03:00
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT rdpei_pen_hover_cancel(RdpeiClientContext* context, INT32 externalId, UINT32 fieldFlags,
|
|
|
|
INT32 x, INT32 y, ...)
|
2021-05-20 15:11:43 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT error = 0;
|
2021-05-20 15:11:43 +03:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, y);
|
|
|
|
error = rdpei_pen_process(context, externalId,
|
2023-06-21 09:57:47 +03:00
|
|
|
RDPINPUT_CONTACT_FLAG_UPDATE | RDPINPUT_CONTACT_FLAG_CANCELED,
|
2023-06-22 17:24:45 +03:00
|
|
|
fieldFlags, x, y, ap);
|
2021-05-20 15:11:43 +03:00
|
|
|
va_end(ap);
|
2023-06-21 09:57:47 +03:00
|
|
|
|
2021-05-20 15:11:43 +03:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT rdpei_pen_raw_event(RdpeiClientContext* context, INT32 externalId, UINT32 contactFlags,
|
|
|
|
UINT32 fieldFlags, INT32 x, INT32 y, ...)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT error = 0;
|
2021-05-20 15:11:43 +03:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, y);
|
2023-06-22 17:24:45 +03:00
|
|
|
error = rdpei_pen_process(context, externalId, contactFlags, fieldFlags, x, y, ap);
|
2021-05-20 15:11:43 +03:00
|
|
|
va_end(ap);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2023-06-22 17:04:34 +03:00
|
|
|
static UINT rdpei_pen_raw_event_va(RdpeiClientContext* context, INT32 externalId,
|
|
|
|
UINT32 contactFlags, UINT32 fieldFlags, INT32 x, INT32 y,
|
|
|
|
va_list args)
|
|
|
|
{
|
2023-06-22 17:24:45 +03:00
|
|
|
return rdpei_pen_process(context, externalId, contactFlags, fieldFlags, x, y, args);
|
2023-06-22 17:04:34 +03:00
|
|
|
}
|
|
|
|
|
2022-06-21 09:09:00 +03:00
|
|
|
static UINT init_plugin_cb(GENERIC_DYNVC_PLUGIN* base, rdpContext* rcontext, rdpSettings* settings)
|
2013-03-20 00:52:07 +04:00
|
|
|
{
|
2022-06-21 09:09:00 +03:00
|
|
|
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*)base;
|
2013-03-20 00:52:07 +04:00
|
|
|
|
2022-06-21 09:09:00 +03:00
|
|
|
WINPR_ASSERT(base);
|
|
|
|
WINPR_UNUSED(settings);
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2022-06-21 09:09:00 +03:00
|
|
|
rdpei->version = RDPINPUT_PROTOCOL_V300;
|
|
|
|
rdpei->currentFrameTime = 0;
|
|
|
|
rdpei->previousFrameTime = 0;
|
|
|
|
rdpei->maxTouchContacts = MAX_CONTACTS;
|
|
|
|
rdpei->maxPenContacts = MAX_PEN_CONTACTS;
|
|
|
|
rdpei->rdpcontext = rcontext;
|
2013-03-20 00:52:07 +04:00
|
|
|
|
2024-09-25 13:41:19 +03:00
|
|
|
WINPR_ASSERT(rdpei->base.log);
|
|
|
|
|
2022-06-21 09:09:00 +03:00
|
|
|
InitializeCriticalSection(&rdpei->lock);
|
|
|
|
rdpei->event = CreateEventA(NULL, TRUE, FALSE, NULL);
|
|
|
|
if (!rdpei->event)
|
|
|
|
{
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(rdpei->base.log, WLOG_ERROR, "calloc failed!");
|
2022-06-21 09:09:00 +03:00
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2015-07-15 10:50:35 +03:00
|
|
|
|
2024-09-25 13:41:19 +03:00
|
|
|
RdpeiClientContext* context = (RdpeiClientContext*)calloc(1, sizeof(RdpeiClientContext));
|
2022-06-21 09:09:00 +03:00
|
|
|
if (!context)
|
|
|
|
{
|
2024-09-25 13:41:19 +03:00
|
|
|
WLog_Print(rdpei->base.log, WLOG_ERROR, "calloc failed!");
|
2022-06-21 09:09:00 +03:00
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2022-06-21 09:09:00 +03:00
|
|
|
context->clientFeaturesMask = UINT32_MAX;
|
|
|
|
context->handle = (void*)rdpei;
|
|
|
|
context->GetVersion = rdpei_get_version;
|
|
|
|
context->GetFeatures = rdpei_get_features;
|
|
|
|
context->AddContact = rdpei_add_contact;
|
|
|
|
context->TouchBegin = rdpei_touch_begin;
|
|
|
|
context->TouchUpdate = rdpei_touch_update;
|
|
|
|
context->TouchEnd = rdpei_touch_end;
|
|
|
|
context->TouchCancel = rdpei_touch_cancel;
|
|
|
|
context->TouchRawEvent = rdpei_touch_raw_event;
|
2023-06-22 17:04:34 +03:00
|
|
|
context->TouchRawEventVA = rdpei_touch_raw_event_va;
|
2022-06-21 09:09:00 +03:00
|
|
|
context->AddPen = rdpei_add_pen;
|
|
|
|
context->PenBegin = rdpei_pen_begin;
|
|
|
|
context->PenUpdate = rdpei_pen_update;
|
|
|
|
context->PenEnd = rdpei_pen_end;
|
2023-06-21 09:57:47 +03:00
|
|
|
context->PenHoverBegin = rdpei_pen_hover_begin;
|
|
|
|
context->PenHoverUpdate = rdpei_pen_hover_update;
|
|
|
|
context->PenHoverCancel = rdpei_pen_hover_cancel;
|
2022-06-21 09:09:00 +03:00
|
|
|
context->PenRawEvent = rdpei_pen_raw_event;
|
2023-06-22 17:04:34 +03:00
|
|
|
context->PenRawEventVA = rdpei_pen_raw_event_va;
|
2022-06-21 09:09:00 +03:00
|
|
|
|
|
|
|
rdpei->context = context;
|
|
|
|
rdpei->base.iface.pInterface = (void*)context;
|
2013-05-14 00:07:42 +04:00
|
|
|
|
2024-09-25 13:41:19 +03:00
|
|
|
rdpei->async =
|
|
|
|
!freerdp_settings_get_bool(rdpei->rdpcontext->settings, FreeRDP_SynchronousDynamicChannels);
|
|
|
|
if (rdpei->async)
|
2022-06-21 09:09:00 +03:00
|
|
|
{
|
2024-09-25 13:41:19 +03:00
|
|
|
rdpei->running = TRUE;
|
|
|
|
|
|
|
|
rdpei->thread = CreateThread(NULL, 0, rdpei_periodic_update, rdpei, 0, NULL);
|
|
|
|
if (!rdpei->thread)
|
|
|
|
{
|
|
|
|
WLog_Print(rdpei->base.log, WLOG_ERROR, "calloc failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!freerdp_client_channel_register(rdpei->rdpcontext->channels, rdpei->event,
|
|
|
|
rdpei_poll_run, rdpei))
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
2013-03-20 00:52:07 +04:00
|
|
|
}
|
|
|
|
|
2015-06-09 13:46:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2022-06-21 09:09:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void terminate_plugin_cb(GENERIC_DYNVC_PLUGIN* base)
|
|
|
|
{
|
|
|
|
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*)base;
|
|
|
|
WINPR_ASSERT(rdpei);
|
|
|
|
|
2022-09-12 22:28:31 +03:00
|
|
|
rdpei->running = FALSE;
|
2022-06-21 09:09:00 +03:00
|
|
|
if (rdpei->event)
|
2024-09-16 05:50:45 +03:00
|
|
|
(void)SetEvent(rdpei->event);
|
2022-06-21 09:09:00 +03:00
|
|
|
|
|
|
|
if (rdpei->thread)
|
|
|
|
{
|
2024-09-16 06:06:07 +03:00
|
|
|
(void)WaitForSingleObject(rdpei->thread, INFINITE);
|
2024-09-16 05:58:36 +03:00
|
|
|
(void)CloseHandle(rdpei->thread);
|
2022-06-21 09:09:00 +03:00
|
|
|
}
|
|
|
|
|
2024-09-25 13:41:19 +03:00
|
|
|
if (rdpei->event && !rdpei->async)
|
|
|
|
(void)freerdp_client_channel_unregister(rdpei->rdpcontext->channels, rdpei->event);
|
|
|
|
|
2022-06-21 09:09:00 +03:00
|
|
|
if (rdpei->event)
|
2024-09-16 05:58:36 +03:00
|
|
|
(void)CloseHandle(rdpei->event);
|
2022-06-21 09:09:00 +03:00
|
|
|
|
|
|
|
DeleteCriticalSection(&rdpei->lock);
|
|
|
|
free(rdpei->context);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IWTSVirtualChannelCallback geometry_callbacks = { rdpei_on_data_received,
|
|
|
|
NULL, /* Open */
|
2023-11-17 11:13:08 +03:00
|
|
|
rdpei_on_close, NULL };
|
2022-06-21 09:09:00 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2024-09-03 17:29:16 +03:00
|
|
|
FREERDP_ENTRY_POINT(UINT VCAPITYPE rdpei_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints))
|
2022-06-21 09:09:00 +03:00
|
|
|
{
|
2024-09-25 13:41:19 +03:00
|
|
|
return freerdp_generic_DVCPluginEntry(pEntryPoints, RDPEI_TAG, RDPEI_DVC_CHANNEL_NAME,
|
2022-06-21 09:09:00 +03:00
|
|
|
sizeof(RDPEI_PLUGIN), sizeof(GENERIC_CHANNEL_CALLBACK),
|
|
|
|
&geometry_callbacks, init_plugin_cb, terminate_plugin_cb);
|
2013-03-20 00:52:07 +04:00
|
|
|
}
|