WindowServer/LibGUI: Add window focus events

This commit is contained in:
2025-08-21 03:01:25 +03:00
parent 2f3fd6867d
commit f11bb082e4
4 changed files with 41 additions and 1 deletions

View File

@@ -90,7 +90,7 @@ void WindowServer::on_window_create(int fd, const LibGUI::WindowPacket::WindowCr
window_popper.disable();
if (packet.attributes.focusable)
if (packet.attributes.shown && packet.attributes.focusable)
set_focused_window(window);
else if (m_client_windows.size() > 1)
BAN::swap(m_client_windows[m_client_windows.size() - 1], m_client_windows[m_client_windows.size() - 2]);
@@ -197,6 +197,9 @@ void WindowServer::on_window_set_attributes(int fd, const LibGUI::WindowPacket::
};
if (auto ret = event_packet.send_serialized(target_window->client_fd()); ret.is_error())
dwarnln("could not send window shown event: {}", ret.error());
if (packet.attributes.focusable && packet.attributes.shown)
set_focused_window(target_window);
}
void WindowServer::on_window_set_mouse_relative(int fd, const LibGUI::WindowPacket::WindowSetMouseRelative& packet)
@@ -781,6 +784,17 @@ void WindowServer::set_focused_window(BAN::RefPtr<Window> window)
invalidate(cursor_area());
}
if (m_focused_window)
{
LibGUI::EventPacket::WindowFocusEvent packet;
packet.event.focused = false;
if (auto ret = packet.send_serialized(m_focused_window->client_fd()); ret.is_error())
{
dwarnln("could not send window focus event: {}", ret.error());
return;
}
}
for (size_t i = m_client_windows.size(); i > 0; i--)
{
if (m_client_windows[i - 1] == window)
@@ -792,6 +806,17 @@ void WindowServer::set_focused_window(BAN::RefPtr<Window> window)
break;
}
}
if (m_focused_window)
{
LibGUI::EventPacket::WindowFocusEvent packet;
packet.event.focused = true;
if (auto ret = packet.send_serialized(m_focused_window->client_fd()); ret.is_error())
{
dwarnln("could not send window focus event: {}", ret.error());
return;
}
}
}
static uint32_t alpha_blend(uint32_t color_a, uint32_t color_b)