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

Upgrade winit to 0.30.2 #4849

Merged
merged 26 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
00c282d
Initial conversion to winit 0.30
ArthurBrussee Jul 18, 2024
5294cae
Pin to 0.30.0 as 0.30.1+ has a bug that crashes on mac :/
ArthurBrussee Jul 18, 2024
3f42b72
Builder -> attributes
ArthurBrussee Jul 18, 2024
2e6c0d3
Add link to problematic winit PR
ArthurBrussee Jul 18, 2024
4f0e7d5
Update WinitApp integration to be more like ApplicationHandler
ArthurBrussee Jul 18, 2024
4623863
Fix for windows & linux
ArthurBrussee Jul 18, 2024
eafed08
Use more modern accesskit lazy init
ArthurBrussee Jul 18, 2024
e6741d2
Fixup comments
ArthurBrussee Jul 18, 2024
f37e52b
Update to latest accesskit and accesskit_winit
DataTriny Jul 19, 2024
fd3e552
Merge pull request #1 from DataTriny/fix-accesskit
ArthurBrussee Jul 19, 2024
cd894eb
Fixes for linux
ArthurBrussee Jul 19, 2024
d90b565
Merge remote-tracking branch 'origin/master' into winit-update
ArthurBrussee Jul 19, 2024
5e0f479
CI fixes
ArthurBrussee Jul 19, 2024
67c456b
Add a comment about wayland-cursor.
ArthurBrussee Jul 19, 2024
6d582f5
Fix crash when using winit 0.30.4
ArthurBrussee Jul 26, 2024
2f4dbaf
Enable nix/fs feature workaround in x11 too
ArthurBrussee Jul 26, 2024
af1c892
Remove leftover comment
ArthurBrussee Jul 26, 2024
c10e3fb
Managed to leave in some typos...
ArthurBrussee Jul 26, 2024
d9905d8
Merge branch 'master' into winit-update
emilk Jul 30, 2024
f10cf80
Fix request_repaint_after
ArthurBrussee Jul 30, 2024
1bbb312
Adress some review comments.
ArthurBrussee Jul 30, 2024
81fd86c
Pin winit, fix wayland dependency issues again.
ArthurBrussee Jul 30, 2024
e4fa5f9
Move `wayland-cursor` dependency to fix Windows build
emilk Jul 30, 2024
ba7cb00
fix typo
emilk Jul 30, 2024
48f402e
Remove duplicate dependency on `async-channel`
emilk Jul 30, 2024
8f337c7
ignore duplicated crate futures-lite
emilk Jul 30, 2024
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
652 changes: 414 additions & 238 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,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.0"
glutin-winit = "0.5.0"
image = { version = "0.25", default-features = false }
log = { version = "0.4", features = ["std"] }
nohash-hasher = "0.2"
Expand All @@ -85,16 +85,16 @@ ron = "0.8"
raw-window-handle = "0.6.0"
serde = { version = "1", features = ["derive"] }
thiserror = "1.0.37"
web-time = "0.2" # Timekeeping for native and web
web-time = "1.1.0" # Timekeeping for native and web
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = "0.3.58"
wgpu = { version = "22.0.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.4", default-features = false }

[workspace.lints.rust]
unsafe_code = "deny"
Expand Down
13 changes: 1 addition & 12 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 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
32 changes: 4 additions & 28 deletions crates/eframe/src/native/epi_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use web_time::Instant;

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

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

Expand All @@ -12,9 +12,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 +95,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 @@ -229,27 +226,6 @@ impl EpiIntegration {
}
}

#[cfg(feature = "accesskit")]
pub fn init_accesskit<E: From<egui_winit::accesskit_winit::ActionRequestEvent> + Send>(
&self,
egui_winit: &mut egui_winit::State,
window: &winit::window::Window,
event_loop_proxy: winit::event_loop::EventLoopProxy<E>,
) {
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()
});
}

/// If `true`, it is time to close the native window.
pub fn should_close(&self) -> bool {
self.close
Expand Down
54 changes: 54 additions & 0 deletions crates/eframe/src/native/event_loop_context.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use std::cell::Cell;
use winit::event_loop::ActiveEventLoop;

thread_local! {
static CURRENT_EVENT_LOOP: Cell<Option<*const ActiveEventLoop>> = Cell::new(None);
}

struct EventLoopGuard;

impl EventLoopGuard {
fn new(event_loop: &ActiveEventLoop) -> Self {
CURRENT_EVENT_LOOP.with(|cell| {
assert!(
cell.get().is_none(),
"Attempted to set a new event loop while one is already set"
);
cell.set(Some(event_loop as *const ActiveEventLoop));
});
Self
}
}

impl Drop for EventLoopGuard {
fn drop(&mut self) {
CURRENT_EVENT_LOOP.with(|cell| cell.set(None));
}
}

// Helper function to safely use the current event loop
#[allow(unsafe_code)]
pub fn with_current_event_loop<F, R>(f: F) -> Option<R>
where
F: FnOnce(&ActiveEventLoop) -> R,
{
CURRENT_EVENT_LOOP.with(|cell| {
cell.get().map(|ptr| {
// SAFETY:
// 1. The pointer is guaranteed to be valid when it's Some, as the EventLoopGuard that created it
// lives at least as long as the reference, and clears it when it's dropped. Only run_with_event_loop creates
// a new EventLoopGuard, and does not leak it.
// 2. Since the pointer was created from a borrow which lives at least as long as this pointer there are
// no mutable references to the ActiveEventLoop.
let event_loop = unsafe { &*ptr };
f(event_loop)
})
})
}

// The only public interface to use the event loop
pub fn with_event_loop_context(event_loop: &ActiveEventLoop, f: impl FnOnce()) {
// NOTE: For safety, this guard must NOT be leaked.
let _guard = EventLoopGuard::new(event_loop);
f();
}
Loading
Loading