Fix bug with -l always being on

This commit is contained in:
Alexander Rosenberg 2024-04-26 22:01:27 -07:00
parent ff4d62ef31
commit 5eff1c42a7
Signed by: Zander671
GPG Key ID: 5FD0394ADBD72730

View File

@ -18,7 +18,7 @@ struct Flags {
tags: bool, tags: bool,
title: bool, title: bool,
urgency: bool, urgency: bool,
viewstag: bool, viewtags: bool,
layout: bool, layout: bool,
mode: bool, mode: bool,
focused: bool, focused: bool,
@ -31,7 +31,7 @@ impl Flags {
tags: false, tags: false,
title: false, title: false,
urgency: false, urgency: false,
viewstag: false, viewtags: false,
layout: false, layout: false,
mode: false, mode: false,
focused: false, focused: false,
@ -52,7 +52,7 @@ struct Env {
mode: Option<String>, mode: Option<String>,
tags: Option<HashMap<u32, Tags>>, tags: Option<HashMap<u32, Tags>>,
urgency: Option<HashMap<u32, Tags>>, urgency: Option<HashMap<u32, Tags>>,
viewstag: Option<HashMap<u32, Vec<u32>>>, viewtags: Option<HashMap<u32, Vec<u32>>>,
status_manager: Option<Main<ZriverStatusManagerV1>>, status_manager: Option<Main<ZriverStatusManagerV1>>,
} }
@ -123,10 +123,10 @@ impl Serialize for Env {
} else { } else {
state.skip_field("urgency")?; state.skip_field("urgency")?;
} }
if let Some(viewstag) = self.viewstag.as_ref() { if let Some(viewtags) = self.viewtags.as_ref() {
state.serialize_field("viewstag", &self.translate_output_map(viewstag))?; state.serialize_field("viewtags", &self.translate_output_map(viewtags))?;
} else { } else {
state.skip_field("viewstag")?; state.skip_field("viewtags")?;
} }
state.end() state.end()
} }
@ -142,7 +142,7 @@ impl Env {
focused: None, focused: None,
tags: flags.tags.then(Default::default), tags: flags.tags.then(Default::default),
urgency: flags.urgency.then(Default::default), urgency: flags.urgency.then(Default::default),
viewstag: flags.viewstag.then(Default::default), viewtags: flags.viewtags.then(Default::default),
status_manager: None, status_manager: None,
flags, flags,
output_names: HashMap::default(), output_names: HashMap::default(),
@ -154,8 +154,9 @@ impl Env {
|| self.tags.is_some() || self.tags.is_some()
|| self.mode.is_some() || self.mode.is_some()
|| self.urgency.is_some() || self.urgency.is_some()
|| self.viewstag.is_some() || self.viewtags.is_some()
|| self.layout.is_some() || self.layout.is_some()
|| self.focused.is_some()
{ {
println!("{}", serde_json::to_string(self).unwrap()); println!("{}", serde_json::to_string(self).unwrap());
} }
@ -203,7 +204,9 @@ fn handle_seat_event(
wl_seat::Event::Name { name } => { wl_seat::Event::Name { name } => {
if let Some(env) = env.get::<Env>() { if let Some(env) = env.get::<Env>() {
if (env.flags.title || env.flags.mode || env.flags.focused) if (env.flags.title || env.flags.mode || env.flags.focused)
&& (env.flags.seat.is_none() || name.eq(env.flags.seat.as_ref().unwrap())) { && (env.flags.seat.is_none()
|| name.eq(env.flags.seat.as_ref().unwrap()))
{
if let Some(status_manager) = &env.status_manager { if let Some(status_manager) = &env.status_manager {
let seat_status = let seat_status =
status_manager.get_river_seat_status(&seat); status_manager.get_river_seat_status(&seat);
@ -237,7 +240,7 @@ fn handle_river_output_status(
zriver_output_status_v1::Event::ViewTags { zriver_output_status_v1::Event::ViewTags {
tags, tags,
} => { } => {
if let Some(viewstag) = &mut env.viewstag { if let Some(viewtags) = &mut env.viewtags {
let tags: Vec<u32> = tags[0..] let tags: Vec<u32> = tags[0..]
.chunks(4) .chunks(4)
.map(|s| { .map(|s| {
@ -252,10 +255,10 @@ fn handle_river_output_status(
0 0
}) })
.collect(); .collect();
if let Some(inner_value) = viewstag.get_mut(&output_id) { if let Some(inner_value) = viewtags.get_mut(&output_id) {
(*inner_value) = tags; (*inner_value) = tags;
} else { } else {
viewstag.insert(output_id, tags); viewtags.insert(output_id, tags);
} }
} }
} }
@ -273,8 +276,10 @@ fn handle_river_output_status(
zriver_output_status_v1::Event::LayoutName { zriver_output_status_v1::Event::LayoutName {
name, name,
} => { } => {
if env.flags.layout {
env.layout = Some(name); env.layout = Some(name);
} }
}
_ => {} _ => {}
} }
} }
@ -339,6 +344,46 @@ fn global_manager_callback(
} }
} }
fn configuration() -> Flags {
let mut default = Flags::default();
let mut args = std::env::args();
loop {
match args.next() {
Some(flag) => match flag.as_str() {
"--seat" | "-s" => default.seat = args.next(),
"--urgency" | "-u" => default.urgency = true,
"--title" | "-w" => default.title = true,
"--mode" | "-m" => default.mode = true,
"--focused" | "-f" => default.focused = true,
"--tags" | "-t" => default.tags = true,
"--layout" | "-l" => default.layout = true,
"--view-tags" | "-vt" => default.viewtags = true,
"--help" | "-h" => {
print!("Usage: ristate [option]\n\n");
print!(" --tag | -t the focused tag of each output\n");
print!(" --title | -w the title of the focused view\n");
print!(" --mode | -m the current input mode\n");
print!(" --layout | -l display the name of the layout\n");
print!(" --focused | -f the name of the focused output\n");
print!(" --urgency | -u tags with urgent views on them\n");
print!(" --view-tags | -vt the tags with views on them\n");
print!(" --seat | -s <string> select the seat\n");
std::process::exit(0);
}
_ => {}
},
None => break,
}
}
if !default.urgency && !default.title && !default.mode && !default.focused
&& !default.tags && !default.layout && !default.viewtags {
println!("error: You must specify at least one thing to listen for!");
std::process::exit(1);
}
default
}
fn main() { fn main() {
let mut env = Env::new(); let mut env = Env::new();
@ -365,38 +410,3 @@ fn main() {
env.fmt(); env.fmt();
} }
} }
fn configuration() -> Flags {
let mut default = Flags::default();
let mut args = std::env::args();
loop {
match args.next() {
Some(flag) => match flag.as_str() {
"--seat" | "-s" => default.seat = args.next(),
"--urgency" | "-u" => default.urgency = true,
"--title" | "-w" => default.title = true,
"--mode" | "-m" => default.mode = true,
"--focused" | "-f" => default.focused = true,
"--tags" | "-t" => default.tags = true,
"--layout" | "-l" => default.layout = true,
"--views-tag" | "-vt" => default.viewstag = true,
"--help" | "-h" => {
print!("Usage: ristate [option]\n\n");
print!(" --tag | -t the focused tag\n");
print!(" --title | -w the title of the focused view\n");
print!(" --mode | -m the current input mode\n");
print!(" --focused | -f the name of the focused output\n");
print!(" --urgency | -u urgent tag\n");
print!(" --views-tag | -vt the tag of all views\n");
print!(" --seat | -s <string> select the seat\n");
print!(" --layout | -l <string> display the name of the layout\n");
std::process::exit(0);
}
_ => {}
},
None => break,
}
}
default
}