summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorMaxVerevkin <maxxverrr@gmail.com>2024-03-30 19:34:08 +0200
committerMaxVerevkin <maxxverrr@gmail.com>2024-03-30 19:34:08 +0200
commitc6da876c3ef4ec9437c269b35bb3b569d159852d (patch)
tree08baa332d2de757479e2a5ce8733353aa030200d /src/main.rs
parent310c8755855266b6f4f956c5d5e6feb91fa6d1db (diff)
downloadi3bar-mango-c6da876c3ef4ec9437c269b35bb3b569d159852d.tar.gz
use libc directly
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs26
1 files changed, 19 insertions, 7 deletions
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)
+ }
+}