Plasma has this terrific feature, that is not that often mentioned, but comparing to that other OS it provides far better everyday experience. Plasma allows you to set specific language layout on dedicated virtual desktop. Thus, layout changes affect windows only on current VD, but also, when different layout is needed one can simply switch to that VD or put desired window on it.
The problem arises on reboot when all customization is lost. That’s why I wanted to share this nifty script. It needs to run on login and is meant as workaround until some of the good people from KDE implement it in settings.
Addendum: I tried to use declarative and PyQt script but failed to call arguments to QDBusInterface, AFAIK due to old dbus bug.
#!/usr/bin/env bash
# This script need to run on startup. It will set language layout on desired virtual desktop when user change to it.
# First user need to define virtual desktops by finding it's ID with command below.
# Then modify the `case` condition, provide integer of desired language layout, and modify test statement.
# To get desktops IDs use:
# qdbus --user --literal -- org.kde.KWin /VirtualDesktopManager org.kde.KWin.VirtualDesktopManager.desktops
desktop3_ID='c3c063fd-e468-40d9-ac7d-30d383fd76ef'
desktop4_ID='7452b9ae-8291-4e9f-af47-69e8a400a960'
# Desktop layouts start from 0 for default layout
while read -r line; do
case $line in
*$desktop3_ID*)
qdbus --user -- org.kde.keyboard /Layouts org.kde.KeyboardLayouts.setLayout 1
desktop3_set='true'
;;
*$desktop4_ID*)
qdbus --user -- org.kde.keyboard /Layouts org.kde.KeyboardLayouts.setLayout 2
desktop4_set='true'
;;
esac
[[ -v 'desktop3_set' && -v 'desktop4_set' ]] && exit
done < <(dbus-monitor "sender='org.kde.KWin',path='/VirtualDesktopManager',member='currentChanged'")