百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
X

xkb-switch

> 编程语言
开源

从命令行切换 X 键盘布局

388 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

从命令行切换 X 键盘布局

XKB-SWITCH

by Jay Bromley, Sergei Mironov, Alexei Rad'kov

xkb-switch is a C++ program that allows to query and change the XKB layout state. Originally ruby-based code written by Jay Bromley.

  • XKeyboard.cpp Implementation for XKB query/set class
  • XKbSwitch.cpp Main program
  • XKbSwitchApi.cpp The Vim API bindings

The C++ class has no special dependencies on anything outside of X-related libraries, so it can be easily used with other software.

Older versions of Xkb-switch were licensed under the GNU GPLv3, the current version is licensed under the MIT license. See COPYING for details.

  • Installing
  • Usage
  • VIM integration
  • Layout groups
  • Bugs or Problems
  • Licensing notice

Installing

Package libxkbfile-dev (or libxkbfile-devel for Fedora) needs to be installed to build the program.

To build the program manually, unpack the tarball and cd to source directory. Nix users may use nix-shell to enter the minimally sufficient development shell or nix-build to build the sources. Other distributions typically require the following commands to build and install the program:

bash
$ mkdir build && cd build
$ cmake ..
$ make

Optionally, test the basic functions by running ./test.sh script. The script should print OK in the last line and return exit code of zero.

bash
$ ../test.sh 2>&1 | tee test.log
$ tail -n 1 test.log | grep OK || echo "Test failed!"

In order to do a system-wide install, use your system's package manager or default to the following:

bash
$ sudo make install                    # System-wide installation
$ make DESTDIR=$HOME/.local install    # User installation

On some distributions, you may need to update the program cache if it's the first time you're installing this program

bash
$ sudo ldconfig

Usage

…

A note on xkb-switch -x Command line option xkb-switch -x has been removed recently. Please, use setxkbmap -query or setxkbmap -print to obtain debug information.

VIM integration

Xkb-switch goes with a library libxkbswitch.so which can be called from within Vim scripts like this:

vim
let g:XkbSwitchLib = "/path/to/libxkbswitch.so"
echo libcall(g:XkbSwitchLib, 'Xkb_Switch_getXkbLayout', '')
call libcall(g:XkbSwitchLib, 'Xkb_Switch_setXkbLayout', 'us')

See also article in Russian describing complex solution.

Layout groups

xkb-group.sh can help you to manage layout groups. Just run it and send some input at it's stdin every time you want to trigger layouts from primary to secondary and back. For example:

bash
$ xkb-group.sh us ru
switch # switch from us to ru or from current layout to us
switch # switch from ru to us or from us to ru

# from another terminal
$ xkb-switch -s de # switch to 'de' layout, change secondary layout to 'de'

# back to terminal running `xkb-group.sh'
switch # switch from de to us
switch # switch from us to de

Bugs or Problems

Admittedly, I only tested with a few different layouts that I used. If you find any bugs let me know by submitting an issue or via [email protected].

References:

    • XKB configuration
    • How to further enhance XKB configuration
    • Old LJ post by Mitya describing minimalistic X11 kb test application

Licensing notice

In response to the request I decided to re-license the project under the more permissive MIT license. Older versions of the software remain under the GPL license we used previously. This StackExchange question includes some information regarding this kind of situations. I included the top-3 contributors into the MIT license text. Please contact me either directly or via the mentioned Github issue if you have any questions or suggestions regarding this decision.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C++

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言