Skip to content

Instantly share code, notes, and snippets.

@Difrex
Created March 10, 2019 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Difrex/3e298544169f75fc92d4e5692a0ab2ed to your computer and use it in GitHub Desktop.
Save Difrex/3e298544169f75fc92d4e5692a0ab2ed to your computer and use it in GitHub Desktop.

Get the current keyboard layout in the Sway

key_layout.py

#!/usr/bin/python

import json
import os


def get_inputs():
    return json.loads(os.popen("swaymsg -t get_inputs").read())


def get_current_layout():
    inputs = get_inputs()
    for inp in inputs:
        if inp.get("identifier", None) == "1:1:AT_Translated_Set_2_keyboard":
            if inp.get("xkb_active_layout_name", None) == "Russian":
                return "Ru"
    return "En"


if __name__ == "__main__":
    print(get_current_layout())

i3blocks.conf

[key_layout]
label=
interval=1
command=~/.config/i3/key_layout.py
separator=true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment