mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-23 22:01:31 +11:00
Add a function for waiting on a Duration
This commit is contained in:
parent
62ce14a013
commit
7d626d9dfd
|
@ -50,6 +50,7 @@ And please only add new entries to the top of this list, right below the `# Unre
|
||||||
- **Breaking:** On Android, switched to using [`android-activity`](https://github.com/rib/android-activity) crate as a glue layer instead of [`ndk-glue`](https://github.com/rust-windowing/android-ndk-rs/tree/master/ndk-glue). See [README.md#Android](https://github.com/rust-windowing/winit#Android) for more details. ([#2444](https://github.com/rust-windowing/winit/pull/2444))
|
- **Breaking:** On Android, switched to using [`android-activity`](https://github.com/rib/android-activity) crate as a glue layer instead of [`ndk-glue`](https://github.com/rust-windowing/android-ndk-rs/tree/master/ndk-glue). See [README.md#Android](https://github.com/rust-windowing/winit#Android) for more details. ([#2444](https://github.com/rust-windowing/winit/pull/2444))
|
||||||
- **Breaking:** Removed support for `raw-window-handle` version `0.4`
|
- **Breaking:** Removed support for `raw-window-handle` version `0.4`
|
||||||
- On Wayland, `RedrawRequested` not emitted during resize.
|
- On Wayland, `RedrawRequested` not emitted during resize.
|
||||||
|
- Add a `set_wait_timeout` function to `ControlFlow` to allow waiting for a `Duration`.
|
||||||
- **Breaking:** Remove the unstable `xlib_xconnection()` function from the private interface.
|
- **Breaking:** Remove the unstable `xlib_xconnection()` function from the private interface.
|
||||||
- Added Orbital support for Redox OS
|
- Added Orbital support for Redox OS
|
||||||
- On X11, added `drag_resize_window` method.
|
- On X11, added `drag_resize_window` method.
|
||||||
|
|
|
@ -11,7 +11,7 @@ use std::marker::PhantomData;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::{error, fmt};
|
use std::{error, fmt};
|
||||||
|
|
||||||
use instant::Instant;
|
use instant::{Duration, Instant};
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use raw_window_handle::{HasRawDisplayHandle, RawDisplayHandle};
|
use raw_window_handle::{HasRawDisplayHandle, RawDisplayHandle};
|
||||||
|
|
||||||
|
@ -163,8 +163,10 @@ pub enum ControlFlow {
|
||||||
/// example when the scaling of the page has changed. This should be treated as an implementation
|
/// example when the scaling of the page has changed. This should be treated as an implementation
|
||||||
/// detail which should not be relied on.
|
/// detail which should not be relied on.
|
||||||
Poll,
|
Poll,
|
||||||
|
|
||||||
/// When the current loop iteration finishes, suspend the thread until another event arrives.
|
/// When the current loop iteration finishes, suspend the thread until another event arrives.
|
||||||
Wait,
|
Wait,
|
||||||
|
|
||||||
/// When the current loop iteration finishes, suspend the thread until either another event
|
/// When the current loop iteration finishes, suspend the thread until either another event
|
||||||
/// arrives or the given time is reached.
|
/// arrives or the given time is reached.
|
||||||
///
|
///
|
||||||
|
@ -174,6 +176,7 @@ pub enum ControlFlow {
|
||||||
///
|
///
|
||||||
/// [`Poll`]: Self::Poll
|
/// [`Poll`]: Self::Poll
|
||||||
WaitUntil(Instant),
|
WaitUntil(Instant),
|
||||||
|
|
||||||
/// Send a [`LoopDestroyed`] event and stop the event loop. This variant is *sticky* - once set,
|
/// Send a [`LoopDestroyed`] event and stop the event loop. This variant is *sticky* - once set,
|
||||||
/// `control_flow` cannot be changed from `ExitWithCode`, and any future attempts to do so will
|
/// `control_flow` cannot be changed from `ExitWithCode`, and any future attempts to do so will
|
||||||
/// result in the `control_flow` parameter being reset to `ExitWithCode`.
|
/// result in the `control_flow` parameter being reset to `ExitWithCode`.
|
||||||
|
@ -221,6 +224,20 @@ impl ControlFlow {
|
||||||
*self = Self::WaitUntil(instant);
|
*self = Self::WaitUntil(instant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets this to wait until a timeout has expired.
|
||||||
|
///
|
||||||
|
/// In most cases, this is set to [`WaitUntil`]. However, if the timeout overflows, it is
|
||||||
|
/// instead set to [`Wait`].
|
||||||
|
///
|
||||||
|
/// [`WaitUntil`]: Self::WaitUntil
|
||||||
|
/// [`Wait`]: Self::Wait
|
||||||
|
pub fn set_wait_timeout(&mut self, timeout: Duration) {
|
||||||
|
match Instant::now().checked_add(timeout) {
|
||||||
|
Some(instant) => self.set_wait_until(instant),
|
||||||
|
None => self.set_wait(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets this to [`ExitWithCode`]`(code)`.
|
/// Sets this to [`ExitWithCode`]`(code)`.
|
||||||
///
|
///
|
||||||
/// [`ExitWithCode`]: Self::ExitWithCode
|
/// [`ExitWithCode`]: Self::ExitWithCode
|
||||||
|
|
Loading…
Reference in a new issue