diff --git a/src/main.rs b/src/main.rs index bd09938..d61e560 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,7 @@ struct Flags { tags: bool, title: bool, urgency: bool, - viewstag: bool, + viewtags: bool, layout: bool, mode: bool, focused: bool, @@ -31,7 +31,7 @@ impl Flags { tags: false, title: false, urgency: false, - viewstag: false, + viewtags: false, layout: false, mode: false, focused: false, @@ -52,7 +52,7 @@ struct Env { mode: Option, tags: Option>, urgency: Option>, - viewstag: Option>>, + viewtags: Option>>, status_manager: Option>, } @@ -123,10 +123,10 @@ impl Serialize for Env { } else { state.skip_field("urgency")?; } - if let Some(viewstag) = self.viewstag.as_ref() { - state.serialize_field("viewstag", &self.translate_output_map(viewstag))?; + if let Some(viewtags) = self.viewtags.as_ref() { + state.serialize_field("viewtags", &self.translate_output_map(viewtags))?; } else { - state.skip_field("viewstag")?; + state.skip_field("viewtags")?; } state.end() } @@ -142,7 +142,7 @@ impl Env { focused: None, tags: flags.tags.then(Default::default), urgency: flags.urgency.then(Default::default), - viewstag: flags.viewstag.then(Default::default), + viewtags: flags.viewtags.then(Default::default), status_manager: None, flags, output_names: HashMap::default(), @@ -154,8 +154,9 @@ impl Env { || self.tags.is_some() || self.mode.is_some() || self.urgency.is_some() - || self.viewstag.is_some() + || self.viewtags.is_some() || self.layout.is_some() + || self.focused.is_some() { println!("{}", serde_json::to_string(self).unwrap()); } @@ -203,13 +204,15 @@ fn handle_seat_event( wl_seat::Event::Name { name } => { if let Some(env) = env.get::() { if (env.flags.title || env.flags.mode || env.flags.focused) - && (env.flags.seat.is_none() || name.eq(env.flags.seat.as_ref().unwrap())) { - if let Some(status_manager) = &env.status_manager { - let seat_status = - status_manager.get_river_seat_status(&seat); - seat_status.quick_assign(handle_river_seat_status); - } + && (env.flags.seat.is_none() + || name.eq(env.flags.seat.as_ref().unwrap())) + { + if let Some(status_manager) = &env.status_manager { + let seat_status = + status_manager.get_river_seat_status(&seat); + seat_status.quick_assign(handle_river_seat_status); } + } } } _ => {} @@ -237,7 +240,7 @@ fn handle_river_output_status( zriver_output_status_v1::Event::ViewTags { tags, } => { - if let Some(viewstag) = &mut env.viewstag { + if let Some(viewtags) = &mut env.viewtags { let tags: Vec = tags[0..] .chunks(4) .map(|s| { @@ -252,10 +255,10 @@ fn handle_river_output_status( 0 }) .collect(); - if let Some(inner_value) = viewstag.get_mut(&output_id) { + if let Some(inner_value) = viewtags.get_mut(&output_id) { (*inner_value) = tags; } else { - viewstag.insert(output_id, tags); + viewtags.insert(output_id, tags); } } } @@ -273,7 +276,9 @@ fn handle_river_output_status( zriver_output_status_v1::Event::LayoutName { name, } => { - env.layout = Some(name); + if env.flags.layout { + 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 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() { let mut env = Env::new(); @@ -365,38 +410,3 @@ fn main() { 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 select the seat\n"); - print!(" --layout | -l display the name of the layout\n"); - std::process::exit(0); - } - _ => {} - }, - None => break, - } - } - default -}