diff options
| -rw-r--r-- | Cargo.lock | 1 | ||||
| -rw-r--r-- | Cargo.toml | 1 | ||||
| -rw-r--r-- | src/main.rs | 26 | ||||
| -rw-r--r-- | src/status_cmd.rs | 9 |
4 files changed, 23 insertions, 14 deletions
@@ -286,7 +286,6 @@ dependencies = [ "clap", "libc", "memchr", - "nix", "pangocairo", "serde", "serde_json", @@ -11,7 +11,6 @@ authors = ["MaxVerevkin <maxxverrr@gmail.com>"] [dependencies] anyhow = "1" memchr = "2" -nix = { version = "0.28", default-features = false, features = ["fs"] } pangocairo = "0.19" serde_json = "1" serde = { version = "1", features = ["derive"] } diff --git a/src/main.rs b/src/main.rs index 1befd65..a6ea3e5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,16 +18,15 @@ mod text; mod utils; mod wm_info_provider; -use std::io::ErrorKind; -use std::os::fd::AsRawFd; +use std::io::{self, ErrorKind}; +use std::os::fd::{AsRawFd, RawFd}; use std::path::PathBuf; use clap::Parser; -use event_loop::EventLoop; -use nix::fcntl::OFlag; use signal_hook::consts::*; use wayrs_client::{Connection, IoMode}; +use event_loop::EventLoop; use state::State; #[derive(Parser)] @@ -41,7 +40,7 @@ struct Cli { fn main() -> anyhow::Result<()> { let args = Cli::parse(); - let (sig_read, sig_write) = nix::unistd::pipe2(OFlag::O_NONBLOCK | OFlag::O_CLOEXEC)?; + let [sig_read, sig_write] = pipe(libc::O_NONBLOCK | libc::O_CLOEXEC)?; signal_hook::low_level::pipe::register(SIGUSR1, sig_write)?; let (mut conn, globals) = Connection::connect_and_collect_globals()?; @@ -49,8 +48,12 @@ fn main() -> anyhow::Result<()> { let mut state = State::new(&mut conn, &globals, &mut el, args.config.as_deref()); conn.flush(IoMode::Blocking)?; - el.register_with_fd(sig_read.as_raw_fd(), move |ctx| { - nix::unistd::read(sig_read.as_raw_fd(), &mut [0; 1])?; + el.register_with_fd(sig_read, move |ctx| { + let mut buf = [0u8]; + assert_eq!( + unsafe { libc::read(sig_read, buf.as_mut_ptr().cast(), 1) }, + 1 + ); ctx.state.toggle_visibility(ctx.conn); Ok(event_loop::Action::Keep) }); @@ -103,3 +106,12 @@ fn main() -> anyhow::Result<()> { el.run(&mut conn, &mut state)?; unreachable!(); } + +fn pipe(flags: libc::c_int) -> io::Result<[RawFd; 2]> { + let mut fds = [0; 2]; + if unsafe { libc::pipe2(fds.as_mut_ptr(), flags) } == -1 { + Err(io::Error::last_os_error()) + } else { + Ok(fds) + } +} diff --git a/src/status_cmd.rs b/src/status_cmd.rs index 0d6f049..243b209 100644 --- a/src/status_cmd.rs +++ b/src/status_cmd.rs @@ -1,4 +1,4 @@ -use std::io::{BufWriter, ErrorKind, Write}; +use std::io::{self, BufWriter, ErrorKind, Write}; use std::os::unix::io::AsRawFd; use std::process::{Child, ChildStdin, ChildStdout, Command, Stdio}; @@ -25,10 +25,9 @@ impl StatusCmd { .spawn()?; let output = child.stdout.take().unwrap(); let input = BufWriter::new(child.stdin.take().unwrap()); - nix::fcntl::fcntl( - output.as_raw_fd(), - nix::fcntl::F_SETFL(nix::fcntl::OFlag::O_NONBLOCK), - )?; + if unsafe { libc::fcntl(output.as_raw_fd(), libc::F_SETFL, libc::O_NONBLOCK) } == -1 { + return Err(io::Error::last_os_error().into()); + } Ok(Self { child, output, |
