GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat: focus next/prev workspace by config order; add `—next-active-workspace` and `—prev-active-workspace` (#783)
DreamMaoMao8eb71b839e15
diff --git a/packages/wm/src/app_command.rs b/packages/wm/src/app_command.rsindex 3a93dde6..f124c920 100644--- a/packages/wm/src/app_command.rs+++ b/packages/wm/src/app_command.rs@@ -317,6 +317,14 @@ impl InvokeCommand {focus_monitor(*monitor_index, state, config)?;}+ if args.next_active_workspace {+ focus_workspace(WorkspaceTarget::NextActive, state, config)?;+ }++ if args.prev_active_workspace {+ focus_workspace(WorkspaceTarget::PreviousActive, state, config)?;+ }+if args.next_workspace {focus_workspace(WorkspaceTarget::Next, state, config)?;}@@ -358,6 +366,24 @@ impl InvokeCommand {)?;}+ if args.next_active_workspace {+ move_window_to_workspace(+ window.clone(),+ WorkspaceTarget::NextActive,+ state,+ config,+ )?;+ }++ if args.prev_active_workspace {+ move_window_to_workspace(+ window.clone(),+ WorkspaceTarget::PreviousActive,+ state,+ config,+ )?;+ }+if args.next_workspace {move_window_to_workspace(window.clone(),@@ -723,6 +749,12 @@ pub struct InvokeFocusCommand {#[clap(long)]monitor: Option<usize>,+ #[clap(long)]+ next_active_workspace: bool,++ #[clap(long)]+ prev_active_workspace: bool,+#[clap(long)]next_workspace: bool,@@ -744,6 +776,12 @@ pub struct InvokeMoveCommand {#[clap(long)]workspace: Option<String>,+ #[clap(long)]+ next_active_workspace: bool,++ #[clap(long)]+ prev_active_workspace: bool,+#[clap(long)]next_workspace: bool,diff --git a/packages/wm/src/wm_state.rs b/packages/wm/src/wm_state.rsindex 16e82859..88599a31 100644--- a/packages/wm/src/wm_state.rs+++ b/packages/wm/src/wm_state.rs@@ -302,38 +302,75 @@ impl WmState {.as_ref().and_then(|name| self.workspace_by_name(&name)),),- WorkspaceTarget::Next => {- let workspaces = self.sorted_workspaces(config);- let origin_index = workspaces+ WorkspaceTarget::NextActive => {+ let active_workspaces = self.sorted_workspaces(config);+ let origin_index = active_workspaces.iter().position(|workspace| workspace.id() == origin_workspace.id()).context("Failed to get index of given workspace.")?;- let next_workspace = workspaces+ let next_active_workspace = active_workspaces.get(origin_index + 1)- .or_else(|| workspaces.first());+ .or_else(|| active_workspaces.first());(- next_workspace.map(|workspace| workspace.config().name),- next_workspace.cloned(),+ next_active_workspace.map(|workspace| workspace.config().name),+ next_active_workspace.cloned(),)}- WorkspaceTarget::Previous => {- let workspaces = self.sorted_workspaces(config);- let origin_index = workspaces+ WorkspaceTarget::PreviousActive => {+ let active_workspaces = self.sorted_workspaces(config);+ let origin_index = active_workspaces.iter().position(|workspace| workspace.id() == origin_workspace.id()).context("Failed to get index of given workspace.")?;- let prev_workspace = workspaces.get(- origin_index.checked_sub(1).unwrap_or(workspaces.len() - 1),+ let prev_active_workspace = active_workspaces.get(+ origin_index.checked_sub(1).unwrap_or(active_workspaces.len() - 1),);(- prev_workspace.map(|workspace| workspace.config().name),- prev_workspace.cloned(),+ prev_active_workspace.map(|workspace| workspace.config().name),+ prev_active_workspace.cloned(),)}+ WorkspaceTarget::Next => {+ let workspaces = &config.value.workspaces;+ let origin_name = origin_workspace.config().name.clone();+ let origin_index = workspaces.iter()+ .position(|workspace| workspace.name == origin_name)+ .context("Failed to get index of given workspace.")?;++ let next_workspace_config = workspaces+ .get(origin_index + 1)+ .or_else(|| workspaces.first());++ let next_workspace_name = next_workspace_config.map(|config| config.name.clone());+ let next_workspace = next_workspace_name+ .as_ref()+ .and_then(|name| self.workspace_by_name(name));++ (next_workspace_name, next_workspace)+ }+ WorkspaceTarget::Previous => {+ let workspaces = &config.value.workspaces;+ let origin_name = origin_workspace.config().name.clone();+ let origin_index = workspaces.iter()+ .position(|workspace| workspace.name == origin_name)+ .context("Failed to get index of given workspace.")?;++ let previous_workspace_config = workspaces.get(+ origin_index.checked_sub(1).unwrap_or(workspaces.len() - 1),+ );++ let previous_workspace_name = previous_workspace_config.map(|config| config.name.clone());+ let previous_workspace = previous_workspace_name+ .as_ref()+ .and_then(|name| self.workspace_by_name(name));++ (previous_workspace_name, previous_workspace)+ }+WorkspaceTarget::Direction(direction) => {let origin_monitor =origin_workspace.monitor().context("No focused monitor.")?;diff --git a/packages/wm/src/workspaces/workspace_target.rs b/packages/wm/src/workspaces/workspace_target.rsindex abda82ca..41d138a9 100644--- a/packages/wm/src/workspaces/workspace_target.rs+++ b/packages/wm/src/workspaces/workspace_target.rs@@ -3,6 +3,8 @@ use crate::common::Direction;pub enum WorkspaceTarget {Name(String),Recent,+ NextActive,+ PreviousActive,Next,Previous,Direction(Direction),