Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/platform/win/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,10 +646,7 @@ impl WindowHandle {
pub fn create_window(init: WindowInitializer) -> Result<WindowHandle> {
let extended_user_32 = ExtendedUser32::load()?;

let window_size = init.settings.size.to_physical(1.0);

let shared_state =
WindowSharedState::new(window_size, extended_user_32, init.settings.parent.is_some());
let shared_state = WindowSharedState::new(extended_user_32, &init.settings);

if init.settings.parented && init.settings.parent.is_none() {
return Ok(WindowHandle {
Expand Down
12 changes: 5 additions & 7 deletions src/platform/win/window_state.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::platform::win::keyboard::KeyboardState;
use crate::platform::PlatformHandle;
use crate::warn;
use crate::wrappers::win32::cursor::SystemCursor;
use crate::wrappers::win32::h_instance::HInstance;
use crate::wrappers::win32::window::HWnd;
use crate::wrappers::win32::{Dpi, ExtendedUser32};
use crate::{warn, WindowSettings};
use crate::{Event, EventStatus, MouseCursor, WindowHandler, WindowSize};
use dpi::{PhysicalSize, Size};
use raw_window_handle::{DisplayHandle, Win32WindowHandle};
Expand Down Expand Up @@ -154,15 +154,13 @@ pub struct WindowSharedState {
}

impl WindowSharedState {
pub fn new(
current_size: PhysicalSize<u32>, user32: ExtendedUser32, parented: bool,
) -> Rc<Self> {
pub fn new(user32: ExtendedUser32, settings: &WindowSettings) -> Rc<Self> {
Self {
parented: parented.into(),
parented: (settings.parent.is_some() || settings.parented).into(),
is_alive: true.into(),
current_dpi: None.into(),
current_size: current_size.into(),
fallback_scale_factor: None.into(),
current_size: settings.size.to_physical(1.0).into(),
fallback_scale_factor: settings.fallback_scale_factor.into(),
resize_host_originated: false.into(),
destroy_host_originated: false.into(),
user32,
Expand Down
11 changes: 4 additions & 7 deletions src/platform/x11/window_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ impl ScalingFactor {
}
}

impl From<Option<f64>> for ScalingFactor {
fn from(value: Option<f64>) -> Self {
Self { system: value.into(), suggested: None.into() }
}
}

pub(crate) struct WindowInner {
// GlContext should be dropped **before** XcbConnection is dropped
#[cfg(feature = "opengl")]
Expand Down Expand Up @@ -123,7 +117,10 @@ impl WindowInner {
xcb_window,
visual_id: visual_info.visual_id,
window_size: physical_size.into(),
scaling_factor: scaling.into(),
scaling_factor: ScalingFactor {
system: scaling.into(),
suggested: options.fallback_scale_factor.into(),
},
mouse_cursor: MouseCursor::default().into(),
loop_signal: ev_loop.get_signal(),

Expand Down
23 changes: 23 additions & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ pub struct WindowSettings {
/// the window is shown first).
pub parented: bool,

/// A fallback scale factor, if Baseview couldn't get one from the platform.
///
/// If the platform does already provide an accurate scaling factor, this doesn't do anything.
///
/// If the given fallback scale factor is actually useful and different from the current one
/// (1.0 by default), this will resize and redraw the window accordingly.
///
/// # Platform compatibility notes.
///
/// On Win32, this value is used if running on early versions of Windows 10 (or earlier).
///
/// On X11, this value is used if no `Xft.dpi`setting is set.
///
/// On macOS, this function is always a no-op.
pub fallback_scale_factor: Option<f64>,

/// If provided, then an OpenGL context will be created for this window. You'll be able to
/// access this context through [crate::WindowContext::gl_context].
///
Expand Down Expand Up @@ -65,6 +81,12 @@ impl WindowSettings {
self
}

#[inline]
pub fn with_fallback_scale_factor(mut self, scale_factor: impl Into<Option<f64>>) -> Self {
self.fallback_scale_factor = scale_factor.into();
self
}

#[cfg(feature = "opengl")]
#[inline]
pub fn with_gl_config(mut self, gl_config: impl Into<Option<GlConfig>>) -> Self {
Expand All @@ -80,6 +102,7 @@ impl Default for WindowSettings {
size: LogicalSize { width: 500.0, height: 400.0 }.into(),
parent: None,
parented: false,
fallback_scale_factor: None,
#[cfg(feature = "opengl")]
gl_config: None,
}
Expand Down