如何设置 XKB 以使用 3 个修饰键和 2 个可切换布局?

如何设置 XKB 以使用 3 个修饰键和 2 个可切换布局?

考虑以下 XKB 布局:

xkb_keymap {

xkb_keycodes {
  <ESC> = 9;
  <FK01> = 67;
  <FK02> = 68;
  <FK03> = 69;
  <FK04> = 70;
  <FK05> = 71;
  <FK06> = 72;
  <FK07> = 73;
  <FK08> = 74;
  <FK09> = 75;
  <FK10> = 76;
  <FK11> = 95;
  <FK12> = 96;

  <INS> = 118;
  <DELE> = 119;
  <HOME> = 110;
  <END> = 115;
  <PGUP> = 112;
  <PGDN> = 117;

  <TLDE> = 49;
  <AE01> = 10;
  <AE02> = 11;
  <AE03> = 12;
  <AE04> = 13;
  <AE05> = 14;
  <AE06> = 15;
  <AE07> = 16;
  <AE08> = 17;
  <AE09> = 18;
  <AE10> = 19;
  <AE11> = 20;
  <AE12> = 21;
  <BKSP> = 22;

  <TAB> = 23;
  <AD01> = 24;
  <AD02> = 25;
  <AD03> = 26;
  <AD04> = 27;
  <AD05> = 28;
  <AD06> = 29;
  <AD07> = 30;
  <AD08> = 31;
  <AD09> = 32;
  <AD10> = 33;
  <AD11> = 34;
  <AD12> = 35;

  <BKSL> = 51;

  <CAPS> = 66;
  <AC01> = 38;
  <AC02> = 39;
  <AC03> = 40;
  <AC04> = 41;
  <AC05> = 42;
  <AC06> = 43;
  <AC07> = 44;
  <AC08> = 45;
  <AC09> = 46;
  <AC10> = 47;
  <AC11> = 48;
  <RTRN> = 36;

  <LFSH> = 50;
  <AB01> = 52;
  <AB02> = 53;
  <AB03> = 54;
  <AB04> = 55;
  <AB05> = 56;
  <AB06> = 57;
  <AB07> = 58;
  <AB08> = 59;
  <AB09> = 60;
  <AB10> = 61;
  <RTSH> = 62;

  <LCTL> = 37;
  <LWIN> = 133;
  <LALT> = 64;
  <SPCE> = 65;
  <RALT> = 108;
  <RWIN> = 134;
  <MENU> = 135;
  <RCTL> = 105;

  <UP> = 111;
  <LEFT> = 113;
  <DOWN> = 116;
  <RGHT> = 114;

  <NMLK> = 77;
  <KPDV> = 106;
  <KPMU> = 63;
  <KPSU> = 82;

  <KP7> = 79;
  <KP8> = 80;
  <KP9> = 81;

  <KPAD> = 86;

  <KP4> = 83;
  <KP5> = 84;
  <KP6> = 85;

  <KP1> = 87;
  <KP2> = 88;
  <KP3> = 89;

  <KPEN> = 104;

  <KP0> = 90;
  <KPDL> = 91;
};

xkb_types {
  type "ONE_LEVEL" {
      modifiers = none;
      level_name[Level1] = "Any";
  };
  type "TWO_LEVEL" {
      modifiers = none;
      level_name[Level1] = "Base";
  };
  type "ALPHABETIC" {
      modifiers = none;
      level_name[Level1] = "Base";
  };
  type "KEYPAD" {
      modifiers = none;
      level_name[Level1] = "Base";
  };
  type "MULTI" {
    modifiers = Shift+Mod3+Mod5;
    map[Shift] = Level2;
    map[Mod3] = Level3;
    map[Shift+Mod3] = Level4;
    map[Mod5] = Level5;
    map[Shift+Mod5] = Level6;
    map[Mod3+Mod5] = Level7;
    map[Shift+Mod3+Mod5] = Level8;
    level_name[Level1] = "Base";
    level_name[Level2] = "Shift";
    level_name[Level3] = "Alt";
    level_name[Level4] = "Shift Alt";
    level_name[Level5] = "Control";
    level_name[Level6] = "Control Shift";
    level_name[Level7] = "Control Alt";
    level_name[Level8] = "Control Shift Alt";
  };
};

xkb_compatibility {
  interpret Any + Any{
    action = SetMods(mods=modMapMods);
  };
  interpret ISO_Next_Group {
    action = LockGroup(group=+1);
  };
  indicator "Shift" {
    modifiers = Shift;
  };
};

xkb_symbols {
  key.type = "MULTI";

  key <ESC> {[Escape]};
  key <FK01> {[U2010]}; # hyphen
  key <FK02> {[U2011]}; # non-breaking hyphen
  key <FK03> {[U00AD]}; # soft hyphen
  key <FK04> {[U200B]}; # zero width space
  key <FK05> {[leftdoublequotemark], [guillemotleft]};
  key <FK06> {[rightdoublequotemark], [guillemotright]};
  key <FK07> {[leftsinglequotemark], [doublelowquotemark]};
  key <FK08> {[rightsinglequotemark], [leftdoublequotemark]};
  key <FK09> {[endash]};
  key <FK10> {[emdash]};
  key <FK11> {[ellipsis, U22EF]}; # cdots
  key <FK12> {[nobreakspace, U2060]}; # word joiner
  key <INS> {[Insert]};
  key <DELE> {[Delete]};
  key <HOME> {[Home]};
  key <END> {[End]};
  key <PGUP> {[Prior]};
  key <PGDN> {[Next]};

  key <TLDE> {[grave, asciitilde, dead_grave, dead_tilde, dead_doublegrave, dead_belowtilde]};
  key <AE01> {[1, exclam, U22C1, U22C3, logicalor, union], [exclam, 1]}; # big or, big union
  key <AE02> {[2, at], [at, 2]};
  key <AE03> {[3, numbersign], [slash, 3]};
  key <AE04> {[4, dollar], [semicolon, 4]};
  key <AE05> {[5, percent, dead_horn, dead_hook], [colon, 5]};
  key <AE06> {[6, asciicircum, dead_circumflex, dead_caron, dead_belowcircumflex], [comma, 6]};
  key <AE07> {[7, ampersand, U22C0, U22C2, logicaland, intersection], [period, 7]}; # big and, big intersection
  key <AE08> {[8, asterisk, VoidSymbol, VoidSymbol, multiply, U2297], [question, 8]};
  key <AE09> {[9, parenleft], [parenleft, 9]};
  key <AE10> {[0, parenright, dead_abovering, dead_belowring, emptyset, U2243], [parenright, 0]}; # bar tilde
  key <AE11> {[minus, underscore, dead_macron, dead_belowmacron, U2212, U2245]}; # minus, double bar tilde
  key <AE12> {[equal, plus, dead_breve, dead_belowbreve, notequal, plusminus]};
  key <BKSP> {[BackSpace]};

  key <TAB> {[Tab, ISO_Left_Tab]};
  key <AD01> {[q, Q, Greek_theta, Greek_THETA, U03D1], [Cyrillic_shorti, Cyrillic_SHORTI]}; # vartheta
  key <AD02> {[w, W, a, A, b, B, c, C], [Cyrillic_tse, Cyrillic_TSE]};
  key <AD03> {[e, E, U03F5, Greek_epsilon, elementof, notelementof], [Cyrillic_u, Cyrillic_U]}; # epsilon, varepsilon
  key <AD04> {[r, R, Greek_rho, VoidSymbol, U03F1], [Cyrillic_ka, Cyrillic_KA]}; # varrho
  key <AD05> {[t, T, Greek_tau, VoidSymbol, thorn, THORN], [Cyrillic_ie, Cyrillic_IE]};
  key <AD06> {[y, Y, Greek_upsilon, Greek_UPSILON], [Cyrillic_en, Cyrillic_EN]};
  key <AD07> {[u, U, Greek_psi, Greek_PSI, udiaeresis, Udiaeresis], [Cyrillic_ghe, Cyrillic_GHE]};
  key <AD08> {[i, I, Greek_iota, VoidSymbol, infinity], [Cyrillic_sha, Cyrillic_SHA]};
  key <AD09> {[o, O, Greek_omega, Greek_OMEGA, odiaeresis, Odiaeresis, oe, OE], [Cyrillic_shcha, Cyrillic_SHCHA]};
  key <AD10> {[p, P, Greek_pi, Greek_PI, U03D6], [Cyrillic_ze, Cyrillic_ZE]}; # varpi
  key <AD11> {[bracketleft, braceleft, VoidSymbol, VoidSymbol, leftarrow, U2282], [Cyrillic_ha, Cyrillic_HA]}; # left angle bracket, subset
  key <AD12> {[bracketright, braceright, U21A6, VoidSymbol, rightarrow, U2283], [Cyrillic_hardsign, Cyrillic_HARDSIGN]}; # right angle bracket, supset
  key <BKSL> {[backslash, bar, VoidSymbol, VoidSymbol, U2016]};

  key <CAPS> {[ISO_Next_Group]};
  key <AC01> {[a, A, Greek_alpha, VoidSymbol, adiaeresis, Adiaeresis, ae, AE], [Cyrillic_ef, Cyrillic_EF]};
  key <AC02> {[s, S, Greek_sigma, Greek_SIGMA, ssharp, U03C2], [Cyrillic_yeru, Cyrillic_YERU]}; # varsigma
  key <AC03> {[d, D, Greek_delta, Greek_DELTA, eth, ETH], [Cyrillic_ve, Cyrillic_VE]};
  key <AC04> {[f, F, Greek_phi, Greek_PHI, U03D5], [Cyrillic_a, Cyrillic_A]}; # varphi
  key <AC05> {[g, G, Greek_gamma, Greek_GAMMA], [Cyrillic_pe, Cyrillic_PE]};
  key <AC06> {[h, H, Greek_eta], [Cyrillic_er, Cyrillic_ER]};
  key <AC07> {[j, J, Greek_xi, Greek_XI], [Cyrillic_o, Cyrillic_O]};
  key <AC08> {[k, K, Greek_kappa], [Cyrillic_el, Cyrillic_EL]};
  key <AC09> {[l, L, Greek_lambda, Greek_LAMBDA], [Cyrillic_de, Cyrillic_DE]};
  key <AC10> {[semicolon, colon, dead_diaeresis, dead_belowdiaeresis], [Cyrillic_zhe, Cyrillic_ZHE]};
  key <AC11> {[apostrophe, quotedbl, dead_acute, dead_doubleacute, U2202, U2207], [Cyrillic_e, Cyrillic_E]};         
  key <RTRN> {[Return]};

  key <LFSH> {[Shift_L]};
  key <AB01> {[z, Z, Greek_zeta], [Cyrillic_ya, Cyrillic_YA]};
  key <AB02> {[x, X, Greek_chi], [Cyrillic_che, Cyrillic_CHE]};
  key <AB03> {[c, C, dead_cedilla], [Cyrillic_es, Cyrillic_ES]};
  key <AB04> {[v, V, dead_ogonek], [Cyrillic_em, Cyrillic_EM]};
  key <AB05> {[b, B, Greek_beta], [Cyrillic_i, Cyrillic_I]};
  key <AB06> {[n, N, Greek_nu], [Cyrillic_te, Cyrillic_TE]};
  key <AB07> {[m, M, Greek_mu], [Cyrillic_softsign, Cyrillic_SOFTSIGN]};
  key <AB08> {[comma, less, dead_belowcomma, dead_abovecomma, lessthanequal, U27E8], [Cyrillic_be, Cyrillic_BE]};
  key <AB09> {[period, greater, dead_belowdot, dead_abovedot, greaterthanequal, U27E9], [Cyrillic_yu, Cyrillic_YU]};
  key <AB10> {[slash, question, dead_stroke, dead_invertedbreve, dead_abovereversedcomma, periodcentered], [Cyrillic_io, Cyrillic_IO]};             
  key <RTSH> {[Shift_R]};

  key <LCTL> {[Control_L]};
  key <LWIN> {[Super_L]};
  key <LALT> {[Alt_L]};
  key <SPCE> {[space]};
  key <RALT> {[Alt_R]};
  key <RWIN> {[Super_R]};
  key <MENU> {[Menu]};
  key <RCTL> {[Control_R]};

  key <UP> {[Up]};
  key <LEFT> {[Left]};
  key <DOWN> {[Down]};
  key <RGHT> {[Right]};

  key <NMLK> {[Num_Lock]};
  key <KPDV> {[KP_Divide]};
  key <KPMU> {[KP_Multiply]};
  key <KPSU> {[KP_Subtract]};

  key <KP7> {[Delete]};
  key <KP8> {[End]};
  key <KP9> {[Next]};

  key <KPAD> {[KP_Add]};

  key <KP4> {[KP_4]};
  key <KP5> {[KP_5]};
  key <KP6> {[KP_6]};

  key <KP1> {[KP_1]};
  key <KP2> {[KP_2]};
  key <KP3> {[KP_3]};

  key <KPEN> {[KP_Enter]};

  key <KP0> {[KP_0]};
  key <KPDL> {[KP_Delete]};

  modifier_map Shift { Shift_L, Shift_R };
  modifier_map Lock { ISO_Next_Group };
  modifier_map Control { Control_L };
  modifier_map Mod1 { Alt_L };
  modifier_map Mod2 { Num_Lock };
  modifier_map Mod3 { Alt_R };
  modifier_map Mod4 { Super_L, Super_R };
  modifier_map Mod5 { Control_R };
};

};

