Skip to content

Commit

Permalink
Allow for a greater range in mouse speeds
Browse files Browse the repository at this point in the history
Prior to this change, the virtual mouse update was restricted to
updating once every `mouse_delay` microseconds, and the allowed values
were a small fixed set. Some users reported that even at the highest
speed, the speed was slower than they were used to (with a high DPI
mouse).

This change modifies the speed calculation algorithm as follows. It
keeps the slowest speed to refresh the mouse every 70 ms. As the speed
increases, the refresh rate drops by 5 ms for every increment in speed,
until the refresh rate caps at once every 10 ms. Beyond that, a
multiplicative factor begins to take effect, with each speed increase
adding 0.25 to the factor. That is, speed 13 would multiply the axis
components by 1.25 _and_ refresh every 10 ms. Speed 14 would bump the
factor to 1.50, speed 15 to 1.75, and so on, until the factor tops out
at 6.0.
  • Loading branch information
nirenjan committed Sep 17, 2021
1 parent 06abc56 commit f490536
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 50 deletions.
41 changes: 24 additions & 17 deletions daemon/x52d_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,13 @@

// Mouse speed is the delay in microseconds between subsequent mouse reports
#define DEFAULT_MOUSE_DELAY 70000
#define MOUSE_DELAY_DELTA 10000
#define MOUSE_DELAY_DELTA 5000
#define MOUSE_DELAY_MIN 10000
#define MAX_MOUSE_MULT 5

volatile bool mouse_enabled = false;
volatile int mouse_delay = DEFAULT_MOUSE_DELAY;

#define MAX_MOUSE_SPEED 5
static const int mouse_speed_map[MAX_MOUSE_SPEED] = {
DEFAULT_MOUSE_DELAY,
DEFAULT_MOUSE_DELAY - MOUSE_DELAY_DELTA*1,
DEFAULT_MOUSE_DELAY - MOUSE_DELAY_DELTA*2,
DEFAULT_MOUSE_DELAY - MOUSE_DELAY_DELTA*3,
DEFAULT_MOUSE_DELAY - MOUSE_DELAY_DELTA*4,
};
volatile int mouse_mult = MOUSE_MULT_FACTOR;

