Skip to content

On Windows, Window size is set incorrectly on HiDPI displays #923

@Osspial

Description

@Osspial

On Windows 10, this can be replicated by setting the scaling ratio greater than 100% in Display settings and running the following example:

extern crate winit;
use winit::window::WindowBuilder;
use winit::event::{Event, WindowEvent};
use winit::event_loop::{EventLoop, ControlFlow};

fn main() {
    let event_loop = EventLoop::new();

    let window = WindowBuilder::new()
        .with_title("A fantastic window!")
        .with_inner_size(winit::dpi::LogicalSize::new(128.0, 128.0))
        .build(&event_loop)
        .unwrap();
    println!("{:?}", window.inner_size());

    event_loop.run(|event, _, control_flow| {
        match event {
            Event::WindowEvent {
                event: WindowEvent::CloseRequested,
                ..
            } => *control_flow = ControlFlow::Exit,
            _ => *control_flow = ControlFlow::Wait,
        }
    });
}

With 150% scaling, the window gets created with a size of LogicalSize { width: 124.0, height: 116.66666666666667 }, instead of the expected LogicalSize { width: 128.0, height: 128.0 }.

Metadata

Metadata

Assignees

No one assigned

    Labels

    D - easyLikely easier than most tasks hereDS - win32Affects the Win32/Windows backendH - good first issueIdeal for new contributors

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions