mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-08-09 08:41:31 +00:00
[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:
@@ -22,11 +22,11 @@
|
||||
|
||||
static const uint8_t REPORT_DESCRIPTOR[] =
|
||||
{
|
||||
// Absolute tablet, report ID 1.
|
||||
// Absolute mouse, report ID 1.
|
||||
0x05, 0x01, // Usage Page (Generic Desktop)
|
||||
0x09, 0x02, // Usage (Mouse)
|
||||
0xA1, 0x01, // Collection (Application)
|
||||
0x85, HID_REPORT_ID_TABLET,
|
||||
0x85, HID_REPORT_ID_MOUSE_ABSOLUTE,
|
||||
0x09, 0x01, // Usage (Pointer)
|
||||
0xA1, 0x00, // Collection (Physical)
|
||||
0x05, 0x09, // Usage Page (Button)
|
||||
@@ -48,6 +48,12 @@ static const uint8_t REPORT_DESCRIPTOR[] =
|
||||
0x75, 0x10, // Report Size (16)
|
||||
0x95, 0x02, // Report Count (2)
|
||||
0x81, 0x02, // Input (Data, Variable, Absolute)
|
||||
0x09, 0x38, // Usage (Wheel)
|
||||
0x15, 0x81, // Logical Minimum (-127)
|
||||
0x25, 0x7F, // Logical Maximum (127)
|
||||
0x75, 0x08, // Report Size (8)
|
||||
0x95, 0x01, // Report Count (1)
|
||||
0x81, 0x06, // Input (Data, Variable, Relative)
|
||||
0xC0, // End Collection
|
||||
0xC0, // End Collection
|
||||
|
||||
@@ -55,7 +61,7 @@ static const uint8_t REPORT_DESCRIPTOR[] =
|
||||
0x05, 0x01, // Usage Page (Generic Desktop)
|
||||
0x09, 0x02, // Usage (Mouse)
|
||||
0xA1, 0x01, // Collection (Application)
|
||||
0x85, HID_REPORT_ID_MOUSE,
|
||||
0x85, HID_REPORT_ID_MOUSE_RELATIVE,
|
||||
0x09, 0x01, // Usage (Pointer)
|
||||
0xA1, 0x00, // Collection (Physical)
|
||||
0x05, 0x09, // Usage Page (Button)
|
||||
@@ -136,11 +142,11 @@ size_t HIDGetInputReportSize(uint8_t reportId)
|
||||
{
|
||||
switch (reportId)
|
||||
{
|
||||
case HID_REPORT_ID_TABLET:
|
||||
return sizeof(HIDTabletReport);
|
||||
case HID_REPORT_ID_MOUSE_ABSOLUTE:
|
||||
return sizeof(HIDMouseAbsoluteReport);
|
||||
|
||||
case HID_REPORT_ID_MOUSE:
|
||||
return sizeof(HIDMouseReport);
|
||||
case HID_REPORT_ID_MOUSE_RELATIVE:
|
||||
return sizeof(HIDMouseRelativeReport);
|
||||
|
||||
case HID_REPORT_ID_KEYBOARD:
|
||||
return sizeof(HIDKeyboardReport);
|
||||
|
||||
@@ -25,22 +25,23 @@
|
||||
|
||||
enum HIDReportId : uint8_t
|
||||
{
|
||||
HID_REPORT_ID_TABLET = 1,
|
||||
HID_REPORT_ID_MOUSE = 2,
|
||||
HID_REPORT_ID_KEYBOARD = 3,
|
||||
HID_REPORT_ID_MOUSE_ABSOLUTE = 1,
|
||||
HID_REPORT_ID_MOUSE_RELATIVE = 2,
|
||||
HID_REPORT_ID_KEYBOARD = 3,
|
||||
};
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
struct HIDTabletReport
|
||||
struct HIDMouseAbsoluteReport
|
||||
{
|
||||
uint8_t reportId;
|
||||
uint8_t buttons;
|
||||
uint16_t x;
|
||||
uint16_t y;
|
||||
int8_t wheel;
|
||||
};
|
||||
|
||||
struct HIDMouseReport
|
||||
struct HIDMouseRelativeReport
|
||||
{
|
||||
uint8_t reportId;
|
||||
uint8_t buttons;
|
||||
@@ -65,8 +66,8 @@ struct HIDKeyboardLedsReport
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
static_assert(sizeof(HIDTabletReport) == 6);
|
||||
static_assert(sizeof(HIDMouseReport) == 7);
|
||||
static_assert(sizeof(HIDMouseAbsoluteReport) == 7);
|
||||
static_assert(sizeof(HIDMouseRelativeReport) == 7);
|
||||
static_assert(sizeof(HIDKeyboardReport) == 9);
|
||||
static_assert(sizeof(HIDKeyboardLedsReport) == 2);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user