Fix some logic errors in the native window handling