Add mode support and update dependencies

This commit is contained in:
2024-04-25 19:28:26 -07:00
parent 92e989f26c
commit 2731d486c7
3 changed files with 81 additions and 63 deletions

View File

@ -16,6 +16,7 @@ struct Flags {
urgency: bool,
viewstag: bool,
layout: bool,
mode: bool,
output: Option<String>,
seat: Option<String>,
}
@ -28,6 +29,7 @@ impl Flags {
urgency: false,
viewstag: false,
layout: false,
mode: false,
output: None,
seat: None,
}
@ -45,6 +47,8 @@ struct Env {
#[serde(skip_serializing_if = "Option::is_none")]
title: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
mode: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
tags: Option<BTreeMap<String, Tags>>,
#[serde(skip_serializing_if = "Option::is_none")]
urgency: Option<BTreeMap<String, Tags>>,
@ -60,6 +64,7 @@ impl Env {
Env {
title: None,
layout: None,
mode: None,
tags: flags.tags.then(BTreeMap::new),
urgency: flags.urgency.then(BTreeMap::new),
viewstag: flags.viewstag.then(BTreeMap::new),
@ -71,6 +76,7 @@ impl Env {
fn fmt(&self) {
if self.title.is_some()
|| self.tags.is_some()
|| self.mode.is_some()
|| self.urgency.is_some()
|| self.viewstag.is_some()
|| self.layout.is_some()
@ -103,7 +109,7 @@ fn main() {
seat.quick_assign(move |seat, event, mut env| match event {
wl_seat::Event::Name { name } => {
if let Some(env) = env.get::<Env>() {
if env.flags.title
if (env.flags.title || env.flags.mode)
&& (env.flags.seat.is_none()
|| name.eq(env.flags.seat.as_ref().unwrap()))
{
@ -113,7 +119,16 @@ fn main() {
move |_, event, mut env| match event {
zriver_seat_status_v1::Event::FocusedView { title } => {
if let Some(env) = env.get::<Env>() {
env.title = Some(title);
if env.flags.title {
env.title = Some(title);
}
}
}
zriver_seat_status_v1::Event::Mode { name } => {
if let Some(env) = env.get::<Env>() {
if env.flags.mode {
env.mode = Some(name);
}
}
}
_ => {}
@ -251,6 +266,7 @@ fn configuration() -> Flags {
"--output" | "-o" => default.output = args.next(),
"--urgency" | "-u" => default.urgency = true,
"--title" | "-w" => default.title = true,
"--mode" | "-m" => default.mode = true,
"--tags" | "-t" => default.tags = true,
"--layout" | "-l" => default.layout = true,
"--views-tag" | "-vt" => default.viewstag = true,
@ -258,6 +274,7 @@ fn configuration() -> Flags {
print!("Usage: ristate [option]\n\n");
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!(" --urgency | -u urgent tag\n");
print!(" --views-tag | -vt the tag of all views\n");
print!(" --seat | -s <string> select the seat\n");