about summary refs log tree commit diff
path: root/src/facility
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-11-25 04:26:26 -0700
committerIrene Knapp <ireneista@irenes.space>2026-11-25 04:26:26 -0700
commit3add32f831f40010700efc324f8f85c481eaf43d (patch)
treec66d9d4edf91c4b13f8df551ce50bf3efb615ef1 /src/facility
parentb65303ede0750e9d83df4d2c5df67f143c9171c4 (diff)
the i3 mode module now gets the name of the current mode at startup
rather than saying "unknown"

Force-Push: yes
Change-Id: Ib48db8f7e12663cd2f312cc2ae2b0a608575b005
Diffstat (limited to 'src/facility')
-rw-r--r--src/facility/i3.rs17
1 files changed, 14 insertions, 3 deletions
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<bool> {
 }
 
 
-pub fn parse_change_string(json: &[u8]) -> Result<String> {
+fn parse_top_level_key_string(json: &[u8], expected_key: &str) -> Result<String> {
   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<String> {
   }
 
   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<String> {
         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<String> {
+  parse_top_level_key_string(json, "change")
+}
+
+
+pub fn parse_name_string(json: &[u8]) -> Result<String> {
+  parse_top_level_key_string(json, "name")
+}
+