Print the title of each output
This commit is contained in:
parent
770568e68f
commit
380c72f0c3
75
src/main.rs
75
src/main.rs
@ -16,7 +16,7 @@ use wayland_client::{Attached, DispatchData, Display, GlobalEvent, GlobalManager
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Flags {
|
struct Flags {
|
||||||
tags: bool,
|
tags: bool,
|
||||||
title: bool,
|
titles: bool,
|
||||||
urgency: bool,
|
urgency: bool,
|
||||||
viewtags: bool,
|
viewtags: bool,
|
||||||
layout: bool,
|
layout: bool,
|
||||||
@ -29,7 +29,7 @@ impl Flags {
|
|||||||
fn default() -> Flags {
|
fn default() -> Flags {
|
||||||
Flags {
|
Flags {
|
||||||
tags: false,
|
tags: false,
|
||||||
title: false,
|
titles: false,
|
||||||
urgency: false,
|
urgency: false,
|
||||||
viewtags: false,
|
viewtags: false,
|
||||||
layout: false,
|
layout: false,
|
||||||
@ -48,7 +48,7 @@ struct Env {
|
|||||||
output_names: HashMap<u32, String>,
|
output_names: HashMap<u32, String>,
|
||||||
focused: Option<u32>,
|
focused: Option<u32>,
|
||||||
layout: Option<String>,
|
layout: Option<String>,
|
||||||
title: Option<String>,
|
titles: Option<HashMap<u32, String>>,
|
||||||
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>>,
|
||||||
@ -95,10 +95,10 @@ impl Serialize for Env {
|
|||||||
} else {
|
} else {
|
||||||
state.skip_field("layout")?;
|
state.skip_field("layout")?;
|
||||||
}
|
}
|
||||||
if let Some(title) = self.title.as_ref() {
|
if let Some(titles) = self.titles.as_ref() {
|
||||||
state.serialize_field("title", title)?;
|
state.serialize_field("titles", &self.translate_output_map(titles))?;
|
||||||
} else {
|
} else {
|
||||||
state.skip_field("title")?;
|
state.skip_field("titles")?;
|
||||||
}
|
}
|
||||||
if let Some(mode) = self.mode.as_ref() {
|
if let Some(mode) = self.mode.as_ref() {
|
||||||
state.serialize_field("mode", mode)?;
|
state.serialize_field("mode", mode)?;
|
||||||
@ -106,7 +106,7 @@ impl Serialize for Env {
|
|||||||
state.skip_field("mode")?;
|
state.skip_field("mode")?;
|
||||||
}
|
}
|
||||||
// kind of inelegant
|
// kind of inelegant
|
||||||
if self.focused.is_some() &&
|
if self.flags.focused && self.focused.is_some() &&
|
||||||
self.output_names.contains_key(&self.focused.unwrap()) {
|
self.output_names.contains_key(&self.focused.unwrap()) {
|
||||||
state.serialize_field(
|
state.serialize_field(
|
||||||
"focused", &self.output_names[&self.focused.unwrap()])?;
|
"focused", &self.output_names[&self.focused.unwrap()])?;
|
||||||
@ -136,10 +136,10 @@ impl Env {
|
|||||||
fn new() -> Env {
|
fn new() -> Env {
|
||||||
let flags = configuration();
|
let flags = configuration();
|
||||||
Env {
|
Env {
|
||||||
title: None,
|
|
||||||
layout: None,
|
layout: None,
|
||||||
mode: None,
|
mode: None,
|
||||||
focused: None,
|
focused: None,
|
||||||
|
titles: flags.titles.then(Default::default),
|
||||||
tags: flags.tags.then(Default::default),
|
tags: flags.tags.then(Default::default),
|
||||||
urgency: flags.urgency.then(Default::default),
|
urgency: flags.urgency.then(Default::default),
|
||||||
viewtags: flags.viewtags.then(Default::default),
|
viewtags: flags.viewtags.then(Default::default),
|
||||||
@ -150,7 +150,7 @@ impl Env {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn fmt(&self) {
|
fn fmt(&self) {
|
||||||
if self.title.is_some()
|
if self.titles.is_some()
|
||||||
|| self.tags.is_some()
|
|| self.tags.is_some()
|
||||||
|| self.mode.is_some()
|
|| self.mode.is_some()
|
||||||
|| self.urgency.is_some()
|
|| self.urgency.is_some()
|
||||||
@ -178,21 +178,23 @@ fn handle_river_seat_status(
|
|||||||
if let Some(env) = env.get::<Env>() {
|
if let Some(env) = env.get::<Env>() {
|
||||||
match event {
|
match event {
|
||||||
zriver_seat_status_v1::Event::FocusedOutput { output } => {
|
zriver_seat_status_v1::Event::FocusedOutput { output } => {
|
||||||
if env.flags.focused {
|
if env.flags.focused || env.flags.titles {
|
||||||
env.focused = Some(output.as_ref().id());
|
env.focused = Some(output.as_ref().id());
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
zriver_seat_status_v1::Event::FocusedView { title } => {
|
zriver_seat_status_v1::Event::FocusedView { title } => {
|
||||||
if env.flags.title {
|
if env.flags.titles && env.focused.is_some() {
|
||||||
env.title = Some(title);
|
if let Some(titles) = &mut env.titles {
|
||||||
|
titles.insert(env.focused.unwrap(), title);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
zriver_seat_status_v1::Event::Mode { name } => {
|
zriver_seat_status_v1::Event::Mode { name } => {
|
||||||
if env.flags.mode {
|
if env.flags.mode {
|
||||||
env.mode = Some(name);
|
env.mode = Some(name);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
_ => {}
|
_ => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -203,7 +205,7 @@ 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.focused)
|
if (env.flags.titles || env.flags.mode || env.flags.focused)
|
||||||
&& (env.flags.seat.is_none()
|
&& (env.flags.seat.is_none()
|
||||||
|| name.eq(env.flags.seat.as_ref().unwrap()))
|
|| name.eq(env.flags.seat.as_ref().unwrap()))
|
||||||
{
|
{
|
||||||
@ -230,11 +232,7 @@ fn handle_river_output_status(
|
|||||||
tags: focused_tags,
|
tags: focused_tags,
|
||||||
} => {
|
} => {
|
||||||
if let Some(tags) = &mut env.tags {
|
if let Some(tags) = &mut env.tags {
|
||||||
if let Some(inner_value) = tags.get_mut(&output_id) {
|
tags.insert(output_id, Tags(focused_tags));
|
||||||
(*inner_value) = Tags(focused_tags);
|
|
||||||
} else {
|
|
||||||
tags.insert(output_id, Tags(focused_tags));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
zriver_output_status_v1::Event::ViewTags {
|
zriver_output_status_v1::Event::ViewTags {
|
||||||
@ -245,8 +243,7 @@ fn handle_river_output_status(
|
|||||||
.chunks(4)
|
.chunks(4)
|
||||||
.map(|s| {
|
.map(|s| {
|
||||||
let buf = [s[0], s[1], s[2], s[3]];
|
let buf = [s[0], s[1], s[2], s[3]];
|
||||||
let tagmask =
|
let tagmask = u32::from_le_bytes(buf);
|
||||||
u32::from_le_bytes(buf);
|
|
||||||
for i in 0..32 {
|
for i in 0..32 {
|
||||||
if 1 << i == tagmask {
|
if 1 << i == tagmask {
|
||||||
return 1 + i;
|
return 1 + i;
|
||||||
@ -255,22 +252,14 @@ fn handle_river_output_status(
|
|||||||
0
|
0
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
if let Some(inner_value) = viewtags.get_mut(&output_id) {
|
viewtags.insert(output_id, tags);
|
||||||
(*inner_value) = tags;
|
|
||||||
} else {
|
|
||||||
viewtags.insert(output_id, tags);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
zriver_output_status_v1::Event::UrgentTags {
|
zriver_output_status_v1::Event::UrgentTags {
|
||||||
tags,
|
tags,
|
||||||
} => {
|
} => {
|
||||||
if let Some(urgency) = &mut env.urgency {
|
if let Some(urgency) = &mut env.urgency {
|
||||||
if let Some(inner_value) = urgency.get_mut(&output_id) {
|
urgency.insert(output_id, Tags(tags));
|
||||||
(*inner_value) = Tags(tags);
|
|
||||||
} else {
|
|
||||||
urgency .insert(output_id, Tags(tags));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
zriver_output_status_v1::Event::LayoutName {
|
zriver_output_status_v1::Event::LayoutName {
|
||||||
@ -339,6 +328,18 @@ fn global_manager_callback(
|
|||||||
GlobalEvent::Removed { id, interface: _ } => {
|
GlobalEvent::Removed { id, interface: _ } => {
|
||||||
if let Some(env) = env.get::<Env>() {
|
if let Some(env) = env.get::<Env>() {
|
||||||
env.output_names.remove(&id);
|
env.output_names.remove(&id);
|
||||||
|
if let Some(titles) = &mut env.titles {
|
||||||
|
titles.remove(&id);
|
||||||
|
}
|
||||||
|
if let Some(tags) = &mut env.tags {
|
||||||
|
tags.remove(&id);
|
||||||
|
}
|
||||||
|
if let Some(urgency) = &mut env.urgency {
|
||||||
|
urgency.remove(&id);
|
||||||
|
}
|
||||||
|
if let Some(viewtags) = &mut env.viewtags {
|
||||||
|
viewtags.remove(&id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -353,7 +354,7 @@ fn configuration() -> Flags {
|
|||||||
Some(flag) => match flag.as_str() {
|
Some(flag) => match flag.as_str() {
|
||||||
"--seat" | "-s" => default.seat = args.next(),
|
"--seat" | "-s" => default.seat = args.next(),
|
||||||
"--urgency" | "-u" => default.urgency = true,
|
"--urgency" | "-u" => default.urgency = true,
|
||||||
"--title" | "-w" => default.title = true,
|
"--title" | "-w" => default.titles = true,
|
||||||
"--mode" | "-m" => default.mode = true,
|
"--mode" | "-m" => default.mode = true,
|
||||||
"--focused" | "-f" => default.focused = true,
|
"--focused" | "-f" => default.focused = true,
|
||||||
"--tags" | "-t" => default.tags = true,
|
"--tags" | "-t" => default.tags = true,
|
||||||
@ -362,7 +363,7 @@ fn configuration() -> Flags {
|
|||||||
"--help" | "-h" => {
|
"--help" | "-h" => {
|
||||||
print!("Usage: ristate [option]\n\n");
|
print!("Usage: ristate [option]\n\n");
|
||||||
print!(" --tag | -t the focused tag of each output\n");
|
print!(" --tag | -t the focused tag of each output\n");
|
||||||
print!(" --title | -w the title of the focused view\n");
|
print!(" --titles | -w the titles of focused views\n");
|
||||||
print!(" --mode | -m the current input mode\n");
|
print!(" --mode | -m the current input mode\n");
|
||||||
print!(" --layout | -l display the name of the layout\n");
|
print!(" --layout | -l display the name of the layout\n");
|
||||||
print!(" --focused | -f the name of the focused output\n");
|
print!(" --focused | -f the name of the focused output\n");
|
||||||
@ -376,7 +377,7 @@ fn configuration() -> Flags {
|
|||||||
None => break,
|
None => break,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !default.urgency && !default.title && !default.mode && !default.focused
|
if !default.urgency && !default.titles && !default.mode && !default.focused
|
||||||
&& !default.tags && !default.layout && !default.viewtags {
|
&& !default.tags && !default.layout && !default.viewtags {
|
||||||
println!("error: You must specify at least one thing to listen for!");
|
println!("error: You must specify at least one thing to listen for!");
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
|
Loading…
Reference in New Issue
Block a user