diff options
| author | MaxVerevkin <maxxverrr@gmail.com> | 2023-09-07 16:31:06 +0300 |
|---|---|---|
| committer | MaxVerevkin <maxxverrr@gmail.com> | 2023-09-07 16:31:06 +0300 |
| commit | 87673d7ecce661f3b8c5db949e70640934a55de9 (patch) | |
| tree | b2ac86792f42a0cf6bd7defc4f8bc86cddfc7988 /src/main.rs | |
| parent | 74cc46a2383db5538d7e0392e4b79b7287775e9b (diff) | |
| download | i3bar-mango-87673d7ecce661f3b8c5db949e70640934a55de9.tar.gz | |
some refactoring
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/src/main.rs b/src/main.rs index 20bc49c..f27e076 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,21 +45,21 @@ fn main() -> anyhow::Result<()> { signal_hook::low_level::pipe::register(SIGUSR1, sig_write)?; let (mut conn, globals) = Connection::connect_and_collect_globals()?; - let mut el = EventLoop::<(Connection<State>, State)>::new(); - let state = State::new(&mut conn, &globals, &mut el, args.config.as_deref()); + let mut el = EventLoop::new(); + let mut state = State::new(&mut conn, &globals, &mut el, args.config.as_deref()); conn.flush(IoMode::Blocking)?; - el.register_with_fd(sig_read, move |(conn, state)| { + el.register_with_fd(sig_read, move |ctx| { nix::unistd::read(sig_read, &mut [0; 1])?; - state.toggle_visibility(conn); + ctx.state.toggle_visibility(ctx.conn); Ok(event_loop::Action::Keep) }); - el.register_with_fd(conn.as_raw_fd(), |(conn, state)| { - match conn.recv_events(IoMode::NonBlocking) { + el.register_with_fd(conn.as_raw_fd(), |ctx| { + match ctx.conn.recv_events(IoMode::NonBlocking) { Ok(()) => { - conn.dispatch_events(state); - conn.flush(IoMode::Blocking)?; + ctx.conn.dispatch_events(ctx.state); + ctx.conn.flush(IoMode::Blocking)?; } Err(e) if e.kind() == ErrorKind::WouldBlock => (), Err(e) => bail!(e), @@ -68,8 +68,9 @@ fn main() -> anyhow::Result<()> { }); if let Some(fd) = state.status_cmd_fd() { - el.register_with_fd(fd, |(conn, state)| { - match state + el.register_with_fd(fd, |ctx| { + match ctx + .state .shared_state .status_cmd .as_mut() @@ -78,22 +79,28 @@ fn main() -> anyhow::Result<()> { { Ok(None) => Ok(event_loop::Action::Keep), Ok(Some(blocks)) => { - state.set_blocks(conn, blocks); - conn.flush(IoMode::Blocking)?; + ctx.state.set_blocks(ctx.conn, blocks); + ctx.conn.flush(IoMode::Blocking)?; Ok(event_loop::Action::Keep) } Err(e) => { - let _ = state.shared_state.status_cmd.take().unwrap().child.kill(); - state.set_error(conn, e); - conn.flush(IoMode::Blocking)?; + let _ = ctx + .state + .shared_state + .status_cmd + .take() + .unwrap() + .child + .kill(); + ctx.state.set_error(ctx.conn, e); + ctx.conn.flush(IoMode::Blocking)?; Ok(event_loop::Action::Unregister) } } }); } - let mut el_state = (conn, state); loop { - el.run(&mut el_state)?; + el.run(&mut conn, &mut state)?; } } |
