2

I have two different keyboard layouts and I switch between them with Ctrl+Shift. And I want to display my current layout with i3blocks. Now I have a super small single-line script that returns current layout with the following command:

xkb-switch

But how can I update information when switching between keyboards? What I've tried:

Attempt #1

I could successfully update information by setting in i3blocks.conf:

[language]
interval=1

... which forces my blocks to run the script every millisecond. It works ok but I'm really not sure it's the proper way to do that, particularly on the laptop.

Attempt #2

I also tried to send a signal to the block when pressing Ctrl+Shift with something like this in my i3/config:

bindsym --release Control+Shift exec --no-startup-id pkill -RTMIN+8 i3blocks

And with the following lines in i3blocks.conf:

[language]
interval=once
signal=8

But I couldn't make it work. If I change Control+Shift keys to any other key (for example $mod+Shift+z or CapsLock or Control+1) it works ok. (I mean, it sends a signal and updates blocks. If I switch keyboard with Ctrl+Shift and then press Mod+Shift+z or CapsLock or Ctrl+1 it will send a signal, update i3blocks and the language block will change).

Other

I saw this post. It's also about switching the layouts. But I couldn't relate this to my problem. I'm not the best bash-programmer and don't understand what's going on in this kbdd-script. As far as I understand there's nothing about my problem.

  • Okay, I've asked another question here. – Neilana May 5 '17 at 17:14
1

Good guy on reddit helped me to solve the problem. I'll just copy-paste his answer here. The crucial command:

xkb-switch -W

With the following lines in i3blocks.conf everything works like a dream.

# AUR package: xkb-switch-git
[keymap]
label=⌨
command=xkb-switch -W
#or
#command=bash -c 'xkb-switch;xkb-switch -W'
interval=persist
border=#0d5eaf
0

I've seen your question here and if you are indeed using i3 I'm pretty sure you can edit the keymap of CTRL+SHIFT (the keymap is in the i3 config file too ~/.config/i3/config) to run a script of yours instead, script that changes the layout AND notifies the bar.

  • As I described above I tried to map my keys with bindsym in the config file. It works with other keys but it doesn't work with Ctrl+Shift. Maybe there's something special about Ctrl+Shift? – Neilana May 5 '17 at 16:09
  • I think the problem might be because CTRL and SHIFT are both dead keys. And i3 might be having trouble picking up a dead-keys only combination. I have two keyboard layouts too, and I use the windows default keybinding Super + Space – Samuel H. May 5 '17 at 19:10
  • Yes, you're right! On my other question is a clear the explanation why. – Neilana May 5 '17 at 20:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.