Use correct names for key events

Replace definitions in ms-rdpbcgr.h marked as TODO with the
names defined in [MS-RDPBCGR]

Some other simplifications around the fake Unicode event processing
have also been made.
This commit is contained in:
matt335672 2024-06-19 17:20:25 +01:00
parent 43d6db45ed
commit ef14039c62
4 changed files with 59 additions and 62 deletions

View File

@ -480,13 +480,10 @@
#define RDP_INPUT_MOUSEX 0x8002
/* Keyboard Event: keyboardFlags (2.2.8.1.1.3.1.1.1) */
/* TODO: to be renamed */
#define KBD_FLAG_RIGHT 0x0001
#define KBD_FLAG_EXT 0x0100 /* KBDFLAGS_EXTENDED */
#define KBD_FLAG_EXT1 0x0200 /* KBDFLAGS_EXTENDED1 */
#define KBD_FLAG_QUIET 0x1000
#define KBD_FLAG_DOWN 0x4000
#define KBD_FLAG_UP 0x8000
#define KBDFLAGS_EXTENDED 0x0100
#define KBDFLAGS_EXTENDED1 0x0200
#define KBDFLAGS_DOWN 0x4000
#define KBDFLAGS_RELEASE 0x8000
/* Mouse Event: pointerFlags (2.2.8.1.1.3.1.1.3) */
#define PTRFLAGS_HWHEEL 0x0400
@ -505,10 +502,9 @@
#define PTRXFLAGS_BUTTON2 0x0002
/* Synchronize Event: toggleFlags (2.2.8.1.1.3.1.1.5) */
/* TODO: to be renamed */
#define KBD_FLAG_SCROLL 0x0001 /* TS_SYNC_SCROLL_LOCK */
#define KBD_FLAG_NUMLOCK 0x0002
#define KBD_FLAG_CAPITAL 0x0004
#define TS_SYNC_SCROLL_LOCK 0x0001
#define TS_SYNC_NUM_LOCK 0x0002
#define TS_SYNC_CAPS_LOCK 0x0004
#define TS_SYNC_KANA_LOCK 0x0008
/* Client Fast-Path Input Event PDU 2.2.8.1.2 */

View File

