Just revisiting this, I found that it very much reduced the chances of this happening if I didn't have any overlap and in fact left a little but of a gab between the windows (even a single pixel seemed to help). I also find it happens more often if I quickly go to a window and right click to loot/talk to npc. So if I just slow down a little and give it a sec to "catch its breath" before I right-click it very rarely happens.

In terms of fixing it when it does, I found that PiP seems to magically let it get fixed. For whatever reason if I hit the PiP key for the window that is borked, it will let the mouse into the window again although it thinks I have the right button held down. So a quick click of the right button again and it is all fixed.

Hope this helps,

Mark.