Skip to content

Commit 8500dc6

Browse files
committed
chore: Update to winit 0.31
1 parent 8e13fce commit 8500dc6

8 files changed

Lines changed: 506 additions & 455 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ futures-channel = "0.3"
4545
euclid = "0.22"
4646

4747
lilt = "0.8"
48-
winit = "0.30"
48+
winit = "0.31.0-beta.2"
4949
dpi = "0.1"
5050
rfd = "0.17"
5151
cpal = "0.17"

neothesia/src/context.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,37 @@ use crate::{
66
};
77
use neothesia_core::render::{QuadRendererFactory, TextRendererFactory};
88
use wgpu_jumpstart::{Gpu, Uniform};
9-
use winit::event_loop::EventLoopProxy;
109

1110
use winit::window::Window;
1211

12+
#[derive(Clone)]
13+
pub struct EventLoopProxy {
14+
proxy: winit::event_loop::EventLoopProxy,
15+
tx: std::sync::mpsc::Sender<NeothesiaEvent>,
16+
}
17+
18+
impl EventLoopProxy {
19+
pub fn new(
20+
proxy: winit::event_loop::EventLoopProxy,
21+
) -> (Self, std::sync::mpsc::Receiver<NeothesiaEvent>) {
22+
let (tx, rx) = std::sync::mpsc::channel();
23+
24+
(Self { proxy, tx }, rx)
25+
}
26+
27+
pub fn send_event(&self, event: NeothesiaEvent) -> Result<(), ()> {
28+
if let Err(err) = self.tx.send(event) {
29+
log::error!("winit event send: {err}");
30+
// TODO: Drop this once winit 0.31 is stable and merge conflits are no longer a concern
31+
return Err(());
32+
}
33+
self.proxy.wake_up();
34+
Ok(())
35+
}
36+
}
37+
1338
pub struct Context {
14-
pub window: Arc<Window>,
39+
pub window: Arc<dyn Window>,
1540

1641
pub window_state: WindowState,
1742
pub gpu: Gpu,
@@ -24,7 +49,7 @@ pub struct Context {
2449
pub input_manager: InputManager,
2550
pub config: Config,
2651

27-
pub proxy: EventLoopProxy<NeothesiaEvent>,
52+
pub proxy: EventLoopProxy,
2853

2954
/// Last frame timestamp
3055
pub frame_timestamp: std::time::Instant,
@@ -41,9 +66,9 @@ impl Drop for Context {
4166

4267
impl Context {
4368
pub fn new(
44-
window: Arc<Window>,
69+
window: Arc<dyn Window>,
4570
window_state: WindowState,
46-
proxy: EventLoopProxy<NeothesiaEvent>,
71+
proxy: EventLoopProxy,
4772
gpu: Gpu,
4873
) -> Self {
4974
let transform_uniform = Uniform::new(

neothesia/src/input_manager/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
use midi_file::midly::{self, MidiMessage, live::LiveEvent};
2-
use winit::event_loop::EventLoopProxy;
32

4-
use crate::NeothesiaEvent;
3+
use crate::{NeothesiaEvent, context::EventLoopProxy};
54

65
pub struct InputManager {
76
input: midi_io::MidiInputManager,
8-
tx: EventLoopProxy<NeothesiaEvent>,
7+
tx: EventLoopProxy,
98
current_connection: Option<midi_io::MidiInputConnection>,
109
}
1110

1211
impl InputManager {
13-
pub fn new(tx: EventLoopProxy<NeothesiaEvent>) -> Self {
12+
pub fn new(tx: EventLoopProxy) -> Self {
1413
let input = midi_io::MidiInputManager::new().unwrap();
1514
Self {
1615
input,

0 commit comments

Comments
 (0)