Add the ability to see focused output

This commit is contained in:
Alexander Rosenberg 2024-04-26 21:50:23 -07:00
parent 0adf3df830
commit ff4d62ef31
Signed by: Zander671
GPG Key ID: 5FD0394ADBD72730

View File

@ -21,6 +21,7 @@ struct Flags {
viewstag: bool,
layout: bool,
mode: bool,
focused: bool,
seat: Option<String>,
}
@ -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<u32, String>,
focused: Option<u32>,
layout: Option<String>,
title: Option<String>,
mode: Option<String>,
@ -86,7 +89,7 @@ impl Serialize for Tags {
impl Serialize for Env {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
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<ZriverSeatStatusV1>, event: zriver_seat_status_v1::Event,
mut env: DispatchData
) {
match event {
zriver_seat_status_v1::Event::FocusedView { title } => {
if let Some(env) = env.get::<Env>() {
if let Some(env) = env.get::<Env>() {
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::<Env>() {
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::<Env>() {
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<WlOutput>, 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::<Env>() {
if let Some(env) = env.get::<Env>() {
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::<Env>() {
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 <string> select the seat\n");