Skip to content

Commit

Permalink
fix(wm): update state for any new float rules
Browse files Browse the repository at this point in the history
This update ensures that whenever a new float rule is added, the focused
workspaces on all monitors will be checked to see if there are any
currently managed windows which match that rule. If so, the matching
window(s) will be removed from the workspace and the workspace will be
updated.

Matching windows on non-focused workspaces will not be removed, as these
windows may be hidden, and removing them could result in these windows
being inaccessible, requiring them to be killed before they can be
relaunched

fix #93
  • Loading branch information
LGUG2Z committed Jan 17, 2022
1 parent 5f1356b commit 87e8eb4
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 20 deletions.
24 changes: 12 additions & 12 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repository.
Articles, blog posts, demos, and videos about _komorebi_ can be added to this list by PR:

- [Moving to Windows from Linux Pt 1](https://kvwu.io/posts/moving-to-windows/)
- [Windows下的现代化平铺窗口管理器 komorebi](https://zhuanlan.zhihu.com/p/455064481)
- [Windows 下的现代化平铺窗口管理器 komorebi](https://zhuanlan.zhihu.com/p/455064481)

## Description

Expand Down
52 changes: 50 additions & 2 deletions komorebi/src/process_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use miow::pipe::connect;
use parking_lot::Mutex;
use uds_windows::UnixStream;

use komorebi_core::ApplicationIdentifier;
use komorebi_core::Axis;
use komorebi_core::FocusFollowsMouseImplementation;
use komorebi_core::Layout;
Expand Down Expand Up @@ -123,10 +124,57 @@ impl WindowManager {
manage_identifiers.push(id);
}
}
SocketMessage::FloatRule(_, id) => {
SocketMessage::FloatRule(identifier, id) => {
let mut float_identifiers = FLOAT_IDENTIFIERS.lock();
if !float_identifiers.contains(&id) {
float_identifiers.push(id);
float_identifiers.push(id.clone());
}

let invisible_borders = self.invisible_borders;
let offset = self.work_area_offset;

let mut hwnds_to_purge = vec![];
for (i, monitor) in self.monitors().iter().enumerate() {
for container in monitor
.focused_workspace()
.ok_or_else(|| anyhow!("there is no workspace"))?
.containers()
.iter()
{
for window in container.windows().iter() {
match identifier {
ApplicationIdentifier::Exe => {
if window.exe()? == id {
hwnds_to_purge.push((i, window.hwnd));
}
}
ApplicationIdentifier::Class => {
if window.class()? == id {
hwnds_to_purge.push((i, window.hwnd));
}
}
ApplicationIdentifier::Title => {
if window.title()? == id {
hwnds_to_purge.push((i, window.hwnd));
}
}
}
}
}
}

for (monitor_idx, hwnd) in hwnds_to_purge {
let monitor = self
.monitors_mut()
.get_mut(monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor"))?;

monitor
.focused_workspace_mut()
.ok_or_else(|| anyhow!("there is no focused workspace"))?
.remove_window(hwnd)?;

monitor.update_focused_workspace(offset, &invisible_borders)?;
}
}
SocketMessage::AdjustContainerPadding(sizing, adjustment) => {
Expand Down
12 changes: 7 additions & 5 deletions komorebi/src/windows_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,11 @@ impl WindowsApi {
let mut path: Vec<u16> = vec![0; len as usize];
let text_ptr = path.as_mut_ptr();

unsafe { QueryFullProcessImageNameW(handle, 0, PWSTR(text_ptr), &mut len as *mut u32) }
.ok()
.process()?;
unsafe {
QueryFullProcessImageNameW(handle, 0, PWSTR(text_ptr), std::ptr::addr_of_mut!(len))
}
.ok()
.process()?;

Ok(String::from_utf16(&path[..len as usize])?)
}
Expand Down Expand Up @@ -543,7 +545,7 @@ impl WindowsApi {
let mut monitor_info: MONITORINFO = unsafe { std::mem::zeroed() };
monitor_info.cbSize = u32::try_from(std::mem::size_of::<MONITORINFO>())?;

unsafe { GetMonitorInfoW(hmonitor, (&mut monitor_info as *mut MONITORINFO).cast()) }
unsafe { GetMonitorInfoW(hmonitor, std::ptr::addr_of_mut!(monitor_info).cast()) }
.ok()
.process()?;

Expand Down Expand Up @@ -579,7 +581,7 @@ impl WindowsApi {
Self::system_parameters_info_w(
SPI_GETACTIVEWINDOWTRACKING,
0,
(&mut is_enabled as *mut BOOL).cast(),
std::ptr::addr_of_mut!(is_enabled).cast(),
SPIF_SENDCHANGE,
)?;

Expand Down

0 comments on commit 87e8eb4

Please sign in to comment.