创建自定义 setxkbmap 选项

Create a custom setxkbmap option

奇怪的是,这似乎应该是以前做过的事情:我想交换数字符号 10 键横跨我的键盘顶部,这样:

我还想进行其他一些修改,但很快发现其他人在使用 setxkbmap 选项(例如 caps:swapescape)之前已经完成了这些布局修改。


鉴于以上情况,这是一个由 3 部分组成的问题:

  1. 是否有用于交换键盘顶行数字和符号的选项?
  2. 不管有没有,有没有什么办法不用手动浏览/usr/share/X11/xkb/rules/里的*.lst*.xml文件就知道有没有这样的东西?
  3. 最后,如果我要为 setxkbmap 创建一个选项,什么是理想的方法,我如何看待将我的选项回馈给社区?

关于问题3:

问题 2:

要获得所有可用选项的列表,您可以执行localectl list-x11-keymap-options。这似乎只为您提供选项本身,而不是描述,因此更好的方法可能是在 XKB *.lst 文件上执行以下操作:

for f in /usr/share/X11/xkb/rules/*.lst; do sed -ne '/^\! option$/{s///; :a' -e 'n;p;ba' -e '}' $f; done | sort -u

(sed reference)*

如果您正在寻找与交换数字相关的内容,您可以附加 | grep -i num,显示使用 numpad/keypad 的几个选项。不幸的是,我认为所有布局都在与 字母数字 字符相关的模板中布置了数字,这意味着它们内置于区域布局本身(或变体,在dvorak).

的情况

问题 1:

您可以采用三种方法。

使用 xmodmap

覆盖布局

如 Arch Wiki here.

中所述,您可以通过在家中创建一个 .Xmodmap 文件来覆盖映射,从而创建一种稍微通用的方法

这是一个示例配置:https://github.com/karma0/layouts/blob/master/home/.Xmodmap

步骤:

  1. .Xmodmap 放在家里。
  2. 将行 xmodmap $HOME/.Xmodmap 添加到您的 .profile

一种快速而肮脏但灵活的方法:

  1. 运行 xkbcomp -xkb $DISPLAY xkbmap 生成一个包含您当前配置的文件 xkbmap
  2. 修改它以匹配所需的配置。这是一个例子:

Original:

key <AE01> {         [               1,          exclam ] };                                                                                                       
key <AE02> {         [               2,              at ] };                                                                                                       
key <AE03> {         [               3,      numbersign ] };                                                                                                       
key <AE04> {         [               4,          dollar ] };                                                                                                       
key <AE05> {         [               5,         percent ] };                                                                                                       
key <AE06> {         [               6,     asciicircum ] };                                                                                                       
key <AE07> {         [               7,       ampersand ] };                                                                                                       
key <AE08> {         [               8,        asterisk ] };                                                                                                       
key <AE09> {         [               9,       parenleft ] };                                                                                                       
key <AE10> {         [               0,      parenright ] };

Modified:

key <AE01> {         [               exclam,        1 ] };                                                                                                         
key <AE02> {         [               at,            2 ] };                                                                                                         
key <AE03> {         [               numbersign,    3 ] };                                                                                                         
key <AE04> {         [               dollar,i       4 ] };                                                                                                         
key <AE05> {         [               percent,       5 ] };                                                                                                         
key <AE06> {         [               asciicircum,   6 ] };                                                                                                         
key <AE07> {         [               ampersand,     7 ] };                                                                                                         
key <AE08> {         [               asterisk,      8 ] };                                                                                                         
key <AE09> {         [               parenleft,     9 ] };                                                                                                         
key <AE10> {         [               parenright,    0 ] };
  1. 执行命令xkbcomp -w 0 xkbmap $DISPLAY加载新配置。
  2. 在启动时使用 xinitrc 或类似的命令获取到 运行 的命令。

修改布局并添加新变体

  1. 打开您最喜欢的布局文件(可能在 /usr/share/X11/xkb/symbols 下)。我们将在此示例中使用 us 文件。
  2. 在文件中找到您最喜欢的变体; workman-intl如果你和我一样。
  3. 假设你想复制 workman-intl 布局,你可以复制那个部分,然后像我在这里做的那样修改它(注意这是 intl 中的 copy/pasted模板和第一列和第二列只是交换):
 partial alphanumeric_keys                                                                                      
 xkb_symbols "workman-programmer" {
     include "us(workman-intl)"
     name[Group1]= "English (Workman, intl., with dead keys and num/sym swapped)";

     key <AE01> { [ exclam,         1,    exclamdown, onesuperior ] };
     key <AE02> { [ at,             2,   twosuperior, dead_doubleacute ] };
     key <AE03> { [ numbersign,     3, threesuperior, dead_macron ] };
     key <AE04> { [ dollar,         4,      currency, sterling ] };
     key <AE05> { [ percent,        5,      EuroSign, dead_cedilla ] };
     key <AE06> { [ dead_circumflex,6,    onequarter, asciicircum ] };
     key <AE07> { [ ampersand,      7,       onehalf, dead_horn ] };
     key <AE08> { [ asterisk,       8, threequarters, dead_ogonek ] };
     key <AE09> { [ parenleft,      9, leftsinglequotemark, dead_breve ] };
     key <AE10> { [ parenright,     0, rightsinglequotemark, dead_abovering ] };
};

The xkb_symbols line defines the name of your variation; the include line borrows everything you need from the variation of your choice within the file (here, it's the workman-intl variation in the us layout). Then, the definitions you want are what follows. 4. Add your new definition to /usr/share/xkb/rules/base.xml to the end of the variantList tag. Here's the one I used:

        <variant>                                                                                              
          <configItem>                                                                                         
            <name>workman-programmer</name>                                                                    
            <description>English (Workman, intl., with dead keys and num/sym swapped)</description>                  
           </configItem>                                                                                       
         </variant>
  1. 将新变体和描述添加到 /usr/share/X11/xkb/rules/base.lst! variant 部分,如:
      workman-programmer    us: English (Workman, intl., with dead keys and num/sys swapped)'
  1. 重新启动您的 Xorg 服务器。

  2. 使用新变体将 setxkbmap 命令设置为 运行。这是此演示的一个:setxkbmap -layout us -variant workman-programmer -option

问题 3:

尽您所能,直到您开始寻找位于 xorg 生态系统中的 xkb 文档,您才能找到该文档。

最好的文章可能是这篇文章:

https://www.charvolant.org/doug/xkb/html/index.html

引用:

Before you read this, please understand that I never wanted to write this document, being grossly under-qualified, but I always wanted to read it, and this was the only way.

此外,这里还有一个链接列表,可以开始学习 xorgxkb 系统的所有复杂功能:https://www.x.org/wiki/XKB/

注意: 大多数文档引用 xkb 内的相对路径,因为它安装在您的系统上。这通常在 /usr/share/X11/xkb


如果你想贡献,这个项目位于 xorg 下,它在此处提供开发人员文档:https://www.x.org/wiki/guide/, or better, here: https://www.x.org/wiki/Development/