In the case of a keyboard grab, you can just switch to a virtual terminal
and kill the offending program (all toolkits popups use grabs so program
freezing with menu open e.g. to network timeout is pretty bad). That
releases the client's pointer/keyboard/server grab.
This helps only to grabs though, if X itself freezes, you cannot do the VT
switch as similarly to other FB apps, X would need to ACK the VT-switch
(at least until kernel can do the mode switches & palette save/restore on
VT switches by itself). Then you need to use the kernel SysRq key to kill
the whole X.