Skip to content

Commit

Permalink
Move workspace intersection checking logic to `window_workspaces_inte…
Browse files Browse the repository at this point in the history
…rsect`
  • Loading branch information
tarek-y-ismail committed Dec 12, 2024
1 parent 075564d commit 2f4c554
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
39 changes: 22 additions & 17 deletions src/miral/basic_window_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,28 +294,16 @@ void miral::BasicWindowManager::refocus(
// Try to activate to recently active window of any application in a shared workspace
{
miral::Window new_focus;

auto workspaces_containing_window_mut = workspaces_containing_window;
// Need to sort only once
std::sort(workspaces_containing_window_mut.begin(), workspaces_containing_window_mut.end());

mru_active_windows.enumerate([&](miral::Window& other_window)
mru_active_windows.enumerate(
[&](miral::Window& other_window)
{
if(!info_for(other_window).is_visible()) return true;

auto workspaces_containing_other_window = workspaces_containing(other_window);
std::sort(workspaces_containing_other_window.begin(), workspaces_containing_other_window.end());

auto intersection = std::vector<std::shared_ptr<Workspace>>();
if (!info_for(other_window).is_visible())
return true;

std::set_intersection(
workspaces_containing_window_mut.begin(),
workspaces_containing_window_mut.end(),
workspaces_containing_other_window.begin(),
workspaces_containing_other_window.end(),
std::back_inserter(intersection));

if(!intersection.empty())
if (window_workspaces_intersect(workspaces_containing_window_mut, other_window))
return !(new_focus = select_active_window(other_window));

return true;
Expand Down Expand Up @@ -2999,3 +2987,20 @@ void miral::BasicWindowManager::move_cursor_to(mir::geometry::PointF point)
});
});
}

auto miral::BasicWindowManager::window_workspaces_intersect(std::vector<std::shared_ptr<Workspace>> const& w1_workspaces, Window const& w2) const -> bool
{
auto w2_workspaces = workspaces_containing(w2);
std::sort(w2_workspaces.begin(), w2_workspaces.end());

auto intersection = std::vector<std::shared_ptr<Workspace>>();

std::set_intersection(
w1_workspaces.begin(),
w1_workspaces.end(),
w2_workspaces.begin(),
w2_workspaces.end(),
std::back_inserter(intersection));

return !intersection.empty();
}
4 changes: 4 additions & 0 deletions src/miral/basic_window_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,10 @@ class BasicWindowManager : public virtual mir::shell::WindowManager,
void for_each_descendent_in(WindowInfo const& info, std::function<void(const Window&)> func);
/// Gathers windows provided WindowInfo
auto collect_windows(WindowInfo const& info) -> SurfaceSet;

// w1_workspaces must be sorted
auto window_workspaces_intersect(
std::vector<std::shared_ptr<Workspace>> const& w1_workspaces, Window const& w2) const -> bool;
};
}

Expand Down

0 comments on commit 2f4c554

Please sign in to comment.