Skip to content

Commit f65060e

Browse files
committed
desktop: Update winit to 0.29.10 and egui to 0.25.0
1 parent 5169d9d commit f65060e

File tree

8 files changed

+520
-555
lines changed

8 files changed

+520
-555
lines changed

Cargo.lock

Lines changed: 303 additions & 231 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
4646
naga = { version = "0.14.2", features = ["validate", "wgsl-out"] }
4747
naga_oil = "0.11.0"
4848
wgpu = "0.18.0"
49-
egui = "0.24.1"
49+
egui = "0.25.0"
5050

5151
[workspace.lints.rust]
5252
# Clippy nightly often adds new/buggy lints that we want to ignore.
@@ -99,3 +99,9 @@ inherits = "release"
9999
# is not yet in the latest wgpu release. TODO: Remove when it is.
100100
wgpu = { git = "https://github.com/gfx-rs/wgpu", branch = "v0.18" }
101101
naga = { git = "https://github.com/gfx-rs/wgpu", branch = "v0.18" }
102+
103+
# https://github.com/emilk/egui/pull/3812
104+
egui = { git = "https://github.com/ruffle-rs/egui", branch = "consume_keys"}
105+
egui_extras = { git = "https://github.com/ruffle-rs/egui", branch = "consume_keys"}
106+
egui-winit = { git = "https://github.com/ruffle-rs/egui", branch = "consume_keys"}
107+
egui-wgpu = { git = "https://github.com/ruffle-rs/egui", branch = "consume_keys"}

core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ hashbrown = { version = "0.14.3", features = ["raw"] }
5555
scopeguard = "1.2.0"
5656
fluent-templates = "0.8.0"
5757
egui = { workspace = true, optional = true }
58-
egui_extras = { version = "0.24.2", optional = true }
58+
egui_extras = { version = "0.25.0", optional = true }
5959
png = { version = "0.17.11", optional = true }
6060
flv-rs = { path = "../flv" }
6161
async-channel = "2.1.1"

desktop/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ workspace = true
1414
clap = { version = "4.4.17", features = ["derive"] }
1515
cpal = "0.15.2"
1616
egui = { workspace = true }
17-
egui_extras = { version = "0.24.2", features = ["image"] }
18-
egui-wgpu = { version = "0.24.1", features = ["winit"] }
17+
egui_extras = { version = "0.25.0", features = ["image"] }
18+
egui-wgpu = { version = "0.25.0", features = ["winit"] }
1919
image = { version = "0.24", features = ["png"] }
20-
egui-winit = "0.24.1"
20+
egui-winit = "0.25.0"
2121
fontdb = "0.16"
2222
ruffle_core = { path = "../core", features = ["audio", "clap", "mp3", "nellymoser", "default_compatibility_rules", "egui"] }
2323
ruffle_render = { path = "../render", features = ["clap"] }
@@ -26,7 +26,7 @@ ruffle_video_software = { path = "../video/software", optional = true }
2626
tracing = { workspace = true}
2727
tracing-subscriber = { workspace = true }
2828
generational-arena = "0.2.9"
29-
winit = "0.28.7"
29+
winit = "0.29.10"
3030
webbrowser = "0.8.12"
3131
url = "2.5.0"
3232
arboard = { version = "3.3.0", features = ["wayland-data-control"] }

desktop/src/app.rs

Lines changed: 64 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use crate::custom_event::RuffleEvent;
33
use crate::gui::{GuiController, MENU_HEIGHT};
44
use crate::player::{PlayerController, PlayerOptions};
55
use crate::util::{
6-
get_screen_size, parse_url, pick_file, plot_stats_in_tracy, winit_key_to_char,
7-
winit_to_ruffle_key_code, winit_to_ruffle_text_control,
6+
get_screen_size, parse_url, pick_file, plot_stats_in_tracy, winit_to_ruffle_key_code,
7+
winit_to_ruffle_text_control,
88
};
99
use anyhow::{Context, Error};
1010
use ruffle_core::{PlayerEvent, StageDisplayState};
@@ -14,8 +14,9 @@ use std::rc::Rc;
1414
use std::time::{Duration, Instant};
1515
use url::Url;
1616
use winit::dpi::{LogicalSize, PhysicalPosition, PhysicalSize, Size};
17-
use winit::event::{ElementState, KeyboardInput, ModifiersState, VirtualKeyCode, WindowEvent};
17+
use winit::event::{ElementState, KeyEvent, Modifiers, WindowEvent};
1818
use winit::event_loop::{ControlFlow, EventLoop, EventLoopBuilder};
19+
use winit::keyboard::{Key, NamedKey};
1920
use winit::window::{Fullscreen, Icon, Window, WindowBuilder};
2021

