From 8a6a727b69efd5656aec16576c3907528af49ba2 Mon Sep 17 00:00:00 2001 From: Skia Date: Fri, 15 Jan 2021 01:11:32 +0100 Subject: [PATCH] Move 'get_workspaces' to its own function --- src/main.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index f5a9025..395bf9b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -155,6 +155,15 @@ fn get_outputs(stream: &UnixStream) -> Vec { serde_json::from_str(&o).unwrap() } +fn get_workspaces(stream: &UnixStream) -> Vec { + send_msg(&stream, GET_WORKSPACES, ""); + let ws = match read_msg(&stream) { + Ok(msg) => msg, + Err(_) => panic!("Unable to get current workspace"), + }; + serde_json::from_str(&ws).unwrap() +} + fn get_current_output_name(stream: &UnixStream) -> String { let outputs = get_outputs(&stream); @@ -167,12 +176,7 @@ fn get_current_output_name(stream: &UnixStream) -> String { } fn get_current_workspace_name(stream: &UnixStream) -> String { - send_msg(&stream, GET_WORKSPACES, ""); - let ws = match read_msg(&stream) { - Ok(msg) => msg, - Err(_) => panic!("Unable to get current workspace"), - }; - let workspaces: Vec = serde_json::from_str(&ws).unwrap(); + let workspaces = get_workspaces(&stream); let focused_workspace_index = match workspaces.iter().position(|x| x.focused) { Some(i) => i,