better title support

This commit is contained in:
Bryan Ndjeutcha 2021-05-26 15:12:41 -04:00
parent 2e61ae41d4
commit 8a871058c1

View File

@ -1,7 +1,9 @@
mod wayland; 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 wayland_client::protocol::{ use wayland_client::protocol::{
wl_seat, wl_seat,
@ -13,7 +15,6 @@ use wayland_client::{Display, GlobalManager, Main};
struct Globals { struct Globals {
seats: Vec<Main<WlSeat>>, seats: Vec<Main<WlSeat>>,
outputs: Vec<Main<WlOutput>>, outputs: Vec<Main<WlOutput>>,
// xdg_outputs: Vec<Main<WlOutput>>,
status_manager: Option<Main<ZriverStatusManagerV1>>, status_manager: Option<Main<ZriverStatusManagerV1>>,
} }
@ -34,7 +35,18 @@ impl Keypair {
} }
impl Config { impl Config {
fn json(&self) { fn mod_value(&mut self, key: String, value: String) {
for keypair in &mut self.keypair {
if keypair.key.eq(&key) { keypair.value = value; break }
}
}
fn add_keypair(&mut self, key: String) {
self.keypair.push({ Keypair {
key: key,
value: String::new()
} });
}
fn to_string(&self) {
let len = self.keypair.len(); let len = self.keypair.len();
print!("{{"); print!("{{");
for (i,keypair) in self.keypair.iter().enumerate() { for (i,keypair) in self.keypair.iter().enumerate() {
@ -56,20 +68,19 @@ fn main() {
Globals { Globals {
seats: Vec::new(), seats: Vec::new(),
outputs: Vec::new(), outputs: Vec::new(),
// xdg_outputs: Vec::new(),
status_manager: None, status_manager: None,
} }
}; };
let mut args = std::env::args();
let mut config = { Config { let mut config = { Config {
seat_name: String::new(), seat_name: String::new(),
keypair: Vec::new() keypair: Vec::new()
} }; } };
let mut args = std::env::args();
let mut monitor = None; let mut monitor = None;
let mut enable_tag = true; let mut enable_tag = false;
let mut enable_title = false; let mut enable_title = false;
let mut enable_views_tag = true; let mut enable_views_tag = false;
args.next(); args.next();
loop { loop {
match args.next() { match args.next() {
@ -135,19 +146,20 @@ fn main() {
for seat in globals.seats { for seat in globals.seats {
if enable_title { if enable_title {
enable_tag = false;
enable_views_tag = false;
let seat_status = globals let seat_status = globals
.status_manager .status_manager
.as_ref() .as_ref()
.expect("Compositor doesn't implement river_status_unstable_v1") .expect("Compositor doesn't implement river_status_unstable_v1")
.get_river_seat_status(&seat); .get_river_seat_status(&seat);
config.add_keypair("title".to_owned());
seat.quick_assign(move |_, event, mut config| { seat.quick_assign(move |_, event, mut config| {
let seat_name = &config.get::<Config>().unwrap().seat_name; let seat_name = &config.get::<Config>().unwrap().seat_name;
match event { match event {
wl_seat::Event::Name{ name } => if seat_name.len() == 0 || name.eq(seat_name) { wl_seat::Event::Name{ name } => if seat_name.len() == 0 || name.eq(seat_name) {
seat_status.quick_assign(move |_, event, _| match event { seat_status.quick_assign(move |_, event, mut config| match event {
zriver_seat_status_v1::Event::FocusedView { title } => println!("{}", title), zriver_seat_status_v1::Event::FocusedView { title } => {
config.get::<Config>().unwrap().mod_value("title".to_owned(), title);
},
_ => {} _ => {}
}) })
} else { seat_status.quick_assign(move |_, _, _| {}) }, } else { seat_status.quick_assign(move |_, _, _| {}) },
@ -165,14 +177,8 @@ fn main() {
if *i == index { true } else { false } if *i == index { true } else { false }
} else { true }) } else { true })
{ {
config.keypair.push({ Keypair { if enable_tag { config.add_keypair(format!("tag{}",i)); }
key: format!("tag{}",i), if enable_views_tag { config.add_keypair(format!("views_tag{}",i)); }
value: String::new()
} });
config.keypair.push({ Keypair {
key: format!("views_tag{}",i),
value: String::new()
} });
let output_status = globals let output_status = globals
.status_manager .status_manager
.as_ref() .as_ref()
@ -181,9 +187,7 @@ fn main() {
output_status.quick_assign(move |_, event, mut config| match event { output_status.quick_assign(move |_, event, mut config| match event {
zriver_output_status_v1::Event::FocusedTags { tags } => { zriver_output_status_v1::Event::FocusedTags { tags } => {
if enable_tag { if enable_tag {
for keypair in &mut config.get::<Config>().unwrap().keypair { config.get::<Config>().unwrap().mod_value(format!("tag{}",i), base10(tags).trim_end().to_owned());
if keypair.key.eq(&format!("tag{}",i)) { keypair.value = base10(tags).trim_end().to_owned(); break }
}
} }
} }
zriver_output_status_v1::Event::ViewTags { tags } => { zriver_output_status_v1::Event::ViewTags { tags } => {
@ -194,9 +198,7 @@ fn main() {
let buf: [u8; 4] = [tags[i], tags[i + 1], tags[i + 2], tags[i + 3]]; let buf: [u8; 4] = [tags[i], tags[i + 1], tags[i + 2], tags[i + 3]];
views_tag.push_str(&base10(u32::from_le_bytes(buf))); views_tag.push_str(&base10(u32::from_le_bytes(buf)));
} }
for keypair in &mut config.get::<Config>().unwrap().keypair { config.get::<Config>().unwrap().mod_value(format!("views_tag{}",i), views_tag.trim_end().to_owned());
if keypair.key.eq(&format!("views_tag{}",i)) { keypair.value = views_tag.trim_end().to_owned(); break }
}
} }
} }
}); });
@ -214,9 +216,7 @@ fn main() {
); );
}) })
.unwrap(); .unwrap();
if enable_views_tag || enable_tag { if enable_views_tag || enable_tag || enable_title { config.to_string(); }
config.json();
}
} }
} }