Well, it just happened again, and I realised that the past two times it has happened has always been when <alt>-tabbing. So I decided to restart kwin and, sure enough, everything works. That's the problem.