From 57f7c9b2938ba87eeb205dfccb070b9844923e1f Mon Sep 17 00:00:00 2001 From: Andreas Backx Date: Mon, 30 Aug 2021 13:01:10 +0100 Subject: [PATCH] Added minimum timeout of 5ms to prevent infinite loop. When passing a timeout of 0ms, it would lead to the corners continuously timing out in an infinite loop. Added a minimum timeout of 5ms to prevent this. Resolves #2. Bumped version to 0.1.4. --- CHANGELOG.md | 4 ++++ Cargo.lock | 4 +++- Cargo.toml | 2 +- src/corner.rs | 13 ++++++++++--- src/main.rs | 2 +- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10e24c2..162c3e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.1.4] - 2021-08-30 +### Changed +- Added a minimum timeout of 5ms to prevent an infinite loop as it would continuously check for updates. + ## [0.1.3] - 2021-05-29 ### Changed - Use the top layer instead of the overlay layer. This makes it not lay on top of lock screens like swaylock. diff --git a/Cargo.lock b/Cargo.lock index 1c37f76..e28c229 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "ab_glyph_rasterizer" version = "0.1.4" @@ -684,7 +686,7 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "waycorner" -version = "0.1.3" +version = "0.1.4" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index b5ffa31..de458b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "waycorner" -version = "0.1.3" +version = "0.1.4" authors = ["Andreas Backx"] edition = "2018" diff --git a/src/corner.rs b/src/corner.rs index 4d4a3c3..e4c14a1 100644 --- a/src/corner.rs +++ b/src/corner.rs @@ -1,5 +1,6 @@ use std::{ borrow::Borrow, + cmp, process::Command, sync::{ mpsc::{channel, Receiver, Sender}, @@ -38,6 +39,8 @@ impl Corner { } pub fn wait(&self) -> Result<()> { + let timeout = + Duration::from_millis(cmp::max(self.config.timeout_ms.into(), 5)); let mut last_event = None; let mut command_done_at = None; loop { @@ -46,7 +49,7 @@ impl Corner { .1 .lock() .expect("cannot get corner receiver") - .recv_timeout(Duration::from_millis(self.config.timeout_ms.into())); + .recv_timeout(timeout); match event_result { Ok(event) => { debug!("Received event: {:?}", event); @@ -57,11 +60,15 @@ impl Corner { }) { last_event = Some(event); } else { - debug!("Ignored the event due to too fast after unlock."); + debug!( + "Ignored the event due to too fast after unlock." + ); } } Err(_error) => { - if last_event.map_or(false, |value| value == CornerEvent::Enter) { + if last_event + .map_or(false, |value| value == CornerEvent::Enter) + { self.execute_command()?; command_done_at = Some(Instant::now()); } diff --git a/src/main.rs b/src/main.rs index 72946af..549d823 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,7 @@ use wayland::Wayland; /// Hot corners for Wayland. /// Waycorner allows you to create anchors on specified locations of your monitors and execute a command of your choice. #[derive(Clap)] -#[clap(version = "0.1.3", author = "Andreas Backx")] +#[clap(version = "0.1.4", author = "Andreas Backx")] #[clap(setting = AppSettings::ColoredHelp)] struct Opts { /// Config file path.