Refresh window module state only when requested specifically

main
Tassilo Horn 3 years ago
parent 613b4eeaeb
commit 167b753363
  1. 60
      Cargo.lock
  2. 2
      swayr/src/daemon.rs
  3. 9
      swayrbar/src/bar.rs
  4. 20
      swayrbar/src/module/window.rs

60
Cargo.lock generated

@ -78,9 +78,9 @@ dependencies = [
[[package]]
name = "clap"
version = "3.1.12"
version = "3.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c167e37342afc5f33fd87bbc870cedd020d2a6dffa05d45ccd9241fbdd146db"
checksum = "85a35a599b11c089a7f49105658d089b8f2cf0882993c17daf6de15285c2c35d"
dependencies = [
"atty",
"bitflags",
@ -108,9 +108,9 @@ dependencies = [
[[package]]
name = "clap_lex"
version = "0.1.1"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "189ddd3b5d32a70b35e7686054371742a937b0d99128e76dde6340210e966669"
checksum = "a37c35f1112dad5e6e0b1adaff798507497a18fceeb30cceb3bae7d1427b9213"
dependencies = [
"os_str_bytes",
]
@ -288,15 +288,15 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "libc"
version = "0.2.124"
version = "0.2.125"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21a41fed9d98f27ab1c6d161da622a4fa35e8a54a8adc24bbf3ddd0ef70b0e50"
checksum = "5916d2ae698f6de9bfb891ad7a8d65c09d232dc58cc4ac433c7da3b2fd84bc2b"
[[package]]
name = "log"
version = "0.4.16"
version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6389c490849ff5bc16be905ae24bc913a9c8892e19b2341dbc175e14c341c2b8"
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
dependencies = [
"cfg-if",
]
@ -312,9 +312,9 @@ dependencies = [
[[package]]
name = "memchr"
version = "2.4.1"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "memoffset"
@ -348,9 +348,9 @@ dependencies = [
[[package]]
name = "num-integer"
version = "0.1.44"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
dependencies = [
"autocfg",
"num-traits",
@ -358,9 +358,9 @@ dependencies = [
[[package]]
name = "num-traits"
version = "0.2.14"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
dependencies = [
"autocfg",
]
@ -550,18 +550,18 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "serde"
version = "1.0.136"
version = "1.0.137"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789"
checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.136"
version = "1.0.137"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9"
checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be"
dependencies = [
"proc-macro2",
"quote",
@ -570,9 +570,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.79"
version = "1.0.80"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95"
checksum = "f972498cf015f7c0746cac89ebe1d6ef10c293b94175a243a2d9442c163d9944"
dependencies = [
"itoa",
"ryu",
@ -657,9 +657,9 @@ dependencies = [
[[package]]
name = "syn"
version = "1.0.91"
version = "1.0.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b683b2b825c8eef438b77c36a06dc262294da3d5a5813fac20da149241dcd44d"
checksum = "7ff7c592601f11445996a06f8ad0c27f094a58857c2f89e97974ab9235b92c52"
dependencies = [
"proc-macro2",
"quote",
@ -668,9 +668,9 @@ dependencies = [
[[package]]
name = "sysinfo"
version = "0.23.10"
version = "0.23.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4eea2ed6847da2e0c7289f72cb4f285f0bd704694ca067d32be811b2a45ea858"
checksum = "3bf915673a340ee41f2fc24ad1286c75ea92026f04b65a0d0e5132d80b95fc61"
dependencies = [
"cfg-if",
"core-foundation-sys 0.8.3",
@ -698,18 +698,18 @@ checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
[[package]]
name = "thiserror"
version = "1.0.30"
version = "1.0.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417"
checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.30"
version = "1.0.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b"
checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a"
dependencies = [
"proc-macro2",
"quote",
@ -743,9 +743,9 @@ checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"
[[package]]
name = "unicode-xid"
version = "0.2.2"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04"
[[package]]
name = "uom"

@ -28,13 +28,11 @@ use std::sync::RwLock;
use std::thread;
use swayipc as s;
pub fn run_daemon() {
let extra_props: Arc<RwLock<HashMap<i64, t::ExtraProps>>> =
Arc::new(RwLock::new(HashMap::new()));
let extra_props_for_ev_handler = extra_props.clone();
thread::spawn(move || {
monitor_sway_events(extra_props_for_ev_handler);
});

@ -108,7 +108,7 @@ fn handle_input(
Ok(click) => click,
Err(err) => {
log::error!("Error while parsing str to Click: {}", err);
log::error!("The string was {}", buf);
log::error!("The string was '{}'.", buf);
log::error!("Skipping this input line...");
continue;
}
@ -271,8 +271,11 @@ fn generate_status(
name_and_instance = None;
} else {
name_and_instance = Some((*result.0).clone());
log::debug!("Status writing thread waked up early by click event for {}/{}.",
&result.0.0, & result.0.1);
log::debug!(
"Status writing thread woke up early by click event for {}/{}.",
&result.0 .0,
&result.0 .1
);
}
}
}

@ -27,6 +27,10 @@ use swaybar_types as s;
const NAME: &str = "window";
const INITIAL_PID: i32 = -128;
const NO_WINDOW_PID: i32 = -1;
const UNKNOWN_PID: i32 = -2;
struct State {
name: String,
app_name: String,
@ -43,13 +47,14 @@ fn refresh_state(state: &mut State) {
let focused_win = root
.iter()
.find(|n| n.focused && n.get_type() == ipc::Type::Window);
log::debug!("Focused win: {:?}", focused_win);
match focused_win {
Some(win) => {
state.name = win.get_name().to_owned();
state.app_name = win.get_app_name().to_owned();
state.pid = win.pid.unwrap_or(-1);
state.pid = win.pid.unwrap_or(UNKNOWN_PID);
}
None => state.pid = -1,
None => state.pid = NO_WINDOW_PID,
};
}
@ -68,7 +73,7 @@ impl BarModuleFn for BarModuleWindow {
state: Mutex::new(State {
name: String::new(),
app_name: String::new(),
pid: -1,
pid: INITIAL_PID,
}),
})
}
@ -102,11 +107,16 @@ impl BarModuleFn for BarModuleWindow {
fn build(&self, nai: &Option<NameAndInstance>) -> s::Block {
let mut state = self.state.lock().expect("Could not lock state.");
if should_refresh(self, nai) {
// In contrast to other modules, this one should only refresh its state
// initially at startup and when explicitly named by `nai` (caused by a
// window or workspace event).
if state.pid == INITIAL_PID
|| (nai.is_some() && should_refresh(self, nai))
{
refresh_state(&mut state);
}
let text = if state.pid == -1 {
let text = if state.pid == NO_WINDOW_PID {
String::new()
} else {
subst_placeholders(

Loading…
Cancel
Save