我正在玩 xkeyboard-config。目前,我正在尝试了解规则文件。
我曾经xkbcomp
从 X 服务器获取当前的键盘映射并将其写入文件。此键映射是默认键映射,setxkbmap
在不带任何参数运行时加载而不会出错。然后,我将各个组件拉入它们自己的文件中,并将这些文件放入类似于 xkb config 目录结构的目录结构中。
它看起来像这样:
xkb
??? compat
? ??? current
??? geometry
? ??? current
??? keycodes
? ??? current
??? rules
? ??? current
? ??? current.lst
? ??? current.xml
??? symbols
? ??? current
??? types
??? current
Run Code Online (Sandbox Code Playgroud)
我自己在 rules 子目录中创建了文件,以尝试创建能够加载单个布局的最小规则文件集。
当我指向setxkbmap
这个目录并尝试加载键盘映射时,我收到一个错误,尽管根本没有更改组件的内容。
$ setxkbmap -Ixkb -v 10 -rules current -layout current -model current -variant current
Setting verbose level to 10
locale is C
Warning! Multiple definitions of rules file
Using command line, ignoring X server
Warning! Multiple definitions of keyboard model
Using command line, ignoring X server
Warning! Multiple definitions of keyboard layout
Using command line, ignoring X server
Trying to load rules file ./rules/current...
Trying to load rules file /usr/share/X11/xkb/rules/current...
Trying to load rules file xkb/rules/current...
Success.
Applied rules from current:
rules: current
model: current
layout: current
variant: current
Trying to build keymap using the following components:
keycodes: current
types: current
compat: current
symbols: current
geometry: current
Error loading new keyboard description
Run Code Online (Sandbox Code Playgroud)
如果我通过将-print
选项添加到来加载键盘映射setxkbmap
,并将结果通过管道传输到xkbcomp
,键映射将被编译和加载而不会出现任何错误。
由于从 X 服务器加载键映射的方式到我加载键映射的方式发生了重大变化的唯一事情是正在使用的规则文件和组件的组织,我假设错误的根源存在于那里。我创建的设置有什么问题?为什么当我尝试使用重新加载键盘映射时会出现错误setxkbmap
?
作为参考,规则文件的内容如下。
xkb/规则/当前
! model layout variant = keycodes types compat symbols geometry
current current current = current current current current current
Run Code Online (Sandbox Code Playgroud)
xkb/规则/current.lst
! layout
current Current Layout
Run Code Online (Sandbox Code Playgroud)
xkb/规则/current.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xkbConfigRegistry SYSTEM "xkb.dtd">
<xkbConfigRegistry version="1.1">
<modelList>
<model>
<configItem>
<name>current</name>
<description>Current Model</description>
<vendor>Zistack</vendor>
</configItem>
</model>
</modelList>
<layoutList>
<layout>
<configItem>
<name>current</name>
<description>Current Layout</description>
<languageList>
<iso639Id>eng</iso639Id>
</languageList>
</configItem>
<variantList>
<variant>
<configItem>
<name>current</name>
<shortDescription>current</shortDescription>
<description>current</description>
<languageList>
<iso639Id>eng</iso639Id>
</languageList>
</configItem>
</variant>
</variantList>
</layout>
</layoutList>
</xkbConfigRegistry>
Run Code Online (Sandbox Code Playgroud)
你的格式已关闭。请参阅此旧文档中的第 4.3 节或此新版本中的规则部分。 道格·帕尔默(Doug Palmer)的《不可靠指南》有点过时,但也是一个很好的资源。
您尝试过:
! model layout variant = keycodes types compat symbols geometry
current current current = current current current current current
Run Code Online (Sandbox Code Playgroud)
具体来说, 的右侧=
采用单个参数。在线上!
,右侧是单一类型的文件 - 只允许{ keycodes, types, compat, Symbols, Geometry } 之一。在其他行中,右侧是单个参数,含义:
test1
)中找到的单个文件test1(foo)
)+test2
或+test2(bar)
)test1+test1(foo)+test2(bar)+test3(baz)
)左侧是过滤器;您可以添加任意数量的这些内容。
基本上,这些规则为每种类型构建单独的文件集。
// KEYCODES SECTION
// load keycodes based on model specified
! model = keycodes
test1 = test1
// ^^^^^^^^^^^^^^
// "if model=test1,
// load the default in the file keycodes/test1"
// load keycodes based on layout specified
! layout = keycodes
test1 = +test1(us)
// ^^^^^^^^^^^^^^
// "if layout=test1,
// also load stanza "us" in the file keycodes/test1"
// all at once
! model layout variant option = keycodes
test2 test2 test2 test2 = test1+test1(de)+test1(var2)+test1(opt2)
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// "if model=test2 and layout=test2 and... ,
// load the default stanza in file keycodes/test1,
// then load stanza "de" in file keycodes/test1, ...
////////////////
// GEOMETRY SECTION
// load geometry based on model specified
! model = geometry
test1 = test1
* = test3 // any other model
Run Code Online (Sandbox Code Playgroud)
定义这些规则后,您可以尝试setxkbmap -print
查看规则的实际效果:
$ setxkbmap -I/path/to/my/xkb -rules test1 -model test1 -print
xkb_keymap {
xkb_keycodes { include "test1" };
xkb_geometry { include "test1" };
};
// no xkb_symbols or other sections of the map with only the rules above
$ setxkbmap -I/path/to/my/xkb -rules test2 -model test1 -layout test1 -print
xkb_keymap {
xkb_keycodes { include "test1+test1(us)" };
xkb_geometry { include "test1" };
};
$ setxkbmap -I/path/to/my/xkb -rules test2 -model test2 -layout test2 -variant test2 -option test2 -print
xkb_keymap {
xkb_keycodes { include "test1+test1(us)+test1(var1)+test1(opt2)" };
xkb_geometry { include "test3" };
};
Run Code Online (Sandbox Code Playgroud)
这是规则运作的基本原理,但当然它可能会变得更加复杂。
%l
和%v
是具有布局和变体的变量(%m
也可用于模型)%(v)
将展开式括在括号中,因此%l%(v)
产生layout(variant)
%l[1]
不起作用%l
):2
(或:3
或:4
) 以限制加载到第二个(或第三个或第四个)布局的文件这是一个非常基本的规则部分,它将正确引入多个布局:
// setxkbmap -layout foo -variant foo1
! model layout = symbols
* * = %l%(v)
// setxkbmap -layout foo,bar -variant foo1,bar1
! model layout[1] = symbols
* * = %l[1]%(v[1])
// setxkbmap -layout foo,bar -variant foo1,bar1
! model layout[2] = symbols
* * = +%l[2]%(v[2]):2
// setxkbmap -layout foo,bar,baz -variant foo1,bar1,baz1
! model layout[3] = symbols
* * = +%l[3]%(v[3]):3
// setxkbmap -layout foo,bar,baz,bat -variant foo1,bar1,baz1,bat1
! model layout[4] = symbols
* * = +%l[4]%(v[4]):4
Run Code Online (Sandbox Code Playgroud)
现在您可以加载测试布局setxkbmap
并查看它们是否被添加。
$ setxkbmap -I/path/to/my/xkb -rules test -model test1 \
-layout test1,test2,test3 \
-variant test1,testA,testB -print
xkb_keymap {
xkb_keycodes { include "test1+test1(us)" };
xkb_symbols { include "test1(test1)+test2(testA):2+test3(testB):3" };
xkb_geometry { include "test1" };
};
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1965 次 |
最近记录: |