From ff4d62ef317821128838d7b3d69be17dfd0335d1 Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Fri, 26 Apr 2024 21:50:23 -0700 Subject: [PATCH] Add the ability to see focused output --- src/main.rs | 71 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 28 deletions(-) diff --git a/src/main.rs b/src/main.rs index 50f050e..bd09938 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,7 @@ struct Flags { viewstag: bool, layout: bool, mode: bool, + focused: bool, seat: Option, } @@ -33,6 +34,7 @@ impl Flags { viewstag: false, layout: false, mode: false, + focused: false, seat: None, } } @@ -44,6 +46,7 @@ struct Tags(u32); struct Env { flags: Flags, output_names: HashMap, + focused: Option, layout: Option, title: Option, mode: Option, @@ -86,7 +89,7 @@ impl Serialize for Tags { impl Serialize for Env { fn serialize(&self, serializer: S) -> Result where S: Serializer { - let mut state = serializer.serialize_struct("Env", 6)?; + let mut state = serializer.serialize_struct("Env", 7)?; if let Some(layout) = self.layout.as_ref() { state.serialize_field("layout", layout)?; } else { @@ -102,6 +105,14 @@ impl Serialize for Env { } else { state.skip_field("mode")?; } + // kind of inelegant + if self.focused.is_some() && + self.output_names.contains_key(&self.focused.unwrap()) { + state.serialize_field( + "focused", &self.output_names[&self.focused.unwrap()])?; + } else { + state.skip_field("focused")?; + } if let Some(tags) = self.tags.as_ref() { state.serialize_field("tags", &self.translate_output_map(tags))?; } else { @@ -128,6 +139,7 @@ impl Env { title: None, layout: None, mode: None, + focused: None, tags: flags.tags.then(Default::default), urgency: flags.urgency.then(Default::default), viewstag: flags.viewstag.then(Default::default), @@ -162,22 +174,25 @@ fn handle_river_seat_status( _status: Main, event: zriver_seat_status_v1::Event, mut env: DispatchData ) { - match event { - zriver_seat_status_v1::Event::FocusedView { title } => { - if let Some(env) = env.get::() { + if let Some(env) = env.get::() { + match event { + zriver_seat_status_v1::Event::FocusedOutput { output } => { + if env.flags.focused { + env.focused = Some(output.as_ref().id()); + } + } + zriver_seat_status_v1::Event::FocusedView { title } => { if env.flags.title { env.title = Some(title); } } - } - zriver_seat_status_v1::Event::Mode { name } => { - if let Some(env) = env.get::() { + zriver_seat_status_v1::Event::Mode { name } => { if env.flags.mode { env.mode = Some(name); } } + _ => {} } - _ => {} } } @@ -187,8 +202,8 @@ fn handle_seat_event( match event { wl_seat::Event::Name { name } => { if let Some(env) = env.get::() { - if (env.flags.title || env.flags.mode) && (env.flags.seat.is_none() - || name.eq(env.flags.seat.as_ref().unwrap())) { + 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); @@ -269,18 +284,18 @@ fn handle_river_output_status( fn handle_output_event( output: Main, event: wl_output::Event, mut env: DispatchData ) { - match event { - wl_output::Event::Geometry { - x: _, - y: _, - physical_width: _, - physical_height: _, - subpixel: _, - make: _, - model: _, - transform: _, - } => { - if let Some(env) = env.get::() { + if let Some(env) = env.get::() { + match event { + wl_output::Event::Geometry { + x: _, + y: _, + physical_width: _, + physical_height: _, + subpixel: _, + make: _, + model: _, + transform: _, + } => { if let Some(status_manager) = &env.status_manager { let output_status = status_manager.get_river_output_status(&output); @@ -289,15 +304,13 @@ fn handle_output_event( }); } } - } - wl_output::Event::Name { - name, - } => { - if let Some(env) = env.get::() { + wl_output::Event::Name { + name, + } => { env.output_names.insert(output.as_ref().id(), name); } + _ => {} } - _ => {} } } @@ -364,6 +377,7 @@ fn configuration() -> Flags { "--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, @@ -372,6 +386,7 @@ fn configuration() -> Flags { 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");