Skip to content

Commit

Permalink
Added minimum timeout of 5ms to prevent infinite loop.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AndreasBackx committed Aug 30, 2021
1 parent 827982f commit 57f7c9b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 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
@@ -1,6 +1,6 @@
[package]
name = "waycorner"
version = "0.1.3"
version = "0.1.4"
authors = ["Andreas Backx"]
edition = "2018"

Expand Down
13 changes: 10 additions & 3 deletions src/corner.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{
borrow::Borrow,
cmp,
process::Command,
sync::{
mpsc::{channel, Receiver, Sender},
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
Expand All @@ -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());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 57f7c9b

Please sign in to comment.