Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keyboard layout set only to "us" after reconnect session instead "us,ru" #337

Open
rzateev opened this issue Feb 29, 2016 · 29 comments
Open
Labels

Comments

@rzateev
Copy link

rzateev commented Feb 29, 2016

Hello!

I test installation xrdp 0.9.0 last version on ubuntu 12.04 32bit (also i test xrdp 0.8.0)
Client is Windows 8.

I use "us,ru" keyboard layout on both computer.

When i connect first time to server with xrdp keyboard layout works perfect.

I check it command setxkbmap

locadmin@locadmin-VirtualBox:~$ setxkbmap -print -verbose 10
 Setting verbose level to 10
 locale is C
 Applied rules from base:
 rules:      base
 model:      pc105
 layout:     us,ru
 variant:    ,
 options:    grp:alt_shift_toggle,grp:toggle
 Trying to build keymap using the following components:
 keycodes:   xfree86+aliases(qwerty)
 types:      complete
 compat:     complete
 symbols:    pc+us+inet(pc105)+ru:2+group(toggle)+group(alt_shift_toggle)
 geometry:   pc(pc105)
 xkb_keymap {
    xkb_keycodes  { include "xfree86+aliases(qwerty)"   };
    xkb_types     { include "complete"  };
    xkb_compat    { include "complete"  };
    xkb_symbols   { include "pc+us+inet(pc105)+ru:2+group(toggle)+group(alt_shift_toggle)"  };
    xkb_geometry  { include "pc(pc105)" };
 };

But when i disconnect from session and connect to a server again i cannot change layout - it only "us".
I check it command setxkbmap:

locadmin@locadmin-VirtualBox:~$ setxkbmap -print -verbose 10
Setting verbose level to 10
locale is C
Applied rules from base:
rules:      base
model:      pc105
layout:     us
Trying to build keymap using the following components:
keycodes:   xfree86+aliases(qwerty)
types:      complete
compat:     complete
symbols:    pc+us+inet(pc105)
geometry:   pc(pc105)
xkb_keymap {
    xkb_keycodes  { include "xfree86+aliases(qwerty)"   };
    xkb_types     { include "complete"  };
    xkb_compat    { include "complete"  };
    xkb_symbols   { include "pc+us+inet(pc105)" };
    xkb_geometry  { include "pc(pc105)" };
};

How can i fix this?

PS. I specially test my old production server on ubuntu 12.04 32bit with version xrdp 0.6.0 - it work correctly.

@rzateev
Copy link
Author

rzateev commented Feb 29, 2016

Addition to the previous text: i use X11rdp backend.

@itamarjp
Copy link
Member

have you tried compiling from git ?

@rzateev
Copy link
Author

rzateev commented Feb 29, 2016

Yes. I compiled it from master branch

@metalefty
Copy link
Member

Two thing,

do you reproduce the issue with xorgxrdp?

run xrdp-sesman in foreground xrdp-sesman -ns and see log carefully around recconection. applying keylayout will be logged.

Like this. This is x11rdp case.

[20160308-10:55:16] [INFO ] An established connection closed to endpoint: NULL:NULL - socket: 8
process_version_msg: version 0 0 0 1
process_screen_size_msg: set width 1920 height 1200 bpp 16
process_screen_size_msg: g_shmemid 327680 g_shmemptr 0x80a400000
process_message_channel_setup: chan name 'rdpdr' id 0 flags 00000000
process_message_channel_setup: chan name 'rdpsnd' id 1 flags 00000000
process_message_channel_setup: chan name 'cliprdr' id 2 flags 00000000
process_message_channel_setup: chan name 'drdynvc' id 3 flags 00000000
xrdp-chansrv [1408203185]: sound_init:
rdpup_process_msg: got client info bytes 5312
  jpeg support 0
  offscreen support 1
  offscreen size 5242880
  offscreen entries 100
  client can not do offscreen to offscreen blits
  client can do new(color) cursor
  client can not do multimon
rdpLoadLayout: keylayout 0xe0200411 variant  display 10 <= THIS
rdpChangeKeyboardControl:
rdpChangeKeyboardControl:

@rzateev
Copy link
Author

rzateev commented Mar 8, 2016

I reproduce the issue.
Before reconnect to session layot was change good.

After reconnect it is only EN layout and I cannot change it.

Log in console:

[20160308-10:27:05] [INFO ] A connection received from: 127.0.0.1 port 35414
[20160308-10:27:06] [INFO ] ++ reconnected session: username locadmin, display :10.0, session_pid 2255, ip 192.168.43.6:54961 - socket: 12
rdpClientConGotConnection:
rdpClientConGotConnection: g_sck_accept ok new_sck 13
rdpClientConGotConnection: adding only clientCon
[20160308-10:27:06] [INFO ] An established connection closed to endpoint: 127.0.0.1:35414 - socket: 9
rdpClientConProcessMsgVersion: version 0 0 0 1
rdpClientConProcessScreenSizeMsg: set width 1920 height 1080 bpp 24
rdpClientConProcessScreenSizeMsg: shmemid 1966101 shmemptr 0xb1e5e000
rdpClientConProcessMsgClientInput: invalidate x 0 y 0 cx 1920 cy 1080
[20160308-10:27:06] [INFO ] An established connection closed to endpoint: NULL:NULL - socket: 9
process_message_channel_setup: chan name 'rdpdr' id 0 flags 00000000
process_message_channel_setup: chan name 'rdpsnd' id 1 flags 00000000
process_message_channel_setup: chan name 'cliprdr' id 2 flags 00000000
rdpClientConProcessMsgClientInfo:
process_message_channel_setup: chan name 'drdynvc' id 3 flags 00000000
  got client info bytes 5392
  jpeg support 0
  offscreen support 1
  offscreen size 7864320
  offscreen entries 100
  client can not do offscreen to offscreen blits
  client can do new(color) cursor
  client can not do multimon
