Skip to content

Commit

Permalink
(#3309) selecting a correct next window after the focused one is clos…
Browse files Browse the repository at this point in the history
…ed or disabled
  • Loading branch information
mattkae committed May 9, 2024
1 parent 9aa2ff7 commit 1d84931
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
31 changes: 15 additions & 16 deletions src/miral/application_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,28 +93,26 @@ void ApplicationSelector::advise_delete_window(WindowInfo const& window_info)
return;
}

// If we delete the selected window, we will try to select the next available one
auto original_it = it;
if (*it == selected)
if (window_info.window() == selected)
{
do {
it++;
if (it == focus_list.end())
it = focus_list.begin();
// If we delete the selected window, let's select the next window according
// to our last traversal scheme.
auto next_selected = next(is_last_traversal_within_app);

if (it == original_it)
break;
} while (!tools.can_select_window(*it));
// If we select the same window again, let's try and select with the other
// traversal scheme
if (next_selected == window_info.window())
next_selected = next(!is_last_traversal_within_app);

if (it != original_it)
selected = *it;
else
// We can complete here, since this is the window that we decided to select
complete();

// If it still doesn't work, then we have nothing else to select
if (next_selected == window_info.window())
selected = Window();
}
else
selected = Window();

focus_list.erase(original_it);
focus_list.erase(it);
}

auto ApplicationSelector::next(bool within_app) -> Window
Expand Down Expand Up @@ -169,6 +167,7 @@ auto ApplicationSelector::get_focused() -> Window

auto ApplicationSelector::advance(bool reverse, bool within_app) -> Window
{
is_last_traversal_within_app = within_app;
if (focus_list.empty())
{
return {};
Expand Down
2 changes: 2 additions & 0 deletions src/miral/application_selector.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class ApplicationSelector
Window selected;

bool is_active_ = false;

bool is_last_traversal_within_app = false;
};

}
Expand Down
6 changes: 5 additions & 1 deletion src/miral/basic_window_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ void miral::BasicWindowManager::remove_surface(

void miral::BasicWindowManager::remove_window(Application const& application, miral::WindowInfo const& info)
{
bool const is_active_window{active_window() == info.window()};
auto const workspaces_containing_window = workspaces_containing(info.window());

{
Expand All @@ -247,6 +246,11 @@ void miral::BasicWindowManager::remove_window(Application const& application, mi

policy->advise_delete_window(info);

// Warning: order is important here. The compositor may decide to
// select a different window in advise_delete_window in response
// to the selected window closing. Hence, is_active_window will
// only be true if they haven't elected to select a new window.
bool const is_active_window{active_window() == info.window()};
info_for(application).remove_window(info.window());
mru_active_windows.erase(info.window());
fullscreen_surfaces.erase(info.window());
Expand Down

0 comments on commit 1d84931

Please sign in to comment.