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

Fix notgull/rwh06 #3129

Closed
Closed
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ And please only add new entries to the top of this list, right below the `# Unre

# Unreleased

- Renamed `EventLoopExtRunOnDemand` / `run_ondemand` to `EventLoopExtRunOnDemand` / `run_on_demand`.
- Make iOS `MonitorHandle` and `VideoMode` usable from other threads.
- On Web, `ControlFlow::WaitUntil` now uses the Prioritized Task Scheduling API. `setTimeout()`, with a trick to circumvent throttling to 4ms, is used as a fallback.
- On Web, never return a `MonitorHandle`.
Expand All @@ -26,6 +27,7 @@ And please only add new entries to the top of this list, right below the `# Unre
- On X11, fix event loop not waking up on `ControlFlow::Poll` and `ControlFlow::WaitUntil`.
- **Breaking:** Change default `ControlFlow` from `Poll` to `Wait`.
- **Breaking:** remove `DeviceEvent::Text`.
- On Android, fix `DeviceId` to contain device id's.

# 0.29.1-beta

Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ winit = "0.29.1-beta"

For features _within_ the scope of winit, see [FEATURES.md](FEATURES.md).

For features _outside_ the scope of winit, see [Missing features provided by other crates](https://github.com/rust-windowing/winit/wiki/Missing-features-provided-by-other-crates) in the wiki.
For features _outside_ the scope of winit, see [Are we GUI Yet?](https://areweguiyet.com/) and [Are we game yet?](https://arewegameyet.rs/), depending on what kind of project you're looking to do.

## Contact Us

Expand Down Expand Up @@ -67,8 +67,8 @@ Winit provides the following features, which can be enabled in your `Cargo.toml`

## MSRV Policy

The Minimum Supported Rust Version (MSRV) of this crate is **1.65**. Changes to
the MSRV will be accompanied by a minor version bump.
The Minimum Supported Rust Version (MSRV) of this crate is **1.65**. Changes to
the MSRV will be accompanied by a minor version bump.

As a **tentative** policy, the upper bound of the MSRV is given by the following
formula:
Expand All @@ -83,13 +83,13 @@ event of a major ecosystem shift or a security vulnerability.

[Debian Sid]: https://packages.debian.org/sid/rustc

The exception to this is for the Android platform, where a higher Rust version
must be used for certain Android features. In this case, the MSRV will be
capped at the latest stable version of Rust minus three. This inconsistency is
not reflected in Cargo metadata, as it is not powerful enough to expose this
The exception to this is for the Android platform, where a higher Rust version
must be used for certain Android features. In this case, the MSRV will be
capped at the latest stable version of Rust minus three. This inconsistency is
not reflected in Cargo metadata, as it is not powerful enough to expose this
restriction.

All crates in the [`rust-windowing`] organizations have the
All crates in the [`rust-windowing`] organizations have the
same MSRV policy.

[`rust-windowing`]: https://github.com/rust-windowing
Expand Down
4 changes: 2 additions & 2 deletions examples/window_ondemand.rs → examples/window_on_demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn main() -> Result<(), impl std::error::Error> {
error::EventLoopError,
event::{Event, WindowEvent},
event_loop::EventLoop,
platform::run_ondemand::EventLoopExtRunOnDemand,
platform::run_on_demand::EventLoopExtRunOnDemand,
window::{Window, WindowBuilder, WindowId},
};

Expand All @@ -30,7 +30,7 @@ fn main() -> Result<(), impl std::error::Error> {
fn run_app(event_loop: &mut EventLoop<()>, idx: usize) -> Result<(), EventLoopError> {
let mut app = App::default();

event_loop.run_ondemand(move |event, elwt| {
event_loop.run_on_demand(move |event, elwt| {
println!("Run {idx}: {:?}", event);

if let Some(window) = &app.window {
Expand Down
4 changes: 2 additions & 2 deletions src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//!
//! And the following platform-specific modules:
//!
//! - `run_ondemand` (available on `windows`, `unix`, `macos`, `android`)
//! - `run_on_demand` (available on `windows`, `unix`, `macos`, `android`)
//! - `pump_events` (available on `windows`, `unix`, `macos`, `android`)
//!
//! However only the module corresponding to the platform you're compiling to will be available.
Expand Down Expand Up @@ -42,7 +42,7 @@ pub mod x11;
x11_platform,
wayland_platform
))]
pub mod run_ondemand;
pub mod run_on_demand;

#[cfg(any(
windows_platform,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub trait EventLoopExtRunOnDemand {
/// to while maintaining the full state of your application. (If you need something like this
/// you can look at the [`EventLoopExtPumpEvents::pump_events()`] API)
///
/// Each time `run_ondemand` is called the `event_handler` can expect to receive a
/// Each time `run_on_demand` is called the `event_handler` can expect to receive a
/// `NewEvents(Init)` and `Resumed` event (even on platforms that have no suspend/resume
/// lifecycle) - which can be used to consistently initialize application state.
///
Expand Down Expand Up @@ -59,18 +59,18 @@ pub trait EventLoopExtRunOnDemand {
///
/// [`exit()`]: EventLoopWindowTarget::exit
/// [`set_control_flow()`]: EventLoopWindowTarget::set_control_flow
fn run_ondemand<F>(&mut self, event_handler: F) -> Result<(), EventLoopError>
fn run_on_demand<F>(&mut self, event_handler: F) -> Result<(), EventLoopError>
where
F: FnMut(Event<Self::UserEvent>, &EventLoopWindowTarget<Self::UserEvent>);
}

impl<T> EventLoopExtRunOnDemand for EventLoop<T> {
type UserEvent = T;

fn run_ondemand<F>(&mut self, event_handler: F) -> Result<(), EventLoopError>
fn run_on_demand<F>(&mut self, event_handler: F) -> Result<(), EventLoopError>
where
F: FnMut(Event<Self::UserEvent>, &EventLoopWindowTarget<Self::UserEvent>),
{
self.event_loop.run_ondemand(event_handler)
self.event_loop.run_on_demand(event_handler)
}
}
12 changes: 6 additions & 6 deletions src/platform_impl/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ impl<T: 'static> EventLoop<T> {
match event {
InputEvent::MotionEvent(motion_event) => {
let window_id = window::WindowId(WindowId);
let device_id = event::DeviceId(DeviceId);
let device_id = event::DeviceId(DeviceId(motion_event.device_id()));

let phase = match motion_event.action() {
MotionAction::Down | MotionAction::PointerDown => {
Expand Down Expand Up @@ -456,7 +456,7 @@ impl<T: 'static> EventLoop<T> {
let event = event::Event::WindowEvent {
window_id: window::WindowId(WindowId),
event: event::WindowEvent::KeyboardInput {
device_id: event::DeviceId(DeviceId),
device_id: event::DeviceId(DeviceId(key.device_id())),
event: event::KeyEvent {
state,
physical_key: keycodes::to_physical_keycode(keycode),
Expand Down Expand Up @@ -485,10 +485,10 @@ impl<T: 'static> EventLoop<T> {
where
F: FnMut(event::Event<T>, &event_loop::EventLoopWindowTarget<T>),
{
self.run_ondemand(event_handler)
self.run_on_demand(event_handler)
}

pub fn run_ondemand<F>(&mut self, mut event_handler: F) -> Result<(), EventLoopError>
pub fn run_on_demand<F>(&mut self, mut event_handler: F) -> Result<(), EventLoopError>
where
F: FnMut(event::Event<T>, &event_loop::EventLoopWindowTarget<T>),
{
Expand Down Expand Up @@ -748,11 +748,11 @@ impl From<u64> for WindowId {
}

#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct DeviceId;
pub struct DeviceId(i32);

impl DeviceId {
pub const fn dummy() -> Self {
DeviceId
DeviceId(0)
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/platform_impl/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,14 +795,14 @@ impl<T: 'static> EventLoop<T> {
where
F: FnMut(crate::event::Event<T>, &RootELW<T>),
{
self.run_ondemand(callback)
self.run_on_demand(callback)
}

pub fn run_ondemand<F>(&mut self, callback: F) -> Result<(), EventLoopError>
pub fn run_on_demand<F>(&mut self, callback: F) -> Result<(), EventLoopError>
where
F: FnMut(crate::event::Event<T>, &RootELW<T>),
{
x11_or_wayland!(match self; EventLoop(evlp) => evlp.run_ondemand(callback))
x11_or_wayland!(match self; EventLoop(evlp) => evlp.run_on_demand(callback))
}

pub fn pump_events<F>(&mut self, timeout: Option<Duration>, callback: F) -> PumpStatus
Expand Down
6 changes: 3 additions & 3 deletions src/platform_impl/linux/wayland/event_loop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type WaylandDispatcher = calloop::Dispatcher<'static, WaylandSource<WinitState>,

/// The Wayland event loop.
pub struct EventLoop<T: 'static> {
/// Has `run` or `run_ondemand` been called or a call to `pump_events` that starts the loop
/// Has `run` or `run_on_demand` been called or a call to `pump_events` that starts the loop
loop_running: bool,

buffer_sink: EventSink,
Expand Down Expand Up @@ -187,7 +187,7 @@ impl<T: 'static> EventLoop<T> {
Ok(event_loop)
}

pub fn run_ondemand<F>(&mut self, mut event_handler: F) -> Result<(), EventLoopError>
pub fn run_on_demand<F>(&mut self, mut event_handler: F) -> Result<(), EventLoopError>
where
F: FnMut(Event<T>, &RootEventLoopWindowTarget<T>),
{
Expand All @@ -210,7 +210,7 @@ impl<T: 'static> EventLoop<T> {
};

// Applications aren't allowed to carry windows between separate
// `run_ondemand` calls but if they have only just dropped their
// `run_on_demand` calls but if they have only just dropped their
// windows we need to make sure those last requests are sent to the
// compositor.
let _ = self.roundtrip().map_err(EventLoopError::Os);
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/linux/x11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ impl<T: 'static> EventLoop<T> {
&self.target
}

pub fn run_ondemand<F>(&mut self, mut event_handler: F) -> Result<(), EventLoopError>
pub fn run_on_demand<F>(&mut self, mut event_handler: F) -> Result<(), EventLoopError>
where
F: FnMut(Event<T>, &RootELW<T>),
{
Expand All @@ -420,7 +420,7 @@ impl<T: 'static> EventLoop<T> {
};

// Applications aren't allowed to carry windows between separate
// `run_ondemand` calls but if they have only just dropped their
// `run_on_demand` calls but if they have only just dropped their
// windows we need to make sure those last requests are sent to the
// X Server.
let wt = get_xtarget(&self.target);
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/macos/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ impl AppState {
/// and can lead to undefined behaviour if the callback is not cleared before the end of
/// its real lifetime.
///
/// All public APIs that take an event callback (`run`, `run_ondemand`,
/// All public APIs that take an event callback (`run`, `run_on_demand`,
/// `pump_events`) _must_ pair a call to `set_callback` with
/// a call to `clear_callback` before returning to avoid undefined behaviour.
pub unsafe fn set_callback<T>(
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/macos/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,14 @@ impl<T> EventLoop<T> {
where
F: FnMut(Event<T>, &RootWindowTarget<T>),
{
self.run_ondemand(callback)
self.run_on_demand(callback)
}

// NB: we don't base this on `pump_events` because for `MacOs` we can't support
// `pump_events` elegantly (we just ask to run the loop for a "short" amount of
// time and so a layered implementation would end up using a lot of CPU due to
// redundant wake ups.
pub fn run_ondemand<F>(&mut self, callback: F) -> Result<(), EventLoopError>
pub fn run_on_demand<F>(&mut self, callback: F) -> Result<(), EventLoopError>
where
F: FnMut(Event<T>, &RootWindowTarget<T>),
{
Expand Down
9 changes: 4 additions & 5 deletions src/platform_impl/windows/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ impl<T: 'static> EventLoop<T> {
where
F: FnMut(Event<T>, &RootELW<T>),
{
self.run_ondemand(event_handler)
self.run_on_demand(event_handler)
}

pub fn run_ondemand<F>(&mut self, mut event_handler: F) -> Result<(), EventLoopError>
pub fn run_on_demand<F>(&mut self, mut event_handler: F) -> Result<(), EventLoopError>
where
F: FnMut(Event<T>, &RootELW<T>),
{
Expand Down Expand Up @@ -982,8 +982,7 @@ pub(super) unsafe extern "system" fn public_window_callback<T: 'static>(
let userdata_ptr = match (userdata, msg) {
(0, WM_NCCREATE) => {
let createstruct = unsafe { &mut *(lparam as *mut CREATESTRUCTW) };
let initdata =
unsafe { &mut *(createstruct.lpCreateParams as *mut InitData<'_, '_, T>) };
let initdata = unsafe { &mut *(createstruct.lpCreateParams as *mut InitData<'_, T>) };

let result = match unsafe { initdata.on_nccreate(window) } {
Some(userdata) => unsafe {
Expand All @@ -1001,7 +1000,7 @@ pub(super) unsafe extern "system" fn public_window_callback<T: 'static>(
(_, WM_CREATE) => unsafe {
let createstruct = &mut *(lparam as *mut CREATESTRUCTW);
let initdata = createstruct.lpCreateParams;
let initdata = &mut *(initdata as *mut InitData<'_, '_, T>);
let initdata = &mut *(initdata as *mut InitData<'_, T>);

initdata.on_create();
return DefWindowProcW(window, msg, wparam, lparam);
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/windows/event_loop/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl<T> EventLoopRunner<T> {
/// outlive the EventLoopRunner) and can lead to undefined behaviour if
/// the handler is not cleared before the end of real lifetime.
///
/// All public APIs that take an event handler (`run`, `run_ondemand`,
/// All public APIs that take an event handler (`run`, `run_on_demand`,
/// `pump_events`) _must_ pair a call to `set_event_handler` with
/// a call to `clear_event_handler` before returning to avoid
/// undefined behaviour.
Expand Down
6 changes: 3 additions & 3 deletions src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,17 +945,17 @@ pub struct WindowWrapper(HWND);
unsafe impl Sync for WindowWrapper {}
unsafe impl Send for WindowWrapper {}

pub(super) struct InitData<'a, 'b, T: 'static> {
pub(super) struct InitData<'a, T: 'static> {
// inputs
pub event_loop: &'a EventLoopWindowTarget<T>,
pub attributes: WindowAttributes<'b>,
pub attributes: WindowAttributes,
pub pl_attribs: PlatformSpecificWindowBuilderAttributes,
pub window_flags: WindowFlags,
// outputs
pub window: Option<Window>,
}

impl<'a, T: 'static> InitData<'a, '_, T> {
impl<'a, T: 'static> InitData<'a, T> {
unsafe fn create_window(&self, window: HWND) -> Window {
// Register for touch events if applicable
{
Expand Down
Loading