rdpRRSetRdpOutputs: numCrtcs 1
rdpRRSetRdpOutputs: numOutputs 1
rdpLoadLayout: keylayout 0x00000409 variant  display 10
rdpkeybChangeKeyboardControl:
rdpkeybChangeKeyboardControl: autoRepeat on
rdpkeybChangeKeyboardControl:
rdpkeybChangeKeyboardControl: autoRepeat on
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
rdpRRGetInfo:
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
xrdp-chansrv [1413713201]: child_signal_handler:
xrdp-chansrv [1413713202]: child_signal_handler: child pid 2752
xrdp-chansrv [1413713202]: child_signal_handler: child pid -1
xrdp-chansrv [1413713202]: sound_init:
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
rdpInDeferredUpdateCallback:
rdpkeybChangeKeyboardControl:
rdpkeybChangeKeyboardControl: autoRepeat off
rdpkeybChangeKeyboardControl:
rdpkeybChangeKeyboardControl: autoRepeat off
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
rdpRRGetPanning: 0x8221c1f8
xrdp-chansrv [1413713575]: sound_process_output_format:
xrdp-chansrv [1413713575]:       wFormatTag      1
xrdp-chansrv [1413713575]:       nChannels       2
xrdp-chansrv [1413713575]:       nSamplesPerSec  44100
xrdp-chansrv [1413713575]:       nAvgBytesPerSec 176400
xrdp-chansrv [1413713575]:       nBlockAlign     4
xrdp-chansrv [1413713575]:       wBitsPerSample  16
xrdp-chansrv [1413713575]:       cbSize          0
xrdp-chansrv [1413713575]: sound_process_output_format:
xrdp-chansrv [1413713575]:       wFormatTag      1
xrdp-chansrv [1413713576]:       nChannels       2
xrdp-chansrv [1413713576]:       nSamplesPerSec  22050
xrdp-chansrv [1413713576]:       nAvgBytesPerSec 88200
xrdp-chansrv [1413713576]:       nBlockAlign     4
xrdp-chansrv [1413713576]:       wBitsPerSample  16
xrdp-chansrv [1413713576]:       cbSize          0
xrdp-chansrv [1413713677]: drdynvc_process_capability_response: DVC version 3 selected
xrdp-chansrv [1413713677]: sound_process_training: round trip time 100
xrdp-chansrv [1413713680]: scard_init:
chansrv:smartcard_pcsc [1413713680]: scard_pcsc_init:

Temprorary i FIX layot with modify file xrdp\xorgxrdp\xrdpkeyb\rdpKeyboard.c and rebuild it:

  1. I modify function rdpLoadLayout (change default options of layout and comment code when it mast be reapply with client info options ):
static int
rdpLoadLayout(rdpKeyboard *keyboard, struct xrdp_client_info *client_info)
{
    XkbRMLVOSet set;

    int keylayout = client_info->keylayout;

    LLOGLN(0, ("rdpLoadLayout: keylayout 0x%8.8x variant %s display %s",
               keylayout, client_info->variant, display));
    memset(&set, 0, sizeof(set));
    set.rules = "base";

// BEGIN-FIX
//    set.model = "pc104";
//   set.layout = "us";
//    set.variant = "";
//    set.options = "";

    set.model = "pc105";
    set.layout = "us,ru";
    set.variant = "";
    set.options = "grp:ctrl_shift_toggle";

//
 //   if (strlen(client_info->model) > 0)
 //   {
  //     set.model = client_info->model;
  //  }
  //  if (strlen(client_info->variant) > 0)
  //  {
  //     set.variant = client_info->variant;
  //  }
  //  if (strlen(client_info->layout) > 0)
  //  {
  //      set.layout = client_info->layout;
  //  }
  //  if (strlen(client_info->options) > 0)
  //  {
 //       set.options = client_info->options;
//    }
// END-FIX

    reload_xkb(keyboard->device, &set);
    reload_xkb(inputInfo.keyboard, &set);

    return 0;
}

  1. Also i modify function rdpkeybControl:
// BEGIN-FIX
//set.model = "pc104";
//set.layout = "us";
//set.variant = "";
//set.options = "";

set.model = "pc105";
set.layout = "us,ru";
set.variant = "";
set.options = "grp:ctrl_shift_toggle";
// END-FIX

After this change keyboard layout work perfectly. I try it on Xubuntu 14.04 and Ubuntu 15.10.

As I understand it , the problem is that the client come empty adjustment and as a result apply the settings that have been set by default : ie only EN layout .

@metalefty
Copy link
Member

As I understand it , the problem is that the client come empty adjustment and as a result apply the settings that have been set by default : ie only EN layout .

I think so, too.

rdpLoadLayout: keylayout 0x00000409 variant  display 10

Your log says client has the US layout. Russian should be 0x00000419.
https://technet.microsoft.com/en-us/library/cc766503%28WS.10%29.aspx

Judging from your log, second or later connections are correct and first connection is somehow going wrong. It shouldn't be "us,ru". When client give xrdp server 0x00000409 layout, server keylayout always should be "us".

Again, let's see which keylayout is given from the client. Now you don't have to run xrdp-sesman in foreground. Just do tail -f /var/log/xrdp.log. You'll see the log like this.
[20160308-10:54:59] [WARN ] local keymap file for 0xe0200411 found and doesn't match built in keymap, using local keymap file

I think you should specify keyboard layout in client. This is a FreeRDP example.
$ xfreerdp /v:server.example.com /kbd:0x00000419
or
$ xfreerdp /v:server.example.com /kbd:Russian

@metalefty
Copy link
Member

Additionally, if you want to use "us,ru" layout even if "0x00000409" is given from the client, you don't need to fix the source code. Editing config files is enough.

Edit xrdp_keyboard.ini like this. This will override "us" by "us,ru".

--- xrdp_keyboard.ini.orig      2016-03-08 13:49:27.488775742 +0900
+++ xrdp_keyboard.ini   2016-03-08 13:51:24.972745599 +0900
@@ -74,7 +74,7 @@

 # <rdp layout name> = <X11 keyboard layout value>
 [default_layouts_map]
