From e1b82e4e43919902937ba28d66e84808510df4db Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sun, 17 Nov 2024 03:14:27 +0200 Subject: [PATCH] WindowServer: Don't allow focusing unfocusable windows after closing --- userspace/programs/WindowServer/WindowServer.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/userspace/programs/WindowServer/WindowServer.cpp b/userspace/programs/WindowServer/WindowServer.cpp index f896c042..abee0a2d 100644 --- a/userspace/programs/WindowServer/WindowServer.cpp +++ b/userspace/programs/WindowServer/WindowServer.cpp @@ -538,6 +538,7 @@ void WindowServer::on_mouse_scroll(LibInput::MouseScrollEvent event) void WindowServer::set_focused_window(BAN::RefPtr window) { + ASSERT(window->get_attributes().focusable); if (m_focused_window == window) return; @@ -1019,8 +1020,14 @@ void WindowServer::remove_client_fd(int fd) if (window == m_focused_window) { m_focused_window = nullptr; - if (!m_client_windows.empty()) - set_focused_window(m_client_windows.back()); + for (size_t j = m_client_windows.size(); j > 0; j--) + { + auto& client_window = m_client_windows[j - 1]; + if (!client_window->get_attributes().focusable) + continue; + set_focused_window(client_window); + break; + } } break;