mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-08-22 07:01:30 +00:00
[client/idd] input: synchronize keyboard LEDs
Report guest HID keyboard LED state from LGInput to LGIdd and publish it with the LGMP input endpoint status. Forward SPICE modifier updates through the same provider state so evdev can synchronize physical keyboard LEDs across transport changes and reconnects. Bump the versioned pipe and KVMFR input status contracts for the new feedback state. Accept earlier LGMP input status versions without LED feedback so the client retains input while the guest driver is being upgraded.
This commit is contained in:
@@ -165,7 +165,10 @@ static NTSTATUS SetOutputReport(
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
|
||||
WDFDEVICE device = WdfIoQueueGetDevice(queue);
|
||||
HIDGetDeviceContext(device)->keyboardLeds = report->leds;
|
||||
HIDDeviceContext * context = HIDGetDeviceContext(device);
|
||||
context->keyboardLeds = report->leds;
|
||||
if (context->inputPipe)
|
||||
context->inputPipe->UpdateKeyboardLEDs(report->leds);
|
||||
WdfRequestSetInformation(request, sizeof(*report));
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,15 @@ static constexpr uint16_t HID_CONSUMER_USAGE_VOLUME_DOWN = 0xea;
|
||||
|
||||
bool CInputPipeClient::Start()
|
||||
{
|
||||
{
|
||||
CSRWExclusiveLock lock(m_feedbackLock);
|
||||
m_feedbackReady = false;
|
||||
}
|
||||
m_endpoint.Stop();
|
||||
{
|
||||
CSRWExclusiveLock lock(m_feedbackLock);
|
||||
m_feedbackSequence = 0;
|
||||
}
|
||||
m_lastSequence = 0;
|
||||
m_statReceived = 0;
|
||||
m_statMalformed = 0;
|
||||
@@ -55,6 +63,10 @@ bool CInputPipeClient::Start()
|
||||
void CInputPipeClient::Stop()
|
||||
{
|
||||
const bool wasRunning = m_endpoint.IsRunning();
|
||||
{
|
||||
CSRWExclusiveLock lock(m_feedbackLock);
|
||||
m_feedbackReady = false;
|
||||
}
|
||||
m_endpoint.Stop();
|
||||
m_lastSequence = 0;
|
||||
if (wasRunning)
|
||||
@@ -67,11 +79,22 @@ void CInputPipeClient::Stop()
|
||||
void CInputPipeClient::OnPipeConnected()
|
||||
{
|
||||
m_lastSequence = 0;
|
||||
{
|
||||
CSRWExclusiveLock lock(m_feedbackLock);
|
||||
m_feedbackSequence = 0;
|
||||
m_feedbackReady = SendKeyboardLEDsLocked();
|
||||
if (!m_feedbackReady)
|
||||
DEBUG_WARN("Failed to report LGInput keyboard LEDs");
|
||||
}
|
||||
DEBUG_INFO("Connected to the LGIdd input transport");
|
||||
}
|
||||
|
||||
void CInputPipeClient::OnPipeDisconnected()
|
||||
{
|
||||
{
|
||||
CSRWExclusiveLock lock(m_feedbackLock);
|
||||
m_feedbackReady = false;
|
||||
}
|
||||
m_lastSequence = 0;
|
||||
LogStatistics(true);
|
||||
CHIDDevice::ResetReports();
|
||||
@@ -319,6 +342,46 @@ bool CInputPipeClient::SubmitReport(
|
||||
return true;
|
||||
}
|
||||
|
||||
void CInputPipeClient::UpdateKeyboardLEDs(uint8_t leds)
|
||||
{
|
||||
const uint8_t mask =
|
||||
KVMFR_INPUT_KEYBOARD_LED_NUM_LOCK |
|
||||
KVMFR_INPUT_KEYBOARD_LED_CAPS_LOCK |
|
||||
KVMFR_INPUT_KEYBOARD_LED_SCROLL_LOCK |
|
||||
KVMFR_INPUT_KEYBOARD_LED_COMPOSE |
|
||||
KVMFR_INPUT_KEYBOARD_LED_KANA;
|
||||
leds &= mask;
|
||||
|
||||
CSRWExclusiveLock lock(m_feedbackLock);
|
||||
if (m_keyboardLEDs == leds)
|
||||
return;
|
||||
|
||||
m_keyboardLEDs = leds;
|
||||
if (m_feedbackReady && !SendKeyboardLEDsLocked())
|
||||
{
|
||||
m_feedbackReady = false;
|
||||
DEBUG_WARN("Failed to report LGInput keyboard LEDs");
|
||||
}
|
||||
}
|
||||
|
||||
bool CInputPipeClient::SendKeyboardLEDsLocked()
|
||||
{
|
||||
LGInputPipeMessage message = {};
|
||||
message.magic = LG_INPUT_PIPE_MAGIC;
|
||||
message.version = LG_INPUT_PIPE_VERSION;
|
||||
message.type = LG_INPUT_PIPE_MESSAGE_KEYBOARD_LEDS;
|
||||
message.payloadSize = sizeof(LGInputPipeKeyboardLEDs);
|
||||
message.sequence = ++m_feedbackSequence;
|
||||
|
||||
const LGInputPipeKeyboardLEDs feedback = { m_keyboardLEDs };
|
||||
memcpy(message.payload, &feedback, sizeof(feedback));
|
||||
if (m_endpoint.Send(&message, sizeof(message)))
|
||||
return true;
|
||||
|
||||
--m_feedbackSequence;
|
||||
return false;
|
||||
}
|
||||
|
||||
void CInputPipeClient::LogStatistics(bool force)
|
||||
{
|
||||
const ULONGLONG now = GetTickCount64();
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "CPipeEndpoint.h"
|
||||
#include "CSRWLock.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
@@ -32,6 +33,7 @@ public:
|
||||
|
||||
bool Start();
|
||||
void Stop();
|
||||
void UpdateKeyboardLEDs(uint8_t leds);
|
||||
|
||||
private:
|
||||
static constexpr ULONGLONG STATISTICS_INTERVAL_MS = 5000;
|
||||
@@ -43,9 +45,14 @@ private:
|
||||
bool HandleMouseAbsolute(const void * payload, size_t size);
|
||||
bool HandleKeyboard(const void * payload, size_t size);
|
||||
bool SubmitReport(const void * report, size_t size);
|
||||
bool SendKeyboardLEDsLocked();
|
||||
void LogStatistics(bool force);
|
||||
|
||||
CPipeEndpoint m_endpoint;
|
||||
CSRWLock m_feedbackLock;
|
||||
bool m_feedbackReady = false;
|
||||
uint64_t m_feedbackSequence = 0;
|
||||
uint8_t m_keyboardLEDs = 0;
|
||||
uint64_t m_lastSequence = 0;
|
||||
uint64_t m_statReceived = 0;
|
||||
uint64_t m_statMalformed = 0;
|
||||
|
||||
Reference in New Issue
Block a user