Skip to content

Commit

Permalink
fix(wm): prevent focus/move from monocle/max windows
Browse files Browse the repository at this point in the history
  • Loading branch information
LGUG2Z committed Aug 8, 2022
1 parent 7e12f6f commit 8c051d9
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 45 deletions.
150 changes: 110 additions & 40 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 22 additions & 5 deletions komorebi/src/window_manager.rs
Expand Up @@ -937,9 +937,16 @@ impl WindowManager {
pub fn focus_container_in_direction(&mut self, direction: OperationDirection) -> Result<()> {
self.handle_unmanaged_window_behaviour()?;

let workspace = self.focused_workspace()?;

if workspace.is_focused_window_monocle_or_maximized()? {
return Err(anyhow!(
"ignoring command while active window is in monocle mode or maximized"
));
}

tracing::info!("focusing container");

let workspace = self.focused_workspace()?;
let new_idx = workspace.new_idx_for_direction(direction);

// if there is no container in that direction for this workspace
Expand All @@ -966,9 +973,14 @@ impl WindowManager {
pub fn move_container_in_direction(&mut self, direction: OperationDirection) -> Result<()> {
self.handle_unmanaged_window_behaviour()?;

tracing::info!("moving container");

let workspace = self.focused_workspace()?;
if workspace.is_focused_window_monocle_or_maximized()? {
return Err(anyhow!(
"ignoring command while active window is in monocle mode or maximized"
));
}

tracing::info!("moving container");

let origin_container_idx = workspace.focused_container_idx();
let origin_monitor_idx = self.focused_monitor_idx();
Expand Down Expand Up @@ -1109,9 +1121,14 @@ impl WindowManager {
pub fn move_container_in_cycle_direction(&mut self, direction: CycleDirection) -> Result<()> {
self.handle_unmanaged_window_behaviour()?;

tracing::info!("moving container");

let workspace = self.focused_workspace_mut()?;
if workspace.is_focused_window_monocle_or_maximized()? {
return Err(anyhow!(
"ignoring command while active window is in monocle mode or maximized"
));
}

tracing::info!("moving container");

let current_idx = workspace.focused_container_idx();
let new_idx = workspace
Expand Down
17 changes: 17 additions & 0 deletions komorebi/src/workspace.rs
Expand Up @@ -362,6 +362,23 @@ impl Workspace {
false
}

pub fn is_focused_window_monocle_or_maximized(&self) -> Result<bool> {
let hwnd = WindowsApi::foreground_window()?;
if let Some(window) = self.maximized_window() {
if hwnd == window.hwnd {
return Ok(true);
}
}

if let Some(container) = self.monocle_container() {
if container.contains_window(hwnd) {
return Ok(true);
}
}

Ok(false)
}

pub fn contains_window(&self, hwnd: isize) -> bool {
for container in self.containers() {
if container.contains_window(hwnd) {
Expand Down

0 comments on commit 8c051d9

Please sign in to comment.