Skip to content

Commit

Permalink
Check if window under test is hidden or minimized in refocus()
Browse files Browse the repository at this point in the history
Took a moment to rewrite the intersection checking code to use
`std::set_intersection`. Maybe a tad more readable?
  • Loading branch information
tarek-y-ismail committed Dec 11, 2024
1 parent 699dcde commit 0048a5b
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions src/miral/basic_window_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
#include "basic_window_manager.h"
#include "display_configuration_listeners.h"

#include "mir_toolkit/common.h"
#include "miral/window_manager_tools.h"

#include <iterator>
#include <mir/log.h>
#include <mir/executor.h>
#include <mir/scene/session.h>
Expand Down Expand Up @@ -291,25 +293,38 @@ void miral::BasicWindowManager::refocus(
if (can_activate_window_for_session_in_workspace(application, workspaces_containing_window))
return;

auto const is_hidden = [this](auto const& w)
{
auto const& info = info_for(w);
return info.state() != mir_window_state_hidden || info.state() == mir_window_state_minimized;
};

// Try to activate to recently active window of any application in a shared workspace
{
miral::Window new_focus;

mru_active_windows.enumerate([&](miral::Window& window)
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)
{
// select_active_window() calls set_focus_to() which updates mru_active_windows and changes window
auto const w = window;
if(is_hidden(other_window)) return true;

for (auto const& workspace : workspaces_containing(w))
{
for (auto const& ww : workspaces_containing_window)
{
if (ww == workspace)
{
return !(new_focus = select_active_window(w));
}
}
}
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>>();

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())
return !(new_focus = select_active_window(other_window));

return true;
});
Expand All @@ -328,14 +343,12 @@ void miral::BasicWindowManager::refocus(
{
// select_active_window() calls set_focus_to() which updates mru_active_windows and changes window
auto const w = window;
if(is_hidden(w)) return true;
return !(new_focus = select_active_window(w));
});

if (new_focus) return;
}

// Fallback to cycling through applications
focus_next_application();
}

void miral::BasicWindowManager::erase(miral::WindowInfo const& info)
Expand Down Expand Up @@ -2993,4 +3006,4 @@ void miral::BasicWindowManager::move_cursor_to(mir::geometry::PointF point)
sink->handle_input(std::move(event));
});
});
}
}

0 comments on commit 0048a5b

Please sign in to comment.