Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: focus next/prev workspace by config order; add —next-active-workspace and —prev-active-workspace #783

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions packages/wm/src/app_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,14 @@ impl InvokeCommand {
focus_workspace(WorkspaceTarget::Previous, state, config)?;
}

if args.next_order_workspace {
focus_workspace(WorkspaceTarget::NextOrder, state, config)?;
}

if args.prev_order_workspace {
focus_workspace(WorkspaceTarget::PreviousOrder, state, config)?;
}

if args.recent_workspace {
focus_workspace(WorkspaceTarget::Recent, state, config)?;
}
Expand Down Expand Up @@ -376,6 +384,24 @@ impl InvokeCommand {
)?;
}

if args.next_order_workspace {
move_window_to_workspace(
window.clone(),
WorkspaceTarget::NextOrder,
state,
config,
)?;
}

if args.prev_order_workspace {
move_window_to_workspace(
window.clone(),
WorkspaceTarget::PreviousOrder,
state,
config,
)?;
}

if args.recent_workspace {
move_window_to_workspace(
window,
Expand Down Expand Up @@ -729,6 +755,12 @@ pub struct InvokeFocusCommand {
#[clap(long)]
prev_workspace: bool,

#[clap(long)]
next_order_workspace: bool,

#[clap(long)]
prev_order_workspace: bool,

#[clap(long)]
recent_workspace: bool,
}
Expand All @@ -750,6 +782,12 @@ pub struct InvokeMoveCommand {
#[clap(long)]
prev_workspace: bool,

#[clap(long)]
next_order_workspace: bool,

#[clap(long)]
prev_order_workspace: bool,

#[clap(long)]
recent_workspace: bool,
}
Expand Down
41 changes: 41 additions & 0 deletions packages/wm/src/wm_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,47 @@ impl WmState {
prev_workspace.cloned(),
)
}
WorkspaceTarget::PreviousOrder => {
let workspaces = &config.value.workspaces;
let origin_name = origin_workspace.config().name.clone();
let origin_index = workspaces.iter()
.position(|workspace| workspace.name == origin_name)
.unwrap_or_else(|| workspaces.len());

let previous_workspace_config = if origin_index > 0 {
workspaces.get(origin_index - 1)
} else {
workspaces.last()
};

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::NextOrder => {
let workspaces = &config.value.workspaces;
let origin_name = origin_workspace.config().name.clone();
let origin_index = workspaces.iter()
.position(|workspace| workspace.name == origin_name)
.unwrap_or_else(|| workspaces.len());

let next_workspace_config = if origin_index < workspaces.len() - 1 {
workspaces.get(origin_index + 1)
} 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::Direction(direction) => {
let origin_monitor =
origin_workspace.monitor().context("No focused monitor.")?;
Expand Down
2 changes: 2 additions & 0 deletions packages/wm/src/workspaces/workspace_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ pub enum WorkspaceTarget {
Recent,
Next,
Previous,
NextOrder,
PreviousOrder,
Direction(Direction),
}