|
|
@ -17,7 +17,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
use crate::config; |
|
|
|
use crate::config; |
|
|
|
use crate::module; |
|
|
|
use crate::module; |
|
|
|
use crate::module::{BarModuleFn, NameAndInstance}; |
|
|
|
use crate::module::{BarModuleFn, NameInstanceAndReason, RefreshReason}; |
|
|
|
use env_logger::Env; |
|
|
|
use env_logger::Env; |
|
|
|
use serde_json; |
|
|
|
use serde_json; |
|
|
|
use std::io; |
|
|
|
use std::io; |
|
|
@ -30,14 +30,6 @@ use std::{sync::Arc, thread}; |
|
|
|
use swaybar_types as sbt; |
|
|
|
use swaybar_types as sbt; |
|
|
|
use swayipc as si; |
|
|
|
use swayipc as si; |
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)] |
|
|
|
|
|
|
|
enum RefreshReason { |
|
|
|
|
|
|
|
ClickEvent, |
|
|
|
|
|
|
|
SwayEvent, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type NameInstanceAndReason = (String, String, RefreshReason); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn start() { |
|
|
|
pub fn start() { |
|
|
|
env_logger::Builder::from_env(Env::default().default_filter_or("warn")) |
|
|
|
env_logger::Builder::from_env(Env::default().default_filter_or("warn")) |
|
|
|
.init(); |
|
|
|
.init(); |
|
|
@ -56,7 +48,7 @@ pub fn start() { |
|
|
|
let sender_for_input = sender.clone(); |
|
|
|
let sender_for_input = sender.clone(); |
|
|
|
thread::spawn(move || handle_input(mods_for_input, sender_for_input)); |
|
|
|
thread::spawn(move || handle_input(mods_for_input, sender_for_input)); |
|
|
|
|
|
|
|
|
|
|
|
let window_mods: Vec<NameAndInstance> = mods |
|
|
|
let window_mods: Vec<(String, String)> = mods |
|
|
|
.iter() |
|
|
|
.iter() |
|
|
|
.filter(|m| m.get_config().name == "window") |
|
|
|
.filter(|m| m.get_config().name == "window") |
|
|
|
.map(|m| (m.get_config().name.clone(), m.get_config().instance.clone())) |
|
|
|
.map(|m| (m.get_config().name.clone(), m.get_config().instance.clone())) |
|
|
@ -134,8 +126,8 @@ fn handle_input( |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
log::debug!("Received click: {:?}", click); |
|
|
|
log::debug!("Received click: {:?}", click); |
|
|
|
if let Some((name, instance)) = handle_click(click, mods.clone()) { |
|
|
|
let event = handle_click(click, mods.clone()); |
|
|
|
let event = Some((name, instance, RefreshReason::ClickEvent)); |
|
|
|
if event.is_some() { |
|
|
|
send_refresh_event(&sender, event); |
|
|
|
send_refresh_event(&sender, event); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -156,7 +148,7 @@ fn send_refresh_event( |
|
|
|
fn handle_click( |
|
|
|
fn handle_click( |
|
|
|
click: sbt::Click, |
|
|
|
click: sbt::Click, |
|
|
|
mods: Arc<Vec<Box<dyn BarModuleFn>>>, |
|
|
|
mods: Arc<Vec<Box<dyn BarModuleFn>>>, |
|
|
|
) -> Option<NameAndInstance> { |
|
|
|
) -> Option<NameInstanceAndReason> { |
|
|
|
let name = click.name?; |
|
|
|
let name = click.name?; |
|
|
|
let instance = click.instance?; |
|
|
|
let instance = click.instance?; |
|
|
|
let button_str = format!("{:?}", click.button); |
|
|
|
let button_str = format!("{:?}", click.button); |
|
|
@ -176,7 +168,11 @@ fn handle_click( |
|
|
|
if cfg.name == module::window::NAME { |
|
|
|
if cfg.name == module::window::NAME { |
|
|
|
return None; |
|
|
|
return None; |
|
|
|
} |
|
|
|
} |
|
|
|
return Some((cfg.name.clone(), cfg.instance.clone())); |
|
|
|
return Some(( |
|
|
|
|
|
|
|
cfg.name.clone(), |
|
|
|
|
|
|
|
cfg.instance.clone(), |
|
|
|
|
|
|
|
RefreshReason::ClickEvent, |
|
|
|
|
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -212,7 +208,7 @@ fn sway_subscribe() -> si::Fallible<si::EventStream> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn handle_sway_events( |
|
|
|
fn handle_sway_events( |
|
|
|
window_mods: Vec<NameAndInstance>, |
|
|
|
window_mods: Vec<(String, String)>, |
|
|
|
sender: SyncSender<Option<NameInstanceAndReason>>, |
|
|
|
sender: SyncSender<Option<NameInstanceAndReason>>, |
|
|
|
) { |
|
|
|
) { |
|
|
|
let mut resets = 0; |
|
|
|
let mut resets = 0; |
|
|
@ -275,7 +271,7 @@ fn handle_sway_events( |
|
|
|
|
|
|
|
|
|
|
|
fn generate_status_1( |
|
|
|
fn generate_status_1( |
|
|
|
mods: &[Box<dyn BarModuleFn>], |
|
|
|
mods: &[Box<dyn BarModuleFn>], |
|
|
|
name_and_instance: &Option<NameAndInstance>, |
|
|
|
name_and_instance: &Option<NameInstanceAndReason>, |
|
|
|
) { |
|
|
|
) { |
|
|
|
let mut blocks = vec![]; |
|
|
|
let mut blocks = vec![]; |
|
|
|
for m in mods { |
|
|
|
for m in mods { |
|
|
@ -296,6 +292,6 @@ fn generate_status( |
|
|
|
println!("["); |
|
|
|
println!("["); |
|
|
|
|
|
|
|
|
|
|
|
for ev in receiver.iter() { |
|
|
|
for ev in receiver.iter() { |
|
|
|
generate_status_1(mods, &ev.map(|x| (x.0, x.1))) |
|
|
|
generate_status_1(mods, &ev) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|