feat(wm): add send-to-monitor-workspace cmd

This commit adds a dedicated command to send a window container to a
specific workspace on a target monitor.
This commit is contained in:
LGUG2Z
2022-01-28 08:23:05 -08:00
parent 4a3f7ee34e
commit 02c54734fb
7 changed files with 53 additions and 10 deletions
+1
View File
@@ -339,6 +339,7 @@ move-to-monitor Move the focused window to the specified mo
move-to-workspace Move the focused window to the specified workspace move-to-workspace Move the focused window to the specified workspace
send-to-monitor Send the focused window to the specified monitor send-to-monitor Send the focused window to the specified monitor
send-to-workspace Send the focused window to the specified workspace send-to-workspace Send the focused window to the specified workspace
send-to-monitor-workspace Send the focused window to the specified monitor workspace
focus-monitor Focus the specified monitor focus-monitor Focus the specified monitor
focus-workspace Focus the specified workspace on the focused monitor focus-workspace Focus the specified workspace on the focused monitor
focus-monitor-workspace Focus the specified workspace on the target monitor focus-monitor-workspace Focus the specified workspace on the target monitor
+1
View File
@@ -48,6 +48,7 @@ pub enum SocketMessage {
MoveContainerToWorkspaceNumber(usize), MoveContainerToWorkspaceNumber(usize),
SendContainerToMonitorNumber(usize), SendContainerToMonitorNumber(usize),
SendContainerToWorkspaceNumber(usize), SendContainerToWorkspaceNumber(usize),
SendContainerToMonitorWorkspaceNumber(usize, usize),
MoveWorkspaceToMonitorNumber(usize), MoveWorkspaceToMonitorNumber(usize),
Promote, Promote,
ToggleFloat, ToggleFloat,
+13 -4
View File
@@ -59,10 +59,19 @@ impl Monitor {
Ok(()) Ok(())
} }
pub fn add_container(&mut self, container: Container) -> Result<()> { pub fn add_container(
let workspace = self &mut self,
.focused_workspace_mut() container: Container,
.ok_or_else(|| anyhow!("there is no workspace"))?; workspace_idx: Option<usize>,
) -> Result<()> {
let workspace = if let Some(idx) = workspace_idx {
self.workspaces_mut()
.get_mut(idx)
.ok_or_else(|| anyhow!("there is no workspace at index {}", idx))?
} else {
self.focused_workspace_mut()
.ok_or_else(|| anyhow!("there is no workspace"))?
};
workspace.add_container(container); workspace.add_container(container);
+5 -2
View File
@@ -189,13 +189,16 @@ impl WindowManager {
self.move_container_to_workspace(workspace_idx, true)?; self.move_container_to_workspace(workspace_idx, true)?;
} }
SocketMessage::MoveContainerToMonitorNumber(monitor_idx) => { SocketMessage::MoveContainerToMonitorNumber(monitor_idx) => {
self.move_container_to_monitor(monitor_idx, true)?; self.move_container_to_monitor(monitor_idx, None, true)?;
} }
SocketMessage::SendContainerToWorkspaceNumber(workspace_idx) => { SocketMessage::SendContainerToWorkspaceNumber(workspace_idx) => {
self.move_container_to_workspace(workspace_idx, false)?; self.move_container_to_workspace(workspace_idx, false)?;
} }
SocketMessage::SendContainerToMonitorNumber(monitor_idx) => { SocketMessage::SendContainerToMonitorNumber(monitor_idx) => {
self.move_container_to_monitor(monitor_idx, false)?; self.move_container_to_monitor(monitor_idx, None, false)?;
}
SocketMessage::SendContainerToMonitorWorkspaceNumber(monitor_idx, workspace_idx) => {
self.move_container_to_monitor(monitor_idx, Option::from(workspace_idx), false)?;
} }
SocketMessage::MoveWorkspaceToMonitorNumber(monitor_idx) => { SocketMessage::MoveWorkspaceToMonitorNumber(monitor_idx) => {
self.move_workspace_to_monitor(monitor_idx)?; self.move_workspace_to_monitor(monitor_idx)?;
+9 -4
View File
@@ -776,7 +776,12 @@ impl WindowManager {
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn move_container_to_monitor(&mut self, idx: usize, follow: bool) -> Result<()> { pub fn move_container_to_monitor(
&mut self,
monitor_idx: usize,
workspace_idx: Option<usize>,
follow: bool,
) -> Result<()> {
tracing::info!("moving container"); tracing::info!("moving container");
let invisible_borders = self.invisible_borders; let invisible_borders = self.invisible_borders;
@@ -802,15 +807,15 @@ impl WindowManager {
let target_monitor = self let target_monitor = self
.monitors_mut() .monitors_mut()
.get_mut(idx) .get_mut(monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor"))?; .ok_or_else(|| anyhow!("there is no monitor"))?;
target_monitor.add_container(container)?; target_monitor.add_container(container, workspace_idx)?;
target_monitor.load_focused_workspace(mouse_follows_focus)?; target_monitor.load_focused_workspace(mouse_follows_focus)?;
target_monitor.update_focused_workspace(offset, &invisible_borders)?; target_monitor.update_focused_workspace(offset, &invisible_borders)?;
if follow { if follow {
self.focus_monitor(idx)?; self.focus_monitor(monitor_idx)?;
} }
self.update_focused_workspace(self.mouse_follows_focus) self.update_focused_workspace(self.mouse_follows_focus)
+4
View File
@@ -96,6 +96,10 @@ SendToWorkspace(target) {
Run, komorebic.exe send-to-workspace %target%, , Hide Run, komorebic.exe send-to-workspace %target%, , Hide
} }
SendToMonitorWorkspace(target_monitor, target_workspace) {
Run, komorebic.exe send-to-monitor-workspace %target_monitor% %target_workspace%, , Hide
}
FocusMonitor(target) { FocusMonitor(target) {
Run, komorebic.exe focus-monitor %target%, , Hide Run, komorebic.exe focus-monitor %target%, , Hide
} }
+20
View File
@@ -245,6 +245,14 @@ struct FocusMonitorWorkspace {
target_workspace: usize, target_workspace: usize,
} }
#[derive(Parser, AhkFunction)]
pub struct SendToMonitorWorkspace {
/// Target monitor index (zero-indexed)
target_monitor: usize,
/// Workspace index on the target monitor (zero-indexed)
target_workspace: usize,
}
macro_rules! gen_padding_subcommand_args { macro_rules! gen_padding_subcommand_args {
// SubCommand Pattern // SubCommand Pattern
( $( $name:ident ),+ $(,)? ) => { ( $( $name:ident ),+ $(,)? ) => {
@@ -451,6 +459,9 @@ enum SubCommand {
/// Send the focused window to the specified workspace /// Send the focused window to the specified workspace
#[clap(setting = AppSettings::ArgRequiredElseHelp)] #[clap(setting = AppSettings::ArgRequiredElseHelp)]
SendToWorkspace(SendToWorkspace), SendToWorkspace(SendToWorkspace),
/// Send the focused window to the specified monitor workspace
#[clap(setting = AppSettings::ArgRequiredElseHelp)]
SendToMonitorWorkspace(SendToMonitorWorkspace),
/// Focus the specified monitor /// Focus the specified monitor
#[clap(setting = AppSettings::ArgRequiredElseHelp)] #[clap(setting = AppSettings::ArgRequiredElseHelp)]
FocusMonitor(FocusMonitor), FocusMonitor(FocusMonitor),
@@ -658,6 +669,15 @@ fn main() -> Result<()> {
SubCommand::SendToWorkspace(arg) => { SubCommand::SendToWorkspace(arg) => {
send_message(&*SocketMessage::SendContainerToWorkspaceNumber(arg.target).as_bytes()?)?; send_message(&*SocketMessage::SendContainerToWorkspaceNumber(arg.target).as_bytes()?)?;
} }
SubCommand::SendToMonitorWorkspace(arg) => {
send_message(
&*SocketMessage::SendContainerToMonitorWorkspaceNumber(
arg.target_monitor,
arg.target_workspace,
)
.as_bytes()?,
)?;
}
SubCommand::MoveWorkspaceToMonitor(arg) => { SubCommand::MoveWorkspaceToMonitor(arg) => {
send_message(&*SocketMessage::MoveWorkspaceToMonitorNumber(arg.target).as_bytes()?)?; send_message(&*SocketMessage::MoveWorkspaceToMonitorNumber(arg.target).as_bytes()?)?;
} }