|
|
@ -15,10 +15,10 @@ |
|
|
|
|
|
|
|
|
|
|
|
//! Structure to hold window focus timestamps used by swayrd
|
|
|
|
//! Structure to hold window focus timestamps used by swayrd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use std::collections::HashMap; |
|
|
|
use std::sync::mpsc; |
|
|
|
use std::sync::mpsc; |
|
|
|
use std::sync::Arc; |
|
|
|
use std::sync::Arc; |
|
|
|
use std::sync::RwLock; |
|
|
|
use std::sync::RwLock; |
|
|
|
use std::collections::HashMap; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Data tracking most recent focus events for Sway windows/containers
|
|
|
|
/// Data tracking most recent focus events for Sway windows/containers
|
|
|
|
#[derive(Clone)] |
|
|
|
#[derive(Clone)] |
|
|
@ -29,18 +29,10 @@ pub struct FocusData { |
|
|
|
|
|
|
|
|
|
|
|
impl FocusData { |
|
|
|
impl FocusData { |
|
|
|
pub fn last_focus_tick(&self, id: i64) -> u64 { |
|
|
|
pub fn last_focus_tick(&self, id: i64) -> u64 { |
|
|
|
*self.focus_tick_by_id |
|
|
|
*self.focus_tick_by_id.read().unwrap().get(&id).unwrap_or(&0) |
|
|
|
.read() |
|
|
|
|
|
|
|
.unwrap() |
|
|
|
|
|
|
|
.get(&id) |
|
|
|
|
|
|
|
.unwrap_or(&0) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn update_last_focus_tick( |
|
|
|
pub fn update_last_focus_tick(&self, id: i64, focus_val: u64) { |
|
|
|
&self, |
|
|
|
|
|
|
|
id: i64, |
|
|
|
|
|
|
|
focus_val: u64, |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
let mut write_lock = self.focus_tick_by_id.write().unwrap(); |
|
|
|
let mut write_lock = self.focus_tick_by_id.write().unwrap(); |
|
|
|
if let Some(tick) = write_lock.get_mut(&id) { |
|
|
|
if let Some(tick) = write_lock.get_mut(&id) { |
|
|
|
*tick = focus_val; |
|
|
|
*tick = focus_val; |
|
|
@ -48,10 +40,7 @@ impl FocusData { |
|
|
|
// else the node has since been closed before this focus event got locked in
|
|
|
|
// else the node has since been closed before this focus event got locked in
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn remove_focus_data( |
|
|
|
pub fn remove_focus_data(&self, id: i64) { |
|
|
|
&self, |
|
|
|
|
|
|
|
id: i64 |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
self.focus_tick_by_id.write().unwrap().remove(&id); |
|
|
|
self.focus_tick_by_id.write().unwrap().remove(&id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -61,10 +50,7 @@ impl FocusData { |
|
|
|
pub fn ensure_id(&self, id: i64) { |
|
|
|
pub fn ensure_id(&self, id: i64) { |
|
|
|
let mut write_lock = self.focus_tick_by_id.write().unwrap(); |
|
|
|
let mut write_lock = self.focus_tick_by_id.write().unwrap(); |
|
|
|
if write_lock.get(&id).is_none() { |
|
|
|
if write_lock.get(&id).is_none() { |
|
|
|
write_lock.insert( |
|
|
|
write_lock.insert(id, 0); |
|
|
|
id, |
|
|
|
|
|
|
|
0, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -73,7 +59,8 @@ impl FocusData { |
|
|
|
if let FocusMessage::FocusEvent(ref fev) = fmsg { |
|
|
|
if let FocusMessage::FocusEvent(ref fev) = fmsg { |
|
|
|
self.ensure_id(fev.node_id); |
|
|
|
self.ensure_id(fev.node_id); |
|
|
|
} |
|
|
|
} |
|
|
|
self.focus_chan.send(fmsg) |
|
|
|
self.focus_chan |
|
|
|
|
|
|
|
.send(fmsg) |
|
|
|
.expect("Failed to send focus event over channel"); |
|
|
|
.expect("Failed to send focus event over channel"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|