2011-07-28 04:14:12 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-07-28 04:14:12 +04:00
|
|
|
* Input PDUs
|
|
|
|
*
|
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@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.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-02-14 02:51:42 +04:00
|
|
|
#include <freerdp/input.h>
|
|
|
|
|
2011-07-28 04:14:12 +04:00
|
|
|
#include "input.h"
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void rdp_write_client_input_pdu_header(STREAM* s, UINT16 number)
|
2011-07-28 04:14:12 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, 1); /* numberEvents (2 bytes) */
|
|
|
|
stream_write_UINT16(s, 0); /* pad2Octets (2 bytes) */
|
2011-07-28 04:14:12 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
void rdp_write_input_event_header(STREAM* s, UINT32 time, UINT16 type)
|
2011-08-01 20:24:29 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_write_UINT32(s, time); /* eventTime (4 bytes) */
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, type); /* messageType (2 bytes) */
|
2011-08-01 20:24:29 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
STREAM* rdp_client_input_pdu_init(rdpRdp* rdp, UINT16 type)
|
2011-07-28 04:14:12 +04:00
|
|
|
{
|
|
|
|
STREAM* s;
|
|
|
|
s = rdp_data_pdu_init(rdp);
|
|
|
|
rdp_write_client_input_pdu_header(s, 1);
|
2011-08-01 20:24:29 +04:00
|
|
|
rdp_write_input_event_header(s, 0, type);
|
2011-07-28 04:14:12 +04:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rdp_send_client_input_pdu(rdpRdp* rdp, STREAM* s)
|
|
|
|
{
|
|
|
|
rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_INPUT, rdp->mcs->user_id);
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
void input_write_synchronize_event(STREAM* s, UINT32 flags)
|
2011-07-28 04:14:12 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, 0); /* pad2Octets (2 bytes) */
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_write_UINT32(s, flags); /* toggleFlags (4 bytes) */
|
2011-07-28 04:14:12 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
void input_send_synchronize_event(rdpInput* input, UINT32 flags)
|
2011-07-28 04:14:12 +04:00
|
|
|
{
|
|
|
|
STREAM* s;
|
2011-10-16 08:50:10 +04:00
|
|
|
rdpRdp* rdp = input->context->rdp;
|
|
|
|
|
|
|
|
s = rdp_client_input_pdu_init(rdp, INPUT_EVENT_SYNC);
|
2011-07-28 04:14:12 +04:00
|
|
|
input_write_synchronize_event(s, flags);
|
2011-10-16 08:50:10 +04:00
|
|
|
rdp_send_client_input_pdu(rdp, s);
|
2011-07-28 04:14:12 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void input_write_keyboard_event(STREAM* s, UINT16 flags, UINT16 code)
|
2011-07-28 04:14:12 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, flags); /* keyboardFlags (2 bytes) */
|
|
|
|
stream_write_UINT16(s, code); /* keyCode (2 bytes) */
|
|
|
|
stream_write_UINT16(s, 0); /* pad2Octets (2 bytes) */
|
2011-07-28 04:14:12 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void input_send_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
|
2011-07-28 04:14:12 +04:00
|
|
|
{
|
|
|
|
STREAM* s;
|
2011-10-16 08:50:10 +04:00
|
|
|
rdpRdp* rdp = input->context->rdp;
|
|
|
|
|
|
|
|
s = rdp_client_input_pdu_init(rdp, INPUT_EVENT_SCANCODE);
|
2011-07-28 04:14:12 +04:00
|
|
|
input_write_keyboard_event(s, flags, code);
|
2011-10-16 08:50:10 +04:00
|
|
|
rdp_send_client_input_pdu(rdp, s);
|
2011-07-28 04:14:12 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void input_write_unicode_keyboard_event(STREAM* s, UINT16 flags, UINT16 code)
|
2011-07-28 04:14:12 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, flags); /* keyboardFlags (2 bytes) */
|
|
|
|
stream_write_UINT16(s, code); /* unicodeCode (2 bytes) */
|
|
|
|
stream_write_UINT16(s, 0); /* pad2Octets (2 bytes) */
|
2011-07-28 04:14:12 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void input_send_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
|
2011-07-28 04:14:12 +04:00
|
|
|
{
|
|
|
|
STREAM* s;
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 keyboardFlags = 0;
|
2011-10-16 08:50:10 +04:00
|
|
|
rdpRdp* rdp = input->context->rdp;
|
|
|
|
|
2012-02-07 15:22:01 +04:00
|
|
|
/*
|
|
|
|
* According to the specification, the slow path Unicode Keyboard Event
|
|
|
|
* (TS_UNICODE_KEYBOARD_EVENT) contains KBD_FLAGS_RELEASE flag when key
|
|
|
|
* is released, but contains no flags when it is pressed.
|
|
|
|
* This is different from the slow path Keyboard Event
|
|
|
|
* (TS_KEYBOARD_EVENT) which does contain KBD_FLAGS_DOWN flag when the
|
|
|
|
* key is pressed.
|
|
|
|
* There is no KBD_FLAGS_EXTENDED flag in TS_UNICODE_KEYBOARD_EVENT.
|
|
|
|
*/
|
|
|
|
keyboardFlags |= (flags & KBD_FLAGS_RELEASE) ? KBD_FLAGS_RELEASE : 0;
|
|
|
|
|
2011-10-16 08:50:10 +04:00
|
|
|
s = rdp_client_input_pdu_init(rdp, INPUT_EVENT_UNICODE);
|
2012-02-07 15:22:01 +04:00
|
|
|
input_write_unicode_keyboard_event(s, flags, code);
|
2011-10-16 08:50:10 +04:00
|
|
|
rdp_send_client_input_pdu(rdp, s);
|
2011-07-28 04:14:12 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void input_write_mouse_event(STREAM* s, UINT16 flags, UINT16 x, UINT16 y)
|
2011-07-28 04:14:12 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, flags); /* pointerFlags (2 bytes) */
|
|
|
|
stream_write_UINT16(s, x); /* xPos (2 bytes) */
|
|
|
|
stream_write_UINT16(s, y); /* yPos (2 bytes) */
|
2011-07-28 04:14:12 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void input_send_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
|
2011-07-28 04:14:12 +04:00
|
|
|
{
|
|
|
|
STREAM* s;
|
2011-10-16 08:50:10 +04:00
|
|
|
rdpRdp* rdp = input->context->rdp;
|
|
|
|
|
|
|
|
s = rdp_client_input_pdu_init(rdp, INPUT_EVENT_MOUSE);
|
2011-07-28 04:14:12 +04:00
|
|
|
input_write_mouse_event(s, flags, x, y);
|
2011-10-16 08:50:10 +04:00
|
|
|
rdp_send_client_input_pdu(rdp, s);
|
2011-07-28 04:14:12 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void input_write_extended_mouse_event(STREAM* s, UINT16 flags, UINT16 x, UINT16 y)
|
2011-07-28 04:14:12 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, flags); /* pointerFlags (2 bytes) */
|
|
|
|
stream_write_UINT16(s, x); /* xPos (2 bytes) */
|
|
|
|
stream_write_UINT16(s, y); /* yPos (2 bytes) */
|
2011-07-28 04:14:12 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void input_send_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
|
2011-07-28 04:14:12 +04:00
|
|
|
{
|
|
|
|
STREAM* s;
|
2011-10-16 08:50:10 +04:00
|
|
|
rdpRdp* rdp = input->context->rdp;
|
|
|
|
|
|
|
|
s = rdp_client_input_pdu_init(rdp, INPUT_EVENT_MOUSEX);
|
2011-07-28 04:14:12 +04:00
|
|
|
input_write_extended_mouse_event(s, flags, x, y);
|
2011-10-16 08:50:10 +04:00
|
|
|
rdp_send_client_input_pdu(rdp, s);
|
2011-07-28 04:14:12 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
void input_send_fastpath_synchronize_event(rdpInput* input, UINT32 flags)
|
2011-08-16 10:37:11 +04:00
|
|
|
{
|
|
|
|
STREAM* s;
|
2011-10-16 08:50:10 +04:00
|
|
|
rdpRdp* rdp = input->context->rdp;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2011-08-16 10:37:11 +04:00
|
|
|
/* The FastPath Synchronization eventFlags has identical values as SlowPath */
|
2012-10-09 11:01:37 +04:00
|
|
|
s = fastpath_input_pdu_init(rdp->fastpath, (BYTE) flags, FASTPATH_INPUT_EVENT_SYNC);
|
2011-08-23 11:51:51 +04:00
|
|
|
fastpath_send_input_pdu(rdp->fastpath, s);
|
2011-08-16 10:37:11 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void input_send_fastpath_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
|
2011-08-16 10:37:11 +04:00
|
|
|
{
|
|
|
|
STREAM* s;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE eventFlags = 0;
|
2011-10-16 08:50:10 +04:00
|
|
|
rdpRdp* rdp = input->context->rdp;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2011-08-16 10:37:11 +04:00
|
|
|
eventFlags |= (flags & KBD_FLAGS_RELEASE) ? FASTPATH_INPUT_KBDFLAGS_RELEASE : 0;
|
|
|
|
eventFlags |= (flags & KBD_FLAGS_EXTENDED) ? FASTPATH_INPUT_KBDFLAGS_EXTENDED : 0;
|
2011-08-23 11:51:51 +04:00
|
|
|
s = fastpath_input_pdu_init(rdp->fastpath, eventFlags, FASTPATH_INPUT_EVENT_SCANCODE);
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_BYTE(s, code); /* keyCode (1 byte) */
|
2011-08-23 11:51:51 +04:00
|
|
|
fastpath_send_input_pdu(rdp->fastpath, s);
|
2011-08-16 10:37:11 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void input_send_fastpath_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
|
2011-08-16 10:37:11 +04:00
|
|
|
{
|
|
|
|
STREAM* s;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE eventFlags = 0;
|
2011-10-16 08:50:10 +04:00
|
|
|
rdpRdp* rdp = input->context->rdp;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2012-02-07 15:22:01 +04:00
|
|
|
eventFlags |= (flags & KBD_FLAGS_RELEASE) ? FASTPATH_INPUT_KBDFLAGS_RELEASE : 0;
|
|
|
|
s = fastpath_input_pdu_init(rdp->fastpath, eventFlags, FASTPATH_INPUT_EVENT_UNICODE);
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, code); /* unicodeCode (2 bytes) */
|
2011-08-23 11:51:51 +04:00
|
|
|
fastpath_send_input_pdu(rdp->fastpath, s);
|
2011-08-16 10:37:11 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void input_send_fastpath_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
|
2011-08-16 10:37:11 +04:00
|
|
|
{
|
|
|
|
STREAM* s;
|
2011-10-16 08:50:10 +04:00
|
|
|
rdpRdp* rdp = input->context->rdp;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
|
|
|
s = fastpath_input_pdu_init(rdp->fastpath, 0, FASTPATH_INPUT_EVENT_MOUSE);
|
2011-08-16 10:37:11 +04:00
|
|
|
input_write_mouse_event(s, flags, x, y);
|
2011-08-23 11:51:51 +04:00
|
|
|
fastpath_send_input_pdu(rdp->fastpath, s);
|
2011-08-16 10:37:11 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void input_send_fastpath_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
|
2011-08-16 10:37:11 +04:00
|
|
|
{
|
|
|
|
STREAM* s;
|
2011-10-16 08:50:10 +04:00
|
|
|
rdpRdp* rdp = input->context->rdp;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
|
|
|
s = fastpath_input_pdu_init(rdp->fastpath, 0, FASTPATH_INPUT_EVENT_MOUSEX);
|
2011-08-16 10:37:11 +04:00
|
|
|
input_write_extended_mouse_event(s, flags, x, y);
|
2011-08-23 11:51:51 +04:00
|
|
|
fastpath_send_input_pdu(rdp->fastpath, s);
|
2011-08-16 10:37:11 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
static BOOL input_recv_sync_event(rdpInput* input, STREAM* s)
|
2012-02-07 16:38:27 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 toggleFlags;
|
2012-02-07 16:38:27 +04:00
|
|
|
|
|
|
|
if (stream_get_left(s) < 6)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-02-07 16:38:27 +04:00
|
|
|
|
|
|
|
stream_seek(s, 2); /* pad2Octets (2 bytes) */
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_read_UINT32(s, toggleFlags); /* toggleFlags (4 bytes) */
|
2012-02-07 16:38:27 +04:00
|
|
|
|
|
|
|
IFCALL(input->SynchronizeEvent, input, toggleFlags);
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2012-02-07 16:38:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
static BOOL input_recv_keyboard_event(rdpInput* input, STREAM* s)
|
2012-02-07 16:38:27 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 keyboardFlags, keyCode;
|
2012-02-07 16:38:27 +04:00
|
|
|
|
|
|
|
if (stream_get_left(s) < 6)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-02-07 16:38:27 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_UINT16(s, keyboardFlags); /* keyboardFlags (2 bytes) */
|
|
|
|
stream_read_UINT16(s, keyCode); /* keyCode (2 bytes) */
|
2012-02-07 16:38:27 +04:00
|
|
|
stream_seek(s, 2); /* pad2Octets (2 bytes) */
|
|
|
|
|
|
|
|
IFCALL(input->KeyboardEvent, input, keyboardFlags, keyCode);
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2012-02-07 16:38:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
static BOOL input_recv_unicode_keyboard_event(rdpInput* input, STREAM* s)
|
2012-02-07 16:38:27 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 keyboardFlags, unicodeCode;
|
2012-02-07 16:38:27 +04:00
|
|
|
|
|
|
|
if (stream_get_left(s) < 6)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-02-07 16:38:27 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_UINT16(s, keyboardFlags); /* keyboardFlags (2 bytes) */
|
|
|
|
stream_read_UINT16(s, unicodeCode); /* unicodeCode (2 bytes) */
|
2012-02-07 16:38:27 +04:00
|
|
|
stream_seek(s, 2); /* pad2Octets (2 bytes) */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* According to the specification, the slow path Unicode Keyboard Event
|
|
|
|
* (TS_UNICODE_KEYBOARD_EVENT) contains KBD_FLAGS_RELEASE flag when key
|
|
|
|
* is released, but contains no flags when it is pressed.
|
|
|
|
* This is different from the slow path Keyboard Event
|
|
|
|
* (TS_KEYBOARD_EVENT) which does contain KBD_FLAGS_DOWN flag when the
|
|
|
|
* key is pressed.
|
|
|
|
* Set the KBD_FLAGS_DOWN flag if the KBD_FLAGS_RELEASE flag is missing.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((keyboardFlags & KBD_FLAGS_RELEASE) == 0)
|
|
|
|
keyboardFlags |= KBD_FLAGS_DOWN;
|
|
|
|
|
|
|
|
IFCALL(input->UnicodeKeyboardEvent, input, keyboardFlags, unicodeCode);
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2012-02-07 16:38:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
static BOOL input_recv_mouse_event(rdpInput* input, STREAM* s)
|
2012-02-07 16:38:27 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 pointerFlags, xPos, yPos;
|
2012-02-07 16:38:27 +04:00
|
|
|
|
|
|
|
if (stream_get_left(s) < 6)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-02-07 16:38:27 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_UINT16(s, pointerFlags); /* pointerFlags (2 bytes) */
|
|
|
|
stream_read_UINT16(s, xPos); /* xPos (2 bytes) */
|
|
|
|
stream_read_UINT16(s, yPos); /* yPos (2 bytes) */
|
2012-02-07 16:38:27 +04:00
|
|
|
|
|
|
|
IFCALL(input->MouseEvent, input, pointerFlags, xPos, yPos);
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2012-02-07 16:38:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
static BOOL input_recv_extended_mouse_event(rdpInput* input, STREAM* s)
|
2012-02-07 16:38:27 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 pointerFlags, xPos, yPos;
|
2012-02-07 16:38:27 +04:00
|
|
|
|
|
|
|
if (stream_get_left(s) < 6)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-02-07 16:38:27 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_UINT16(s, pointerFlags); /* pointerFlags (2 bytes) */
|
|
|
|
stream_read_UINT16(s, xPos); /* xPos (2 bytes) */
|
|
|
|
stream_read_UINT16(s, yPos); /* yPos (2 bytes) */
|
2012-02-07 16:38:27 +04:00
|
|
|
|
|
|
|
IFCALL(input->ExtendedMouseEvent, input, pointerFlags, xPos, yPos);
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2012-02-07 16:38:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
static BOOL input_recv_event(rdpInput* input, STREAM* s)
|
2012-02-07 16:38:27 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 messageType;
|
2012-02-07 16:38:27 +04:00
|
|
|
|
|
|
|
if (stream_get_left(s) < 4)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-02-07 16:38:27 +04:00
|
|
|
|
|
|
|
stream_seek(s, 4); /* eventTime (4 bytes), ignored by the server */
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_UINT16(s, messageType); /* messageType (2 bytes) */
|
2012-02-07 16:38:27 +04:00
|
|
|
|
|
|
|
switch (messageType)
|
|
|
|
{
|
|
|
|
case INPUT_EVENT_SYNC:
|
|
|
|
if (!input_recv_sync_event(input, s))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-02-07 16:38:27 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case INPUT_EVENT_SCANCODE:
|
|
|
|
if (!input_recv_keyboard_event(input, s))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-02-07 16:38:27 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case INPUT_EVENT_UNICODE:
|
|
|
|
if (!input_recv_unicode_keyboard_event(input, s))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-02-07 16:38:27 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case INPUT_EVENT_MOUSE:
|
|
|
|
if (!input_recv_mouse_event(input, s))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-02-07 16:38:27 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case INPUT_EVENT_MOUSEX:
|
|
|
|
if (!input_recv_extended_mouse_event(input, s))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-02-07 16:38:27 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("Unknown messageType %u\n", messageType);
|
|
|
|
/* Each input event uses 6 bytes. */
|
|
|
|
stream_seek(s, 6);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2012-02-07 16:38:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL input_recv(rdpInput* input, STREAM* s)
|
2012-02-07 16:38:27 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 i, numberEvents;
|
2012-02-07 16:38:27 +04:00
|
|
|
|
|
|
|
if (stream_get_left(s) < 4)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-02-07 16:38:27 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_UINT16(s, numberEvents); /* numberEvents (2 bytes) */
|
2012-02-07 16:38:27 +04:00
|
|
|
stream_seek(s, 2); /* pad2Octets (2 bytes) */
|
|
|
|
|
|
|
|
/* Each input event uses 6 exactly bytes. */
|
|
|
|
if (stream_get_left(s) < 6 * numberEvents)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-02-07 16:38:27 +04:00
|
|
|
|
|
|
|
for (i = 0; i < numberEvents; i++)
|
|
|
|
{
|
|
|
|
if (!input_recv_event(input, s))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-02-07 16:38:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2012-02-07 16:38:27 +04:00
|
|
|
}
|
|
|
|
|
2011-08-23 07:50:41 +04:00
|
|
|
void input_register_client_callbacks(rdpInput* input)
|
|
|
|
{
|
2011-10-16 08:50:10 +04:00
|
|
|
rdpRdp* rdp = input->context->rdp;
|
2011-08-23 07:50:41 +04:00
|
|
|
|
2012-11-08 03:23:25 +04:00
|
|
|
if (rdp->settings->FastPathInput)
|
2011-08-23 07:50:41 +04:00
|
|
|
{
|
|
|
|
input->SynchronizeEvent = input_send_fastpath_synchronize_event;
|
|
|
|
input->KeyboardEvent = input_send_fastpath_keyboard_event;
|
|
|
|
input->UnicodeKeyboardEvent = input_send_fastpath_unicode_keyboard_event;
|
|
|
|
input->MouseEvent = input_send_fastpath_mouse_event;
|
|
|
|
input->ExtendedMouseEvent = input_send_fastpath_extended_mouse_event;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
input->SynchronizeEvent = input_send_synchronize_event;
|
|
|
|
input->KeyboardEvent = input_send_keyboard_event;
|
|
|
|
input->UnicodeKeyboardEvent = input_send_unicode_keyboard_event;
|
|
|
|
input->MouseEvent = input_send_mouse_event;
|
|
|
|
input->ExtendedMouseEvent = input_send_extended_mouse_event;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
void freerdp_input_send_synchronize_event(rdpInput* input, UINT32 flags)
|
2012-02-14 02:51:42 +04:00
|
|
|
{
|
|
|
|
IFCALL(input->SynchronizeEvent, input, flags);
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void freerdp_input_send_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
|
2012-02-14 02:51:42 +04:00
|
|
|
{
|
|
|
|
IFCALL(input->KeyboardEvent, input, flags, code);
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
void freerdp_input_send_keyboard_event_ex(rdpInput* input, BOOL down, UINT32 rdp_scancode)
|
2012-09-22 22:27:30 +04:00
|
|
|
{
|
|
|
|
freerdp_input_send_keyboard_event(input,
|
|
|
|
(RDP_SCANCODE_EXTENDED(rdp_scancode) ? KBD_FLAGS_EXTENDED : 0) |
|
|
|
|
((down) ? KBD_FLAGS_DOWN : KBD_FLAGS_RELEASE),
|
|
|
|
RDP_SCANCODE_CODE(rdp_scancode));
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void freerdp_input_send_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
|
2012-02-14 02:51:42 +04:00
|
|
|
{
|
|
|
|
IFCALL(input->UnicodeKeyboardEvent, input, flags, code);
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void freerdp_input_send_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
|
2012-02-14 02:51:42 +04:00
|
|
|
{
|
|
|
|
IFCALL(input->MouseEvent, input, flags, x, y);
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void freerdp_input_send_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
|
2012-02-14 02:51:42 +04:00
|
|
|
{
|
|
|
|
IFCALL(input->ExtendedMouseEvent, input, flags, x, y);
|
|
|
|
}
|
|
|
|
|
2011-07-28 04:14:12 +04:00
|
|
|
rdpInput* input_new(rdpRdp* rdp)
|
|
|
|
{
|
|
|
|
rdpInput* input;
|
|
|
|
|
|
|
|
input = (rdpInput*) xzalloc(sizeof(rdpInput));
|
|
|
|
|
|
|
|
if (input != NULL)
|
|
|
|
{
|
2011-10-16 08:50:10 +04:00
|
|
|
|
2011-07-28 04:14:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
|
|
|
void input_free(rdpInput* input)
|
|
|
|
{
|
|
|
|
if (input != NULL)
|
|
|
|
{
|
2012-10-09 07:21:26 +04:00
|
|
|
free(input);
|
2011-07-28 04:14:12 +04:00
|
|
|
}
|
|
|
|
}
|