@ -151,6 +151,38 @@ xrdp_fastpath_send(struct xrdp_fastpath *self, struct stream *s)
return 0;
}
/*****************************************************************************/
/**
* Converts the fastpath keyboard event flags to slowpath event flags
* @param Faspath flags
* @return slowpath flags
*
* See [MMS-RDPBCGR] 2.2.8.1.1.3.1.1.1 and 2.2.8.1.2.2.1
*/
static int
get_slowpath_keyboard_event_flags(int fp_flags)
{
int flags = 0;
if (fp_flags & FASTPATH_INPUT_KBDFLAGS_RELEASE)
{
// Assume the key was down prior to this event - the fastpath
// message doesn't have a separate flag which maps to
// KBDFLAGS_DOWN
flags |= KBDFLAGS_DOWN | KBDFLAGS_RELEASE;
}
if (fp_flags & FASTPATH_INPUT_KBDFLAGS_EXTENDED)
{
flags |= KBDFLAGS_EXTENDED;
}
if (fp_flags & FASTPATH_INPUT_KBDFLAGS_EXTENDED1)
{
flags |= KBDFLAGS_EXTENDED1;
}
return flags;
}
/*****************************************************************************/
/* FASTPATH_INPUT_EVENT_SCANCODE */
static int
@ -159,7 +191,6 @@ xrdp_fastpath_process_EVENT_SCANCODE(struct xrdp_fastpath *self,
{
int flags;
int code;
flags = 0;
if (!s_check_rem_and_log(s, 1, "Parsing [MS-RDPBCGR] TS_FP_KEYBOARD_EVENT"))
{
@ -170,24 +201,7 @@ xrdp_fastpath_process_EVENT_SCANCODE(struct xrdp_fastpath *self,
"eventHeader.eventFlags 0x%2.2x, eventHeader.eventCode (ignored), "
"keyCode %d", eventFlags, code);
if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_RELEASE))
{
flags |= KBD_FLAG_UP;
}
else
{
flags |= KBD_FLAG_DOWN;
}
if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_EXTENDED))
{
flags |= KBD_FLAG_EXT;
}
if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_EXTENDED1))
{
flags |= KBD_FLAG_EXT1;
}
flags = get_slowpath_keyboard_event_flags(eventFlags);
xrdp_fastpath_session_callback(self, RDP_INPUT_SCANCODE,
code, 0, flags, 0);
@ -296,7 +310,6 @@ xrdp_fastpath_process_EVENT_UNICODE(struct xrdp_fastpath *self,
int flags;
int code;
flags = 0;
if (!s_check_rem_and_log(s, 2, "Parsing [MS-RDPBCGR] TS_FP_UNICODE_KEYBOARD_EVENT"))
{
return 1;
@ -307,18 +320,8 @@ xrdp_fastpath_process_EVENT_UNICODE(struct xrdp_fastpath *self,
"unicodeCode %d",
eventFlags, code);
if (eventFlags & FASTPATH_INPUT_KBDFLAGS_RELEASE)
{
flags |= KBD_FLAG_UP;
}
else
{
flags |= KBD_FLAG_DOWN;
}
if (eventFlags & FASTPATH_INPUT_KBDFLAGS_EXTENDED)
{
flags |= KBD_FLAG_EXT;
}
flags = get_slowpath_keyboard_event_flags(eventFlags);
xrdp_fastpath_session_callback(self, RDP_INPUT_UNICODE,
code, 0, flags, 0);
return 0;

View File

@ -50,7 +50,7 @@ get_key_info_from_kbd_event(int keyboard_flags, int key_code, int *keys,
int index;
shift = keys[42] || keys[54];
altgr_scancode = SCANCODE_FROM_KBD_EVENT(56, KBD_FLAG_EXT);
altgr_scancode = SCANCODE_FROM_KBD_EVENT(56, KBDFLAGS_EXTENDED);
altgr = keys[scancode_to_index(altgr_scancode)]; /* right alt */
rv = 0;
@ -158,7 +158,7 @@ key_to_scancode_index(const char *key)
{
if (key[1] == '0')
{
keyboard_flags |= KBD_FLAG_EXT;
keyboard_flags |= KBDFLAGS_EXTENDED;
key += 3;
}
}

View File

@ -1578,7 +1578,7 @@ xrdp_wm_key(struct xrdp_wm *self, int keyboard_flags, int key_code)
"xrdp_wm_key: RDP key_code:0x%04x, keyboard_flags: 0x%04x",
key_code, keyboard_flags);
int scancode = SCANCODE_FROM_KBD_EVENT(key_code, keyboard_flags);
int keyup = ((keyboard_flags & KBD_FLAG_UP) != 0);
int keyup = ((keyboard_flags & KBDFLAGS_RELEASE) != 0);
int sindex = scancode_to_index(scancode);
if (sindex < 0)
@ -1695,7 +1695,7 @@ get_unicode_character(struct xrdp_wm *self, int device_flags, char16_t c16)
char32_t c32 = 0;
int *high_ptr;
if (device_flags & KBD_FLAG_UP)
if (device_flags & KBDFLAGS_RELEASE)
{
high_ptr = &self->last_high_surrogate_key_up;
}
@ -1745,7 +1745,7 @@ fake_kbd_event_from_scancode_index(struct xrdp_wm *self, int device_flags,
int scancode = scancode_from_index(index);
int key_code = SCANCODE_TO_KBD_EVENT_KEY_CODE(scancode);
device_flags &= ~(KBD_FLAG_EXT | KBD_FLAG_EXT1);
device_flags &= ~(KBDFLAGS_EXTENDED | KBDFLAGS_EXTENDED1);
device_flags |= SCANCODE_TO_KBD_EVENT_KBD_FLAGS(scancode);
xrdp_wm_key(self, device_flags, key_code);
@ -1778,14 +1778,14 @@ xrdp_wm_key_unicode(struct xrdp_wm *self, int device_flags, char32_t c16)
{
if (c32 == self->keymap.keys_shift[index].chr)
{
if (device_flags & KBD_FLAG_UP)
if (device_flags & KBDFLAGS_RELEASE)
{
fake_kbd_event_from_scancode_index(self, device_flags, index);
xrdp_wm_key(self, KBD_FLAG_UP, XR_RDP_SCAN_LSHIFT);
xrdp_wm_key(self, device_flags, XR_RDP_SCAN_LSHIFT);
}
else
{
xrdp_wm_key(self, KBD_FLAG_DOWN, XR_RDP_SCAN_LSHIFT);
xrdp_wm_key(self, device_flags, XR_RDP_SCAN_LSHIFT);
fake_kbd_event_from_scancode_index(self, device_flags, index);
}
return 0;
@ -1796,16 +1796,14 @@ xrdp_wm_key_unicode(struct xrdp_wm *self, int device_flags, char32_t c16)
{
if (c32 == self->keymap.keys_altgr[index].chr)
{
if (device_flags & KBD_FLAG_UP)
if (device_flags & KBDFLAGS_RELEASE)
{
fake_kbd_event_from_scancode_index(self, device_flags, index);
xrdp_wm_key(self, KBD_FLAG_UP | KBD_FLAG_EXT,
XR_RDP_SCAN_ALT);
xrdp_wm_key(self, device_flags, XR_RDP_SCAN_ALT);
}
else
{
xrdp_wm_key(self, KBD_FLAG_DOWN | KBD_FLAG_EXT,
XR_RDP_SCAN_ALT);
xrdp_wm_key(self, device_flags, XR_RDP_SCAN_ALT);
fake_kbd_event_from_scancode_index(self, device_flags, index);
}
return 0;
@ -1816,16 +1814,16 @@ xrdp_wm_key_unicode(struct xrdp_wm *self, int device_flags, char32_t c16)
{
if (c32 == self->keymap.keys_shiftaltgr[index].chr)
{
if (device_flags & KBD_FLAG_UP)
if (device_flags & KBDFLAGS_RELEASE)
{
fake_kbd_event_from_scancode_index(self, device_flags, index);
xrdp_wm_key(self, KBD_FLAG_UP | KBD_FLAG_EXT, XR_RDP_SCAN_ALT);
xrdp_wm_key(self, KBD_FLAG_UP, XR_RDP_SCAN_LSHIFT);
xrdp_wm_key(self, device_flags | KBDFLAGS_EXTENDED, XR_RDP_SCAN_ALT);
xrdp_wm_key(self, device_flags, XR_RDP_SCAN_LSHIFT);
}
else
{
xrdp_wm_key(self, KBD_FLAG_DOWN, XR_RDP_SCAN_LSHIFT);
xrdp_wm_key(self, KBD_FLAG_DOWN | KBD_FLAG_EXT,
xrdp_wm_key(self, device_flags, XR_RDP_SCAN_LSHIFT);
xrdp_wm_key(self, device_flags | KBDFLAGS_EXTENDED,
XR_RDP_SCAN_ALT);
fake_kbd_event_from_scancode_index(self, device_flags, index);
}
@ -1840,7 +1838,7 @@ xrdp_wm_key_unicode(struct xrdp_wm *self, int device_flags, char32_t c16)
self->mm->chan_trans->status == TRANS_STATUS_UP)
{
xrdp_mm_send_unicode_to_chansrv(self->mm,
!(device_flags & KBD_FLAG_UP), c32);
!(device_flags & KBDFLAGS_RELEASE), c32);
return 0;
}