mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-07-12 16:12:44 +02:00
feat(cli): add focus-stack-window cmd
This commit adds a new command, focus-stack-window, which allows users to focus windows in the focused container stack by their index (zero-indexed) within the stack. If the user tries to focus an index which does not correspond to a window within the container stack, an error will be logged.
This commit is contained in:
@@ -45,12 +45,13 @@ pub enum SocketMessage {
|
|||||||
CycleFocusWindow(CycleDirection),
|
CycleFocusWindow(CycleDirection),
|
||||||
CycleMoveWindow(CycleDirection),
|
CycleMoveWindow(CycleDirection),
|
||||||
StackWindow(OperationDirection),
|
StackWindow(OperationDirection),
|
||||||
|
UnstackWindow,
|
||||||
|
CycleStack(CycleDirection),
|
||||||
|
FocusStackWindow(usize),
|
||||||
StackAll,
|
StackAll,
|
||||||
UnstackAll,
|
UnstackAll,
|
||||||
ResizeWindowEdge(OperationDirection, Sizing),
|
ResizeWindowEdge(OperationDirection, Sizing),
|
||||||
ResizeWindowAxis(Axis, Sizing),
|
ResizeWindowAxis(Axis, Sizing),
|
||||||
UnstackWindow,
|
|
||||||
CycleStack(CycleDirection),
|
|
||||||
MoveContainerToMonitorNumber(usize),
|
MoveContainerToMonitorNumber(usize),
|
||||||
CycleMoveContainerToMonitor(CycleDirection),
|
CycleMoveContainerToMonitor(CycleDirection),
|
||||||
MoveContainerToWorkspaceNumber(usize),
|
MoveContainerToWorkspaceNumber(usize),
|
||||||
|
|||||||
@@ -228,6 +228,10 @@ impl WindowManager {
|
|||||||
self.cycle_container_window_in_direction(direction)?;
|
self.cycle_container_window_in_direction(direction)?;
|
||||||
self.focused_window()?.focus(self.mouse_follows_focus)?;
|
self.focused_window()?.focus(self.mouse_follows_focus)?;
|
||||||
}
|
}
|
||||||
|
SocketMessage::FocusStackWindow(idx) => {
|
||||||
|
self.focus_container_window(idx)?;
|
||||||
|
self.focused_window()?.focus(self.mouse_follows_focus)?;
|
||||||
|
}
|
||||||
SocketMessage::ForceFocus => {
|
SocketMessage::ForceFocus => {
|
||||||
let focused_window = self.focused_window()?;
|
let focused_window = self.focused_window()?;
|
||||||
let focused_window_rect = WindowsApi::window_rect(focused_window.hwnd())?;
|
let focused_window_rect = WindowsApi::window_rect(focused_window.hwnd())?;
|
||||||
|
|||||||
@@ -1534,6 +1534,31 @@ impl WindowManager {
|
|||||||
self.update_focused_workspace(self.mouse_follows_focus, true)
|
self.update_focused_workspace(self.mouse_follows_focus, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(skip(self))]
|
||||||
|
pub fn focus_container_window(&mut self, idx: usize) -> Result<()> {
|
||||||
|
self.handle_unmanaged_window_behaviour()?;
|
||||||
|
|
||||||
|
tracing::info!("focusing container window at index {idx}");
|
||||||
|
|
||||||
|
let container = self.focused_container_mut()?;
|
||||||
|
|
||||||
|
let len = NonZeroUsize::new(container.windows().len())
|
||||||
|
.ok_or_else(|| anyhow!("there must be at least one window in a container"))?;
|
||||||
|
|
||||||
|
if len.get() == 1 {
|
||||||
|
bail!("there is only one window in this container");
|
||||||
|
}
|
||||||
|
|
||||||
|
if container.windows().get(idx).is_none() {
|
||||||
|
bail!("there is no window in this container at index {idx}");
|
||||||
|
}
|
||||||
|
|
||||||
|
container.focus_window(idx);
|
||||||
|
container.load_focused_window();
|
||||||
|
|
||||||
|
self.update_focused_workspace(self.mouse_follows_focus, true)
|
||||||
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self))]
|
#[tracing::instrument(skip(self))]
|
||||||
pub fn stack_all(&mut self) -> Result<()> {
|
pub fn stack_all(&mut self) -> Result<()> {
|
||||||
self.handle_unmanaged_window_behaviour()?;
|
self.handle_unmanaged_window_behaviour()?;
|
||||||
|
|||||||
+12
-5
@@ -190,6 +190,7 @@ gen_target_subcommand_args! {
|
|||||||
FocusWorkspaces,
|
FocusWorkspaces,
|
||||||
MoveWorkspaceToMonitor,
|
MoveWorkspaceToMonitor,
|
||||||
SwapWorkspacesWithMonitor,
|
SwapWorkspacesWithMonitor,
|
||||||
|
FocusStackWindow,
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! gen_named_target_subcommand_args {
|
macro_rules! gen_named_target_subcommand_args {
|
||||||
@@ -944,6 +945,14 @@ enum SubCommand {
|
|||||||
/// Stack the focused window in the specified direction
|
/// Stack the focused window in the specified direction
|
||||||
#[clap(arg_required_else_help = true)]
|
#[clap(arg_required_else_help = true)]
|
||||||
Stack(Stack),
|
Stack(Stack),
|
||||||
|
/// Unstack the focused window
|
||||||
|
Unstack,
|
||||||
|
/// Cycle the focused stack in the specified cycle direction
|
||||||
|
#[clap(arg_required_else_help = true)]
|
||||||
|
CycleStack(CycleStack),
|
||||||
|
/// Focus the specified window index in the focused stack
|
||||||
|
#[clap(arg_required_else_help = true)]
|
||||||
|
FocusStackWindow(FocusStackWindow),
|
||||||
/// Stack all windows on the focused workspace
|
/// Stack all windows on the focused workspace
|
||||||
StackAll,
|
StackAll,
|
||||||
/// Unstack all windows in the focused container
|
/// Unstack all windows in the focused container
|
||||||
@@ -955,11 +964,6 @@ enum SubCommand {
|
|||||||
/// Resize the focused window or primary column along the specified axis
|
/// Resize the focused window or primary column along the specified axis
|
||||||
#[clap(arg_required_else_help = true)]
|
#[clap(arg_required_else_help = true)]
|
||||||
ResizeAxis(ResizeAxis),
|
ResizeAxis(ResizeAxis),
|
||||||
/// Unstack the focused window
|
|
||||||
Unstack,
|
|
||||||
/// Cycle the focused stack in the specified cycle direction
|
|
||||||
#[clap(arg_required_else_help = true)]
|
|
||||||
CycleStack(CycleStack),
|
|
||||||
/// Move the focused window to the specified monitor
|
/// Move the focused window to the specified monitor
|
||||||
#[clap(arg_required_else_help = true)]
|
#[clap(arg_required_else_help = true)]
|
||||||
MoveToMonitor(MoveToMonitor),
|
MoveToMonitor(MoveToMonitor),
|
||||||
@@ -2103,6 +2107,9 @@ Stop-Process -Name:komorebi -ErrorAction SilentlyContinue
|
|||||||
SubCommand::UnstackAll => {
|
SubCommand::UnstackAll => {
|
||||||
send_message(&SocketMessage::UnstackAll)?;
|
send_message(&SocketMessage::UnstackAll)?;
|
||||||
}
|
}
|
||||||
|
SubCommand::FocusStackWindow(arg) => {
|
||||||
|
send_message(&SocketMessage::FocusStackWindow(arg.target))?;
|
||||||
|
}
|
||||||
SubCommand::CycleStack(arg) => {
|
SubCommand::CycleStack(arg) => {
|
||||||
send_message(&SocketMessage::CycleStack(arg.cycle_direction))?;
|
send_message(&SocketMessage::CycleStack(arg.cycle_direction))?;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user