From 28250c4dca108ca65e90c99ccbca66d101766a48 Mon Sep 17 00:00:00 2001 From: Tarek Ismail Date: Fri, 6 Dec 2024 18:06:47 +0200 Subject: [PATCH] Hack around alt+tab for focus stealing prevented apps. --- src/miral/application_selector.cpp | 13 +++++++++---- src/miral/basic_window_manager.cpp | 12 +++++++++++- src/miral/mru_window_list.cpp | 9 +++++++++ src/miral/mru_window_list.h | 1 + 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/miral/application_selector.cpp b/src/miral/application_selector.cpp index 1d4e8d5de5b..3a50e4ea606 100644 --- a/src/miral/application_selector.cpp +++ b/src/miral/application_selector.cpp @@ -19,6 +19,7 @@ #include #include #include +#include using namespace miral; @@ -212,6 +213,7 @@ auto ApplicationSelector::advance(bool reverse, bool within_app) -> Window auto it = find(selected); std::optional next_window = std::nullopt; + auto should_continue = true; do { if (reverse) { @@ -236,9 +238,10 @@ auto ApplicationSelector::advance(bool reverse, bool within_app) -> Window if (within_app) { if (it->application() == (*originally_selected_it).application() && tools.can_select_window(*it)) + { next_window = *it; - else - next_window = std::nullopt; + should_continue = false; + } } else { @@ -251,15 +254,17 @@ auto ApplicationSelector::advance(bool reverse, bool within_app) -> Window if (prev_it->application() == it->application()) { - next_window = std::nullopt; already_encountered = true; break; } } if (!already_encountered) + { next_window = tools.window_to_select_application(it->application()); + should_continue = !next_window.has_value(); + } } - } while (next_window == std::nullopt); + } while (should_continue); if (next_window == std::nullopt) return selected; diff --git a/src/miral/basic_window_manager.cpp b/src/miral/basic_window_manager.cpp index c4490d0e38c..b2a1cba04b9 100644 --- a/src/miral/basic_window_manager.cpp +++ b/src/miral/basic_window_manager.cpp @@ -196,6 +196,16 @@ void miral::BasicWindowManager::surface_ready(std::shared_ptr co { Locker lock{this}; policy->handle_window_ready(info_for(surface)); + + // Need to push onto the MRU list for alt+tab to work correctly. + // + // Originally, applications were pushed only when selected, but due to + // focus stealing prevention, they were not activated and thus weren't + // selected nor added to mru_active_windows, breaking alt+tab + auto window = info_for(surface).window(); + auto const top = mru_active_windows.top(); + if(top && top != window) + mru_active_windows.push_unfocused(window); } void miral::BasicWindowManager::modify_surface( @@ -2993,4 +3003,4 @@ void miral::BasicWindowManager::move_cursor_to(mir::geometry::PointF point) sink->handle_input(std::move(event)); }); }); -} \ No newline at end of file +} diff --git a/src/miral/mru_window_list.cpp b/src/miral/mru_window_list.cpp index 1ee0b7b5832..25c63ae79e6 100644 --- a/src/miral/mru_window_list.cpp +++ b/src/miral/mru_window_list.cpp @@ -35,6 +35,15 @@ void miral::MRUWindowList::push(Window const& window) windows.push_back(window); } +void miral::MRUWindowList::push_unfocused(Window const& window) +{ + windows.erase(remove(begin(windows), end(windows), window), end(windows)); + if(!windows.empty()) + windows.insert(windows.end()-1, window); + else + windows.push_back(window); +} + void miral::MRUWindowList::erase(Window const& window) { windows.erase(remove(begin(windows), end(windows), window), end(windows)); diff --git a/src/miral/mru_window_list.h b/src/miral/mru_window_list.h index fc799f17a2e..132838a713c 100644 --- a/src/miral/mru_window_list.h +++ b/src/miral/mru_window_list.h @@ -29,6 +29,7 @@ class MRUWindowList public: void push(Window const& window); + void push_unfocused(Window const& window); void erase(Window const& window); auto top() const -> Window;