added function to move windows

This commit is contained in:
Nickiel12 2024-11-22 19:59:28 -08:00
parent d4bb5118da
commit 7f9439b8b0
2 changed files with 21 additions and 4 deletions

View file

@ -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<ProcessType>,
#[arg(index=2, required_if_eq("action", "workspace-selector"))]
#[arg(index=2, required_if_eq("action", "workspace"))]
source_workspace: Option<i32>,
#[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<dyn std::error::Error>> {
ProcessType::CalendarBackground => {
run_calendar();
}
ProcessType::WorkspaceSelector => {
ProcessType::Workspace => {
run_workspace_selector(&args);
}
ProcessType::PrevNextWorkspace => {

View file

@ -68,6 +68,7 @@ fn _get_workspaces_info() -> Vec<WorkspaceInfo> {
}
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();
}
}