Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 12 additions & 0 deletions packages/wm-common/src/app_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,12 @@ pub struct InvokeFocusCommand {

#[clap(long)]
pub recent_workspace: bool,

#[clap(long)]
pub next_populated_workspace: bool,

#[clap(long)]
pub prev_populated_workspace: bool,
}

#[derive(Args, Clone, Debug, PartialEq, Serialize)]
Expand Down Expand Up @@ -399,6 +405,12 @@ pub struct InvokeMoveCommand {

#[clap(long)]
pub recent_workspace: bool,

#[clap(long)]
pub next_populated_workspace: bool,

#[clap(long)]
pub prev_populated_workspace: bool,
}

#[derive(Args, Clone, Debug, PartialEq, Serialize)]
Expand Down
2 changes: 2 additions & 0 deletions packages/wm/src/models/workspace_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pub enum WorkspaceTarget {
PreviousActiveInMonitor,
Next,
Previous,
NextPopulated,
PreviousPopulated,
#[allow(dead_code)]
Direction(Direction),
}
36 changes: 35 additions & 1 deletion packages/wm/src/wm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,22 @@ impl WindowManager {
)?;
}

if args.next_populated_workspace {
focus_workspace(
WorkspaceTarget::NextPopulated,
state,
config,
)?;
}

if args.prev_populated_workspace {
focus_workspace(
WorkspaceTarget::PreviousPopulated,
state,
config,
)?;
}

Ok(())
}
InvokeCommand::Ignore => {
Expand Down Expand Up @@ -411,12 +427,30 @@ impl WindowManager {

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

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

if args.prev_populated_workspace {
move_window_to_workspace(
window,
WorkspaceTarget::PreviousPopulated,
state,
config,
)?;
}
Ok(())
}

Expand Down
96 changes: 96 additions & 0 deletions packages/wm/src/wm_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,102 @@ impl WmState {
(previous_workspace_name, previous_workspace)
}

WorkspaceTarget::NextPopulated => {
let all_sorted = self.sorted_workspaces(config);
let populated: Vec<_> = all_sorted
.iter()
.filter(|w| w.has_children())
.cloned()
.collect();

let next = if populated.is_empty() {
None
} else {
match populated
.iter()
.position(|w| w.id() == origin_workspace.id())
{
Some(i) => populated
.get(i + 1)
.or_else(|| populated.first())
.cloned(),
None => {
// Origin is empty; find its position in the full
// sorted list and pick the next populated workspace.
let origin_pos = all_sorted
.iter()
.position(|w| w.id() == origin_workspace.id())
.unwrap_or(0);
populated
.iter()
.find(|w| {
all_sorted
.iter()
.position(|s| s.id() == w.id())
.unwrap_or(0)
> origin_pos
})
.or_else(|| populated.first())
.cloned()
}
}
};

(
next.as_ref().map(|w| w.config().name),
next,
)
}
WorkspaceTarget::PreviousPopulated => {
let all_sorted = self.sorted_workspaces(config);
let populated: Vec<_> = all_sorted
.iter()
.filter(|w| w.has_children())
.cloned()
.collect();

let prev = if populated.is_empty() {
None
} else {
match populated
.iter()
.position(|w| w.id() == origin_workspace.id())
{
Some(i) => populated
.get(
i.checked_sub(1)
.unwrap_or(populated.len() - 1),
)
.cloned(),
None => {
// Origin is empty; find its position in the full
// sorted list and pick the previous populated workspace.
let origin_pos = all_sorted
.iter()
.position(|w| w.id() == origin_workspace.id())
.unwrap_or(0);
populated
.iter()
.rev()
.find(|w| {
all_sorted
.iter()
.position(|s| s.id() == w.id())
.unwrap_or(0)
< origin_pos
})
.or_else(|| populated.last())
.cloned()
}
}
};

(
prev.as_ref().map(|w| w.config().name),
prev,
)
}

WorkspaceTarget::Direction(direction) => {
let origin_monitor =
origin_workspace.monitor().context("No focused monitor.")?;
Expand Down