aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fastmouse.patch92
-rw-r--r--src/hid-input.c84
2 files changed, 117 insertions, 59 deletions
diff --git a/fastmouse.patch b/fastmouse.patch
index 55dd0b5..6670742 100644
--- a/fastmouse.patch
+++ b/fastmouse.patch
@@ -1,5 +1,5 @@
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
-index 9d80635a91eb..7cd438cbb76c 100644
+index 9d80635a91eb..8c8a7483261f 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -14,6 +14,7 @@
@@ -10,19 +10,21 @@ index 9d80635a91eb..7cd438cbb76c 100644
#include <linux/slab.h>
#include <linux/kernel.h>
-@@ -1505,6 +1506,63 @@ static void hid_report_set_tool(struct hid_report *report, struct input_dev *inp
+@@ -1505,6 +1506,87 @@ static void hid_report_set_tool(struct hid_report *report, struct input_dev *inp
report->tool = new_tool;
}
-+
+struct fastmouse_state {
+ int division;
-+ int x, y;
++ long x, y;
++ int rise, run;
+};
+static struct fastmouse_state fastmouse = {
+ .division = 1,
+ .x = 0,
+ .y = 0,
++ .rise = 0,
++ .run = INT_MAX,
+};
+
+static int set_division(const char *val, const struct kernel_param *kp) {
@@ -30,12 +32,8 @@ index 9d80635a91eb..7cd438cbb76c 100644
+ if (ret != 0 || fastmouse.division <= 0) {
+ return -EINVAL;
+ }
-+ // Modifying divison should reset accumlated events.
-+ fastmouse.x = fastmouse.y = 0;
-+
+ return ret;
+}
-+
+static const struct kernel_param_ops division_ops = {
+ .set = set_division,
+ .get = param_get_int,
@@ -43,42 +41,74 @@ index 9d80635a91eb..7cd438cbb76c 100644
+module_param_cb(division, &division_ops, &fastmouse.division, 0664);
+MODULE_PARM_DESC(division, "Mouse movement division amount (default: 1)");
+
-+static int apply_fastmouse(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value) {
-+ if (hid->type != HID_TYPE_USBMOUSE) {
-+ return value;
++static int set_rise(const char *val, const struct kernel_param *kp) {
++ const int ret = kstrtoint(val, 0, &fastmouse.rise);
++ if (ret != 0) {
++ return -EINVAL;
+ }
++ return ret;
++}
++static const struct kernel_param_ops rise_ops = {
++ .set = set_rise,
++ .get = param_get_int,
++};
++module_param_cb(rise, &rise_ops, &fastmouse.rise, 0664);
++MODULE_PARM_DESC(rise, "Mouse movement rise amount (default: 0)");
+
-+ if (usage->type != EV_REL) {
-+ return value;
++static int set_run(const char *val, const struct kernel_param *kp) {
++ const int ret = kstrtoint(val, 0, &fastmouse.run);
++ if (ret != 0) {
++ return -EINVAL;
+ }
++ return ret;
++}
++static const struct kernel_param_ops run_ops = {
++ .set = set_run,
++ .get = param_get_int,
++};
++module_param_cb(run, &run_ops, &fastmouse.run, 0664);
++MODULE_PARM_DESC(run, "Mouse movement run amount (default: INT_MAX)");
++
++static void fastmouse_handle_motion(const long in_x, const long in_y) {
++ const long rise = fastmouse.rise / fastmouse.division;
++ const long run = fastmouse.run / fastmouse.division;
++ fastmouse.x += in_x * run - in_y * rise;
++ fastmouse.y += in_x * rise + in_y * run;
++}
+
-+ int* target;
-+ switch (usage->code) {
-+ case REL_X:
-+ target = &fastmouse.x;
-+ break;
-+ case REL_Y:
-+ target = &fastmouse.y;
-+ break;
-+ default:
-+ return value;
-+ };
++static void input_event_fastmouse(struct input_dev *input, const unsigned int type, const unsigned int code, __s32 value) {
++ const long in_x = (code == REL_X) * value;
++ const long in_y = (code == REL_Y) * value;
+
-+ *target += value;
-+ const int result = *target / fastmouse.division;
-+ *target %= fastmouse.division;
++ fastmouse_handle_motion(in_x, in_y);
+
-+ return result;
++ const long emit_x = fastmouse.x / INT_MAX;
++ if (emit_x != 0) {
++ input_event(input, type, REL_X, emit_x);
++ }
++ const long emit_y = fastmouse.y / INT_MAX;
++ if (emit_y != 0) {
++ input_event(input, type, REL_Y, emit_y);
++ }
++
++ fastmouse.x %= INT_MAX;
++ fastmouse.y %= INT_MAX;
+}
+
void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value)
{
struct input_dev *input;
-@@ -1713,6 +1771,7 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
+@@ -1713,7 +1795,12 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
(!test_bit(usage->code, input->key)) == value)
input_event(input, EV_MSC, MSC_SCAN, usage->hid);
-+ value = apply_fastmouse(hid, field, usage, value);
- input_event(input, usage->type, usage->code, value);
+- input_event(input, usage->type, usage->code, value);
++ if (hid->type == HID_TYPE_USBMOUSE && usage->type == EV_REL) {
++ input_event_fastmouse(input, usage->type, usage->code, value);
++ } else {
++ input_event(input, usage->type, usage->code, value);
++ }
++
if ((field->flags & HID_MAIN_ITEM_RELATIVE) &&
+ usage->type == EV_KEY && value) {
diff --git a/src/hid-input.c b/src/hid-input.c
index 7cd438c..8c8a748 100644
--- a/src/hid-input.c
+++ b/src/hid-input.c
@@ -1506,15 +1506,17 @@ static void hid_report_set_tool(struct hid_report *report, struct input_dev *inp
report->tool = new_tool;
}
-
struct fastmouse_state {
int division;
- int x, y;
+ long x, y;
+ int rise, run;
};
static struct fastmouse_state fastmouse = {
.division = 1,
.x = 0,
.y = 0,
+ .rise = 0,
+ .run = INT_MAX,
};
static int set_division(const char *val, const struct kernel_param *kp) {
@@ -1522,12 +1524,8 @@ static int set_division(const char *val, const struct kernel_param *kp) {
if (ret != 0 || fastmouse.division <= 0) {
return -EINVAL;
}
- // Modifying divison should reset accumlated events.
- fastmouse.x = fastmouse.y = 0;
-
return ret;
}
-
static const struct kernel_param_ops division_ops = {
.set = set_division,
.get = param_get_int,
@@ -1535,32 +1533,58 @@ static const struct kernel_param_ops division_ops = {
module_param_cb(division, &division_ops, &fastmouse.division, 0664);
MODULE_PARM_DESC(division, "Mouse movement division amount (default: 1)");
-static int apply_fastmouse(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value) {
- if (hid->type != HID_TYPE_USBMOUSE) {
- return value;
+static int set_rise(const char *val, const struct kernel_param *kp) {
+ const int ret = kstrtoint(val, 0, &fastmouse.rise);
+ if (ret != 0) {
+ return -EINVAL;
}
+ return ret;
+}
+static const struct kernel_param_ops rise_ops = {
+ .set = set_rise,
+ .get = param_get_int,
+};
+module_param_cb(rise, &rise_ops, &fastmouse.rise, 0664);
+MODULE_PARM_DESC(rise, "Mouse movement rise amount (default: 0)");
- if (usage->type != EV_REL) {
- return value;
+static int set_run(const char *val, const struct kernel_param *kp) {
+ const int ret = kstrtoint(val, 0, &fastmouse.run);
+ if (ret != 0) {
+ return -EINVAL;
}
+ return ret;
+}
+static const struct kernel_param_ops run_ops = {
+ .set = set_run,
+ .get = param_get_int,
+};
+module_param_cb(run, &run_ops, &fastmouse.run, 0664);
+MODULE_PARM_DESC(run, "Mouse movement run amount (default: INT_MAX)");
+
+static void fastmouse_handle_motion(const long in_x, const long in_y) {
+ const long rise = fastmouse.rise / fastmouse.division;
+ const long run = fastmouse.run / fastmouse.division;
+ fastmouse.x += in_x * run - in_y * rise;
+ fastmouse.y += in_x * rise + in_y * run;
+}
- int* target;
- switch (usage->code) {
- case REL_X:
- target = &fastmouse.x;
- break;
- case REL_Y:
- target = &fastmouse.y;
- break;
- default:
- return value;
- };
+static void input_event_fastmouse(struct input_dev *input, const unsigned int type, const unsigned int code, __s32 value) {
+ const long in_x = (code == REL_X) * value;
+ const long in_y = (code == REL_Y) * value;
- *target += value;
- const int result = *target / fastmouse.division;
- *target %= fastmouse.division;
+ fastmouse_handle_motion(in_x, in_y);
- return result;
+ const long emit_x = fastmouse.x / INT_MAX;
+ if (emit_x != 0) {
+ input_event(input, type, REL_X, emit_x);
+ }
+ const long emit_y = fastmouse.y / INT_MAX;
+ if (emit_y != 0) {
+ input_event(input, type, REL_Y, emit_y);
+ }
+
+ fastmouse.x %= INT_MAX;
+ fastmouse.y %= INT_MAX;
}
void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value)
@@ -1771,8 +1795,12 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
(!test_bit(usage->code, input->key)) == value)
input_event(input, EV_MSC, MSC_SCAN, usage->hid);
- value = apply_fastmouse(hid, field, usage, value);
- input_event(input, usage->type, usage->code, value);
+ if (hid->type == HID_TYPE_USBMOUSE && usage->type == EV_REL) {
+ input_event_fastmouse(input, usage->type, usage->code, value);
+ } else {
+ input_event(input, usage->type, usage->code, value);
+ }
+
if ((field->flags & HID_MAIN_ITEM_RELATIVE) &&
usage->type == EV_KEY && value) {