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: add focus_container_id command #963

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions packages/wm-common/src/app_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ pub struct InvokeFocusCommand {
#[clap(long)]
pub direction: Option<Direction>,

#[clap(long)]
pub container_id: Option<Uuid>,

#[clap(long)]
pub workspace: Option<String>,

Expand Down
20 changes: 20 additions & 0 deletions packages/wm/src/commands/container/focus_container_id.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use anyhow::Context;
use uuid::Uuid;

use super::set_focused_descendant;
use crate::wm_state::WmState;

pub fn focus_container_id(
container_id: &Uuid,
state: &mut WmState,
) -> anyhow::Result<()> {
let focus_target = state
.container_by_id(*container_id)
.context("No container with given id")?;

// Set focus to the target container.
set_focused_descendant(&focus_target, None);
state.pending_sync.queue_focus_change().queue_cursor_jump();

Ok(())
}
2 changes: 2 additions & 0 deletions packages/wm/src/commands/container/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod attach_container;
mod detach_container;
mod flatten_child_split_containers;
mod flatten_split_container;
mod focus_container_id;
mod focus_in_direction;
mod move_container_within_tree;
mod replace_container;
Expand All @@ -14,6 +15,7 @@ pub use attach_container::*;
pub use detach_container::*;
pub use flatten_child_split_containers::*;
pub use flatten_split_container::*;
pub use focus_container_id::*;
pub use focus_in_direction::*;
pub use move_container_within_tree::*;
pub use replace_container::*;
Expand Down
7 changes: 6 additions & 1 deletion packages/wm/src/wm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use wm_platform::PlatformEvent;
use crate::{
commands::{
container::{
focus_in_direction, set_tiling_direction, toggle_tiling_direction,
focus_container_id, focus_in_direction, set_tiling_direction,
toggle_tiling_direction,
},
general::{
cycle_focus, disable_binding_mode, enable_binding_mode,
Expand Down Expand Up @@ -238,6 +239,10 @@ impl WindowManager {
focus_in_direction(&subject_container, direction, state)?;
}

if let Some(container_id) = &args.container_id {
focus_container_id(container_id, state)?;
}

if let Some(name) = &args.workspace {
focus_workspace(
WorkspaceTarget::Name(name.to_string()),
Expand Down