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