diff --git a/channels/rdpei/client/rdpei_common.c b/channels/rdpei/client/rdpei_common.c index e0b758a04..b1deb8b1d 100644 --- a/channels/rdpei/client/rdpei_common.c +++ b/channels/rdpei/client/rdpei_common.c @@ -480,23 +480,22 @@ BOOL rdpei_write_8byte_unsigned(wStream* s, UINT64 value) if (value <= 0x1F) { - count = 0; byte = value & 0x1F; - Stream_Write_UINT8(s, byte | (count << 5)); + Stream_Write_UINT8(s, byte); } else if (value <= 0x1FFF) { - count = 1; byte = (value >> 8) & 0x1F; - Stream_Write_UINT8(s, byte | (count << 5)); + byte |= (1 << 5); + Stream_Write_UINT8(s, byte); byte = (value & 0xFF); Stream_Write_UINT8(s, byte); } else if (value <= 0x1FFFFF) { - count = 2; byte = (value >> 16) & 0x1F; - Stream_Write_UINT8(s, byte | (count << 5)); + byte |= (2 << 5); + Stream_Write_UINT8(s, byte); byte = (value >> 8) & 0xFF; Stream_Write_UINT8(s, byte); byte = (value & 0xFF); @@ -504,9 +503,9 @@ BOOL rdpei_write_8byte_unsigned(wStream* s, UINT64 value) } else if (value <= 0x1FFFFF) { - count = 3; byte = (value >> 24) & 0x1F; - Stream_Write_UINT8(s, byte | (count << 5)); + byte |= (3 << 5); + Stream_Write_UINT8(s, byte); byte = (value >> 16) & 0xFF; Stream_Write_UINT8(s, byte); byte = (value >> 8) & 0xFF; @@ -516,9 +515,9 @@ BOOL rdpei_write_8byte_unsigned(wStream* s, UINT64 value) } else if (value <= 0x1FFFFFFF) { - count = 4; byte = (value >> 32) & 0x1F; - Stream_Write_UINT8(s, byte | (count << 5)); + byte |= (4 << 5); + Stream_Write_UINT8(s, byte); byte = (value >> 24) & 0x1F; Stream_Write_UINT8(s, byte); byte = (value >> 16) & 0xFF; @@ -530,9 +529,9 @@ BOOL rdpei_write_8byte_unsigned(wStream* s, UINT64 value) } else if (value <= 0x1FFFFFFFFF) { - count = 5; byte = (value >> 40) & 0x1F; - Stream_Write_UINT8(s, byte | (count << 5)); + byte |= (5 << 5); + Stream_Write_UINT8(s, byte); byte = (value >> 32) & 0x1F; Stream_Write_UINT8(s, byte); byte = (value >> 24) & 0x1F; @@ -546,9 +545,9 @@ BOOL rdpei_write_8byte_unsigned(wStream* s, UINT64 value) } else if (value <= 0x1FFFFFFFFFFF) { - count = 6; byte = (value >> 48) & 0x1F; - Stream_Write_UINT8(s, byte | (count << 5)); + byte |= (6 << 5); + Stream_Write_UINT8(s, byte); byte = (value >> 40) & 0x1F; Stream_Write_UINT8(s, byte); byte = (value >> 32) & 0x1F; @@ -564,9 +563,9 @@ BOOL rdpei_write_8byte_unsigned(wStream* s, UINT64 value) } else if (value <= 0x1FFFFFFFFFFFFF) { - count = 7; byte = (value >> 56) & 0x1F; - Stream_Write_UINT8(s, byte | (count << 5)); + byte |= (7 << 5); + Stream_Write_UINT8(s, byte); byte = (value >> 48) & 0x1F; Stream_Write_UINT8(s, byte); byte = (value >> 40) & 0x1F; diff --git a/channels/rdpei/client/rdpei_main.c b/channels/rdpei/client/rdpei_main.c index 026f73c93..65baaf430 100644 --- a/channels/rdpei/client/rdpei_main.c +++ b/channels/rdpei/client/rdpei_main.c @@ -66,6 +66,7 @@ struct _RDPEI_PLUGIN RDPEI_LISTENER_CALLBACK* listener_callback; int version; + int touchIdOffset; UINT64 currentFrameTime; UINT64 previousFrameTime; RDPINPUT_TOUCH_FRAME frame; @@ -93,11 +94,10 @@ int rdpei_send_pdu(RDPEI_CHANNEL_CALLBACK* callback, wStream* s, UINT16 eventId, Stream_Write_UINT32(s, pduLength); /* pduLength (4 bytes) */ Stream_SetPosition(s, Stream_Length(s)); - printf("rdpei_send_pdu: eventId: %d (%s) length: %d\n", - eventId, RDPEI_EVENTID_STRINGS[eventId], pduLength); + status = callback->channel->Write(callback->channel, Stream_Length(s), Stream_Buffer(s), NULL); - status = callback->channel->Write(callback->channel, - Stream_Length(s), Stream_Buffer(s), NULL); + printf("rdpei_send_pdu: eventId: %d (%s) length: %d status: %d\n", + eventId, RDPEI_EVENTID_STRINGS[eventId], pduLength, status); return status; } @@ -137,8 +137,11 @@ int rdpei_write_touch_frame(wStream* s, RDPINPUT_TOUCH_FRAME* frame) int index; RDPINPUT_CONTACT_DATA* contact; - rdpei_write_2byte_unsigned(s, frame->contactCount); - rdpei_write_8byte_unsigned(s, frame->frameOffset); + printf("contactCount: %d\n", frame->contactCount); + printf("frameOffset: 0x%08X\n", (UINT32) frame->frameOffset); + + rdpei_write_2byte_unsigned(s, frame->contactCount); /* contactCount (TWO_BYTE_UNSIGNED_INTEGER) */ + rdpei_write_8byte_unsigned(s, frame->frameOffset); /* frameOffset (EIGHT_BYTE_UNSIGNED_INTEGER) */ Stream_EnsureRemainingCapacity(s, frame->contactCount * 32); @@ -146,27 +149,44 @@ int rdpei_write_touch_frame(wStream* s, RDPINPUT_TOUCH_FRAME* frame) { contact = &frame->contacts[index]; - Stream_Write_UINT8(s, contact->contactId); + printf("contact[%d].contactId: %d\n", index, contact->contactId); + printf("contact[%d].fieldsPresent: %d\n", index, contact->fieldsPresent); + printf("contact[%d].x: %d\n", index, contact->x); + printf("contact[%d].y: %d\n", index, contact->y); + printf("contact[%d].contactFlags: 0x%04X\n", index, contact->contactFlags); + + Stream_Write_UINT8(s, contact->contactId); /* contactId (1 byte) */ + + /* fieldsPresent (TWO_BYTE_UNSIGNED_INTEGER) */ rdpei_write_2byte_unsigned(s, contact->fieldsPresent); - rdpei_write_4byte_signed(s, contact->x); - rdpei_write_4byte_signed(s, contact->y); + + 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) */ rdpei_write_4byte_unsigned(s, contact->contactFlags); if (contact->fieldsPresent & CONTACT_DATA_CONTACTRECT_PRESENT) { + /* contactRectLeft (TWO_BYTE_SIGNED_INTEGER) */ rdpei_write_2byte_signed(s, contact->contactRectLeft); + /* contactRectTop (TWO_BYTE_SIGNED_INTEGER) */ rdpei_write_2byte_signed(s, contact->contactRectTop); + /* contactRectRight (TWO_BYTE_SIGNED_INTEGER) */ rdpei_write_2byte_signed(s, contact->contactRectRight); + /* contactRectBottom (TWO_BYTE_SIGNED_INTEGER) */ rdpei_write_2byte_signed(s, contact->contactRectBottom); } if (contact->fieldsPresent & CONTACT_DATA_ORIENTATION_PRESENT) { + /* orientation (FOUR_BYTE_UNSIGNED_INTEGER) */ rdpei_write_4byte_unsigned(s, contact->orientation); } if (contact->fieldsPresent & CONTACT_DATA_PRESSURE_PRESENT) { + /* pressure (FOUR_BYTE_UNSIGNED_INTEGER) */ rdpei_write_4byte_unsigned(s, contact->pressure); } } @@ -179,17 +199,14 @@ int rdpei_send_touch_event_pdu(RDPEI_CHANNEL_CALLBACK* callback, RDPINPUT_TOUCH_ int status; wStream* s; UINT32 pduLength; - UINT32 encodeTime; - UINT16 frameCount; - encodeTime = 0; - frameCount = 1; + pduLength = 64 + (frame->contactCount * 32); - s = Stream_New(NULL, 512); + s = Stream_New(NULL, pduLength); Stream_Seek(s, RDPINPUT_HEADER_LENGTH); - rdpei_write_4byte_unsigned(s, encodeTime); - rdpei_write_2byte_unsigned(s, frameCount); + rdpei_write_4byte_unsigned(s, frame->frameOffset); /* FOUR_BYTE_UNSIGNED_INTEGER */ + rdpei_write_2byte_unsigned(s, frame->contactCount); /* TWO_BYTE_UNSIGNED_INTEGER */ rdpei_write_touch_frame(s, frame); @@ -368,6 +385,9 @@ int rdpei_end_frame(RdpeiClientContext* context) RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*) context->handle; RDPEI_CHANNEL_CALLBACK* callback = rdpei->listener_callback->channel_callback; + //if (rdpei->frame.contactCount < 8) + // return 0; + if (!rdpei->previousFrameTime && !rdpei->currentFrameTime) { rdpei->currentFrameTime = (UINT64) GetTickCount64(); @@ -388,10 +408,27 @@ int rdpei_end_frame(RdpeiClientContext* context) int rdpei_add_contact(RdpeiClientContext* context, RDPINPUT_CONTACT_DATA* contact) { + RDPINPUT_CONTACT_DATA* previousContact; RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*) context->handle; if (rdpei->frame.contactCount < MAX_CONTACTS) { + if (rdpei->frame.contactCount > 0) + { + previousContact = &(rdpei->contacts[rdpei->frame.contactCount - 1]); + + if ((previousContact->x == contact->x) || (previousContact->y == contact->y) || + (previousContact->contactId == contact->contactId)) + { + return 1; + } + } + + if (rdpei->touchIdOffset < 0) + rdpei->touchIdOffset = contact->contactId; + + contact->contactId -= rdpei->touchIdOffset; + CopyMemory(&(rdpei->contacts[rdpei->frame.contactCount]), contact, sizeof(RDPINPUT_CONTACT_DATA)); rdpei->frame.contactCount++; } @@ -422,6 +459,7 @@ int DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints) rdpei->iface.Terminated = rdpei_plugin_terminated; rdpei->version = 1; + rdpei->touchIdOffset = -1; rdpei->currentFrameTime = 0; rdpei->previousFrameTime = 0; rdpei->frame.contacts = (RDPINPUT_CONTACT_DATA*) rdpei->contacts; diff --git a/client/X11/xf_input.c b/client/X11/xf_input.c index e0e6eafe0..a8a442cb6 100644 --- a/client/X11/xf_input.c +++ b/client/X11/xf_input.c @@ -328,20 +328,31 @@ int xf_input_touch_remote(xfInfo* xfi, XIDeviceEvent* event, DWORD flags) y = (int) event->event_y; ZeroMemory(&contact, sizeof(RDPINPUT_CONTACT_DATA)); - if ((x < 0) || (y < 0)) - return 0; + //if ((x < 0) || (y < 0)) + // return 0; - printf("%s: id: %d x: %d y: %d\n", - xf_input_touch_state_string(flags), - touchId, x, y); - - contact.contactId = touchId % 0xFF; + contact.contactId = touchId; contact.fieldsPresent = 0; contact.x = x; contact.y = y; contact.contactFlags = flags; - rdpei->BeginFrame(rdpei); + if (flags & CONTACT_FLAG_DOWN) + { + contact.contactFlags |= CONTACT_FLAG_INRANGE; + contact.contactFlags |= CONTACT_FLAG_INCONTACT; + } + else if (flags & CONTACT_FLAG_UPDATE) + { + contact.contactFlags |= CONTACT_FLAG_INRANGE; + contact.contactFlags |= CONTACT_FLAG_INCONTACT; + } + else if (flags & CONTACT_FLAG_UP) + { + //contact.contactFlags |= CONTACT_FLAG_INRANGE; + } + + //rdpei->BeginFrame(rdpei); rdpei->AddContact(rdpei, &contact); rdpei->EndFrame(rdpei);