如何在 xkb 中制作 ISO_Level4_Shift 和 Lock?

Yah*_*dre 7 xkb keyboard-layout

我想知道是否可以在 xkb 中将密钥设置为 4 级修饰符或储物柜,而不是使用:Shift + ISO_Level3_Shift(又名 AltGr)。

与级别 6、7 和 8 相同的问题(使用“EIGHT_LEVEL”或变体)。

既然3级和5级都可以,那为什么其他的不行呢?

qui*_*tic 7

这是可能的,但有点hacky。尚未定义特定的键符。 ISO_Level3_{Shift,Latch,Lock}(和 level5 相同的三个)在编译时在 X11 和 libxkbcommon 头文件中定义。

在运行时,它们compatibility通过interpret节和actions;在模块中被激活。例如,检查您当前的键盘映射:

$ xkbcomp $DISPLAY - | less

//....
xkb_compatibility "complete+ledcaps(shift_lock)" {
    //....
    interpret ISO_Level3_Shift+AnyOf(all) {
        virtualModifier= LevelThree;
        useModMapMods=level1;
        action= SetMods(modifiers=LevelThree,clearLocks);
    };
    interpret ISO_Level3_Latch+AnyOf(all) {
        virtualModifier= LevelThree;
        useModMapMods=level1;
        action= LatchMods(modifiers=LevelThree,clearLocks,latchToLock);
    };
    interpret ISO_Level3_Lock+AnyOf(all) {
        virtualModifier= LevelThree;
        useModMapMods=level1;
        action= LockMods(modifiers=LevelThree);
    };
    //....
    interpret ISO_Level3_Shift+AnyOfOrNone(all) {
        action= SetMods(modifiers=LevelThree,clearLocks);
    };
    interpret ISO_Level3_Latch+AnyOfOrNone(all) {
        action= LatchMods(modifiers=LevelThree,clearLocks,latchToLock);
    };
    interpret ISO_Level3_Lock+AnyOfOrNone(all) {
        action= LockMods(modifiers=LevelThree);
    };
//....
Run Code Online (Sandbox Code Playgroud)

有一个现有的ISO_Level2_Latch键符。它没有interpret像上面那样的现有兼容性节,但是如果您添加它们,它会按您的预期运行。(Shift已经存在所以ISO_Level2_Shift是不必要的;Shift_Lock或者Caps_Lock代替ISO_Level2_Lock。)所以如果你想要一个Shift_Latch键,使用键ISO_Level2_Latch符并将这些添加到你的键映射中:

    interpret ISO_Level2_Latch+AnyOf(all) {
        useModMapMods=level1;
        action= LatchMods(modifiers=Shift,clearLocks,latchToLock);
    };
    interpret ISO_Level2_Latch+AnyOfOrNone(all) {
        action= LatchMods(modifiers=Shift,clearLocks,latchToLock);
    };
Run Code Online (Sandbox Code Playgroud)

我们可以将这种方法用于 4、6、7 和 8 级,但没有预定义的键符ISO_Level4_Shift等。您可以将它们添加到代码中并重新编译,或者您可以重新利用一些未使用的键符并将其解释为级别 4 转换(或闩锁或锁定)。检查头文件,libxkbcommon我们发现 XKB 知道的所有键符名称;这些看起来可能适合我们的目的:

//....in xkbcommon/xkbcommon-keysyms.h:
//....
#define XKB_KEY_ISO_Fast_Cursor_Left          0xfe2c
#define XKB_KEY_ISO_Fast_Cursor_Right         0xfe2d
#define XKB_KEY_ISO_Fast_Cursor_Up            0xfe2e
#define XKB_KEY_ISO_Fast_Cursor_Down          0xfe2f
Run Code Online (Sandbox Code Playgroud)

删除XKB_KEY_前缀以获得我们可以在 XKB 规则中引用的键符名称。让我们ISO_Fast_Cursor_Left用来伪造ISO_Level4_Latch.

首先,生成一个基本的键盘映射,使用setxkbmap -print; 然后我们将编辑此文件并为其添加覆盖,最后使用以下命令加载更改后的键盘映射xkbcomp [file] $DISPLAY

$ setxkbmap -print > mykeymap.xkb
xkb_keymap {
    xkb_keycodes  { include "evdev+aliases(qwerty)" };
    xkb_types     { include "complete"  };
    xkb_compat    { include "complete"  };
    xkb_symbols   { include "pc+us(altgr-intl)+inet(evdev)" };
    xkb_geometry  { include "pc(pc105)" };
};
Run Code Online (Sandbox Code Playgroud)

现在编辑此文件并将我们需要的覆盖放入其中:

// Attempting to define and use a key as Level4 Shift/Latch/Lock.
// Plan: * activate lv5 shift on rctrl.
//       * place latches on lv5 of keys 2,3,4,5 for corresponding level.
//       * replace keys ASDF with 8-level versions and define symbols for test.
//       * pressing RCtrl+4 then A should result in Á

// starting point: setxkbmap -layout us -variant altgr-intl -option '' -print
// load this file: xkbcomp myfile.xkb $DISPLAY
xkb_keymap {
    xkb_keycodes  { include "evdev+aliases(qwerty)" };
    xkb_types     { include "complete"      };
    xkb_compat    { 
        include "complete"      

        // add in interpretations
        // ISO_Level3_Latch includes a +AnyOf stanza and a +AnyOfOrNone stanza (same for ISO_Level5_Latch)
        // assume each additional latch needs both
        interpret ISO_Level2_Latch+AnyOf(all) {
            useModMapMods=level1;
            action= LatchMods(modifiers=Shift,clearLocks,latchToLock);
        };
        interpret ISO_Level2_Latch+AnyOfOrNone(all) {
            action= LatchMods(modifiers=Shift,clearLocks,latchToLock);
        };
        interpret ISO_Fast_Cursor_Left+AnyOf(all) {
            // Level4 needs both Shift and LevelThree
            useModMapMods=level1;
            action= LatchMods(modifiers=Shift+LevelThree,clearLocks,latchToLock);
        };
        interpret ISO_Fast_Cursor_Left+AnyOfOrNone(all) {
            // Level4 needs both Shift and LevelThree
            action= LatchMods(modifiers=Shift+LevelThree,clearLocks,latchToLock);
        };
    };
    xkb_symbols   { 
        include "pc"
        include "us(altgr-intl)"
        include "inet(evdev)"

        // latch keys
        key <AE02> {
            type= "EIGHT_LEVEL",
            symbols[Group1]= [ 2, at, twosuperior, dead_doubleacute, ISO_Level2_Latch, X, z, Z ]
        };
        key <AE03> {
            type= "EIGHT_LEVEL",
            symbols[Group1]= [ 3, numbersign, threesuperior, dead_macron, ISO_Level3_Latch, X, z, Z ]
        };
        // no ISO_Level4_Latch so use ISO_Fast_Cursor_Left
        key <AE04> {
            type= "EIGHT_LEVEL",
            symbols[Group1]= [ 4, dollar, currency, sterling, ISO_Fast_Cursor_Left, X, z, Z ]
        };
        key <AE05> {
            type= "EIGHT_LEVEL",
            symbols[Group1]= [ 5, percent, EuroSign, dead_cedilla, ISO_Level5_Latch, X, z, Z ]
        };
        // no ISO_Level6_Latch so use ISO_Fast_Cursor_Right
        // no ISO_Level7_Latch so use ISO_Fast_Cursor_Up
        // no ISO_Level8_Latch so use ISO_Fast_Cursor_Down

        // eight-level keys ASDF for testing
        key <AC01> {
            type= "EIGHT_LEVEL_SEMIALPHABETIC",
            symbols[Group1]= [ a, A, aacute, Aacute, agrave, Agrave, aring, Aring ]
        };
        key <AC02> {
            type= "EIGHT_LEVEL_SEMIALPHABETIC",
            symbols[Group1]= [ s, S, ssharp, section, ccedilla, Ccedilla, ntilde, Ntilde ]
        };
        key <AC03> {
            type= "EIGHT_LEVEL_SEMIALPHABETIC",
            symbols[Group1]= [ d, D, eth, ETH, thorn, THORN, t, T ]
        };
        key <AC04> {
            type= "EIGHT_LEVEL_SEMIALPHABETIC",
            symbols[Group1]= [ f, F, eacute, Eacute, x, X, z, Z ]
        };

        // ISO_Level3_Shift on Right Alt
        include "level3(ralt_switch)"
        // ISO_Level5_Shift on Right Ctrl
        include "level5(rctrl_switch)"  
    };
    xkb_geometry  { include "pc(pc105)"     };
};
Run Code Online (Sandbox Code Playgroud)

现在您可以测试闩锁(在上面的示例中,ISO_Level5_Shift应该是右键Ctrlxkbcomp如果不是,请重新运行命令):

  • ISO_Level5_Shift+2然后a应该打印A
  • ISO_Level5_Shift+3然后a应该打印á
  • ISO_Level5_Shift+4然后a应该打印Á
  • ISO_Level5_Shift+5然后a应该打印à

在测试中,我注意到 RCtrl-as-level5-shift 有点不稳定,并不总是正确应用。通常重新运行该xkbcomp命令一两次即可使其正常工作。用AF键测试;Ctrl+D可能会退出您的外壳。


一些应用程序将无法识别我们借用的密钥符号,并且可能会做一些奇怪的事情。例如,Firefox 将4在激活适当的闩锁时打印偶数,因此键序列rctrl+4 then a结果为; 这对于 3 和 5 上的真实键符不会发生,所以也许借用不同的键符会让 Firefox 识别出不应打印任何内容。到目前为止,大多数终端应用程序都按预期运行。