summaryrefslogtreecommitdiff
path: root/driver/driver.cpp
diff options
context:
space:
mode:
authora1xd <[email protected]>2021-01-07 12:52:51 -0500
committera1xd <[email protected]>2021-01-07 12:52:51 -0500
commitbe22e78f96fd34245bdad03b68cfd4e60ded1ba6 (patch)
tree3418a80ed7a4bc2857354faf328809239ba5d18e /driver/driver.cpp
parentget hwid when adding device (diff)
downloadrawaccel-be22e78f96fd34245bdad03b68cfd4e60ded1ba6.tar.xz
rawaccel-be22e78f96fd34245bdad03b68cfd4e60ded1ba6.zip
refactor main callback
check for empty input as suggested by @aroidzap
Diffstat (limited to 'driver/driver.cpp')
-rw-r--r--driver/driver.cpp51
1 files changed, 23 insertions, 28 deletions
diff --git a/driver/driver.cpp b/driver/driver.cpp
index e3ffb4d..4f108bd 100644
--- a/driver/driver.cpp
+++ b/driver/driver.cpp
@@ -54,20 +54,18 @@ Arguments:
WDFDEVICE hDevice = WdfWdmDeviceGetWdfDeviceHandle(DeviceObject);
PDEVICE_EXTENSION devExt = FilterGetData(hDevice);
- bool devMatch = true;
- if (global.args.device_hw_id[0] != 0) {
- devMatch = wcsncmp(devExt->hwid, global.args.device_hw_id, MAX_HWID_LEN) == 0;
- }
+ auto num_packets = InputDataEnd - InputDataStart;
+
+ bool any = num_packets > 0;
+ bool rel_move = !(InputDataStart->Flags & MOUSE_MOVE_ABSOLUTE);
+ bool dev_match = global.args.device_hw_id[0] == 0 ||
+ wcsncmp(devExt->hwid, global.args.device_hw_id, MAX_HWID_LEN) == 0;
- if (!(InputDataStart->Flags & MOUSE_MOVE_ABSOLUTE)) {
- auto num_packets = InputDataEnd - InputDataStart;
-
+ if (any && rel_move && dev_match) {
// if IO is backed up to the point where we get more than 1 packet here
// then applying accel is pointless as we can't get an accurate timing
bool enable_accel = num_packets == 1;
- vec2d carry = devExt->carry;
-
auto it = InputDataStart;
do {
vec2d input = {
@@ -75,39 +73,36 @@ Arguments:
static_cast<double>(it->LastY)
};
- if (devMatch) {
- global.modifier.apply_rotation(input);
+ global.modifier.apply_rotation(input);
- if (enable_accel) {
- auto time_supplier = [=] {
- counter_t now = KeQueryPerformanceCounter(NULL).QuadPart;
- counter_t ticks = now - devExt->counter;
- devExt->counter = now;
- milliseconds time = ticks * global.tick_interval;
- return clampsd(time, global.args.time_min, 100);
- };
+ if (enable_accel) {
+ auto time_supplier = [=] {
+ counter_t now = KeQueryPerformanceCounter(NULL).QuadPart;
+ counter_t ticks = now - devExt->counter;
+ devExt->counter = now;
+ milliseconds time = ticks * global.tick_interval;
+ return clampsd(time, global.args.time_min, 100);
+ };
- global.modifier.apply_acceleration(input, time_supplier);
- }
-
- global.modifier.apply_sensitivity(input);
+ global.modifier.apply_acceleration(input, time_supplier);
}
- double carried_result_x = input.x + carry.x;
- double carried_result_y = input.y + carry.y;
+ global.modifier.apply_sensitivity(input);
+
+ double carried_result_x = input.x + devExt->carry.x;
+ double carried_result_y = input.y + devExt->carry.y;
LONG out_x = static_cast<LONG>(carried_result_x);
LONG out_y = static_cast<LONG>(carried_result_y);
- carry.x = carried_result_x - out_x;
- carry.y = carried_result_y - out_y;
+ devExt->carry.x = carried_result_x - out_x;
+ devExt->carry.y = carried_result_y - out_y;
it->LastX = out_x;
it->LastY = out_y;
} while (++it != InputDataEnd);
- devExt->carry = carry;
}
(*(PSERVICE_CALLBACK_ROUTINE)devExt->UpperConnectData.ClassService)(