Skip to content

Commit

Permalink
Bump winit to 0.30.0 and accesskit to 0.14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriBaal committed May 6, 2024
1 parent ded8dbd commit 8a8f6ea
Show file tree
Hide file tree
Showing 16 changed files with 457 additions and 269 deletions.
455 changes: 322 additions & 133 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ wgpu = { version = "0.20.0", default-features = false, features = [
# Make the renderer `Sync` even on wasm32, because it makes the code simpler:
"fragile-send-sync-non-atomic-wasm",
] }
winit = { version = "0.29.4", default-features = false }
winit = { version = "0.30.0", default-features = false }


[workspace.lints.rust]
Expand Down
2 changes: 1 addition & 1 deletion crates/eframe/src/epi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use static_assertions::assert_not_impl_any;

#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(feature = "glow", feature = "wgpu"))]
pub use winit::{event_loop::EventLoopBuilder, window::WindowBuilder};
pub use winit::{event_loop::EventLoopBuilder, window::WindowAttributes};

/// Hook into the building of an event loop before it is run
///
Expand Down
23 changes: 6 additions & 17 deletions crates/eframe/src/native/epi_integration.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Common tools used by [`super::glow_integration`] and [`super::wgpu_integration`].
use web_time::Instant;
use winit::event_loop::EventLoopWindowTarget;
use winit::event_loop::ActiveEventLoop;

use raw_window_handle::{HasDisplayHandle as _, HasWindowHandle as _};

Expand All @@ -10,9 +10,9 @@ use egui_winit::{EventResponse, WindowSettings};

use crate::{epi, Theme};

