FreeRDP/libfreerdp/core/input.c

804 lines
21 KiB
C
Raw Normal View History

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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <winpr/crt.h>
#include <winpr/assert.h>
2012-02-14 02:51:42 +04:00
#include <freerdp/input.h>
#include <freerdp/log.h>
2012-02-14 02:51:42 +04:00
#include "message.h"
2011-07-28 04:14:12 +04:00
#include "input.h"
#define TAG FREERDP_TAG("core")
/* Input Events */
2019-11-06 17:24:51 +03:00
#define INPUT_EVENT_SYNC 0x0000
#define INPUT_EVENT_SCANCODE 0x0004
#define INPUT_EVENT_UNICODE 0x0005
#define INPUT_EVENT_MOUSE 0x8001
#define INPUT_EVENT_MOUSEX 0x8002
2019-11-06 17:24:51 +03:00
#define RDP_CLIENT_INPUT_PDU_HEADER_LENGTH 4
static void rdp_write_client_input_pdu_header(wStream* s, UINT16 number)
2011-07-28 04:14:12 +04:00
{
2013-05-09 00:09:16 +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
}
static void rdp_write_input_event_header(wStream* s, UINT32 time, UINT16 type)
{
2013-05-09 00:09:16 +04:00
Stream_Write_UINT32(s, time); /* eventTime (4 bytes) */
Stream_Write_UINT16(s, type); /* messageType (2 bytes) */
}
static wStream* rdp_client_input_pdu_init(rdpRdp* rdp, UINT16 type)
2011-07-28 04:14:12 +04:00
{
wStream* s;
2011-07-28 04:14:12 +04:00
s = rdp_data_pdu_init(rdp);
if (!s)
return NULL;
2011-07-28 04:14:12 +04:00
rdp_write_client_input_pdu_header(s, 1);
rdp_write_input_event_header(s, 0, type);
2011-07-28 04:14:12 +04:00
return s;
}
static BOOL rdp_send_client_input_pdu(rdpRdp* rdp, wStream* s)
2011-07-28 04:14:12 +04:00
{
return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_INPUT, rdp->mcs->userId);
2011-07-28 04:14:12 +04:00
}
static void input_write_synchronize_event(wStream* s, UINT32 flags)
2011-07-28 04:14:12 +04:00
{
2019-11-06 17:24:51 +03:00
Stream_Write_UINT16(s, 0); /* pad2Octets (2 bytes) */
2013-05-09 00:09:16 +04:00
Stream_Write_UINT32(s, flags); /* toggleFlags (4 bytes) */
2011-07-28 04:14:12 +04:00
}
static BOOL input_send_synchronize_event(rdpInput* input, UINT32 flags)
2011-07-28 04:14:12 +04:00
{
wStream* s;
rdpRdp* rdp;
if (!input || !input->context)
return FALSE;
rdp = input->context->rdp;
s = rdp_client_input_pdu_init(rdp, INPUT_EVENT_SYNC);
if (!s)
return FALSE;
2011-07-28 04:14:12 +04:00
input_write_synchronize_event(s, flags);
return rdp_send_client_input_pdu(rdp, s);
2011-07-28 04:14:12 +04:00
}
static void input_write_keyboard_event(wStream* s, UINT16 flags, UINT16 code)
2011-07-28 04:14:12 +04:00
{
2013-05-09 00:09:16 +04:00
Stream_Write_UINT16(s, flags); /* keyboardFlags (2 bytes) */
2019-11-06 17:24:51 +03:00
Stream_Write_UINT16(s, code); /* keyCode (2 bytes) */
Stream_Write_UINT16(s, 0); /* pad2Octets (2 bytes) */
2011-07-28 04:14:12 +04:00
}
static BOOL input_send_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
2011-07-28 04:14:12 +04:00
{
wStream* s;
rdpRdp* rdp;
if (!input || !input->context)
return FALSE;
rdp = input->context->rdp;
s = rdp_client_input_pdu_init(rdp, INPUT_EVENT_SCANCODE);
if (!s)
return FALSE;
2011-07-28 04:14:12 +04:00
input_write_keyboard_event(s, flags, code);
return rdp_send_client_input_pdu(rdp, s);
2011-07-28 04:14:12 +04:00
}
static void input_write_unicode_keyboard_event(wStream* s, UINT16 flags, UINT16 code)
2011-07-28 04:14:12 +04:00
{
2013-05-09 00:09:16 +04:00
Stream_Write_UINT16(s, flags); /* keyboardFlags (2 bytes) */
2019-11-06 17:24:51 +03:00
Stream_Write_UINT16(s, code); /* unicodeCode (2 bytes) */
Stream_Write_UINT16(s, 0); /* pad2Octets (2 bytes) */
2011-07-28 04:14:12 +04:00
}
static BOOL input_send_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
2011-07-28 04:14:12 +04:00
{
wStream* s;
rdpRdp* rdp;
if (!input || !input->context)
return FALSE;
if (!input->context->settings->UnicodeInput)
{
WLog_WARN(TAG, "Unicode input not supported by server.");
return FALSE;
}
rdp = input->context->rdp;
s = rdp_client_input_pdu_init(rdp, INPUT_EVENT_UNICODE);
if (!s)
return FALSE;
input_write_unicode_keyboard_event(s, flags, code);
return rdp_send_client_input_pdu(rdp, s);
2011-07-28 04:14:12 +04:00
}
static void input_write_mouse_event(wStream* s, UINT16 flags, UINT16 x, UINT16 y)
2011-07-28 04:14:12 +04:00
{
2013-05-09 00:09:16 +04:00
Stream_Write_UINT16(s, flags); /* pointerFlags (2 bytes) */
2019-11-06 17:24:51 +03:00
Stream_Write_UINT16(s, x); /* xPos (2 bytes) */
Stream_Write_UINT16(s, y); /* yPos (2 bytes) */
2011-07-28 04:14:12 +04:00
}
static BOOL input_send_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
2011-07-28 04:14:12 +04:00
{
wStream* s;
rdpRdp* rdp;
if (!input || !input->context || !input->context->settings)
return FALSE;
rdp = input->context->rdp;
if (!input->context->settings->HasHorizontalWheel)
{
if (flags & PTR_FLAGS_HWHEEL)
{
2019-05-16 16:14:16 +03:00
WLog_WARN(TAG,
2019-11-06 17:24:51 +03:00
"skip mouse event %" PRIu16 "x%" PRIu16 " flags=0x%04" PRIX16
", no horizontal mouse wheel supported",
x, y, flags);
return TRUE;
}
}
s = rdp_client_input_pdu_init(rdp, INPUT_EVENT_MOUSE);
if (!s)
return FALSE;
2011-07-28 04:14:12 +04:00
input_write_mouse_event(s, flags, x, y);
return rdp_send_client_input_pdu(rdp, s);
2011-07-28 04:14:12 +04:00
}
static void input_write_extended_mouse_event(wStream* s, UINT16 flags, UINT16 x, UINT16 y)
2011-07-28 04:14:12 +04:00
{
2013-05-09 00:09:16 +04:00
Stream_Write_UINT16(s, flags); /* pointerFlags (2 bytes) */
2019-11-06 17:24:51 +03:00
Stream_Write_UINT16(s, x); /* xPos (2 bytes) */
Stream_Write_UINT16(s, y); /* yPos (2 bytes) */
2011-07-28 04:14:12 +04:00
}
2019-11-06 17:24:51 +03:00
static BOOL input_send_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
2011-07-28 04:14:12 +04:00
{
wStream* s;
rdpRdp* rdp;
if (!input || !input->context)
return FALSE;
if (!input->context->settings->HasExtendedMouseEvent)
{
2019-05-16 16:14:16 +03:00
WLog_WARN(TAG,
2019-11-06 17:24:51 +03:00
"skip extended mouse event %" PRIu16 "x%" PRIu16 " flags=0x%04" PRIX16
", no extended mouse events supported",
x, y, flags);
return TRUE;
}
rdp = input->context->rdp;
s = rdp_client_input_pdu_init(rdp, INPUT_EVENT_MOUSEX);
if (!s)
return FALSE;
2011-07-28 04:14:12 +04:00
input_write_extended_mouse_event(s, flags, x, y);
return rdp_send_client_input_pdu(rdp, s);
2011-07-28 04:14:12 +04:00
}
static BOOL input_send_focus_in_event(rdpInput* input, UINT16 toggleStates)
{
/* send a tab up like mstsc.exe */
if (!input_send_keyboard_event(input, KBD_FLAGS_RELEASE, 0x0f))
return FALSE;
/* send the toggle key states */
if (!input_send_synchronize_event(input, (toggleStates & 0x1F)))
return FALSE;
/* send another tab up like mstsc.exe */
return input_send_keyboard_event(input, KBD_FLAGS_RELEASE, 0x0f);
}
static BOOL input_send_keyboard_pause_event(rdpInput* input)
{
/* In ancient days, pause-down without control sent E1 1D 45 E1 9D C5,
* and pause-up sent nothing. However, reverse engineering mstsc shows
* it sending the following sequence:
*/
/* Control down (0x1D) */
2019-05-16 16:14:16 +03:00
if (!input_send_keyboard_event(input, KBD_FLAGS_EXTENDED1,
RDP_SCANCODE_CODE(RDP_SCANCODE_LCONTROL)))
return FALSE;
/* Numlock down (0x45) */
2019-11-06 17:24:51 +03:00
if (!input_send_keyboard_event(input, 0, RDP_SCANCODE_CODE(RDP_SCANCODE_NUMLOCK)))
return FALSE;
/* Control up (0x1D) */
2019-05-16 16:14:16 +03:00
if (!input_send_keyboard_event(input, KBD_FLAGS_RELEASE | KBD_FLAGS_EXTENDED1,
RDP_SCANCODE_CODE(RDP_SCANCODE_LCONTROL)))
return FALSE;
/* Numlock up (0x45) */
return input_send_keyboard_event(input, KBD_FLAGS_RELEASE,
RDP_SCANCODE_CODE(RDP_SCANCODE_NUMLOCK));
}
static BOOL input_send_fastpath_synchronize_event(rdpInput* input, UINT32 flags)
{
wStream* s;
rdpRdp* rdp;
if (!input || !input->context)
return FALSE;
rdp = input->context->rdp;
/* The FastPath Synchronization eventFlags has identical values as SlowPath */
2019-11-06 17:24:51 +03:00
s = fastpath_input_pdu_init(rdp->fastpath, (BYTE)flags, FASTPATH_INPUT_EVENT_SYNC);
if (!s)
return FALSE;
return fastpath_send_input_pdu(rdp->fastpath, s);
}
static BOOL input_send_fastpath_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
{
wStream* s;
BYTE eventFlags = 0;
rdpRdp* rdp;
if (!input || !input->context)
return FALSE;
rdp = input->context->rdp;
eventFlags |= (flags & KBD_FLAGS_RELEASE) ? FASTPATH_INPUT_KBDFLAGS_RELEASE : 0;
eventFlags |= (flags & KBD_FLAGS_EXTENDED) ? FASTPATH_INPUT_KBDFLAGS_EXTENDED : 0;
2019-05-16 16:14:16 +03:00
eventFlags |= (flags & KBD_FLAGS_EXTENDED1) ? FASTPATH_INPUT_KBDFLAGS_PREFIX_E1 : 0;
2011-08-23 11:51:51 +04:00
s = fastpath_input_pdu_init(rdp->fastpath, eventFlags, FASTPATH_INPUT_EVENT_SCANCODE);
if (!s)
return FALSE;
WINPR_ASSERT(code <= UINT8_MAX);
Stream_Write_UINT8(s, (UINT8)code); /* keyCode (1 byte) */
return fastpath_send_input_pdu(rdp->fastpath, s);
}
static BOOL input_send_fastpath_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
{
wStream* s;
BYTE eventFlags = 0;
rdpRdp* rdp;
if (!input || !input->context)
return FALSE;
if (!input->context->settings->UnicodeInput)
{
WLog_WARN(TAG, "Unicode input not supported by server.");
return FALSE;
}
rdp = input->context->rdp;
eventFlags |= (flags & KBD_FLAGS_RELEASE) ? FASTPATH_INPUT_KBDFLAGS_RELEASE : 0;
s = fastpath_input_pdu_init(rdp->fastpath, eventFlags, FASTPATH_INPUT_EVENT_UNICODE);
if (!s)
return FALSE;
2013-05-09 00:09:16 +04:00
Stream_Write_UINT16(s, code); /* unicodeCode (2 bytes) */
return fastpath_send_input_pdu(rdp->fastpath, s);
}
2019-11-06 17:24:51 +03:00
static BOOL input_send_fastpath_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
{
wStream* s;
rdpRdp* rdp;
if (!input || !input->context || !input->context->settings)
return FALSE;
rdp = input->context->rdp;
2011-08-23 11:51:51 +04:00
if (!input->context->settings->HasHorizontalWheel)
{
if (flags & PTR_FLAGS_HWHEEL)
{
2019-05-16 16:14:16 +03:00
WLog_WARN(TAG,
2019-11-06 17:24:51 +03:00
"skip mouse event %" PRIu16 "x%" PRIu16 " flags=0x%04" PRIX16
", no horizontal mouse wheel supported",
x, y, flags);
return TRUE;
}
}
2011-08-23 11:51:51 +04:00
s = fastpath_input_pdu_init(rdp->fastpath, 0, FASTPATH_INPUT_EVENT_MOUSE);
if (!s)
return FALSE;
input_write_mouse_event(s, flags, x, y);
return fastpath_send_input_pdu(rdp->fastpath, s);
}
2019-11-06 17:24:51 +03:00
static BOOL input_send_fastpath_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x,
UINT16 y)
{
wStream* s;
rdpRdp* rdp;
if (!input || !input->context)
return FALSE;
if (!input->context->settings->HasExtendedMouseEvent)
{
2019-05-16 16:14:16 +03:00
WLog_WARN(TAG,
2019-11-06 17:24:51 +03:00
"skip extended mouse event %" PRIu16 "x%" PRIu16 " flags=0x%04" PRIX16
", no extended mouse events supported",
x, y, flags);
return TRUE;
}
rdp = input->context->rdp;
2011-08-23 11:51:51 +04:00
s = fastpath_input_pdu_init(rdp->fastpath, 0, FASTPATH_INPUT_EVENT_MOUSEX);
if (!s)
return FALSE;
input_write_extended_mouse_event(s, flags, x, y);
return fastpath_send_input_pdu(rdp->fastpath, s);
}
static BOOL input_send_fastpath_focus_in_event(rdpInput* input, UINT16 toggleStates)
{
wStream* s;
BYTE eventFlags = 0;
rdpRdp* rdp;
if (!input || !input->context)
return FALSE;
rdp = input->context->rdp;
s = fastpath_input_pdu_init_header(rdp->fastpath);
if (!s)
return FALSE;
/* send a tab up like mstsc.exe */
eventFlags = FASTPATH_INPUT_KBDFLAGS_RELEASE | FASTPATH_INPUT_EVENT_SCANCODE << 5;
2013-05-09 00:09:16 +04:00
Stream_Write_UINT8(s, eventFlags); /* Key Release event (1 byte) */
2019-11-06 17:24:51 +03:00
Stream_Write_UINT8(s, 0x0f); /* keyCode (1 byte) */
/* send the toggle key states */
eventFlags = (toggleStates & 0x1F) | FASTPATH_INPUT_EVENT_SYNC << 5;
2013-05-09 00:09:16 +04:00
Stream_Write_UINT8(s, eventFlags); /* toggle state (1 byte) */
/* send another tab up like mstsc.exe */
eventFlags = FASTPATH_INPUT_KBDFLAGS_RELEASE | FASTPATH_INPUT_EVENT_SCANCODE << 5;
2013-05-09 00:09:16 +04:00
Stream_Write_UINT8(s, eventFlags); /* Key Release event (1 byte) */
2019-11-06 17:24:51 +03:00
Stream_Write_UINT8(s, 0x0f); /* keyCode (1 byte) */
return fastpath_send_multiple_input_pdu(rdp->fastpath, s, 3);
}
static BOOL input_send_fastpath_keyboard_pause_event(rdpInput* input)
{
/* In ancient days, pause-down without control sent E1 1D 45 E1 9D C5,
* and pause-up sent nothing. However, reverse engineering mstsc shows
* it sending the following sequence:
*/
wStream* s;
const BYTE keyDownEvent = FASTPATH_INPUT_EVENT_SCANCODE << 5;
2019-11-06 17:24:51 +03:00
const BYTE keyUpEvent = (FASTPATH_INPUT_EVENT_SCANCODE << 5) | FASTPATH_INPUT_KBDFLAGS_RELEASE;
rdpRdp* rdp;
if (!input || !input->context)
return FALSE;
rdp = input->context->rdp;
s = fastpath_input_pdu_init_header(rdp->fastpath);
if (!s)
return FALSE;
/* Control down (0x1D) */
Stream_Write_UINT8(s, keyDownEvent | FASTPATH_INPUT_KBDFLAGS_PREFIX_E1);
Stream_Write_UINT8(s, RDP_SCANCODE_CODE(RDP_SCANCODE_LCONTROL));
/* Numlock down (0x45) */
Stream_Write_UINT8(s, keyDownEvent);
Stream_Write_UINT8(s, RDP_SCANCODE_CODE(RDP_SCANCODE_NUMLOCK));
/* Control up (0x1D) */
Stream_Write_UINT8(s, keyUpEvent | FASTPATH_INPUT_KBDFLAGS_PREFIX_E1);
Stream_Write_UINT8(s, RDP_SCANCODE_CODE(RDP_SCANCODE_LCONTROL));
/* Numlock down (0x45) */
Stream_Write_UINT8(s, keyUpEvent);
Stream_Write_UINT8(s, RDP_SCANCODE_CODE(RDP_SCANCODE_NUMLOCK));
return fastpath_send_multiple_input_pdu(rdp->fastpath, s, 4);
}
static BOOL input_recv_sync_event(rdpInput* input, wStream* s)
{
2012-10-09 11:26:39 +04:00
UINT32 toggleFlags;
if (Stream_GetRemainingLength(s) < 6)
return FALSE;
2019-11-06 17:24:51 +03:00
Stream_Seek(s, 2); /* pad2Octets (2 bytes) */
2013-05-09 00:09:16 +04:00
Stream_Read_UINT32(s, toggleFlags); /* toggleFlags (4 bytes) */
return IFCALLRESULT(TRUE, input->SynchronizeEvent, input, toggleFlags);
}
static BOOL input_recv_keyboard_event(rdpInput* input, wStream* s)
{
UINT16 keyboardFlags, keyCode;
if (Stream_GetRemainingLength(s) < 6)
return FALSE;
2013-05-09 00:09:16 +04:00
Stream_Read_UINT16(s, keyboardFlags); /* keyboardFlags (2 bytes) */
2019-11-06 17:24:51 +03:00
Stream_Read_UINT16(s, keyCode); /* keyCode (2 bytes) */
Stream_Seek(s, 2); /* pad2Octets (2 bytes) */
/**
* Note: A lot of code in FreeRDP and in dependent projects checks the
* KBDFLAGS_DOWN flag in order to detect a key press.
* According to the specs only the absence of the slow-path
* KBDFLAGS_RELEASE flag indicates a key-down event.
* The slow-path KBDFLAGS_DOWN flag merely indicates that the key was
* down prior to this event.
* The checks for KBDFLAGS_DOWN only work successfully because the code
* handling the fast-path keyboard input sets the KBDFLAGS_DOWN flag if
* the FASTPATH_INPUT_KBDFLAGS_RELEASE flag is missing.
* Since the same input callback is used for slow- and fast-path events
* we have to follow that "convention" here.
*/
if (keyboardFlags & KBD_FLAGS_RELEASE)
keyboardFlags &= ~KBD_FLAGS_DOWN;
else
keyboardFlags |= KBD_FLAGS_DOWN;
return IFCALLRESULT(TRUE, input->KeyboardEvent, input, keyboardFlags, keyCode);
}
static BOOL input_recv_unicode_keyboard_event(rdpInput* input, wStream* s)
{
UINT16 keyboardFlags, unicodeCode;
if (Stream_GetRemainingLength(s) < 6)
return FALSE;
2013-05-09 00:09:16 +04:00
Stream_Read_UINT16(s, keyboardFlags); /* keyboardFlags (2 bytes) */
2019-11-06 17:24:51 +03:00
Stream_Read_UINT16(s, unicodeCode); /* unicodeCode (2 bytes) */
Stream_Seek(s, 2); /* pad2Octets (2 bytes) */
/* "fix" keyboardFlags - see comment in input_recv_keyboard_event() */
if (keyboardFlags & KBD_FLAGS_RELEASE)
keyboardFlags &= ~KBD_FLAGS_DOWN;
else
keyboardFlags |= KBD_FLAGS_DOWN;
return IFCALLRESULT(TRUE, input->UnicodeKeyboardEvent, input, keyboardFlags, unicodeCode);
}
static BOOL input_recv_mouse_event(rdpInput* input, wStream* s)
{
UINT16 pointerFlags, xPos, yPos;
if (Stream_GetRemainingLength(s) < 6)
return FALSE;
2013-05-09 00:09:16 +04:00
Stream_Read_UINT16(s, pointerFlags); /* pointerFlags (2 bytes) */
2019-11-06 17:24:51 +03:00
Stream_Read_UINT16(s, xPos); /* xPos (2 bytes) */
Stream_Read_UINT16(s, yPos); /* yPos (2 bytes) */
return IFCALLRESULT(TRUE, input->MouseEvent, input, pointerFlags, xPos, yPos);
}
static BOOL input_recv_extended_mouse_event(rdpInput* input, wStream* s)
{
UINT16 pointerFlags, xPos, yPos;
if (Stream_GetRemainingLength(s) < 6)
return FALSE;
2013-05-09 00:09:16 +04:00
Stream_Read_UINT16(s, pointerFlags); /* pointerFlags (2 bytes) */
2019-11-06 17:24:51 +03:00
Stream_Read_UINT16(s, xPos); /* xPos (2 bytes) */
Stream_Read_UINT16(s, yPos); /* yPos (2 bytes) */
return IFCALLRESULT(TRUE, input->ExtendedMouseEvent, input, pointerFlags, xPos, yPos);
}
static BOOL input_recv_event(rdpInput* input, wStream* s)
{
UINT16 messageType;
if (Stream_GetRemainingLength(s) < 6)
return FALSE;
2019-11-06 17:24:51 +03:00
Stream_Seek(s, 4); /* eventTime (4 bytes), ignored by the server */
2013-05-09 00:09:16 +04:00
Stream_Read_UINT16(s, messageType); /* messageType (2 bytes) */
switch (messageType)
{
case INPUT_EVENT_SYNC:
if (!input_recv_sync_event(input, s))
return FALSE;
break;
case INPUT_EVENT_SCANCODE:
if (!input_recv_keyboard_event(input, s))
return FALSE;
break;
case INPUT_EVENT_UNICODE:
if (!input_recv_unicode_keyboard_event(input, s))
return FALSE;
break;
case INPUT_EVENT_MOUSE:
if (!input_recv_mouse_event(input, s))
return FALSE;
break;
case INPUT_EVENT_MOUSEX:
if (!input_recv_extended_mouse_event(input, s))
return FALSE;
break;
default:
2019-11-06 17:24:51 +03:00
WLog_ERR(TAG, "Unknown messageType %" PRIu16 "", messageType);
/* Each input event uses 6 bytes. */
Stream_Seek(s, 6);
break;
}
return TRUE;
}
BOOL input_recv(rdpInput* input, wStream* s)
{
UINT16 i, numberEvents;
if (!input || !s)
return FALSE;
if (Stream_GetRemainingLength(s) < 4)
return FALSE;
2013-05-09 00:09:16 +04:00
Stream_Read_UINT16(s, numberEvents); /* numberEvents (2 bytes) */
2019-11-06 17:24:51 +03:00
Stream_Seek(s, 2); /* pad2Octets (2 bytes) */
/* Each input event uses 6 exactly bytes. */
if (Stream_GetRemainingLength(s) < (size_t)(6 * numberEvents))
return FALSE;
for (i = 0; i < numberEvents; i++)
{
if (!input_recv_event(input, s))
return FALSE;
}
return TRUE;
}
BOOL input_register_client_callbacks(rdpInput* input)
2011-08-23 07:50:41 +04:00
{
rdpSettings* settings;
if (!input || !input->context)
return FALSE;
settings = input->context->settings;
if (!settings)
return FALSE;
2011-08-23 07:50:41 +04:00
if (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->KeyboardPauseEvent = input_send_fastpath_keyboard_pause_event;
2011-08-23 07:50:41 +04:00
input->UnicodeKeyboardEvent = input_send_fastpath_unicode_keyboard_event;
input->MouseEvent = input_send_fastpath_mouse_event;
input->ExtendedMouseEvent = input_send_fastpath_extended_mouse_event;
input->FocusInEvent = input_send_fastpath_focus_in_event;
2011-08-23 07:50:41 +04:00
}
else
{
input->SynchronizeEvent = input_send_synchronize_event;
input->KeyboardEvent = input_send_keyboard_event;
input->KeyboardPauseEvent = input_send_keyboard_pause_event;
2011-08-23 07:50:41 +04:00
input->UnicodeKeyboardEvent = input_send_unicode_keyboard_event;
input->MouseEvent = input_send_mouse_event;
input->ExtendedMouseEvent = input_send_extended_mouse_event;
input->FocusInEvent = input_send_focus_in_event;
2011-08-23 07:50:41 +04:00
}
input->asynchronous = settings->AsyncInput;
if (input->asynchronous)
{
input->proxy = input_message_proxy_new(input);
if (!input->proxy)
return FALSE;
}
return TRUE;
2011-08-23 07:50:41 +04:00
}
BOOL freerdp_input_send_synchronize_event(rdpInput* input, UINT32 flags)
2012-02-14 02:51:42 +04:00
{
if (!input || !input->context)
return FALSE;
if (freerdp_settings_get_bool(input->context->settings, FreeRDP_SuspendInput))
return TRUE;
return IFCALLRESULT(TRUE, input->SynchronizeEvent, input, flags);
2012-02-14 02:51:42 +04:00
}
BOOL freerdp_input_send_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
2012-02-14 02:51:42 +04:00
{
if (!input || !input->context)
return FALSE;
if (freerdp_settings_get_bool(input->context->settings, FreeRDP_SuspendInput))
return TRUE;
return IFCALLRESULT(TRUE, input->KeyboardEvent, input, flags, code);
2012-02-14 02:51:42 +04:00
}
BOOL freerdp_input_send_keyboard_event_ex(rdpInput* input, BOOL down, UINT32 rdp_scancode)
{
2019-11-06 17:24:51 +03:00
return freerdp_input_send_keyboard_event(
input,
(RDP_SCANCODE_EXTENDED(rdp_scancode) ? KBD_FLAGS_EXTENDED : 0) |
((down) ? KBD_FLAGS_DOWN : KBD_FLAGS_RELEASE),
2019-11-06 17:24:51 +03:00
RDP_SCANCODE_CODE(rdp_scancode));
}
BOOL freerdp_input_send_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
2012-02-14 02:51:42 +04:00
{
if (!input || !input->context)
return FALSE;
if (freerdp_settings_get_bool(input->context->settings, FreeRDP_SuspendInput))
return TRUE;
return IFCALLRESULT(TRUE, input->UnicodeKeyboardEvent, input, flags, code);
2012-02-14 02:51:42 +04:00
}
BOOL freerdp_input_send_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
2012-02-14 02:51:42 +04:00
{
if (!input || !input->context)
return FALSE;
if (freerdp_settings_get_bool(input->context->settings, FreeRDP_SuspendInput))
return TRUE;
return IFCALLRESULT(TRUE, input->MouseEvent, input, flags, x, y);
2012-02-14 02:51:42 +04:00
}
BOOL freerdp_input_send_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
2012-02-14 02:51:42 +04:00
{
if (!input || !input->context)
return FALSE;
if (freerdp_settings_get_bool(input->context->settings, FreeRDP_SuspendInput))
return TRUE;
return IFCALLRESULT(TRUE, input->ExtendedMouseEvent, input, flags, x, y);
2012-02-14 02:51:42 +04:00
}
BOOL freerdp_input_send_focus_in_event(rdpInput* input, UINT16 toggleStates)
{
if (!input || !input->context)
return FALSE;
if (freerdp_settings_get_bool(input->context->settings, FreeRDP_SuspendInput))
return TRUE;
return IFCALLRESULT(TRUE, input->FocusInEvent, input, toggleStates);
}
BOOL freerdp_input_send_keyboard_pause_event(rdpInput* input)
{
if (!input || !input->context)
return FALSE;
if (freerdp_settings_get_bool(input->context->settings, FreeRDP_SuspendInput))
return TRUE;
return IFCALLRESULT(TRUE, input->KeyboardPauseEvent, input);
}
int input_process_events(rdpInput* input)
{
if (!input)
return FALSE;
return input_message_queue_process_pending_messages(input);
}
static void input_free_queued_message(void* obj)
{
wMessage* msg = (wMessage*)obj;
input_message_queue_free_message(msg);
}
2011-07-28 04:14:12 +04:00
rdpInput* input_new(rdpRdp* rdp)
{
const wObject cb = { NULL, NULL, NULL, input_free_queued_message, NULL };
2011-07-28 04:14:12 +04:00
rdpInput* input;
2019-11-06 17:24:51 +03:00
input = (rdpInput*)calloc(1, sizeof(rdpInput));
if (!input)
return NULL;
2011-07-28 04:14:12 +04:00
input->queue = MessageQueue_New(&cb);
if (!input->queue)
2011-07-28 04:14:12 +04:00
{
free(input);
return NULL;
2011-07-28 04:14:12 +04:00
}
return input;
}
void input_free(rdpInput* input)
{
if (input != NULL)
{
if (input->asynchronous)
input_message_proxy_free(input->proxy);
MessageQueue_Free(input->queue);
free(input);
2011-07-28 04:14:12 +04:00
}
}