2

I am trying to remap some keys with xkb. In the below extract, I've changed two lines to configure my keymap. The one for space workes just fine. But both of the Delete I mapped on BKSP does not work, while BackSpace and AltGr+BKSP=BackSpace work as wanted.

I want to use Backspace+Shift as Delete.

my /usr/share/X11/xkb/symbols/pc file looks like this:

default  partial alphanumeric_keys modifier_keys
xkb_symbols "pc105" {
key <ESC>  {    [ Escape        ]   };

// The extra key on many European keyboards:
key <LSGT> {    [ less, greater, bar, brokenbar ] };

// The following keys are common to all layouts.
key <BKSL> {    [ backslash,    bar ]   };

// key <SPCE> { [ space ] }; // user manipulated next line. this works and has nothing to do with my question. key <SPCE> { [ space, space, bar ] }; include "srvr_ctrl(fkey2vt)" include "pc(editing)" include "keypad(x11)"

// key <BKSP> { [ BackSpace, BackSpace ] }; // user manipulated next line. This does not work and is relevant for this question. key <BKSP> { [ BackSpace, Delete, BackSpace, Delete ] };

key  &lt;TAB&gt; {    [ Tab,  ISO_Left_Tab    ]   };
key &lt;RTRN&gt; {    [ Return        ]   };

key &lt;CAPS&gt; {    [ Caps_Lock     ]   };
key &lt;NMLK&gt; {    [ Num_Lock      ]   };

key &lt;LFSH&gt; {    [ Shift_L       ]   };
key &lt;LCTL&gt; {    [ Control_L     ]   };
key &lt;LWIN&gt; {    [ Super_L       ]   };

key &lt;RTSH&gt; {    [ Shift_R       ]   };
key &lt;RCTL&gt; {    [ Control_R     ]   };
key &lt;RWIN&gt; {    [ Super_R       ]   };
key &lt;MENU&gt; {    [ Menu          ]   };

// Beginning of modifier mappings.
modifier_map Shift  { Shift_L, Shift_R };
modifier_map Lock   { Caps_Lock };
modifier_map Control{ Control_L, Control_R };
modifier_map Mod2   { Num_Lock };
modifier_map Mod4   { Super_L, Super_R };

// Fake keys for virtual&lt;-&gt;real modifiers mapping:
key &lt;LVL3&gt; {    [ ISO_Level3_Shift  ]   };
key &lt;MDSW&gt; {    [ Mode_switch       ]   };
modifier_map Mod5   { &lt;LVL3&gt;, &lt;MDSW&gt; };

key &lt;ALT&gt;  {    [ NoSymbol, Alt_L   ]   };
include &quot;altwin(meta_alt)&quot;

key &lt;META&gt; {    [ NoSymbol, Meta_L  ]   };
modifier_map Mod1   { &lt;META&gt; };

key &lt;SUPR&gt; {    [ NoSymbol, Super_L ]   };
modifier_map Mod4   { &lt;SUPR&gt; };

key &lt;HYPR&gt; {    [ NoSymbol, Hyper_L ]   };
modifier_map Mod4   { &lt;HYPR&gt; };
// End of modifier mappings.

key &lt;OUTP&gt; { [ XF86Display ] };
key &lt;KITG&gt; { [ XF86KbdLightOnOff ] };
key &lt;KIDN&gt; { [ XF86KbdBrightnessDown ] };
key &lt;KIUP&gt; { [ XF86KbdBrightnessUp ] };

};

hidden partial alphanumeric_keys xkb_symbols "editing" { key <PRSC> { type= "PC_ALT_LEVEL2", symbols[Group1]= [ Print, Sys_Req ] }; key <SCLK> { [ Scroll_Lock ] }; key <PAUS> { type= "PC_CONTROL_LEVEL2", symbols[Group1]= [ Pause, Break ] }; key <INS> { [ Insert ] }; key <HOME> { [ Home ] }; key <PGUP> { [ Prior ] }; key <DELE> { [ Delete ] }; key <END> { [ End ] }; key <PGDN> { [ Next ] };

key   &lt;UP&gt; {    [  Up           ]   };
key &lt;LEFT&gt; {    [  Left         ]   };
key &lt;DOWN&gt; {    [  Down         ]   };
key &lt;RGHT&gt; {    [  Right        ]   };

};

