Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

feat: add `focus --container-id <id>` command (#963)

Jens Fredskova5b70454f166
diff --git a/packages/wm-common/src/app_command.rs b/packages/wm-common/src/app_command.rs
index b98fa614..0f30e20b 100644
--- a/packages/wm-common/src/app_command.rs
+++ b/packages/wm-common/src/app_command.rs
@@ -307,6 +307,9 @@ pub struct InvokeFocusCommand {
#[clap(long)]
pub direction: Option<Direction>,
+ #[clap(long)]
+ pub container_id: Option<Uuid>,
+
#[clap(long)]
pub workspace: Option<String>,
diff --git a/packages/wm/src/commands/container/focus_container_by_id.rs b/packages/wm/src/commands/container/focus_container_by_id.rs
new file mode 100644
index 00000000..cee089b8
--- /dev/null
+++ b/packages/wm/src/commands/container/focus_container_by_id.rs
@@ -0,0 +1,20 @@
+use anyhow::Context;
+use uuid::Uuid;
+
+use super::set_focused_descendant;
+use crate::wm_state::WmState;
+
+pub fn focus_container_by_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(())
+}
diff --git a/packages/wm/src/commands/container/mod.rs b/packages/wm/src/commands/container/mod.rs
index b42854eb..61471cd1 100644
--- a/packages/wm/src/commands/container/mod.rs
+++ b/packages/wm/src/commands/container/mod.rs
@@ -2,6 +2,7 @@ mod attach_container;
mod detach_container;
mod flatten_child_split_containers;
mod flatten_split_container;
+mod focus_container_by_id;
mod focus_in_direction;
mod move_container_within_tree;
mod replace_container;
@@ -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_by_id::*;
pub use focus_in_direction::*;
pub use move_container_within_tree::*;
pub use replace_container::*;
diff --git a/packages/wm/src/wm.rs b/packages/wm/src/wm.rs
index 946c6e53..e7593b9e 100644
--- a/packages/wm/src/wm.rs
+++ b/packages/wm/src/wm.rs
@@ -11,7 +11,8 @@ use wm_platform::PlatformEvent;
use crate::{
commands::{
container::{
- focus_in_direction, set_tiling_direction, toggle_tiling_direction,
+ focus_container_by_id, focus_in_direction, set_tiling_direction,
+ toggle_tiling_direction,
},
general::{
cycle_focus, disable_binding_mode, enable_binding_mode,
@@ -238,6 +239,10 @@ impl WindowManager {
focus_in_direction(&subject_container, direction, state)?;
}
+ if let Some(container_id) = &args.container_id {
+ focus_container_by_id(container_id, state)?;
+ }
+
if let Some(name) = &args.workspace {
focus_workspace(
WorkspaceTarget::Name(name.to_string()),