Upgrade to egui@0.29.1 and winit@0.30.5 (#33751)

* update egui dependencies

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* update glow to 0.14.1

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* update winit to 0.30.5

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* update servo-tidy.toml

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* Use more imports to avoid qualified usage, fix build, and silence warnings about deprecated methods

Signed-off-by: Martin Robinson <mrobinson@igalia.com>

---------

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Gae24 2024-10-10 19:18:03 +02:00 committed by GitHub
parent 6b3a316e1b
commit fd19409f31
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 339 additions and 182 deletions

View file

@ -102,13 +102,13 @@ webxr = { git = "https://github.com/servo/webxr" }
# For optional feature servo_allocator/use-system-allocator
servo_allocator = { path = "../../components/allocator" }
arboard = { version = "3" }
egui = { version = "0.28.1" }
egui_glow = { version = "0.28.1", features = ["winit"] }
egui-winit = { version = "0.28.1", default-features = false, features = ["clipboard", "wayland"] }
egui = { version = "0.29.1" }
egui_glow = { version = "0.29.1", features = ["winit"] }
egui-winit = { version = "0.29.1", default-features = false, features = ["clipboard", "wayland"] }
euclid = { workspace = true }
gilrs = "0.11.0"
gleam = { workspace = true }
glow = "0.13.1"
glow = "0.14.1"
headers = { workspace = true }
http = { workspace = true }
keyboard-types = { workspace = true }
@ -119,7 +119,7 @@ shellwords = "1.0.0"
surfman = { workspace = true, features = ["sm-x11", "sm-raw-window-handle-06"] }
tinyfiledialogs = "3.0"
webxr = { git = "https://github.com/servo/webxr", features = ["ipc", "glwindow", "headless"] }
winit = "0.29.10"
winit = "0.30.5"
[target.'cfg(any(all(target_os = "linux", not(target_env = "ohos")), target_os = "windows"))'.dependencies]
image = { workspace = true }

View file

@ -22,7 +22,7 @@ use webxr::glwindow::GlWindowDiscovery;
#[cfg(target_os = "windows")]
use webxr::openxr::{AppInfo, OpenXrDiscovery};
use winit::event::WindowEvent;
use winit::event_loop::EventLoopWindowTarget;
use winit::event_loop::ActiveEventLoop;
use winit::window::WindowId;
use super::events_loop::{EventsLoop, WakerEvent};
@ -80,7 +80,7 @@ impl App {
} else {
Rc::new(headed_window::Window::new(
opts::get().initial_window_size,
&events_loop,
&events_loop.as_winit(),
no_native_titlebar,
device_pixel_ratio_override,
))
@ -116,7 +116,12 @@ impl App {
debug_assert_eq!(webrender_gl.get_error(), gleam::gl::NO_ERROR);
app.minibrowser = Some(
Minibrowser::new(&rendering_context, &events_loop, initial_url.clone()).into(),
Minibrowser::new(
&rendering_context,
&events_loop.as_winit(),
initial_url.clone(),
)
.into(),
);
}
@ -164,10 +169,9 @@ impl App {
// ever try to make use of it once shutdown begins and
// it stops being valid.
let w = unsafe {
std::mem::transmute::<
&EventLoopWindowTarget<WakerEvent>,
&'static EventLoopWindowTarget<WakerEvent>,
>(w.unwrap())
std::mem::transmute::<&ActiveEventLoop, &'static ActiveEventLoop>(
w.unwrap(),
)
};
let factory = Box::new(move || Ok(window.new_glwindow(w)));
Some(XrDiscovery::GlWindow(GlWindowDiscovery::new(

View file

@ -51,12 +51,12 @@ pub struct EguiGlow {
impl EguiGlow {
/// For automatic shader version detection set `shader_version` to `None`.
pub fn new<E>(
event_loop: &winit::event_loop::EventLoopWindowTarget<E>,
pub fn new(
event_loop: &winit::event_loop::EventLoop<super::events_loop::WakerEvent>,
gl: std::sync::Arc<glow::Context>,
shader_version: Option<ShaderVersion>,
) -> Self {
let painter = egui_glow::Painter::new(gl, "", shader_version)
let painter = egui_glow::Painter::new(gl, "", shader_version, false)
.map_err(|err| {
log::error!("error occurred in initializing painter:\n{err}");
})
@ -70,6 +70,7 @@ impl EguiGlow {
event_loop,
None,
None,
None,
),
egui_ctx,
painter,

View file

@ -9,6 +9,9 @@ use std::time;
use log::warn;
use servo::embedder_traits::EventLoopWaker;
use winit::error::EventLoopError;
use winit::event::{Event, StartCause};
use winit::event_loop::{ActiveEventLoop, EventLoop as WinitEventLoop};
#[cfg(target_os = "macos")]
use winit::platform::macos::{ActivationPolicy, EventLoopBuilderExtMacOS};
@ -33,36 +36,25 @@ impl EventsLoop {
// Ideally, we could use the winit event loop in both modes,
// but on Linux, the event loop requires a X11 server.
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
pub fn new(
_headless: bool,
_has_output_file: bool,
) -> Result<EventsLoop, winit::error::EventLoopError> {
pub fn new(_headless: bool, _has_output_file: bool) -> Result<EventsLoop, EventLoopError> {
Ok(EventsLoop(EventLoop::Winit(Some(
winit::event_loop::EventLoopBuilder::with_user_event().build()?,
WinitEventLoop::with_user_event().build()?,
))))
}
#[cfg(target_os = "linux")]
pub fn new(
headless: bool,
_has_output_file: bool,
) -> Result<EventsLoop, winit::error::EventLoopError> {
pub fn new(headless: bool, _has_output_file: bool) -> Result<EventsLoop, EventLoopError> {
Ok(EventsLoop(if headless {
EventLoop::Headless(Arc::new((Mutex::new(false), Condvar::new())))
} else {
EventLoop::Winit(Some(
winit::event_loop::EventLoopBuilder::with_user_event().build()?,
))
EventLoop::Winit(Some(WinitEventLoop::with_user_event().build()?))
}))
}
#[cfg(target_os = "macos")]
pub fn new(
headless: bool,
_has_output_file: bool,
) -> Result<EventsLoop, winit::error::EventLoopError> {
pub fn new(headless: bool, _has_output_file: bool) -> Result<EventsLoop, EventLoopError> {
Ok(EventsLoop(if headless {
EventLoop::Headless(Arc::new((Mutex::new(false), Condvar::new())))
} else {
let mut event_loop_builder = winit::event_loop::EventLoopBuilder::with_user_event();
let mut event_loop_builder = WinitEventLoop::with_user_event();
if _has_output_file {
// Prevent the window from showing in Dock.app, stealing focus,
// when generating an output file.
@ -85,7 +77,7 @@ impl EventsLoop {
EventLoop::Headless(ref data) => Box::new(HeadlessEventLoopWaker(data.clone())),
}
}
pub fn as_winit(&self) -> &winit::event_loop::EventLoop<WakerEvent> {
pub fn as_winit(&self) -> &WinitEventLoop<WakerEvent> {
match self.0 {
EventLoop::Winit(Some(ref event_loop)) => event_loop,
EventLoop::Winit(None) | EventLoop::Headless(..) => {
@ -96,16 +88,12 @@ impl EventsLoop {
pub fn run_forever<F>(self, mut callback: F)
where
F: 'static
+ FnMut(
winit::event::Event<WakerEvent>,
Option<&winit::event_loop::EventLoopWindowTarget<WakerEvent>>,
&mut ControlFlow,
),
F: 'static + FnMut(Event<WakerEvent>, Option<&ActiveEventLoop>, &mut ControlFlow),
{
match self.0 {
EventLoop::Winit(events_loop) => {
let events_loop = events_loop.expect("Can't run an unavailable event loop.");
#[allow(deprecated)]
events_loop
.run(move |e, window_target| {
let mut control_flow = ControlFlow::default();
@ -116,12 +104,12 @@ impl EventsLoop {
},
EventLoop::Headless(ref data) => {
let (flag, condvar) = &**data;
let mut event = winit::event::Event::NewEvents(winit::event::StartCause::Init);
let mut event = Event::NewEvents(StartCause::Init);
loop {
self.sleep(flag, condvar);
let mut control_flow = ControlFlow::Poll;
callback(event, None, &mut control_flow);
event = winit::event::Event::<WakerEvent>::UserEvent(WakerEvent);
event = Event::<WakerEvent>::UserEvent(WakerEvent);
if control_flow != ControlFlow::Poll {
*flag.lock().unwrap() = false;
@ -164,7 +152,7 @@ pub enum ControlFlow {
}
impl ControlFlow {
fn apply_to(self, window_target: &winit::event_loop::EventLoopWindowTarget<WakerEvent>) {
fn apply_to(self, window_target: &ActiveEventLoop) {
match self {
ControlFlow::Poll => {
window_target.set_control_flow(winit::event_loop::ControlFlow::Poll)

View file

@ -30,7 +30,7 @@ use winit::keyboard::{Key as LogicalKey, ModifiersState, NamedKey};
#[cfg(any(target_os = "linux", target_os = "windows"))]
use winit::window::Icon;
use super::events_loop::{EventsLoop, WakerEvent};
use super::events_loop::WakerEvent;
use super::geometry::{winit_position_to_euclid_point, winit_size_to_euclid_size};
use super::keyutils::keyboard_event_from_winit;
use super::window_trait::{WindowPortsMethods, LINE_HEIGHT};
@ -60,7 +60,7 @@ pub struct Window {
impl Window {
pub fn new(
win_size: Size2D<u32, DeviceIndependentPixel>,
events_loop: &EventsLoop,
event_loop: &winit::event_loop::EventLoop<WakerEvent>,
no_native_titlebar: bool,
device_pixel_ratio_override: Option<f32>,
) -> Window {
@ -72,15 +72,16 @@ impl Window {
// #9996.
let visible = opts.output_file.is_none() && !no_native_titlebar;
let window_builder = winit::window::WindowBuilder::new()
let window_attr = winit::window::Window::default_attributes()
.with_title("Servo".to_string())
.with_decorations(!no_native_titlebar)
.with_transparent(no_native_titlebar)
.with_inner_size(LogicalSize::new(win_size.width, win_size.height))
.with_visible(visible);
let winit_window = window_builder
.build(events_loop.as_winit())
#[allow(deprecated)]
let winit_window = event_loop
.create_window(window_attr)
.expect("Failed to create window.");
#[cfg(any(target_os = "linux", target_os = "windows"))]
@ -89,8 +90,7 @@ impl Window {
winit_window.set_window_icon(Some(load_icon(icon_bytes)));
}
let primary_monitor = events_loop
.as_winit()
let primary_monitor = winit_window
.available_monitors()
.nth(0)
.expect("No monitor detected");
@ -377,7 +377,7 @@ impl WindowPortsMethods for Window {
return;
},
};
self.winit_window.set_cursor_icon(winit_cursor);
self.winit_window.set_cursor(winit_cursor);
self.winit_window.set_cursor_visible(true);
}
@ -460,7 +460,7 @@ impl WindowPortsMethods for Window {
.borrow_mut()
.push(EmbedderEvent::Touch(phase, id, point));
},
winit::event::WindowEvent::TouchpadMagnify { delta, .. } => {
winit::event::WindowEvent::PinchGesture { delta, .. } => {
let magnification = delta as f32 + 1.0;
self.event_queue
.borrow_mut()
@ -489,17 +489,17 @@ impl WindowPortsMethods for Window {
fn new_glwindow(
&self,
event_loop: &winit::event_loop::EventLoopWindowTarget<WakerEvent>,
event_loop: &winit::event_loop::ActiveEventLoop,
) -> Box<dyn webxr::glwindow::GlWindow> {
let size = self.winit_window.outer_size();
let window_builder = winit::window::WindowBuilder::new()
let window_attr = winit::window::Window::default_attributes()
.with_title("Servo XR".to_string())
.with_inner_size(size)
.with_visible(true);
let winit_window = window_builder
.build(event_loop)
let winit_window = event_loop
.create_window(window_attr)
.expect("Failed to create window.");
let pose = Rc::new(XRWindowPose {
@ -531,15 +531,15 @@ impl WindowMethods for Window {
let viewport_origin = DeviceIntPoint::zero(); // bottom left
let viewport_size = winit_size_to_euclid_size(self.winit_window.inner_size()).to_f32();
let viewport = DeviceIntRect::from_origin_and_size(viewport_origin, viewport_size.to_i32());
let screen = self.screen_size.to_i32();
let screen_size = self.screen_size.to_i32();
EmbedderCoordinates {
viewport,
framebuffer: viewport.size(),
window_rect: DeviceIntRect::from_origin_and_size(window_origin, window_size),
screen_size: screen,
screen_size,
// FIXME: Winit doesn't have API for available size. Fallback to screen size
available_screen_size: screen,
available_screen_size: screen_size,
hidpi_factor: self.hidpi_factor(),
}
}

View file

@ -20,7 +20,6 @@ use servo::webrender_api::units::{DeviceIntRect, DeviceIntSize};
use servo::webrender_traits::RenderingContext;
use surfman::{Connection, Context, Device, SurfaceType};
use super::events_loop::WakerEvent;
use crate::desktop::window_trait::WindowPortsMethods;
pub struct Window {
@ -70,7 +69,7 @@ impl WindowPortsMethods for Window {
}
fn id(&self) -> winit::window::WindowId {
unsafe { winit::window::WindowId::dummy() }
winit::window::WindowId::dummy()
}
fn request_inner_size(&self, size: DeviceIntSize) -> Option<DeviceIntSize> {
@ -136,7 +135,7 @@ impl WindowPortsMethods for Window {
fn new_glwindow(
&self,
_events_loop: &winit::event_loop::EventLoopWindowTarget<WakerEvent>,
_events_loop: &winit::event_loop::ActiveEventLoop,
) -> Box<dyn webxr::glwindow::GlWindow> {
unimplemented!()
}

View file

@ -27,10 +27,12 @@ use servo::servo_url::ServoUrl;
use servo::style_traits::DevicePixel;
use servo::webrender_traits::RenderingContext;
use servo::TopLevelBrowsingContextId;
use winit::event::{ElementState, MouseButton};
use winit::event::{ElementState, MouseButton, WindowEvent};
use winit::event_loop::EventLoop;
use winit::window::Window;
use super::egui_glue::EguiGlow;
use super::events_loop::EventsLoop;
use super::events_loop::WakerEvent;
use super::geometry::winit_position_to_euclid_point;
use super::webview::{LoadStatus, WebViewManager};
use super::window_trait::WindowPortsMethods;
@ -78,7 +80,7 @@ fn truncate_with_ellipsis(input: &str, max_length: usize) -> String {
impl Minibrowser {
pub fn new(
rendering_context: &RenderingContext,
events_loop: &EventsLoop,
event_loop: &EventLoop<WakerEvent>,
initial_url: ServoUrl,
) -> Self {
let gl = unsafe {
@ -87,7 +89,7 @@ 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);
let context = EguiGlow::new(event_loop, 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.
@ -118,14 +120,10 @@ impl Minibrowser {
/// Preprocess the given [winit::event::WindowEvent], returning unconsumed for mouse events in
/// the Servo browser rect. This is needed because the CentralPanel we create for our webview
/// would otherwise make egui report events in that area as consumed.
pub fn on_window_event(
&mut self,
window: &winit::window::Window,
event: &winit::event::WindowEvent,
) -> EventResponse {
pub fn on_window_event(&mut self, window: &Window, event: &WindowEvent) -> EventResponse {
let mut result = self.context.on_window_event(window, event);
result.consumed &= match event {
winit::event::WindowEvent::CursorMoved { position, .. } => {
WindowEvent::CursorMoved { position, .. } => {
let scale = Scale::<_, DeviceIndependentPixel, _>::new(
self.context.egui_ctx.pixels_per_point(),
);
@ -134,7 +132,7 @@ impl Minibrowser {
self.last_mouse_position
.map_or(false, |p| self.is_in_browser_rect(p))
},
winit::event::WindowEvent::MouseInput {
WindowEvent::MouseInput {
state: ElementState::Pressed,
button: MouseButton::Forward,
..
@ -144,7 +142,7 @@ impl Minibrowser {
.push(MinibrowserEvent::Forward);
true
},
winit::event::WindowEvent::MouseInput {
WindowEvent::MouseInput {
state: ElementState::Pressed,
button: MouseButton::Back,
..
@ -152,8 +150,7 @@ impl Minibrowser {
self.event_queue.borrow_mut().push(MinibrowserEvent::Back);
true
},
winit::event::WindowEvent::MouseWheel { .. } |
winit::event::WindowEvent::MouseInput { .. } => self
WindowEvent::MouseWheel { .. } | WindowEvent::MouseInput { .. } => self
.last_mouse_position
.map_or(false, |p| self.is_in_browser_rect(p)),
_ => true,
@ -259,7 +256,7 @@ impl Minibrowser {
/// CentralPanel when [`Minibrowser::paint`] is called.
pub fn update(
&mut self,
window: &winit::window::Window,
window: &Window,
webviews: &mut WebViewManager<dyn WindowPortsMethods>,
servo_framebuffer_id: Option<gl::GLuint>,
reason: &'static str,
@ -484,7 +481,7 @@ impl Minibrowser {
}
/// Paint the minibrowser, as of the last update.
pub fn paint(&mut self, window: &winit::window::Window) {
pub fn paint(&mut self, window: &Window) {
unsafe {
use glow::HasContext as _;
self.context

View file

@ -114,9 +114,10 @@ mod from_winit {
Self::CursorLeft { .. } => target_variant!("CursorLeft"),
Self::MouseWheel { .. } => target_variant!("MouseWheel"),
Self::MouseInput { .. } => target_variant!("MouseInput"),
Self::TouchpadMagnify { .. } => target_variant!("TouchpadMagnify"),
Self::SmartMagnify { .. } => target_variant!("SmartMagnify"),
Self::TouchpadRotate { .. } => target_variant!("TouchpadRotate"),
Self::PanGesture { .. } => target_variant!("PanGesture"),
Self::PinchGesture { .. } => target_variant!("PinchGesture"),
Self::DoubleTapGesture { .. } => target_variant!("DoubleTapGesture"),
Self::RotationGesture { .. } => target_variant!("RotationGesture"),
Self::TouchpadPressure { .. } => target_variant!("TouchpadPressure"),
Self::AxisMotion { .. } => target_variant!("AxisMotion"),
Self::Touch(..) => target_variant!("Touch"),

View file

@ -13,8 +13,6 @@ use servo::servo_geometry::DeviceIndependentPixel;
use servo::style_traits::DevicePixel;
use servo::webrender_api::units::{DeviceIntPoint, DeviceIntSize};
use super::events_loop::WakerEvent;
// This should vary by zoom level and maybe actual text size (focused or under cursor)
pub const LINE_HEIGHT: f32 = 38.0;
@ -43,7 +41,7 @@ pub trait WindowPortsMethods: WindowMethods {
fn set_cursor(&self, _cursor: Cursor) {}
fn new_glwindow(
&self,
events_loop: &winit::event_loop::EventLoopWindowTarget<WakerEvent>,
event_loop: &winit::event_loop::ActiveEventLoop,
) -> Box<dyn webxr::glwindow::GlWindow>;
fn winit_window(&self) -> Option<&winit::window::Window>;
fn toolbar_height(&self) -> Length<f32, DeviceIndependentPixel>;