You are not logged in.

#1 2017-12-11 00:34:39

mezlogo
Member
Registered: 2017-12-10
Posts: 7

[SOLVED] Can't extend keyboard layout using xkbcomp and setxkbmap.

Hello. I'm a software developer and I wanna add new layout with navigation and special characters, for instance: AltGr + h == left arrow and AltGr + a == '(' character.
I've read three arch wiki pages about xkb and googled a lot, but all my tryies weren't successful.
In general, I don't understand many of the concepts, so I decided to join this forum and ask for the help.
Let me describe what I did step by step:
1) My current configuration is:

setxkbmap -layout us,ru -option '' -option 'grp:caps_toggle,grp_led:caps' -print | xsel -b
xkb_keymap {
    xkb_keycodes  { include "evdev+aliases(qwerty)"    };
    xkb_types     { include "complete"    };
    xkb_compat    { include "complete+ledcaps(group_lock)"    };
    xkb_symbols   { include "pc+us+ru:2+inet(evdev)+capslock(grouplock)"    };
    xkb_geometry  { include "pc(pc105)"    };
};

2) I decided to make tiny step: just create a dump file of my current config using xkbcomp

xkbcomp -xkb $DISPLAY ~/.xkb/xkbmap

The content is too large and I believe you can reproduce.
Two ideas came in my head:
a) Add a layout (a new group) and activate it while pressed AltGr.
/usr/share/X11/xkb/rules/base.lst contains a hint grp:switch. symbols/group defines "switch" and other options.
An additional note is  'while pressed' feature differs from 'change state' by 'virtual_modifiers' statement and ISO_Next_Group vs Mode_switch action.
I use two layouts: us and ru, so I don't understand how to select my last group with navigation and special chars. After find definition of Mode_switch in compat/basic

action= SetGroup(group=+1);

I guess I can use third group only when I'm at second layout (ru).
b) After that I chose to use levels and types, just like low and high case for alphabet keys or better "TWO_LEVEL", but my first test didn't work: I set type "TWO_LEVEL" for AC06 (h), saved and restarted xkbcomp

xkbcomp -xkb $DISPLAY ~/.xkb/xkbmap

No errors were appeared, but caps lock affected 'H'.
What is wrong with my simplest sample?
If I exchange the order of h `[H,h]` I'll get capital without shift, so the recompilation process is working correctly.

P.s. please, tell me if I made a mistake in English. I'm learning it, so it's crucial for me.
Thanks!

Last edited by mezlogo (2017-12-13 16:46:25)

Offline

#2 2017-12-11 00:40:01

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: [SOLVED] Can't extend keyboard layout using xkbcomp and setxkbmap.

Please use code tags when pasting to the boards: https://wiki.archlinux.org/index.php/Co … s_and_code


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2017-12-11 12:54:56

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,102

Re: [SOLVED] Can't extend keyboard layout using xkbcomp and setxkbmap.

mezlogo wrote:

I'm a software developer and I wanna add new layout

