LibGUI/WindowServer: Allow querying global cursor position

This commit is contained in:
2026-06-23 23:31:17 +03:00
parent 1287c8e335
commit 689494db63
6 changed files with 46 additions and 0 deletions

View File

@@ -274,6 +274,12 @@ namespace LibGUI
send_packet(packet, __FUNCTION__);
}
void Window::query_cursor_position()
{
const WindowPacket::QueryPointer packet {};
send_packet(packet, __FUNCTION__);
}
void Window::on_socket_error(BAN::StringView function)
{
if (m_handling_socket_error)
@@ -419,6 +425,10 @@ namespace LibGUI
if (m_mouse_scroll_event_callback)
m_mouse_scroll_event_callback(TRY_OR_BREAK(EventPacket::MouseScrollEvent::deserialize(packet_span)).event);
break;
case PacketType::QueryPointerEvent:
if (m_query_pointer_event_callback)
m_query_pointer_event_callback(TRY_OR_BREAK(EventPacket::QueryPointerEvent::deserialize(packet_span)).event);
break;
#undef TRY_OR_BREAK
default:
dprintln("unhandled packet type: {}", static_cast<uint32_t>(header.type));

View File

@@ -211,6 +211,9 @@ namespace LibGUI
MouseButtonEvent,
MouseMoveEvent,
MouseScrollEvent,
QueryPointer,
QueryPointerEvent,
};
struct PacketHeader
@@ -303,6 +306,10 @@ namespace LibGUI
BAN::Vector<uint32_t>, pixels
);
DEFINE_PACKET(
QueryPointer
);
}
namespace EventPacket
@@ -390,6 +397,15 @@ namespace LibGUI
event_t, event
);
DEFINE_PACKET_EXTRA(
QueryPointerEvent,
struct event_t {
int32_t x;
int32_t y;
},
event_t, event
);
}
}

View File

@@ -63,6 +63,8 @@ namespace LibGUI
// actual resize is only done after resize callback is called
void request_resize(uint32_t width, uint32_t height);
void query_cursor_position();
uint32_t width() const { return m_width; }
uint32_t height() const { return m_height; }
@@ -80,6 +82,7 @@ namespace LibGUI
void set_window_focus_event_callback(BAN::Function<void(EventPacket::WindowFocusEvent::event_t)> callback) { m_window_focus_event_callback = callback; }
void set_window_fullscreen_event_callback(BAN::Function<void(EventPacket::WindowFullscreenEvent::event_t)> callback) { m_window_fullscreen_event_callback = callback; }
void set_window_move_event_callback(BAN::Function<void(EventPacket::WindowMoveEvent::event_t)> callback) { m_window_move_event_callback = callback; }
void set_query_pointer_event_callback(BAN::Function<void(EventPacket::QueryPointerEvent::event_t)> callback) { m_query_pointer_event_callback = callback; }
int server_fd() const { return m_server_fd; }
@@ -124,6 +127,7 @@ namespace LibGUI
BAN::Function<void(EventPacket::MouseButtonEvent::event_t)> m_mouse_button_event_callback;
BAN::Function<void(EventPacket::MouseMoveEvent::event_t)> m_mouse_move_event_callback;
BAN::Function<void(EventPacket::MouseScrollEvent::event_t)> m_mouse_scroll_event_callback;
BAN::Function<void(EventPacket::QueryPointerEvent::event_t)> m_query_pointer_event_callback;
size_t m_in_buffer_size { 0 };
BAN::Array<uint8_t, 64 * 1024> m_in_buffer;