Skip to content

Commit 13f2e18

Browse files
committed
Update to work with winit 0.29.15.
1 parent 4937dfe commit 13f2e18

File tree

14 files changed

+184
-210
lines changed

14 files changed

+184
-210
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pin-project-lite = "0.2.9"
2020
raw-window-handle = "0.5.2"
2121
slab = "0.4.8"
2222
unsend = { version = "0.2.1", default-features = false, features = ["alloc"] }
23-
winit = { version = "0.28.3", default-features = false }
23+
winit = { version = "0.29.15", default-features = false, features = ["rwh_05"] }
2424

2525
[build-dependencies]
2626
cfg_aliases = "0.1.1"
@@ -29,7 +29,7 @@ cfg_aliases = "0.1.1"
2929
async-channel = "1.8.0"
3030
futures-lite = { version = "1.13.0", features = ["std"], default-features = false }
3131
softbuffer = { version = "0.2.0", default-features = false, features = ["x11"] }
32-
winit = { version = "0.28.3", default-features = false, features = ["x11"] }
32+
winit = { version = "0.29.15", default-features = false, features = ["rwh_05", "x11"] }
3333

3434
[features]
3535
default = ["wayland", "wayland-dlopen", "x11"]

smol_example/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ fn main2(event_loop: EventLoop<ThreadUnsafe>) {
177177
target.exit().await;
178178
}
179179
}
180-
});
180+
}).unwrap();
181181
}
182182

183183
async fn make_url_queries<'a>(

src/event_loop.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ use raw_window_handle::{HasRawDisplayHandle, RawDisplayHandle};
6262
use winit::event_loop::EventLoopProxy;
6363

6464
#[doc(inline)]
65-
pub use winit::event_loop::{ControlFlow, DeviceEventFilter, EventLoopClosed};
65+
pub use winit::event_loop::{ControlFlow, EventLoopClosed};
6666

