HashMap -> BTreeMap

This commit is contained in:
Bryan Ndjeutcha 2021-09-09 15:05:49 -04:00
parent bf2f7a28eb
commit 34dfd0a0ba

View File

@ -3,16 +3,10 @@ mod wayland;
use crate::wayland::river_status_unstable_v1::{ use crate::wayland::river_status_unstable_v1::{
zriver_output_status_v1, zriver_seat_status_v1, zriver_status_manager_v1::ZriverStatusManagerV1, zriver_output_status_v1, zriver_seat_status_v1, zriver_status_manager_v1::ZriverStatusManagerV1,
}; };
use std::collections::HashMap; use std::collections::BTreeMap;
use wayland_client::protocol::{wl_output, wl_output::WlOutput, wl_seat, wl_seat::WlSeat}; use wayland_client::protocol::{wl_output, wl_output::WlOutput, wl_seat, wl_seat::WlSeat};
use wayland_client::{Display, GlobalManager, Main}; use wayland_client::{Display, GlobalManager, Main};
#[derive(Debug)]
enum Value {
Tags(u32),
ViewsTag(Vec<u32>),
}
#[derive(Debug)] #[derive(Debug)]
struct Flags { struct Flags {
tags: bool, tags: bool,
@ -36,12 +30,13 @@ impl Flags {
} }
} }
#[derive(Debug)]
struct Env { struct Env {
flags: Flags, flags: Flags,
title: Option<String>, title: Option<String>,
tags: HashMap<String, u32>, tags: BTreeMap<String, u32>,
urgency: HashMap<String, u32>, urgency: BTreeMap<String, u32>,
viewstag: HashMap<String, Vec<u32>>, viewstag: BTreeMap<String, Vec<u32>>,
status_manager: Option<Main<ZriverStatusManagerV1>>, status_manager: Option<Main<ZriverStatusManagerV1>>,
} }
@ -50,30 +45,12 @@ impl Env {
Env { Env {
title: None, title: None,
flags: configuration(), flags: configuration(),
viewstag: HashMap::new(), viewstag: BTreeMap::new(),
urgency: HashMap::new(), urgency: BTreeMap::new(),
tags: HashMap::new(), tags: BTreeMap::new(),
status_manager: None, status_manager: None,
} }
} }
fn set_value(&mut self, key: &str, value: Value) {
match value {
Value::Tags( tags ) => {
if let Some(inner_value) = self.tags.get_mut(key) {
(*inner_value) = tags;
} else {
self.tags.insert(key.to_string(), tags);
}
}
Value::ViewsTag( tags ) => {
if let Some(inner_value) = self.viewstag.get_mut(key) {
(*inner_value) = tags;
} else {
self.viewstag.insert(key.to_string(), tags);
}
}
}
}
fn fmt(&self) { fn fmt(&self) {
if !self.tags.is_empty() if !self.tags.is_empty()
|| !self.viewstag.is_empty() || !self.viewstag.is_empty()
@ -207,7 +184,11 @@ fn main() {
tags, tags,
} => { } => {
if env.flags.tags { if env.flags.tags {
env.set_value(&make, Value::Tags(tags)); if let Some(inner_value) = env.tags.get_mut(&make) {
(*inner_value) = tags;
} else {
env.tags.insert(make.clone(), tags);
}
} }
} }
zriver_output_status_v1::Event::ViewTags { zriver_output_status_v1::Event::ViewTags {
@ -228,10 +209,11 @@ fn main() {
0 0
}) })
.collect(); .collect();
env.set_value( if let Some(inner_value) = env.viewstag.get_mut(&make) {
&make, (*inner_value) = tags;
Value::ViewsTag(tags), } else {
); env.viewstag.insert(make.clone(), tags);
}
} }
} }
zriver_output_status_v1::Event::UrgentTags { zriver_output_status_v1::Event::UrgentTags {
@ -241,6 +223,7 @@ fn main() {
if let Some(inner_value) = env.urgency.get_mut(&make) { if let Some(inner_value) = env.urgency.get_mut(&make) {
(*inner_value) = tags; (*inner_value) = tags;
} else { } else {
// println!("{}", tags);
env.urgency.insert(make.clone(), tags); env.urgency.insert(make.clone(), tags);
} }
} }