-rdp_layout_us=us
+rdp_layout_us=us,ru
 rdp_layout_de=de
 rdp_layout_fr=fr
 rdp_layout_it=it

If you want to use "us,ru" instead of "ru" in case you specify Russian in client, like this.

--- xrdp_keyboard.ini.orig      2016-03-08 13:49:27.488775742 +0900
+++ xrdp_keyboard.ini   2016-03-08 13:52:33.092750998 +0900
@@ -82,7 +82,7 @@
 rdp_layout_jp2=jp
 rdp_layout_jp3=jp
 rdp_layout_jp4=jp
-rdp_layout_ru=ru
+rdp_layout_ru=us,ru
 rdp_layout_se=se
 rdp_layout_ch=ch
 rdp_layout_pt=pt

@rzateev
Copy link
Author

rzateev commented Mar 8, 2016

metalefty,
I tried to edit the file xrdp_keyboard.ini before, but in my case it did not work for some reason. It was the first thing I tried to correct the situation . That's why I went so far as to correct the source code - only in this case the result was correct .

@rzateev
Copy link
Author

rzateev commented Mar 8, 2016

I tried again using change xrdp_keyboard.ini - no result. As before, only the English keyboard layout.

@metalefty
Copy link
Member

Hmm, xrdp_keyboard.ini works for me.

I tried to disconnect & reconnect 3 different client keyboard types (us -> jp -> ru).
Server keyboard changes "us,ru" -> "jp" -> "ru". This is exactly I expected.

Server session type is xorgxrdp. xrdp= cdb967c, xorgxrdp=a0add6c.
xrdp_keyboard2

By the way, what about #issuecomment-193607180?

@albert-a
Copy link

albert-a commented Aug 4, 2016

Thanks a lot for your instructions!
#337 (comment)
It was helpful! I use this in my script that builds xrdp to automate the process of patching:

kb_model="pc105"
kb_layout="us,ru"
kb_options="grp:alt_shift_toggle,grp_led:scroll"
sed -ri.bak "s/(set.model)[^;]+/\1 = \"$kb_model\"/;s/(set.layout)[^;]+/\1 = \"$kb_layout\"/;s/(set.options)[^;]+/\1 = \"$kb_options\"/" xorgxrdp/xrdpkeyb/rdpKeyboard.c

@SamTheReaper
Copy link

SamTheReaper commented Sep 21, 2016

How to add option "grp:alt_shift_toggle,grp_led:scroll" in xrdp_keyboard.ini?

@cypa
Copy link

cypa commented Feb 17, 2018

on CentOS 7.4 problem persists

@mr-GreyWolf
Copy link

Please add keyboard layout switch on login screen

@gusarg81
Copy link

Hi, I al so facing this same problem. On first login the keyboard is OK (which in my case, is Spanish Latin, or es-ar). On reconnect to existing session, then the keyboards is US.

Any ideas of how to fix this? The only way that works is to close the session.

PD: in my case, I am accessing from Windows 10 to Ubuntu 18.04.

Thanks in advance.

@ipirojnoe
Copy link

ipirojnoe commented Jan 11, 2020

Simple solution
As metalefty said
Add in /etc/xrdp/xrdp_keyboard.ini

-rdp_layout_us=us
+rdp_layout_us=us,ru

and reconnect

@gusarg81
Copy link

Same applies for es layout?

@andvary
Copy link

andvary commented Oct 6, 2020

I had a similar problem: Ubuntu server running xrdp and Win10 client with japaneese layout. Every time I reconnected to a session, only japaneese layout was available.
[20201006-20:07:53] [INFO ] Cannot find keymap file /etc/xrdp/km-e0010411.ini [20201006-20:07:53] [INFO ] Loading keymap file /etc/xrdp/km-00000411.ini [20201006-20:07:53] [WARN ] local keymap file for 0xe0010411 found and doesn't m atch built in keymap, using local keymap file
Managed to solve the problem (following metalefty's instructions) by changing "rdp_layout_jp=jp" to "rdp_layout_jp=us,ru" in xrdp_keyboard.ini. It works now, although the solution seems somewhat strange to me.

@Mingun
Copy link

Mingun commented Oct 18, 2021

In my case xrdp only reset to only us layout if previous session was closed unexpectedly (probably because of the network error/loosing network connection).

The normal reconnects (i.e. initiated via closing the RDP client (default mstsc.exe) or ending the seance on the remote machine), that happened before the error occurs, works fine and I always get my "us,ru" layout, although I didn't touch the /etc/xrdp/xrdp_keyboard.ini. After the error the normal reconnects does not restore status quo (but maybe this is because I always tried to reconnect instantly after the error, I didn't try to wait some time and reconnect after that).

The situation is normalized after I reboot my remote Ubuntu machine.

My `/etc/xrdp/xrdp_keyboard.ini` for the reference
;
; RDP Keyboard <-> X11 Keyboard layout map
;
; How this file works:
;   1. load the file and scan each section to find matching "keyboard_type"
;      and "keyboard_subtype" based on the values received from the client.
;      If not found, then jump to default section.
;   2. in the selected section, look for "rdp_layouts" and "layouts_map".
;      Based on the "keylayout" value from the client, find the right x11
;      layout value.
;   3. model/variant are inferred based on the "keyboard_type" and
;      "keyboard_subtype", but they can be overridden.
;

