奇怪的是,这似乎应该是以前做过的事情:我想交换1上的数字和符号—— 0 键横跨我的键盘顶部,以便:
- 当我按下 6 键时,输入的是
*
而不是6
。 - 当我按下 Shift+6 时,将显示数字
6
而不是*
。
我还想做一些其他的修改,但很快发现其他人在使用 setxkbmap
选项之前已经完成了这些布局修改(比如 caps:swapescape
,例如)。
鉴于上述情况,这是一个由 3 部分组成的问题:
- 是否有用于交换键盘顶行数字和符号的选项?
- 不管有没有,有没有办法不用手动浏览
*.lst
和*.xml
文件就可以知道是否存在这样的东西/usr/share/X11/xkb/rules/
? - 最后,如果我要为
setxkbmap
创建一个选项,什么是理想的方法,我如何看待将我的选项回馈社区?
至于问题 3:
- 我尝试创建该选项但没有成功(
setxkbmap
默默地失败了,我什至对我的方法没有信心)。 - 我找不到托管项目的位置。
- 除了
man setxkbmap
和涉及该主题的各种博客文章外,我找不到任何关于这些的文档。
最佳答案
问题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
如果您正在寻找与交换数字相关的内容,您可以附加 | grep -i num
,显示使用小键盘/小键盘的几个选项。不幸的是,我认为所有布局都有与字母数字字符相关的模板中布局的数字,这意味着它们内置于区域布局本身(或变体,在 dvorak
的情况下) ).
问题一:
您可以采用三种方法。
使用 xmodmap
覆盖布局
您可以通过在您的家中创建一个 .Xmodmap
文件来覆盖映射,从而创建一种有点通用的方法,如 Arch Wiki here 中所述。
这是一个示例配置:https://github.com/karma0/layouts/blob/master/home/.Xmodmap
步骤:
- 将
.Xmodmap
放到你的家里。 - 将行
xmodmap $HOME/.Xmodmap
添加到您的.profile
一种快速而肮脏但灵活的方法:
- 运行
xkbcomp -xkb $DISPLAY xkbmap
以生成一个包含您当前配置的文件xkbmap
。 - 修改它以匹配所需的配置。这是一个例子:
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 ] };
- 执行命令
xkbcomp -w 0 xkbmap $DISPLAY
以加载新配置。 - 使用
xinitrc
或类似地址获取要在启动时运行的命令。
修改布局并添加新变体
- 打开您最喜欢的布局文件(可能位于
/usr/share/X11/xkb/symbols
下)。我们将在此示例中使用us
文件。 - 在文件中找到您最喜欢的变体;
workman-intl
如果你和我一样。 - 假设您想要复制
workman-intl
布局,您可以复制该部分,并按照我在此处所做的方式对其进行修改(请注意,这是从intl
模板复制/粘贴的,第一列和第二列只是交换):
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; theinclude
line borrows everything you need from the variation of your choice within the file (here, it's theworkman-intl
variation in theus
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 thevariantList
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>
- 将新变体和描述添加到
! variant
的/usr/share/X11/xkb/rules/base.lst
部分,如下所示:
workman-programmer us: English (Workman, intl., with dead keys and num/sys swapped)'
重新启动您的 Xorg 服务器。
设置
setxkbmap
命令以使用新变体运行。这是此演示的代码:setxkbmap -layout us -variant workman-programmer -option
问题三:
尽您所能,直到您开始寻找位于 xkb
生态系统中的 xorg
文档,您才能找到该文档。
最好的文章可能是这篇文章:
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.
此外,这里还有一个链接列表,可以开始学习 xkb
中 xorg
系统的所有复杂性:https://www.x.org/wiki/XKB/
注意: 大多数文档都引用 xkb
内的相对路径,因为它安装在您的系统上。这通常在 /usr/share/X11/xkb
如果你想贡献,这个项目位于 xorg
下,它在此处提供开发人员文档:https://www.x.org/wiki/guide/,或者更好,在此处:https://www.x.org/wiki/Development/
关于linux - 创建自定义 setxkbmap 选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45021978/