The swaykbdd utility can be used to automatically change the keyboard layout on a per-window basis.
https://github.com/artemsen/swaykbdd