Skip to content

Commit 6319d81

Browse files
authored
Add opt-in handlers for before sleeping and before handling events (Smithay#144)
* Add opt-in handlers for before sleeping and before handling events * Remove pre_run and fix some missed impls * Appease the great 📎 * Use an associated constant instead * Do the borrow outside the loop * Fix cfged out mistake * Update documentation to reflect changes * Actually use the synthetic events * Add some tests for the new functionality * Pin `nix` to a lower version * Rename `before_will_sleep` to `before_sleep` * Add some more coverage * Solve review comments * Restore inconsistencies in formatting * Remove AdditionalLifetimeEventsRegister * Remove unused lifetime * Unencapsulate the refcell * Address review comments * Exclude synthetic events from the iterator * Follow clippy's improvement (?)
1 parent d468cc9 commit 6319d81

File tree

5 files changed

+589
-131
lines changed

5 files changed

+589
-131
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
- Bump MSRV to 1.63
88
- Make signals an optional feature under the `signals` features.
9-
- Replace the `nix` crate with standard library I/O errors and the `rustix`
10-
crate.
9+
- Replace the `nix` crate with standard library I/O errors and the `rustix` crate.
10+
- `pre_run` and `post_run` on `EventSource` have been replaced with `before_sleep` and `before_handle_events`, respectively.
11+
These are now opt-in through the `NEEDS_EXTRA_LIFECYCLE_EVENTS` associated constant, and occur at slightly different times to
12+
the methods they are replacing. This allows greater compatibility with Wayland based event sources.
1113

1214
## 0.11.0 -- 2023-06-05
1315

src/io.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ use rustix::fs::{fcntl_getfl, fcntl_setfl, OFlags};
1818
#[cfg(feature = "futures-io")]
1919
use futures_io::{AsyncRead, AsyncWrite, IoSlice, IoSliceMut};
2020

21+
use crate::loop_logic::EventIterator;
2122
use crate::{
2223
loop_logic::{LoopInner, MAX_SOURCES_MASK},
2324
sources::EventDispatcher,
2425
Interest, Mode, Poll, PostAction, Readiness, Token, TokenFactory,
2526
};
27+
use crate::{AdditionalLifecycleEventsSet, RegistrationToken};
2628

2729
/// Adapter for async IO manipulations
2830
///
@@ -237,30 +239,43 @@ impl<Data> EventDispatcher<Data> for RefCell<IoDispatcher> {
237239
Ok(PostAction::Continue)
238240
}
239241

240-
fn register(&self, _: &mut Poll, _: &mut TokenFactory) -> crate::Result<()> {
242+
fn register(
243+
&self,
244+
_: &mut Poll,
245+
_: &mut AdditionalLifecycleEventsSet,
246+
_: &mut TokenFactory,
247+
) -> crate::Result<()> {
241248
// registration is handled by IoLoopInner
242249
unreachable!()
243250
}
244251

245-
fn reregister(&self, _: &mut Poll, _: &mut TokenFactory) -> crate::Result<bool> {
252+
fn reregister(
253+
&self,
254+
_: &mut Poll,
255+
_: &mut AdditionalLifecycleEventsSet,
256+
_: &mut TokenFactory,
257+
) -> crate::Result<bool> {
246258
// registration is handled by IoLoopInner
247259
unreachable!()
248260
}
249261

250-
fn unregister(&self, poll: &mut Poll) -> crate::Result<bool> {
262+
fn unregister(
263+
&self,
264+
poll: &mut Poll,
265+
_: &mut AdditionalLifecycleEventsSet,
266+
_: RegistrationToken,
267+
) -> crate::Result<bool> {
251268
let disp = self.borrow();
252269
if disp.is_registered {
253270
poll.unregister(unsafe { BorrowedFd::borrow_raw(disp.fd) })?;
254271
}
255272
Ok(true)
256273
}
257274

258-
fn pre_run(&self, _data: &mut Data) -> crate::Result<()> {
259-
Ok(())
260-
}
261-
fn post_run(&self, _data: &mut Data) -> crate::Result<()> {
262-
Ok(())
275+
fn before_sleep(&self) -> crate::Result<Option<(Readiness, Token)>> {
276+
Ok(None)
263277
}
278+
fn before_handle_events(&self, _: EventIterator<'_>) {}
264279
}
265280

266281
/*

0 commit comments

Comments
 (0)