Do you want to write a new xkb layout or scratch an itch?
The QnD solution is xmodmap, https://wiki.archlinux.org/index.php/Xmodmap#Templates
Things you got to learn are about none but this will impact both layouts (I've no idea what russian has on the "h" key, but that could be a problem to the approach)

If you want/need to provide an own map, copy /usr/share/X11/xkb/symbols/ru, add a new symbol table, include at least "ru(common)" and override the relevant keys.
If you want to use the compiled keymap, edit the 3rd element in the xkb_symbols table for the respective keys.

Offline

#4 2017-12-11 22:47:15

mezlogo
Member
Registered: 2017-12-10
Posts: 7

Re: [SOLVED] Can't extend keyboard layout using xkbcomp and setxkbmap.

seth, thx for your replay.
I've read xmodmap is a deprecated tool, therefore I want to use xkb.
By the end of my keyboard modification trip I want to get two language layouts (en and ru), caps lock switchs layout and my additional alt+some keys for navigation (arrows), text manipulation (del, bckspc) and special chars insertion (`~#$^&*()-_=+\|]['"/) layout (group or level).
As the start point I want to use compiled keymap and third level for some keys.
Let me use the simplest way: only us layout.

setxkbmap -layout us -option ''
xkb_keymap {
	xkb_keycodes  { include "evdev+aliases(qwerty)"	};
	xkb_types     { include "complete"	};
	xkb_compat    { include "complete"	};
	xkb_symbols   { include "pc+us+inet(evdev)"	};
	xkb_geometry  { include "pc(pc105)"	};
};

For instance, I want to add 'tilda' for alt + j using third level.
What do I do?
1) Make a dump of current configuration:

xkbcomp -xkb $DISPLAY ~/.xkb/xkbmap

2) Create a hybrid type from ALPHABETIC and PC_ALT_LEVEL2 AND set my type for 'j' key:
https://gist.github.com/mezlogo/3bd1010 … /revisions
3) Compile

xkbcomp -w 0 ~/.xkb/xkbmap $DISPLAY

xev output is absolutely correct:

KeyPress event, serial 33, synthetic NO, window 0x1a00001,
    root 0xfd, subw 0x0, time 4502556, (-224,714), root:(461,716),
    state 0x8, keycode 44 (keysym 0x7e, asciitilde), same_screen YES,
    XKeysymToKeycode returns keycode: 49
    XLookupString gives 1 bytes: (7e) "~"
    XmbLookupString gives 1 bytes: (7e) "~"
    XFilterEvent returns: False

Although, neither terminal (urxvt+zsh) nor browser (ff and chrome) see changes. Moreover shift+j doesn't produce 'J', only caps lock does.

Where is my mistake? I have no idea, what's wrong with my changes.

Offline

#5 2017-12-12 08:07:47

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,102

Re: [SOLVED] Can't extend keyboard layout using xkbcomp and setxkbmap.

Why do you add a "SPECIAL_TYPE" type?

Offline

#6 2017-12-12 09:52:26

mezlogo
Member
Registered: 2017-12-10
Posts: 7

Re: [SOLVED] Can't extend keyboard layout using xkbcomp and setxkbmap.

I wanted to add a third level for type similar to ALPHABETIC and existed types didn't feet my need, for instance THREE_LEVEL doesn't declare Lock functionality for caps lock and so on.
Is this a mistake?

BTW, previously I tried to use existed type CTRL+ALT, cos' I know that is works well and added additional three levels for 'j' key, but a result was the same.

Last edited by mezlogo (2017-12-12 09:54:34)

Offline

#7 2017-12-12 12:59:02

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,102

Re: [SOLVED] Can't extend keyboard layout using xkbcomp and setxkbmap.

Did you try to simply add the 3rd level item to the alphabetic table?

Offline

#8 2017-12-12 13:49:17

mezlogo
Member
Registered: 2017-12-10
Posts: 7

Re: [SOLVED] Can't extend keyboard layout using xkbcomp and setxkbmap.

I've just tried it.
Added third level in ALPHABETIC type

type "ALPHABETIC" {
    modifiers= Shift+Lock+Alt;
    map[Shift]= Level2;
    map[Lock]= Level2;
    map[Alt]= Level3;
    level_name[Level1]= "Base";
    level_name[Level2]= "Caps";
    level_name[Level3]= "Alt";
};

And got compilation error:

xkbcomp -w 0 ~/.xkb/xkbmap $DISPLAY             
Error:            Key type "ALPHABETIC" has 3 levels, must have 2
                  Illegal type definition ignored

Then I googled this message and found some source
It seems to me that I can't change levels for {ONE,TWO}_LEVELS,ALPHABETIC and KEYPAD types.

So, I don't understand, what's wrong with me and my tries.
I guess it's might be a complex software related (i3wm, lib versions, or something like that) problem OR I hope, I missed something important. But xev correct output is getting me crazy.

Offline

#9 2017-12-12 14:52:40

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,102

Re: [SOLVED] Can't extend keyboard layout using xkbcomp and setxkbmap.

Indeed, but FOUR_LEVEL_SEMIALPHABETIC should work?

Offline

#10 2017-12-13 11:35:58

mezlogo
Member
Registered: 2017-12-10
Posts: 7

Re: [SOLVED] Can't extend keyboard layout using xkbcomp and setxkbmap.

seth, your guiding skill is amazing.
After your suggestion to use another existed class I read four_* classes and I discovered LevelThree modifier had no mapping at all!
So, for test, I remapped Menu key to ISO_Level3_Shift and default FOUR_LEVEL key LSGT produced correct output everywhere, not only in xev.

Thanks for your straight corrections and for giving me 'not alone' feeling!

But, this is't the end. I want to define my layout/rules in home dir and load it at startime using setxkbmap.

Can I close this topic after that? Current topic's name fits my goals, as well.

Last edited by mezlogo (2017-12-13 11:37:28)

Offline

#11 2017-12-13 16:07:08

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,102

Re: [SOLVED] Can't extend keyboard layout using xkbcomp and setxkbmap.

You can and should mark [SOLVED] threads by editing the subject of your first post and open further threads for every (new) question you can't asnswer yourself, though forking an existing symbol table should not turn out being a major obstacle now?

Offline

Board footer

Powered by FluxBB