[idd] input: add mouse and keyboard IPC messages

Replace raw HID report forwarding with typed absolute mouse, relative
mouse, and keyboard messages.

Expose absolute and relative modes as separate Mouse collections because
Windows MouHID requires one X/Y motion mode per mouse device.
This commit is contained in:
Geoffrey McRae
2026-08-08 19:39:17 +10:00
parent 241ab3fad2
commit 04fd31219c
7 changed files with 288 additions and 29 deletions

View File

@@ -23,6 +23,9 @@
#include "CDebug.h"
#include "InputPipeProtocol.h"
#include "../CHIDDevice.h"
#include "../HIDReports.h"
#include <string.h>
bool CInputPipeClient::Start()
{
@@ -67,7 +70,6 @@ bool CInputPipeClient::OnPipeMessage(
*static_cast<const LGInputPipeMessage *>(frame);
if (message.magic != LG_INPUT_PIPE_MAGIC ||
message.version != LG_INPUT_PIPE_VERSION ||
message.type != LG_INPUT_PIPE_MESSAGE_REPORT ||
!message.payloadSize ||
message.payloadSize > sizeof(message.payload))
return false;
@@ -78,10 +80,111 @@ bool CInputPipeClient::OnPipeMessage(
DEBUG_WARN("LGInput pipe report sequence changed unexpectedly");
return false;
}
m_lastSequence = message.sequence;
bool handled = false;
switch (message.type)
{
case LG_INPUT_PIPE_MESSAGE_MOUSE_RELATIVE:
handled = HandleMouseRelative(
message.payload, message.payloadSize);
break;
case LG_INPUT_PIPE_MESSAGE_MOUSE_ABSOLUTE:
handled = HandleMouseAbsolute(
message.payload, message.payloadSize);
break;
case LG_INPUT_PIPE_MESSAGE_KEYBOARD:
handled = HandleKeyboard(message.payload, message.payloadSize);
break;
default:
return false;
}
if (!handled)
return false;
m_lastSequence = message.sequence;
return true;
}
bool CInputPipeClient::HandleMouseRelative(
const void * payload,
size_t size)
{
if (size != sizeof(LGInputPipeMouseRelative))
return false;
LGInputPipeMouseRelative input = {};
memcpy(&input, payload, sizeof(input));
if (input.wheel < LG_INPUT_MOUSE_WHEEL_MIN ||
(input.buttons & ~LG_INPUT_MOUSE_BUTTON_MASK))
return false;
const HIDMouseRelativeReport report = {
HID_REPORT_ID_MOUSE_RELATIVE,
input.buttons,
input.deltaX,
input.deltaY,
input.wheel,
};
return SubmitReport(&report, sizeof(report));
}
bool CInputPipeClient::HandleMouseAbsolute(
const void * payload,
size_t size)
{
if (size != sizeof(LGInputPipeMouseAbsolute))
return false;
LGInputPipeMouseAbsolute input = {};
memcpy(&input, payload, sizeof(input));
if (input.x > LG_INPUT_MOUSE_ABSOLUTE_MAX ||
input.y > LG_INPUT_MOUSE_ABSOLUTE_MAX ||
input.wheel < LG_INPUT_MOUSE_WHEEL_MIN ||
(input.buttons & ~LG_INPUT_MOUSE_BUTTON_MASK))
return false;
const HIDMouseAbsoluteReport report = {
HID_REPORT_ID_MOUSE_ABSOLUTE,
input.buttons,
input.x,
input.y,
input.wheel,
};
return SubmitReport(&report, sizeof(report));
}
bool CInputPipeClient::HandleKeyboard(
const void * payload,
size_t size)
{
if (size != sizeof(LGInputPipeKeyboard))
return false;
LGInputPipeKeyboard input = {};
memcpy(&input, payload, sizeof(input));
HIDKeyboardReport report = {};
report.reportId = HID_REPORT_ID_KEYBOARD;
report.modifiers = input.modifiers;
for (size_t i = 0; i < LG_INPUT_KEYBOARD_KEY_COUNT; ++i)
{
if (input.keys[i] > LG_INPUT_KEYBOARD_USAGE_MAX)
return false;
report.keys[i] = input.keys[i];
}
return SubmitReport(&report, sizeof(report));
}
bool CInputPipeClient::SubmitReport(
const void * report,
size_t size)
{
const NTSTATUS status = CHIDDevice::SubmitReport(report, size);
const NTSTATUS status =
CHIDDevice::SubmitReport(message.payload, message.payloadSize);
if (status == STATUS_INVALID_PARAMETER)
return false;

View File

@@ -38,6 +38,10 @@ private:
void OnPipeConnected() override;
void OnPipeDisconnected() override;
bool OnPipeMessage(const void * message, size_t size) override;
bool HandleMouseRelative(const void * payload, size_t size);
bool HandleMouseAbsolute(const void * payload, size_t size);
bool HandleKeyboard(const void * payload, size_t size);
bool SubmitReport(const void * report, size_t size);
CPipeEndpoint m_endpoint;
uint64_t m_lastSequence = 0;