|
|
@ -26,7 +26,6 @@ use std::os::unix::net::{UnixListener, UnixStream}; |
|
|
|
use std::sync::Arc; |
|
|
|
use std::sync::Arc; |
|
|
|
use std::sync::RwLock; |
|
|
|
use std::sync::RwLock; |
|
|
|
use std::thread; |
|
|
|
use std::thread; |
|
|
|
use std::time::{SystemTime, UNIX_EPOCH}; |
|
|
|
|
|
|
|
use swayipc as s; |
|
|
|
use swayipc as s; |
|
|
|
|
|
|
|
|
|
|
|
pub fn run_demon() { |
|
|
|
pub fn run_demon() { |
|
|
@ -53,6 +52,7 @@ pub fn monitor_sway_events( |
|
|
|
extra_props: Arc<RwLock<HashMap<i64, t::ExtraProps>>>, |
|
|
|
extra_props: Arc<RwLock<HashMap<i64, t::ExtraProps>>>, |
|
|
|
) { |
|
|
|
) { |
|
|
|
let config = config::load_config(); |
|
|
|
let config = config::load_config(); |
|
|
|
|
|
|
|
let mut focus_counter = 0; |
|
|
|
let mut resets = 0; |
|
|
|
let mut resets = 0; |
|
|
|
let max_resets = 10; |
|
|
|
let max_resets = 10; |
|
|
|
|
|
|
|
|
|
|
@ -76,17 +76,21 @@ pub fn monitor_sway_events( |
|
|
|
Ok(ev) => match ev { |
|
|
|
Ok(ev) => match ev { |
|
|
|
s::Event::Window(win_ev) => { |
|
|
|
s::Event::Window(win_ev) => { |
|
|
|
let extra_props_clone = extra_props.clone(); |
|
|
|
let extra_props_clone = extra_props.clone(); |
|
|
|
|
|
|
|
focus_counter += 1; |
|
|
|
show_extra_props_state = handle_window_event( |
|
|
|
show_extra_props_state = handle_window_event( |
|
|
|
win_ev, |
|
|
|
win_ev, |
|
|
|
extra_props_clone, |
|
|
|
extra_props_clone, |
|
|
|
&config, |
|
|
|
&config, |
|
|
|
|
|
|
|
focus_counter, |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
s::Event::Workspace(ws_ev) => { |
|
|
|
s::Event::Workspace(ws_ev) => { |
|
|
|
let extra_props_clone = extra_props.clone(); |
|
|
|
let extra_props_clone = extra_props.clone(); |
|
|
|
|
|
|
|
focus_counter += 1; |
|
|
|
show_extra_props_state = handle_workspace_event( |
|
|
|
show_extra_props_state = handle_workspace_event( |
|
|
|
ws_ev, |
|
|
|
ws_ev, |
|
|
|
extra_props_clone, |
|
|
|
extra_props_clone, |
|
|
|
|
|
|
|
focus_counter, |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
s::Event::Shutdown(sd_ev) => { |
|
|
|
s::Event::Shutdown(sd_ev) => { |
|
|
@ -124,6 +128,7 @@ fn handle_window_event( |
|
|
|
ev: Box<s::WindowEvent>, |
|
|
|
ev: Box<s::WindowEvent>, |
|
|
|
extra_props: Arc<RwLock<HashMap<i64, t::ExtraProps>>>, |
|
|
|
extra_props: Arc<RwLock<HashMap<i64, t::ExtraProps>>>, |
|
|
|
config: &config::Config, |
|
|
|
config: &config::Config, |
|
|
|
|
|
|
|
focus_val: u64, |
|
|
|
) -> bool { |
|
|
|
) -> bool { |
|
|
|
let s::WindowEvent { |
|
|
|
let s::WindowEvent { |
|
|
|
change, container, .. |
|
|
|
change, container, .. |
|
|
@ -131,13 +136,13 @@ fn handle_window_event( |
|
|
|
match change { |
|
|
|
match change { |
|
|
|
s::WindowChange::Focus => { |
|
|
|
s::WindowChange::Focus => { |
|
|
|
layout::maybe_auto_tile(config); |
|
|
|
layout::maybe_auto_tile(config); |
|
|
|
update_last_focus_time(container.id, extra_props); |
|
|
|
update_last_focus_tick(container.id, extra_props, focus_val); |
|
|
|
println!("Handled window event type {:?}", change); |
|
|
|
println!("Handled window event type {:?}", change); |
|
|
|
true |
|
|
|
true |
|
|
|
} |
|
|
|
} |
|
|
|
s::WindowChange::New => { |
|
|
|
s::WindowChange::New => { |
|
|
|
layout::maybe_auto_tile(config); |
|
|
|
layout::maybe_auto_tile(config); |
|
|
|
update_last_focus_time(container.id, extra_props); |
|
|
|
update_last_focus_tick(container.id, extra_props, focus_val); |
|
|
|
println!("Handled window event type {:?}", change); |
|
|
|
println!("Handled window event type {:?}", change); |
|
|
|
true |
|
|
|
true |
|
|
|
} |
|
|
|
} |
|
|
@ -162,6 +167,7 @@ fn handle_window_event( |
|
|
|
fn handle_workspace_event( |
|
|
|
fn handle_workspace_event( |
|
|
|
ev: Box<s::WorkspaceEvent>, |
|
|
|
ev: Box<s::WorkspaceEvent>, |
|
|
|
extra_props: Arc<RwLock<HashMap<i64, t::ExtraProps>>>, |
|
|
|
extra_props: Arc<RwLock<HashMap<i64, t::ExtraProps>>>, |
|
|
|
|
|
|
|
focus_val: u64, |
|
|
|
) -> bool { |
|
|
|
) -> bool { |
|
|
|
let s::WorkspaceEvent { |
|
|
|
let s::WorkspaceEvent { |
|
|
|
change, |
|
|
|
change, |
|
|
@ -171,11 +177,12 @@ fn handle_workspace_event( |
|
|
|
} = *ev; |
|
|
|
} = *ev; |
|
|
|
match change { |
|
|
|
match change { |
|
|
|
s::WorkspaceChange::Init | s::WorkspaceChange::Focus => { |
|
|
|
s::WorkspaceChange::Init | s::WorkspaceChange::Focus => { |
|
|
|
update_last_focus_time( |
|
|
|
update_last_focus_tick( |
|
|
|
current |
|
|
|
current |
|
|
|
.expect("No current in Init or Focus workspace event") |
|
|
|
.expect("No current in Init or Focus workspace event") |
|
|
|
.id, |
|
|
|
.id, |
|
|
|
extra_props, |
|
|
|
extra_props, |
|
|
|
|
|
|
|
focus_val, |
|
|
|
); |
|
|
|
); |
|
|
|
println!("Handled workspace event type {:?}", change); |
|
|
|
println!("Handled workspace event type {:?}", change); |
|
|
|
true |
|
|
|
true |
|
|
@ -192,19 +199,20 @@ fn handle_workspace_event( |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn update_last_focus_time( |
|
|
|
fn update_last_focus_tick( |
|
|
|
id: i64, |
|
|
|
id: i64, |
|
|
|
extra_props: Arc<RwLock<HashMap<i64, t::ExtraProps>>>, |
|
|
|
extra_props: Arc<RwLock<HashMap<i64, t::ExtraProps>>>, |
|
|
|
|
|
|
|
focus_val: u64, |
|
|
|
) { |
|
|
|
) { |
|
|
|
let mut write_lock = extra_props.write().unwrap(); |
|
|
|
let mut write_lock = extra_props.write().unwrap(); |
|
|
|
if let Some(wp) = write_lock.get_mut(&id) { |
|
|
|
if let Some(wp) = write_lock.get_mut(&id) { |
|
|
|
wp.last_focus_time = get_epoch_time_as_millis(); |
|
|
|
wp.last_focus_tick = focus_val; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
write_lock.insert( |
|
|
|
write_lock.insert( |
|
|
|
id, |
|
|
|
id, |
|
|
|
t::ExtraProps { |
|
|
|
t::ExtraProps { |
|
|
|
last_focus_time: get_epoch_time_as_millis(), |
|
|
|
last_focus_tick: focus_val, |
|
|
|
last_focus_time_for_next_prev_seq: 0, |
|
|
|
last_focus_tick_for_next_prev_seq: 0, |
|
|
|
}, |
|
|
|
}, |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
@ -217,13 +225,6 @@ fn remove_extra_props( |
|
|
|
extra_props.write().unwrap().remove(&id); |
|
|
|
extra_props.write().unwrap().remove(&id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn get_epoch_time_as_millis() -> u128 { |
|
|
|
|
|
|
|
SystemTime::now() |
|
|
|
|
|
|
|
.duration_since(UNIX_EPOCH) |
|
|
|
|
|
|
|
.expect("Couldn't get epoch time!") |
|
|
|
|
|
|
|
.as_millis() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn serve_client_requests( |
|
|
|
pub fn serve_client_requests( |
|
|
|
extra_props: Arc<RwLock<HashMap<i64, t::ExtraProps>>>, |
|
|
|
extra_props: Arc<RwLock<HashMap<i64, t::ExtraProps>>>, |
|
|
|
) { |
|
|
|
) { |
|
|
|