Fix a9e845 and 797755 Allow X*IfEvent() to reenter libX11

a9e84580 tried to fix 79775575 but introduced a condition where another thread could increase in_ifevent before waiting for the other thread to unlock the display and also prevented other threads from locking / unlocking the display. This commit tries to implement 79775575 with a simpler approach which hopefully fixes all issues mentioned in #168 (closed).
Note that I only tested this with firefox on my personal machine and it should be made sure that this still fixes the original problems described in !150 (merged).

Edited by GaryOderNichts

Merge request reports