Fix #10375: reorder window operations in event handling

rebases #828