diff --git a/ewwtilities/src/main.rs b/ewwtilities/src/main.rs index 71943b4..4ec4d65 100644 --- a/ewwtilities/src/main.rs +++ b/ewwtilities/src/main.rs @@ -18,6 +18,9 @@ pub struct CliArgs { #[arg(index = 1, value_enum)] action: Option, + #[arg(index=2, required_if_eq("action", "workspace-selector"))] + source_workspace: Option, + #[arg(short, long)] debug: bool, } @@ -42,7 +45,7 @@ fn main() -> Result<(), Box> { run_calendar(); } ProcessType::WorkspaceSelector => { - run_workspace_selector(); + run_workspace_selector(&args); } } Ok(()) diff --git a/ewwtilities/src/workspace_switcher.rs b/ewwtilities/src/workspace_switcher.rs index da7938d..4cd6a35 100644 --- a/ewwtilities/src/workspace_switcher.rs +++ b/ewwtilities/src/workspace_switcher.rs @@ -1,38 +1,12 @@ use log::{debug, error}; -use std::io::stdin; -use std::io::IsTerminal; use std::process::Command; use serde::{Deserialize, Serialize}; use serde_json; -pub fn run_workspace_selector() { - let in_pipe = stdin(); - if in_pipe.is_terminal() { - error!("Workspace Selector process requires being run as a terminal process"); - panic!("Expected to be run in a terminal process, but was not"); - } - - let mut buffer = String::new(); - let bytes = in_pipe.read_line(&mut buffer).unwrap(); - - debug!("Received from pipe: {buffer}"); - - if bytes == 0 { - error!("The input pipe was empty! Unrecoverable error"); - panic!("The input pipe was empty! Unrecoverable error"); - } - - debug!("Attempting to parse buffer"); - - let src_workspace = match buffer.trim().parse::() { - Ok(val) => val, - Err(e) => { - error!("Error parsing stdin buffer: {e}"); - panic!("Could not parse stdin to i32"); - } - }; +use crate::CliArgs; +pub fn run_workspace_selector(cli: &CliArgs) { let output = { let std_out = match Command::new("hyprctl").arg("monitors").arg("-j").output() { Ok(val) => val, @@ -91,11 +65,12 @@ pub fn run_workspace_selector() { debug!("Monitor number adjusted: {}", monitor_num); // Because there is a monitor 0, make sure it is always at least monitor 1 - let target_workspace = src_workspace * (monitor_num + 1) as i32; + let target_workspace = cli.source_workspace.unwrap() * (monitor_num + 1) as i32; debug!("Target workspace: {}", target_workspace); - print!("{}", target_workspace); + debug!("Calling hyprctl and closing"); + Command::new("hyprctl").arg("dispatch").arg("workspace").arg(target_workspace.to_string()).output().unwrap(); }