diff --git a/desktop/os.header b/desktop/os.header index 38b5587..680a74a 100644 --- a/desktop/os.header +++ b/desktop/os.header @@ -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 { diff --git a/drivers/ps2.cpp b/drivers/ps2.cpp index 0a4b24b..c358bd4 100644 --- a/drivers/ps2.cpp +++ b/drivers/ps2.cpp @@ -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) { diff --git a/drivers/usb_hid.cpp b/drivers/usb_hid.cpp index bdb3753..a25f7f9 100644 --- a/drivers/usb_hid.cpp +++ b/drivers/usb_hid.cpp @@ -1,6 +1,6 @@ #include -// #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. diff --git a/kernel/module.h b/kernel/module.h index 2276704..c9aa216 100644 --- a/kernel/module.h +++ b/kernel/module.h @@ -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); diff --git a/kernel/windows.cpp b/kernel/windows.cpp index 4bd47f1..7f7d37a 100644 --- a/kernel/windows.cpp +++ b/kernel/windows.cpp @@ -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) {