2016-08-13 17:33:30 -07:00
|
|
|
/*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you 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.
|
|
|
|
*/
|
|
|
|
|
2020-01-04 11:43:32 -08:00
|
|
|
#include "decompose.h"
|
|
|
|
#include "keyboard.h"
|
|
|
|
#include "keymap.h"
|
2019-12-23 13:29:13 -08:00
|
|
|
#include "rdp.h"
|
2016-08-13 17:33:30 -07:00
|
|
|
|
|
|
|
#include <freerdp/freerdp.h>
|
|
|
|
#include <freerdp/input.h>
|
|
|
|
#include <guacamole/client.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2020-06-21 20:59:11 -07:00
|
|
|
/**
|
|
|
|
* Translates the given keysym into the corresponding modifier flag, as defined
|
|
|
|
* by keymap.h. If the given keysym does not represent a modifier key, zero is
|
|
|
|
* returned.
|
|
|
|
*
|
|
|
|
* @param keysym
|
|
|
|
* The keysym to translate into a modifier flag.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* The modifier flag which corresponds to the given keysym, or zero if the
|
|
|
|
* given keysym does not represent a modifier key.
|
|
|
|
*/
|
|
|
|
static int guac_rdp_keyboard_modifier_flag(int keysym) {
|
|
|
|
|
|
|
|
/* Translate keysym into corresponding modifier flag */
|
|
|
|
switch (keysym) {
|
|
|
|
|
|
|
|
/* Shift */
|
|
|
|
case 0xFFE1:
|
|
|
|
case 0xFFE2:
|
|
|
|
return GUAC_RDP_KEYMAP_MODIFIER_SHIFT;
|
|
|
|
|
|
|
|
/* AltGr */
|
|
|
|
case 0xFE03:
|
|
|
|
return GUAC_RDP_KEYMAP_MODIFIER_ALTGR;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Not a modifier */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-08-14 17:19:09 -07:00
|
|
|
/**
|
|
|
|
* Translates the given keysym into the corresponding lock flag, as would be
|
|
|
|
* required by the RDP synchronize event. If the given keysym does not
|
|
|
|
* represent a lock key, zero is returned.
|
|
|
|
*
|
|
|
|
* @param keysym
|
|
|
|
* The keysym to translate into a RDP lock flag.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* The RDP lock flag which corresponds to the given keysym, or zero if the
|
|
|
|
* given keysym does not represent a lock key.
|
|
|
|
*/
|
|
|
|
static int guac_rdp_keyboard_lock_flag(int keysym) {
|
|
|
|
|
|
|
|
/* Translate keysym into corresponding lock flag */
|
|
|
|
switch (keysym) {
|
|
|
|
|
|
|
|
/* Scroll lock */
|
|
|
|
case 0xFF14:
|
|
|
|
return KBD_SYNC_SCROLL_LOCK;
|
|
|
|
|
|
|
|
/* Kana lock */
|
|
|
|
case 0xFF2D:
|
|
|
|
return KBD_SYNC_KANA_LOCK;
|
|
|
|
|
|
|
|
/* Num lock */
|
|
|
|
case 0xFF7F:
|
|
|
|
return KBD_SYNC_NUM_LOCK;
|
|
|
|
|
|
|
|
/* Caps lock */
|
|
|
|
case 0xFFE5:
|
|
|
|
return KBD_SYNC_CAPS_LOCK;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Not a lock key */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-08-14 13:17:34 -07:00
|
|
|
/**
|
|
|
|
* Immediately sends an RDP key event having the given scancode and flags.
|
|
|
|
*
|
|
|
|
* @param rdp_client
|
|
|
|
* The RDP client instance associated with the RDP session along which the
|
|
|
|
* key event should be sent.
|
|
|
|
*
|
|
|
|
* @param scancode
|
|
|
|
* The scancode of the key to press or release via the RDP key event.
|
|
|
|
*
|
|
|
|
* @param flags
|
|
|
|
* Any RDP-specific flags required for the provided scancode to have the
|
|
|
|
* intended meaning, such as KBD_FLAGS_EXTENDED. The possible flags and
|
|
|
|
* their meanings are dictated by RDP. KBD_FLAGS_DOWN and KBD_FLAGS_UP
|
|
|
|
* need not be specified here - they will automatically be added depending
|
|
|
|
* on the value specified for the pressed parameter.
|
|
|
|
*
|
|
|
|
* @param pressed
|
|
|
|
* Non-zero if the key is being pressed, zero if the key is being released.
|
|
|
|
*/
|
|
|
|
static void guac_rdp_send_key_event(guac_rdp_client* rdp_client,
|
|
|
|
int scancode, int flags, int pressed) {
|
|
|
|
|
|
|
|
/* Determine proper event flag for pressed state */
|
|
|
|
int pressed_flags;
|
|
|
|
if (pressed)
|
|
|
|
pressed_flags = KBD_FLAGS_DOWN;
|
|
|
|
else
|
|
|
|
pressed_flags = KBD_FLAGS_RELEASE;
|
|
|
|
|
|
|
|
/* Skip if not yet connected */
|
|
|
|
freerdp* rdp_inst = rdp_client->rdp_inst;
|
2019-12-21 20:02:17 -08:00
|
|
|
if (rdp_inst == NULL)
|
2016-08-14 13:17:34 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Send actual key */
|
|
|
|
rdp_inst->input->KeyboardEvent(rdp_inst->input,
|
|
|
|
flags | pressed_flags, scancode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Immediately sends an RDP Unicode event having the given Unicode codepoint.
|
|
|
|
* Unlike key events, RDP Unicode events do have not a pressed or released
|
|
|
|
* state. They represent strictly the input of a single character, and are
|
|
|
|
* technically independent of the keyboard.
|
|
|
|
*
|
|
|
|
* @param rdp_client
|
|
|
|
* The RDP client instance associated with the RDP session along which the
|
|
|
|
* Unicode event should be sent.
|
|
|
|
*
|
|
|
|
* @param codepoint
|
|
|
|
* The Unicode codepoint of the character being input via the Unicode
|
|
|
|
* event.
|
|
|
|
*/
|
|
|
|
static void guac_rdp_send_unicode_event(guac_rdp_client* rdp_client,
|
|
|
|
int codepoint) {
|
|
|
|
|
|
|
|
/* Skip if not yet connected */
|
|
|
|
freerdp* rdp_inst = rdp_client->rdp_inst;
|
2019-12-21 20:02:17 -08:00
|
|
|
if (rdp_inst == NULL)
|
2016-08-14 13:17:34 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Send Unicode event */
|
|
|
|
rdp_inst->input->UnicodeKeyboardEvent(
|
|
|
|
rdp_inst->input,
|
|
|
|
0, codepoint);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-08-14 17:19:09 -07:00
|
|
|
/**
|
|
|
|
* Immediately sends an RDP synchonize event having the given flags. An RDP
|
|
|
|
* synchronize event sets the state of remote lock keys absolutely, where a
|
|
|
|
* lock key will be active only if its corresponding flag is set in the event.
|
|
|
|
*
|
|
|
|
* @param rdp_client
|
|
|
|
* The RDP client instance associated with the RDP session along which the
|
|
|
|
* synchronize event should be sent.
|
|
|
|
*
|
|
|
|
* @param flags
|
|
|
|
* Bitwise OR of the flags representing the lock keys which should be set,
|
|
|
|
* if any, as dictated by the RDP protocol. If no flags are set, then no
|
|
|
|
* lock keys will be active.
|
|
|
|
*/
|
|
|
|
static void guac_rdp_send_synchronize_event(guac_rdp_client* rdp_client,
|
|
|
|
int flags) {
|
|
|
|
|
|
|
|
/* Skip if not yet connected */
|
|
|
|
freerdp* rdp_inst = rdp_client->rdp_inst;
|
2019-12-21 20:02:17 -08:00
|
|
|
if (rdp_inst == NULL)
|
2016-08-14 17:19:09 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Synchronize lock key states */
|
|
|
|
rdp_inst->input->SynchronizeEvent(rdp_inst->input, flags);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-01-28 22:50:11 -08:00
|
|
|
/**
|
|
|
|
* Given a keyboard instance and X11 keysym, returns a pointer to the key
|
|
|
|
* structure that represents or can represent the key having that keysym within
|
|
|
|
* the keyboard, regardless of whether the key is currently defined. If no such
|
|
|
|
* key can exist (the keysym cannot be mapped or is out of range), NULL is
|
|
|
|
* returned.
|
|
|
|
*
|
|
|
|
* @param keyboard
|
|
|
|
* The guac_rdp_keyboard associated with the current RDP session.
|
|
|
|
*
|
|
|
|
* @param keysym
|
|
|
|
* The keysym of the key to lookup within the given keyboard.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* A pointer to the guac_rdp_key structure which represents or can
|
|
|
|
* represent the key having the given keysym, or NULL if no such keysym can
|
|
|
|
* be defined within a guac_rdp_keyboard structure.
|
|
|
|
*/
|
|
|
|
static guac_rdp_key* guac_rdp_keyboard_map_key(guac_rdp_keyboard* keyboard,
|
|
|
|
int keysym) {
|
|
|
|
|
|
|
|
int index;
|
|
|
|
|
|
|
|
/* Map keysyms between 0x0000 and 0xFFFF directly */
|
|
|
|
if (keysym >= 0x0000 && keysym <= 0xFFFF)
|
|
|
|
index = keysym;
|
|
|
|
|
|
|
|
/* Map all Unicode keysyms from U+0000 to U+FFFF */
|
|
|
|
else if (keysym >= 0x1000000 && keysym <= 0x100FFFF)
|
|
|
|
index = 0x10000 + (keysym & 0xFFFF);
|
|
|
|
|
|
|
|
/* All other keysyms are unmapped */
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Corresponding key mapping (defined or not) has been located */
|
|
|
|
return &(keyboard->keys[index]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a pointer to the guac_rdp_key structure representing the definition
|
|
|
|
* and state of the key having the given keysym. If no such key is defined
|
|
|
|
* within the keyboard layout of the RDP server, NULL is returned.
|
|
|
|
*
|
|
|
|
* @param keyboard
|
|
|
|
* The guac_rdp_keyboard associated with the current RDP session.
|
|
|
|
*
|
|
|
|
* @param keysym
|
|
|
|
* The keysym of the key to lookup within the given keyboard.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* A pointer to the guac_rdp_key structure representing the definition and
|
|
|
|
* state of the key having the given keysym, or NULL if no such key is
|
|
|
|
* defined within the keyboard layout of the RDP server.
|
|
|
|
*/
|
|
|
|
static guac_rdp_key* guac_rdp_keyboard_get_key(guac_rdp_keyboard* keyboard,
|
|
|
|
int keysym) {
|
|
|
|
|
|
|
|
/* Verify that the key is actually defined */
|
|
|
|
guac_rdp_key* key = guac_rdp_keyboard_map_key(keyboard, keysym);
|
|
|
|
if (key == NULL || key->definition == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Key is defined within keyboard */
|
|
|
|
return key;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-08-13 17:33:30 -07:00
|
|
|
/**
|
|
|
|
* Loads all keysym/scancode mappings declared within the given keymap and its
|
|
|
|
* parent keymap, if any. These mappings are stored within the given
|
|
|
|
* guac_rdp_keyboard structure for future use in translating keysyms to the
|
|
|
|
* scancodes required by RDP key events.
|
|
|
|
*
|
|
|
|
* @param keyboard
|
|
|
|
* The guac_rdp_keyboard which should be initialized with the
|
|
|
|
* keysym/scancode mapping defined in the given keymap.
|
|
|
|
*
|
|
|
|
* @param keymap
|
|
|
|
* The keymap to use to populate the given client's keysym/scancode
|
|
|
|
* mapping.
|
|
|
|
*/
|
|
|
|
static void __guac_rdp_keyboard_load_keymap(guac_rdp_keyboard* keyboard,
|
|
|
|
const guac_rdp_keymap* keymap) {
|
|
|
|
|
|
|
|
/* Get mapping */
|
|
|
|
const guac_rdp_keysym_desc* mapping = keymap->mapping;
|
|
|
|
|
|
|
|
/* If parent exists, load parent first */
|
|
|
|
if (keymap->parent != NULL)
|
|
|
|
__guac_rdp_keyboard_load_keymap(keyboard, keymap->parent);
|
|
|
|
|
|
|
|
/* Log load */
|
|
|
|
guac_client_log(keyboard->client, GUAC_LOG_INFO,
|
|
|
|
"Loading keymap \"%s\"", keymap->name);
|
|
|
|
|
|
|
|
/* Load mapping into keymap */
|
|
|
|
while (mapping->keysym != 0) {
|
|
|
|
|
2018-01-28 22:50:11 -08:00
|
|
|
/* Locate corresponding key definition within keyboard */
|
|
|
|
guac_rdp_key* key = guac_rdp_keyboard_map_key(keyboard,
|
|
|
|
mapping->keysym);
|
|
|
|
|
|
|
|
/* Copy mapping (if key is mappable) */
|
|
|
|
if (key != NULL)
|
|
|
|
key->definition = mapping;
|
|
|
|
else
|
|
|
|
guac_client_log(keyboard->client, GUAC_LOG_DEBUG,
|
|
|
|
"Ignoring unmappable keysym 0x%X", mapping->keysym);
|
2016-08-13 17:33:30 -07:00
|
|
|
|
|
|
|
/* Next keysym */
|
|
|
|
mapping++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
guac_rdp_keyboard* guac_rdp_keyboard_alloc(guac_client* client,
|
|
|
|
const guac_rdp_keymap* keymap) {
|
|
|
|
|
|
|
|
guac_rdp_keyboard* keyboard = calloc(1, sizeof(guac_rdp_keyboard));
|
|
|
|
keyboard->client = client;
|
|
|
|
|
|
|
|
/* Load keymap into keyboard */
|
|
|
|
__guac_rdp_keyboard_load_keymap(keyboard, keymap);
|
|
|
|
|
|
|
|
return keyboard;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void guac_rdp_keyboard_free(guac_rdp_keyboard* keyboard) {
|
|
|
|
free(keyboard);
|
|
|
|
}
|
|
|
|
|
2018-01-28 00:56:24 -08:00
|
|
|
int guac_rdp_keyboard_is_defined(guac_rdp_keyboard* keyboard, int keysym) {
|
|
|
|
|
|
|
|
/* Return whether the mapping actually exists */
|
2018-01-28 22:50:11 -08:00
|
|
|
return guac_rdp_keyboard_get_key(keyboard, keysym) != NULL;
|
2018-01-28 00:56:24 -08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-06-21 22:10:02 -07:00
|
|
|
/**
|
|
|
|
* Presses/releases the requested key by sending one or more RDP key events, as
|
|
|
|
* defined within the keymap defining that key.
|
|
|
|
*
|
|
|
|
* @param keyboard
|
|
|
|
* The guac_rdp_keyboard associated with the current RDP session.
|
|
|
|
*
|
|
|
|
* @param key
|
|
|
|
* The guac_rdp_keysym_desc of the key being pressed or released, as
|
|
|
|
* retrieved from the relevant keymap.
|
|
|
|
*
|
|
|
|
* @param pressed
|
|
|
|
* Zero if the key is being released, non-zero otherwise.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* Zero if the key was successfully pressed/released, non-zero if the key
|
|
|
|
* cannot be sent using RDP key events.
|
|
|
|
*/
|
|
|
|
static int guac_rdp_keyboard_send_defined_key(guac_rdp_keyboard* keyboard,
|
|
|
|
guac_rdp_key* key, int pressed) {
|
2016-08-13 17:33:30 -07:00
|
|
|
|
|
|
|
guac_client* client = keyboard->client;
|
|
|
|
guac_rdp_client* rdp_client = (guac_rdp_client*) client->data;
|
|
|
|
|
2020-06-21 22:10:02 -07:00
|
|
|
if (key->definition->scancode == 0)
|
|
|
|
return 1;
|
2016-08-13 17:33:30 -07:00
|
|
|
|
2020-06-21 22:10:02 -07:00
|
|
|
const guac_rdp_keysym_desc* keysym_desc = key->definition;
|
2016-08-13 17:33:30 -07:00
|
|
|
|
2020-06-21 22:10:02 -07:00
|
|
|
/* Update state of required locks and modifiers only when key is just
|
|
|
|
* now being pressed */
|
|
|
|
if (pressed) {
|
|
|
|
guac_rdp_keyboard_update_locks(keyboard,
|
|
|
|
keysym_desc->set_locks,
|
|
|
|
keysym_desc->clear_locks);
|
2016-08-13 17:33:30 -07:00
|
|
|
|
2020-06-21 22:10:02 -07:00
|
|
|
guac_rdp_keyboard_update_modifiers(keyboard,
|
|
|
|
keysym_desc->set_modifiers,
|
|
|
|
keysym_desc->clear_modifiers);
|
|
|
|
}
|
2016-08-14 17:19:09 -07:00
|
|
|
|
2020-06-21 22:10:02 -07:00
|
|
|
/* Fire actual key event for target key */
|
|
|
|
guac_rdp_send_key_event(rdp_client, keysym_desc->scancode,
|
|
|
|
keysym_desc->flags, pressed);
|
2016-08-13 17:33:30 -07:00
|
|
|
|
2020-06-21 22:10:02 -07:00
|
|
|
return 0;
|
2016-08-13 17:33:30 -07:00
|
|
|
|
2020-06-21 22:10:02 -07:00
|
|
|
}
|
2016-08-13 17:33:30 -07:00
|
|
|
|
2020-06-21 22:10:02 -07:00
|
|
|
/**
|
|
|
|
* Presses and releases the requested key by sending one or more RDP events,
|
|
|
|
* without relying on a keymap for that key. This will typically involve either
|
|
|
|
* sending the key using a Unicode event or decomposing the key into a series
|
|
|
|
* of keypresses involving deadkeys.
|
|
|
|
*
|
|
|
|
* @param keyboard
|
|
|
|
* The guac_rdp_keyboard associated with the current RDP session.
|
|
|
|
*
|
|
|
|
* @param keysym
|
|
|
|
* The keysym of the key to press and release.
|
|
|
|
*/
|
|
|
|
static void guac_rdp_keyboard_send_missing_key(guac_rdp_keyboard* keyboard,
|
|
|
|
int keysym) {
|
2016-08-13 17:33:30 -07:00
|
|
|
|
2020-06-21 22:10:02 -07:00
|
|
|
guac_client* client = keyboard->client;
|
|
|
|
guac_rdp_client* rdp_client = (guac_rdp_client*) client->data;
|
2016-08-13 17:33:30 -07:00
|
|
|
|
2020-06-21 22:10:02 -07:00
|
|
|
/* Attempt to type using dead keys */
|
|
|
|
if (!guac_rdp_decompose_keysym(keyboard, keysym))
|
|
|
|
return;
|
2018-01-28 01:00:02 -08:00
|
|
|
|
2020-06-21 22:10:02 -07:00
|
|
|
guac_client_log(client, GUAC_LOG_DEBUG, "Sending keysym 0x%x as "
|
|
|
|
"Unicode", keysym);
|
|
|
|
|
|
|
|
/* Translate keysym into codepoint */
|
|
|
|
int codepoint;
|
|
|
|
if (keysym <= 0xFF)
|
|
|
|
codepoint = keysym;
|
|
|
|
else if (keysym >= 0x1000000)
|
|
|
|
codepoint = keysym & 0xFFFFFF;
|
|
|
|
else {
|
|
|
|
guac_client_log(client, GUAC_LOG_DEBUG, "Unmapped keysym has no "
|
|
|
|
"equivalent unicode value: 0x%x", keysym);
|
|
|
|
return;
|
|
|
|
}
|
2016-08-13 17:33:30 -07:00
|
|
|
|
2020-06-21 22:10:02 -07:00
|
|
|
/* Send as Unicode event */
|
|
|
|
guac_rdp_send_unicode_event(rdp_client, codepoint);
|
2016-08-13 17:33:30 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-08-14 17:19:09 -07:00
|
|
|
void guac_rdp_keyboard_update_locks(guac_rdp_keyboard* keyboard,
|
|
|
|
int set_flags, int clear_flags) {
|
|
|
|
|
|
|
|
guac_client* client = keyboard->client;
|
|
|
|
guac_rdp_client* rdp_client = (guac_rdp_client*) client->data;
|
|
|
|
|
|
|
|
/* Calculate updated lock flags */
|
|
|
|
int lock_flags = (keyboard->lock_flags | set_flags) & ~clear_flags;
|
|
|
|
|
|
|
|
/* Synchronize remote side only if lock flags have changed */
|
|
|
|
if (lock_flags != keyboard->lock_flags) {
|
|
|
|
guac_rdp_send_synchronize_event(rdp_client, lock_flags);
|
|
|
|
keyboard->lock_flags = lock_flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-06-21 20:59:11 -07:00
|
|
|
void guac_rdp_keyboard_update_modifiers(guac_rdp_keyboard* keyboard,
|
|
|
|
int set_flags, int clear_flags) {
|
|
|
|
|
|
|
|
/* Only clear modifiers that are set */
|
|
|
|
clear_flags &= keyboard->modifier_flags;
|
|
|
|
|
|
|
|
/* Only set modifiers that are currently cleared */
|
|
|
|
set_flags &= ~keyboard->modifier_flags;
|
|
|
|
|
|
|
|
/* Press/release Shift as needed */
|
|
|
|
if (set_flags & GUAC_RDP_KEYMAP_MODIFIER_SHIFT) {
|
|
|
|
guac_rdp_keyboard_update_keysym(keyboard, 0xFFE1, 1);
|
|
|
|
}
|
|
|
|
else if (clear_flags & GUAC_RDP_KEYMAP_MODIFIER_SHIFT) {
|
|
|
|
guac_rdp_keyboard_update_keysym(keyboard, 0xFFE1, 0);
|
|
|
|
guac_rdp_keyboard_update_keysym(keyboard, 0xFFE2, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Press/release AltGr as needed */
|
|
|
|
if (set_flags & GUAC_RDP_KEYMAP_MODIFIER_ALTGR) {
|
|
|
|
guac_rdp_keyboard_update_keysym(keyboard, 0xFE03, 1);
|
|
|
|
}
|
|
|
|
else if (clear_flags & GUAC_RDP_KEYMAP_MODIFIER_ALTGR) {
|
|
|
|
guac_rdp_keyboard_update_keysym(keyboard, 0xFE03, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-08-13 17:33:30 -07:00
|
|
|
int guac_rdp_keyboard_update_keysym(guac_rdp_keyboard* keyboard,
|
|
|
|
int keysym, int pressed) {
|
|
|
|
|
2016-08-14 17:19:09 -07:00
|
|
|
/* Synchronize lock keys states, if this has not yet been done */
|
|
|
|
if (!keyboard->synchronized) {
|
|
|
|
|
|
|
|
guac_client* client = keyboard->client;
|
|
|
|
guac_rdp_client* rdp_client = (guac_rdp_client*) client->data;
|
|
|
|
|
|
|
|
/* Synchronize remote lock key states with local state */
|
|
|
|
guac_rdp_send_synchronize_event(rdp_client, keyboard->lock_flags);
|
|
|
|
keyboard->synchronized = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-06-21 22:10:02 -07:00
|
|
|
/* If key is known, update stored state, ignoring the key event entirely if
|
|
|
|
* state is not actually changing */
|
|
|
|
guac_rdp_key* key = guac_rdp_keyboard_get_key(keyboard, keysym);
|
|
|
|
if (key != NULL) {
|
|
|
|
|
|
|
|
guac_rdp_key_state new_state = pressed ? GUAC_RDP_KEY_PRESSED : GUAC_RDP_KEY_RELEASED;
|
|
|
|
if (key->state == new_state)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
key->state = new_state;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-06-21 20:59:11 -07:00
|
|
|
/* Toggle locks and set modifiers on keydown */
|
|
|
|
if (pressed) {
|
2016-08-14 17:19:09 -07:00
|
|
|
keyboard->lock_flags ^= guac_rdp_keyboard_lock_flag(keysym);
|
2020-06-21 20:59:11 -07:00
|
|
|
keyboard->modifier_flags |= guac_rdp_keyboard_modifier_flag(keysym);
|
|
|
|
}
|
2016-08-14 17:19:09 -07:00
|
|
|
|
2020-06-21 20:59:11 -07:00
|
|
|
/* Clear modifiers on keyup */
|
2020-06-21 22:10:02 -07:00
|
|
|
else {
|
2020-06-21 20:59:11 -07:00
|
|
|
keyboard->modifier_flags &= ~guac_rdp_keyboard_modifier_flag(keysym);
|
2020-06-21 22:10:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Attempt to send using normal RDP key events */
|
|
|
|
if (key == NULL && !guac_rdp_keyboard_send_defined_key(keyboard, key, pressed))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* 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 (pressed)
|
|
|
|
guac_rdp_keyboard_send_missing_key(keyboard, keysym);
|
2016-08-13 17:33:30 -07:00
|
|
|
|
2020-06-21 22:10:02 -07:00
|
|
|
return 0;
|
2016-08-13 17:33:30 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|