ui+wind: Send mouse move events through IPC

This commit is contained in:
apio 2023-08-15 11:31:01 +02:00
parent 02c72e15d5
commit 0a39628bb1
Signed by: apio
GPG Key ID: B8A7D06E42258954
3 changed files with 34 additions and 0 deletions

View File

@ -9,6 +9,7 @@
#pragma once #pragma once
#include <os/IPC.h> #include <os/IPC.h>
#include <ui/Point.h>
namespace ui namespace ui
{ {
@ -17,6 +18,7 @@ namespace ui
IPC_ENUM_CLIENT(ui), IPC_ENUM_CLIENT(ui),
CREATE_WINDOW_RESPONSE_ID, CREATE_WINDOW_RESPONSE_ID,
WINDOW_CLOSE_REQUEST_ID, WINDOW_CLOSE_REQUEST_ID,
MOUSE_EVENT_REQUEST_ID,
}; };
struct CreateWindowResponse struct CreateWindowResponse
@ -33,4 +35,13 @@ namespace ui
int window; int window;
}; };
struct MouseEventRequest
{
static constexpr u8 ID = MOUSE_EVENT_REQUEST_ID;
int window;
Point position;
int buttons;
};
} }

View File

@ -92,6 +92,12 @@ namespace ui
window->close(); window->close();
return {}; 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!"); default: fail("Unexpected IPC request from server!");
} }
} }

View File

@ -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;
}
}
} }