Skip to content

Commit

Permalink
Hack around alt+tab for focus stealing prevented apps.
Browse files Browse the repository at this point in the history
  • Loading branch information
tarek-y-ismail committed Dec 6, 2024
1 parent fe15087 commit 28250c4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/miral/application_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <miral/application.h>
#include <mir/log.h>
#include <mir/scene/session.h>
#include <unordered_set>

using namespace miral;

Expand Down Expand Up @@ -212,6 +213,7 @@ auto ApplicationSelector::advance(bool reverse, bool within_app) -> Window
auto it = find(selected);

std::optional<Window> next_window = std::nullopt;
auto should_continue = true;
do {
if (reverse)
{
Expand All @@ -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
{
Expand All @@ -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;
Expand Down
12 changes: 11 additions & 1 deletion src/miral/basic_window_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,16 @@ void miral::BasicWindowManager::surface_ready(std::shared_ptr<scene::Surface> 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(
Expand Down Expand Up @@ -2993,4 +3003,4 @@ void miral::BasicWindowManager::move_cursor_to(mir::geometry::PointF point)
sink->handle_input(std::move(event));
});
});
}
}
9 changes: 9 additions & 0 deletions src/miral/mru_window_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions src/miral/mru_window_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 28250c4

Please sign in to comment.