kwin occasionally hangs, which looks like the system not responding to mouse clicks or key presses - although the mouse pointer still moves when you move the mouse!
As described in the official Kwin documentation, a good way to go would be to try this either on a running terminal application or on a virtual console (i.e.: Ctrl+Alt+F1), :
DISPLAY=:0 kwin --replace
Similar to Robin Green's answer, but this does not require a terminal window to be open already. Instead, specify the display in which to start kwin from tty1. Hence,
Press Ctrl+Alt+F1 to access a terminal. Log in.
killall kwin. Then, type in
Press Ctrl+Alt+F7 to change back to your primary display.
This actually works. It is a nasty bug but at least I can recover now.
In my case, there is no need to go back to the console login using ctrl+alt+f2 but using alt+f2 I can simply type
killall plasma-desktop plasma-desktop and then using alt+f2 again,
I can run
plasma-desktop. Could also be used in a script of course. This way I get back my mouse and I will not lose any work.
In later Kubuntu/Plasma 5
kwin still hangs/crashes (especially with Intel display drivers it seems), but can be more easily restarted: just run in
krunner - Alt-Space, or Alt-F2:
Or, create a new custom shortcut for that: e.g. Trigger: Meta+K, Action, Command/URL:
In this way
kwin can be restarted with just the Meta-K shortcut.