mirror of https://gitlab.com/nakst/essence
prep for absolute mouse movement
This commit is contained in:
parent
125cdfde4b
commit
7b53a6925d
|
@ -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_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
|
include desktop/icons.header
|
||||||
|
|
||||||
enum EsFatalError {
|
enum EsFatalError {
|
||||||
|
|
|
@ -198,7 +198,14 @@ uint16_t scancodeConversionTable2[] = {
|
||||||
|
|
||||||
void PS2MouseUpdated(EsGeneric _update) {
|
void PS2MouseUpdated(EsGeneric _update) {
|
||||||
PS2Update *update = (PS2Update *) _update.p;
|
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) {
|
void PS2KeyboardUpdated(EsGeneric _update) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include <module.h>
|
#include <module.h>
|
||||||
|
|
||||||
// #define TRACE_REPORTS
|
#define TRACE_REPORTS
|
||||||
|
|
||||||
// TODO Key repeat not working on Qemu.
|
// TODO Key repeat not working on Qemu.
|
||||||
|
|
||||||
|
@ -421,8 +421,7 @@ void HIDDevice::ReportReceived(BitBuffer *buffer) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool mouseEvent = false;
|
bool mouseEvent = false;
|
||||||
int mouseXMovement = 0, mouseYMovement = 0;
|
KMouseUpdateData mouse = {};
|
||||||
int mouseScrollWheel = 0, mouseButtons = 0;
|
|
||||||
bool keyboardEvent = false;
|
bool keyboardEvent = false;
|
||||||
uint16_t keysDown[32];
|
uint16_t keysDown[32];
|
||||||
size_t keysDownCount = 0;
|
size_t keysDownCount = 0;
|
||||||
|
@ -491,23 +490,39 @@ void HIDDevice::ReportReceived(BitBuffer *buffer) {
|
||||||
bool handled = false;
|
bool handled = false;
|
||||||
|
|
||||||
if (item->application == HID_APPLICATION_MOUSE) {
|
if (item->application == HID_APPLICATION_MOUSE) {
|
||||||
// TODO Handle unsigned, absolute, and wrapping movements.
|
// TODO Handle absolute, and wrapping movements.
|
||||||
|
|
||||||
mouseEvent = true;
|
mouseEvent = true;
|
||||||
handled = true;
|
handled = true;
|
||||||
|
|
||||||
if (item->usage == HID_USAGE_X_AXIS) {
|
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) {
|
} 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) {
|
} 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) {
|
} 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) {
|
} 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) {
|
} else if (item->usage == HID_USAGE_WHEEL) {
|
||||||
mouseScrollWheel = buffer->ReadSigned(item->bits);
|
mouse.yScroll = buffer->ReadSigned(item->bits) * K_CURSOR_MOVEMENT_SCALE;
|
||||||
} else {
|
} else {
|
||||||
handled = false;
|
handled = false;
|
||||||
}
|
}
|
||||||
|
@ -566,8 +581,7 @@ void HIDDevice::ReportReceived(BitBuffer *buffer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mouseEvent) {
|
if (mouseEvent) {
|
||||||
KMouseUpdate(mouseXMovement * K_CURSOR_MOVEMENT_SCALE, mouseYMovement * K_CURSOR_MOVEMENT_SCALE,
|
KMouseUpdate(&mouse);
|
||||||
mouseButtons, 0, mouseScrollWheel * ES_SCROLL_WHEEL_SCALE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keyboardEvent) {
|
if (keyboardEvent) {
|
||||||
|
@ -624,7 +638,6 @@ void HIDDevice::Initialise() {
|
||||||
if (!device->controlTransfer(device, 0x21, 0x0B /* set protocol */, 1 /* report protocol */,
|
if (!device->controlTransfer(device, 0x21, 0x0B /* set protocol */, 1 /* report protocol */,
|
||||||
device->interfaceDescriptor.interfaceIndex, nullptr, 0, K_ACCESS_WRITE, nullptr)) {
|
device->interfaceDescriptor.interfaceIndex, nullptr, 0, K_ACCESS_WRITE, nullptr)) {
|
||||||
KernelLog(LOG_ERROR, "USBHID", "set protocol failure", "Could not switch to the report protocol.\n");
|
KernelLog(LOG_ERROR, "USBHID", "set protocol failure", "Could not switch to the report protocol.\n");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the report descriptor and parse it.
|
// Get the report descriptor and parse it.
|
||||||
|
|
|
@ -364,8 +364,16 @@ void KTimerRemove(KTimer *timer); // Timers with callbacks cannot be removed (it
|
||||||
// Window manager.
|
// Window manager.
|
||||||
// ---------------------------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#define K_CURSOR_MOVEMENT_SCALE ES_SCROLL_WHEEL_SCALE
|
struct KMouseUpdateData {
|
||||||
void KMouseUpdate(int32_t xMovement, int32_t yMovement, uint32_t buttons, int32_t scrollX = 0, int32_t scrollY = 0);
|
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 KKeyboardUpdate(uint16_t *keysDown, size_t keysDownCount);
|
||||||
void KKeyPress(uint32_t scancode);
|
void KKeyPress(uint32_t scancode);
|
||||||
|
|
||||||
|
|
|
@ -1223,28 +1223,33 @@ void WindowManager::StartEyedrop(uintptr_t object, Window *avoid, uint32_t cance
|
||||||
KMutexRelease(&mutex);
|
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) {
|
if (!windowManager.initialised) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xMovement || yMovement) {
|
KMutexAcquire(&windowManager.mutex);
|
||||||
if (xMovement * xMovement + yMovement * yMovement < 10 && buttons != windowManager.lastButtons) {
|
|
||||||
|
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.
|
// This seems to be movement noise generated when the buttons were pressed/released.
|
||||||
} else {
|
} else {
|
||||||
KMutexAcquire(&windowManager.mutex);
|
|
||||||
windowManager.MoveCursor(xMovement, yMovement);
|
windowManager.MoveCursor(xMovement, yMovement);
|
||||||
KMutexRelease(&windowManager.mutex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scrollX || scrollY) {
|
if (data->xScroll || data->yScroll) {
|
||||||
KMutexAcquire(&windowManager.mutex);
|
windowManager.ScrollWheel(data->xScroll, data->yScroll);
|
||||||
windowManager.ScrollWheel(scrollX, scrollY);
|
|
||||||
KMutexRelease(&windowManager.mutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
windowManager.ClickCursor(buttons);
|
KMutexRelease(&windowManager.mutex);
|
||||||
|
|
||||||
|
windowManager.ClickCursor(data->buttons);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KKeyPress(unsigned scancode) {
|
void KKeyPress(unsigned scancode) {
|
||||||
|
|
Loading…
Reference in New Issue