Skip to content

Commit

Permalink
Fix "update = true" click event handling for some blocks (e.g. pacman)
Browse files Browse the repository at this point in the history
Fixes #1945
  • Loading branch information
MaxVerevkin committed Sep 9, 2023
1 parent 36feb3f commit 5aa6278
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ impl Block {
let _ = tx.send((self.id, intervals));
}

fn send_action(&mut self, action: BlockAction) {
if let Some(sender) = &self.action_sender {
if sender.send(action).is_err() {
self.action_sender = None;
}
}
}

fn set_error(&mut self, fullscreen: bool, error: Error) {
let mut widget = Widget::new()
.with_state(State::Critical)
Expand Down Expand Up @@ -377,23 +385,20 @@ impl BarState {
match &mut block.state {
BlockState::None => (),
BlockState::Normal { .. } => {
let post_actions = block.click_handler.handle(&event).await.in_block(block.name, event.id)?;
if let Some(sender) = &block.action_sender {
match post_actions {
Some(post_actions) => {
if let Some(action) = post_actions.action {
let _ = sender.send(Cow::Owned(action));
}
if post_actions.update {
block.update_request.notify_one();
}
match block.click_handler.handle(&event).await.in_block(block.name, event.id)? {
Some(post_actions) => {
if let Some(action) = post_actions.action {
block.send_action(Cow::Owned(action));
}
if post_actions.update {
block.update_request.notify_one();
}
None => {
if let Some((_, _, action)) = block.default_actions
.iter()
.find(|(btn, widget, _)| *btn == event.button && *widget == event.instance.as_deref()) {
let _ = sender.send(Cow::Borrowed(action));
}
}
None => {
if let Some((_, _, action)) = block.default_actions
.iter()
.find(|(btn, widget, _)| *btn == event.button && *widget == event.instance.as_deref()) {
block.send_action(Cow::Borrowed(action));
}
}
}
Expand Down

0 comments on commit 5aa6278

Please sign in to comment.