diff --git a/src/screen.c b/src/screen.c
index fc7c6085deb33b543b9a272f960860f81c619f40..3cdc7cbb7a5330443299f06ebd6095801a82498d 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -108,6 +108,7 @@ myScreenSetWMAtom (ScreenInfo *screen_info, gboolean replace_wm)
         gdk_error_trap_push ();
         attrs.event_mask = StructureNotifyMask;
         XChangeWindowAttributes (display_info->dpy, current_wm, CWEventMask, &attrs);
+        gdk_flush ();
         if (gdk_error_trap_pop ())
         {
             current_wm = None;