Fixes X11 threading issue, under Linux

Haven't tested on windows, so it should probably be tested before it's merged.