1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-07-01 18:51:04 +02:00

refactor(workspaces): avoid sending unknown update info

This commit is contained in:
Jake Stanger 2023-12-31 00:43:36 +00:00
parent 1b54de98e6
commit 967801dc32
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
4 changed files with 15 additions and 8 deletions

View file

@ -84,7 +84,6 @@ impl EventClient {
}, },
|workspace| { |workspace| {
// there may be another type of update so dispatch that regardless of focus change // there may be another type of update so dispatch that regardless of focus change
send!(tx, WorkspaceUpdate::Update(workspace.clone()));
if !workspace.visibility.is_focused() { if !workspace.visibility.is_focused() {
Self::send_focus_change(&mut prev_workspace, workspace, &tx); Self::send_focus_change(&mut prev_workspace, workspace, &tx);
} }

View file

@ -116,13 +116,17 @@ pub enum WorkspaceUpdate {
Init(Vec<Workspace>), Init(Vec<Workspace>),
Add(Workspace), Add(Workspace),
Remove(String), Remove(String),
Update(Workspace),
Move(Workspace), Move(Workspace),
/// Declares focus moved from the old workspace to the new. /// Declares focus moved from the old workspace to the new.
Focus { Focus {
old: Option<Workspace>, old: Option<Workspace>,
new: Workspace, new: Workspace,
}, },
/// An update was triggered by the compositor but this was not mapped by Ironbar.
///
/// This is purely used for ergonomics within the compositor clients
/// and should be ignored by consumers.
Unknown,
} }
pub trait WorkspaceClient { pub trait WorkspaceClient {

View file

@ -31,8 +31,11 @@ impl SwayEventClient {
while let Some(event) = events.next().await { while let Some(event) = events.next().await {
trace!("event: {:?}", event); trace!("event: {:?}", event);
if let Event::Workspace(ev) = event? { if let Event::Workspace(event) = event? {
workspace_tx.send(WorkspaceUpdate::from(*ev))?; let event = WorkspaceUpdate::from(*event);
if !matches!(event, WorkspaceUpdate::Unknown) {
workspace_tx.send(event)?;
}
}; };
} }
@ -172,7 +175,7 @@ impl From<WorkspaceEvent> for WorkspaceUpdate {
WorkspaceChange::Move => { WorkspaceChange::Move => {
Self::Move(event.current.expect("Missing current workspace").into()) Self::Move(event.current.expect("Missing current workspace").into())
} }
_ => Self::Update(event.current.expect("Missing current workspace").into()), _ => Self::Unknown,
} }
} }
} }

View file

@ -10,7 +10,7 @@ use serde::Deserialize;
use std::cmp::Ordering; use std::cmp::Ordering;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use tokio::sync::mpsc::{Receiver, Sender}; use tokio::sync::mpsc::{Receiver, Sender};
use tracing::trace; use tracing::{debug, trace, warn};
#[derive(Debug, Deserialize, Clone, Copy, Eq, PartialEq)] #[derive(Debug, Deserialize, Clone, Copy, Eq, PartialEq)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
@ -162,9 +162,10 @@ impl Module<gtk::Box> for WorkspacesModule {
client.subscribe_workspace_change() client.subscribe_workspace_change()
}; };
trace!("Set up Sway workspace subscription"); trace!("Set up workspace subscription");
while let Ok(payload) = srx.recv().await { while let Ok(payload) = srx.recv().await {
debug!("Received update: {payload:?}");
send_async!(tx, ModuleUpdateEvent::Update(payload)); send_async!(tx, ModuleUpdateEvent::Update(payload));
} }
}); });
@ -351,7 +352,7 @@ impl Module<gtk::Box> for WorkspacesModule {
} }
} }
} }
WorkspaceUpdate::Update(_) => {} WorkspaceUpdate::Unknown => warn!("Received unknown type workspace event")
}; };
}); });
} }