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

desktop: Update winit to 0.29.10 and egui to 0.25.0 #14703

Merged
merged 1 commit into from
Jan 16, 2024
Merged
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
534 changes: 303 additions & 231 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
naga = { version = "0.14.2", features = ["validate", "wgsl-out"] }
naga_oil = "0.11.0"
wgpu = "0.18.0"
egui = "0.24.1"
egui = "0.25.0"

[workspace.lints.rust]
# Clippy nightly often adds new/buggy lints that we want to ignore.
Expand Down Expand Up @@ -99,3 +99,9 @@ inherits = "release"
# is not yet in the latest wgpu release. TODO: Remove when it is.
wgpu = { git = "https://github.com/gfx-rs/wgpu", branch = "v0.18" }
naga = { git = "https://github.com/gfx-rs/wgpu", branch = "v0.18" }

# https://github.com/emilk/egui/pull/3812
egui = { git = "https://github.com/ruffle-rs/egui", branch = "consume_keys"}
egui_extras = { git = "https://github.com/ruffle-rs/egui", branch = "consume_keys"}
egui-winit = { git = "https://github.com/ruffle-rs/egui", branch = "consume_keys"}
egui-wgpu = { git = "https://github.com/ruffle-rs/egui", branch = "consume_keys"}
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ hashbrown = { version = "0.14.3", features = ["raw"] }
scopeguard = "1.2.0"
fluent-templates = "0.8.0"
egui = { workspace = true, optional = true }
egui_extras = { version = "0.24.2", optional = true }
egui_extras = { version = "0.25.0", optional = true }
png = { version = "0.17.11", optional = true }
flv-rs = { path = "../flv" }
async-channel = "2.1.1"
Expand Down
8 changes: 4 additions & 4 deletions desktop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ workspace = true
clap = { version = "4.4.17", features = ["derive"] }
cpal = "0.15.2"
egui = { workspace = true }
egui_extras = { version = "0.24.2", features = ["image"] }
egui-wgpu = { version = "0.24.1", features = ["winit"] }
egui_extras = { version = "0.25.0", features = ["image"] }
egui-wgpu = { version = "0.25.0", features = ["winit"] }
image = { version = "0.24", features = ["png"] }
egui-winit = "0.24.1"
egui-winit = "0.25.0"
fontdb = "0.16"
ruffle_core = { path = "../core", features = ["audio", "clap", "mp3", "nellymoser", "default_compatibility_rules", "egui"] }
ruffle_render = { path = "../render", features = ["clap"] }
Expand All @@ -26,7 +26,7 @@ ruffle_video_software = { path = "../video/software", optional = true }
tracing = { workspace = true}
tracing-subscriber = { workspace = true }
generational-arena = "0.2.9"
winit = "0.28.7"
winit = "0.29.10"
webbrowser = "0.8.12"
url = "2.5.0"
arboard = { version = "3.3.0", features = ["wayland-data-control"] }
Expand Down
119 changes: 64 additions & 55 deletions desktop/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::custom_event::RuffleEvent;
use crate::gui::{GuiController, MENU_HEIGHT};
use crate::player::{PlayerController, PlayerOptions};
use crate::util::{
get_screen_size, parse_url, pick_file, plot_stats_in_tracy, winit_key_to_char,
winit_to_ruffle_key_code, winit_to_ruffle_text_control,
get_screen_size, parse_url, pick_file, plot_stats_in_tracy, winit_to_ruffle_key_code,
winit_to_ruffle_text_control,
};
use anyhow::{Context, Error};
use ruffle_core::{PlayerEvent, StageDisplayState};
Expand All @@ -14,8 +14,9 @@ use std::rc::Rc;
use std::time::{Duration, Instant};
use url::Url;
use winit::dpi::{LogicalSize, PhysicalPosition, PhysicalSize, Size};
use winit::event::{ElementState, KeyboardInput, ModifiersState, VirtualKeyCode, WindowEvent};
use winit::event::{ElementState, KeyEvent, Modifiers, WindowEvent};
use winit::event_loop::{ControlFlow, EventLoop, EventLoopBuilder};
use winit::keyboard::{Key, NamedKey};
use winit::window::{Fullscreen, Icon, Window, WindowBuilder};

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

let event_loop = EventLoopBuilder::with_user_event().build();
let event_loop = EventLoopBuilder::with_user_event().build()?;

let min_window_size = (16, if opt.no_gui { 16 } else { MENU_HEIGHT + 16 }).into();
let max_window_size = get_screen_size(&event_loop);
Expand Down Expand Up @@ -78,7 +79,7 @@ impl App {
})
}

