Skip to content

Commit

Permalink
small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxVerevkin committed Apr 2, 2023
1 parent a671269 commit 3b8aafe
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pangocairo = "0.17"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
memchr = "2"
thiserror = "1.0.38"
signal-hook = { version = "0.3", default-features = false }
nix = { version = "0.26", default-features = false, features = ["fs", "poll"] }

Expand All @@ -21,3 +20,4 @@ wayrs-protocols = { version = "0.5", features = ["wlr-layer-shell-unstable-v1",
[profile.release]
lto = "fat"
strip = true
codegen-units = 1
10 changes: 8 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn main() -> anyhow::Result<()> {
conn.flush(IoMode::Blocking)?;
}
Err(e) if e.kind() == ErrorKind::WouldBlock => (),
Err(e) => return Err(e.into()),
Err(e) => bail!(e),
}
}

Expand All @@ -72,7 +72,13 @@ fn main() -> anyhow::Result<()> {
}

if fds.len() > 2 && fds[2].any().unwrap_or(false) {
match state.shared_state.status_cmd.as_mut().unwrap().read() {
match state
.shared_state
.status_cmd
.as_mut()
.unwrap()
.receive_blocks()
{
Ok(None) => (),
Ok(Some(blocks)) => {
state.set_blocks(&mut conn, blocks);
Expand Down
16 changes: 6 additions & 10 deletions src/status_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ impl StatusCmd {
})
}

pub fn read(&mut self) -> Result<Option<Vec<Block>>> {
match read(self.output.as_raw_fd(), &mut self.buf) {
pub fn receive_blocks(&mut self) -> Result<Option<Vec<Block>>> {
match read_to_vec(self.output.as_raw_fd(), &mut self.buf) {
Ok(0) => bail!("status command exited"),
Ok(_n) => (),
Err(Errno::EAGAIN) => return Ok(None),
Expand All @@ -57,7 +57,7 @@ impl StatusCmd {

pub fn send_click_event(&mut self, event: &Event) -> Result<()> {
if self.protocol.supports_clicks() {
writeln!(self.input, "{}", serde_json::to_string(event).unwrap())?;
writeln!(self.input, "{}", serde_json::to_string(event)?)?;
}
Ok(())
}
Expand All @@ -66,7 +66,7 @@ impl StatusCmd {
/// Read from a raw file descriptor to the vector.
///
/// Appends data at the end of the buffer. Resizes vector as needed.
pub fn read(fd: RawFd, buf: &mut Vec<u8>) -> nix::Result<usize> {
pub fn read_to_vec(fd: RawFd, buf: &mut Vec<u8>) -> nix::Result<usize> {
if buf.capacity() - buf.len() < 1024 {
buf.reserve(buf.capacity().max(1024));
}
Expand All @@ -79,12 +79,8 @@ pub fn read(fd: RawFd, buf: &mut Vec<u8>) -> nix::Result<usize> {
)
};

let read = Errno::result(res).map(|r| r as usize)?;
if read > 0 {
unsafe {
buf.set_len(buf.len() + read);
}
}
let read = Errno::result(res)? as usize;
unsafe { buf.set_len(buf.len() + read) };

Ok(read)
}

0 comments on commit 3b8aafe

Please sign in to comment.