Add the ability to see focused output
This commit is contained in:
parent
0adf3df830
commit
ff4d62ef31
71
src/main.rs
71
src/main.rs
@ -21,6 +21,7 @@ struct Flags {
|
|||||||
viewstag: bool,
|
viewstag: bool,
|
||||||
layout: bool,
|
layout: bool,
|
||||||
mode: bool,
|
mode: bool,
|
||||||
|
focused: bool,
|
||||||
seat: Option<String>,
|
seat: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,6 +34,7 @@ impl Flags {
|
|||||||
viewstag: false,
|
viewstag: false,
|
||||||
layout: false,
|
layout: false,
|
||||||
mode: false,
|
mode: false,
|
||||||
|
focused: false,
|
||||||
seat: None,
|
seat: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,6 +46,7 @@ struct Tags(u32);
|
|||||||
struct Env {
|
struct Env {
|
||||||
flags: Flags,
|
flags: Flags,
|
||||||
output_names: HashMap<u32, String>,
|
output_names: HashMap<u32, String>,
|
||||||
|
focused: Option<u32>,
|
||||||
layout: Option<String>,
|
layout: Option<String>,
|
||||||
title: Option<String>,
|
title: Option<String>,
|
||||||
mode: Option<String>,
|
mode: Option<String>,
|
||||||
@ -86,7 +89,7 @@ impl Serialize for Tags {
|
|||||||
impl Serialize for Env {
|
impl Serialize for Env {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where S: Serializer {
|
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() {
|
if let Some(layout) = self.layout.as_ref() {
|
||||||
state.serialize_field("layout", layout)?;
|
state.serialize_field("layout", layout)?;
|
||||||
} else {
|
} else {
|
||||||
@ -102,6 +105,14 @@ impl Serialize for Env {
|
|||||||
} else {
|
} else {
|
||||||
state.skip_field("mode")?;
|
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() {
|
if let Some(tags) = self.tags.as_ref() {
|
||||||
state.serialize_field("tags", &self.translate_output_map(tags))?;
|
state.serialize_field("tags", &self.translate_output_map(tags))?;
|
||||||
} else {
|
} else {
|
||||||
@ -128,6 +139,7 @@ impl Env {
|
|||||||
title: None,
|
title: None,
|
||||||
layout: None,
|
layout: None,
|
||||||
mode: None,
|
mode: 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),
|
viewstag: flags.viewstag.then(Default::default),
|
||||||
@ -162,22 +174,25 @@ fn handle_river_seat_status(
|
|||||||
_status: Main<ZriverSeatStatusV1>, event: zriver_seat_status_v1::Event,
|
_status: Main<ZriverSeatStatusV1>, event: zriver_seat_status_v1::Event,
|
||||||
mut env: DispatchData
|
mut env: DispatchData
|
||||||
) {
|
) {
|
||||||
match event {
|
if let Some(env) = env.get::<Env>() {
|
||||||
zriver_seat_status_v1::Event::FocusedView { title } => {
|
match event {
|
||||||
if let Some(env) = env.get::<Env>() {
|
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 {
|
if env.flags.title {
|
||||||
env.title = Some(title);
|
env.title = Some(title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
zriver_seat_status_v1::Event::Mode { name } => {
|
||||||
zriver_seat_status_v1::Event::Mode { name } => {
|
|
||||||
if let Some(env) = env.get::<Env>() {
|
|
||||||
if env.flags.mode {
|
if env.flags.mode {
|
||||||
env.mode = Some(name);
|
env.mode = Some(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,8 +202,8 @@ fn handle_seat_event(
|
|||||||
match event {
|
match 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.seat.is_none()
|
if (env.flags.title || env.flags.mode || env.flags.focused)
|
||||||
|| 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);
|
||||||
@ -269,18 +284,18 @@ fn handle_river_output_status(
|
|||||||
fn handle_output_event(
|
fn handle_output_event(
|
||||||
output: Main<WlOutput>, event: wl_output::Event, mut env: DispatchData
|
output: Main<WlOutput>, event: wl_output::Event, mut env: DispatchData
|
||||||
) {
|
) {
|
||||||
match event {
|
if let Some(env) = env.get::<Env>() {
|
||||||
wl_output::Event::Geometry {
|
match event {
|
||||||
x: _,
|
wl_output::Event::Geometry {
|
||||||
y: _,
|
x: _,
|
||||||
physical_width: _,
|
y: _,
|
||||||
physical_height: _,
|
physical_width: _,
|
||||||
subpixel: _,
|
physical_height: _,
|
||||||
make: _,
|
subpixel: _,
|
||||||
model: _,
|
make: _,
|
||||||
transform: _,
|
model: _,
|
||||||
} => {
|
transform: _,
|
||||||
if let Some(env) = env.get::<Env>() {
|
} => {
|
||||||
if let Some(status_manager) = &env.status_manager {
|
if let Some(status_manager) = &env.status_manager {
|
||||||
let output_status =
|
let output_status =
|
||||||
status_manager.get_river_output_status(&output);
|
status_manager.get_river_output_status(&output);
|
||||||
@ -289,15 +304,13 @@ fn handle_output_event(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
wl_output::Event::Name {
|
||||||
wl_output::Event::Name {
|
name,
|
||||||
name,
|
} => {
|
||||||
} => {
|
|
||||||
if let Some(env) = env.get::<Env>() {
|
|
||||||
env.output_names.insert(output.as_ref().id(), name);
|
env.output_names.insert(output.as_ref().id(), name);
|
||||||
}
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,6 +377,7 @@ fn configuration() -> Flags {
|
|||||||
"--urgency" | "-u" => default.urgency = true,
|
"--urgency" | "-u" => default.urgency = true,
|
||||||
"--title" | "-w" => default.title = true,
|
"--title" | "-w" => default.title = true,
|
||||||
"--mode" | "-m" => default.mode = true,
|
"--mode" | "-m" => default.mode = true,
|
||||||
|
"--focused" | "-f" => default.focused = true,
|
||||||
"--tags" | "-t" => default.tags = true,
|
"--tags" | "-t" => default.tags = true,
|
||||||
"--layout" | "-l" => default.layout = true,
|
"--layout" | "-l" => default.layout = true,
|
||||||
"--views-tag" | "-vt" => default.viewstag = true,
|
"--views-tag" | "-vt" => default.viewstag = true,
|
||||||
@ -372,6 +386,7 @@ fn configuration() -> Flags {
|
|||||||
print!(" --tag | -t the focused tag\n");
|
print!(" --tag | -t the focused tag\n");
|
||||||
print!(" --title | -w the title of the focused view\n");
|
print!(" --title | -w the title of the focused view\n");
|
||||||
print!(" --mode | -m the current input mode\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!(" --urgency | -u urgent tag\n");
|
||||||
print!(" --views-tag | -vt the tag of all views\n");
|
print!(" --views-tag | -vt the tag of all views\n");
|
||||||
print!(" --seat | -s <string> select the seat\n");
|
print!(" --seat | -s <string> select the seat\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user