diff --git a/userspace/libraries/LibGUI/Window.cpp b/userspace/libraries/LibGUI/Window.cpp index 3c79b259..f0a11b64 100644 --- a/userspace/libraries/LibGUI/Window.cpp +++ b/userspace/libraries/LibGUI/Window.cpp @@ -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(header.type)); diff --git a/userspace/libraries/LibGUI/include/LibGUI/Packet.h b/userspace/libraries/LibGUI/include/LibGUI/Packet.h index d701df81..a9eae34b 100644 --- a/userspace/libraries/LibGUI/include/LibGUI/Packet.h +++ b/userspace/libraries/LibGUI/include/LibGUI/Packet.h @@ -211,6 +211,9 @@ namespace LibGUI MouseButtonEvent, MouseMoveEvent, MouseScrollEvent, + + QueryPointer, + QueryPointerEvent, }; struct PacketHeader @@ -303,6 +306,10 @@ namespace LibGUI BAN::Vector, 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 + ); + } } diff --git a/userspace/libraries/LibGUI/include/LibGUI/Window.h b/userspace/libraries/LibGUI/include/LibGUI/Window.h index b9cf8c65..11f9f1f9 100644 --- a/userspace/libraries/LibGUI/include/LibGUI/Window.h +++ b/userspace/libraries/LibGUI/include/LibGUI/Window.h @@ -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 callback) { m_window_focus_event_callback = callback; } void set_window_fullscreen_event_callback(BAN::Function callback) { m_window_fullscreen_event_callback = callback; } void set_window_move_event_callback(BAN::Function callback) { m_window_move_event_callback = callback; } + void set_query_pointer_event_callback(BAN::Function callback) { m_query_pointer_event_callback = callback; } int server_fd() const { return m_server_fd; } @@ -124,6 +127,7 @@ namespace LibGUI BAN::Function m_mouse_button_event_callback; BAN::Function m_mouse_move_event_callback; BAN::Function m_mouse_scroll_event_callback; + BAN::Function m_query_pointer_event_callback; size_t m_in_buffer_size { 0 }; BAN::Array m_in_buffer; diff --git a/userspace/programs/WindowServer/WindowServer.cpp b/userspace/programs/WindowServer/WindowServer.cpp index 3620b3f1..b29b5888 100644 --- a/userspace/programs/WindowServer/WindowServer.cpp +++ b/userspace/programs/WindowServer/WindowServer.cpp @@ -40,6 +40,19 @@ BAN::ErrorOr WindowServer::set_background_image(BAN::UniqPtr set_background_image(BAN::UniqPtr); + void on_query_pointer(int fd, const LibGUI::WindowPacket::QueryPointer&); + void on_window_create(int fd, const LibGUI::WindowPacket::WindowCreate&); void on_window_invalidate(int fd, const LibGUI::WindowPacket::WindowInvalidate&); void on_window_set_position(int fd, const LibGUI::WindowPacket::WindowSetPosition&); diff --git a/userspace/programs/WindowServer/main.cpp b/userspace/programs/WindowServer/main.cpp index 89f6d526..5b860dc7 100644 --- a/userspace/programs/WindowServer/main.cpp +++ b/userspace/programs/WindowServer/main.cpp @@ -472,6 +472,7 @@ int main() WINDOW_PACKET_CASE(WindowSetFullscreen, on_window_set_fullscreen); WINDOW_PACKET_CASE(WindowSetTitle, on_window_set_title); WINDOW_PACKET_CASE(WindowSetCursor, on_window_set_cursor); + WINDOW_PACKET_CASE(QueryPointer, on_query_pointer); #undef WINDOW_PACKET_CASE default: dprintln("unhandled packet type: {}", static_cast(header.type));