Skip to content

Commit

Permalink
Merge pull request pierrechevalier83#30 from MaxVerevkin/main
Browse files Browse the repository at this point in the history
better logging of errors
  • Loading branch information
pierrechevalier83 authored Feb 20, 2022
2 parents 3be1c4f + 81cfa0b commit 5db330c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
7 changes: 5 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,19 @@ fn main() -> Result<()> {
}
Err(error) => {
error!("{error}");
error.chain().skip(1).for_each(|e| error!("because: {e}"));
error!("Failed to connect to WM. Will try again in 1 second");
sleep(Duration::from_secs(1));
}
}
};

if let Err(error) = process_events(wm) {
error!("Error: {error}");
error!("{error}");
error.chain().skip(1).for_each(|e| error!("because: {e}"));
error!("Couldn't process WM events. The WM might have been terminated");
info!("Attempting to reconnect to the WM");
info!("Attempting to reconnect to the WM in 1 second");
sleep(Duration::from_secs(1));
}
}
}
30 changes: 9 additions & 21 deletions src/window_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ trait NodeExt {

impl NodeExt for Node {
fn is_workspace(&self) -> bool {
self.node_type == NodeType::Workspace
// `__i3_scratch` is a special workspace that connot be renamed, so we just skip it
self.name.as_deref() != Some("__i3_scratch") && self.node_type == NodeType::Workspace
}
fn is_window(&self) -> bool {
matches!(self.node_type, NodeType::Con | NodeType::FloatingCon)
Expand Down Expand Up @@ -117,17 +118,8 @@ pub struct WindowManager {
impl WindowManager {
pub fn connect() -> Result<Self> {
Ok(Self {
connection: Connection::new()
.map_err(|e| {
log::error!("{e}");
e
})
.context("Couldn't connect to WM")?,
connection: Connection::new().context("Couldn't connect to WM")?,
events: Connection::new()
.map_err(|e| {
log::error!("{e}");
e
})
.context("Couldn't connect to WM")?
.subscribe(&[EventType::Window])
.context("Couldn't subscribe to events of type Window")?,
Expand All @@ -137,22 +129,18 @@ impl WindowManager {
pub fn get_windows_in_each_workspace(&mut self) -> Result<BTreeMap<String, Vec<Window>>> {
self.connection
.get_tree()
.map_err(|e| {
log::error!("{e}");
e
})
.context("get_tree() failed")?
.workspaces_in_node()
}

pub fn rename_workspace(&mut self, old: &str, new: &str) -> Result<()> {
self.connection
for result in self
.connection
.run_command(&format!("rename workspace \"{old}\" to \"{new}\"",))
.map_err(|e| {
log::error!("{e}");
e
})
.context("Failed to rename the workspace")?;
.context("Failed to rename the workspace")?
{
result.context("Failed to rename the workspace")?;
}
Ok(())
}

Expand Down

0 comments on commit 5db330c

Please sign in to comment.