Output of setxkbmap -print:

xkb_keymap {
    xkb_keycodes  { include "evdev+aliases(qwertz)" };
    xkb_types     { include "complete"  };
    xkb_compat    { include "complete"  };
    xkb_symbols   { include "pc+de+gr(extended):2+ru(dos):3+us:4+inet(evdev)+ctrl(nocaps)+terminate(ctrl_alt_bksp)" };
    xkb_geometry  { include "pc(pc105)" };
};

xev output:

KeyPress event, serial 37, synthetic NO, window 0x6a00001,
    root 0x13d, subw 0x0, time 2108465, (124,40), root:(1315,695),
    state 0x10, keycode 50 (keysym 0xffe1, Shift_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyPress event, serial 37, synthetic NO, window 0x6a00001, root 0x13d, subw 0x0, time 2108612, (124,40), root:(1315,695), state 0x11, keycode 22 (keysym 0xffff, Delete), same_screen YES, XKeysymToKeycode returns keycode: 119 XLookupString gives 1 bytes: (7f) "" XmbLookupString gives 1 bytes: (7f) "" XFilterEvent returns: False

KeyRelease event, serial 37, synthetic NO, window 0x6a00001, root 0x13d, subw 0x0, time 2108707, (124,40), root:(1315,695), state 0x11, keycode 22 (keysym 0xffff, Delete), same_screen YES, XKeysymToKeycode returns keycode: 119 XLookupString gives 1 bytes: (7f) "" XFilterEvent returns: False

KeyRelease event, serial 37, synthetic NO, window 0x6a00001, root 0x13d, subw 0x0, time 2108764, (124,40), root:(1315,695), state 0x11, keycode 50 (keysym 0xffe1, Shift_L), same_screen YES, XLookupString gives 0 bytes: XFilterEvent returns: False

Right now with the manipulations I've made, pressing Backspace+Shift gives me a ~. I am using X11 and switch between german and us layout.

  • If you have any suggestion how I could clarify my question or which information to add, please let me know :) – katexochen Feb 04 '21 at 14:45
  • it is hard to pinpoint with given info. please provide the whole of "pc105" layout. Which layout are you using? is it possible that <BKSP> is overwritten later on (or in another file, depending on which layout you are using)?. Please state as well more clearly what the key combinations should produce and what they are producing instead. You can use xev from command line to check in detail how each key is being interpreted. Are u on x11 or wayland? – avila Mar 11 '21 at 12:29
  • also provide the output of setxkbmap -print – avila Mar 11 '21 at 12:33
  • 1
    @MarceloAvila I added the information you asked for to my question. Thanks for helping :) – katexochen Mar 21 '21 at 12:20
  • From your xev output, looks like xkb is interpreting shift+delete (because shift is pressed in order to get the second level of the key. This is indeed annoying to fix, but there are pre-mate layouts that use exactly this configuration for the BKSP key (as /usr/share/X11/xkb/symbols/macintosh_vndr/apple... maybe worth looking there to see how it is accomplished – avila Mar 21 '21 at 17:54

1 Answers1

4

I usually don't like to say if the intention of the OP is a good idea or not. In any case, it is not advisable to edit these standard symbols files (such as pc, de, us, etc) because they might get overwritten in a system update. It is, however, easier to change those files, because either they affect multiple layouts at once or these layouts are already available to choose from in the gnome-settings (or the other usual places). If you, instead, create a custom layout from scratch, you would have to change a few other files in order to find those layouts in the settings as well. (or you would need to set you keyboard layout with setxkbmap)

In any case, I am not sure why BKSP is returning ~. (in which application does it return a tilde? these xkb customization are not always intepreted equally by all applications). Maybe BKSP is redefined in some of the other symbols file that make out your keyboard layout. In any case, the following would, I believe, solve your problem. You have (at least) two options, a harder but "safer" or an easier but less "long lasting". I will give a "opianated" answer, but of course, you can get the relevant info and do as you find best.

create a custom symbols file

I'll call it custom. If you name it something else, make sure it is consistent with the includes statements in the definitions file.

This file show be found in /usr/share/X11/xkb/symbols/ where all other symbols definitions (for other languages and layouts) can be found. Because it is bad practice to edit files outside your home folder, create a file somewhere you can edit and link to /usr/share/X11/xkb/symbols with:

cd <PATH-WHERE-YOUR-SYBMBOLS-FILE-IS>
sudo ln -sr ./custom /usr/share/X11/xkb/symbols/

contents of custom

The relevant part to make the SHIFT+BackSpace function properly is something like the following. Note the clearmods=Shift option.

partial alphanumeric_keys xkb_symbols "backspace_delete" {
    key.type[Group1] = "TWO_LEVEL";
    key <BKSP> { 
            symbols[Group1] = [ BackSpace, Delete], 
            actions[Group1] = [ NoAction(), RedirectKey(keycode=<DELE>, clearmods=Shift) ]
    };
};

The rest of .../symbols/custom:

default partial alphanumeric_keys xkb_symbols "basic" {
name[Group1]=&quot;German Custom&quot;;

// basic layout 
include &quot;de(basic)&quot; // you could also include &quot;de(deadgraveacute)&quot; if you are not using the plain german layout

// special includes (these can be also choosen from gnome tweaks &gt; additional layout options)
include &quot;ctrl(nocaps)&quot;  
include &quot;terminate(ctrl_alt_bksp)&quot;
include &quot;level3(ralt_switch)&quot; // &lt;&lt;-- adapt accordingly (possible pre-made definitions in /usr/share/X11/symbols/level3)

// custom includes
include &quot;custom(backspace_delete)&quot;
include &quot;custom(other_changes)&quot;

};

default alphanumeric_keys partial xkb_symbols "us" {

name[Group1]=&quot;US Custom&quot;;

// basic layout 
include &quot;us(basic)&quot;

// special includes 
include &quot;ctrl(nocaps)&quot;  
include &quot;terminate(ctrl_alt_bksp)&quot;
include &quot;level3(ralt_switch)&quot; // &lt;&lt;-- adapt accordingly (possible pre-made definitions in /usr/share/X11/symbols/level3)

// custom includes
include &quot;custom(backspace_delete)&quot;
include &quot;custom(other_changes)&quot;

};

partial alphanumeric_keys xkb_symbols "backspace_delete" { key.type[Group1] = "TWO_LEVEL"; key <BKSP> { symbols[Group1] = [ BackSpace, Delete], actions[Group1] = [ NoAction(), RedirectKey(keycode=<DELE>, clearmods=Shift) ] }; };

partial alphanumeric_keys xkb_symbols "other_changes" { key <SPCE> { [ space, space, bar, NoSymbol ] }; // NoSymbol does not override previous definition, VoidSymbol does. };

In order to find your custom layout in the gnome settings, modify /usr/share/X11/xkb/rules/evdev.xml. It is a long xml file, insert it somewhere in that file. (here I am not sure i can be anywhere, or if you should introduce one part under the german section and the other part under the US section.)

    <!-- Keyboard indicator for Custom Layouts -->
    <layout>
      <configItem>
        <name>custom</name>
        <shortDescription>cu</shortDescription>
        <description>Custom (German - base)</description>
        <languageList>
          <iso639Id>ger</iso639Id>
        </languageList>
      </configItem>
      <variantList>
        <variant>
          <configItem>
            <name>us</name>
           <description>Custom (US)</description>
          </configItem>
        </variant>
      </variantList>
    </layout>
    <!-- End of Custom Layouts -->
  • you might have to run sudo dpkg-reconfigure xkb-data for the custom keyboard to show in the settings.
  • while trying out your layout, you can run setxkbmap custom for the base (german) or setxkbmap custom -variant us for the us version.
  • if you still prefer to edit the pc file directly, I would suggest you do it by 1) creating one or more partial definitions and only include those in the pc or in the relevant de and us definitions. For that you just need to place the custom file in the xkb/symbols folder and use include "nameOfFile(nameOfPartial)" accordingly.
avila
  • 563
  • 1
  • 6
  • 21