feat(wm): implement various focus and move cmds

This commit implements the MoveContainerToLastWorkspace,
SendContainerToLastWorkspace, MoveContainerToMonitorNumber,
CycleMoveContainerToMonitor, MoveContainerToWorkspaceNumber,
MoveContainerToNamedWorkspace, CycleMoveContainerToWorkspace,
SendContainerToMonitorNumber, CycleSendContainerToMonitor,
SendContainerToWorkspaceNumber, CycleSendContainerToWorkspace,
SendContainerToMonitorWorkspaceNumber,
MoveContainerToMonitorWorkspaceNumber, SendContainerToNamedWorkspace,
CycleMoveWorkspaceToMonitor, MoveWorkspaceToMonitorNumber, and
SwapWorkspacesToMonitorNumber SocketMessage variants.

This is primarily a lift-and-shift from komorebi.

I still have no idea if the monitor-related stuff works as expected.

I need to figure out how to construct a light Window from a window_id to
be able to call move_to_area() when moving a container to another
monitor.
This commit is contained in:
LGUG2Z committed 2025-09-19 11:37:09 -07:00
1 parent e883f4a161
commit 19686d9778
7 files changed
+795 -22

No files matched your search

+19 -4
View File
@@ -143,6 +143,25 @@ pub enum SocketMessage {
StackWindow(OperationDirection),
CycleStack(CycleDirection),
UnstackWindow,
ResizeWindowEdge(OperationDirection, Sizing),
ResizeWindowAxis(Axis, Sizing),
MoveContainerToLastWorkspace,
SendContainerToLastWorkspace,
MoveContainerToMonitorNumber(usize),
CycleMoveContainerToMonitor(CycleDirection),
MoveContainerToWorkspaceNumber(usize),
MoveContainerToNamedWorkspace(String),
CycleMoveContainerToWorkspace(CycleDirection),
SendContainerToMonitorNumber(usize),
CycleSendContainerToMonitor(CycleDirection),
SendContainerToWorkspaceNumber(usize),
CycleSendContainerToWorkspace(CycleDirection),
SendContainerToMonitorWorkspaceNumber(usize, usize),
MoveContainerToMonitorWorkspaceNumber(usize, usize),
SendContainerToNamedWorkspace(String),
CycleMoveWorkspaceToMonitor(CycleDirection),
MoveWorkspaceToMonitorNumber(usize),
SwapWorkspacesToMonitorNumber(usize),
ChangeLayout(DefaultLayout),
CycleLayout(CycleDirection),
FlipLayout(Axis),
@@ -171,10 +190,6 @@ pub enum SocketMessage {
FocusWorkspaceNumbers(usize),
FocusMonitorWorkspaceNumber(usize, usize),
FocusNamedWorkspace(String),
MoveContainerToWorkspaceNumber(usize),
SendContainerToWorkspaceNumber(usize),
ResizeWindowEdge(OperationDirection, Sizing),
ResizeWindowAxis(Axis, Sizing),
Retile,
RetileWithResizeDimensions,
Promote,
+72
View File
@@ -1,6 +1,7 @@
use crate::DEFAULT_CONTAINER_PADDING;
use crate::DEFAULT_WORKSPACE_PADDING;
use crate::container::Container;
use crate::core::FloatingLayerBehaviour;
use crate::core::default_layout::DefaultLayout;
use crate::core::layout::Layout;
use crate::core::operation_direction::OperationDirection;
@@ -12,6 +13,7 @@ use crate::workspace::WorkspaceGlobals;
use crate::workspace::WorkspaceLayer;
use color_eyre::eyre;
use color_eyre::eyre::eyre;
use std::collections::VecDeque;
use std::sync::atomic::Ordering;
impl_ring_elements!(Monitor, Workspace);
@@ -28,6 +30,7 @@ pub struct Monitor {
pub container_padding: Option<i32>,
pub workspace_padding: Option<i32>,
pub last_focused_workspace: Option<usize>,
pub floating_layer_behaviour: Option<FloatingLayerBehaviour>,
}
impl Monitor {
@@ -52,6 +55,7 @@ impl Monitor {
container_padding: None,
workspace_padding: None,
last_focused_workspace: None,
floating_layer_behaviour: None,
}
}
@@ -84,6 +88,7 @@ impl Monitor {
let work_area_offset = self.work_area_offset.or(offset);
let window_based_work_area_offset = self.window_based_work_area_offset;
let window_based_work_area_offset_limit = self.window_based_work_area_offset_limit;
let floating_layer_behaviour = self.floating_layer_behaviour;
if let Some(workspace) = self.workspaces_mut().get_mut(workspace_idx) {
workspace.globals = WorkspaceGlobals {
@@ -95,6 +100,7 @@ impl Monitor {
work_area_offset,
window_based_work_area_offset,
window_based_work_area_offset_limit,
floating_layer_behaviour,
}
}
}
@@ -334,4 +340,70 @@ impl Monitor {
Ok(())
}
pub fn update_workspaces_globals(&mut self, offset: Option<Rect>) {
let container_padding = self
.container_padding
.or(Some(DEFAULT_CONTAINER_PADDING.load(Ordering::SeqCst)));
let workspace_padding = self
.workspace_padding
.or(Some(DEFAULT_WORKSPACE_PADDING.load(Ordering::SeqCst)));
let (border_width, border_offset) = (0, 0);
let work_area = self.work_area_size;
let work_area_offset = self.work_area_offset.or(offset);
let window_based_work_area_offset = self.window_based_work_area_offset;
let window_based_work_area_offset_limit = self.window_based_work_area_offset_limit;
let floating_layer_behaviour = self.floating_layer_behaviour;
for workspace in self.workspaces_mut() {
workspace.globals = WorkspaceGlobals {
container_padding,
workspace_padding,
border_width,
border_offset,
work_area,
work_area_offset,
window_based_work_area_offset,
window_based_work_area_offset_limit,
floating_layer_behaviour,
}
}
}
pub fn remove_workspace_by_idx(&mut self, idx: usize) -> Option<Workspace> {
if idx < self.workspaces().len() {
return self.workspaces_mut().remove(idx);
}
if idx == 0 {
self.workspaces_mut().push_back(Workspace::default());
} else {
self.focus_workspace(idx.saturating_sub(1)).ok()?;
};
None
}
pub fn add_container(
&mut self,
container: Container,
workspace_idx: Option<usize>,
) -> eyre::Result<()> {
let workspace = if let Some(idx) = workspace_idx {
self.workspaces_mut()
.get_mut(idx)
.ok_or_else(|| eyre!("there is no workspace at index {}", idx))?
} else {
self.focused_workspace_mut()
.ok_or_else(|| eyre!("there is no workspace"))?
};
workspace.add_container_to_back(container);
Ok(())
}
pub fn remove_workspaces(&mut self) -> VecDeque<Workspace> {
self.workspaces_mut().drain(..).collect()
}
}
+216
View File
@@ -5,7 +5,9 @@ use crate::core::arrangement::Axis;
use crate::core::operation_direction::OperationDirection;
use crate::core::rect::Rect;
use crate::macos_api::MacosApi;
use crate::monitor::Monitor;
use crate::window_manager::WindowManager;
use crate::workspace::Workspace;
use crate::workspace::WorkspaceLayer;
use color_eyre::eyre;
use color_eyre::eyre::eyre;
@@ -589,10 +591,224 @@ impl WindowManager {
SocketMessage::ToggleTiling => {
self.toggle_tiling()?;
}
SocketMessage::MoveContainerToLastWorkspace => {
// This is to ensure that even on an empty workspace on a secondary monitor, the
// secondary monitor where the cursor is focused will be used as the target for
// the workspace switch op
if let Some(monitor_idx) = self.monitor_idx_from_current_pos()
&& monitor_idx != self.focused_monitor_idx()
&& let Some(monitor) = self.monitors().get(monitor_idx)
&& let Some(workspace) = monitor.focused_workspace()
&& workspace.is_empty()
{
self.focus_monitor(monitor_idx)?;
}
let idx = self
.focused_monitor()
.ok_or_else(|| eyre!("there is no monitor"))?
.focused_workspace_idx();
if let Some(monitor) = self.focused_monitor_mut()
&& let Some(last_focused_workspace) = monitor.last_focused_workspace
{
self.move_container_to_workspace(last_focused_workspace, true, None)?;
}
self.focused_monitor_mut()
.ok_or_else(|| eyre!("there is no monitor"))?
.last_focused_workspace = Option::from(idx);
}
SocketMessage::SendContainerToLastWorkspace => {
// This is to ensure that even on an empty workspace on a secondary monitor, the
// secondary monitor where the cursor is focused will be used as the target for
// the workspace switch op
if let Some(monitor_idx) = self.monitor_idx_from_current_pos()
&& monitor_idx != self.focused_monitor_idx()
&& let Some(monitor) = self.monitors().get(monitor_idx)
&& let Some(workspace) = monitor.focused_workspace()
&& workspace.is_empty()
{
self.focus_monitor(monitor_idx)?;
}
let idx = self
.focused_monitor()
.ok_or_else(|| eyre!("there is no monitor"))?
.focused_workspace_idx();
if let Some(monitor) = self.focused_monitor_mut()
&& let Some(last_focused_workspace) = monitor.last_focused_workspace
{
self.move_container_to_workspace(last_focused_workspace, false, None)?;
}
self.focused_monitor_mut()
.ok_or_else(|| eyre!("there is no monitor"))?
.last_focused_workspace = Option::from(idx);
}
SocketMessage::CycleMoveContainerToWorkspace(direction) => {
let focused_monitor = self
.focused_monitor()
.ok_or_else(|| eyre!("there is no monitor"))?;
let focused_workspace_idx = focused_monitor.focused_workspace_idx();
let workspaces = focused_monitor.workspaces().len();
let workspace_idx = direction.next_idx(
focused_workspace_idx,
NonZeroUsize::new(workspaces)
.ok_or_else(|| eyre!("there must be at least one workspace"))?,
);
self.move_container_to_workspace(workspace_idx, true, None)?;
}
SocketMessage::MoveContainerToMonitorNumber(monitor_idx) => {
let direction = self.direction_from_monitor_idx(monitor_idx);
self.move_container_to_monitor(monitor_idx, None, true, direction)?;
}
SocketMessage::SwapWorkspacesToMonitorNumber(monitor_idx) => {
self.swap_focused_monitor(monitor_idx)?;
}
SocketMessage::CycleMoveContainerToMonitor(direction) => {
let monitor_idx = direction.next_idx(
self.focused_monitor_idx(),
NonZeroUsize::new(self.monitors().len())
.ok_or_else(|| eyre!("there must be at least one monitor"))?,
);
let direction = self.direction_from_monitor_idx(monitor_idx);
self.move_container_to_monitor(monitor_idx, None, true, direction)?;
}
SocketMessage::CycleSendContainerToWorkspace(direction) => {
let focused_monitor = self
.focused_monitor()
.ok_or_else(|| eyre!("there is no monitor"))?;
let focused_workspace_idx = focused_monitor.focused_workspace_idx();
let workspaces = focused_monitor.workspaces().len();
let workspace_idx = direction.next_idx(
focused_workspace_idx,
NonZeroUsize::new(workspaces)
.ok_or_else(|| eyre!("there must be at least one workspace"))?,
);
self.move_container_to_workspace(workspace_idx, false, None)?;
}
SocketMessage::SendContainerToMonitorNumber(monitor_idx) => {
let direction = self.direction_from_monitor_idx(monitor_idx);
self.move_container_to_monitor(monitor_idx, None, false, direction)?;
}
SocketMessage::CycleSendContainerToMonitor(direction) => {
let monitor_idx = direction.next_idx(
self.focused_monitor_idx(),
NonZeroUsize::new(self.monitors().len())
.ok_or_else(|| eyre!("there must be at least one monitor"))?,
);
let direction = self.direction_from_monitor_idx(monitor_idx);
self.move_container_to_monitor(monitor_idx, None, false, direction)?;
}
SocketMessage::SendContainerToMonitorWorkspaceNumber(monitor_idx, workspace_idx) => {
let direction = self.direction_from_monitor_idx(monitor_idx);
self.move_container_to_monitor(
monitor_idx,
Option::from(workspace_idx),
false,
direction,
)?;
}
SocketMessage::MoveContainerToMonitorWorkspaceNumber(monitor_idx, workspace_idx) => {
let direction = self.direction_from_monitor_idx(monitor_idx);
self.move_container_to_monitor(
monitor_idx,
Option::from(workspace_idx),
true,
direction,
)?;
}
SocketMessage::SendContainerToNamedWorkspace(ref workspace) => {
if let Some((monitor_idx, workspace_idx)) =
self.monitor_workspace_index_by_name(workspace)
{
let direction = self.direction_from_monitor_idx(monitor_idx);
self.move_container_to_monitor(
monitor_idx,
Option::from(workspace_idx),
false,
direction,
)?;
}
}
SocketMessage::MoveContainerToNamedWorkspace(ref workspace) => {
if let Some((monitor_idx, workspace_idx)) =
self.monitor_workspace_index_by_name(workspace)
{
let direction = self.direction_from_monitor_idx(monitor_idx);
self.move_container_to_monitor(
monitor_idx,
Option::from(workspace_idx),
true,
direction,
)?;
}
}
SocketMessage::MoveWorkspaceToMonitorNumber(monitor_idx) => {
self.move_workspace_to_monitor(monitor_idx)?;
}
SocketMessage::CycleMoveWorkspaceToMonitor(direction) => {
let monitor_idx = direction.next_idx(
self.focused_monitor_idx(),
NonZeroUsize::new(self.monitors().len())
.ok_or_else(|| eyre!("there must be at least one monitor"))?,
);
self.move_workspace_to_monitor(monitor_idx)?;
}
}
Ok(())
}
#[tracing::instrument(skip(self))]
pub fn move_workspace_to_monitor(&mut self, idx: usize) -> eyre::Result<()> {
tracing::info!("moving workspace");
let mouse_follows_focus = self.mouse_follows_focus;
let offset = self.work_area_offset;
let workspace = self
.remove_focused_workspace()
.ok_or_else(|| eyre!("there is no workspace"))?;
{
let target_monitor: &mut Monitor = self
.monitors_mut()
.get_mut(idx)
.ok_or_else(|| eyre!("there is no monitor"))?;
target_monitor.workspaces_mut().push_back(workspace);
target_monitor.update_workspaces_globals(offset);
target_monitor.focus_workspace(target_monitor.workspaces().len().saturating_sub(1))?;
target_monitor.load_focused_workspace(mouse_follows_focus)?;
}
self.focus_monitor(idx)?;
self.update_focused_workspace(mouse_follows_focus, true)
}
pub fn remove_focused_workspace(&mut self) -> Option<Workspace> {
let focused_monitor: &mut Monitor = self.focused_monitor_mut()?;
let focused_workspace_idx = focused_monitor.focused_workspace_idx();
let workspace = focused_monitor.remove_workspace_by_idx(focused_workspace_idx);
if let Err(error) = focused_monitor.focus_workspace(focused_workspace_idx.saturating_sub(1))
{
tracing::error!(
"Error focusing previous workspace while removing the focused workspace: {}",
error
);
}
workspace
}
}
pub fn read_commands_uds(
+72
View File
@@ -355,6 +355,78 @@ impl Window {
bottom: target_height,
})
}
pub fn move_to_area(
&self,
current_area: &Rect,
target_area: &Rect,
) -> Result<(), AccessibilityError> {
let current_rect = Rect::from(MacosApi::window_rect(&self.element)?);
let x_diff = target_area.left - current_area.left;
let y_diff = target_area.top - current_area.top;
let x_ratio = f32::abs((target_area.right as f32) / (current_area.right as f32));
let y_ratio = f32::abs((target_area.bottom as f32) / (current_area.bottom as f32));
let window_relative_x = current_rect.left - current_area.left;
let window_relative_y = current_rect.top - current_area.top;
let corrected_relative_x = (window_relative_x as f32 * x_ratio) as i32;
let corrected_relative_y = (window_relative_y as f32 * y_ratio) as i32;
let window_x = current_area.left + corrected_relative_x;
let window_y = current_area.top + corrected_relative_y;
let left = x_diff + window_x;
let top = y_diff + window_y;
let corrected_width = (current_rect.right as f32 * x_ratio) as i32;
let corrected_height = (current_rect.bottom as f32 * y_ratio) as i32;
let new_rect = Rect {
left,
top,
right: corrected_width,
bottom: corrected_height,
};
// TODO: figure out what to do about maximized windows on macOS
// let is_maximized = &new_rect == target_area;
// if is_maximized {
// windows_api::WindowsApi::unmaximize_window(self.hwnd);
// let animation_enabled = ANIMATION_ENABLED_PER_ANIMATION.lock();
// let move_enabled = animation_enabled
// .get(&MovementRenderDispatcher::PREFIX)
// .is_some_and(|v| *v);
// drop(animation_enabled);
//
// if move_enabled || ANIMATION_ENABLED_GLOBAL.load(Ordering::SeqCst) {
// let anim_count = ANIMATION_MANAGER
// .lock()
// .count_in_progress(MovementRenderDispatcher::PREFIX);
// self.set_position(&new_rect, true)?;
// let hwnd = self.hwnd;
// // Wait for the animation to finish before maximizing the window again, otherwise
// // we would be maximizing the window on the current monitor anyway
// thread::spawn(move || {
// let mut new_anim_count = ANIMATION_MANAGER
// .lock()
// .count_in_progress(MovementRenderDispatcher::PREFIX);
// let mut max_wait = 2000; // Max waiting time. No one will be using an animation longer than 2s, right? RIGHT??? WHY?
// while new_anim_count > anim_count && max_wait > 0 {
// thread::sleep(Duration::from_millis(10));
// new_anim_count = ANIMATION_MANAGER
// .lock()
// .count_in_progress(MovementRenderDispatcher::PREFIX);
// max_wait -= 1;
// }
// windows_api::WindowsApi::maximize_window(hwnd);
// });
// } else {
// self.set_position(&new_rect, true)?;
// windows_api::WindowsApi::maximize_window(self.hwnd);
// }
// } else {
self.set_position(&new_rect)?;
// }
Ok(())
}
}
impl From<&CFDictionary> for WindowInfo {
+256
View File
@@ -1344,4 +1344,260 @@ impl WindowManager {
None
}
/// Calculates the direction of a move across monitors given a specific monitor index
pub fn direction_from_monitor_idx(
&self,
target_monitor_idx: usize,
) -> Option<OperationDirection> {
let current_monitor_idx = self.focused_monitor_idx();
if current_monitor_idx == target_monitor_idx {
return None;
}
let current_monitor_size = self.focused_monitor_size().ok()?;
let target_monitor_size = self.monitors().get(target_monitor_idx)?.size;
if target_monitor_size.left + target_monitor_size.right == current_monitor_size.left {
return Some(OperationDirection::Left);
}
if current_monitor_size.right + current_monitor_size.left == target_monitor_size.left {
return Some(OperationDirection::Right);
}
if target_monitor_size.top + target_monitor_size.bottom == current_monitor_size.top {
return Some(OperationDirection::Up);
}
if current_monitor_size.top + current_monitor_size.bottom == target_monitor_size.top {
return Some(OperationDirection::Down);
}
None
}
#[tracing::instrument(skip(self))]
pub fn move_container_to_monitor(
&mut self,
monitor_idx: usize,
workspace_idx: Option<usize>,
follow: bool,
move_direction: Option<OperationDirection>,
) -> eyre::Result<()> {
tracing::info!("moving container");
let focused_monitor_idx = self.focused_monitor_idx();
if focused_monitor_idx == monitor_idx
&& let Some(workspace_idx) = workspace_idx
{
return self.move_container_to_workspace(workspace_idx, follow, None);
}
let offset = self.work_area_offset;
let mouse_follows_focus = self.mouse_follows_focus;
let monitor = self
.focused_monitor_mut()
.ok_or_else(|| eyre!("there is no monitor"))?;
let current_area = monitor.work_area_size;
let workspace = monitor
.focused_workspace_mut()
.ok_or_else(|| eyre!("there is no workspace"))?;
if workspace.maximized_window.is_some() {
return Err(eyre!(
"cannot move native maximized window to another monitor or workspace"
));
}
let foreground_window_id =
MacosApi::foreground_window_id().ok_or(eyre!("no foreground window"))?;
let floating_window_index = workspace
.floating_windows()
.iter()
.position(|w| w.id == foreground_window_id);
let floating_window =
floating_window_index.and_then(|idx| workspace.floating_windows_mut().remove(idx));
let container = if floating_window_index.is_none() {
Some(
workspace
.remove_focused_container()
.ok_or_else(|| eyre!("there is no container"))?,
)
} else {
None
};
monitor.update_focused_workspace(offset)?;
let target_monitor = self
.monitors_mut()
.get_mut(monitor_idx)
.ok_or_else(|| eyre!("there is no monitor"))?;
let target_monitor_work_area_size = target_monitor.work_area_size;
let mut should_load_workspace = false;
if let Some(workspace_idx) = workspace_idx
&& workspace_idx != target_monitor.focused_workspace_idx()
{
target_monitor.focus_workspace(workspace_idx)?;
should_load_workspace = true;
}
let target_workspace = target_monitor
.focused_workspace_mut()
.ok_or_else(|| eyre!("there is no focused workspace on target monitor"))?;
if target_workspace.monocle_container.is_some() {
for container in target_workspace.containers_mut() {
container.restore()?;
}
for window in target_workspace.floating_windows_mut() {
window.restore()?;
}
target_workspace.reintegrate_monocle_container()?;
}
if let Some(window) = floating_window {
window.move_to_area(&current_area, &target_monitor_work_area_size)?;
target_workspace.floating_windows_mut().push_back(window);
target_workspace.layer = WorkspaceLayer::Floating;
} else if let Some(container) = container {
let _container_window_ids =
container.windows().iter().map(|w| w.id).collect::<Vec<_>>();
target_workspace.layer = WorkspaceLayer::Tiling;
if let Some(direction) = move_direction {
target_monitor.add_container_with_direction(container, workspace_idx, direction)?;
} else {
target_monitor.add_container(container, workspace_idx)?;
}
if let Some(workspace) = target_monitor.focused_workspace()
&& !workspace.tile
{
// TODO: figure out how to construct a Window from just an id here
// for window_id in container_window_ids {
// Window::from(window_id)
// .move_to_area(&current_area, &target_monitor.work_area_size)?;
// }
}
} else {
return Err(eyre!("failed to find a window to move"));
}
if should_load_workspace {
target_monitor.load_focused_workspace(mouse_follows_focus)?;
}
target_monitor.update_focused_workspace(offset)?;
// this second one is for DPI changes when the target is another monitor
// if we don't do this the layout on the other monitor could look funny
// until it is interacted with again
target_monitor.update_focused_workspace(offset)?;
if follow {
self.focus_monitor(monitor_idx)?;
}
self.update_focused_workspace(self.mouse_follows_focus, true)?;
Ok(())
}
#[tracing::instrument(skip(self))]
pub fn swap_focused_monitor(&mut self, idx: usize) -> eyre::Result<()> {
tracing::info!("swapping focused monitor");
let focused_monitor_idx = self.focused_monitor_idx();
let mouse_follows_focus = self.mouse_follows_focus;
self.swap_monitor_workspaces(focused_monitor_idx, idx)?;
self.update_focused_workspace(mouse_follows_focus, true)
}
#[tracing::instrument(skip(self))]
pub fn swap_monitor_workspaces(
&mut self,
first_idx: usize,
second_idx: usize,
) -> eyre::Result<()> {
tracing::info!("swaping monitors");
if first_idx == second_idx {
return Ok(());
}
let mouse_follows_focus = self.mouse_follows_focus;
let offset = self.work_area_offset;
let first_focused_workspace = {
let first_monitor = self
.monitors()
.get(first_idx)
.ok_or_else(|| eyre!("There is no monitor"))?;
first_monitor.focused_workspace_idx()
};
let second_focused_workspace = {
let second_monitor = self
.monitors()
.get(second_idx)
.ok_or_else(|| eyre!("There is no monitor"))?;
second_monitor.focused_workspace_idx()
};
// Swap workspaces between the first and second monitors
let first_workspaces = self
.monitors_mut()
.get_mut(first_idx)
.ok_or_else(|| eyre!("There is no monitor"))?
.remove_workspaces();
let second_workspaces = self
.monitors_mut()
.get_mut(second_idx)
.ok_or_else(|| eyre!("There is no monitor"))?
.remove_workspaces();
self.monitors_mut()
.get_mut(first_idx)
.ok_or_else(|| eyre!("There is no monitor"))?
.workspaces_mut()
.extend(second_workspaces);
self.monitors_mut()
.get_mut(second_idx)
.ok_or_else(|| eyre!("There is no monitor"))?
.workspaces_mut()
.extend(first_workspaces);
// Set the focused workspaces for the first and second monitors
if let Some(first_monitor) = self.monitors_mut().get_mut(first_idx) {
first_monitor.update_workspaces_globals(offset);
first_monitor.focus_workspace(second_focused_workspace)?;
first_monitor.load_focused_workspace(mouse_follows_focus)?;
}
if let Some(second_monitor) = self.monitors_mut().get_mut(second_idx) {
second_monitor.update_workspaces_globals(offset);
second_monitor.focus_workspace(first_focused_workspace)?;
second_monitor.load_focused_workspace(mouse_follows_focus)?;
}
self.update_focused_workspace_by_monitor_idx(second_idx)?;
self.update_focused_workspace_by_monitor_idx(first_idx)
}
pub fn update_focused_workspace_by_monitor_idx(&mut self, idx: usize) -> eyre::Result<()> {
let offset = self.work_area_offset;
self.monitors_mut()
.get_mut(idx)
.ok_or_else(|| eyre!("there is no monitor"))?
.update_focused_workspace(offset)
}
}
+1
View File
@@ -108,6 +108,7 @@ pub struct WorkspaceGlobals {
pub work_area_offset: Option<Rect>,
pub window_based_work_area_offset: Option<Rect>,
pub window_based_work_area_offset_limit: isize,
pub floating_layer_behaviour: Option<FloatingLayerBehaviour>,
}
impl Workspace {
+159 -18
View File
@@ -56,15 +56,29 @@ macro_rules! gen_enum_subcommand_args {
gen_enum_subcommand_args! {
Focus: OperationDirection,
Move: OperationDirection,
FlipLayout: Axis,
ChangeLayout: DefaultLayout,
CycleLayout: CycleDirection,
Stack: OperationDirection,
CycleStack: CycleDirection,
PromoteWindow: OperationDirection,
CycleFocus: CycleDirection,
CycleMove: CycleDirection,
CycleMoveToWorkspace: CycleDirection,
CycleSendToWorkspace: CycleDirection,
CycleSendToMonitor: CycleDirection,
CycleMoveToMonitor: CycleDirection,
CycleMonitor: CycleDirection,
CycleWorkspace: CycleDirection,
CycleEmptyWorkspace: CycleDirection,
CycleMoveWorkspaceToMonitor: CycleDirection,
Stack: OperationDirection,
CycleStack: CycleDirection,
CycleStackIndex: CycleDirection,
FlipLayout: Axis,
ChangeLayout: DefaultLayout,
CycleLayout: CycleDirection,
// WatchConfiguration: BooleanState,
// MouseFollowsFocus: BooleanState,
// Query: StateQuery,
// WindowHidingBehaviour: HidingBehaviour,
// CrossMonitorMoveBehaviour: MoveBehaviour,
// UnmanagedWindowOperationBehaviour: OperationBehaviour,
PromoteWindow: OperationDirection,
}
macro_rules! gen_target_subcommand_args {
@@ -88,6 +102,9 @@ gen_target_subcommand_args! {
FocusMonitor,
FocusWorkspace,
FocusWorkspaces,
MoveWorkspaceToMonitor,
SwapWorkspacesWithMonitor,
FocusStackWindow,
}
macro_rules! gen_named_target_subcommand_args {
@@ -104,7 +121,10 @@ macro_rules! gen_named_target_subcommand_args {
}
gen_named_target_subcommand_args! {
MoveToNamedWorkspace,
SendToNamedWorkspace,
FocusNamedWorkspace,
ClearNamedWorkspaceLayoutRules
}
#[derive(Parser)]
@@ -131,6 +151,22 @@ struct FocusMonitorWorkspace {
target_workspace: usize,
}
#[derive(Parser)]
pub struct SendToMonitorWorkspace {
/// Target monitor index (zero-indexed)
target_monitor: usize,
/// Workspace index on the target monitor (zero-indexed)
target_workspace: usize,
}
#[derive(Parser)]
pub struct MoveToMonitorWorkspace {
/// Target monitor index (zero-indexed)
target_monitor: usize,
/// Workspace index on the target monitor (zero-indexed)
target_workspace: usize,
}
#[derive(Parser)]
#[clap(author, about, version)]
struct Opts {
@@ -184,6 +220,56 @@ enum SubCommand {
PromoteFocus,
/// Promote the window in the specified direction
PromoteWindow(PromoteWindow),
/// Move the focused window to the specified monitor
#[clap(arg_required_else_help = true)]
MoveToMonitor(MoveToMonitor),
/// Move the focused window to the monitor in the given cycle direction
#[clap(arg_required_else_help = true)]
CycleMoveToMonitor(CycleMoveToMonitor),
/// Move the focused window to the specified workspace
#[clap(arg_required_else_help = true)]
MoveToWorkspace(MoveToWorkspace),
/// Move the focused window to the specified workspace
#[clap(arg_required_else_help = true)]
MoveToNamedWorkspace(MoveToNamedWorkspace),
/// Move the focused window to the workspace in the given cycle direction
#[clap(arg_required_else_help = true)]
CycleMoveToWorkspace(CycleMoveToWorkspace),
/// Send the focused window to the specified monitor
#[clap(arg_required_else_help = true)]
SendToMonitor(SendToMonitor),
/// Send the focused window to the monitor in the given cycle direction
#[clap(arg_required_else_help = true)]
CycleSendToMonitor(CycleSendToMonitor),
/// Send the focused window to the specified workspace
#[clap(arg_required_else_help = true)]
SendToWorkspace(SendToWorkspace),
/// Send the focused window to the specified workspace
#[clap(arg_required_else_help = true)]
SendToNamedWorkspace(SendToNamedWorkspace),
/// Send the focused window to the workspace in the given cycle direction
#[clap(arg_required_else_help = true)]
CycleSendToWorkspace(CycleSendToWorkspace),
/// Send the focused window to the specified monitor workspace
#[clap(arg_required_else_help = true)]
SendToMonitorWorkspace(SendToMonitorWorkspace),
/// Move the focused window to the specified monitor workspace
#[clap(arg_required_else_help = true)]
MoveToMonitorWorkspace(MoveToMonitorWorkspace),
/// Send the focused window to the last focused monitor workspace
SendToLastWorkspace,
/// Move the focused window to the last focused monitor workspace
MoveToLastWorkspace,
/// Move the focused workspace to the specified monitor
#[clap(arg_required_else_help = true)]
MoveWorkspaceToMonitor(MoveWorkspaceToMonitor),
/// Move the focused workspace monitor in the given cycle direction
#[clap(arg_required_else_help = true)]
CycleMoveWorkspaceToMonitor(CycleMoveWorkspaceToMonitor),
/// Swap focused monitor workspaces with specified monitor
#[clap(arg_required_else_help = true)]
SwapWorkspacesWithMonitor(SwapWorkspacesWithMonitor),
/// Focus the specified monitor
#[clap(arg_required_else_help = true)]
FocusMonitor(FocusMonitor),
@@ -214,12 +300,6 @@ enum SubCommand {
/// Focus the next empty workspace in the given cycle direction (if one exists)
#[clap(arg_required_else_help = true)]
CycleEmptyWorkspace(CycleEmptyWorkspace),
/// Move the focused window to the specified workspace
#[clap(arg_required_else_help = true)]
MoveToWorkspace(MoveToWorkspace),
/// Send the focused window to the specified workspace
#[clap(arg_required_else_help = true)]
SendToWorkspace(SendToWorkspace),
/// Force the retiling of all managed windows
Retile,
/// Toggle application of the window-based work area offset for the focused workspace
@@ -278,12 +358,6 @@ fn main() -> eyre::Result<()> {
SubCommand::FocusWorkspace(arg) => {
send_message(&SocketMessage::FocusWorkspaceNumber(arg.target))?;
}
SubCommand::MoveToWorkspace(arg) => {
send_message(&SocketMessage::MoveContainerToWorkspaceNumber(arg.target))?;
}
SubCommand::SendToWorkspace(arg) => {
send_message(&SocketMessage::SendContainerToWorkspaceNumber(arg.target))?;
}
SubCommand::ToggleMonocle => {
send_message(&SocketMessage::ToggleMonocle)?;
}
@@ -370,6 +444,73 @@ fn main() -> eyre::Result<()> {
arg.cycle_direction,
))?;
}
SubCommand::MoveToMonitor(arg) => {
send_message(&SocketMessage::MoveContainerToMonitorNumber(arg.target))?;
}
SubCommand::CycleMoveToMonitor(arg) => {
send_message(&SocketMessage::CycleMoveContainerToMonitor(
arg.cycle_direction,
))?;
}
SubCommand::MoveToWorkspace(arg) => {
send_message(&SocketMessage::MoveContainerToWorkspaceNumber(arg.target))?;
}
SubCommand::MoveToNamedWorkspace(arg) => {
send_message(&SocketMessage::MoveContainerToNamedWorkspace(arg.workspace))?;
}
SubCommand::CycleMoveToWorkspace(arg) => {
send_message(&SocketMessage::CycleMoveContainerToWorkspace(
arg.cycle_direction,
))?;
}
SubCommand::SendToMonitor(arg) => {
send_message(&SocketMessage::SendContainerToMonitorNumber(arg.target))?;
}
SubCommand::CycleSendToMonitor(arg) => {
send_message(&SocketMessage::CycleSendContainerToMonitor(
arg.cycle_direction,
))?;
}
SubCommand::SendToWorkspace(arg) => {
send_message(&SocketMessage::SendContainerToWorkspaceNumber(arg.target))?;
}
SubCommand::SendToNamedWorkspace(arg) => {
send_message(&SocketMessage::SendContainerToNamedWorkspace(arg.workspace))?;
}
SubCommand::CycleSendToWorkspace(arg) => {
send_message(&SocketMessage::CycleSendContainerToWorkspace(
arg.cycle_direction,
))?;
}
SubCommand::SendToMonitorWorkspace(arg) => {
send_message(&SocketMessage::SendContainerToMonitorWorkspaceNumber(
arg.target_monitor,
arg.target_workspace,
))?;
}
SubCommand::MoveToMonitorWorkspace(arg) => {
send_message(&SocketMessage::MoveContainerToMonitorWorkspaceNumber(
arg.target_monitor,
arg.target_workspace,
))?;
}
SubCommand::MoveWorkspaceToMonitor(arg) => {
send_message(&SocketMessage::MoveWorkspaceToMonitorNumber(arg.target))?;
}
SubCommand::CycleMoveWorkspaceToMonitor(arg) => {
send_message(&SocketMessage::CycleMoveWorkspaceToMonitor(
arg.cycle_direction,
))?;
}
SubCommand::MoveToLastWorkspace => {
send_message(&SocketMessage::MoveContainerToLastWorkspace)?;
}
SubCommand::SendToLastWorkspace => {
send_message(&SocketMessage::SendContainerToLastWorkspace)?;
}
SubCommand::SwapWorkspacesWithMonitor(arg) => {
send_message(&SocketMessage::SwapWorkspacesToMonitorNumber(arg.target))?;
}
}
Ok(())