diff --git a/ewwtilities/src/main.rs b/ewwtilities/src/main.rs index 0990946..d9829bb 100644 --- a/ewwtilities/src/main.rs +++ b/ewwtilities/src/main.rs @@ -9,7 +9,7 @@ use workspace_switcher::{prev_or_next_workspace_selector, run_workspace_selector #[derive(ValueEnum, Debug, Clone)] enum ProcessType { CalendarBackground, - WorkspaceSelector, + Workspace, PrevNextWorkspace, } @@ -19,9 +19,15 @@ pub struct CliArgs { #[arg(index = 1, value_enum)] action: Option, - #[arg(index=2, required_if_eq("action", "workspace-selector"))] + #[arg(index=2, required_if_eq("action", "workspace"))] source_workspace: Option, + #[arg(short, long, conflicts_with="switch_workspace", default_value="false")] + move_window: bool, + + #[arg(short, long, conflicts_with="move_window", default_value="false")] + switch_workspace: bool, + #[arg(short, long)] debug: bool, } @@ -45,7 +51,7 @@ fn main() -> Result<(), Box> { ProcessType::CalendarBackground => { run_calendar(); } - ProcessType::WorkspaceSelector => { + ProcessType::Workspace => { run_workspace_selector(&args); } ProcessType::PrevNextWorkspace => { diff --git a/ewwtilities/src/workspace_switcher.rs b/ewwtilities/src/workspace_switcher.rs index b46f458..763661e 100644 --- a/ewwtilities/src/workspace_switcher.rs +++ b/ewwtilities/src/workspace_switcher.rs @@ -68,6 +68,7 @@ fn _get_workspaces_info() -> Vec { } + pub fn prev_or_next_workspace_selector(cli: &CliArgs) { let monitors = get_monitors_info(); @@ -108,6 +109,12 @@ pub fn prev_or_next_workspace_selector(cli: &CliArgs) { } pub fn run_workspace_selector(cli: &CliArgs) { + + if !cli.move_window && !cli.switch_workspace { + error!("When action is 'workspace', either `--move-window` or `--switch-window` need to be set"); + panic!("When action is 'workspace', either `--move-window` or `--switch-window` need to be set"); + } + let output = get_monitors_info(); debug!("Parsed monitor json: {:#?}", output); @@ -145,7 +152,11 @@ pub fn run_workspace_selector(cli: &CliArgs) { debug!("Target workspace: {}", target_workspace); debug!("Calling hyprctl and closing"); - Command::new("hyprctl").arg("dispatch").arg("workspace").arg(target_workspace.to_string()).output().unwrap(); + if cli.switch_workspace { + Command::new("hyprctl").arg("dispatch").arg("workspace").arg(target_workspace.to_string()).output().unwrap(); + } else if cli.move_window { + Command::new("hyprctl").arg("dispatch").arg("movetoworkspacesilent").arg(target_workspace.to_string()).output().unwrap(); + } }