void x52d_cfg_set_Mouse_Enabled(bool enabled)
{
Expand All @@ -43,13 +37,26 @@ void x52d_cfg_set_Mouse_Enabled(bool enabled)
void x52d_cfg_set_Mouse_Speed(int speed)
{
int new_delay;
if (speed >= 0 && speed < MAX_MOUSE_SPEED) {
new_delay = mouse_speed_map[speed];
PINELOG_DEBUG(_("Setting mouse speed to %d (delay %d ms)"),
speed, new_delay);
mouse_delay = new_delay;
} else {
int new_mult;

int max_base_speed = (DEFAULT_MOUSE_DELAY - MOUSE_DELAY_MIN) / MOUSE_DELAY_DELTA;
int max_speed = max_base_speed + MAX_MOUSE_MULT * MOUSE_MULT_FACTOR;

if (speed < 0 || speed > max_speed) {
PINELOG_INFO(_("Ignoring mouse speed %d outside supported range (0-%d)"),
speed, MAX_MOUSE_SPEED-1);
speed, max_speed);
return;
} else if (speed <= max_base_speed) {
new_delay = DEFAULT_MOUSE_DELAY - speed * MOUSE_DELAY_DELTA;
new_mult = MOUSE_MULT_FACTOR;
} else {
// speed between max_base_speed & max_speed
new_delay = MOUSE_DELAY_MIN;
new_mult = MOUSE_MULT_FACTOR + (speed - max_base_speed);
}

PINELOG_DEBUG(_("Setting mouse speed to %d (delay %d ms, multiplier %f)"),
speed, new_delay / 1000, new_mult / (double)MOUSE_MULT_FACTOR);
mouse_delay = new_delay;
mouse_mult = new_mult;
}
3 changes: 3 additions & 0 deletions daemon/x52d_mouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

extern volatile bool mouse_enabled;
extern volatile int mouse_delay;
extern volatile int mouse_mult;

#define MOUSE_MULT_FACTOR 4

void x52d_mouse_evdev_thread_control(bool enabled);
void x52d_mouse_evdev_init(void);
Expand Down
7 changes: 7 additions & 0 deletions daemon/x52d_mouse_evdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ static int report_axis(int axis, int index)
*/
axis_val = ((axis_val << 1) - 15) >> 1;

/*
* Factor in the multiplicative factor for the axis. This deliberately
* uses integer division, since the uinput event only accepts integers.
* For the speed purposes, this should be good enough.
*/
axis_val = (axis_val * mouse_mult) / MOUSE_MULT_FACTOR;

if (axis_val) {
rc = libevdev_uinput_write_event(mouse_uidev, EV_REL, axis, axis_val);
if (rc != 0) {
Expand Down
30 changes: 15 additions & 15 deletions po/x52pro-linux.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: x52pro-linux 0.2.2\n"
"Report-Msgid-Bugs-To: /~https://github.com/nirenjan/x52pro-linux/issues\n"
"POT-Creation-Date: 2021-09-15 09:25-0700\n"
"POT-Creation-Date: 2021-09-16 23:03-0700\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -142,11 +142,11 @@ msgstr ""
msgid "Unknown LED state %d"
msgstr ""

#: libx52/x52_stringify.c:47 daemon/x52d_clock.c:28 daemon/x52d_mouse.c:37
#: libx52/x52_stringify.c:47 daemon/x52d_clock.c:28 daemon/x52d_mouse.c:31
msgid "off"
msgstr ""

#: libx52/x52_stringify.c:48 daemon/x52d_clock.c:28 daemon/x52d_mouse.c:37
#: libx52/x52_stringify.c:48 daemon/x52d_clock.c:28 daemon/x52d_mouse.c:31
msgid "on"
msgstr ""

Expand Down Expand Up @@ -735,19 +735,19 @@ msgstr ""
msgid "Shutting down X52 I/O driver thread"
msgstr ""

#: daemon/x52d_mouse.c:36
#: daemon/x52d_mouse.c:30
#, c-format
msgid "Setting mouse enable to %s"
msgstr ""

#: daemon/x52d_mouse.c:48
#: daemon/x52d_mouse.c:46
#, c-format
msgid "Setting mouse speed to %d (delay %d ms)"
msgid "Ignoring mouse speed %d outside supported range (0-%d)"
msgstr ""

#: daemon/x52d_mouse.c:52
#: daemon/x52d_mouse.c:58
#, c-format
msgid "Ignoring mouse speed %d outside supported range (0-%d)"
msgid "Setting mouse speed to %d (delay %d ms, multiplier %f)"
msgstr ""

#: daemon/x52d_mouse_evdev.c:43
Expand All @@ -760,33 +760,33 @@ msgstr ""
msgid "Error writing mouse wheel event %d"
msgstr ""

#: daemon/x52d_mouse_evdev.c:95
#: daemon/x52d_mouse_evdev.c:102
#, c-format
msgid "Error writing mouse axis event (axis %d, value %d)"
msgstr ""

#: daemon/x52d_mouse_evdev.c:108
#: daemon/x52d_mouse_evdev.c:115
msgid "Error writing mouse sync event"
msgstr ""

#: daemon/x52d_mouse_evdev.c:127
#: daemon/x52d_mouse_evdev.c:134
msgid "Starting X52 virtual mouse driver thread"
msgstr ""

#: daemon/x52d_mouse_evdev.c:150
#: daemon/x52d_mouse_evdev.c:157
#, c-format
msgid "Error %d initializing mouse thread: %s"
msgstr ""

#: daemon/x52d_mouse_evdev.c:157
#: daemon/x52d_mouse_evdev.c:164
msgid "Shutting down X52 virtual mouse driver thread"
msgstr ""

#: daemon/x52d_mouse_evdev.c:164
#: daemon/x52d_mouse_evdev.c:171
msgid "Virtual mouse not created. Ignoring thread state change"
msgstr ""

#: daemon/x52d_mouse_evdev.c:225
#: daemon/x52d_mouse_evdev.c:232
#, c-format
msgid "Error %d creating X52 virtual mouse: %s"
msgstr ""
36 changes: 18 additions & 18 deletions po/xx_PL.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: x52pro-linux 0.2.1\n"
"Report-Msgid-Bugs-To: /~https://github.com/nirenjan/x52pro-linux/issues\n"
"POT-Creation-Date: 2021-09-15 09:25-0700\n"
"PO-Revision-Date: 2021-09-15 00:12-0700\n"
"POT-Creation-Date: 2021-09-16 23:03-0700\n"
"PO-Revision-Date: 2021-09-16 23:04-0700\n"
"Last-Translator: Nirenjan Krishnan <nirenjan@gmail.com>\n"
"Language-Team: Dummy Language for testing i18n\n"
"Language: xx_PL\n"
Expand Down Expand Up @@ -142,11 +142,11 @@ msgstr "YYay-MMay-DDay"
msgid "Unknown LED state %d"
msgstr "Unknownay EDLay atestay %d"

#: libx52/x52_stringify.c:47 daemon/x52d_clock.c:28 daemon/x52d_mouse.c:37
#: libx52/x52_stringify.c:47 daemon/x52d_clock.c:28 daemon/x52d_mouse.c:31
msgid "off"
msgstr "offay"

#: libx52/x52_stringify.c:48 daemon/x52d_clock.c:28 daemon/x52d_mouse.c:37
#: libx52/x52_stringify.c:48 daemon/x52d_clock.c:28 daemon/x52d_mouse.c:31
msgid "on"
msgstr "onay"

Expand Down Expand Up @@ -784,21 +784,21 @@ msgstr "Erroray %d initializingay I/O iverdray eadthray: %s"
msgid "Shutting down X52 I/O driver thread"
msgstr "Uttingshay ownday X52 I/O iverdray eadthray"

#: daemon/x52d_mouse.c:36
#: daemon/x52d_mouse.c:30
#, c-format
msgid "Setting mouse enable to %s"
msgstr "Ettingsay ousemay enableay otay %s"

#: daemon/x52d_mouse.c:48
#, c-format
msgid "Setting mouse speed to %d (delay %d ms)"
msgstr "Ettingsay ousemay eedspay otay %d (elayday %d ms)"

#: daemon/x52d_mouse.c:52
#: daemon/x52d_mouse.c:46
#, c-format
msgid "Ignoring mouse speed %d outside supported range (0-%d)"
msgstr "Ignoringay ousemay eedspay %d outsideay upportedsay angeray (0-%d)"

#: daemon/x52d_mouse.c:58
#, c-format
msgid "Setting mouse speed to %d (delay %d ms, multiplier %f)"
msgstr "Ettingsay ousemay eedspay otay %d (elayday %d ms, ultipliermay %f)"

#: daemon/x52d_mouse_evdev.c:43
#, c-format
msgid "Error writing mouse button event (button %d, state %d)"
Expand All @@ -809,33 +809,33 @@ msgstr "Erroray itingwray ousemay uttonbay eventay (uttonbay %d, atestay %d)"
msgid "Error writing mouse wheel event %d"
msgstr "Erroray itingwray ousemay eelwhay eventay %d"

#: daemon/x52d_mouse_evdev.c:95
#: daemon/x52d_mouse_evdev.c:102
#, c-format
msgid "Error writing mouse axis event (axis %d, value %d)"
msgstr "Erroray itingwray ousemay axisay eventay (axisay %d, aluevay %d)"

#: daemon/x52d_mouse_evdev.c:108
#: daemon/x52d_mouse_evdev.c:115
msgid "Error writing mouse sync event"
msgstr "Erroray itingwray ousemay yncsay eventay"

#: daemon/x52d_mouse_evdev.c:127
#: daemon/x52d_mouse_evdev.c:134
msgid "Starting X52 virtual mouse driver thread"
msgstr "Artingstay X52 irtualvay ousemay iverdray eadthray"

#: daemon/x52d_mouse_evdev.c:150
#: daemon/x52d_mouse_evdev.c:157
#, c-format
msgid "Error %d initializing mouse thread: %s"
msgstr "Erroray %d initializingay ousemay eadthray: %s"

#: daemon/x52d_mouse_evdev.c:157
#: daemon/x52d_mouse_evdev.c:164
msgid "Shutting down X52 virtual mouse driver thread"
msgstr "Uttingshay ownday X52 irtualvay ousemay iverdray eadthray"

#: daemon/x52d_mouse_evdev.c:164
#: daemon/x52d_mouse_evdev.c:171
msgid "Virtual mouse not created. Ignoring thread state change"
msgstr "Irtualvay ousemay otnay eatedcray. Ignoringa eadthray atestay angechay"

#: daemon/x52d_mouse_evdev.c:225
#: daemon/x52d_mouse_evdev.c:232
#, c-format
msgid "Error %d creating X52 virtual mouse: %s"
msgstr "Erroray %d eatingcray X52 irtualvay ousemay: %s"

0 comments on commit f490536

Please sign in to comment.