• Stars
    star
    353
  • Rank 120,322 (Top 3 %)
  • Language
    C++
  • License
    MIT License
  • Created about 14 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Switch your X keyboard layouts from the command line

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

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:

$ 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.

$ ../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:

$ 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

$ sudo ldconfig

Usage

$ xkb-switch --help

Usage: xkb-switch -s ARG            Sets current layout group to ARG
       xkb-switch -l|--list         Displays all layout groups
       xkb-switch -h|--help         Displays this message
       xkb-switch -v|--version      Shows version number
       xkb-switch -w|--wait [-p]    Waits for group change and exits
       xkb-switch -W                Infinitely waits for group change
       xkb-switch -n|--next         Switch to the next layout group
       xkb-switch [-p]              Displays current layout group

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:

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:

$ 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:

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.

More Repositories

1

asterisk-dongle-setup

Playground project aimed at setting up Asterisk server and the GSM stack on Nix.
Nix
30
star
2

awesomerc-ierton

ierton's awesome config
Lua
24
star
3

mobile-nixos-cfg

A personal MobileNixos adventure
Shell
21
star
4

htvm

Haskell experiments involving TVM AI framework
Haskell
21
star
5

cake3

Makefile DSL
Haskell
12
star
6

nixtvm

Python
11
star
7

udprelay

Symmetrical UDP relay
C
10
star
8

vsim

VHDL simulator in Haskell
VHDL
9
star
9

oilprice

urweb application
Makefile
6
star
10

urweb-build

Build system for Ur/Web projects, written in Nix expression language
Nix
5
star
11

uru3

UrWeb
4
star
12

rl

Refactored rl-examples
Haskell
4
star
13

urweb-prelude

Collection of basic combinators for Ur/Web, inspired by Haskell's Prelude library
UrWeb
4
star
14

urweb-callback

urweb: run serve-side processes asynchronously
C++
4
star
15

git-powercommit

Commit all the changes to your git submodules tree using a single command.
Shell
4
star
16

urweb-monad-pack

UrWeb
3
star
17

urweb-monad-state

MonadState implementation in Ur/Web
Haskell
2
star
18

nixos-ssh-over-tls

NixOS module which hides both HTTP and SSH daemons behind SSL proxy on the same port
Nix
2
star
19

litrepl

LitREPL is a command-line tool and a Vim plugin for code snippet evaluation
Python
2
star
20

urxml

XML parser and indenter supporting Ur/Web's dialect. VIM-friendly.
Haskell
1
star
21

xscreensaver-run

Run the screensaver from XScreenSaver collection synchronousely in the fullscreen
C
1
star
22

topics

Nix
1
star
23

rm2env

reMarkable2 Nix environment
Shell
1
star
24

urweb-homepage

UrWeb
1
star
25

brick

brick game in Ur/Web
Haskell
1
star
26

urweb-utf8

Basic UTF8 library for Ur/Web
Makefile
1
star
27

urembed

Ur/Web module generator: embed custom file or JavaScript code into your Ur/Web application
Haskell
1
star
28

ml-sb

ML sandbox (a toy language project)
Haskell
1
star
29

vim-markdown-indent

Vim markdown indentation plugin
Vim Script
1
star
30

aicli

A basic command-line interface for interacting with gpt4all ai runner using GNU Readline.
Python
1
star