From d7aa1d856c40641d1bbf2246c98a62f756533f5b Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Thu, 5 May 2022 12:34:15 +0200 Subject: [PATCH] Cargo format --- swayr/src/cmds.rs | 2 +- swayr/src/daemon.rs | 7 ++----- swayr/src/focus.rs | 35 +++++++++++------------------------ swayr/src/lib.rs | 2 +- 4 files changed, 15 insertions(+), 31 deletions(-) diff --git a/swayr/src/cmds.rs b/swayr/src/cmds.rs index 550763a..dd88257 100644 --- a/swayr/src/cmds.rs +++ b/swayr/src/cmds.rs @@ -754,7 +754,7 @@ fn select_and_move_focused_to(prompt: &str, choices: &[t::DisplayNode]) { pub fn move_focused_to_workspace(fdata: &FocusData) { let root = ipc::get_root_node(true); let tree = t::get_tree(&root); -select_and_move_focused_to( + select_and_move_focused_to( "Move focused container to workspace", &tree.get_workspaces(fdata), ); diff --git a/swayr/src/daemon.rs b/swayr/src/daemon.rs index 353f575..69d174b 100644 --- a/swayr/src/daemon.rs +++ b/swayr/src/daemon.rs @@ -296,10 +296,7 @@ fn focus_lock_in_handler( let update_focus = |fev: Option| { if let Some(fev) = fev { log::debug!("Locking-in focus on {}", fev.node_id); - fdata.update_last_focus_tick( - fev.node_id, - fev.ev_focus_ctr, - ) + fdata.update_last_focus_tick(fev.node_id, fev.ev_focus_ctr) } }; @@ -318,7 +315,7 @@ fn focus_lock_in_handler( FocusMessage::TickUpdateActivate => { inhibit.clear(); update_focus(pending_fev.take()); - continue + continue; } FocusMessage::FocusEvent(fev) => { if let InhibitState::FocusInhibit = inhibit { diff --git a/swayr/src/focus.rs b/swayr/src/focus.rs index 5340094..e8951d4 100644 --- a/swayr/src/focus.rs +++ b/swayr/src/focus.rs @@ -15,10 +15,10 @@ //! Structure to hold window focus timestamps used by swayrd +use std::collections::HashMap; use std::sync::mpsc; use std::sync::Arc; use std::sync::RwLock; -use std::collections::HashMap; /// Data tracking most recent focus events for Sway windows/containers #[derive(Clone)] @@ -29,51 +29,38 @@ pub struct FocusData { impl FocusData { pub fn last_focus_tick(&self, id: i64) -> u64 { - *self.focus_tick_by_id - .read() - .unwrap() - .get(&id) - .unwrap_or(&0) + *self.focus_tick_by_id.read().unwrap().get(&id).unwrap_or(&0) } - pub fn update_last_focus_tick( - &self, - id: i64, - focus_val: u64, - ) { + pub fn update_last_focus_tick(&self, id: i64, focus_val: u64) { let mut write_lock = self.focus_tick_by_id.write().unwrap(); if let Some(tick) = write_lock.get_mut(&id) { *tick = focus_val; } // else the node has since been closed before this focus event got locked in } - - pub fn remove_focus_data( - &self, - id: i64 - ) { + + pub fn remove_focus_data(&self, id: i64) { self.focus_tick_by_id.write().unwrap().remove(&id); } - + /// Ensures that a given node_id is present in the ExtraProps map, this /// later used to distinguish between the case where a container was - /// closed (it will no longer be in the map) or + /// closed (it will no longer be in the map) or pub fn ensure_id(&self, id: i64) { let mut write_lock = self.focus_tick_by_id.write().unwrap(); if write_lock.get(&id).is_none() { - write_lock.insert( - id, - 0, - ); + write_lock.insert(id, 0); } } pub fn send(&self, fmsg: FocusMessage) { // todo can this be removed? - if let FocusMessage::FocusEvent(ref fev) = fmsg { + if let FocusMessage::FocusEvent(ref fev) = fmsg { self.ensure_id(fev.node_id); } - self.focus_chan.send(fmsg) + self.focus_chan + .send(fmsg) .expect("Failed to send focus event over channel"); } } diff --git a/swayr/src/lib.rs b/swayr/src/lib.rs index c3b6e3b..e319373 100644 --- a/swayr/src/lib.rs +++ b/swayr/src/lib.rs @@ -22,8 +22,8 @@ pub mod client; pub mod cmds; pub mod config; pub mod daemon; +pub mod focus; pub mod layout; pub mod shared; pub mod tree; pub mod util; -pub mod focus;