Repository: tauri-apps/tauri
File: core/tauri-runtime-wry/src/lib.rs (Rust)

Code before:
        let monitor_size = m.size();

        let window_position = window_position.to_logical(m.scale_factor());

        monitor_pos.x <= window_position.x
          && window_position.x <= monitor_pos.x + monitor_size.width as i32
          && monitor_pos.y <= window_position.y
          && window_position.y <= monitor_pos.y + monitor_size.height as i32
      })
    } else {
      event_loop.primary_monitor()
    };

    if let Some(monitor) = monitor {
      let desired_size = window_builder
        .inner
        .window
        .inner_size
        .unwrap_or_else(|| TaoPhysicalSize::new(800, 600).into());
      let window_size = window_builder
        .inner
        .window
        .inner_size_constraints
        .clamp(desired_size, monitor.scale_factor())
        .to_logical::<i32>(monitor.scale_factor());
      let scale_factor = monitor.scale_factor();
      let screen_size = monitor.size().to_logical::<i32>(scale_factor);
      let monitor_pos = monitor.position().to_logical::<i32>(scale_factor);
      let x = (screen_size.width as i32 - window_size.width) / 2 + monitor_pos.x;
      let y = (screen_size.height as i32 - window_size.height) / 2 + monitor_pos.y;

      window_builder = window_builder.position(x as f64, y as f64);
    }
  }

  let window = window_builder.inner.build(event_loop).unwrap();

  #[cfg(feature = "tracing")]
  {
    drop(window_create_span);

    context
      .main_thread
      .active_tracing_spans
      .0
      .borrow_mut()
      .push(ActiveTracingSpan::WindowDraw {
        id: window.id(),
        span: window_draw_span,
      });
  }

Review comment (suggestion):
scale_factor is also used in `desired_size` and `window_size` variables above, let's move these variables above them and use it there

Code after:
        let monitor_size = m.size();

        let window_position = window_position.to_logical(m.scale_factor());

        monitor_pos.x <= window_position.x
          && window_position.x <= monitor_pos.x + monitor_size.width as i32
          && monitor_pos.y <= window_position.y
          && window_position.y <= monitor_pos.y + monitor_size.height as i32
      })
    } else {
      event_loop.primary_monitor()
    };

    if let Some(monitor) = monitor {
      let desired_size = window_builder
        .inner
        .window
        .inner_size
        .unwrap_or_else(|| TaoPhysicalSize::new(800, 600).into());
      let scale_factor = monitor.scale_factor();
      let window_size = window_builder
        .inner
        .window
        .inner_size_constraints
        .clamp(desired_size, scale_factor)
        .to_logical::<i32>(scale_factor);
      let screen_size = monitor.size().to_logical::<i32>(scale_factor);
      let monitor_pos = monitor.position().to_logical::<i32>(scale_factor);
      let x = (screen_size.width - window_size.width) / 2 + monitor_pos.x;
      let y = (screen_size.height - window_size.height) / 2 + monitor_pos.y;

      window_builder = window_builder.position(x as f64, y as f64);
    }
  }

  let window = window_builder.inner.build(event_loop).unwrap();

  #[cfg(feature = "tracing")]
  {
    drop(window_create_span);

    context
      .main_thread
      .active_tracing_spans
      .0
      .borrow_mut()
      .push(ActiveTracingSpan::WindowDraw {
        id: window.id(),
        span: window_draw_span,
      });
  }