;
; RDP Keyboard Type (http://msdn.microsoft.com/en-us/library/cc240563.aspx)
;
; 0 is not a valid value
;
; 1 - IBM PC/XT or compatible (83-key) keyboard
; 2 - Olivetti "ICO" (102-key) keyboard
; 3 - IBM PC/AT (84-key) or similar keyboard
; 4 - IBM enhanced (101- or 102-key) keyboard
; 5 - Nokia 1050 and similar keyboards
; 6 - Nokia 9140 and similar keyboards
; 7 - Japanese keyboard
;
; RDP Keyboard Subtype is vendor dependent. XRDP defines as follows:
;
; 0 is not a valid value
;
; 1 - Standard
; 2 - FreeRDP JP keyboard
; 3 - Macintosh
; ... - < any vendor dependent subtype >
;
; The list can be augmented.
;


; default
[default]
; keyboard_type and keyboard_subtype is not read for default section. It
; is only a placeholder to keep consistency. Default model/variant are
; platform dependent, and could be overridden if needed.
keyboard_type=0
keyboard_subtype=0

; user could override variant and model, but generally they should be inferred
; automatically based on keyboard type and subtype
;variant=
;model=

; A list of supported RDP keyboard layouts
rdp_layouts=default_rdp_layouts
; The map from RDP keyboard layout to X11 keyboard layout
layouts_map=default_layouts_map

[default_rdp_layouts]
rdp_layout_us=0x00000409
rdp_layout_us_dvorak=0x00010409
rdp_layout_dk=0x00000406
rdp_layout_de=0x00000407
rdp_layout_es=0x0000040A
rdp_layout_fi=0x0000040B
rdp_layout_fr=0x0000040C
rdp_layout_it=0x00000410
rdp_layout_jp=0x00000411
rdp_layout_jp=0xe0010411
rdp_layout_jp=0xe0200411
rdp_layout_jp=0xe0210411
rdp_layout_kr=0x00000412
rdp_layout_pl=0x00000415
rdp_layout_br=0x00000416
rdp_layout_ru=0x00000419
rdp_layout_se=0x0000041D
rdp_layout_ch=0x00000807
rdp_layout_ch_fr=0x0000100C
rdp_layout_gb=0x00000809
rdp_layout_latam=0x0000080A
rdp_layout_be=0x00000813
rdp_layout_pt=0x00000816

; <rdp layout name> = <X11 keyboard layout value>
[default_layouts_map]
rdp_layout_us=us
rdp_layout_us_dvorak=dvorak
rdp_layout_dk=dk
rdp_layout_de=de
rdp_layout_es=es
rdp_layout_fi=fi
rdp_layout_fr=fr
rdp_layout_it=it
rdp_layout_jp=jp
rdp_layout_kr=kr
rdp_layout_pl=pl
rdp_layout_br=br(abnt2)
rdp_layout_ru=ru
rdp_layout_se=se
rdp_layout_ch=ch
rdp_layout_ch_fr=ch(fr)
rdp_layout_gb=gb
rdp_layout_latam=latam
rdp_layout_be=be
rdp_layout_pt=pt

; if two sections have the same keyboard_type and keyboard_subtype, then
; the latter could override the former.
[rdp_keyboard_mac]
keyboard_type=4
keyboard_subtype=3
rdp_layouts=default_rdp_layouts
layouts_map=rdp_layouts_map_mac

[rdp_keyboard_jp]
keyboard_type=7
keyboard_subtype=2
model=pc105
rdp_layouts=default_rdp_layouts
layouts_map=default_layouts_map

[rdp_layouts_map_mac]
rdp_layout_us=us
rdp_layout_us_dvorak=dvorak
rdp_layout_dk=dk
rdp_layout_de=de
rdp_layout_es=es
rdp_layout_fi=fi
rdp_layout_fr=fr
rdp_layout_it=it
rdp_layout_jp=jp
rdp_layout_kr=kr
rdp_layout_pl=pl
rdp_layout_br=br(abnt2)
rdp_layout_ru=ru
rdp_layout_se=se
rdp_layout_ch=ch
rdp_layout_ch_fr=ch(fr)
rdp_layout_gb=gb
rdp_layout_latam=latam
rdp_layout_be=be
rdp_layout_pt=pt

Is there any details that I can see in the xrdp logs? For example, what layout values client was send (keyboard_type and keyboard_subtype mentioned in the xrdp_keyboard.ini)? And what the marker of the new remote session in the logs (i.e. how I can understand that this log entries from the one remote session and the other from another)?

xrdp --version
$ /usr/sbin/xrdp --version
xrdp 0.9.12
  A Remote Desktop Protocol Server.
  Copyright (C) 2004-2018 Jay Sorg, Neutrino Labs, and all contributors.
  See https://github.com/neutrinolabs/xrdp for more information.

  Configure options:
      --enable-ipv6
      --enable-jpeg
      --enable-fuse
      --enable-rfxcodec
      --enable-opus
      --enable-painter
      --enable-vsock
      --build=x86_64-linux-gnu
      --prefix=/usr
      --includedir=${prefix}/include
      --mandir=${prefix}/share/man
      --infodir=${prefix}/share/info
      --sysconfdir=/etc
      --localstatedir=/var
      --disable-silent-rules
      --libdir=${prefix}/lib/x86_64-linux-gnu
      --libexecdir=${prefix}/lib/x86_64-linux-gnu
      --disable-maintainer-mode
      --disable-dependency-tracking
      --with-socketdir=/run/xrdp/sockdir
      build_alias=x86_64-linux-gnu
      CFLAGS=-g -O2 -fdebug-prefix-map=/build/xrdp-GJgww4/xrdp-0.9.12=. -fstack-protector-strong -Wformat -Werror=format-security 
      LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--as-needed
      CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2 
      PKG_CONFIG_PATH=/build/xrdp-GJgww4/xrdp-0.9.12/pkgconfig

  Compiled with OpenSSL 1.1.1f  31 Mar 2020

@Shrizt
Copy link

Shrizt commented Dec 24, 2021

Simple solution As metalefty said Add in /etc/xrdp/xrdp_keyboard.ini

-rdp_layout_us=us
+rdp_layout_us=us,ru

and reconnect

Privet!
This adds layout, but i still miss the keyboard shortcut to switch between it.

What I need to have eg (setxkbmap -print -verbose 10):
xkb_symbols { include "pc+us+ru:2+group(ctrl_shift_toggle)" };

What I had just after reconnect:
xkb_symbols { include "pc+us" };

What i have after i changed +rdp_layout_us=us,ru
xkb_symbols { include "pc+us+ru:2" };

How to add shortcut to switch layouts? Thnx

@TrueOsiris
Copy link

TrueOsiris commented Sep 27, 2022

I encountered exactly the same issue on ubuntu 22 & xrdp 0.9.17
My local keyboard is be.
After desktop start, I can connect to the xrdp and have be keyboard.
When I disconnect & reconnect, it's us keyboard

I solved it by this https://c-nergy.be/blog/?p=17223 (my thanx go out to this guy)
... so setting this in /etc/xrdp/xrdp_keyboard.ini (you have to check in the xrdp.log which is the right keyb code)

;rdp_layout_be=0x00000813
rdp_layout_be=0x0000080c

Some details:

After first & second connect ...

ct@RAconsole:~$ setxkbmap -print
xkb_keymap {
	xkb_keycodes  { include "xfree86+aliases(azerty)"	};
	xkb_types     { include "complete"	};
	xkb_compat    { include "complete"	};
	xkb_symbols   { include "pc+be+us:2+level3(ralt_switch)"	};
	xkb_geometry  { include "pc(pc104)"	};
};
ct@RAconsole:~$ 
ct@RAconsole:~$ 
ct@RAconsole:~$ setxkbmap -print
xkb_keymap {
	xkb_keycodes  { include "xfree86+aliases(qwerty)"	};
	xkb_types     { include "complete"	};
	xkb_compat    { include "complete"	};
	xkb_symbols   { include "pc+us"	};
	xkb_geometry  { include "pc(pc104)"	};
};

After solving, restarting server, it shows this at second connect:

ct@RAconsole:~$ setxkbmap -print
xkb_keymap {
	xkb_keycodes  { include "xfree86+aliases(azerty)"	};
	xkb_types     { include "complete"	};
	xkb_compat    { include "complete"	};
	xkb_symbols   { include "pc+be"	};
	xkb_geometry  { include "pc(pc104)"	};
};

Before applying the solution, here is the xrdp.log after server restart, disconnect & reconnect.
I echoed some lines in between to make it more clear.

[20220927-14:08:33] [INFO ] Received termination signal, stopping the server accept new connections thread
[20220927-14:09:08] [INFO ] address [0.0.0.0] port [3389] mode 1
[20220927-14:09:08] [INFO ] listening to port 3389 on 0.0.0.0
[20220927-14:09:08] [INFO ] xrdp_listen_pp done
[20220927-14:09:10] [INFO ] starting xrdp with pid 1081
[20220927-14:09:10] [INFO ] address [0.0.0.0] port [3389] mode 1
[20220927-14:09:10] [INFO ] listening to port 3389 on 0.0.0.0
[20220927-14:09:10] [INFO ] xrdp_listen_pp done
[20220927-14:09:39] [INFO ] Socket 12: AF_INET6 connection received from ::ffff:10.10.0.99 port 25739
[20220927-14:09:39] [INFO ] Using default X.509 certificate: /etc/xrdp/cert.pem
[20220927-14:09:39] [INFO ] Using default X.509 key file: /etc/xrdp/key.pem
[20220927-14:09:39] [ERROR] Cannot read private key file /etc/xrdp/key.pem: Permission denied
[20220927-14:09:39] [ERROR] libxrdp_force_read: header read error
[20220927-14:09:39] [ERROR] [ITU-T X.224] Connection Sequence: CR-TPDU (Connection Request) failed
[20220927-14:09:39] [ERROR] xrdp_sec_incoming: xrdp_iso_incoming failed
[20220927-14:09:39] [ERROR] xrdp_rdp_incoming: xrdp_sec_incoming failed
[20220927-14:09:39] [ERROR] xrdp_process_main_loop: libxrdp_process_incoming failed
[20220927-14:09:39] [ERROR] xrdp_iso_send: trans_write_copy_s failed
[20220927-14:09:39] [ERROR] Sending [ITU T.125] DisconnectProviderUltimatum failed
[20220927-14:09:42] [INFO ] Socket 12: AF_INET6 connection received from ::ffff:10.10.0.99 port 25741
[20220927-14:09:42] [INFO ] Using default X.509 certificate: /etc/xrdp/cert.pem
[20220927-14:09:42] [INFO ] Using default X.509 key file: /etc/xrdp/key.pem
[20220927-14:09:42] [ERROR] Cannot read private key file /etc/xrdp/key.pem: Permission denied
[20220927-14:09:42] [ERROR] libxrdp_force_read: header read error
[20220927-14:09:42] [INFO ] Socket 12: AF_INET6 connection received from ::ffff:10.10.0.99 port 25742
[20220927-14:09:42] [ERROR] Processing [ITU-T T.125] Connect-Initial failed
[20220927-14:09:42] [ERROR] [MCS Connection Sequence] receive connection request failed
[20220927-14:09:42] [INFO ] Using default X.509 certificate: /etc/xrdp/cert.pem
[20220927-14:09:42] [INFO ] Using default X.509 key file: /etc/xrdp/key.pem
[20220927-14:09:42] [ERROR] xrdp_sec_incoming: xrdp_mcs_incoming failed
[20220927-14:09:42] [ERROR] xrdp_rdp_incoming: xrdp_sec_incoming failed
[20220927-14:09:42] [ERROR] Cannot read private key file /etc/xrdp/key.pem: Permission denied
[20220927-14:09:42] [ERROR] xrdp_process_main_loop: libxrdp_process_incoming failed
[20220927-14:09:42] [INFO ] Connected client computer name: DUC-JJJFGB3HZQZ
[20220927-14:09:42] [ERROR] xrdp_iso_send: trans_write_copy_s failed
[20220927-14:09:42] [WARN ] Received [MS-RDPBCGR] TS_UD_HEADER type 0xc006 is unknown (ignored)
[20220927-14:09:42] [WARN ] Received [MS-RDPBCGR] TS_UD_HEADER type 0xc00a is unknown (ignored)
[20220927-14:09:42] [ERROR] Sending [ITU T.125] DisconnectProviderUltimatum failed
[20220927-14:09:42] [INFO ] xrdp_load_keyboard_layout: Keyboard information sent by the RDP client, keyboard_type:[0x04], keyboard_subtype:[0x00], keylayout:[0x0000080C]
[20220927-14:09:42] [INFO ] xrdp_load_keyboard_layout: model [] variant [] layout [us] options []
[20220927-14:09:42] [INFO ] Non-TLS connection established from ::ffff:10.10.0.99 port 25742: encrypted with standard RDP security
[20220927-14:09:43] [INFO ] xrdp_caps_process_pointer: client supports new(color) cursor
[20220927-14:09:43] [INFO ] xrdp_process_offscreen_bmpcache: support level 1 cache size 10485760 MB cache entries 100
[20220927-14:09:43] [INFO ] xrdp_caps_process_codecs: nscodec, codec id 1, properties len 3
[20220927-14:09:43] [WARN ] xrdp_caps_process_codecs: unknown codec id 5
[20220927-14:09:43] [INFO ] xrdp_caps_process_codecs: RemoteFX, codec id 3, properties len 49
[20220927-14:09:43] [INFO ] Loading keymap file /etc/xrdp/km-0000080c.ini
[20220927-14:09:43] [WARN ] local keymap file for 0x0000080c found and doesn't match built in keymap, using local keymap file
[20220927-14:09:43] [INFO ] connecting to sesman ip 127.0.0.1 port 3350
[20220927-14:09:43] [INFO ] xrdp_wm_log_msg: sesman connect ok
[20220927-14:09:43] [INFO ] sesman connect ok
[20220927-14:09:43] [INFO ] sending login info to session manager, please wait...
[20220927-14:09:44] [INFO ] xrdp_wm_log_msg: login successful for display 10
[20220927-14:09:44] [INFO ] login successful for display 10
[20220927-14:09:44] [INFO ] loaded module 'libxup.so' ok, interface size 10296, version 4
[20220927-14:09:44] [INFO ] started connecting
[20220927-14:09:44] [INFO ] lib_mod_connect: connecting via UNIX socket
[20220927-14:09:45] [INFO ] lib_mod_log_peer: xrdp_pid=2341 connected to X11rdp_pid=2365 X11rdp_uid=1000 X11rdp_gid=1000 client_ip=::ffff:10.10.0.99 client_port=25742
[20220927-14:09:45] [INFO ] connected ok
testing!
testing!
testing!
[20220927-14:10:51] [ERROR] xrdp_sec_recv: xrdp_mcs_recv failed
[20220927-14:10:51] [ERROR] xrdp_rdp_recv: xrdp_sec_recv failed
[20220927-14:10:51] [ERROR] libxrdp_process_data: xrdp_rdp_recv failed
[20220927-14:10:51] [ERROR] xrdp_process_data_in: xrdp_process_loop failed
[20220927-14:10:51] [ERROR] xrdp_iso_send: trans_write_copy_s failed
[20220927-14:10:51] [ERROR] Sending [ITU T.125] DisconnectProviderUltimatum failed
testing! just disconnected
testing! just disconnected
testing! just disconnected
[20220927-14:11:21] [INFO ] Socket 12: AF_INET6 connection received from ::ffff:10.10.0.99 port 25815
[20220927-14:11:21] [INFO ] Using default X.509 certificate: /etc/xrdp/cert.pem
[20220927-14:11:21] [INFO ] Using default X.509 key file: /etc/xrdp/key.pem
[20220927-14:11:21] [ERROR] Cannot read private key file /etc/xrdp/key.pem: Permission denied
[20220927-14:11:21] [ERROR] libxrdp_force_read: header read error
[20220927-14:11:21] [ERROR] [ITU-T X.224] Connection Sequence: CR-TPDU (Connection Request) failed
[20220927-14:11:21] [ERROR] xrdp_sec_incoming: xrdp_iso_incoming failed
[20220927-14:11:21] [ERROR] xrdp_rdp_incoming: xrdp_sec_incoming failed
[20220927-14:11:21] [ERROR] xrdp_process_main_loop: libxrdp_process_incoming failed
[20220927-14:11:21] [ERROR] xrdp_iso_send: trans_write_copy_s failed
[20220927-14:11:21] [ERROR] Sending [ITU T.125] DisconnectProviderUltimatum failed
[20220927-14:11:24] [INFO ] Socket 12: AF_INET6 connection received from ::ffff:10.10.0.99 port 25830
[20220927-14:11:24] [INFO ] Using default X.509 certificate: /etc/xrdp/cert.pem
[20220927-14:11:24] [INFO ] Using default X.509 key file: /etc/xrdp/key.pem
[20220927-14:11:24] [ERROR] Cannot read private key file /etc/xrdp/key.pem: Permission denied
[20220927-14:11:24] [ERROR] libxrdp_force_read: header read error
[20220927-14:11:24] [INFO ] Socket 12: AF_INET6 connection received from ::ffff:10.10.0.99 port 25831
[20220927-14:11:24] [ERROR] Processing [ITU-T T.125] Connect-Initial failed
[20220927-14:11:24] [INFO ] Using default X.509 certificate: /etc/xrdp/cert.pem
[20220927-14:11:24] [INFO ] Using default X.509 key file: /etc/xrdp/key.pem
[20220927-14:11:24] [ERROR] [MCS Connection Sequence] receive connection request failed
[20220927-14:11:24] [ERROR] Cannot read private key file /etc/xrdp/key.pem: Permission denied
[20220927-14:11:24] [ERROR] xrdp_sec_incoming: xrdp_mcs_incoming failed
[20220927-14:11:24] [INFO ] Connected client computer name: DUC-JJJFGB3HZQZ
[20220927-14:11:24] [ERROR] xrdp_rdp_incoming: xrdp_sec_incoming failed
[20220927-14:11:24] [WARN ] Received [MS-RDPBCGR] TS_UD_HEADER type 0xc006 is unknown (ignored)
[20220927-14:11:24] [ERROR] xrdp_process_main_loop: libxrdp_process_incoming failed
[20220927-14:11:24] [WARN ] Received [MS-RDPBCGR] TS_UD_HEADER type 0xc00a is unknown (ignored)
[20220927-14:11:24] [ERROR] xrdp_iso_send: trans_write_copy_s failed
[20220927-14:11:24] [INFO ] xrdp_load_keyboard_layout: Keyboard information sent by the RDP client, keyboard_type:[0x04], keyboard_subtype:[0x00], keylayout:[0x0000080C]
[20220927-14:11:24] [ERROR] Sending [ITU T.125] DisconnectProviderUltimatum failed
[20220927-14:11:24] [INFO ] xrdp_load_keyboard_layout: model [] variant [] layout [us] options []
[20220927-14:11:24] [INFO ] Non-TLS connection established from ::ffff:10.10.0.99 port 25831: encrypted with standard RDP security
[20220927-14:11:25] [INFO ] xrdp_caps_process_pointer: client supports new(color) cursor
[20220927-14:11:25] [INFO ] xrdp_process_offscreen_bmpcache: support level 1 cache size 10485760 MB cache entries 100
[20220927-14:11:25] [INFO ] xrdp_caps_process_codecs: nscodec, codec id 1, properties len 3
[20220927-14:11:25] [WARN ] xrdp_caps_process_codecs: unknown codec id 5
[20220927-14:11:25] [INFO ] xrdp_caps_process_codecs: RemoteFX, codec id 3, properties len 49
[20220927-14:11:25] [INFO ] Loading keymap file /etc/xrdp/km-0000080c.ini
[20220927-14:11:25] [WARN ] local keymap file for 0x0000080c found and doesn't match built in keymap, using local keymap file
[20220927-14:11:25] [INFO ] connecting to sesman ip 127.0.0.1 port 3350
[20220927-14:11:25] [INFO ] xrdp_wm_log_msg: sesman connect ok
[20220927-14:11:25] [INFO ] sesman connect ok
[20220927-14:11:25] [INFO ] sending login info to session manager, please wait...
[20220927-14:11:25] [INFO ] xrdp_wm_log_msg: login successful for display 10
[20220927-14:11:25] [INFO ] login successful for display 10
[20220927-14:11:25] [INFO ] loaded module 'libxup.so' ok, interface size 10296, version 4
[20220927-14:11:25] [INFO ] started connecting
[20220927-14:11:25] [INFO ] lib_mod_connect: connecting via UNIX socket
[20220927-14:11:25] [INFO ] lib_mod_log_peer: xrdp_pid=3625 connected to X11rdp_pid=2365 X11rdp_uid=1000 X11rdp_gid=1000 client_ip=::ffff:10.10.0.99 client_port=25831
[20220927-14:11:25] [INFO ] connected ok

@VVakko
Copy link

VVakko commented Oct 8, 2022

This is a very strange issue, to solve which you have to resort to various hacks, although in the 21st century such things should, in my opinion, work out of the box.

For those who, like me, will face this problem, the solution is simple, but not obvious. Just making some adjustments to file xrdp_keyboard.ini:

$ sudoedit /etc/xrdp/xrdp_keyboard.ini
[default_rdp_layouts]
rdp_layout_none=0x00000000
rdp_layout_us=0x00000409
rdp_layout_us_pd=0xa0000409
rdp_layout_ru=0x00000419

[default_layouts_map]
rdp_layout_none=us,ru
rdp_layout_us=us,ru
rdp_layout_us_pd=us,ru
rdp_layout_ru=us,ru

[rdp_keyboard_ru]
keyboard_type=4
keyboard_subtype=1
options=grp:ctrl_shift_toggle
rdp_layouts=default_rdp_layouts
layouts_map=default_layouts_map

After these corrections, switching layouts will work even at the first connection, even at next ones. The key difference from the previous tips is setting layout: rdp_layout_none=0x00000000.
I use Royal TSX to connect via RDP, and by default it does not transmit keyboard layout.

For me, the main oddity is that even if you do not make any changes in the xrdp_keyboard.ini file and select any exotic keyboard layout in the connection settings, for example 0x00000435 (Zulu (South Africa)), when you connect to RDP for the first time, everything will work perfectly, as it is configured in Xorg:

wakko@acmenet:~$ setxkbmap -print
xkb_keymap {
	xkb_keycodes  { include "xfree86+aliases(qwerty)"	};
	xkb_types     { include "complete"	};
	xkb_compat    { include "complete+ledscroll(group_lock)"	};
	xkb_symbols   { include "pc+us+ru:2+group(ctrl_shift_toggle)"	};
	xkb_geometry  { include "pc(pc104)"	};
};

But with any next connections, the second keyboard layout disappears.

wakko@acmenet:~$ setxkbmap -print
xkb_keymap {
	xkb_keycodes  { include "xfree86+aliases(qwerty)"	};
	xkb_types     { include "complete"	};
	xkb_compat    { include "complete+ledscroll(group_lock)"	};
	xkb_symbols   { include "pc+us+group(ctrl_shift_toggle)"	};
	xkb_geometry  { include "pc(pc104)"	};
};

Although the layout switching indicator is visible in the tray, and it even switches by Ctrl+Shift.

@StrikerRUS
Copy link

@VVakko Thanks a lot for posting this workaround! Helped me on Ubuntu 20.04 with xrdp 0.9.12.

@Shrizt
Copy link

Shrizt commented Mar 24, 2023

For those who, like me, will face this problem, the solution is simple, but not obvious. Just making some adjustments to file xrdp_keyboard.ini:

@VVakko спасибо, помогло! :)

