Skip to content

Instantly share code, notes, and snippets.

@Hammer2900
Forked from sintezoid/sway-python-kbdd.py
Created August 25, 2021 10:13
Show Gist options
  • Save Hammer2900/bfc1c0ecf63659ff1aa74a6117f3cf5f to your computer and use it in GitHub Desktop.
Save Hammer2900/bfc1c0ecf63659ff1aa74a6117f3cf5f to your computer and use it in GitHub Desktop.
#Принудительно меняем раскладу для Konsole и kitty
#Для телеграм меняем на Русский
#Для всего остального меняю на английский
from i3ipc import Connection, Event
import subprocess,os
# Create the Connection object that can be used to send commands and subscribe
# to events.
i3 = Connection()
# Print the name of the focused window
def on_window_focus(i3, e):
focused = i3.get_tree().find_focused()
if focused.app_id == "kitty" or focused.app_id == "org.kde.konsole":
os.system("swaymsg input \* xkb_switch_layout 0")
elif focused.app_id == "telegramdesktop":
os.system("swaymsg input \* xkb_switch_layout 1")
#В телеграм я обычно пишу на русском, поэтому переключаем принудительно.
else:
os.system("swaymsg input \* xkb_switch_layout 0")
#Если необходимо закостылить еще что-то, то ищем app_id приложения
#print("app_id", focused.app_id)
# Subscribe to events
i3.on(Event.WINDOW_FOCUS, on_window_focus)
# Start the main loop and wait for events to come in.
i3.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment