Fix #10375: reorder window operations in event handling