Tips: Modify Logitech K380 Layout on Ubuntu Linux

 

Logitech K380

I love the Logitech K380 keyboard. In my case I'm using the UK layout version. But it annoys me that some the keys do not exactly represent the letters on it. For example the keys with the grey letters.

In the past I got over it and trained my muscle memory to hit a key when I mean to type a certain letter.

However I found out that it's very simple to adapt the layout in Linux (I'm using Ubuntu 23.10 at the moment). Not only that you can exchange the keys for something else, for example for a letter or symbols that you frequently use.

In my case I need to type the letters ŵ and ö a lot in my work. So I added the functionality that AltGr+w and AltGr+o produce the letter ŵ and ö respectively.

How to do that? Easier than you think. Here is how to do it.

We need to modify 5 files. First the layout file inside the /usr/share/X11/xkb/symbols directory and the other 4 are inside the /usr/share/X11/xkb/rules directory.

As I am using a UK keyboard, the layout file I need to modify is GB (UK).

1. Open gb file in a Text editor, for example with Gedit.

2. Append the following lines at the end of the file:

partial alphanumeric_keys

xkb_symbols "k380" {

   include "gb(basic)"

   name[Group1]= "English (UK, Logitech K380)";

// get altgr+w and altgr+o to produce Nias characters (ŵ and ö)

   key <AD02> {[ w,        W, wcircumflex,  Wcircumflex ]};

   key <AD09> {[ o,        O,  odiaeresis,   Odiaeresis ]};

// represent the exta keys on K380

   key <AE04> {[ 4,   dollar,    EuroSign,       dollar ]};

   key <AE02> {[ 2, quotedbl,    EuroSign,           at ]};

   key <TLDE> {[      grave,     notsign,    section,  plusminus]};

   key <AC11> {[ apostrophe,          at, apostrophe,   quotedbl]};

   key <BKSL> {[ numbersign,  asciitilde,  backslash,        bar]};

   key <LSGT> {[ backslash ,         bar,      grave, asciitilde]};

   include "level3(ralt_switch)"

};

As you can see in those codes, I modified the second layer (AltGr) of w and o keys to produce circumflex and diaresis letters.

The rest of the code is to represent the grey letters on the K380 keyboard (UK version). The grey letters are now accessible on the second layer through AltGr key combination. 

In similar way you can modify any other keys on the keyboard.

3. Save the file.

Now we are ready for the next step. There are 4 files we need to modify, i.e. base.lst, base.xml, evdev.lst and evdev.xml. They are located in /usr/share/X11/xkb/rules directory.

4. Open base.lst file and insert the following line for example in the beginning of the block of gb: at line 733.

k380            gb: English (UK, Logitech K380)

5. Save the file.

6. Do exactly the same with the file evdev.lst and save it.

7. Open the base.xml file and insert the following line for example in the beginning of the block gb layout variants for example at line 6058:

        <variant>

          <configItem>

            <name>k380</name>

            <description>English (UK, Logitech K380)</description>

          </configItem>

        </variant>

This lines of code is a statement opened by <variant> and closed by </variant>. Make sure that they are inserted before or after the variant statement of other keyboard layouts. If you go the line 6058 you see that all the variants there belong to the GB keyboard layout. I inserted mine just before the English (UK, extended, Windows) layout variant.

8. Save the file.

9. Now do exactly the same with the file evdev.xml and save it.

10. Log out.

11. Log in again and add the new k380 layout in the Settings > Keyboard > Input sources. You can see the new layout under the name English (UK, Logitech K380)

12. Enjoy your k380 keyboard.