Skip to content

Commit

Permalink
Allow keycode set to be specified for the X server
Browse files Browse the repository at this point in the history
This commit allows a keycode_set to be specified as a module parameter
in xrdp.ini. This has the following effects:-
1) xrdp loads the specified keycode set for mapping RDP scancodes to
   X11 keycodes. These are then passed to xorgxrdp as part of key press/
   key release events.
2) The name of the XKB rules which use the specified keycode set are
   passed to xorgxrdp so that XKB can be configured with rules which
   match the chosen keycodes.

The effect is to remove all keycode set dependencies from xorgxrdp.
Normally evdev rules and evdev keycodes will be used but base rules and
base keycodes can be used instead for applications that require them.
Also, any systems which do not ship the evdev rules can be made to
work with base rules.
  • Loading branch information
matt335672 committed Jun 24, 2024
1 parent 61317f0 commit 76a6642
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 1 deletion.
7 changes: 6 additions & 1 deletion common/xrdp_client_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ struct xrdp_client_info
char layout[16];
char variant[16];
char options[256];
char xkb_rules[32];
// A few x11 keycodes are needed by the xup module
int x11_keycode_caps_lock;
int x11_keycode_num_lock;
int x11_keycode_scroll_lock;

/* ==================================================================== */
/* Private to xrdp below this line */
Expand Down Expand Up @@ -269,6 +274,6 @@ enum xrdp_encoder_flags

/* yyyymmdd of last incompatible change to xrdp_client_info */
/* also used for changes to all the xrdp installed headers */
#define CLIENT_INFO_CURRENT_VERSION 20240514
#define CLIENT_INFO_CURRENT_VERSION 20240624

#endif
5 changes: 5 additions & 0 deletions docs/man/xrdp.ini.5.in
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,11 @@ use of \fBxrdp\-chansrv\fR facilities in the VNC session.
The first form of this setting is recommended, replacing \fIn\fR with the
X11 display number of the session.

.TP
\fBkeycode_set\fR=\fI<string>\fR
[Xorg only] Asks for the specified keycode set to be used by the X server.
Normally "evdev" or "base". The default should be correct for your system.

.SH "EXAMPLES"
This is an example \fBxrdp.ini\fR:

Expand Down
10 changes: 10 additions & 0 deletions xrdp/lang.c
Original file line number Diff line number Diff line change
Expand Up @@ -653,4 +653,14 @@ xrdp_init_xkb_layout(struct xrdp_client_info *client_info)
LOG(LOG_LEVEL_ERROR, "xrdp_init_xkb_layout: error opening %s",
keyboard_cfg_file);
}

// Initialise the rules and a few keycodes for xorgxrdp
snprintf(client_info->xkb_rules, sizeof(client_info->xkb_rules),
"%s", scancode_get_xkb_rules());
client_info->x11_keycode_caps_lock =
scancode_to_x11_keycode(SCANCODE_CAPS_KEY);
client_info->x11_keycode_num_lock =
scancode_to_x11_keycode(SCANCODE_NUMLOCK_KEY);
client_info->x11_keycode_scroll_lock =
scancode_to_x11_keycode(SCANCODE_SCROLL_KEY);
}
1 change: 1 addition & 0 deletions xrdp/xrdp.ini.in
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ username=ask
password=ask
port=-1
code=20
#keycode_set=evdev

[Xvnc]
name=Xvnc
Expand Down
18 changes: 18 additions & 0 deletions xup/xup.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,21 @@ lib_mod_connect(struct mod *mod)
// be set.
//
// Load the XKB layout
if (mod->keycode_set[0] != '\0')
{
if (scancode_set_keycode_set(mod->keycode_set) == 0)
{
LOG(LOG_LEVEL_INFO, "Loaded '%s' keycode set", mod->keycode_set);
}
else
{
LOG(LOG_LEVEL_WARNING, "Unable to load '%s' keycode set",
mod->keycode_set);
}
}
mod->server_init_xkb_layout(mod, &(mod->client_info));
LOG(LOG_LEVEL_INFO, "XKB rules '%s' will be used by the module",
mod->client_info.xkb_rules);

make_stream(s);
g_sprintf(con_port, "%s", mod->port);
Expand Down Expand Up @@ -1869,6 +1883,10 @@ lib_mod_set_param(struct mod *mod, const char *name, const char *value)
{
g_strncpy(mod->port, value, 255);
}
else if (g_strcasecmp(name, "keycode_set") == 0)
{
g_snprintf(mod->keycode_set, sizeof(mod->keycode_set), "%s", value);
}
else if (g_strcasecmp(name, "client_info") == 0)
{
g_memcpy(&(mod->client_info), value, sizeof(mod->client_info));
Expand Down
1 change: 1 addition & 0 deletions xup/xup.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ struct mod
int screen_shmem_id_mapped; /* boolean */
char *screen_shmem_pixels;
struct trans *trans;
char keycode_set[32];
};

#endif // XUP_H

0 comments on commit 76a6642

Please sign in to comment.