pub fn viewport_builder<E>(
pub fn viewport_builder(
egui_zoom_factor: f32,
event_loop: &EventLoopWindowTarget<E>,
event_loop: &ActiveEventLoop,
native_options: &mut epi::NativeOptions,
window_settings: Option<WindowSettings>,
) -> ViewportBuilder {
Expand Down Expand Up @@ -90,10 +90,7 @@ pub fn apply_window_settings(
}
}

fn largest_monitor_point_size<E>(
egui_zoom_factor: f32,
event_loop: &EventLoopWindowTarget<E>,
) -> egui::Vec2 {
fn largest_monitor_point_size(egui_zoom_factor: f32, event_loop: &ActiveEventLoop) -> egui::Vec2 {
crate::profile_function!();

let mut max_size = egui::Vec2::ZERO;
Expand Down Expand Up @@ -217,7 +214,7 @@ impl EpiIntegration {
}

#[cfg(feature = "accesskit")]
pub fn init_accesskit<E: From<egui_winit::accesskit_winit::ActionRequestEvent> + Send>(
pub fn init_accesskit<E: From<egui_winit::accesskit_winit::Event> + Send>(
&self,
egui_winit: &mut egui_winit::State,
window: &winit::window::Window,
Expand All @@ -226,15 +223,7 @@ impl EpiIntegration {
crate::profile_function!();

let egui_ctx = self.egui_ctx.clone();
egui_winit.init_accesskit(window, event_loop_proxy, move || {
// This function is called when an accessibility client
// (e.g. screen reader) makes its first request. If we got here,
// we know that an accessibility tree is actually wanted.
egui_ctx.enable_accesskit();
// Enqueue a repaint so we'll receive a full tree update soon.
egui_ctx.request_repaint();
egui_ctx.accesskit_placeholder_tree_update()
});
egui_winit.init_accesskit(window, event_loop_proxy, egui_ctx);
}

/// If `true`, it is time to close the native window.
Expand Down
38 changes: 17 additions & 21 deletions crates/eframe/src/native/glow_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use glutin::{
surface::GlSurface,
};
use winit::{
event_loop::{EventLoop, EventLoopProxy, EventLoopWindowTarget},
event_loop::{ActiveEventLoop, EventLoop, EventLoopProxy},
window::{Window, WindowId},
};

Expand All @@ -31,8 +31,6 @@ use egui::{
ViewportBuilder, ViewportClass, ViewportId, ViewportIdMap, ViewportIdPair, ViewportInfo,
ViewportOutput,
};
#[cfg(feature = "accesskit")]
use egui_winit::accesskit_winit;

use crate::{
native::{epi_integration::EpiIntegration, winit_integration::create_egui_context},
Expand Down Expand Up @@ -145,7 +143,7 @@ impl GlowWinitApp {
#[allow(unsafe_code)]
fn create_glutin_windowed_context(
egui_ctx: &egui::Context,
event_loop: &EventLoopWindowTarget<UserEvent>,
event_loop: &ActiveEventLoop,
storage: Option<&dyn Storage>,
native_options: &mut NativeOptions,
) -> Result<(GlutinWindowContext, egui_glow::Painter)> {
Expand Down Expand Up @@ -189,10 +187,7 @@ impl GlowWinitApp {
Ok((glutin_window_context, painter))
}

fn init_run_state(
&mut self,
event_loop: &EventLoopWindowTarget<UserEvent>,
) -> Result<&mut GlowWinitRunning> {
fn init_run_state(&mut self, event_loop: &ActiveEventLoop) -> Result<&mut GlowWinitRunning> {
crate::profile_function!();

let storage = epi_integration::create_storage(
Expand Down Expand Up @@ -321,7 +316,7 @@ impl GlowWinitApp {
let painter = Rc::downgrade(&painter);
let beginning = integration.beginning;

let event_loop: *const EventLoopWindowTarget<UserEvent> = event_loop;
let event_loop: *const ActiveEventLoop = event_loop;

egui::Context::set_immediate_viewport_renderer(move |egui_ctx, immediate_viewport| {
if let (Some(glutin), Some(painter)) = (glutin.upgrade(), painter.upgrade()) {
Expand Down Expand Up @@ -392,7 +387,7 @@ impl WinitApp for GlowWinitApp {

fn run_ui_and_paint(
&mut self,
event_loop: &EventLoopWindowTarget<UserEvent>,
event_loop: &ActiveEventLoop,
window_id: WindowId,
) -> EventResult {
if let Some(running) = &mut self.running {
Expand All @@ -404,7 +399,7 @@ impl WinitApp for GlowWinitApp {

fn on_event(
&mut self,
event_loop: &EventLoopWindowTarget<UserEvent>,
event_loop: &ActiveEventLoop,
event: &winit::event::Event<UserEvent>,
) -> Result<EventResult> {
crate::profile_function!(winit_integration::short_event_description(event));
Expand Down Expand Up @@ -471,9 +466,10 @@ impl WinitApp for GlowWinitApp {
}

#[cfg(feature = "accesskit")]
winit::event::Event::UserEvent(UserEvent::AccessKitActionRequest(
accesskit_winit::ActionRequestEvent { request, window_id },
)) => {
winit::event::Event::UserEvent(UserEvent::AccessKitActionRequest {
request,
window_id,
}) => {
if let Some(running) = &self.running {
let mut glutin = running.glutin.borrow_mut();
if let Some(viewport_id) = glutin.viewport_from_window.get(window_id).copied() {
Expand All @@ -499,7 +495,7 @@ impl WinitApp for GlowWinitApp {
impl GlowWinitRunning {
fn run_ui_and_paint(
&mut self,
event_loop: &EventLoopWindowTarget<UserEvent>,
event_loop: &ActiveEventLoop,
window_id: WindowId,
) -> EventResult {
crate::profile_function!();
Expand Down Expand Up @@ -894,7 +890,7 @@ impl GlutinWindowContext {
egui_ctx: &egui::Context,
viewport_builder: ViewportBuilder,
native_options: &NativeOptions,
event_loop: &EventLoopWindowTarget<UserEvent>,
event_loop: &ActiveEventLoop,
) -> Result<Self> {
crate::profile_function!();

Expand Down Expand Up @@ -943,7 +939,7 @@ impl GlutinWindowContext {
let display_builder = glutin_winit::DisplayBuilder::new()
// we might want to expose this option to users in the future. maybe using an env var or using native_options.
.with_preference(glutin_winit::ApiPreference::FallbackEgl) // https://github.com/emilk/egui/issues/2520#issuecomment-1367841150
.with_window_builder(Some(egui_winit::create_winit_window_builder(
.with_window_builder(Some(egui_winit::create_winit_window_attributes(
egui_ctx,
event_loop,
viewport_builder.clone(),
Expand Down Expand Up @@ -1066,7 +1062,7 @@ impl GlutinWindowContext {
/// Create a surface, window, and winit integration for all viewports lacking any of that.
///
/// Errors will be logged.
fn initialize_all_windows(&mut self, event_loop: &EventLoopWindowTarget<UserEvent>) {
fn initialize_all_windows(&mut self, event_loop: &ActiveEventLoop) {
crate::profile_function!();

let viewports: Vec<ViewportId> = self.viewports.keys().copied().collect();
Expand All @@ -1083,7 +1079,7 @@ impl GlutinWindowContext {
pub(crate) fn initialize_window(
&mut self,
viewport_id: ViewportId,
event_loop: &EventLoopWindowTarget<UserEvent>,
event_loop: &ActiveEventLoop,
) -> Result<()> {
crate::profile_function!();

Expand Down Expand Up @@ -1249,7 +1245,7 @@ impl GlutinWindowContext {

fn handle_viewport_output(
&mut self,
event_loop: &EventLoopWindowTarget<UserEvent>,
event_loop: &ActiveEventLoop,
egui_ctx: &egui::Context,
viewport_output: &ViewportIdMap<ViewportOutput>,
) {
Expand Down Expand Up @@ -1373,7 +1369,7 @@ fn initialize_or_update_viewport(
/// This is called (via a callback) by user code to render immediate viewports,
/// i.e. viewport that are directly nested inside a parent viewport.
fn render_immediate_viewport(
event_loop: &EventLoopWindowTarget<UserEvent>,
event_loop: &ActiveEventLoop,
egui_ctx: &egui::Context,
glutin: &RefCell<GlutinWindowContext>,
painter: &RefCell<egui_glow::Painter>,
Expand Down
2 changes: 1 addition & 1 deletion crates/eframe/src/native/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn create_event_loop_builder(
native_options: &mut epi::NativeOptions,
) -> EventLoopBuilder<UserEvent> {
crate::profile_function!();
let mut event_loop_builder = winit::event_loop::EventLoopBuilder::with_user_event();
let mut event_loop_builder = winit::event_loop::EventLoop::with_user_event();

if let Some(hook) = std::mem::take(&mut native_options.event_loop_builder) {
hook(&mut event_loop_builder);
Expand Down
33 changes: 14 additions & 19 deletions crates/eframe/src/native/wgpu_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use egui_winit::ActionRequested;
use parking_lot::Mutex;
use raw_window_handle::{HasDisplayHandle as _, HasWindowHandle as _};
use winit::{
event_loop::{EventLoop, EventLoopProxy, EventLoopWindowTarget},
event_loop::{ActiveEventLoop, EventLoop, EventLoopProxy},
window::{Window, WindowId},
};

Expand All @@ -20,8 +20,6 @@ use egui::{
DeferredViewportUiCallback, FullOutput, ImmediateViewport, ViewportBuilder, ViewportClass,
ViewportId, ViewportIdMap, ViewportIdPair, ViewportIdSet, ViewportInfo, ViewportOutput,
};
#[cfg(feature = "accesskit")]
use egui_winit::accesskit_winit;

use crate::{
native::{epi_integration::EpiIntegration, winit_integration::EventResult},
Expand Down Expand Up @@ -119,7 +117,7 @@ impl WgpuWinitApp {
}

/// Create a window for all viewports lacking one.
fn initialized_all_windows(&mut self, event_loop: &EventLoopWindowTarget<UserEvent>) {
fn initialized_all_windows(&mut self, event_loop: &ActiveEventLoop) {
let Some(running) = &mut self.running else {
return;
};
Expand All @@ -142,11 +140,7 @@ impl WgpuWinitApp {
}

#[cfg(target_os = "android")]
fn recreate_window(
&self,
event_loop: &EventLoopWindowTarget<UserEvent>,
running: &WgpuWinitRunning,
) {
fn recreate_window(&self, event_loop: &ActiveEventLoop, running: &WgpuWinitRunning) {
let SharedState {
egui_ctx,
viewports,
Expand Down Expand Up @@ -178,7 +172,7 @@ impl WgpuWinitApp {
fn init_run_state(
&mut self,
egui_ctx: egui::Context,
event_loop: &EventLoopWindowTarget<UserEvent>,
event_loop: &ActiveEventLoop,
storage: Option<Box<dyn Storage>>,
window: Window,
builder: ViewportBuilder,
Expand Down Expand Up @@ -310,7 +304,7 @@ impl WgpuWinitApp {
let shared = Rc::downgrade(&shared);
let beginning = integration.beginning;

let event_loop: *const EventLoopWindowTarget<UserEvent> = event_loop;
let event_loop: *const ActiveEventLoop = event_loop;

egui::Context::set_immediate_viewport_renderer(move |_egui_ctx, immediate_viewport| {
if let Some(shared) = shared.upgrade() {
Expand Down Expand Up @@ -376,7 +370,7 @@ impl WinitApp for WgpuWinitApp {

fn run_ui_and_paint(
&mut self,
event_loop: &EventLoopWindowTarget<UserEvent>,
event_loop: &ActiveEventLoop,
window_id: WindowId,
) -> EventResult {
self.initialized_all_windows(event_loop);
Expand All @@ -390,7 +384,7 @@ impl WinitApp for WgpuWinitApp {

fn on_event(
&mut self,
event_loop: &EventLoopWindowTarget<UserEvent>,
event_loop: &ActiveEventLoop,
event: &winit::event::Event<UserEvent>,
) -> Result<EventResult> {
crate::profile_function!(winit_integration::short_event_description(event));
Expand Down Expand Up @@ -473,9 +467,10 @@ impl WinitApp for WgpuWinitApp {
}

#[cfg(feature = "accesskit")]
winit::event::Event::UserEvent(UserEvent::AccessKitActionRequest(
accesskit_winit::ActionRequestEvent { request, window_id },
)) => {
winit::event::Event::UserEvent(UserEvent::AccessKitActionRequest {
request,
window_id,
}) => {
if let Some(running) = &mut self.running {
let mut shared_lock = running.shared.borrow_mut();
let SharedState {
Expand Down Expand Up @@ -861,7 +856,7 @@ impl Viewport {
/// Create winit window, if needed.
fn initialize_window(
&mut self,
event_loop: &EventLoopWindowTarget<UserEvent>,
event_loop: &ActiveEventLoop,
egui_ctx: &egui::Context,
windows_id: &mut HashMap<WindowId, ViewportId>,
painter: &mut egui_wgpu::winit::Painter,
Expand Down Expand Up @@ -906,7 +901,7 @@ impl Viewport {

fn create_window(
egui_ctx: &egui::Context,
event_loop: &EventLoopWindowTarget<UserEvent>,
event_loop: &ActiveEventLoop,
storage: Option<&dyn Storage>,
native_options: &mut NativeOptions,
) -> Result<(Window, ViewportBuilder), winit::error::OsError> {
Expand All @@ -927,7 +922,7 @@ fn create_window(
}

fn render_immediate_viewport(
event_loop: &EventLoopWindowTarget<UserEvent>,
event_loop: &ActiveEventLoop,
beginning: Instant,
shared: &RefCell<SharedState>,
immediate_viewport: ImmediateViewport<'_>,
Expand Down
Loading

0 comments on commit 8a8f6ea

Please sign in to comment.