From 3add32f831f40010700efc324f8f85c481eaf43d Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Wed, 25 Nov 2026 04:26:26 -0700 Subject: the i3 mode module now gets the name of the current mode at startup rather than saying "unknown" Force-Push: yes Change-Id: Ib48db8f7e12663cd2f312cc2ae2b0a608575b005 --- src/facility/i3.rs | 17 ++++++++++++++--- src/module/i3_mode.rs | 7 +++++-- 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/facility/i3.rs b/src/facility/i3.rs index 53258f8..4dd4a87 100644 --- a/src/facility/i3.rs +++ b/src/facility/i3.rs @@ -531,7 +531,7 @@ fn parse_success_object(json: &[u8]) -> Result { } -pub fn parse_change_string(json: &[u8]) -> Result { +fn parse_top_level_key_string(json: &[u8], expected_key: &str) -> Result { let mut parser = SliceJsonParser::new(json); if let JsonEvent::StartObject = parser.parse_next()? { } else { @@ -539,7 +539,7 @@ pub fn parse_change_string(json: &[u8]) -> Result { } if let JsonEvent::ObjectKey(key) = parser.parse_next()? { - if key == "change" { + if key == expected_key { if let JsonEvent::String(result) = parser.parse_next()? { /* That's our answer; exit early. */ return Ok(result.into_owned()); @@ -547,10 +547,21 @@ pub fn parse_change_string(json: &[u8]) -> Result { return Err(Error::custom("Reading i3 JSON, expected string.")); } } else { - return Err(Error::custom("Reading i3 JSON, expected \"change\" key.")); + return Err(Error::custom(&format!("Reading i3 JSON, expected {:?} key.", + expected_key))); } } else { return Err(Error::custom("Reading i3 JSON, expected object key.")); } } + +pub fn parse_change_string(json: &[u8]) -> Result { + parse_top_level_key_string(json, "change") +} + + +pub fn parse_name_string(json: &[u8]) -> Result { + parse_top_level_key_string(json, "name") +} + diff --git a/src/module/i3_mode.rs b/src/module/i3_mode.rs index c1b6484..96862eb 100644 --- a/src/module/i3_mode.rs +++ b/src/module/i3_mode.rs @@ -1,6 +1,8 @@ use crate::error::{ Error, Result }; use crate::facility::{ FacilityMap, FacilityType }; -use crate::facility::i3::{ parse_change_string, EventType, I3 }; +use crate::facility::i3::{ + parse_change_string, parse_name_string, EventType, I3 +}; use crate::module::{ CreatableModule, Module }; use std::sync::Arc; @@ -36,7 +38,8 @@ impl CreatableModule for I3ModeModule { return Err(Error::custom("Unable to subscribe to i3 mode changes.")); } - let current_mode = Arc::new(Mutex::new("unknown".to_string())); + let current_mode = Arc::new(Mutex::new(parse_name_string( + i3.command(12, "").await?.as_bytes())?)); let update_task = executor.spawn(update_loop(receiver, Arc::clone(¤t_mode), -- cgit 1.4.1