You are not logged in.
I have a problem because I am switching between 3 keyboard layouts often: english, russian and serbian. The first is latin, others are cyrillic. Russian and serbian share a lot of characters, but are permuted. The problem arises when I try to use keyboard shortcuts in many applications. Many applications accept only latin shortcuts, so if I switch to Russian keyboard, then Ctrl+C for copying (for example) doesn't work anymore. My idea was to remap the combination Ctrl+(keycode for A) to the other key combination Ctrl+(keysym for A). I tried using many tools: xbindkeys, xdotool, xvkbd, autokey, but none worked. Only xbindkeys+xvkbd worked, but only for nano editor. I can't find solutions for zathura or geany or LyX, programs that I plan to use very often. I am switching keyboards using setxkbmap. Is there a way to actually accomplish this, or perhaps create a custom layout where single keys will behave like from Russian normal layout, but combinations Ctrl+ and Alt+ will behave like on the English layout?
Last edited by donaastor (2022-03-24 23:30:34)
Offline
a custom layout where single keys will behave like from Russian normal layout, but combinations Ctrl+ and Alt+ will behave like on the English layout?
ctrl/alt are modifiers, you cannot depend the layout on them (unlike shift/altgr, the latter being the 3rd level shift)
Only xbindkeys+xvkbd worked, but only for nano editormy terminal emulator. I can't find solutions for zathura or geany or LyX, programs that I plan to use very often.
ftfy
-xsendevent
Make xvkbd to use XSendEvent() to simulate keyboard events, as it was in xvkbd version 1.0. xvkbd version 1.1 and later will try to use XTEST extension instead in the default configuration. Because it is not unusual applications to ignore keyboard events generated with -xsendevent, you shouldn't use -xsendevent option unless it is really required.
export GTK_IM_MODULE=xim
export GDK_CORE_DEVICE_EVENTS=1might help w/ gtk clients, but cause other side effects.
xtest then runs you into the pitfall of ending up w/ cyclic shortcuts - eg. if you wanted to bind shortcuts to xdotool, you'd have to ungrab the relevant combo in the shortcut daemon first.
And nano only seems to support ASCII shortcuts, https://man.archlinux.org/man/core/nano/nanorc.5.en
So let's go straight back to
I am switching keyboards using setxkbmap.
WHY?
This is absolutely no smart choice - everytime you run "setxkbmap -layout something" it'll reconfigure the keyboard.
That's not only slow af but will also reset the autorepeat settings, kill xmodmap augmentations and whatnot else. It might also impact the behavior of your shortcut daemon (in various ways, depending on whether it catches that event and re-grabs the codepoints)
I'll point out that several WMs allow layouts to be window specific (ie. when activating nano, switch to the us layout) and you can probably hack that into most others.
eg. "xdotool key ISO_First_Group ISO_Next_Group" should™ move to the second group.
Offline
@seth Hi seth
Looks like nobody else cares to talk to me lol. Thank you for consistently replying. I would really like to see a solution for this, but it looks like I have to create one myself... You seem to know a lot, so I will have to take time to learn about "input methods" and "shortcut daemons" because I've never heard of them before.
From what you said, I would have to use some outer tool like xkb-switch, instead of setxkbmap, to set layouts, right? It uses XkbLockGroup() method to set keyboards. Does that sound good to you?
For now, I can only answer your "Why?" question so you would better unserstand me. I am familiar with programming, so I felt confident making these scripts. I am using i3-wm with i3bar and i3status. i3bar refreshes every second and it is not showing the keyboard layout by default, so I had to implement it myself, so that the keyboard layout gets changed right after I changed it, but other info gets refreshed only every second, not when I change the keyboard. So I made these 2 scripts:
~/.config/i3/status_script.sh:
#!/bin/sh
# shell script to prepend i3status with more stuff
if [[ ! -p "/tmp/i3statusP" ]]; then
mkfifo "/tmp/i3statusP"
fi
i3status --config /home/***/.config/i3/i3status > /tmp/i3statusP &
cpref="[{\"name\":\"keyboard layout\",\"markup\":\"none\",\"full_text\":\""
(while :
do
read line
lo=$(xkblayout-state print %s/%v)
lol=${#lo}-1
if [ ${lo:$lol} = "/" ]; then
lo=${lo:0:$lol}
fi
if [ "$line" == "U" ]; then
echo $pref$cpref$lo$"\"},"$postf
else
poc=${line:0:2}
if [ "$poc" == "[{" ]; then
pref=""
postf="${line:1}"
echo $pref$cpref$lo$"\"},"$postf
elif [ "$poc" == ",[" ]; then
pref=","
postf="${line:2}"
echo $pref$cpref$lo$"\"},"$postf
else
echo $line
fi
fi
done) < /tmp/i3statusPand I am calling it from i3 with:
...
bar {
status_command /bin/sh /home/***/.config/i3/status_script.sh
}And then I had to trigger this script somehow when changing keyboard layouts. So initially, I wanted to bind it to Alt+Shift but it was not possible. So I made new shortcuts: Alt+0,Alt+1,Alt+2,Alt+3 to change between the keyboard layouts I use. I made this xbindkeys config:
~/.xbindkeysrc:
"setxkbmap us; echo U > /tmp/i3statusP"
Alt+F9
"setxkbmap ru; echo U > /tmp/i3statusP"
Alt+F10
"setxkbmap -layout rs -variant latin; echo U > /tmp/i3statusP"
Alt+F11
"setxkbmap -layout rs -variant yz; echo U > /tmp/i3statusP"
Alt+F12
"setxkbmap us; echo U > /tmp/i3statusP"
Alt+KP_Insert
"setxkbmap ru; echo U > /tmp/i3statusP"
Alt+KP_End
"setxkbmap -layout rs -variant latin; echo U > /tmp/i3statusP"
Alt+KP_Down
"setxkbmap -layout rs -variant yz; echo U > /tmp/i3statusP"
Alt+KP_NextLast edited by donaastor (2022-03-21 15:16:24)
Offline
I would have to use some outer tool like xkb-switch … It uses XkbLockGroup() … using i3-wm with i3bar and i3status
https://github.com/zebradil/xkb-switch-i3 ?
xkb-switch [-p] Displays current layout group
Offline
@seth Yeah, I saw that package, thanks, but I already had my script so I didn't want to experiment again... so I just swapped in the xkb-switch... "If it works, don't touch it"
Btw, do you believe it is realistic to achieve what I want to achieve regarding my shortcuts? Would you root for me? Or would you give up on my efforts?
Also, I am ready to do some programming and make my own package. Where would I need to start looking in order to learn the needed APIs, do you know? Also, for debugging, how would I track what kind of signals my programs catch and process (speaking of key presses).
I know I ask a lot, but just some basic guidance, some keywords and concepts (like you mentioned input methods) would be very helpful.
Last edited by donaastor (2022-03-21 16:27:32)
Offline
If you want Ы to be Ы but ctrl+Ы to fire ctrl+s you'll need some shortcut daemon and it has to be very specific in that it grabs ctrl+Ы but ungrabs the (any) combination before faking ctrl+s
You can look up any existing shortcut daemon as well as https://tronche.com/gui/x/xlib/input/XGrabKey.html
Modifier list is in https://tronche.com/gui/x/xlib/events/k … inter.html
XTest input faking would be XTestFakeKeyEvent and https://man.archlinux.org/man/extra/lib … Event.3.en
Offline
@seth Thank you very much! I will look into that and post later what I did at the end.
Offline
I found the solution...
Everything works just fine, all I had to do is set up the layouts with
localectl --no-convert set-x11-keymap us,ru,rs,rs pc105 ,,latin,yzand then switch between them using
xkb-switch -s ru(you would need the xkb-switch package)
DO NOT use
setxkbmapto switch between keyboards!
By the way, during my unsuccessful attempts to fight this problem that wasn't really a problem, I made a cli cleanup version of xvkbd package:
https://github.com/donaastor/xvkbd-cli
The original package contains a GUI keyboard that won't launch if you use it with any other flags in terminal, but will still produce an error about missing fonts (if you actually miss them). So I made a "debloated" kinda version of it.
Offline