pub fn run(mut self) -> ! {
pub fn run(mut self) -> Result<(), Error> {
enum LoadingState {
Loading,
WaitingForResize,
Expand All @@ -89,7 +90,7 @@ impl App {
let mut time = Instant::now();
let mut next_frame_time = None;
let mut minimized = false;
let mut modifiers = ModifiersState::empty();
let mut modifiers = Modifiers::default();
let mut fullscreen_down = false;

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

// Poll UI events.
let event_loop = self.event_loop.take().expect("App already running");
event_loop.run(move |event, _window_target, control_flow| {
event_loop.run(move |event, elwt| {
let mut check_redraw = false;
match event {
winit::event::Event::LoopDestroyed => {
winit::event::Event::LoopExiting => {
if let Some(mut player) = self.player.get() {
player.flush_shared_objects();
}
Expand All @@ -112,9 +113,9 @@ impl App {
}

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

// Render
winit::event::Event::RedrawRequested(_) => {
winit::event::Event::WindowEvent {
event: WindowEvent::RedrawRequested,
..
} => {
// Don't render when minimized to avoid potential swap chain errors in `wgpu`.
if !minimized {
if let Some(mut player) = self.player.get() {
Expand All @@ -156,7 +160,7 @@ impl App {
};
match event {
WindowEvent::CloseRequested => {
*control_flow = ControlFlow::Exit;
elwt.exit();
return;
}
WindowEvent::Resized(size) => {
Expand Down Expand Up @@ -211,7 +215,7 @@ impl App {
MouseButton::Left => RuffleMouseButton::Left,
MouseButton::Right => RuffleMouseButton::Right,
MouseButton::Middle => RuffleMouseButton::Middle,
MouseButton::Other(_) => RuffleMouseButton::Unknown,
_ => RuffleMouseButton::Unknown,
};
let event = match state {
ElementState::Pressed => PlayerEvent::MouseDown { x, y, button },
Expand Down Expand Up @@ -260,14 +264,14 @@ impl App {
WindowEvent::ModifiersChanged(new_modifiers) => {
modifiers = new_modifiers;
}
WindowEvent::KeyboardInput { input, .. } => {
WindowEvent::KeyboardInput { event, .. } => {
// Handle fullscreen keyboard shortcuts: Alt+Return, Escape.
match input {
KeyboardInput {
match event {
KeyEvent {
state: ElementState::Pressed,
virtual_keycode: Some(VirtualKeyCode::Return),
logical_key: Key::Named(NamedKey::Enter),
..
} if modifiers.alt() => {
} if modifiers.state().alt_key() => {
if !fullscreen_down {
if let Some(mut player) = self.player.get() {
player.update(|uc| {
Expand All @@ -278,16 +282,16 @@ impl App {
fullscreen_down = true;
return;
}
KeyboardInput {
KeyEvent {
state: ElementState::Released,
virtual_keycode: Some(VirtualKeyCode::Return),
logical_key: Key::Named(NamedKey::Enter),
..
} if fullscreen_down => {
fullscreen_down = false;
}
KeyboardInput {
KeyEvent {
state: ElementState::Pressed,
virtual_keycode: Some(VirtualKeyCode::Escape),
logical_key: Key::Named(NamedKey::Escape),
..
} => {
if let Some(mut player) = self.player.get() {
Expand All @@ -304,38 +308,42 @@ impl App {
_ => (),
}

if let Some(key) = input.virtual_keycode {
let key_code = winit_to_ruffle_key_code(key);
let key_char = winit_key_to_char(key, modifiers.shift());
match input.state {
ElementState::Pressed => {
self.player.handle_event(PlayerEvent::KeyDown {
key_code,
key_char,
let key_code = winit_to_ruffle_key_code(&event);
// [NA] TODO: This event used to give a single char. `last()` is functionally the same,
// but we may want to be better at this in the future.
let key_char = event.text.clone().and_then(|text| text.chars().last());
let mut allow_text = true;

match &event.state {
ElementState::Pressed => {
self.player
.handle_event(PlayerEvent::KeyDown { key_code, key_char });
if let Some(control_code) =
winit_to_ruffle_text_control(&event, &modifiers)
{
self.player.handle_event(PlayerEvent::TextControl {
code: control_code,
});
if let Some(control_code) =
winit_to_ruffle_text_control(key, modifiers)
{
self.player.handle_event(PlayerEvent::TextControl {
code: control_code,
});
}
allow_text = false;
}
ElementState::Released => {
self.player.handle_event(PlayerEvent::KeyUp {
key_code,
key_char,
});
}
ElementState::Released => {
self.player
.handle_event(PlayerEvent::KeyUp { key_code, key_char });
}
};
check_redraw = true;

if allow_text {
if let Some(text) = event.text {
for codepoint in text.chars() {
self.player
.handle_event(PlayerEvent::TextInput { codepoint });
}
};
check_redraw = true;
check_redraw = true;
}
}
}
WindowEvent::ReceivedCharacter(codepoint) => {
let event = PlayerEvent::TextInput { codepoint };
self.player.handle_event(event);
check_redraw = true;
}
_ => (),
}
}
Expand Down Expand Up @@ -385,7 +393,7 @@ impl App {
self.window.scale_factor(),
);

self.window.set_inner_size(window_size);
let _ = self.window.request_inner_size(window_size);
self.window.set_fullscreen(if self.opt.fullscreen {
Some(Fullscreen::Borderless(None))
} else {
Expand Down Expand Up @@ -441,7 +449,7 @@ impl App {
}

winit::event::Event::UserEvent(RuffleEvent::ExitRequested) => {
*control_flow = ControlFlow::Exit;
elwt.exit();
return;
}

Expand All @@ -458,7 +466,7 @@ impl App {
}

// After polling events, sleep the event loop until the next event or the next frame.
*control_flow = if matches!(loaded, LoadingState::Loaded) {
elwt.set_control_flow(if matches!(loaded, LoadingState::Loaded) {
if let Some(next_frame_time) = next_frame_time {
ControlFlow::WaitUntil(next_frame_time)
} else {
Expand All @@ -468,7 +476,8 @@ impl App {
}
} else {
ControlFlow::Wait
};
});
});
})?;
Ok(())
}
}
27 changes: 12 additions & 15 deletions desktop/src/gui/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use winit::window::{Theme, Window};
/// Integration layer connecting wgpu+winit to egui.
pub struct GuiController {
descriptors: Arc<Descriptors>,
egui_ctx: egui::Context,
egui_winit: egui_winit::State,
egui_renderer: egui_wgpu::renderer::Renderer,
gui: RuffleGui,
Expand Down Expand Up @@ -92,7 +91,8 @@ impl GuiController {
egui_ctx.set_visuals(egui::Visuals::light());
}

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

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

egui_extras::install_image_loaders(&egui_ctx);
egui_extras::install_image_loaders(egui_winit.egui_ctx());

Ok(Self {
descriptors: Arc::new(descriptors),
egui_ctx,
egui_winit,
egui_renderer,
gui,
Expand Down Expand Up @@ -163,10 +162,10 @@ impl GuiController {
Theme::Dark => egui::Visuals::dark(),
Theme::Light => egui::Visuals::light(),
};
self.egui_ctx.set_visuals(visuals);
self.egui_winit.egui_ctx().set_visuals(visuals);
}

let response = self.egui_winit.on_window_event(&self.egui_ctx, event);
let response = self.egui_winit.on_window_event(&self.window, event);
if response.repaint {
self.window.request_redraw();
}
Expand Down Expand Up @@ -203,7 +202,7 @@ impl GuiController {

let raw_input = self.egui_winit.take_egui_input(&self.window);
let show_menu = self.window.fullscreen().is_none() && !self.no_gui;
let mut full_output = self.egui_ctx.run(raw_input, |context| {
let mut full_output = self.egui_winit.egui_ctx().run(raw_input, |context| {
self.gui.update(
context,
show_menu,
Expand All @@ -222,7 +221,7 @@ impl GuiController {
.repaint_delay;

// If we're not in a UI, tell egui which cursor we prefer to use instead
if !self.egui_ctx.wants_pointer_input() {
if !self.egui_winit.egui_ctx().wants_pointer_input() {
if let Some(player) = player.as_deref() {
full_output.platform_output.cursor_icon = player
.ui()
Expand All @@ -231,14 +230,12 @@ impl GuiController {
.cursor();
}
}
self.egui_winit.handle_platform_output(
&self.window,
&self.egui_ctx,
full_output.platform_output,
);
self.egui_winit
.handle_platform_output(&self.window, full_output.platform_output);

let clipped_primitives = self
.egui_ctx
.egui_winit
.egui_ctx()
.tessellate(full_output.shapes, full_output.pixels_per_point);

let scale_factor = self.window.scale_factor() as f32;
Expand Down
2 changes: 1 addition & 1 deletion desktop/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fn main() -> Result<(), Error> {
let result = if opt.timedemo {
time_demo::run_timedemo(opt)
} else {
App::new(opt).map(|app| app.run())
App::new(opt).and_then(|app| app.run())
};
#[cfg(windows)]
if let Err(error) = &result {
Expand Down
Loading