Counter-intuitively my usual go-to is to SSH in from another device (phone, tablet, another computer). 95% of the time when the UI is locked up the ssh daemon is still responsive.
Note: I also do this on macOS but it’s much less useful since there are very few commands to actually restore a session that’s locked up.