使用 i3 切换键盘布局

Nia*_*ais 7 keyboard ibus 16.04

我在 Ubuntu 16.04 上安装了新的 i3 版本 4.11(2015 年 9 月 30 日,分支“4.11”)。实际上,例如en,我需要使用 3 种不同的键盘布局,fr并且ru可以使用一些键盘快捷键在它们之间进行切换。

我尝试了一些方法,但都不是完全令人满意的:

  • 使用ibus-daemon几乎有效,但我无法使用任何快捷方式来更改布局。
  • setxkbmap当我开始时,我的实际设置正在配置i3

    exec --no-startup-id "setxkbmap -model pc105 -layout fr,us,ru -option grp:alt_shift_toggle"
    
    Run Code Online (Sandbox Code Playgroud)

所以我可以在我的布局之间切换,但有时我不知道我实际使用的是哪个布局,因为在这个设置中没有任何托盘图标。

总之,我的需求是:

  • 可以通过按一些热键来切换布局。

  • 我实际使用的布局的一些指示(最好是托盘图标)。

有什么解决办法吗?或者也许有一些 i3 插件实际上可以完成这项工作?第三方软件?

小智 8

你可以用xkblayout-statei3blocks

对于xkblayout-state

我假设你有git

~$ git clone https://github.com/nonpop/xkblayout-state.git
~$ cd xkblayout-state
~$ make
Run Code Online (Sandbox Code Playgroud)

现在复制编译xkblayout-state在你的某处PATH,例如:

~$ `cp xkblayout-state /usr/local/bin/`
Run Code Online (Sandbox Code Playgroud)

现在为i3blocks

sudo apt-get install i3blocks
cp /etc/i3blocks.conf ~/.i3blocks.conf
Run Code Online (Sandbox Code Playgroud)

在您的i3配置文件 (~/.config/i3/config) 中替换i3statusi3blocks

# Start i3bar to display a workspace bar (plus the system information i3status
# finds out, if available)
bar {
        status_command i3blocks
        tray_output primary                                               
}
# in case of layout change event - send signal to i3blocks
bindsym ISO_Next_Group exec pkill -RTMIN+1 i3blocks
Run Code Online (Sandbox Code Playgroud)

并重新启动i3wm(mod+shift+R),您现在应该看到i3blocks出现了。

打开~/.i3blocks.conf并添加某处(例如,在 [VOLUME] 部分的正上方):

#Language indicator
[language]
#label=LNG
command=xkblayout-state print %s | awk '{print toupper($0)}'
interval=once
signal=1
Run Code Online (Sandbox Code Playgroud)

再次,重新启动 i3wm (mod+shift+R),您应该会在状态栏中看到您的语言环境,正在切换。

检查一下 xkblayout-state --help,不同的输出有很多选项。