6767
/// Used to indicate that we need to wake up the event loop.
6868
///
@@ -178,7 +178,7 @@ impl EventLoopBuilder {
178178
///
179179
/// [`platform`]: crate::platform
180180
pub fn build<TS: ThreadSafety>(&mut self) -> EventLoop<TS> {
181-
let inner = self.inner.build();
181+
let inner = self.inner.build().unwrap();
182182
EventLoop {
183183
window_target: EventLoopWindowTarget {
184184
reactor: Reactor::<TS>::get(),
@@ -291,18 +291,6 @@ impl<TS: ThreadSafety> EventLoopWindowTarget<TS> {
291291
.await;
292292
rx.recv().await.into_iter()
293293
}
294-
295-
/// Set the device event filter.
296-
#[inline]
297-
pub async fn set_device_event_filter(&self, filter: DeviceEventFilter) {
298-
let (tx, rx) = crate::oneoff::oneoff();
299-
self.reactor
300-
.push_event_loop_op(EventLoopOp::SetDeviceFilter { filter, waker: tx })
301-
.await;
302-
303-
// Wait for the filter to be set.
304-
rx.recv().await;
305-
}
306294
}
307295

308296
unsafe impl<TS: ThreadSafety> HasRawDisplayHandle for EventLoopWindowTarget<TS> {
@@ -320,14 +308,14 @@ impl<TS: ThreadSafety + 'static> EventLoop<TS> {
320308

321309
/// Block on a future forever.
322310
#[inline]
323-
pub fn block_on(self, future: impl Future<Output = Infallible> + 'static) -> ! {
311+
pub fn block_on(self, future: impl Future<Output = Infallible> + 'static) -> Result<(), winit::error::EventLoopError> {
324312
let inner = self.inner;
325313

326314
let mut future = Box::pin(future);
327315
let mut filter = crate::filter::Filter::<TS>::new(&inner);
328316

329-
inner.run(move |event, elwt, flow| {
330-
filter.handle_event(future.as_mut(), event, elwt, flow);
317+
inner.run(move |event, elwt| {
318+
filter.handle_event(future.as_mut(), event, elwt);
331319
})
332320
}
333321
}

src/filter.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,8 @@ impl<TS: ThreadSafety> Filter<TS> {
126126
pub fn handle_event<F>(
127127
&mut self,
128128
future: Pin<&mut F>,
129-
event: Event<'_, Wakeup>,
129+
event: Event<Wakeup>,
130130
elwt: &EventLoopWindowTarget<Wakeup>,
131-
flow: &mut ControlFlow,
132131
) -> ReturnOrFinish<(), F::Output>
133132
where
134133
F: Future,
@@ -159,14 +158,6 @@ impl<TS: ThreadSafety> Filter<TS> {
159158
false
160159
}
161160

162-
Event::RedrawEventsCleared => {
163-
// We are about to fall asleep, so make sure that the future knows it.
164-
self.notifier.awake.store(false, Ordering::SeqCst);
165-
166-
// We are about to fall asleep.
167-
true
168-
}
169-
170161
_ => {
171162
// We are not about to fall asleep.
172163
false
@@ -250,18 +241,18 @@ impl<TS: ThreadSafety> Filter<TS> {
250241
}
251242

252243
// Set the control flow.
253-
if let Some(code) = self.reactor.exit_requested() {
244+
if let Some(_code) = self.reactor.exit_requested() {
254245
// The user wants to exit.
255-
flow.set_exit_with_code(code);
246+
elwt.exit();
256247
} else if self.yielding {
257248
// The future wants to be polled again as soon as possible.
258-
flow.set_poll();
249+
elwt.set_control_flow(ControlFlow::Poll);
259250
} else if let Some(deadline) = self.deadline {
260251
// The future wants to be polled again when the deadline is reached.
261-
flow.set_wait_until(deadline);
252+
elwt.set_control_flow(ControlFlow::WaitUntil(deadline));
262253
} else {
263254
// The future wants to poll.
264-
flow.set_wait();
255+
elwt.set_control_flow(ControlFlow::Wait);
265256
}
266257

267258
// Return the output if any.

src/handler.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,10 +537,12 @@ impl<T: Clone + 'static> Event for T {
537537
}
538538
}
539539

540+
/*
540541
struct CallOnDrop<F: FnMut()>(F);
541542
542543
impl<F: FnMut()> Drop for CallOnDrop<F> {
543544
fn drop(&mut self) {
544545
(self.0)();
545546
}
546547
}
548+
*/

src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ pub mod filter;
3131
pub mod platform;
3232
pub mod window;
3333

34+
pub mod keyboard {
35+
#[doc(inline)]
36+
pub use winit::keyboard::*;
37+
}
38+
3439
pub mod event {
3540
#[doc(inline)]
3641
pub use winit::event::*;

src/platform.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ cfg_if::cfg_if! {
6868
}
6969

7070
mod __private {
71-
use crate::event_loop::{EventLoop, EventLoopBuilder, EventLoopWindowTarget};
71+
use crate::event_loop::{EventLoopBuilder, EventLoopWindowTarget};
7272
use crate::window::{Window, WindowBuilder};
7373

7474
#[doc(hidden)]
@@ -107,7 +107,7 @@ mod __private {
107107

108108
sealed_trait_with_gen! {
109109
EventLoopWindowTarget EventLoopWindowTargetPrivate
110-
EventLoop EventLoopPrivate
110+
//EventLoop EventLoopPrivate
111111
Window WindowPrivate
112112
}
113113
}

src/platform/run_return.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,24 @@ use futures_lite::pin;
2828
use std::future::Future;
2929

3030
/// Additional methods on [`EventLoop`] to return control flow to the caller.
31-
pub trait EventLoopExtRunReturn {
31+
pub trait EventLoopExtRunOnDemand {
3232
/// Initializes the `winit` event loop.
3333
///
3434
/// Unlike [`EventLoop::block_on`], this function accepts non-`'static` (i.e. non-`move`) closures
3535
/// and returns control flow to the caller when `control_flow` is set to [`ControlFlow::Exit`].
3636
///
3737
/// [`ControlFlow::Exit`]: crate::event_loop::ControlFlow::Exit
38-
fn block_on_return<F>(&mut self, future: F) -> ReturnOrFinish<i32, F::Output>
38+
fn block_on_demand<F>(&mut self, future: F) -> ReturnOrFinish<Result<(), winit::error::EventLoopError>, F::Output>
3939
where
4040
F: Future;
4141
}
4242

43-
impl<TS: ThreadSafety> EventLoopExtRunReturn for EventLoop<TS> {
44-
fn block_on_return<F>(&mut self, fut: F) -> ReturnOrFinish<i32, F::Output>
43+
impl<TS: ThreadSafety> EventLoopExtRunOnDemand for EventLoop<TS> {
44+
fn block_on_demand<F>(&mut self, fut: F) -> ReturnOrFinish<Result<(), winit::error::EventLoopError>, F::Output>
4545
where
4646
F: Future,
4747
{
48-
use winit::platform::run_return::EventLoopExtRunReturn as _;
48+
use winit::platform::run_on_demand::EventLoopExtRunOnDemand as _;
4949

5050
let inner = &mut self.inner;
5151

@@ -54,12 +54,12 @@ impl<TS: ThreadSafety> EventLoopExtRunReturn for EventLoop<TS> {
5454
let mut filter = Filter::<TS>::new(inner);
5555

5656
let mut output = None;
57-
let exit = inner.run_return({
57+
let exit = inner.run_on_demand({
5858
let output = &mut output;
59-
move |event, elwt, flow| match filter.handle_event(fut.as_mut(), event, elwt, flow) {
59+
move |event, elwt| match filter.handle_event(fut.as_mut(), event, elwt) {
6060
ReturnOrFinish::FutureReturned(out) => {
6161
*output = Some(out);
62-
flow.set_exit()
62+
elwt.exit();
6363
}
6464

6565
ReturnOrFinish::Output(()) => {}

src/platform/wayland.rs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::window::{Window, WindowBuilder};
2929
use std::os::raw;
3030

3131
use winit::platform::wayland::{
32-
EventLoopBuilderExtWayland as _, WindowBuilderExtWayland as _, WindowExtWayland as _,
32+
EventLoopBuilderExtWayland as _, WindowBuilderExtWayland as _,
3333
};
3434

3535
#[doc(inline)]
@@ -95,31 +95,9 @@ impl EventLoopBuilderExtWayland for EventLoopBuilder {
9595
///
9696
/// [`Window`]: crate::window::Window
9797
pub trait WindowExtWayland: sealed::WindowPrivate {
98-
/// Returns a pointer to the `wl_surface` object of wayland that is used by this window.
99-
///
100-
/// Returns `None` if the window doesn't use wayland (if it uses xlib for example).
101-
///
102-
/// The pointer will become invalid when the [`Window`] is destroyed.
103-
fn wayland_surface(&self) -> Option<*mut raw::c_void>;
104-
105-
/// Returns a pointer to the `wl_display` object of wayland that is used by this window.
106-
///
107-
/// Returns `None` if the window doesn't use wayland (if it uses xlib for example).
108-
///
109-
/// The pointer will become invalid when the [`Window`] is destroyed.
110-
fn wayland_display(&self) -> Option<*mut raw::c_void>;
11198
}
11299

113100
impl<TS: ThreadSafety> WindowExtWayland for Window<TS> {
114-
#[inline]
115-
fn wayland_surface(&self) -> Option<*mut raw::c_void> {
116-
self.window().wayland_surface()
117-
}
118-
119-
#[inline]
120-
fn wayland_display(&self) -> Option<*mut raw::c_void> {
121-
self.window().wayland_display()
122-
}
123101
}
124102

125103
/// Additional methods on [`WindowBuilder`] that are specific to Wayland.

src/platform/x11.rs

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ use crate::event_loop::{EventLoopBuilder, EventLoopWindowTarget};
2626
use crate::sync::ThreadSafety;
2727
use crate::window::{Window, WindowBuilder};
2828

29-
use std::os::raw;
30-
3129
use winit::dpi::Size;
32-
use winit::platform::x11::{EventLoopBuilderExtX11 as _, WindowExtX11 as _};
30+
use winit::platform::x11::EventLoopBuilderExtX11 as _;
3331

3432
#[doc(inline)]
3533
pub use winit::platform::x11::{register_xlib_error_hook, XWindowType, XlibErrorHook};
@@ -81,44 +79,9 @@ impl EventLoopBuilderExtX11 for EventLoopBuilder {
8179
///
8280
/// [`Window`]: crate::window::Window
8381
pub trait WindowExtX11: sealed::WindowPrivate {
84-
/// Returns the ID of the [`Window`] xlib object that is used by this window.
85-
///
86-
/// Returns `None` if the window doesn't use xlib (if it uses wayland for example).
87-
fn xlib_window(&self) -> Option<raw::c_ulong>;
88-
89-
/// Returns a pointer to the `Display` object of xlib that is used by this window.
90-
///
91-
/// Returns `None` if the window doesn't use xlib (if it uses wayland for example).
92-
///
93-
/// The pointer will become invalid when the [`Window`] is destroyed.
94-
fn xlib_display(&self) -> Option<*mut raw::c_void>;
95-
96-
fn xlib_screen_id(&self) -> Option<raw::c_int>;
97-
98-
/// This function returns the underlying `xcb_connection_t` of an xlib `Display`.
99-
///
100-
/// Returns `None` if the window doesn't use xlib (if it uses wayland for example).
101-
///
102-
/// The pointer will become invalid when the [`Window`] is destroyed.
103-
fn xcb_connection(&self) -> Option<*mut raw::c_void>;
10482
}
10583

10684
impl<TS: ThreadSafety> WindowExtX11 for Window<TS> {
107-
fn xcb_connection(&self) -> Option<*mut raw::c_void> {
108-
self.window().xcb_connection()
109-
}
110-
111-
fn xlib_display(&self) -> Option<*mut raw::c_void> {
112-
self.window().xlib_display()
113-
}
114-
115-
fn xlib_screen_id(&self) -> Option<raw::c_int> {
116-
self.window().xlib_screen_id()
117-
}
118-
119-
fn xlib_window(&self) -> Option<raw::c_ulong> {
120-
self.window().xlib_window()
121-
}
12285
}
12386

12487
/// Additional methods on [`WindowBuilder`] that are specific to X11.

0 commit comments

Comments
 (0)