目的是使用 Caps Lack 切换两种布局;每个布局都有 3 个修饰键:Shift、右 Alt 和右 Control。因此,每个按键在每种布局中最多可生成 8 个不同的字母。例如,以下行

  key <AD02> {[w, W, a, A, b, B, c, C], [Cyrillic_tse, Cyrillic_TSE]};

旨在在第一个布局中进行以下分配:

w → w
Shift+w → W
Alt_R+w → a
Alt_R+Shift+w → A
Control_R+w → b
Control_R+Shift+w → B
Control_R+Alt_R+w → c
Control_R+Alt_R+Shift+w → C

当我使用 xkbcomp - :0 加载此布局时,8 个组合中只有 4 个按预期工作,如下所示:

w → w
Shift+w → W
Alt_R+w → a
Alt_R+Shift+w → a
Control_R+w → b
Control_R+Shift+w → b
Control_R+Alt_R+w → b
Control_R+Alt_R+Shift+w → b

换句话说,两个或三个修饰键的组合不起作用。为了获得所需的行为应该改变什么?

答案1

让我们尝试稍微简化一下。

我不知道有任何符号命令keys.type=MULTI,所以我先删除了该行。

我将您的文件保存为keys(减去该行)并运行xkbcomp -w 10 keys.它报告:

