Skip to content

Commit 9da424e

Browse files
committed
feat(wm): toggle layer moves all windows
This commit makes it so when you toggle between workspace layers it moves all windows of that layer to the top. So if you move to `Floating` layer, then all floating windows are moved to the top, if you go back to `Tiling` layer all containers are moved to the top.
1 parent b0963c3 commit 9da424e

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

komorebi/src/process_command.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -1049,24 +1049,37 @@ impl WindowManager {
10491049
let mouse_follows_focus = self.mouse_follows_focus;
10501050
let workspace = self.focused_workspace_mut()?;
10511051

1052+
let mut to_focus = None;
10521053
match workspace.layer() {
10531054
WorkspaceLayer::Tiling => {
10541055
workspace.set_layer(WorkspaceLayer::Floating);
10551056

1056-
if let Some(first) = workspace.floating_windows().first() {
1057-
first.focus(mouse_follows_focus)?;
1057+
for (i, window) in workspace.floating_windows().iter().enumerate() {
1058+
if i == 0 {
1059+
to_focus = Some(*window);
1060+
}
1061+
// WindowsApi::raise_window(window.hwnd)?;
1062+
WindowsApi::raise_and_focus_window(window.hwnd)?;
10581063
}
10591064
}
10601065
WorkspaceLayer::Floating => {
10611066
workspace.set_layer(WorkspaceLayer::Tiling);
10621067

1063-
if let Some(container) = workspace.focused_container() {
1068+
let focused_container_idx = workspace.focused_container_idx();
1069+
for (i, container) in workspace.containers_mut().iter_mut().enumerate() {
10641070
if let Some(window) = container.focused_window() {
1065-
window.focus(mouse_follows_focus)?;
1071+
if i == focused_container_idx {
1072+
to_focus = Some(*window);
1073+
}
1074+
// WindowsApi::raise_window(window.hwnd)?;
1075+
WindowsApi::raise_and_focus_window(window.hwnd)?;
10661076
}
10671077
}
10681078
}
10691079
};
1080+
if let Some(window) = to_focus {
1081+
window.focus(mouse_follows_focus)?;
1082+
}
10701083
}
10711084
SocketMessage::Stop => {
10721085
self.stop(false)?;

komorebi/src/windows_api.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,9 @@ impl WindowsApi {
480480
// Raise the window to the top of the Z order, but do not activate or focus
481481
// it. Use raise_and_focus_window to activate and focus a window.
482482
pub fn raise_window(hwnd: isize) -> Result<()> {
483-
let flags = SetWindowPosition::NO_MOVE | SetWindowPosition::NO_ACTIVATE;
483+
let flags = SetWindowPosition::NO_MOVE
484+
| SetWindowPosition::NO_SIZE
485+
| SetWindowPosition::NO_ACTIVATE;
484486

485487
let position = HWND_TOP;
486488
Self::set_window_pos(

0 commit comments

Comments
 (0)