diff options
Diffstat (limited to 'src/event_loop.rs')
| -rw-r--r-- | src/event_loop.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/event_loop.rs b/src/event_loop.rs index 89f6f81..28fc0dc 100644 --- a/src/event_loop.rs +++ b/src/event_loop.rs @@ -7,7 +7,7 @@ use wayrs_client::Connection; use crate::state::State; -type Callback = Box<dyn FnMut(EventLoopCtx) -> Result<Action>>; +pub type Callback = Box<dyn FnMut(EventLoopCtx) -> Result<Action>>; pub struct EventLoopCtx<'a> { pub conn: &'a mut Connection<State>, @@ -22,6 +22,7 @@ pub struct EventLoop { pub enum Action { Keep, + KeepAndRegister(RawFd, Callback), Unregister, } @@ -80,6 +81,10 @@ impl EventLoop { Action::Keep => { self.cbs.insert(fd.fd, cb); } + Action::KeepAndRegister(new_fd, new_cb) => { + self.cbs.insert(fd.fd, cb); + self.cbs.insert(new_fd, new_cb); + } Action::Unregister => (), } } @@ -88,6 +93,10 @@ impl EventLoop { for mut cb in self.on_idle.drain(..) { match cb(EventLoopCtx { conn, state })? { Action::Keep => on_idle_scratch.push(cb), + Action::KeepAndRegister(fd, new_cb) => { + on_idle_scratch.push(cb); + self.cbs.insert(fd, new_cb); + } Action::Unregister => (), } } |
