Use XSync instead of XFlush for the initial capture to give the X server a round-trip to process the map. Remove the deferred timer re-capture which could crash if the icon was destroyed before firing.