I already fix it by adding this line inside "xdnd_event_loop" function.
# THIS IS CRUCIAL:
win.change_attributes(event_mask=X.PropertyChangeMask | X.StructureNotifyMask | X.SubstructureNotifyMask)
d.flush()
while True:
while d.pending_events():