2005-08-03 12:56:16 +02:00
|
|
|
/* -*- c-basic-offset: 8 -*-
|
2002-04-04 14:04:33 +02:00
|
|
|
rdesktop: A Remote Desktop Protocol client.
|
|
|
|
User interface services - X keyboard mapping
|
2003-09-08 10:27:57 +02:00
|
|
|
|
2011-04-13 13:13:04 +02:00
|
|
|
Copyright (C) Matthew Chapman <matthewc.unsw.edu.au> 1999-2008
|
2011-09-28 11:36:59 +02:00
|
|
|
Copyright 2003-2008 Peter Astrand <astrand@cendio.se> for Cendio AB
|
2017-01-26 14:19:40 +01:00
|
|
|
Copyright 2014-2017 Henrik Andersson <hean01@cendio.se> for Cendio AB
|
2007-01-04 06:39:39 +01:00
|
|
|
|
2010-01-12 09:31:06 +01:00
|
|
|
This program is free software: you can redistribute it and/or modify
|
2002-04-04 14:04:33 +02:00
|
|
|
it under the terms of the GNU General Public License as published by
|
2010-01-12 09:31:06 +01:00
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
2002-04-04 14:04:33 +02:00
|
|
|
(at your option) any later version.
|
2007-01-04 06:39:39 +01:00
|
|
|
|
2002-04-04 14:04:33 +02:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2003-05-19 23:36:33 +02:00
|
|
|
|
2002-04-04 14:04:33 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
2010-01-12 09:31:06 +01:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2002-04-04 14:04:33 +02:00
|
|
|
*/
|
|
|
|
|
2003-02-20 13:14:13 +01:00
|
|
|
#ifdef RDP2VNC
|
|
|
|
#include "vnc/x11stubs.h"
|
|
|
|
#else
|
2002-04-04 14:04:33 +02:00
|
|
|
#include <X11/Xlib.h>
|
2003-02-18 14:44:27 +01:00
|
|
|
#include <X11/keysym.h>
|
2003-02-20 13:14:13 +01:00
|
|
|
#endif
|
|
|
|
|
2002-07-18 20:28:12 +02:00
|
|
|
#include <ctype.h>
|
2002-04-05 09:57:43 +02:00
|
|
|
#include <limits.h>
|
2002-09-24 09:33:17 +02:00
|
|
|
#include <time.h>
|
2005-08-03 11:32:22 +02:00
|
|
|
#include <string.h>
|
2009-09-17 15:52:04 +02:00
|
|
|
#include <assert.h>
|
2002-04-04 14:04:33 +02:00
|
|
|
#include "rdesktop.h"
|
2002-07-18 20:28:12 +02:00
|
|
|
#include "scancodes.h"
|
2002-04-04 14:04:33 +02:00
|
|
|
|
2014-05-20 13:24:59 +02:00
|
|
|
#define KEYMAP_SIZE 0x7f+1
|
|
|
|
#define KEYMAP_MASK 0x7f
|
2002-07-18 20:28:12 +02:00
|
|
|
#define KEYMAP_MAX_LINE_LENGTH 80
|
2002-04-04 14:04:33 +02:00
|
|
|
|
2003-08-28 00:51:33 +02:00
|
|
|
extern Display *g_display;
|
2003-11-03 14:33:35 +01:00
|
|
|
extern Window g_wnd;
|
2005-08-04 14:51:44 +02:00
|
|
|
extern char g_keymapname[16];
|
2005-12-30 21:32:06 +01:00
|
|
|
extern unsigned int g_keylayout;
|
2005-08-03 13:30:53 +02:00
|
|
|
extern int g_keyboard_type;
|
|
|
|
extern int g_keyboard_subtype;
|
|
|
|
extern int g_keyboard_functionkeys;
|
2003-08-28 00:51:33 +02:00
|
|
|
extern int g_win_button_size;
|
2007-01-08 05:47:06 +01:00
|
|
|
extern RD_BOOL g_enable_compose;
|
2012-06-15 07:16:20 +02:00
|
|
|
extern RDP_VERSION g_rdp_version;
|
2007-01-08 05:47:06 +01:00
|
|
|
extern RD_BOOL g_numlock_sync;
|
2002-04-04 14:04:33 +02:00
|
|
|
|
2007-01-08 05:47:06 +01:00
|
|
|
static RD_BOOL keymap_loaded;
|
2014-05-20 12:43:03 +02:00
|
|
|
static key_translation_entry *keymap[KEYMAP_SIZE];
|
2009-09-17 15:52:04 +02:00
|
|
|
static KeySym keypress_keysyms[256];
|
2002-07-29 21:21:51 +02:00
|
|
|
static int min_keycode;
|
2002-07-18 20:28:12 +02:00
|
|
|
static uint16 remote_modifier_state = 0;
|
2003-08-27 11:42:55 +02:00
|
|
|
static uint16 saved_remote_modifier_state = 0;
|
2002-07-18 20:28:12 +02:00
|
|
|
|
2007-01-08 05:47:06 +01:00
|
|
|
static void update_modifier_state(uint8 scancode, RD_BOOL pressed);
|
2002-09-11 11:52:30 +02:00
|
|
|
|
2005-08-03 09:08:48 +02:00
|
|
|
/* Free key_translation structure, including linked list */
|
2005-08-03 09:08:17 +02:00
|
|
|
static void
|
2005-08-02 20:07:56 +02:00
|
|
|
free_key_translation(key_translation * ptr)
|
|
|
|
{
|
|
|
|
key_translation *next;
|
|
|
|
|
|
|
|
while (ptr)
|
|
|
|
{
|
|
|
|
next = ptr->next;
|
|
|
|
xfree(ptr);
|
|
|
|
ptr = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-20 12:43:03 +02:00
|
|
|
/* Free the key_translation_entry for a given keysym and remove from the table */
|
|
|
|
static void
|
|
|
|
delete_key_translation_entry(KeySym keysym)
|
|
|
|
{
|
|
|
|
uint32 hash;
|
|
|
|
key_translation_entry *ptr;
|
|
|
|
key_translation_entry *next;
|
|
|
|
key_translation_entry *prev;
|
|
|
|
key_translation_entry tmp;
|
|
|
|
|
|
|
|
/* Faking a prev node allows us to keep the algorithm simple */
|
|
|
|
hash = keysym & KEYMAP_MASK;
|
|
|
|
ptr = keymap[hash];
|
|
|
|
tmp.next = ptr;
|
|
|
|
prev = &tmp;
|
|
|
|
|
|
|
|
while (ptr)
|
|
|
|
{
|
|
|
|
next = ptr->next;
|
|
|
|
if (ptr->keysym == keysym)
|
|
|
|
{
|
|
|
|
free_key_translation(ptr->tr);
|
|
|
|
prev->next = next;
|
|
|
|
xfree(ptr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prev = ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy pointer back from our fake node */
|
|
|
|
keymap[hash] = tmp.next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate and return a new entry in the translation table */
|
|
|
|
static key_translation_entry *
|
|
|
|
new_key_translation_entry(KeySym keysym)
|
|
|
|
{
|
|
|
|
uint32 hash;
|
|
|
|
key_translation_entry *entry;
|
|
|
|
|
|
|
|
/* Clear out any existing entry */
|
|
|
|
delete_key_translation_entry(keysym);
|
|
|
|
|
|
|
|
/* Allocate the new one */
|
|
|
|
entry = (key_translation_entry *) xmalloc(sizeof(key_translation_entry));
|
|
|
|
memset(entry, 0, sizeof(key_translation_entry));
|
|
|
|
entry->keysym = keysym;
|
|
|
|
|
|
|
|
/* And insert it at head of list */
|
|
|
|
hash = keysym & KEYMAP_MASK;
|
|
|
|
entry->next = keymap[hash];
|
|
|
|
keymap[hash] = entry;
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Retrieve the key_translation_entry for a given keysym */
|
|
|
|
static key_translation_entry *
|
|
|
|
get_key_translation_entry(uint32 keysym)
|
|
|
|
{
|
|
|
|
key_translation_entry *ptr;
|
|
|
|
key_translation_entry *next;
|
|
|
|
|
|
|
|
ptr = keymap[keysym & KEYMAP_MASK];
|
|
|
|
|
|
|
|
while (ptr)
|
|
|
|
{
|
|
|
|
next = ptr->next;
|
|
|
|
if (ptr->keysym == keysym)
|
|
|
|
return ptr;
|
|
|
|
|
|
|
|
ptr = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Not found */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-07-18 20:28:12 +02:00
|
|
|
static void
|
|
|
|
add_to_keymap(char *keyname, uint8 scancode, uint16 modifiers, char *mapname)
|
|
|
|
{
|
|
|
|
KeySym keysym;
|
2014-05-20 12:43:03 +02:00
|
|
|
key_translation_entry *entry;
|
2002-07-18 20:28:12 +02:00
|
|
|
|
|
|
|
keysym = XStringToKeysym(keyname);
|
|
|
|
if (keysym == NoSymbol)
|
|
|
|
{
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Keyboard, Error, "add_to_keymap(), ignoring bad keysym '%s' in keymap %s",
|
|
|
|
keyname, mapname);
|
2002-07-18 20:28:12 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Keyboard, Debug, "add_to_keymap(), adding translation, keysym=0x%x, scancode=0x%x, "
|
|
|
|
"modifiers=0x%x", (unsigned int) keysym, scancode, modifiers);
|
2002-07-18 20:28:12 +02:00
|
|
|
|
2014-05-20 12:43:03 +02:00
|
|
|
/* Make a new entry in the table */
|
|
|
|
entry = new_key_translation_entry(keysym);
|
|
|
|
|
|
|
|
/* And add the new translation to it */
|
|
|
|
entry->tr = (key_translation *) xmalloc(sizeof(key_translation));
|
|
|
|
memset(entry->tr, 0, sizeof(key_translation));
|
|
|
|
entry->tr->scancode = scancode;
|
|
|
|
entry->tr->modifiers = modifiers;
|
2002-07-18 20:28:12 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-08-02 17:07:35 +02:00
|
|
|
static void
|
|
|
|
add_sequence(char *rest, char *mapname)
|
|
|
|
{
|
|
|
|
KeySym keysym;
|
2014-05-20 12:43:03 +02:00
|
|
|
KeySym seq_keysym;
|
|
|
|
key_translation_entry *entry;
|
2005-08-02 17:07:35 +02:00
|
|
|
key_translation *tr, **prev_next;
|
|
|
|
size_t chars;
|
|
|
|
char keyname[KEYMAP_MAX_LINE_LENGTH];
|
|
|
|
|
|
|
|
/* Skip over whitespace after the sequence keyword */
|
|
|
|
chars = strspn(rest, " \t");
|
|
|
|
rest += chars;
|
|
|
|
|
|
|
|
/* Fetch the keysym name */
|
|
|
|
chars = strcspn(rest, " \t\0");
|
|
|
|
STRNCPY(keyname, rest, chars + 1);
|
|
|
|
rest += chars;
|
|
|
|
|
|
|
|
keysym = XStringToKeysym(keyname);
|
|
|
|
if (keysym == NoSymbol)
|
|
|
|
{
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Keyboard, Error, "add_sequence(), ignoring bad keysym '%s' in keymap %s",
|
|
|
|
keyname, mapname);
|
2005-08-02 17:07:35 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Keyboard, Debug, "add_sequence(), adding squence for keysym '%s' (0x%lx)", keyname,
|
|
|
|
keysym);
|
2005-08-02 17:07:35 +02:00
|
|
|
|
2014-05-20 12:43:03 +02:00
|
|
|
entry = new_key_translation_entry(keysym);
|
|
|
|
prev_next = &(entry->tr);
|
2005-08-02 17:07:35 +02:00
|
|
|
|
|
|
|
while (*rest)
|
|
|
|
{
|
|
|
|
/* Skip whitespace */
|
|
|
|
chars = strspn(rest, " \t");
|
|
|
|
rest += chars;
|
|
|
|
|
|
|
|
/* Fetch the keysym name */
|
|
|
|
chars = strcspn(rest, " \t\0");
|
|
|
|
STRNCPY(keyname, rest, chars + 1);
|
|
|
|
rest += chars;
|
|
|
|
|
2014-05-20 12:52:39 +02:00
|
|
|
/* Handle trailing whitespace */
|
|
|
|
if (*keyname == 0)
|
|
|
|
break;
|
|
|
|
|
2014-05-20 12:43:03 +02:00
|
|
|
seq_keysym = XStringToKeysym(keyname);
|
|
|
|
if (seq_keysym == NoSymbol)
|
2005-08-02 17:07:35 +02:00
|
|
|
{
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Keyboard, Error,
|
|
|
|
"add_sequence(), ignoring line with bad keysym '%s' in keymap %s",
|
|
|
|
keyname, mapname);
|
2014-05-20 12:43:03 +02:00
|
|
|
delete_key_translation_entry(keysym);
|
2005-08-02 17:07:35 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate space for key_translation structure */
|
|
|
|
tr = (key_translation *) xmalloc(sizeof(key_translation));
|
|
|
|
memset(tr, 0, sizeof(key_translation));
|
2014-05-20 12:43:03 +02:00
|
|
|
|
|
|
|
/* Do this straight away so the key_translation won't get orphaned on error */
|
|
|
|
if (!entry->tr)
|
|
|
|
entry->tr = tr;
|
|
|
|
|
2005-08-02 17:07:35 +02:00
|
|
|
*prev_next = tr;
|
|
|
|
prev_next = &tr->next;
|
2014-05-20 12:43:03 +02:00
|
|
|
tr->seq_keysym = seq_keysym;
|
2005-08-02 17:07:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-08 05:47:06 +01:00
|
|
|
RD_BOOL
|
2005-08-03 11:56:17 +02:00
|
|
|
xkeymap_from_locale(const char *locale)
|
|
|
|
{
|
|
|
|
char *str, *ptr;
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
/* Create a working copy */
|
2005-08-04 14:50:15 +02:00
|
|
|
str = xstrdup(locale);
|
2005-08-03 11:56:17 +02:00
|
|
|
|
|
|
|
/* Truncate at dot and at */
|
|
|
|
ptr = strrchr(str, '.');
|
|
|
|
if (ptr)
|
|
|
|
*ptr = '\0';
|
|
|
|
ptr = strrchr(str, '@');
|
|
|
|
if (ptr)
|
|
|
|
*ptr = '\0';
|
|
|
|
|
|
|
|
/* Replace _ with - */
|
|
|
|
ptr = strrchr(str, '_');
|
|
|
|
if (ptr)
|
|
|
|
*ptr = '-';
|
|
|
|
|
|
|
|
/* Convert to lowercase */
|
|
|
|
ptr = str;
|
|
|
|
while (*ptr)
|
|
|
|
{
|
|
|
|
*ptr = tolower((int) *ptr);
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to open this keymap (da-dk) */
|
|
|
|
fp = xkeymap_open(str);
|
|
|
|
if (fp == NULL)
|
|
|
|
{
|
|
|
|
/* Truncate at dash */
|
|
|
|
ptr = strrchr(str, '-');
|
|
|
|
if (ptr)
|
|
|
|
*ptr = '\0';
|
|
|
|
|
|
|
|
/* Try the short name (da) */
|
|
|
|
fp = xkeymap_open(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fp)
|
|
|
|
{
|
|
|
|
fclose(fp);
|
2005-08-04 14:51:44 +02:00
|
|
|
STRNCPY(g_keymapname, str, sizeof(g_keymapname));
|
2006-06-14 08:30:54 +02:00
|
|
|
xfree(str);
|
2005-08-04 14:44:10 +02:00
|
|
|
return True;
|
2005-08-03 11:56:17 +02:00
|
|
|
}
|
2005-08-04 14:44:10 +02:00
|
|
|
|
2006-06-14 08:30:54 +02:00
|
|
|
xfree(str);
|
2005-08-04 14:44:10 +02:00
|
|
|
return False;
|
2005-08-03 11:56:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-03 10:25:32 +02:00
|
|
|
/* Joins two path components. The result should be freed with
|
|
|
|
xfree(). */
|
|
|
|
static char *
|
|
|
|
pathjoin(const char *a, const char *b)
|
|
|
|
{
|
|
|
|
char *result;
|
|
|
|
result = xmalloc(PATH_MAX * 2 + 1);
|
|
|
|
|
|
|
|
if (b[0] == '/')
|
|
|
|
{
|
|
|
|
strncpy(result, b, PATH_MAX);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strncpy(result, a, PATH_MAX);
|
|
|
|
strcat(result, "/");
|
|
|
|
strncat(result, b, PATH_MAX);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to open a keymap with fopen() */
|
|
|
|
FILE *
|
|
|
|
xkeymap_open(const char *filename)
|
|
|
|
{
|
|
|
|
char *path1, *path2;
|
|
|
|
char *home;
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
/* Try ~/.rdesktop/keymaps */
|
|
|
|
home = getenv("HOME");
|
|
|
|
if (home)
|
|
|
|
{
|
|
|
|
path1 = pathjoin(home, ".rdesktop/keymaps");
|
|
|
|
path2 = pathjoin(path1, filename);
|
|
|
|
xfree(path1);
|
|
|
|
fp = fopen(path2, "r");
|
|
|
|
xfree(path2);
|
|
|
|
if (fp)
|
|
|
|
return fp;
|
|
|
|
}
|
|
|
|
|
2005-08-03 10:41:02 +02:00
|
|
|
/* Try KEYMAP_PATH */
|
|
|
|
path1 = pathjoin(KEYMAP_PATH, filename);
|
|
|
|
fp = fopen(path1, "r");
|
|
|
|
xfree(path1);
|
|
|
|
if (fp)
|
|
|
|
return fp;
|
|
|
|
|
2005-08-03 10:25:32 +02:00
|
|
|
/* Try current directory, in case we are running from the source
|
|
|
|
tree */
|
|
|
|
path1 = pathjoin("keymaps", filename);
|
|
|
|
fp = fopen(path1, "r");
|
|
|
|
xfree(path1);
|
|
|
|
if (fp)
|
|
|
|
return fp;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-01-08 05:47:06 +01:00
|
|
|
static RD_BOOL
|
2002-07-18 18:38:31 +02:00
|
|
|
xkeymap_read(char *mapname)
|
2002-04-04 14:04:33 +02:00
|
|
|
{
|
|
|
|
FILE *fp;
|
2002-10-08 04:30:20 +02:00
|
|
|
char line[KEYMAP_MAX_LINE_LENGTH];
|
2002-07-18 20:28:12 +02:00
|
|
|
unsigned int line_num = 0;
|
|
|
|
unsigned int line_length = 0;
|
2002-04-04 14:04:33 +02:00
|
|
|
char *keyname, *p;
|
2002-07-18 20:28:12 +02:00
|
|
|
char *line_rest;
|
|
|
|
uint8 scancode;
|
|
|
|
uint16 modifiers;
|
|
|
|
|
2005-08-03 10:25:32 +02:00
|
|
|
fp = xkeymap_open(mapname);
|
2002-04-04 14:04:33 +02:00
|
|
|
if (fp == NULL)
|
|
|
|
{
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Keyboard, Error, "xkeymap_read(), failed to open keymap %s", mapname);
|
2005-08-03 10:25:32 +02:00
|
|
|
return False;
|
2002-04-04 14:04:33 +02:00
|
|
|
}
|
|
|
|
|
2002-07-18 20:28:12 +02:00
|
|
|
/* FIXME: More tolerant on white space */
|
2002-04-04 14:04:33 +02:00
|
|
|
while (fgets(line, sizeof(line), fp) != NULL)
|
|
|
|
{
|
2002-07-18 20:28:12 +02:00
|
|
|
line_num++;
|
|
|
|
|
|
|
|
/* Replace the \n with \0 */
|
2002-04-04 14:04:33 +02:00
|
|
|
p = strchr(line, '\n');
|
|
|
|
if (p != NULL)
|
|
|
|
*p = 0;
|
|
|
|
|
2002-07-18 20:28:12 +02:00
|
|
|
line_length = strlen(line);
|
2002-04-04 14:04:33 +02:00
|
|
|
|
2002-07-18 20:28:12 +02:00
|
|
|
/* Completely empty line */
|
|
|
|
if (strspn(line, " \t\n\r\f\v") == line_length)
|
|
|
|
{
|
|
|
|
continue;
|
2002-04-04 14:04:33 +02:00
|
|
|
}
|
2002-07-18 20:28:12 +02:00
|
|
|
|
|
|
|
/* Include */
|
2005-08-31 15:00:57 +02:00
|
|
|
if (str_startswith(line, "include "))
|
2002-04-04 14:04:33 +02:00
|
|
|
{
|
2005-08-03 13:47:20 +02:00
|
|
|
if (!xkeymap_read(line + sizeof("include ") - 1))
|
2002-04-04 14:04:33 +02:00
|
|
|
return False;
|
2002-07-18 20:28:12 +02:00
|
|
|
continue;
|
2002-04-04 14:04:33 +02:00
|
|
|
}
|
2002-07-18 20:28:12 +02:00
|
|
|
|
|
|
|
/* map */
|
2005-08-31 15:00:57 +02:00
|
|
|
if (str_startswith(line, "map "))
|
2002-04-04 14:04:33 +02:00
|
|
|
{
|
2005-12-30 21:32:06 +01:00
|
|
|
g_keylayout = strtoul(line + sizeof("map ") - 1, NULL, 16);
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Keyboard, Debug, "xkeymap_read(), Keylayout 0x%x", g_keylayout);
|
2002-07-18 20:28:12 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2002-07-28 01:09:32 +02:00
|
|
|
/* compose */
|
2005-08-31 15:00:57 +02:00
|
|
|
if (str_startswith(line, "enable_compose"))
|
2002-07-28 01:09:32 +02:00
|
|
|
{
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Keyboard, Debug, "xkeymap_read(), enabling compose handling");
|
2003-08-22 01:23:15 +02:00
|
|
|
g_enable_compose = True;
|
2002-07-28 01:09:32 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2005-08-02 17:07:35 +02:00
|
|
|
/* sequence */
|
2005-08-31 15:00:57 +02:00
|
|
|
if (str_startswith(line, "sequence"))
|
2005-08-02 17:07:35 +02:00
|
|
|
{
|
2005-08-03 13:47:20 +02:00
|
|
|
add_sequence(line + sizeof("sequence") - 1, mapname);
|
2005-08-02 17:07:35 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2005-08-03 13:30:53 +02:00
|
|
|
/* keyboard_type */
|
2005-08-31 15:00:57 +02:00
|
|
|
if (str_startswith(line, "keyboard_type "))
|
2005-08-03 13:30:53 +02:00
|
|
|
{
|
2005-08-03 13:47:20 +02:00
|
|
|
g_keyboard_type = strtol(line + sizeof("keyboard_type ") - 1, NULL, 16);
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Keyboard, Debug, "xkeymap_read(), keyboard_type 0x%x",
|
|
|
|
g_keyboard_type);
|
2005-08-03 13:30:53 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* keyboard_subtype */
|
2005-08-31 15:00:57 +02:00
|
|
|
if (str_startswith(line, "keyboard_subtype "))
|
2005-08-03 13:30:53 +02:00
|
|
|
{
|
2005-08-03 13:47:20 +02:00
|
|
|
g_keyboard_subtype =
|
|
|
|
strtol(line + sizeof("keyboard_subtype ") - 1, NULL, 16);
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Keyboard, Debug, "xkeymap_read(), keyboard_subtype 0x%x",
|
|
|
|
g_keyboard_subtype);
|
2005-08-03 13:30:53 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* keyboard_functionkeys */
|
2005-08-31 15:00:57 +02:00
|
|
|
if (str_startswith(line, "keyboard_functionkeys "))
|
2005-08-03 13:30:53 +02:00
|
|
|
{
|
|
|
|
g_keyboard_functionkeys =
|
2005-08-03 13:47:20 +02:00
|
|
|
strtol(line + sizeof("keyboard_functionkeys ") - 1, NULL, 16);
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Keyboard, Debug, "xkeymap_read(), keyboard_functionkeys 0x%x",
|
|
|
|
g_keyboard_functionkeys);
|
2005-08-03 13:30:53 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2002-07-18 20:28:12 +02:00
|
|
|
/* Comment */
|
|
|
|
if (line[0] == '#')
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Normal line */
|
|
|
|
keyname = line;
|
|
|
|
p = strchr(line, ' ');
|
|
|
|
if (p == NULL)
|
|
|
|
{
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Keyboard, Error, "xkeymap_read(), bad line %d in keymap %s",
|
|
|
|
line_num, mapname);
|
2002-07-18 20:28:12 +02:00
|
|
|
continue;
|
2002-04-04 14:04:33 +02:00
|
|
|
}
|
2002-07-18 20:28:12 +02:00
|
|
|
else
|
2002-04-04 14:04:33 +02:00
|
|
|
{
|
2002-07-18 20:28:12 +02:00
|
|
|
*p = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* scancode */
|
|
|
|
p++;
|
|
|
|
scancode = strtol(p, &line_rest, 16);
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
/* FIXME: Should allow case-insensitive flag names.
|
|
|
|
Fix by using lex+yacc... */
|
|
|
|
modifiers = 0;
|
|
|
|
if (strstr(line_rest, "altgr"))
|
|
|
|
{
|
|
|
|
MASK_ADD_BITS(modifiers, MapAltGrMask);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strstr(line_rest, "shift"))
|
|
|
|
{
|
|
|
|
MASK_ADD_BITS(modifiers, MapLeftShiftMask);
|
|
|
|
}
|
|
|
|
|
2003-12-08 13:01:25 +01:00
|
|
|
if (strstr(line_rest, "numlock"))
|
|
|
|
{
|
|
|
|
MASK_ADD_BITS(modifiers, MapNumLockMask);
|
|
|
|
}
|
|
|
|
|
2002-07-28 00:35:38 +02:00
|
|
|
if (strstr(line_rest, "localstate"))
|
|
|
|
{
|
|
|
|
MASK_ADD_BITS(modifiers, MapLocalStateMask);
|
|
|
|
}
|
|
|
|
|
2002-09-11 13:11:27 +02:00
|
|
|
if (strstr(line_rest, "inhibit"))
|
|
|
|
{
|
|
|
|
MASK_ADD_BITS(modifiers, MapInhibitMask);
|
|
|
|
}
|
|
|
|
|
2002-07-18 20:28:12 +02:00
|
|
|
add_to_keymap(keyname, scancode, modifiers, mapname);
|
|
|
|
|
|
|
|
if (strstr(line_rest, "addupper"))
|
|
|
|
{
|
|
|
|
/* Automatically add uppercase key, with same modifiers
|
|
|
|
plus shift */
|
|
|
|
for (p = keyname; *p; p++)
|
2003-02-10 13:58:51 +01:00
|
|
|
*p = toupper((int) *p);
|
2002-07-18 20:28:12 +02:00
|
|
|
MASK_ADD_BITS(modifiers, MapLeftShiftMask);
|
|
|
|
add_to_keymap(keyname, scancode, modifiers, mapname);
|
2002-04-04 14:04:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
2002-07-18 20:28:12 +02:00
|
|
|
|
|
|
|
/* Before connecting and creating UI */
|
2002-07-18 18:38:31 +02:00
|
|
|
void
|
2002-09-14 13:48:44 +02:00
|
|
|
xkeymap_init(void)
|
2002-04-04 14:04:33 +02:00
|
|
|
{
|
2002-09-14 13:48:44 +02:00
|
|
|
unsigned int max_keycode;
|
2002-10-11 10:54:08 +02:00
|
|
|
|
2005-08-04 14:51:44 +02:00
|
|
|
if (strcmp(g_keymapname, "none"))
|
2002-09-26 16:11:59 +02:00
|
|
|
{
|
2005-08-04 14:51:44 +02:00
|
|
|
if (xkeymap_read(g_keymapname))
|
2002-09-26 16:11:59 +02:00
|
|
|
keymap_loaded = True;
|
|
|
|
}
|
2002-07-18 20:28:12 +02:00
|
|
|
|
2003-08-28 00:51:33 +02:00
|
|
|
XDisplayKeycodes(g_display, &min_keycode, (int *) &max_keycode);
|
2002-07-18 20:28:12 +02:00
|
|
|
}
|
2002-04-04 14:04:33 +02:00
|
|
|
|
2003-08-31 21:45:56 +02:00
|
|
|
static void
|
2007-01-08 05:47:06 +01:00
|
|
|
send_winkey(uint32 ev_time, RD_BOOL pressed, RD_BOOL leftkey)
|
2003-08-31 21:45:56 +02:00
|
|
|
{
|
|
|
|
uint8 winkey;
|
|
|
|
|
|
|
|
if (leftkey)
|
|
|
|
winkey = SCANCODE_CHAR_LWIN;
|
|
|
|
else
|
|
|
|
winkey = SCANCODE_CHAR_RWIN;
|
|
|
|
|
|
|
|
if (pressed)
|
|
|
|
{
|
2012-06-15 07:16:20 +02:00
|
|
|
if (g_rdp_version >= RDP_V5)
|
2003-08-31 21:45:56 +02:00
|
|
|
{
|
|
|
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, winkey);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* RDP4 doesn't support winkey. Fake with Ctrl-Esc */
|
|
|
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LCTRL);
|
|
|
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_ESC);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* key released */
|
2012-06-15 07:16:20 +02:00
|
|
|
if (g_rdp_version >= RDP_V5)
|
2003-08-31 21:45:56 +02:00
|
|
|
{
|
|
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, winkey);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_ESC);
|
|
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-11 15:01:31 +01:00
|
|
|
static void
|
|
|
|
reset_winkey(uint32 ev_time)
|
|
|
|
{
|
2012-06-15 07:16:20 +02:00
|
|
|
if (g_rdp_version >= RDP_V5)
|
2003-11-11 15:01:31 +01:00
|
|
|
{
|
|
|
|
/* For some reason, it seems to suffice to release
|
|
|
|
*either* the left or right winkey. */
|
|
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LWIN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-17 15:52:04 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
set_keypress_keysym(unsigned int keycode, KeySym keysym)
|
|
|
|
{
|
|
|
|
if (keycode < 8 || keycode > 255)
|
|
|
|
return;
|
|
|
|
keypress_keysyms[keycode] = keysym;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
KeySym
|
|
|
|
reset_keypress_keysym(unsigned int keycode, KeySym keysym)
|
|
|
|
{
|
|
|
|
KeySym ks;
|
|
|
|
if (keycode < 8 || keycode > 255)
|
|
|
|
return keysym;
|
|
|
|
ks = keypress_keysyms[keycode];
|
|
|
|
if (ks != 0)
|
|
|
|
{
|
|
|
|
keypress_keysyms[keycode] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ks = keysym;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ks;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-02 20:15:07 +02:00
|
|
|
/* Handle special key combinations */
|
2007-01-08 05:47:06 +01:00
|
|
|
RD_BOOL
|
|
|
|
handle_special_keys(uint32 keysym, unsigned int state, uint32 ev_time, RD_BOOL pressed)
|
2002-09-11 13:45:20 +02:00
|
|
|
{
|
|
|
|
switch (keysym)
|
|
|
|
{
|
2002-10-24 10:48:51 +02:00
|
|
|
case XK_Return:
|
2002-10-06 15:25:30 +02:00
|
|
|
if ((get_key_state(state, XK_Alt_L) || get_key_state(state, XK_Alt_R))
|
2002-10-11 11:37:48 +02:00
|
|
|
&& (get_key_state(state, XK_Control_L)
|
|
|
|
|| get_key_state(state, XK_Control_R)))
|
2002-09-11 13:45:20 +02:00
|
|
|
{
|
2002-10-24 10:48:51 +02:00
|
|
|
/* Ctrl-Alt-Enter: toggle full screen */
|
2002-09-24 13:14:46 +02:00
|
|
|
if (pressed)
|
|
|
|
xwin_toggle_fullscreen();
|
2002-10-24 10:48:51 +02:00
|
|
|
return True;
|
|
|
|
}
|
|
|
|
break;
|
2002-09-25 13:17:59 +02:00
|
|
|
|
2002-10-24 10:48:51 +02:00
|
|
|
case XK_Break:
|
|
|
|
/* Send Break sequence E0 46 E0 C6 */
|
|
|
|
if (pressed)
|
|
|
|
{
|
|
|
|
rdp_send_scancode(ev_time, RDP_KEYPRESS,
|
|
|
|
(SCANCODE_EXTENDED | 0x46));
|
|
|
|
rdp_send_scancode(ev_time, RDP_KEYPRESS,
|
|
|
|
(SCANCODE_EXTENDED | 0xc6));
|
2002-09-25 13:17:59 +02:00
|
|
|
}
|
2002-10-24 10:48:51 +02:00
|
|
|
/* No release sequence */
|
|
|
|
return True;
|
2003-12-08 16:28:24 +01:00
|
|
|
break;
|
2002-10-24 10:48:51 +02:00
|
|
|
|
|
|
|
case XK_Pause:
|
|
|
|
/* According to MS Keyboard Scan Code
|
|
|
|
Specification, pressing Pause should result
|
|
|
|
in E1 1D 45 E1 9D C5. I'm not exactly sure
|
|
|
|
of how this is supposed to be sent via
|
|
|
|
RDP. The code below seems to work, but with
|
|
|
|
the side effect that Left Ctrl stays
|
|
|
|
down. Therefore, we release it when Pause
|
|
|
|
is released. */
|
|
|
|
if (pressed)
|
2002-09-25 13:17:59 +02:00
|
|
|
{
|
2002-11-18 16:31:19 +01:00
|
|
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xe1, 0);
|
|
|
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x1d, 0);
|
|
|
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x45, 0);
|
|
|
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xe1, 0);
|
|
|
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x9d, 0);
|
|
|
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xc5, 0);
|
2002-09-11 13:45:20 +02:00
|
|
|
}
|
2002-10-24 10:48:51 +02:00
|
|
|
else
|
2002-09-25 13:07:57 +02:00
|
|
|
{
|
2002-10-24 10:48:51 +02:00
|
|
|
/* Release Left Ctrl */
|
|
|
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYRELEASE,
|
|
|
|
0x1d, 0);
|
2002-09-25 13:07:57 +02:00
|
|
|
}
|
|
|
|
return True;
|
2003-12-08 16:28:24 +01:00
|
|
|
break;
|
2002-09-25 13:07:57 +02:00
|
|
|
|
2002-09-11 13:45:20 +02:00
|
|
|
case XK_Meta_L: /* Windows keys */
|
|
|
|
case XK_Super_L:
|
|
|
|
case XK_Hyper_L:
|
2003-08-31 21:45:56 +02:00
|
|
|
send_winkey(ev_time, pressed, True);
|
|
|
|
return True;
|
2003-12-08 16:28:24 +01:00
|
|
|
break;
|
2003-08-31 21:45:56 +02:00
|
|
|
|
2002-09-11 13:45:20 +02:00
|
|
|
case XK_Meta_R:
|
|
|
|
case XK_Super_R:
|
|
|
|
case XK_Hyper_R:
|
2003-08-31 21:45:56 +02:00
|
|
|
send_winkey(ev_time, pressed, False);
|
2002-09-11 13:45:20 +02:00
|
|
|
return True;
|
2003-12-08 16:28:24 +01:00
|
|
|
break;
|
2003-02-18 14:44:27 +01:00
|
|
|
|
|
|
|
case XK_space:
|
|
|
|
/* Prevent access to the Windows system menu in single app mode */
|
2003-08-28 00:51:33 +02:00
|
|
|
if (g_win_button_size
|
2003-02-18 14:44:27 +01:00
|
|
|
&& (get_key_state(state, XK_Alt_L) || get_key_state(state, XK_Alt_R)))
|
|
|
|
return True;
|
2003-12-08 16:28:24 +01:00
|
|
|
break;
|
2005-06-07 13:21:53 +02:00
|
|
|
|
2003-12-08 13:01:25 +01:00
|
|
|
case XK_Num_Lock:
|
2005-06-07 13:21:53 +02:00
|
|
|
/* Synchronize on key release */
|
|
|
|
if (g_numlock_sync && !pressed)
|
|
|
|
rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0,
|
|
|
|
ui_get_numlock_state(read_keyboard_state()), 0);
|
|
|
|
|
|
|
|
/* Inhibit */
|
|
|
|
return True;
|
2003-12-08 16:28:24 +01:00
|
|
|
break;
|
2006-03-10 09:50:43 +01:00
|
|
|
case XK_Overlay1_Enable:
|
|
|
|
/* Toggle SeamlessRDP */
|
|
|
|
if (pressed)
|
|
|
|
ui_seamless_toggle();
|
|
|
|
break;
|
2003-02-18 14:44:27 +01:00
|
|
|
|
2002-09-11 13:45:20 +02:00
|
|
|
}
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
2002-04-20 11:41:03 +02:00
|
|
|
|
2002-07-18 20:28:12 +02:00
|
|
|
key_translation
|
2002-09-24 09:33:17 +02:00
|
|
|
xkeymap_translate_key(uint32 keysym, unsigned int keycode, unsigned int state)
|
2002-07-18 20:28:12 +02:00
|
|
|
{
|
2005-08-02 17:07:35 +02:00
|
|
|
key_translation tr = { 0, 0, 0, 0 };
|
|
|
|
key_translation *ptr;
|
2014-05-20 12:43:03 +02:00
|
|
|
key_translation_entry *entry;
|
|
|
|
|
|
|
|
entry = get_key_translation_entry(keysym);
|
|
|
|
ptr = entry ? entry->tr : NULL;
|
2002-07-18 20:28:12 +02:00
|
|
|
|
2005-08-02 17:07:35 +02:00
|
|
|
if (ptr)
|
2002-09-11 13:11:27 +02:00
|
|
|
{
|
2005-08-02 17:07:35 +02:00
|
|
|
tr = *ptr;
|
|
|
|
if (tr.seq_keysym == 0) /* Normal scancode translation */
|
2002-07-28 00:35:38 +02:00
|
|
|
{
|
2006-04-08 00:20:43 +02:00
|
|
|
if (MASK_HAS_BITS(tr.modifiers, MapInhibitMask))
|
2005-08-02 17:07:35 +02:00
|
|
|
{
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Keyboard, Debug, "xkeymap_translate_key(), inhibiting key");
|
2005-08-02 17:07:35 +02:00
|
|
|
tr.scancode = 0;
|
|
|
|
return tr;
|
|
|
|
}
|
|
|
|
|
2006-04-08 00:20:43 +02:00
|
|
|
if (MASK_HAS_BITS(tr.modifiers, MapLocalStateMask))
|
2005-08-02 17:07:35 +02:00
|
|
|
{
|
|
|
|
/* The modifiers to send for this key should be obtained
|
|
|
|
from the local state. Currently, only shift is implemented. */
|
2006-04-08 00:20:43 +02:00
|
|
|
if (MASK_HAS_BITS(state, ShiftMask))
|
2005-08-02 17:07:35 +02:00
|
|
|
{
|
|
|
|
tr.modifiers = MapLeftShiftMask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-08 00:17:14 +02:00
|
|
|
/* Windows interprets CapsLock+Ctrl+key
|
|
|
|
differently from Shift+Ctrl+key. Since we
|
|
|
|
are simulating CapsLock with Shifts, things
|
|
|
|
like Ctrl+f with CapsLock on breaks. To
|
|
|
|
solve this, we are releasing Shift if Ctrl
|
|
|
|
is on, but only if Shift isn't physically pressed. */
|
|
|
|
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask)
|
|
|
|
&& MASK_HAS_BITS(remote_modifier_state, MapCtrlMask)
|
|
|
|
&& !MASK_HAS_BITS(state, ShiftMask))
|
2005-08-02 17:07:35 +02:00
|
|
|
{
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Keyboard, Debug,
|
|
|
|
"xkeymap_translate_key(), non-physical Shift + Ctrl pressed, releasing Shift");
|
2006-04-08 00:17:14 +02:00
|
|
|
MASK_REMOVE_BITS(tr.modifiers, MapShiftMask);
|
2005-08-02 17:07:35 +02:00
|
|
|
}
|
|
|
|
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Keyboard, Debug,
|
|
|
|
"xkeymap_translate_key(), found scancode translation, scancode=0x%x, modifiers=0x%x",
|
|
|
|
tr.scancode, tr.modifiers);
|
2002-07-28 00:35:38 +02:00
|
|
|
}
|
|
|
|
}
|
2005-08-02 17:07:35 +02:00
|
|
|
else
|
2005-01-23 20:29:31 +01:00
|
|
|
{
|
2005-08-02 17:07:35 +02:00
|
|
|
if (keymap_loaded)
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Keyboard, Warning, "No translation for (keysym 0x%lx, %s)", keysym,
|
|
|
|
get_ksname(keysym));
|
2005-01-23 20:29:31 +01:00
|
|
|
|
2005-08-02 17:07:35 +02:00
|
|
|
/* not in keymap, try to interpret the raw scancode */
|
|
|
|
if (((int) keycode >= min_keycode) && (keycode <= 0x60))
|
|
|
|
{
|
|
|
|
tr.scancode = keycode - min_keycode;
|
|
|
|
|
|
|
|
/* The modifiers to send for this key should be
|
|
|
|
obtained from the local state. Currently, only
|
|
|
|
shift is implemented. */
|
2006-04-08 00:20:43 +02:00
|
|
|
if (MASK_HAS_BITS(state, ShiftMask))
|
2005-08-02 17:07:35 +02:00
|
|
|
{
|
|
|
|
tr.modifiers = MapLeftShiftMask;
|
|
|
|
}
|
|
|
|
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Keyboard, Debug, "Sending guessed scancode 0x%x", tr.scancode);
|
2005-08-02 17:07:35 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Keyboard, Debug, "No good guess for keycode 0x%x found", keycode);
|
2005-08-02 17:07:35 +02:00
|
|
|
}
|
2002-04-20 11:41:03 +02:00
|
|
|
}
|
2002-04-04 14:04:33 +02:00
|
|
|
|
2005-08-02 17:07:35 +02:00
|
|
|
return tr;
|
|
|
|
}
|
2002-04-04 14:04:33 +02:00
|
|
|
|
2007-05-03 06:53:39 +02:00
|
|
|
static RD_BOOL
|
|
|
|
is_modifier(uint8 scancode)
|
|
|
|
{
|
|
|
|
switch (scancode)
|
|
|
|
{
|
|
|
|
case SCANCODE_CHAR_LSHIFT:
|
|
|
|
case SCANCODE_CHAR_RSHIFT:
|
|
|
|
case SCANCODE_CHAR_LCTRL:
|
|
|
|
case SCANCODE_CHAR_RCTRL:
|
|
|
|
case SCANCODE_CHAR_LALT:
|
|
|
|
case SCANCODE_CHAR_RALT:
|
|
|
|
case SCANCODE_CHAR_LWIN:
|
|
|
|
case SCANCODE_CHAR_RWIN:
|
|
|
|
case SCANCODE_CHAR_NUMLOCK:
|
|
|
|
return True;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-02 17:07:35 +02:00
|
|
|
void
|
|
|
|
xkeymap_send_keys(uint32 keysym, unsigned int keycode, unsigned int state, uint32 ev_time,
|
2007-01-08 05:47:06 +01:00
|
|
|
RD_BOOL pressed, uint8 nesting)
|
2005-08-02 17:07:35 +02:00
|
|
|
{
|
|
|
|
key_translation tr, *ptr;
|
|
|
|
tr = xkeymap_translate_key(keysym, keycode, state);
|
|
|
|
|
|
|
|
if (tr.seq_keysym == 0)
|
2002-07-18 20:28:12 +02:00
|
|
|
{
|
2005-08-02 17:07:35 +02:00
|
|
|
/* Scancode translation */
|
|
|
|
if (tr.scancode == 0)
|
|
|
|
return;
|
2002-09-16 15:21:44 +02:00
|
|
|
|
2007-10-08 14:34:05 +02:00
|
|
|
save_remote_modifiers(tr.scancode);
|
|
|
|
ensure_remote_modifiers(ev_time, tr);
|
|
|
|
rdp_send_scancode(ev_time, pressed ? RDP_KEYPRESS : RDP_KEYRELEASE, tr.scancode);
|
|
|
|
restore_remote_modifiers(ev_time, tr.scancode);
|
2005-08-02 17:07:35 +02:00
|
|
|
return;
|
2002-07-18 20:28:12 +02:00
|
|
|
}
|
2005-08-02 17:07:35 +02:00
|
|
|
|
|
|
|
/* Sequence, only on key down */
|
|
|
|
if (pressed)
|
2002-07-18 20:28:12 +02:00
|
|
|
{
|
2005-08-02 17:07:35 +02:00
|
|
|
ptr = &tr;
|
|
|
|
do
|
|
|
|
{
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Keyboard, Debug,
|
|
|
|
"xkeymap_send_keys(), handling sequence element, keysym=0x%x",
|
|
|
|
(unsigned int) ptr->seq_keysym);
|
2005-08-04 15:39:57 +02:00
|
|
|
|
|
|
|
if (nesting++ > 32)
|
|
|
|
{
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Keyboard, Error, "Sequence nesting too deep");
|
2005-08-04 15:39:57 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
xkeymap_send_keys(ptr->seq_keysym, keycode, state, ev_time, True, nesting);
|
|
|
|
xkeymap_send_keys(ptr->seq_keysym, keycode, state, ev_time, False, nesting);
|
2005-08-02 17:07:35 +02:00
|
|
|
ptr = ptr->next;
|
|
|
|
}
|
|
|
|
while (ptr);
|
2002-04-04 14:04:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-18 18:38:31 +02:00
|
|
|
uint16
|
|
|
|
xkeymap_translate_button(unsigned int button)
|
2002-04-04 14:04:33 +02:00
|
|
|
{
|
|
|
|
switch (button)
|
|
|
|
{
|
2002-07-18 18:38:31 +02:00
|
|
|
case Button1: /* left */
|
2002-04-04 14:04:33 +02:00
|
|
|
return MOUSE_FLAG_BUTTON1;
|
2002-07-18 18:38:31 +02:00
|
|
|
case Button2: /* middle */
|
2002-04-04 14:04:33 +02:00
|
|
|
return MOUSE_FLAG_BUTTON3;
|
2002-07-18 18:38:31 +02:00
|
|
|
case Button3: /* right */
|
2002-04-04 14:04:33 +02:00
|
|
|
return MOUSE_FLAG_BUTTON2;
|
2002-07-23 03:53:04 +02:00
|
|
|
case Button4: /* wheel up */
|
|
|
|
return MOUSE_FLAG_BUTTON4;
|
|
|
|
case Button5: /* wheel down */
|
|
|
|
return MOUSE_FLAG_BUTTON5;
|
2002-04-04 14:04:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2002-07-18 20:28:12 +02:00
|
|
|
|
|
|
|
char *
|
2002-09-24 09:33:17 +02:00
|
|
|
get_ksname(uint32 keysym)
|
2002-07-18 20:28:12 +02:00
|
|
|
{
|
|
|
|
char *ksname = NULL;
|
|
|
|
|
|
|
|
if (keysym == NoSymbol)
|
|
|
|
ksname = "NoSymbol";
|
|
|
|
else if (!(ksname = XKeysymToString(keysym)))
|
|
|
|
ksname = "(no name)";
|
|
|
|
|
|
|
|
return ksname;
|
|
|
|
}
|
|
|
|
|
2003-08-27 11:42:55 +02:00
|
|
|
void
|
2003-09-15 10:03:30 +02:00
|
|
|
save_remote_modifiers(uint8 scancode)
|
2003-08-27 11:42:55 +02:00
|
|
|
{
|
2003-09-15 10:03:30 +02:00
|
|
|
if (is_modifier(scancode))
|
|
|
|
return;
|
|
|
|
|
2003-08-27 11:42:55 +02:00
|
|
|
saved_remote_modifier_state = remote_modifier_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-09-15 10:03:30 +02:00
|
|
|
restore_remote_modifiers(uint32 ev_time, uint8 scancode)
|
2003-08-27 11:42:55 +02:00
|
|
|
{
|
2014-11-19 08:44:18 +01:00
|
|
|
key_translation dummy = { 0 };
|
2003-08-27 11:42:55 +02:00
|
|
|
|
2003-09-15 10:03:30 +02:00
|
|
|
if (is_modifier(scancode))
|
|
|
|
return;
|
|
|
|
|
2003-08-27 11:42:55 +02:00
|
|
|
dummy.scancode = 0;
|
|
|
|
dummy.modifiers = saved_remote_modifier_state;
|
|
|
|
ensure_remote_modifiers(ev_time, dummy);
|
|
|
|
}
|
2002-07-18 20:28:12 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
ensure_remote_modifiers(uint32 ev_time, key_translation tr)
|
|
|
|
{
|
|
|
|
/* If this key is a modifier, do nothing */
|
2003-09-15 10:03:30 +02:00
|
|
|
if (is_modifier(tr.scancode))
|
|
|
|
return;
|
2002-07-18 20:28:12 +02:00
|
|
|
|
2003-12-08 13:01:25 +01:00
|
|
|
if (!g_numlock_sync)
|
|
|
|
{
|
|
|
|
/* NumLock */
|
|
|
|
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)
|
|
|
|
!= MASK_HAS_BITS(remote_modifier_state, MapNumLockMask))
|
|
|
|
{
|
|
|
|
/* The remote modifier state is not correct */
|
|
|
|
uint16 new_remote_state;
|
|
|
|
|
|
|
|
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask))
|
|
|
|
{
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Keyboard, Debug,
|
|
|
|
"ensure_remote_modifiers(), remote NumLock state is incorrect, activating NumLock");
|
2003-12-08 13:01:25 +01:00
|
|
|
new_remote_state = KBD_FLAG_NUMLOCK;
|
|
|
|
remote_modifier_state = MapNumLockMask;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Keyboard, Debug,
|
|
|
|
"ensure_remote_modifiers(), remote NumLock state is incorrect, deactivating NumLock.");
|
2003-12-08 13:01:25 +01:00
|
|
|
new_remote_state = 0;
|
|
|
|
remote_modifier_state = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-17 18:57:07 +02:00
|
|
|
/* Shift. Left shift and right shift are treated as equal; either is fine. */
|
2002-07-18 20:28:12 +02:00
|
|
|
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask)
|
|
|
|
!= MASK_HAS_BITS(remote_modifier_state, MapShiftMask))
|
|
|
|
{
|
|
|
|
/* The remote modifier state is not correct */
|
2002-09-17 18:57:07 +02:00
|
|
|
if (MASK_HAS_BITS(tr.modifiers, MapLeftShiftMask))
|
2002-07-18 20:28:12 +02:00
|
|
|
{
|
2002-09-17 18:57:07 +02:00
|
|
|
/* Needs left shift. Send down. */
|
2002-07-30 09:18:48 +02:00
|
|
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LSHIFT);
|
2002-07-18 20:28:12 +02:00
|
|
|
}
|
2002-09-17 18:57:07 +02:00
|
|
|
else if (MASK_HAS_BITS(tr.modifiers, MapRightShiftMask))
|
|
|
|
{
|
|
|
|
/* Needs right shift. Send down. */
|
|
|
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_RSHIFT);
|
|
|
|
}
|
2002-07-18 20:28:12 +02:00
|
|
|
else
|
|
|
|
{
|
2002-09-17 18:57:07 +02:00
|
|
|
/* Should not use this modifier. Send up for shift currently pressed. */
|
|
|
|
if (MASK_HAS_BITS(remote_modifier_state, MapLeftShiftMask))
|
|
|
|
/* Left shift is down */
|
|
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT);
|
|
|
|
else
|
|
|
|
/* Right shift is down */
|
|
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT);
|
2002-07-18 20:28:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* AltGr */
|
|
|
|
if (MASK_HAS_BITS(tr.modifiers, MapAltGrMask)
|
|
|
|
!= MASK_HAS_BITS(remote_modifier_state, MapAltGrMask))
|
|
|
|
{
|
|
|
|
/* The remote modifier state is not correct */
|
|
|
|
if (MASK_HAS_BITS(tr.modifiers, MapAltGrMask))
|
|
|
|
{
|
|
|
|
/* Needs this modifier. Send down. */
|
2002-07-30 09:18:48 +02:00
|
|
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_RALT);
|
2002-07-18 20:28:12 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Should not use this modifier. Send up. */
|
2002-07-30 09:18:48 +02:00
|
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT);
|
2002-07-18 20:28:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-11 11:52:30 +02:00
|
|
|
|
2002-07-18 20:28:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-03 14:33:35 +01:00
|
|
|
unsigned int
|
|
|
|
read_keyboard_state()
|
|
|
|
{
|
2004-04-10 11:34:52 +02:00
|
|
|
#ifdef RDP2VNC
|
|
|
|
return 0;
|
|
|
|
#else
|
2003-11-03 14:33:35 +01:00
|
|
|
unsigned int state;
|
|
|
|
Window wdummy;
|
|
|
|
int dummy;
|
|
|
|
|
|
|
|
XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy, &dummy, &dummy, &state);
|
|
|
|
return state;
|
2004-04-10 11:34:52 +02:00
|
|
|
#endif
|
2003-11-03 14:33:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint16
|
|
|
|
ui_get_numlock_state(unsigned int state)
|
|
|
|
{
|
|
|
|
uint16 numlock_state = 0;
|
|
|
|
|
|
|
|
if (get_key_state(state, XK_Num_Lock))
|
|
|
|
numlock_state = KBD_FLAG_NUMLOCK;
|
|
|
|
|
|
|
|
return numlock_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-17 10:18:41 +02:00
|
|
|
void
|
2003-11-03 14:33:35 +01:00
|
|
|
reset_modifier_keys()
|
2002-09-17 10:18:41 +02:00
|
|
|
{
|
2003-11-03 14:33:35 +01:00
|
|
|
unsigned int state = read_keyboard_state();
|
|
|
|
|
2002-09-17 10:18:41 +02:00
|
|
|
/* reset keys */
|
|
|
|
uint32 ev_time;
|
|
|
|
ev_time = time(NULL);
|
|
|
|
|
2002-10-11 11:37:48 +02:00
|
|
|
if (MASK_HAS_BITS(remote_modifier_state, MapLeftShiftMask)
|
|
|
|
&& !get_key_state(state, XK_Shift_L))
|
2002-09-17 10:18:41 +02:00
|
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT);
|
|
|
|
|
2002-10-11 11:37:48 +02:00
|
|
|
if (MASK_HAS_BITS(remote_modifier_state, MapRightShiftMask)
|
|
|
|
&& !get_key_state(state, XK_Shift_R))
|
2002-09-17 10:18:41 +02:00
|
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT);
|
|
|
|
|
2002-10-11 11:37:48 +02:00
|
|
|
if (MASK_HAS_BITS(remote_modifier_state, MapLeftCtrlMask)
|
|
|
|
&& !get_key_state(state, XK_Control_L))
|
2002-09-17 10:18:41 +02:00
|
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL);
|
|
|
|
|
2002-10-11 11:37:48 +02:00
|
|
|
if (MASK_HAS_BITS(remote_modifier_state, MapRightCtrlMask)
|
|
|
|
&& !get_key_state(state, XK_Control_R))
|
2002-09-17 10:18:41 +02:00
|
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RCTRL);
|
|
|
|
|
2002-09-26 16:04:30 +02:00
|
|
|
if (MASK_HAS_BITS(remote_modifier_state, MapLeftAltMask) && !get_key_state(state, XK_Alt_L))
|
2002-09-17 10:18:41 +02:00
|
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LALT);
|
|
|
|
|
|
|
|
if (MASK_HAS_BITS(remote_modifier_state, MapRightAltMask) &&
|
2004-06-01 10:06:02 +02:00
|
|
|
!get_key_state(state, XK_Alt_R) && !get_key_state(state, XK_Mode_switch)
|
|
|
|
&& !get_key_state(state, XK_ISO_Level3_Shift))
|
2002-09-17 10:18:41 +02:00
|
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT);
|
2003-11-03 14:33:35 +01:00
|
|
|
|
2003-11-11 15:01:31 +01:00
|
|
|
reset_winkey(ev_time);
|
|
|
|
|
2003-12-08 13:01:25 +01:00
|
|
|
if (g_numlock_sync)
|
|
|
|
rdp_send_input(ev_time, RDP_INPUT_SYNCHRONIZE, 0, ui_get_numlock_state(state), 0);
|
2002-09-17 10:18:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-18 20:28:12 +02:00
|
|
|
static void
|
2007-01-08 05:47:06 +01:00
|
|
|
update_modifier_state(uint8 scancode, RD_BOOL pressed)
|
2002-07-18 20:28:12 +02:00
|
|
|
{
|
2002-09-11 09:39:53 +02:00
|
|
|
uint16 old_modifier_state;
|
|
|
|
|
|
|
|
old_modifier_state = remote_modifier_state;
|
2002-07-18 20:28:12 +02:00
|
|
|
|
2002-09-26 16:04:30 +02:00
|
|
|
switch (scancode)
|
2002-07-18 20:28:12 +02:00
|
|
|
{
|
|
|
|
case SCANCODE_CHAR_LSHIFT:
|
2002-07-30 09:18:48 +02:00
|
|
|
MASK_CHANGE_BIT(remote_modifier_state, MapLeftShiftMask, pressed);
|
2002-07-18 20:28:12 +02:00
|
|
|
break;
|
|
|
|
case SCANCODE_CHAR_RSHIFT:
|
2002-07-30 09:18:48 +02:00
|
|
|
MASK_CHANGE_BIT(remote_modifier_state, MapRightShiftMask, pressed);
|
2002-07-18 20:28:12 +02:00
|
|
|
break;
|
|
|
|
case SCANCODE_CHAR_LCTRL:
|
2002-07-30 09:18:48 +02:00
|
|
|
MASK_CHANGE_BIT(remote_modifier_state, MapLeftCtrlMask, pressed);
|
2002-07-18 20:28:12 +02:00
|
|
|
break;
|
|
|
|
case SCANCODE_CHAR_RCTRL:
|
2002-07-30 09:18:48 +02:00
|
|
|
MASK_CHANGE_BIT(remote_modifier_state, MapRightCtrlMask, pressed);
|
2002-07-18 20:28:12 +02:00
|
|
|
break;
|
|
|
|
case SCANCODE_CHAR_LALT:
|
2002-07-30 09:18:48 +02:00
|
|
|
MASK_CHANGE_BIT(remote_modifier_state, MapLeftAltMask, pressed);
|
2002-07-18 20:28:12 +02:00
|
|
|
break;
|
|
|
|
case SCANCODE_CHAR_RALT:
|
2002-07-30 09:18:48 +02:00
|
|
|
MASK_CHANGE_BIT(remote_modifier_state, MapRightAltMask, pressed);
|
2002-07-18 20:28:12 +02:00
|
|
|
break;
|
|
|
|
case SCANCODE_CHAR_LWIN:
|
2002-07-30 09:18:48 +02:00
|
|
|
MASK_CHANGE_BIT(remote_modifier_state, MapLeftWinMask, pressed);
|
2002-07-18 20:28:12 +02:00
|
|
|
break;
|
|
|
|
case SCANCODE_CHAR_RWIN:
|
2002-07-30 09:18:48 +02:00
|
|
|
MASK_CHANGE_BIT(remote_modifier_state, MapRightWinMask, pressed);
|
2002-07-18 20:28:12 +02:00
|
|
|
break;
|
2003-12-08 13:01:25 +01:00
|
|
|
case SCANCODE_CHAR_NUMLOCK:
|
|
|
|
/* KeyReleases for NumLocks are sent immediately. Toggle the
|
|
|
|
modifier state only on Keypress */
|
|
|
|
if (pressed && !g_numlock_sync)
|
|
|
|
{
|
2007-01-08 05:47:06 +01:00
|
|
|
RD_BOOL newNumLockState;
|
2003-12-08 13:01:25 +01:00
|
|
|
newNumLockState =
|
|
|
|
(MASK_HAS_BITS
|
|
|
|
(remote_modifier_state, MapNumLockMask) == False);
|
|
|
|
MASK_CHANGE_BIT(remote_modifier_state,
|
|
|
|
MapNumLockMask, newNumLockState);
|
|
|
|
}
|
2002-07-18 20:28:12 +02:00
|
|
|
}
|
2002-09-11 09:39:53 +02:00
|
|
|
|
|
|
|
if (old_modifier_state != remote_modifier_state)
|
|
|
|
{
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Keyboard, Debug,
|
|
|
|
"update_modifier_state(), before modifier_state:0x%x, pressed=0x%x",
|
|
|
|
old_modifier_state, pressed);
|
|
|
|
logger(Keyboard, Debug, "update_modifier_state(), after modifier_state:0x%x",
|
|
|
|
remote_modifier_state);
|
2002-09-11 09:39:53 +02:00
|
|
|
}
|
2002-07-18 20:28:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Send keyboard input */
|
|
|
|
void
|
2002-09-26 16:04:30 +02:00
|
|
|
rdp_send_scancode(uint32 time, uint16 flags, uint8 scancode)
|
2002-07-18 20:28:12 +02:00
|
|
|
{
|
|
|
|
update_modifier_state(scancode, !(flags & RDP_KEYRELEASE));
|
|
|
|
|
|
|
|
if (scancode & SCANCODE_EXTENDED)
|
|
|
|
{
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Keyboard, Debug,
|
|
|
|
"rdp_send_scancode(), sending extended scancode=0x%x, flags=0x%x",
|
|
|
|
scancode & ~SCANCODE_EXTENDED, flags);
|
2002-07-18 20:28:12 +02:00
|
|
|
rdp_send_input(time, RDP_INPUT_SCANCODE, flags | KBD_FLAG_EXT,
|
|
|
|
scancode & ~SCANCODE_EXTENDED, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Keyboard, Debug, "rdp_send_scancode(), sending scancode=0x%x, flags=0x%x",
|
|
|
|
scancode, flags);
|
2002-07-31 08:49:34 +02:00
|
|
|
rdp_send_input(time, RDP_INPUT_SCANCODE, flags, scancode, 0);
|
2002-07-18 20:28:12 +02:00
|
|
|
}
|
|
|
|
}
|