Skip to content

Commit

Permalink
keyboard: fix panic when layout update channel lags behind
Browse files Browse the repository at this point in the history
  • Loading branch information
quietvoid committed Feb 16, 2025
1 parent 452e85f commit 1b23611
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/clients/compositor/hyprland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct Client {
impl Client {
pub(crate) fn new() -> Self {
let (workspace_tx, workspace_rx) = channel(16);
let (keyboard_layout_tx, keyboard_layout_rx) = channel(4);
let (keyboard_layout_tx, keyboard_layout_rx) = channel(16);

let instance = Self {
workspace_tx,
Expand Down
2 changes: 1 addition & 1 deletion src/clients/compositor/sway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl KeyboardLayoutClient for Client {
}

fn subscribe(&self) -> Receiver<KeyboardLayoutUpdate> {
let (tx, rx) = channel(4);
let (tx, rx) = channel(16);

let client = self.connection().clone();

Expand Down
17 changes: 14 additions & 3 deletions src/modules/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,20 @@ impl Module<gtk::Box> for KeyboardModule {

trace!("Set up keyboard_layout subscription");

while let Ok(payload) = srx.recv().await {
debug!("Received update: {payload:?}");
module_update!(tx, KeyboardUpdate::Layout(payload));
loop {
match srx.recv().await {
Ok(payload) => {
debug!("Received update: {payload:?}");
module_update!(tx, KeyboardUpdate::Layout(payload));
}
Err(tokio::sync::broadcast::error::RecvError::Lagged(count)) => {
tracing::warn!("Channel lagged behind by {count}, this may result in unexpected or broken behaviour");
}
Err(err) => {
tracing::error!("{err:?}");
break;
}
};
}
});
}
Expand Down

0 comments on commit 1b23611

Please sign in to comment.