Skip to content

Commit

Permalink
Allow a programmable backspace key for the login screen
Browse files Browse the repository at this point in the history
The login screen uses hardcoded scancode values to identify particular
keys. This is changed for the backspace key for Colemak support, as
the caps lock key has been re-purposed as a backspace key. We now
identify a backspace request by looking at the keysym for the key.
  • Loading branch information
matt335672 committed Nov 18, 2024
1 parent cbf5f7a commit 17ad375
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 55 deletions.
40 changes: 0 additions & 40 deletions xrdp/lang.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,46 +118,6 @@ get_key_info_from_kbd_event(int keyboard_flags, int key_code, int *keys,
return rv;
}

/*****************************************************************************/
int
get_keysym_from_kbd_event(int keyboard_flags, int key_code, int *keys,
int caps_lock, int num_lock, int scroll_lock,
struct xrdp_keymap *keymap)
{
struct xrdp_key_info *ki;

ki = get_key_info_from_kbd_event(keyboard_flags, key_code, keys,
caps_lock, num_lock, scroll_lock,
keymap);

if (ki == 0)
{
return 0;
}

return ki->sym;
}

/*****************************************************************************/
char32_t
get_char_from_kbd_event(int keyboard_flags, int key_code, int *keys,
int caps_lock, int num_lock, int scroll_lock,
struct xrdp_keymap *keymap)
{
struct xrdp_key_info *ki;

ki = get_key_info_from_kbd_event(keyboard_flags, key_code, keys,
caps_lock, num_lock, scroll_lock,
keymap);

if (ki == 0)
{
return 0;
}

return ki->chr;
}

/*****************************************************************************/
/**
* Converts a table key to a scancode index value
Expand Down
8 changes: 0 additions & 8 deletions xrdp/xrdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,14 +442,6 @@ get_key_info_from_kbd_event(int keyboard_flags, int key_code, int *keys,
int caps_lock, int num_lock, int scroll_lock,
struct xrdp_keymap *keymap);
int
get_keysym_from_kbd_event(int keyboard_flags, int key_code, int *keys,
int caps_lock, int num_lock, int scroll_lock,
struct xrdp_keymap *keymap);
char32_t
get_char_from_kbd_event(int keyboard_flags, int key_code, int *keys,
int caps_lock, int num_lock, int scroll_lock,
struct xrdp_keymap *keymap);
int
get_keymaps(int keylayout, struct xrdp_keymap *keymap);

int
Expand Down
22 changes: 15 additions & 7 deletions xrdp/xrdp_bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
#include "log.h"
#include "string_calls.h"


// For a very few key functions, using the keysym is preferable to the
// raw scancode. Here are defines to avoid pulling an X11 dependency
// into the xrdp:-
#define XK_BackSpace 0xff08


static const unsigned int g_crc_table[256] =
Expand Down Expand Up @@ -1150,6 +1153,13 @@ xrdp_bitmap_def_proc(struct xrdp_bitmap *self, int msg,
{
int scan_code = SCANCODE_FROM_KBD_EVENT(param1, param2);
int num_lock = self->wm->num_lock;
/* We may need a keysym or a printable character for the key */
struct xrdp_key_info *ki = get_key_info_from_kbd_event
(param2, param1, self->wm->keys,
self->wm->caps_lock,
self->wm->num_lock, self->wm->scroll_lock,
&(self->wm->keymap));

/* left or up arrow */
if ((scan_code == SCANCODE_LEFT_ARROW_KEY) ||
(scan_code == SCANCODE_UP_ARROW_KEY) ||
Expand All @@ -1174,8 +1184,9 @@ xrdp_bitmap_def_proc(struct xrdp_bitmap *self, int msg,
xrdp_bitmap_invalidate(self, 0);
}
}
/* backspace */
else if (scan_code == SCANCODE_BACKSPACE_KEY)
/* backspace. Test keysym rather than scan code, so keys
* other than SCANCODE_BACKSPACE_KEY can generate backspace */
else if (ki != NULL && ki->sym == XK_BackSpace)
{
n = utf8_char_count(self->caption1);

Expand Down Expand Up @@ -1229,10 +1240,7 @@ xrdp_bitmap_def_proc(struct xrdp_bitmap *self, int msg,
}
else
{
char32_t c = get_char_from_kbd_event
(param2, param1, self->wm->keys, self->wm->caps_lock,
self->wm->num_lock, self->wm->scroll_lock,
&(self->wm->keymap));
char32_t c = (ki == NULL) ? 0 : ki->chr;
// Add a printing character to the string. If successful,
// bump the edit position and re-display the string
if (c >= ' ' &&
Expand Down

0 comments on commit 17ad375

Please sign in to comment.