prep for absolute mouse movement

This commit is contained in:
nakst 2021-09-25 21:59:41 +01:00
parent 125cdfde4b
commit 7b53a6925d
5 changed files with 59 additions and 28 deletions

View File

@ -735,8 +735,6 @@ define ES_PATH_MOVE_ALLOW_COPY_AND_DELETE (1 << 0) // Copy and delete the file i
define ES_CLIPBOARD_ADD_LAZY_CUT (1 << 0) // Only perform the deletion after pasting; often implemented as a move.
define ES_SCROLL_WHEEL_SCALE (0x100)
include desktop/icons.header
enum EsFatalError {

View File

@ -198,7 +198,14 @@ uint16_t scancodeConversionTable2[] = {
void PS2MouseUpdated(EsGeneric _update) {
PS2Update *update = (PS2Update *) _update.p;
KMouseUpdate(update->xMovement * K_CURSOR_MOVEMENT_SCALE, update->yMovement * K_CURSOR_MOVEMENT_SCALE, update->buttons);
KMouseUpdateData data = {
.xMovement = update->xMovement * K_CURSOR_MOVEMENT_SCALE,
.yMovement = update->yMovement * K_CURSOR_MOVEMENT_SCALE,
.buttons = update->buttons,
};
KMouseUpdate(&data);
}
void PS2KeyboardUpdated(EsGeneric _update) {

View File

@ -1,6 +1,6 @@
#include <module.h>
// #define TRACE_REPORTS
#define TRACE_REPORTS
// TODO Key repeat not working on Qemu.
@ -421,8 +421,7 @@ void HIDDevice::ReportReceived(BitBuffer *buffer) {
#endif
bool mouseEvent = false;
int mouseXMovement = 0, mouseYMovement = 0;
int mouseScrollWheel = 0, mouseButtons = 0;
KMouseUpdateData mouse = {};
bool keyboardEvent = false;
uint16_t keysDown[32];
size_t keysDownCount = 0;
@ -491,23 +490,39 @@ void HIDDevice::ReportReceived(BitBuffer *buffer) {
bool handled = false;
if (item->application == HID_APPLICATION_MOUSE) {
// TODO Handle unsigned, absolute, and wrapping movements.
// TODO Handle absolute, and wrapping movements.
mouseEvent = true;
handled = true;
if (item->usage == HID_USAGE_X_AXIS) {
mouseXMovement = buffer->ReadSigned(item->bits);
if (item->flags & REPORT_ITEM_SIGNED) {
mouse.xMovement = buffer->ReadSigned(item->bits) * K_CURSOR_MOVEMENT_SCALE;
} else {
mouse.xMovement = buffer->ReadUnsigned(item->bits) * K_CURSOR_MOVEMENT_SCALE;
}
mouse.xIsAbsolute = !(item->flags & REPORT_ITEM_RELATIVE);
mouse.xFrom = item->logicalMinimum;
mouse.xTo = item->logicalMaximum;
} else if (item->usage == HID_USAGE_Y_AXIS) {
mouseYMovement = buffer->ReadSigned(item->bits);
if (item->flags & REPORT_ITEM_SIGNED) {
mouse.yMovement = buffer->ReadSigned(item->bits) * K_CURSOR_MOVEMENT_SCALE;
} else {
mouse.yMovement = buffer->ReadUnsigned(item->bits) * K_CURSOR_MOVEMENT_SCALE;
}
mouse.yIsAbsolute = !(item->flags & REPORT_ITEM_RELATIVE);
mouse.yFrom = item->logicalMinimum;
mouse.yTo = item->logicalMaximum;
} else if (item->usage == HID_USAGE_BUTTON_1) {
if (buffer->ReadUnsigned(item->bits)) mouseButtons |= 1 << 0;
if (buffer->ReadUnsigned(item->bits)) mouse.buttons |= 1 << 0;
} else if (item->usage == HID_USAGE_BUTTON_2) {
if (buffer->ReadUnsigned(item->bits)) mouseButtons |= 1 << 2;
if (buffer->ReadUnsigned(item->bits)) mouse.buttons |= 1 << 2;
} else if (item->usage == HID_USAGE_BUTTON_3) {
if (buffer->ReadUnsigned(item->bits)) mouseButtons |= 1 << 1;
if (buffer->ReadUnsigned(item->bits)) mouse.buttons |= 1 << 1;
} else if (item->usage == HID_USAGE_WHEEL) {
mouseScrollWheel = buffer->ReadSigned(item->bits);
mouse.yScroll = buffer->ReadSigned(item->bits) * K_CURSOR_MOVEMENT_SCALE;
} else {
handled = false;
}
@ -566,8 +581,7 @@ void HIDDevice::ReportReceived(BitBuffer *buffer) {
}
if (mouseEvent) {
KMouseUpdate(mouseXMovement * K_CURSOR_MOVEMENT_SCALE, mouseYMovement * K_CURSOR_MOVEMENT_SCALE,
mouseButtons, 0, mouseScrollWheel * ES_SCROLL_WHEEL_SCALE);
KMouseUpdate(&mouse);
}
if (keyboardEvent) {
@ -624,7 +638,6 @@ void HIDDevice::Initialise() {
if (!device->controlTransfer(device, 0x21, 0x0B /* set protocol */, 1 /* report protocol */,
device->interfaceDescriptor.interfaceIndex, nullptr, 0, K_ACCESS_WRITE, nullptr)) {
KernelLog(LOG_ERROR, "USBHID", "set protocol failure", "Could not switch to the report protocol.\n");
return;
}
// Get the report descriptor and parse it.

View File

@ -364,8 +364,16 @@ void KTimerRemove(KTimer *timer); // Timers with callbacks cannot be removed (it
// Window manager.
// ---------------------------------------------------------------------------------------------------------------
#define K_CURSOR_MOVEMENT_SCALE ES_SCROLL_WHEEL_SCALE
void KMouseUpdate(int32_t xMovement, int32_t yMovement, uint32_t buttons, int32_t scrollX = 0, int32_t scrollY = 0);
struct KMouseUpdateData {
int32_t xMovement, yMovement;
bool xIsAbsolute, yIsAbsolute;
int32_t xFrom, xTo, yFrom, yTo;
int32_t xScroll, yScroll;
uint32_t buttons;
};
#define K_CURSOR_MOVEMENT_SCALE (0x100)
void KMouseUpdate(const KMouseUpdateData *data);
void KKeyboardUpdate(uint16_t *keysDown, size_t keysDownCount);
void KKeyPress(uint32_t scancode);

View File

@ -1223,28 +1223,33 @@ void WindowManager::StartEyedrop(uintptr_t object, Window *avoid, uint32_t cance
KMutexRelease(&mutex);
}
void KMouseUpdate(int32_t xMovement, int32_t yMovement, uint32_t buttons, int32_t scrollX, int32_t scrollY) {
void KMouseUpdate(const KMouseUpdateData *data) {
if (!windowManager.initialised) {
return;
}
if (xMovement || yMovement) {
if (xMovement * xMovement + yMovement * yMovement < 10 && buttons != windowManager.lastButtons) {
KMutexAcquire(&windowManager.mutex);
if (data->xMovement || data->yMovement) {
int32_t xMovement = data->xMovement;
int32_t yMovement = data->yMovement;
// TODO Handling xIsAbsolute and yIsAbsolute
if (xMovement * xMovement + yMovement * yMovement < 10 && data->buttons != windowManager.lastButtons) {
// This seems to be movement noise generated when the buttons were pressed/released.
} else {
KMutexAcquire(&windowManager.mutex);
windowManager.MoveCursor(xMovement, yMovement);
KMutexRelease(&windowManager.mutex);
}
}
if (scrollX || scrollY) {
KMutexAcquire(&windowManager.mutex);
windowManager.ScrollWheel(scrollX, scrollY);
KMutexRelease(&windowManager.mutex);
if (data->xScroll || data->yScroll) {
windowManager.ScrollWheel(data->xScroll, data->yScroll);
}
windowManager.ClickCursor(buttons);
KMutexRelease(&windowManager.mutex);
windowManager.ClickCursor(data->buttons);
}
void KKeyPress(unsigned scancode) {