メモ:WSLgにおけるキーボードレイアウト設定

Waylandではキーボード配列の設定を各アプリケーションごとに行わせるため、どこで設定すればよいのかよくわからない。

WSLgはWaylandとそのコンポジタであるWestonを使用している(https://github.com/microsoft/wslg の「WSLg Architecture Overview」参照)。WSL上のLinuxで使用しているX Window アプリについても、XWaylandというデーモン経由でWaylandを利用するため、これまでのX.org用の設定が反映されない。

そして、WSLgでは、Windows側に接続されているキーボードの設定を利用して、Linux側の設定を無視してキーボードレイアウトを変更しているようなので、どこをいじればキーボードレイアウトを変更できるかわからない。

WSLgのwestonは初回のweston.ini設定のキーボード配列を保持しません。

ログを見ると途中で、

convert_rdp_keyboard_to_xkb_rule_names: matching model=pc105 layout=us variant=(null) options=(null)

のような動作が行われており、 Windows側のキーボード配列にXのキーボード配列を合わせているようです。

WSLgのWestonは起動時に /home/wslg/.config/weston.ini という設定ファイルを読み込んでいるが、/home/wslgは私の環境に存在しない。

% more /mnt/wslg/weston.log
Date: 2025-06-13 JST
[17:57:09.975] weston 9.0.0
               https://wayland.freedesktop.org
               Bug reports to: https://gitlab.freedesktop.org/wayland/weston/issues/
               Build: 9.0.0-210-gf227edd6
[17:57:09.977] Command line: /usr/bin/weston --backend=rdp-backend.so --modules=wslgd-notify.so --xwayland --socket=wayl
and-0 --shell=rdprail-shell.so --log=/mnt/wslg/weston.log --logger-scopes=log,rdp-backend,rdprail-shell
[17:57:09.977] OS: Linux, 5.15.167.4-microsoft-standard-WSL2, #1 SMP Tue Nov 5 00:21:55 UTC 2024, x86_64
[17:57:09.977] warning: XDG_RUNTIME_DIR "/mnt/wslg/runtime-dir" is not configured
correctly.  Unix access mode must be 0700 (current mode is 777),
and must be owned by the user (current owner is UID 1000).
Refer to your distribution on how to get it, or
http://www.freedesktop.org/wiki/Specifications/basedir-spec
on how to implement it.
[17:57:09.984] Using config file '/home/wslg/.config/weston.ini'
[17:57:09.986] Output repaint window is 7 ms maximum.
[17:57:09.987] Loading module '/usr/lib/libweston-9/rdp-backend.so'
[17:57:09.996] using FreeRDP version 2.4.0
Date: 2025-06-13 JST
~以下略~

私の環境でもキーボード設定の読み替えをしている。私はWindows11にJIS配列のキーボードを接続している。

% grep convert_rdp_keyboard_to_xkb_rule_names /mnt/wslg/weston.log
[17:57:15.315] convert_rdp_keyboard_to_xkb_rule_names: matching model=pc105 layout=jp variant=(null) options=(null)
[18:20:17.347] convert_rdp_keyboard_to_xkb_rule_names: matching model=pc105 layout=jp variant=(null) options=(null)
[18:35:49.023] convert_rdp_keyboard_to_xkb_rule_names: matching model=pc105 layout=jp variant=(null) options=(null)

Windows11でキーボード配列を英語配列に変更してみたところ、以下のようにUS配列となった。

% grep convert_rdp_keyboard_to_xkb_rule_names /mnt/wslg/weston.log
[19:55:05.700] convert_rdp_keyboard_to_xkb_rule_names: matching model=pc105 layout=us variant=(null) options=(null)

fcitx5-configtoolの設定も、setxkbmapでの設定もキーボートレイアウトの設定に関しては関係ない。ただし、fcitx5-configtoolの設定は標準入力と日本語入力(Mozc)に切り替えるキーをどれにするのかには関係がある。

メモ:Ubuntuでのキー配列の調べ方

Ubuntu 24.04LTSでのキー配列の調べ方

localectl

% localectl status
System Locale: LANG=ja_JP.UTF-8
    VC Keymap: (unset)
   X11 Layout: us
    X11 Model: pc105

setxkbmap

%  setxkbmap -print -verbose 10
Setting verbose level to 10
WARNING: Running setxkbmap against an Xwayland server
locale is C
Trying to load rules file ./rules/evdev...
Trying to load rules file /usr/share/X11/xkb/rules/evdev...
Success.
Applied rules from evdev:
rules:      evdev
model:      pc105
layout:     jp
Trying to build keymap using the following components:
keycodes:   evdev+aliases(qwerty)
types:      complete
compat:     complete+japan
symbols:    pc+jp+inet(evdev)
geometry:   pc(pc105)
xkb_keymap {
        xkb_keycodes  { include "evdev+aliases(qwerty)" };
        xkb_types     { include "complete"      };
        xkb_compat    { include "complete+japan"        };
        xkb_symbols   { include "pc+jp+inet(evdev)"     };
        xkb_geometry  { include "pc(pc105)"     };
};

各キーのキーコード(keycode)を調べる場合

% xev
~略~
KeyPress event, serial 35, synthetic NO, window 0x400001,
    root 0x3a4, subw 0x0, time 3686508, (-229,-122), root:(1800,541),
    state 0x0, keycode 49 (keysym 0xff2a, Zenkaku_Hankaku), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyPress event, serial 35, synthetic NO, window 0x400001,
    root 0x3a4, subw 0x0, time 3686524, (-229,-122), root:(1800,541),
    state 0x0, keycode 38 (keysym 0x61, a), same_screen YES,
    XLookupString gives 1 bytes: (61) "a"
    XmbLookupString gives 1 bytes: (61) "a"
    XFilterEvent returns: False

KeyRelease event, serial 35, synthetic NO, window 0x400001,
    root 0x3a4, subw 0x0, time 3686724, (-229,-122), root:(1800,541),
    state 0x0, keycode 38 (keysym 0x61, a), same_screen YES,
    XLookupString gives 1 bytes: (61) "a"
    XFilterEvent returns: False

X11でのキーボード情報

% xset -q
Keyboard Control:
  auto repeat:  on    key click percent:  0    LED mask:  00000000
  XKB indicators:
    00: Caps Lock:   off    01: Num Lock:    off    02: Scroll Lock: off
    03: Compose:     off    04: Kana:        off    05: Sleep:       off
    06: Suspend:     off    07: Mute:        off    08: Misc:        off
    09: Mail:        off    10: Charging:    off    11: Shift Lock:  off
    12: Group 2:     off    13: Mouse Keys:  off
  auto repeat delay:  400    repeat rate:  40
  auto repeating keys:  00ffffffdffffbbf
                        fadfffefffedffff
                        9fffffffffffffff
                        fff7ffffffffffff
  bell percent:  50    bell pitch:  400    bell duration:  100
Pointer Control:
  acceleration:  2/1    threshold:  4
Screen Saver:
  prefer blanking:  yes    allow exposures:  yes
  timeout:  0    cycle:  0
Colors:
  default colormap:  0x24    BlackPixel:  0x0    WhitePixel:  0xffffff
Font Path:
  built-ins
DPMS (Display Power Management Signaling):
  Server does not have the DPMS Extension

X11のキーボード配置の設定ファイル

%  ls -l /etc/vconsole.conf
lrwxrwxrwx 1 root root 16  2月 15 17:09 /etc/vconsole.conf -> default/keyboard

% cat /etc/default/keyboard
# KEYBOARD CONFIGURATION FILE

# Consult the keyboard(5) manual page.

XKBMODEL="pc105"
XKBLAYOUT="us"
XKBVARIANT=""
XKBOPTIONS=""

BACKSPACE="guess"

未解決:Ubuntu 24.04LTS上で半角/全角キーが連打状態になる

Ubuntu 24.04ではX11の代わりにWaylandが利用されている。X11環境において、半角/全角キーが連打状態になるという現象がずっと生じていたみたい。

上記の問題への対処療法がログイン時に「xset -r 49」を実行する。この命令はキーコード 49(半角/全角キー)のオートリピート(autorepeat)をオフにするというもの。これにより、実際には半角/全角キーが連打されていても、X11からはそれを無視するということになる。

これまではこの対処でよかったのだが、X11の代わりに使われているWaylandでは「xset -r 49」が効かないみたい。

askubuntu.com

xset only affects X11 cliients that may be running on Wayland via a compatibility tool Xwayland. For native Wayland apps you need to look through the settings app, possibly as described here for an earlier version of gnome (if that is your desktop).

xsetは、Wayland上で互換性ツールXwayland経由で実行されているX11クライアントにのみ影響します。ネイティブのWaylandアプリの場合、設定アプリを確認する必要があります。詳細な手順は、GNOMEの以前のバージョン(デスクトップ環境がGNOMEの場合)については、こちらを参照してください。

どうも、「半角/全角」キー(keycode=49)と「カタカナ ひらがな ローマ字」キー(keycode=101)が連打状態になっているみたい。何が原因なんだ?