From 0a39628bb14e03a6a37fd9593ab4a749445057fc Mon Sep 17 00:00:00 2001 From: apio Date: Tue, 15 Aug 2023 11:31:01 +0200 Subject: [PATCH] ui+wind: Send mouse move events through IPC --- libui/include/ui/ipc/Client.h | 11 +++++++++++ libui/src/App.cpp | 6 ++++++ wind/Mouse.cpp | 17 +++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/libui/include/ui/ipc/Client.h b/libui/include/ui/ipc/Client.h index 35fbbef9..35b09642 100644 --- a/libui/include/ui/ipc/Client.h +++ b/libui/include/ui/ipc/Client.h @@ -9,6 +9,7 @@ #pragma once #include +#include namespace ui { @@ -17,6 +18,7 @@ namespace ui IPC_ENUM_CLIENT(ui), CREATE_WINDOW_RESPONSE_ID, WINDOW_CLOSE_REQUEST_ID, + MOUSE_EVENT_REQUEST_ID, }; struct CreateWindowResponse @@ -33,4 +35,13 @@ namespace ui int window; }; + + struct MouseEventRequest + { + static constexpr u8 ID = MOUSE_EVENT_REQUEST_ID; + + int window; + Point position; + int buttons; + }; } diff --git a/libui/src/App.cpp b/libui/src/App.cpp index 79c00d23..7d934f9f 100644 --- a/libui/src/App.cpp +++ b/libui/src/App.cpp @@ -92,6 +92,12 @@ namespace ui window->close(); return {}; } + case MOUSE_EVENT_REQUEST_ID: { + MouseEventRequest request; + TRY(m_client->recv_typed(request)); + os::eprintln("ui: Mouse move to (%d, %d)", request.position.x, request.position.y); + return {}; + } default: fail("Unexpected IPC request from server!"); } } diff --git a/wind/Mouse.cpp b/wind/Mouse.cpp index 63ea0aad..7f3d72e2 100644 --- a/wind/Mouse.cpp +++ b/wind/Mouse.cpp @@ -78,4 +78,21 @@ void Mouse::update(const moon::MousePacket& packet) } } } + + for (Window* window = g_windows.last().value_or(nullptr); window; + window = g_windows.previous(window).value_or(nullptr)) + { + auto titlebar = window->surface.absolute(window->titlebar); + auto contents = window->surface.absolute(window->contents); + if (titlebar.contains(m_position)) break; + if (contents.contains(m_position)) + { + ui::MouseEventRequest request; + request.window = window->id; + request.position = contents.relative(m_position); + request.buttons = packet.buttons; + os::IPC::send_async(window->client->conn, request); + break; + } + } }