2122
pub struct App {
@@ -35,7 +36,7 @@ impl App {
3536
let icon =
3637
Icon::from_rgba(icon_bytes.to_vec(), 32, 32).context("Couldn't load app icon")?;
3738

38-
let event_loop = EventLoopBuilder::with_user_event().build();
39+
let event_loop = EventLoopBuilder::with_user_event().build()?;
3940

4041
let min_window_size = (16, if opt.no_gui { 16 } else { MENU_HEIGHT + 16 }).into();
4142
let max_window_size = get_screen_size(&event_loop);
@@ -78,7 +79,7 @@ impl App {
7879
})
7980
}
8081

81-
pub fn run(mut self) -> ! {
82+
pub fn run(mut self) -> Result<(), Error> {
8283
enum LoadingState {
8384
Loading,
8485
WaitingForResize,
@@ -89,7 +90,7 @@ impl App {
8990
let mut time = Instant::now();
9091
let mut next_frame_time = None;
9192
let mut minimized = false;
92-
let mut modifiers = ModifiersState::empty();
93+
let mut modifiers = Modifiers::default();
9394
let mut fullscreen_down = false;
9495

9596
if self.opt.movie_url.is_none() {
@@ -100,10 +101,10 @@ impl App {
100101

101102
// Poll UI events.
102103
let event_loop = self.event_loop.take().expect("App already running");
103-
event_loop.run(move |event, _window_target, control_flow| {
104+
event_loop.run(move |event, elwt| {
104105
let mut check_redraw = false;
105106
match event {
106-
winit::event::Event::LoopDestroyed => {
107+
winit::event::Event::LoopExiting => {
107108
if let Some(mut player) = self.player.get() {
108109
player.flush_shared_objects();
109110
}
@@ -112,9 +113,9 @@ impl App {
112113
}
113114

114115
// Core loop
115-
winit::event::Event::MainEventsCleared
116-
if matches!(loaded, LoadingState::Loaded) =>
117-
{
116+
// [NA] This used to be called `MainEventsCleared`, but I think the behaviour is different now.
117+
// We should look at changing our tick to happen somewhere else if we see any behavioural problems.
118+
winit::event::Event::AboutToWait if matches!(loaded, LoadingState::Loaded) => {
118119
let new_time = Instant::now();
119120
let dt = new_time.duration_since(time).as_micros();
120121
if dt > 0 {
@@ -130,7 +131,10 @@ impl App {
130131
}
131132

132133
// Render
133-
winit::event::Event::RedrawRequested(_) => {
134+
winit::event::Event::WindowEvent {
135+
event: WindowEvent::RedrawRequested,
136+
..
137+
} => {
134138
// Don't render when minimized to avoid potential swap chain errors in `wgpu`.
135139
if !minimized {
136140
if let Some(mut player) = self.player.get() {
@@ -156,7 +160,7 @@ impl App {
156160
};
157161
match event {
158162
WindowEvent::CloseRequested => {
159-
*control_flow = ControlFlow::Exit;
163+
elwt.exit();
160164
return;
161165
}
162166
WindowEvent::Resized(size) => {
@@ -211,7 +215,7 @@ impl App {
211215
MouseButton::Left => RuffleMouseButton::Left,
212216
MouseButton::Right => RuffleMouseButton::Right,
213217
MouseButton::Middle => RuffleMouseButton::Middle,
214-
MouseButton::Other(_) => RuffleMouseButton::Unknown,
218+
_ => RuffleMouseButton::Unknown,
215219
};
216220
let event = match state {
217221
ElementState::Pressed => PlayerEvent::MouseDown { x, y, button },
@@ -260,14 +264,14 @@ impl App {
260264
WindowEvent::ModifiersChanged(new_modifiers) => {
261265
modifiers = new_modifiers;
262266
}
263-
WindowEvent::KeyboardInput { input, .. } => {
267+
WindowEvent::KeyboardInput { event, .. } => {
264268
// Handle fullscreen keyboard shortcuts: Alt+Return, Escape.
265-
match input {
266-
KeyboardInput {
269+
match event {
270+
KeyEvent {
267271
state: ElementState::Pressed,
268-
virtual_keycode: Some(VirtualKeyCode::Return),
272+
logical_key: Key::Named(NamedKey::Enter),
269273
..
270-
} if modifiers.alt() => {
274+
} if modifiers.state().alt_key() => {
271275
if !fullscreen_down {
272276
if let Some(mut player) = self.player.get() {
273277
player.update(|uc| {
@@ -278,16 +282,16 @@ impl App {
278282
fullscreen_down = true;
279283
return;
280284
}
281-
KeyboardInput {
285+
KeyEvent {
282286
state: ElementState::Released,
283-
virtual_keycode: Some(VirtualKeyCode::Return),
287+
logical_key: Key::Named(NamedKey::Enter),
284288
..
285289
} if fullscreen_down => {
286290
fullscreen_down = false;
287291
}
288-
KeyboardInput {
292+
KeyEvent {
289293
state: ElementState::Pressed,
290-
virtual_keycode: Some(VirtualKeyCode::Escape),
294+
logical_key: Key::Named(NamedKey::Escape),
291295
..
292296
} => {
293297
if let Some(mut player) = self.player.get() {
@@ -304,38 +308,42 @@ impl App {
304308
_ => (),
305309
}
306310

307-
if let Some(key) = input.virtual_keycode {
308-
let key_code = winit_to_ruffle_key_code(key);
309-
let key_char = winit_key_to_char(key, modifiers.shift());
310-
match input.state {
311-
ElementState::Pressed => {
312-
self.player.handle_event(PlayerEvent::KeyDown {
313-
key_code,
314-
key_char,
311+
let key_code = winit_to_ruffle_key_code(&event);
312+
// [NA] TODO: This event used to give a single char. `last()` is functionally the same,
313+
// but we may want to be better at this in the future.
314+
let key_char = event.text.clone().and_then(|text| text.chars().last());
315+
let mut allow_text = true;
316+
317+
match &event.state {
318+
ElementState::Pressed => {
319+
self.player
320+
.handle_event(PlayerEvent::KeyDown { key_code, key_char });
321+
if let Some(control_code) =
322+
winit_to_ruffle_text_control(&event, &modifiers)
323+
{
324+
self.player.handle_event(PlayerEvent::TextControl {
325+
code: control_code,
315326
});
316-
if let Some(control_code) =
317-
winit_to_ruffle_text_control(key, modifiers)
318-
{
319-
self.player.handle_event(PlayerEvent::TextControl {
320-
code: control_code,
321-
});
322-
}
327+
allow_text = false;
323328
}
324-
ElementState::Released => {
325-
self.player.handle_event(PlayerEvent::KeyUp {
326-
key_code,
327-
key_char,
328-
});
329+
}
330+
ElementState::Released => {
331+
self.player
332+
.handle_event(PlayerEvent::KeyUp { key_code, key_char });
333+
}
334+
};
335+
check_redraw = true;
336+
337+
if allow_text {
338+
if let Some(text) = event.text {
339+
for codepoint in text.chars() {
340+
self.player
341+
.handle_event(PlayerEvent::TextInput { codepoint });
329342
}
330-
};
331-
check_redraw = true;
343+
check_redraw = true;
344+
}
332345
}
333346
}
334-
WindowEvent::ReceivedCharacter(codepoint) => {
335-
let event = PlayerEvent::TextInput { codepoint };
336-
self.player.handle_event(event);
337-
check_redraw = true;
338-
}
339347
_ => (),
340348
}
341349
}
@@ -385,7 +393,7 @@ impl App {
385393
self.window.scale_factor(),
386394
);
387395

388-
self.window.set_inner_size(window_size);
396+
let _ = self.window.request_inner_size(window_size);
389397
self.window.set_fullscreen(if self.opt.fullscreen {
390398
Some(Fullscreen::Borderless(None))
391399
} else {
@@ -441,7 +449,7 @@ impl App {
441449
}
442450

443451
winit::event::Event::UserEvent(RuffleEvent::ExitRequested) => {
444-
*control_flow = ControlFlow::Exit;
452+
elwt.exit();
445453
return;
446454
}
447455

@@ -458,7 +466,7 @@ impl App {
458466
}
459467

460468
// After polling events, sleep the event loop until the next event or the next frame.
461-
*control_flow = if matches!(loaded, LoadingState::Loaded) {
469+
elwt.set_control_flow(if matches!(loaded, LoadingState::Loaded) {
462470
if let Some(next_frame_time) = next_frame_time {
463471
ControlFlow::WaitUntil(next_frame_time)
464472
} else {
@@ -468,7 +476,8 @@ impl App {
468476
}
469477
} else {
470478
ControlFlow::Wait
471-
};
472-
});
479+
});
480+
})?;
481+
Ok(())
473482
}
474483
}

desktop/src/gui/controller.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use winit::window::{Theme, Window};
2323
/// Integration layer connecting wgpu+winit to egui.
2424
pub struct GuiController {
2525
descriptors: Arc<Descriptors>,
26-
egui_ctx: egui::Context,
2726
egui_winit: egui_winit::State,
2827
egui_renderer: egui_wgpu::renderer::Renderer,
2928
gui: RuffleGui,
@@ -92,7 +91,8 @@ impl GuiController {
9291
egui_ctx.set_visuals(egui::Visuals::light());
9392
}
9493

95-
let mut egui_winit = egui_winit::State::new(ViewportId::ROOT, window.as_ref(), None, None);
94+
let mut egui_winit =
95+
egui_winit::State::new(egui_ctx, ViewportId::ROOT, window.as_ref(), None, None);
9696
egui_winit.set_max_texture_side(descriptors.limits.max_texture_dimension_2d as usize);
9797

9898
let movie_view_renderer = Arc::new(MovieViewRenderer::new(
@@ -107,13 +107,12 @@ impl GuiController {
107107
let gui = RuffleGui::new(event_loop, opt.movie_url.clone(), PlayerOptions::from(opt));
108108
let system_fonts =
109109
load_system_fonts(font_database, gui.locale.to_owned()).unwrap_or_default();
110-
egui_ctx.set_fonts(system_fonts);
110+
egui_winit.egui_ctx().set_fonts(system_fonts);
111111

112-
egui_extras::install_image_loaders(&egui_ctx);
112+
egui_extras::install_image_loaders(egui_winit.egui_ctx());
113113

114114
Ok(Self {
115115
descriptors: Arc::new(descriptors),
116-
egui_ctx,
117116
egui_winit,
118117
egui_renderer,
119118
gui,
@@ -163,10 +162,10 @@ impl GuiController {
163162
Theme::Dark => egui::Visuals::dark(),
164163
Theme::Light => egui::Visuals::light(),
165164
};
166-
self.egui_ctx.set_visuals(visuals);
165+
self.egui_winit.egui_ctx().set_visuals(visuals);
167166
}
168167

169-
let response = self.egui_winit.on_window_event(&self.egui_ctx, event);
168+
let response = self.egui_winit.on_window_event(&self.window, event);
170169
if response.repaint {
171170
self.window.request_redraw();
172171
}
@@ -203,7 +202,7 @@ impl GuiController {
203202

204203
let raw_input = self.egui_winit.take_egui_input(&self.window);
205204
let show_menu = self.window.fullscreen().is_none() && !self.no_gui;
206-
let mut full_output = self.egui_ctx.run(raw_input, |context| {
205+
let mut full_output = self.egui_winit.egui_ctx().run(raw_input, |context| {
207206
self.gui.update(
208207
context,
209208
show_menu,
@@ -222,7 +221,7 @@ impl GuiController {
222221
.repaint_delay;
223222

224223
// If we're not in a UI, tell egui which cursor we prefer to use instead
225-
if !self.egui_ctx.wants_pointer_input() {
224+
if !self.egui_winit.egui_ctx().wants_pointer_input() {
226225
if let Some(player) = player.as_deref() {
227226
full_output.platform_output.cursor_icon = player
228227
.ui()
@@ -231,14 +230,12 @@ impl GuiController {
231230
.cursor();
232231
}
233232
}
234-
self.egui_winit.handle_platform_output(
235-
&self.window,
236-
&self.egui_ctx,
237-
full_output.platform_output,
238-
);
233+
self.egui_winit
234+
.handle_platform_output(&self.window, full_output.platform_output);
239235

240236
let clipped_primitives = self
241-
.egui_ctx
237+
.egui_winit
238+
.egui_ctx()
242239
.tessellate(full_output.shapes, full_output.pixels_per_point);
243240

244241
let scale_factor = self.window.scale_factor() as f32;

desktop/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ fn main() -> Result<(), Error> {
159159
let result = if opt.timedemo {
160160
time_demo::run_timedemo(opt)
161161
} else {
162-
App::new(opt).map(|app| app.run())
162+
App::new(opt).and_then(|app| app.run())
163163
};
164164
#[cfg(windows)]
165165
if let Err(error) = &result {

0 commit comments

Comments
 (0)