Add gtk_ids field
This commit is contained in:
parent
380c72f0c3
commit
3de24bc47f
27
src/main.rs
27
src/main.rs
@ -8,7 +8,7 @@ use river_protocols::{
|
||||
use serde::ser::{SerializeSeq, SerializeStruct, Serializer};
|
||||
use serde::Serialize;
|
||||
use wayland_client::protocol::wl_registry::WlRegistry;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use wayland_client::protocol::{wl_output, wl_output::WlOutput, wl_seat,
|
||||
wl_seat::WlSeat};
|
||||
use wayland_client::{Attached, DispatchData, Display, GlobalEvent, GlobalManager, Main};
|
||||
@ -22,6 +22,7 @@ struct Flags {
|
||||
layout: bool,
|
||||
mode: bool,
|
||||
focused: bool,
|
||||
gtk_nums: bool,
|
||||
seat: Option<String>,
|
||||
}
|
||||
|
||||
@ -35,6 +36,7 @@ impl Flags {
|
||||
layout: false,
|
||||
mode: false,
|
||||
focused: false,
|
||||
gtk_nums: false,
|
||||
seat: None,
|
||||
}
|
||||
}
|
||||
@ -45,7 +47,7 @@ struct Tags(u32);
|
||||
|
||||
struct Env {
|
||||
flags: Flags,
|
||||
output_names: HashMap<u32, String>,
|
||||
output_names: BTreeMap<u32, String>,
|
||||
focused: Option<u32>,
|
||||
layout: Option<String>,
|
||||
titles: Option<HashMap<u32, String>>,
|
||||
@ -89,7 +91,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", 7)?;
|
||||
let mut state = serializer.serialize_struct("Env", 8)?;
|
||||
if let Some(layout) = self.layout.as_ref() {
|
||||
state.serialize_field("layout", layout)?;
|
||||
} else {
|
||||
@ -128,6 +130,18 @@ impl Serialize for Env {
|
||||
} else {
|
||||
state.skip_field("viewtags")?;
|
||||
}
|
||||
if self.flags.gtk_nums {
|
||||
let mut name_id_map = HashMap::<&str, u32>::new();
|
||||
name_id_map.reserve(self.output_names.len());
|
||||
let mut id = 0;
|
||||
for (_, value) in &self.output_names {
|
||||
name_id_map.insert(value, id);
|
||||
id += 1;
|
||||
}
|
||||
state.serialize_field("gtk_ids", &name_id_map)?;
|
||||
} else {
|
||||
state.skip_field("gtk_ids")?;
|
||||
}
|
||||
state.end()
|
||||
}
|
||||
}
|
||||
@ -145,7 +159,7 @@ impl Env {
|
||||
viewtags: flags.viewtags.then(Default::default),
|
||||
status_manager: None,
|
||||
flags,
|
||||
output_names: HashMap::default(),
|
||||
output_names: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,6 +171,7 @@ impl Env {
|
||||
|| self.viewtags.is_some()
|
||||
|| self.layout.is_some()
|
||||
|| self.focused.is_some()
|
||||
|| self.flags.gtk_nums
|
||||
{
|
||||
println!("{}", serde_json::to_string(self).unwrap());
|
||||
}
|
||||
@ -360,6 +375,7 @@ fn configuration() -> Flags {
|
||||
"--tags" | "-t" => default.tags = true,
|
||||
"--layout" | "-l" => default.layout = true,
|
||||
"--view-tags" | "-vt" => default.viewtags = true,
|
||||
"--gtk-ids" | "-g" => default.gtk_nums = true,
|
||||
"--help" | "-h" => {
|
||||
print!("Usage: ristate [option]\n\n");
|
||||
print!(" --tag | -t the focused tag of each output\n");
|
||||
@ -369,6 +385,7 @@ fn configuration() -> Flags {
|
||||
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!(" --gtk-ids | -g attempt to map output names to their gtk id\n");
|
||||
print!(" --seat | -s <string> select the seat\n");
|
||||
std::process::exit(0);
|
||||
}
|
||||
@ -378,7 +395,7 @@ fn configuration() -> Flags {
|
||||
}
|
||||
}
|
||||
if !default.urgency && !default.titles && !default.mode && !default.focused
|
||||
&& !default.tags && !default.layout && !default.viewtags {
|
||||
&& !default.tags && !default.layout && !default.viewtags && !default.gtk_nums {
|
||||
println!("error: You must specify at least one thing to listen for!");
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user