diff --git a/ports/servoshell/desktop/app.rs b/ports/servoshell/desktop/app.rs index 528ee96ba01..d87daf3124d 100644 --- a/ports/servoshell/desktop/app.rs +++ b/ports/servoshell/desktop/app.rs @@ -249,15 +249,18 @@ impl App { // Intercept any ScaleFactorChanged events away from EguiGlow::on_window_event, so // we can use our own logic for calculating the scale factor and set egui’s // scale factor to that value manually. - let effective_scale_factor = window.hidpi_factor().get(); + let desired_scale_factor = window.hidpi_factor().get(); + let effective_egui_zoom_factor = desired_scale_factor / scale_factor as f32; + info!( - "window scale factor changed to {}, setting scale factor to {}", - scale_factor, effective_scale_factor + "window scale factor changed to {}, setting egui zoom factor to {}", + scale_factor, effective_egui_zoom_factor ); + minibrowser .context .egui_ctx - .set_pixels_per_point(effective_scale_factor); + .set_zoom_factor(effective_egui_zoom_factor); // Request a winit redraw event, so we can recomposite, update and paint // the minibrowser, and present the new frame. diff --git a/ports/servoshell/desktop/headed_window.rs b/ports/servoshell/desktop/headed_window.rs index 73be7c7602c..911e60d9caf 100644 --- a/ports/servoshell/desktop/headed_window.rs +++ b/ports/servoshell/desktop/headed_window.rs @@ -24,7 +24,7 @@ use servo::webrender_api::units::{DeviceIntPoint, DeviceIntRect, DeviceIntSize}; use servo::webrender_api::ScrollLocation; use servo::webrender_traits::RenderingContext; use surfman::{Connection, Context, Device, SurfaceType}; -use winit::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize}; +use winit::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize}; use winit::event::{ElementState, KeyEvent, MouseButton, MouseScrollDelta, TouchPhase}; use winit::keyboard::{Key as LogicalKey, ModifiersState, NamedKey}; #[cfg(any(target_os = "linux", target_os = "windows"))] @@ -57,19 +57,6 @@ pub struct Window { modifiers_state: Cell, } -#[cfg(not(target_os = "windows"))] -fn window_creation_scale_factor() -> Scale { - Scale::new(1.0) -} - -#[cfg(target_os = "windows")] -fn window_creation_scale_factor() -> Scale { - use windows_sys::Win32::Graphics::Gdi::{GetDC, GetDeviceCaps, LOGPIXELSY}; - - let ppi = unsafe { GetDeviceCaps(GetDC(std::ptr::null_mut()), LOGPIXELSY as i32) }; - Scale::new(ppi as f32 / 96.0) -} - impl Window { pub fn new( win_size: Size2D, @@ -85,15 +72,11 @@ impl Window { // #9996. let visible = opts.output_file.is_none() && !no_native_titlebar; - let win_size: DeviceIntSize = (win_size.to_f32() * window_creation_scale_factor()).to_i32(); - let width = win_size.to_untyped().width; - let height = win_size.to_untyped().height; - let window_builder = winit::window::WindowBuilder::new() .with_title("Servo".to_string()) .with_decorations(!no_native_titlebar) .with_transparent(no_native_titlebar) - .with_inner_size(PhysicalSize::new(width as f64, height as f64)) + .with_inner_size(LogicalSize::new(win_size.width, win_size.height)) .with_visible(visible); let winit_window = window_builder @@ -128,7 +111,10 @@ impl Window { .window_handle() .expect("could not get window handle from window"); let native_widget = connection - .create_native_widget_from_window_handle(window_handle, Size2D::new(width, height)) + .create_native_widget_from_window_handle( + window_handle, + inner_size.to_i32().to_untyped(), + ) .expect("Failed to create native widget"); let surface_type = SurfaceType::Widget { native_widget }; let rendering_context = RenderingContext::create(&connection, &adapter, surface_type) diff --git a/ports/servoshell/desktop/minibrowser.rs b/ports/servoshell/desktop/minibrowser.rs index ea71d8ca72c..77d0e676068 100644 --- a/ports/servoshell/desktop/minibrowser.rs +++ b/ports/servoshell/desktop/minibrowser.rs @@ -88,6 +88,13 @@ impl Minibrowser { // Adapted from https://github.com/emilk/egui/blob/9478e50d012c5138551c38cbee16b07bc1fcf283/crates/egui_glow/examples/pure_glow.rs #[allow(clippy::arc_with_non_send_sync)] let context = EguiGlow::new(events_loop.as_winit(), Arc::new(gl), None); + + // Disable the builtin egui handlers for the Ctrl+Plus, Ctrl+Minus and Ctrl+0 + // shortcuts as they don't work well with servoshell's `device-pixel-ratio` CLI argument. + context + .egui_ctx + .options_mut(|options| options.zoom_with_keyboard = false); + let widget_surface_fbo = match rendering_context.context_surface_info() { Ok(Some(info)) => NonZeroU32::new(info.framebuffer_object).map(NativeFramebuffer), Ok(None) => panic!("Failed to get widget surface info from surfman!"),