Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump winit to 0.30.0 and accesskit to 0.14.0 #4466

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
492 changes: 279 additions & 213 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ bytemuck = "1.7.2"
criterion = { version = "0.5.1", default-features = false }
document-features = " 0.2.8"
glow = "0.13"
glutin = "0.31"
glutin-winit = "0.4"
glutin = "0.32"
glutin-winit = "0.5"
image = { version = "0.25", default-features = false }
log = { version = "0.4", features = ["std"] }
nohash-hasher = "0.2"
Expand All @@ -92,7 +92,7 @@ wgpu = { version = "0.19.1", 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
15 changes: 2 additions & 13 deletions crates/eframe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,7 @@ android-native-activity = ["egui-winit/android-native-activity"]
default_fonts = ["egui/default_fonts"]

## Use [`glow`](https://github.com/grovesNL/glow) for painting, via [`egui_glow`](https://github.com/emilk/egui/tree/master/crates/egui_glow).
glow = [
"dep:egui_glow",
"dep:glow",
"dep:glutin-winit",
"dep:glutin",
"dep:rwh_05",
"winit/rwh_05",
]
glow = ["dep:egui_glow", "dep:glow", "dep:glutin-winit", "dep:glutin"]

## Enable saving app state to disk.
persistence = [
Expand Down Expand Up @@ -141,10 +134,6 @@ web-time.workspace = true

egui_glow = { workspace = true, optional = true, default-features = false }
glow = { workspace = true, optional = true }
# glutin stuck on old version of raw-window-handle:
rwh_05 = { package = "raw-window-handle", version = "0.5.2", optional = true, features = [
"std",
] }
ron = { workspace = true, optional = true, features = ["integer128"] }
serde = { workspace = true, optional = true }

Expand All @@ -156,7 +145,7 @@ egui-winit = { workspace = true, default-features = false, features = [
"links",
] }
image = { workspace = true, features = ["png"] } # Needed for app icon
winit = { workspace = true, default-features = false, features = ["rwh_06"] }
winit = { workspace = true, default-features = false }

# optional native:
directories-next = { version = "2", optional = true }
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
26 changes: 7 additions & 19 deletions crates/eframe/src/native/epi_integration.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//! Common tools used by [`super::glow_integration`] and [`super::wgpu_integration`].

use web_time::Instant;

use std::path::PathBuf;
use winit::event_loop::EventLoopWindowTarget;
use web_time::Instant;
use winit::event_loop::ActiveEventLoop;

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

Expand All @@ -12,9 +11,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 @@ -95,10 +94,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 @@ -232,7 +228,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 @@ -241,15 +237,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
72 changes: 40 additions & 32 deletions crates/eframe/src/native/glow_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ use glutin::{
prelude::{GlDisplay, PossiblyCurrentGlContext},
surface::GlSurface,
};
use raw_window_handle::HasWindowHandle;
use winit::{
event_loop::{EventLoop, EventLoopProxy, EventLoopWindowTarget},
event_loop::{ActiveEventLoop, EventLoop, EventLoopProxy},
window::{Window, WindowId},
};

Expand All @@ -31,8 +32,6 @@ use egui::{
DeferredViewportUiCallback, ImmediateViewport, 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 +144,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 +188,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 = if let Some(file) = &self.native_options.persistence_path {
Expand Down Expand Up @@ -325,7 +321,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 @@ -396,7 +392,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 @@ -408,7 +404,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 @@ -475,22 +471,32 @@ impl WinitApp for GlowWinitApp {
}

#[cfg(feature = "accesskit")]
winit::event::Event::UserEvent(UserEvent::AccessKitActionRequest(
accesskit_winit::ActionRequestEvent { request, window_id },
winit::event::Event::UserEvent(UserEvent::AccessKitEvent(
egui_winit::accesskit_winit::Event {
window_id,
window_event,
},
)) => {
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() {
if let Some(viewport) = glutin.viewports.get_mut(&viewport_id) {
if let Some(egui_winit) = &mut viewport.egui_winit {
crate::profile_scope!("on_accesskit_action_request");
egui_winit.on_accesskit_action_request(request.clone());
crate::profile_scope!("on_accesskit_window_event");
winit_integration::on_accesskit_window_event(
egui_winit,
*window_id,
window_event,
)
} else {
EventResult::Wait
}
} else {
EventResult::Wait
}
} else {
EventResult::Wait
}
// As a form of user input, accessibility actions should
// lead to a repaint.
EventResult::RepaintNext(*window_id)
} else {
EventResult::Wait
}
Expand All @@ -503,7 +509,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 @@ -898,7 +904,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 @@ -947,7 +953,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_attributes(Some(egui_winit::create_winit_window_attributes(
egui_ctx,
event_loop,
viewport_builder.clone(),
Expand Down Expand Up @@ -982,10 +988,9 @@ impl GlutinWindowContext {
gl_display.version_string(),
gl_display.supported_features()
);
let glutin_raw_window_handle = window.as_ref().map(|w| {
use rwh_05::HasRawWindowHandle as _; // glutin stuck on old version of raw-window-handle
w.raw_window_handle()
});
let glutin_raw_window_handle = window
.as_ref()
.and_then(|w| w.window_handle().ok().map(|h| h.as_raw()));
log::debug!("creating gl context using raw window handle: {glutin_raw_window_handle:?}");

// create gl context. if core context cannot be created, try gl es context as fallback.
Expand Down Expand Up @@ -1070,7 +1075,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 @@ -1087,7 +1092,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 All @@ -1100,7 +1105,7 @@ impl GlutinWindowContext {
window
} else {
log::debug!("Creating a window for viewport {viewport_id:?}");
let window_builder = egui_winit::create_winit_window_builder(
let window_builder = egui_winit::create_winit_window_attributes(
&self.egui_ctx,
event_loop,
viewport.builder.clone(),
Expand Down Expand Up @@ -1140,9 +1145,12 @@ impl GlutinWindowContext {
let width_px = NonZeroU32::new(width_px).unwrap_or(NonZeroU32::MIN);
let height_px = NonZeroU32::new(height_px).unwrap_or(NonZeroU32::MIN);
let surface_attributes = {
use rwh_05::HasRawWindowHandle as _; // glutin stuck on old version of raw-window-handle
glutin::surface::SurfaceAttributesBuilder::<glutin::surface::WindowSurface>::new()
.build(window.raw_window_handle(), width_px, height_px)
.build(
window.window_handle().unwrap().as_raw(),
width_px,
height_px,
)
};

log::trace!("creating surface with attributes: {surface_attributes:?}");
Expand Down Expand Up @@ -1253,7 +1261,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 @@ -1377,7 +1385,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
Loading
Loading