Skip to content

Commit

Permalink
intercept ScaleFactorChanged events to ensure we apply our overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
delan committed Sep 13, 2023
1 parent 69138c0 commit b90e315
Showing 1 changed file with 41 additions and 12 deletions.
53 changes: 41 additions & 12 deletions ports/servoshell/app.rs
Expand Up @@ -10,13 +10,14 @@ use std::rc::Rc;
use std::time::Instant;

use gleam::gl;
use log::{trace, warn};
use log::{info, trace, warn};
use servo::compositing::windowing::EmbedderEvent;
use servo::config::opts;
use servo::servo_config::pref;
use servo::Servo;
use surfman::GLApi;
use webxr::glwindow::GlWindowDiscovery;
use winit::event::WindowEvent;
use winit::event_loop::EventLoopWindowTarget;
use winit::window::WindowId;

Expand Down Expand Up @@ -121,8 +122,16 @@ impl App {
events_loop.run_forever(move |e, w, control_flow| {
let now = Instant::now();
match e {
// Uncomment to filter out logging of DeviceEvent, which can be very noisy.
// Uncomment to filter out logging of common events, which can be very noisy.
// winit::event::Event::DeviceEvent { .. } => {},
// winit::event::Event::WindowEvent {
// event: WindowEvent::CursorMoved { .. },
// ..
// } => {},
// winit::event::Event::MainEventsCleared => {},
// winit::event::Event::RedrawEventsCleared => {},
// winit::event::Event::UserEvent(..) => {},
// winit::event::Event::NewEvents(..) => {},
_ => trace!("@{:?} (+{:?}) {:?}", now - t_start, now - t, e),
}
t = now;
Expand Down Expand Up @@ -207,16 +216,36 @@ impl App {
// Handle the event
let mut consumed = false;
if let Some(mut minibrowser) = app.minibrowser() {
if let winit::event::Event::WindowEvent { ref event, .. } = e {
let response = minibrowser.context.on_event(&event);
if response.repaint {
// Request a winit redraw event, so we can recomposite, update and paint the
// minibrowser, and present the new frame.
window.winit_window().unwrap().request_redraw();
}

// TODO how do we handle the tab key? (see doc for consumed)
consumed = response.consumed;
match e {
winit::event::Event::WindowEvent {
event: WindowEvent::ScaleFactorChanged { scale_factor, .. },
..
} => {
// Catch any ScaleFactorChanged events and set egui’s scale factor manually,
// because we have our own logic for calculating the scale factor to use.
let effective_scale_factor = window.hidpi_factor().get();
info!(
"window scale factor changed to {}, setting scale factor to {}",
scale_factor, effective_scale_factor
);
minibrowser
.context
.egui_ctx
.set_pixels_per_point(effective_scale_factor);
},
winit::event::Event::WindowEvent { ref event, .. } => {
let response = minibrowser.context.on_event(&event);
if response.repaint {
// Request a winit redraw event, so we can recomposite, update and paint the
// minibrowser, and present the new frame.
window.winit_window().unwrap().request_redraw();
}

// TODO how do we handle the tab key? (see doc for consumed)
// Note that servo doesn’t yet support tabbing through links and inputs
consumed = response.consumed;
},
_ => {},
}
}
if !consumed {
Expand Down

0 comments on commit b90e315

Please sign in to comment.