@mr-GreyWolf
Copy link

[default_rdp_layouts]
rdp_layout_none=0x00000000
rdp_layout_us=0x00000409
rdp_layout_us_pd=0xa0000409
rdp_layout_ru=0x00000419

[default_layouts_map]
rdp_layout_none=us,ru
rdp_layout_us=us,ru
rdp_layout_us_pd=us,ru
rdp_layout_ru=us,ru

[rdp_keyboard_ru]
keyboard_type=4
keyboard_subtype=1
options=grp:ctrl_shift_toggle
rdp_layouts=default_rdp_layouts
layouts_map=default_layouts_map

Молодец, @VVakko, оно работает!
Важно, что не нужно задавать раскладки клавиатуры через setxkbmap

@sergey-shuyskiy
Copy link

[default_rdp_layouts]
rdp_layout_none=0x00000000
rdp_layout_us=0x00000409
rdp_layout_us_pd=0xa0000409
rdp_layout_ru=0x00000419

[default_layouts_map]
rdp_layout_none=us,ru
rdp_layout_us=us,ru
rdp_layout_us_pd=us,ru
rdp_layout_ru=us,ru

[rdp_keyboard_ru]
keyboard_type=4
keyboard_subtype=1
options=grp:ctrl_shift_toggle
rdp_layouts=default_rdp_layouts
layouts_map=default_layouts_map

