GUACAMOLE-518: Ensure all keys are released even if the key pressed client-side is unknown except through dead keys.

This commit is contained in:
Michael Jumper 2020-06-24 00:50:23 -07:00
parent 3798d85bd1
commit 628f2fd815

View File

@ -651,52 +651,47 @@ int guac_rdp_keyboard_update_keysym(guac_rdp_keyboard* keyboard,
* are tracked server-side, as well (to ensure that the key count remains * are tracked server-side, as well (to ensure that the key count remains
* correct, even if a user sends extra unbalanced or excessive press and * correct, even if a user sends extra unbalanced or excessive press and
* release events) */ * release events) */
if (key != NULL && source == GUAC_RDP_KEY_SOURCE_CLIENT) { if (source == GUAC_RDP_KEY_SOURCE_CLIENT && key != NULL) {
if (pressed && !key->user_pressed) { if (pressed && !key->user_pressed) {
keyboard->user_pressed_keys++; keyboard->user_pressed_keys++;
key->user_pressed = 1; key->user_pressed = 1;
} }
else if (!pressed && key->user_pressed) { else if (!pressed && key->user_pressed) {
keyboard->user_pressed_keys--; keyboard->user_pressed_keys--;
key->user_pressed = 0; key->user_pressed = 0;
}
}
/* Reset RDP server keyboard state (releasing any automatically /* Send events and update server-side lock state only if server-side key
* pressed keys) once all keys have been released on the client * state is changing (or if server-side state of this key is untracked) */
* side */ if (key == NULL || (pressed && key->pressed == NULL) || (!pressed && key->pressed != NULL)) {
if (keyboard->user_pressed_keys == 0)
guac_rdp_keyboard_reset(keyboard);
/* Toggle locks on keydown */
if (pressed)
keyboard->lock_flags ^= guac_rdp_keyboard_lock_flag(keysym);
/* If key is known, update state and attempt to send using normal RDP key
* events */
const guac_rdp_keysym_desc* definition = NULL;
if (key != NULL) {
definition = guac_rdp_keyboard_send_defined_key(keyboard, key, pressed);
key->pressed = pressed ? definition : NULL;
}
/* Fall back to dead keys or Unicode events if otherwise undefined inside
* current keymap (note that we only handle "pressed" here, as neither
* Unicode events nor dead keys can have a pressed/released state) */
if (definition == NULL && pressed) {
guac_rdp_keyboard_send_missing_key(keyboard, keysym);
} }
} }
/* If key is known, ignore the key event entirely if state is not actually /* Reset RDP server keyboard state (releasing any automatically
* changing */ * pressed keys) once all keys have been released on the client
if (key != NULL) { * side */
if ((!pressed && key->pressed == NULL) || (pressed && key->pressed != NULL)) if (source == GUAC_RDP_KEY_SOURCE_CLIENT && keyboard->user_pressed_keys == 0)
return 0; guac_rdp_keyboard_reset(keyboard);
}
/* Toggle locks on keydown */
if (pressed)
keyboard->lock_flags ^= guac_rdp_keyboard_lock_flag(keysym);
/* If key is known, update state and attempt to send using normal RDP key
* events */
const guac_rdp_keysym_desc* definition = NULL;
if (key != NULL) {
definition = guac_rdp_keyboard_send_defined_key(keyboard, key, pressed);
key->pressed = pressed ? definition : NULL;
}
/* Fall back to dead keys or Unicode events if otherwise undefined inside
* current keymap (note that we only handle "pressed" here, as neither
* Unicode events nor dead keys can have a pressed/released state) */
if (definition == NULL && pressed) {
guac_rdp_keyboard_send_missing_key(keyboard, keysym);
}
return 0; return 0;