Warning:          No automatic type for 6 symbols
                  Using  for the <TLDE> key (keycode 49)
Warning:          Type "" is not defined
                  Using TWO_LEVEL for the <TLDE> key (keycode 49)

(之后还有更多错误)

因此,让我们添加一个MULTI3模仿MULTI但具有 3 (6) 个级别的定义:

  type "MULTI3" {
    modifiers = Shift+Mod3+Mod5;
    map[Shift] = Level2;
    map[Mod3] = Level3;
    map[Shift+Mod3] = Level4;
    map[Mod5] = Level5;
    map[Shift+Mod5] = Level6;
    level_name[Level1] = "Base";
    level_name[Level2] = "Shift"; 
    level_name[Level3] = "Alt";  
    level_name[Level4] = "Shift Alt";
    level_name[Level5] = "Control";
    level_name[Level6] = "Control Shift";
  };

...然后将其分配给TLDE

  key <TLDE> {type="MULTI3", symbols=[grave, asciitilde, dead_grave, dead_tilde, dead_doublegrave, dead_belowtilde]};

好的,重新运行xkbcomp -w 10 keys确认这消除了该错误。

相同类型的错误会影响其他 27 个键……因此,用所需的类型对它们进行注释,和/或创建新类型来处理它们,应该可以消除这些错误。

如果在同一个文件中定义了两个组(顺便说一句,这将以非常不愉快的方式与大多数用于选择键盘布局的工具(例如在 Gnome 中)进行交互),您将必须为每个组指定符号和类型。我自己从未尝试过,但是例如:

  key <AD01> {type[group1]="NewTypeFor5Levels",
              symbols[group1]=[q, Q, Greek_theta, Greek_THETA, U03D1], 
              type[group2]="TWO_LEVEL",
              symbols[group2]=[Cyrillic_shorti, Cyrillic_SHORTI]};
       // vartheta
  key <AD02> {type[group1]="MULTI",
              symbols[group1]=[w, W, a, A, b, B, c, C],
              type[group2]="TWO_LEVEL",
              symbols[group2]=[Cyrillic_tse, Cyrillic_TSE]};

一旦可以编译文件,您应该会取得更好的成功。

相关内容