Thank you! It's worked for me. I changed property options=grp:ctrl_shift_toggle to options=grp:alt_shift_toggle.

Versions:

  • uname -a
Linux local-pc 6.5.6-060506-generic #202310061235 SMP PREEMPT_DYNAMIC Fri Oct  6 12:42:12 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
  • xrdp --version
xrdp 0.9.21.1
  A Remote Desktop Protocol Server.
  Copyright (C) 2004-2020 Jay Sorg, Neutrino Labs, and all contributors.
  See https://github.com/neutrinolabs/xrdp for more information.

  Configure options:
      --enable-ipv6
      --enable-jpeg
      --enable-fuse
      --enable-rfxcodec
      --enable-opus
      --enable-painter
      --enable-vsock
      --build=x86_64-linux-gnu
      --prefix=/usr
      --includedir=${prefix}/include
      --mandir=${prefix}/share/man
      --infodir=${prefix}/share/info
      --sysconfdir=/etc
      --localstatedir=/var
      --disable-silent-rules
      --libdir=${prefix}/lib/x86_64-linux-gnu
      --libexecdir=${prefix}/lib/x86_64-linux-gnu
      --disable-maintainer-mode
      --disable-dependency-tracking
      --with-socketdir=/run/xrdp/sockdir
      build_alias=x86_64-linux-gnu
      CFLAGS=-g -O2 -ffile-prefix-map=/build/xrdp-AsZfz3/xrdp-0.9.21.1=. -fdebug-prefix-map=/build/xrdp-AsZfz3/xrdp-0.9.21.1=/usr/src/xrdp-0.9.21.1-1 -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security 
      LDFLAGS=-Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -Wl,-z,now -Wl,--as-needed
      CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2 
      PKG_CONFIG_PATH=/build/xrdp-AsZfz3/xrdp-0.9.21.1/pkgconfig

  Compiled with OpenSSL 3.0.8 7 Feb 2023
  • cat /etc/*-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=23.04
DISTRIB_CODENAME=lunar
DISTRIB_DESCRIPTION="Ubuntu 23.04"
PRETTY_NAME="Ubuntu 23.04"
NAME="Ubuntu"
VERSION_ID="23.04"
VERSION="23.04 (Lunar Lobster)"
VERSION_CODENAME=lunar
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=lunar
LOGO=ubuntu-logo
  • plasmashell --version
plasmashell 5.27.4
  • kf5-config --version
Qt: 5.15.8
KDE Frameworks: 5.104.0
kf5-config: 1.0

@mbrozzo
Copy link

mbrozzo commented Apr 18, 2024

I have a workaround for Ubuntu 22.04 and possibly anyone using Gnome Desktop. I created this script:

#!/bin/bash

# Get the current input sources
input_sources=$(gsettings get org.gnome.desktop.input-sources sources)

# Parse the output to get the layouts and variants
layouts_variants=$(echo $input_sources | grep -Po "'xkb', '\K[^']+" | tr '\n' ',')

# Initialize empty strings for layouts and variants
layouts=""
variants=""

# Process each layout and variant
IFS=',' read -ra ADDR <<< "$layouts_variants"
for i in "${ADDR[@]}"; do
    # process "$i"
    IFS='+' read -ra LV <<< "$i"
    layouts+="${LV[0]},"
    if [ -z "${LV[1]}" ]; then
        variants+=","
    else
        variants+="${LV[1]},"
    fi
done

# Remove the trailing comma
layouts=${layouts::-1}
variants=${variants::-1}

# Set the keyboard layout
setxkbmap -layout "$layouts" -variant "$variants"

and made it executable to any user, then I added it to /etc/xrdp/reconnectwm.sh.

This gets you user settings regarding keyboard layouts, parses them and executes the setxkbmap command with the corresponding arguments.

EDIT: To be fair, I did not write the parsing part of the script, Copilot did.

@matt335672
Copy link
Member

I'd appreciate comments on #3322 from anyone monitoring this, if they think it's relevant.

@albert-a
Copy link

albert-a commented Dec 3, 2024

@VVakko, thanks, it works!

Can you please explain, what rdp_layout_none and rdp_layout_us_pd are and why are these parameters needed?

[default_rdp_layouts]
rdp_layout_none=0x00000000
rdp_layout_us=0x00000409
rdp_layout_us_pd=0xa0000409
rdp_layout_ru=0x00000419

[default_layouts_map]
rdp_layout_none=us,ru
rdp_layout_us=us,ru
rdp_layout_us_pd=us,ru
rdp_layout_ru=us,ru

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests