summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxVerevkin <maxxverrr@gmail.com>2023-04-02 22:32:52 +0300
committerMaxVerevkin <maxxverrr@gmail.com>2023-04-02 22:32:52 +0300
commit3b8aafe1018ed626dbb4c19759195a05be93a1bf (patch)
tree767261aba4e1466a4bf061f8cbcae33412017d07
parenta6712690dcfe7dc7c3f2ee8714fa29ad6bbc10ef (diff)
downloadi3bar-mango-3b8aafe1018ed626dbb4c19759195a05be93a1bf.tar.gz
small changes
-rw-r--r--Cargo.lock1
-rw-r--r--Cargo.toml2
-rw-r--r--src/main.rs10
-rw-r--r--src/status_cmd.rs16
4 files changed, 15 insertions, 14 deletions
diff --git a/Cargo.lock b/Cargo.lock
index ebcbde4..7de53f3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -247,7 +247,6 @@ dependencies = [
"serde",
"serde_json",
"signal-hook",
- "thiserror",
"toml",
"wayrs-client",
"wayrs-protocols",
diff --git a/Cargo.toml b/Cargo.toml
index 0cbb28a..84db476 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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"] }
@@ -21,3 +20,4 @@ wayrs-protocols = { version = "0.5", features = ["wlr-layer-shell-unstable-v1",
[profile.release]
lto = "fat"
strip = true
+codegen-units = 1
diff --git a/src/main.rs b/src/main.rs
index befd750..72d635c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -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),
}
}
@@ -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);
diff --git a/src/status_cmd.rs b/src/status_cmd.rs
index 58ba877..172bee2 100644
--- a/src/status_cmd.rs
+++ b/src/status_cmd.rs
@@ -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),
@@ -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(())
}
@@ -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));
}
@@ -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)
}