Gentoo Archives: gentoo-user

From: Gevisz <gevisz@×××××.com>
To: gentoo-user@l.g.o
Subject: [gentoo-user] A direct keyboard layout switch for xfce4
Date: Sun, 11 Oct 2015 09:17:04
1 I am asking this question here after discussing it
2 at vim_use mailing list (as an slight off topic to
3 the "vim and touch typing" thread) and after an extensive
4 google search earlier.
6 Below is some resumee from that discussion but for those
7 of you how do not want to read all that I just formulate
8 my question in short first: "Is there any plugin or
9 application working under xfce4 that allows switching
10 the keyboard layout directly, that is not by circling or
11 toggling it.
13 By a direct keyboard switch I mean the way to switch
14 to a certain keyboard layout irrespectively of the its
15 initial state. For example, I need a (configurable)
16 hot key to switch to a Cyrillic keyboard layout if
17 I am currently in the English keyboard layout and
18 to do nothing if I am already in the Cyrillic keyboard
19 layout.
21 As far as I know it is impossible to do with the current
22 X config and/or xfce4 keyboard layout switch plugin.
24 So, my original post at vim_use mailing list was as follows:
26 > I do use a "blind typing" in the sense that
27 > I do not look into the monitor when I type,
28 > only to the keyboard. I get used to this style
29 > yet about 25 years ago trying to save my eyes
30 > from the ray monitors of that days.
31 >
32 > Usually, I type a whole sentence without looking
33 > into the monitor.
34 >
35 > It does not mean that I do not know my keyboard layout.
36 > I do know it and can type in a complete darkness
37 > (but much more slowly, of course).
38 >
39 > My hands move over the keyboard almost automatically
40 > but I still need a little feedback from my eyes to not
41 > hit "i" instead of "o" for example.
42 >
43 > In this connection I have only one inconvenience
44 > connected with the facts that
45 > 1) I usually have to use 3 keyboard layouts at
46 > the same time switching between them with a hot key,
47 > 2) it is impossible to have a "direct hot key switch"
48 > to a certain keyboard layout in Linux world.
49 >
50 > Because of that I have to remember all the time not only
51 > in which vim mode I am but also in which keyboard layout
52 > I am and it is too much for me. As the result, I too often
53 > end up raising my eyes to the monitor and finding out that
54 > I have typed the whole sentence in incorrect keybord layout. :(
55 >
56 > In such times I very much miss the good old MS DOS keyrus
57 > driver that could have been configured to produce a pleasant
58 > "crimping" noise when typing in a Cyrillic keyboard layout
59 > and nothing when typing in Latin keyboard layout, for example.
60 >
61 > But the "direct hot key switch" could also help a lot in this
62 > situation. Unfortunately, as far as I know, it is impossible
63 > in the Linux World.
64 >
65 > P.S. By a "direct hot key switch" I mean the hot key that
66 > switches directly to a certain keyboard layout, not by
67 > circling through all the active ones.
68 >
69 > However, such a "direct hot key switch" is possible in Windows.
71 I was encoraged to ask this question by the post of Nikolay Pavlov
72 who wrote:
74 > I would suggest to ask this on AFAIK you cannot
75 > do this directly with X server configuration, but there are a number
76 > of “external” keyboard switchers which may have the needed capabilities.
77 > The other variant is a console app like setxkbmap or xkb-switch used
78 > in conjunction with global shortcuts capabilities provided by your
79 > DE/WM (if no, there still are apps which provide global shortcuts
80 > using X server own capabilities).
82 One of the most valuable suggestions were provided by Erik Christiansen.
83 Below, I provide them after the ">" with my comments intermitted.
85 > It is very risky to say that anything is impossible in linux;
87 Ok, next to impossible. ;)
89 > it usually turns out that there are at least three ways to do what
90 > one at first thinks impossible. My first reaction to your problem was
91 > to suggest several files to switch to ~/.Xmodmap, and then find out
92 > if a SIGHUP to X would make it re-read its config.
94 And what if not?
96 I may try this solution but I still have to google how to send
97 a SIGNUP signal to X and, moreover, to find out how to send it
98 in a quick and convenient way. Otherwise this way will not be
99 a solution at all.
101 Moreover, even before trying it, I suspect that this way of
102 achieving a "direct hot key keyboard switch" will cause X to
103 re-read its configuration from a file on a disk that can take
104 a noticeable time, which is not desired.
106 The true solution to this should be to keep all the needed
107 keyboard layouts in memory and only change the pointer to
108 the corresponding memory locations by a corresponding hot key.
110 I believe that such a solution should be provided in the X configuration
111 and realized in the corresponding window manager plugin but, as far as I know,
112 it is not. That is why I wrote that it is impossible in Linux (unless you
113 can re-write X, of course :).
115 > Much easier, by appearances, is Tony's suggestion. A quick look at
116 > ":h keymap", leading to ":h mbyte-keymap", looks very promising, not
117 > least since there are many ready-to-use mappings:
118 >
119 > $ locate -r 'keymap.*vim' | wc -l
120 > 130
121 >
122 > That, though, only maps in Vim, and only during text insertion.
123 > (which may be just what you want)
125 Yes, you are right, this workaround can be what I actually need.
126 Moreover, I have used a similar workaround when I used emacs about 15 years ago.
128 However, in ":h mbyte-keymap" is written that this workaround would interfere
129 with using "commands that take a single character argument, like f and r" what
130 is definitely a drawback.
132 Moreover, as far as I understand, in this workaround the keymap tables are
133 read anew from disk every time you hit <C-^>, so it, again, can take a noticeable
134 time, what is not good.
136 Otherwise, this suggestion looks interesting and I will try it a bit later.
138 > If cross-application mapping is desired, though, then an alternative to
139 > ~/.Xmodmap is to just execute (several of) something like:
140 >
141 > $ xmodmap -e 'keycode 91 = 0x2c' # Change numeric pad '.' to ','
142 >
143 > in a shell script, after using xev to elucidate the keycode and keysim of
144 > all the keys you want to remap.
145 >
146 > For me, this reverts the above mapping:
147 >
148 > $ xmodmap -e 'keycode 91 = 0x2e' # Change numeric pad ',' to '.'
150 Thank you for pointing me to the xmodmap and xev utilities. I will consider
151 this solution as well but it would lead to execution of a long remapping script
152 that again should take a noticeable time comparing with just changing a pointer
153 to the corresponding keymap table in memory.