1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:28:12 +00:00

WindowServer: Make the ordering in the window switcher a bit more sane.

This commit is contained in:
Andreas Kling 2019-05-13 00:08:56 +02:00
parent a20ce4d2b8
commit 8c4b7fe385
2 changed files with 14 additions and 11 deletions

View file

@ -105,21 +105,24 @@ void WSWindowSwitcher::draw()
void WSWindowSwitcher::refresh()
{
auto& wm = WSWindowManager::the();
WSWindow* selected_window = nullptr;
if (m_selected_index > 0 && m_windows[m_selected_index])
selected_window = m_windows[m_selected_index].ptr();
if (!selected_window)
selected_window = wm.highlight_window() ? wm.highlight_window() : wm.active_window();
m_windows.clear();
m_selected_index = 0;
int window_count = 0;
int longest_title_width = 0;
WSWindowManager::the().for_each_visible_window_of_type_from_back_to_front(WSWindowType::Normal, [&] (WSWindow& window) {
wm.for_each_visible_window_of_type_from_front_to_back(WSWindowType::Normal, [&] (WSWindow& window) {
++window_count;
longest_title_width = max(longest_title_width, WSWindowManager::the().font().width(window.title()));
longest_title_width = max(longest_title_width, wm.font().width(window.title()));
if (selected_window == &window)
m_selected_index = m_windows.size();
m_windows.append(window.make_weak_ptr());
return IterationDecision::Continue;
});
}, true);
if (m_windows.is_empty()) {
hide();
return;
@ -127,7 +130,7 @@ void WSWindowSwitcher::refresh()
int space_for_window_rect = 180;
m_rect.set_width(thumbnail_width() + longest_title_width + space_for_window_rect + padding() * 2 + item_padding() * 2);
m_rect.set_height(window_count * item_height() + padding() * 2);
m_rect.center_within(WSWindowManager::the().m_screen_rect);
m_rect.center_within(wm.m_screen_rect);
if (!m_switcher_window)
m_switcher_window = make<WSWindow>(*this, WSWindowType::WindowSwitcher);
m_switcher_window->set_rect(m_rect);