Move arrays into mouse handler file

mouse-isometric-mode
nirenjan 2026-04-01 14:27:00 -07:00
parent e810f43512
commit 6b94d0653e
6 changed files with 75 additions and 76 deletions

View File

@ -60,7 +60,7 @@ test('daemon-communication', files('test_daemon_comm.py')[0],
x52d_mouse_test_sources = ['x52d_mouse_test.c', 'x52d_mouse.c'] x52d_mouse_test_sources = ['x52d_mouse_test.c', 'x52d_mouse.c']
x52d_mouse_test = executable('x52d-mouse-test', x52d_mouse_test_sources, x52d_mouse_test = executable('x52d-mouse-test', x52d_mouse_test_sources,
include_directories: includes, include_directories: includes,
dependencies: [dep_pinelog, dep_cmocka, dep_intl]) dependencies: [dep_pinelog, dep_cmocka, dep_intl, dep_math])
test('x52d-mouse-test', x52d_mouse_test, protocol: 'tap') test('x52d-mouse-test', x52d_mouse_test, protocol: 'tap')

View File

@ -26,18 +26,10 @@
#define MIN_SENSITIVITY 10 #define MIN_SENSITIVITY 10
#define MAX_SENSITIVITY 500 #define MAX_SENSITIVITY 500
static const double MOUSE_CURVE_FACTORS[5] = {
1.0, 1.2, 1.5, 1.8, 2.2
};
static const double MOUSE_DEADZONES[12] = {
0.0, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5
};
volatile int mouse_scroll_dir = 1; volatile int mouse_scroll_dir = 1;
volatile bool mouse_isometric_mode = false; volatile bool mouse_isometric_mode = false;
volatile double mouse_curve_factor = MOUSE_CURVE_FACTORS[2]; // default volatile int mouse_curve_factor = 3;
volatile double mouse_deadzone = MOUSE_DEADZONES[0]; volatile int mouse_deadzone_factor = 0;
volatile int mouse_sensitivity = 0; volatile int mouse_sensitivity = 0;
static int clamp_int(const char *description, int value, int min, int max) static int clamp_int(const char *description, int value, int min, int max)
@ -127,17 +119,14 @@ void x52d_cfg_set_Mouse_Sensitivity(int factor)
void x52d_cfg_set_Mouse_CurveFactor(int factor) void x52d_cfg_set_Mouse_CurveFactor(int factor)
{ {
// Factor ranges from 1-5, clamp it in this range // Factor ranges from 1-5, clamp it in this range
factor = clamp_int(_("curve factor"), factor, 1, 5); // Shift by 1 so it uses the correct index
mouse_curve_factor = clamp_int(_("curve factor"), factor, 1, 5) - 1;
mouse_curve_factor = MOUSE_CURVE_FACTORS[factor-1];
PINELOG_DEBUG(_("Setting mouse curve factor to %f"), mouse_curve_factor); PINELOG_DEBUG(_("Setting mouse curve factor to %f"), mouse_curve_factor);
} }
void x52d_cfg_set_Mouse_Deadzone(int factor) void x52d_cfg_set_Mouse_Deadzone(int factor)
{ {
// Factor ranges from 0-12, clamp it in this range // Factor ranges from 0-12, clamp it in this range
factor = clamp_int(_("deadzone factor"), factor, 0, 11); mouse_deadzone_factor = clamp_int(_("deadzone factor"), factor, 0, 11);
PINELOG_DEBUG(_("Setting mouse deadzone to %f"), mouse_deadzone_factor);
mouse_deadzone = MOUSE_DEADZONES[factor];
PINELOG_DEBUG(_("Setting mouse deadzone to %f"), mouse_deadzone);
} }

View File

@ -14,8 +14,8 @@
extern volatile bool mouse_isometric_mode; extern volatile bool mouse_isometric_mode;
extern volatile int mouse_scroll_dir; extern volatile int mouse_scroll_dir;
extern volatile double mouse_curve_factor; extern volatile int mouse_curve_factor;
extern volatile double mouse_deadzone; extern volatile int mouse_deadzone_factor;
extern volatile int mouse_sensitivity; extern volatile int mouse_sensitivity;
void x52d_mouse_thread_control(bool enabled); void x52d_mouse_thread_control(bool enabled);

View File

@ -91,6 +91,14 @@ static inline int fsgn(double f)
return (f >= 0 ? 1 : -1); return (f >= 0 ? 1 : -1);
} }
static const double MOUSE_CURVE_FACTORS[5] = {
1.0, 1.2, 1.5, 1.8, 2.2
};
static const double MOUSE_DEADZONES[12] = {
0.0, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5
};
static int report_axis(void) static int report_axis(void)
{ {
#define MAX_TICK_SPEED 250.0 #define MAX_TICK_SPEED 250.0
@ -104,9 +112,10 @@ static int report_axis(void)
/* Calculate radial magnitude */ /* Calculate radial magnitude */
double mag = sqrt((double)(dx * dx + dy * dy)); double mag = sqrt((double)(dx * dx + dy * dy));
double cfg_deadzone = MOUSE_DEADZONES[mouse_deadzone_factor];
/* Radial deadzone check */ /* Radial deadzone check */
if (mag <= mouse_deadzone) { if (mag <= cfg_deadzone) {
accum_x = 0.0; accum_x = 0.0;
accum_y = 0.0; accum_y = 0.0;
return 0; return 0;
@ -114,15 +123,16 @@ static int report_axis(void)
/* Calculate gain */ /* Calculate gain */
double gain = (double)mouse_sensitivity / 100.0; double gain = (double)mouse_sensitivity / 100.0;
double exponent = MOUSE_CURVE_FACTORS[mouse_curve_factor];
/* Normalize magnitude */ /* Normalize magnitude */
double adj_mag = mag - mouse_deadzone; double adj_mag = mag - cfg_deadzone;
double out_x = 0.0; double out_x = 0.0;
double out_y = 0.0; double out_y = 0.0;
if (mouse_isometric_mode) { if (mouse_isometric_mode) {
/* Isometric mode: speed is a function of total distance */ /* Isometric mode: speed is a function of total distance */
double speed = gain * pow(adj_mag, mouse_curve_factor); double speed = gain * pow(adj_mag, exponent);
/* Clamp total speed before breaking into components */ /* Clamp total speed before breaking into components */
if (speed > MAX_TICK_SPEED) { if (speed > MAX_TICK_SPEED) {
@ -138,8 +148,8 @@ static int report_axis(void)
double cur_x = dx * ratio; double cur_x = dx * ratio;
double cur_y = dy * ratio; double cur_y = dy * ratio;
out_x = fsgn(cur_x) * gain * pow(fabs(cur_x), mouse_curve_factor); out_x = fsgn(cur_x) * gain * pow(fabs(cur_x), exponent);
out_y = fsgn(cur_y) * gain * pow(fabs(cur_y), mouse_curve_factor); out_y = fsgn(cur_y) * gain * pow(fabs(cur_y), exponent);
/* Clamp individual axis speeds */ /* Clamp individual axis speeds */
if (fabs(out_x) > MAX_TICK_SPEED) { if (fabs(out_x) > MAX_TICK_SPEED) {

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: libx52 0.3.3\n" "Project-Id-Version: libx52 0.3.3\n"
"Report-Msgid-Bugs-To: https://github.com/nirenjan/libx52/issues\n" "Report-Msgid-Bugs-To: https://github.com/nirenjan/libx52/issues\n"
"POT-Creation-Date: 2026-04-01 14:00-0700\n" "POT-Creation-Date: 2026-04-01 14:23-0700\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -142,13 +142,13 @@ msgstr ""
msgid "Unknown LED state %d" msgid "Unknown LED state %d"
msgstr "" msgstr ""
#: libx52/x52_stringify.c:47 daemon/x52d_clock.c:29 daemon/x52d_mouse.c:63 #: libx52/x52_stringify.c:47 daemon/x52d_clock.c:29 daemon/x52d_mouse.c:55
#: daemon/x52d_mouse.c:103 daemon/x52d_mouse.c:115 #: daemon/x52d_mouse.c:95 daemon/x52d_mouse.c:107
msgid "off" msgid "off"
msgstr "" msgstr ""
#: libx52/x52_stringify.c:48 daemon/x52d_clock.c:29 daemon/x52d_mouse.c:63 #: libx52/x52_stringify.c:48 daemon/x52d_clock.c:29 daemon/x52d_mouse.c:55
#: daemon/x52d_mouse.c:103 daemon/x52d_mouse.c:115 #: daemon/x52d_mouse.c:95 daemon/x52d_mouse.c:107
msgid "on" msgid "on"
msgstr "" msgstr ""
@ -864,64 +864,64 @@ msgstr ""
msgid "Shutting down X52 I/O driver thread" msgid "Shutting down X52 I/O driver thread"
msgstr "" msgstr ""
#: daemon/x52d_mouse.c:46 daemon/x52d_mouse.c:52 #: daemon/x52d_mouse.c:38 daemon/x52d_mouse.c:44
#, c-format #, c-format
msgid "Clamping %s value %d to range [%d..%d]" msgid "Clamping %s value %d to range [%d..%d]"
msgstr "" msgstr ""
#: daemon/x52d_mouse.c:62 #: daemon/x52d_mouse.c:54
#, c-format #, c-format
msgid "Setting mouse enable to %s" msgid "Setting mouse enable to %s"
msgstr "" msgstr ""
#: daemon/x52d_mouse.c:79 #: daemon/x52d_mouse.c:71
msgid "" msgid ""
"Config option 'mouse.speed' is DEPRECATED. Please use 'mouse.sensitivity' " "Config option 'mouse.speed' is DEPRECATED. Please use 'mouse.sensitivity' "
"instead" "instead"
msgstr "" msgstr ""
#: daemon/x52d_mouse.c:94 #: daemon/x52d_mouse.c:86
#, c-format #, c-format
msgid "Migrating legacy mouse speed '%d' to sensitivity '%d%%'" msgid "Migrating legacy mouse speed '%d' to sensitivity '%d%%'"
msgstr "" msgstr ""
#: daemon/x52d_mouse.c:96 #: daemon/x52d_mouse.c:88
msgid "speed -> sensitivity" msgid "speed -> sensitivity"
msgstr "" msgstr ""
#: daemon/x52d_mouse.c:102 #: daemon/x52d_mouse.c:94
#, c-format #, c-format
msgid "Setting mouse reverse scroll to %s" msgid "Setting mouse reverse scroll to %s"
msgstr "" msgstr ""
#: daemon/x52d_mouse.c:114 #: daemon/x52d_mouse.c:106
#, c-format #, c-format
msgid "Setting mouse isometric mode to %s" msgid "Setting mouse isometric mode to %s"
msgstr "" msgstr ""
#: daemon/x52d_mouse.c:121 #: daemon/x52d_mouse.c:113
msgid "sensitivity" msgid "sensitivity"
msgstr "" msgstr ""
#: daemon/x52d_mouse.c:124 #: daemon/x52d_mouse.c:116
#, c-format #, c-format
msgid "Setting mouse sensitivity to %d%%" msgid "Setting mouse sensitivity to %d%%"
msgstr "" msgstr ""
#: daemon/x52d_mouse.c:130 #: daemon/x52d_mouse.c:123
msgid "curve factor" msgid "curve factor"
msgstr "" msgstr ""
#: daemon/x52d_mouse.c:133 #: daemon/x52d_mouse.c:124
#, c-format #, c-format
msgid "Setting mouse curve factor to %f" msgid "Setting mouse curve factor to %f"
msgstr "" msgstr ""
#: daemon/x52d_mouse.c:139 #: daemon/x52d_mouse.c:130
msgid "deadzone factor" msgid "deadzone factor"
msgstr "" msgstr ""
#: daemon/x52d_mouse.c:142 #: daemon/x52d_mouse.c:131
#, c-format #, c-format
msgid "Setting mouse deadzone to %f" msgid "Setting mouse deadzone to %f"
msgstr "" msgstr ""
@ -936,33 +936,33 @@ msgstr ""
msgid "Error writing mouse wheel event %d" msgid "Error writing mouse wheel event %d"
msgstr "" msgstr ""
#: daemon/x52d_mouse_handler.c:175 #: daemon/x52d_mouse_handler.c:185
#, c-format #, c-format
msgid "Error %d writing mouse axis event (dx %d, dy %d)" msgid "Error %d writing mouse axis event (dx %d, dy %d)"
msgstr "" msgstr ""
#: daemon/x52d_mouse_handler.c:187 #: daemon/x52d_mouse_handler.c:197
msgid "Error writing mouse sync event" msgid "Error writing mouse sync event"
msgstr "" msgstr ""
#: daemon/x52d_mouse_handler.c:206 #: daemon/x52d_mouse_handler.c:216
msgid "Starting X52 virtual mouse driver thread" msgid "Starting X52 virtual mouse driver thread"
msgstr "" msgstr ""
#: daemon/x52d_mouse_handler.c:225 #: daemon/x52d_mouse_handler.c:235
#, c-format #, c-format
msgid "Error %d initializing mouse thread: %s" msgid "Error %d initializing mouse thread: %s"
msgstr "" msgstr ""
#: daemon/x52d_mouse_handler.c:232 #: daemon/x52d_mouse_handler.c:242
msgid "Shutting down X52 virtual mouse driver thread" msgid "Shutting down X52 virtual mouse driver thread"
msgstr "" msgstr ""
#: daemon/x52d_mouse_handler.c:239 #: daemon/x52d_mouse_handler.c:249
msgid "Virtual mouse not created. Ignoring thread state change" msgid "Virtual mouse not created. Ignoring thread state change"
msgstr "" msgstr ""
#: daemon/x52d_mouse_handler.c:291 daemon/x52d_mouse_handler.c:299 #: daemon/x52d_mouse_handler.c:301 daemon/x52d_mouse_handler.c:309
#, c-format #, c-format
msgid "Error %d creating X52 virtual mouse" msgid "Error %d creating X52 virtual mouse"
msgstr "" msgstr ""

View File

@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: libx52 0.2.3\n" "Project-Id-Version: libx52 0.2.3\n"
"Report-Msgid-Bugs-To: https://github.com/nirenjan/libx52/issues\n" "Report-Msgid-Bugs-To: https://github.com/nirenjan/libx52/issues\n"
"POT-Creation-Date: 2026-04-01 14:00-0700\n" "POT-Creation-Date: 2026-04-01 14:23-0700\n"
"PO-Revision-Date: 2026-03-27 08:33-0700\n" "PO-Revision-Date: 2026-03-27 08:33-0700\n"
"Last-Translator: Nirenjan Krishnan <nirenjan@gmail.com>\n" "Last-Translator: Nirenjan Krishnan <nirenjan@gmail.com>\n"
"Language-Team: Dummy Language for testing i18n\n" "Language-Team: Dummy Language for testing i18n\n"
@ -142,13 +142,13 @@ msgstr "YYay-MMay-DDay"
msgid "Unknown LED state %d" msgid "Unknown LED state %d"
msgstr "Unknownay EDLay atestay %d" msgstr "Unknownay EDLay atestay %d"
#: libx52/x52_stringify.c:47 daemon/x52d_clock.c:29 daemon/x52d_mouse.c:63 #: libx52/x52_stringify.c:47 daemon/x52d_clock.c:29 daemon/x52d_mouse.c:55
#: daemon/x52d_mouse.c:103 daemon/x52d_mouse.c:115 #: daemon/x52d_mouse.c:95 daemon/x52d_mouse.c:107
msgid "off" msgid "off"
msgstr "offay" msgstr "offay"
#: libx52/x52_stringify.c:48 daemon/x52d_clock.c:29 daemon/x52d_mouse.c:63 #: libx52/x52_stringify.c:48 daemon/x52d_clock.c:29 daemon/x52d_mouse.c:55
#: daemon/x52d_mouse.c:103 daemon/x52d_mouse.c:115 #: daemon/x52d_mouse.c:95 daemon/x52d_mouse.c:107
msgid "on" msgid "on"
msgstr "onay" msgstr "onay"
@ -917,64 +917,64 @@ msgstr "Erroray %d initializingay I/O iverdray eadthray: %s"
msgid "Shutting down X52 I/O driver thread" msgid "Shutting down X52 I/O driver thread"
msgstr "Uttingshay ownday X52 I/O iverdray eadthray" msgstr "Uttingshay ownday X52 I/O iverdray eadthray"
#: daemon/x52d_mouse.c:46 daemon/x52d_mouse.c:52 #: daemon/x52d_mouse.c:38 daemon/x52d_mouse.c:44
#, c-format #, c-format
msgid "Clamping %s value %d to range [%d..%d]" msgid "Clamping %s value %d to range [%d..%d]"
msgstr "" msgstr ""
#: daemon/x52d_mouse.c:62 #: daemon/x52d_mouse.c:54
#, c-format #, c-format
msgid "Setting mouse enable to %s" msgid "Setting mouse enable to %s"
msgstr "Ettingsay ousemay enableay otay %s" msgstr "Ettingsay ousemay enableay otay %s"
#: daemon/x52d_mouse.c:79 #: daemon/x52d_mouse.c:71
msgid "" msgid ""
"Config option 'mouse.speed' is DEPRECATED. Please use 'mouse.sensitivity' " "Config option 'mouse.speed' is DEPRECATED. Please use 'mouse.sensitivity' "
"instead" "instead"
msgstr "" msgstr ""
#: daemon/x52d_mouse.c:94 #: daemon/x52d_mouse.c:86
#, c-format #, c-format
msgid "Migrating legacy mouse speed '%d' to sensitivity '%d%%'" msgid "Migrating legacy mouse speed '%d' to sensitivity '%d%%'"
msgstr "" msgstr ""
#: daemon/x52d_mouse.c:96 #: daemon/x52d_mouse.c:88
msgid "speed -> sensitivity" msgid "speed -> sensitivity"
msgstr "" msgstr ""
#: daemon/x52d_mouse.c:102 #: daemon/x52d_mouse.c:94
#, c-format #, c-format
msgid "Setting mouse reverse scroll to %s" msgid "Setting mouse reverse scroll to %s"
msgstr "Ettingsay ousemay everseray ollscray otay %s" msgstr "Ettingsay ousemay everseray ollscray otay %s"
#: daemon/x52d_mouse.c:114 #: daemon/x52d_mouse.c:106
#, c-format #, c-format
msgid "Setting mouse isometric mode to %s" msgid "Setting mouse isometric mode to %s"
msgstr "Ettingsay ousemay isometricay odemay otay %s" msgstr "Ettingsay ousemay isometricay odemay otay %s"
#: daemon/x52d_mouse.c:121 #: daemon/x52d_mouse.c:113
msgid "sensitivity" msgid "sensitivity"
msgstr "ensitivitysay" msgstr "ensitivitysay"
#: daemon/x52d_mouse.c:124 #: daemon/x52d_mouse.c:116
#, c-format #, c-format
msgid "Setting mouse sensitivity to %d%%" msgid "Setting mouse sensitivity to %d%%"
msgstr "Ettingsay ousemay ensitivitysay otay %s" msgstr "Ettingsay ousemay ensitivitysay otay %s"
#: daemon/x52d_mouse.c:130 #: daemon/x52d_mouse.c:123
msgid "curve factor" msgid "curve factor"
msgstr "urvecay actorfay" msgstr "urvecay actorfay"
#: daemon/x52d_mouse.c:133 #: daemon/x52d_mouse.c:124
#, c-format #, c-format
msgid "Setting mouse curve factor to %f" msgid "Setting mouse curve factor to %f"
msgstr "Ettingsay ousemay urvecay actorfay otay %s" msgstr "Ettingsay ousemay urvecay actorfay otay %s"
#: daemon/x52d_mouse.c:139 #: daemon/x52d_mouse.c:130
msgid "deadzone factor" msgid "deadzone factor"
msgstr "eadzoneday actorfay" msgstr "eadzoneday actorfay"
#: daemon/x52d_mouse.c:142 #: daemon/x52d_mouse.c:131
#, c-format #, c-format
msgid "Setting mouse deadzone to %f" msgid "Setting mouse deadzone to %f"
msgstr "Ettingsay ousemay eadzoneday otay %s" msgstr "Ettingsay ousemay eadzoneday otay %s"
@ -990,33 +990,33 @@ msgstr ""
msgid "Error writing mouse wheel event %d" msgid "Error writing mouse wheel event %d"
msgstr "Erroray itingwray ousemay eelwhay eventay %d" msgstr "Erroray itingwray ousemay eelwhay eventay %d"
#: daemon/x52d_mouse_handler.c:175 #: daemon/x52d_mouse_handler.c:185
#, c-format #, c-format
msgid "Error %d writing mouse axis event (dx %d, dy %d)" msgid "Error %d writing mouse axis event (dx %d, dy %d)"
msgstr "Erroray %d itingwray ousemay axisay eventay (xday %d, yday %d)" msgstr "Erroray %d itingwray ousemay axisay eventay (xday %d, yday %d)"
#: daemon/x52d_mouse_handler.c:187 #: daemon/x52d_mouse_handler.c:197
msgid "Error writing mouse sync event" msgid "Error writing mouse sync event"
msgstr "Erroray itingwray ousemay yncsay eventay" msgstr "Erroray itingwray ousemay yncsay eventay"
#: daemon/x52d_mouse_handler.c:206 #: daemon/x52d_mouse_handler.c:216
msgid "Starting X52 virtual mouse driver thread" msgid "Starting X52 virtual mouse driver thread"
msgstr "Artingstay X52 irtualvay ousemay iverdray eadthray" msgstr "Artingstay X52 irtualvay ousemay iverdray eadthray"
#: daemon/x52d_mouse_handler.c:225 #: daemon/x52d_mouse_handler.c:235
#, c-format #, c-format
msgid "Error %d initializing mouse thread: %s" msgid "Error %d initializing mouse thread: %s"
msgstr "Erroray %d initializingay ousemay eadthray: %s" msgstr "Erroray %d initializingay ousemay eadthray: %s"
#: daemon/x52d_mouse_handler.c:232 #: daemon/x52d_mouse_handler.c:242
msgid "Shutting down X52 virtual mouse driver thread" msgid "Shutting down X52 virtual mouse driver thread"
msgstr "Uttingshay ownday X52 irtualvay ousemay iverdray eadthray" msgstr "Uttingshay ownday X52 irtualvay ousemay iverdray eadthray"
#: daemon/x52d_mouse_handler.c:239 #: daemon/x52d_mouse_handler.c:249
msgid "Virtual mouse not created. Ignoring thread state change" msgid "Virtual mouse not created. Ignoring thread state change"
msgstr "Irtualvay ousemay otnay eatedcray. Ignoringa eadthray atestay angechay" msgstr "Irtualvay ousemay otnay eatedcray. Ignoringa eadthray atestay angechay"
#: daemon/x52d_mouse_handler.c:291 daemon/x52d_mouse_handler.c:299 #: daemon/x52d_mouse_handler.c:301 daemon/x52d_mouse_handler.c:309
#, c-format #, c-format
msgid "Error %d creating X52 virtual mouse" msgid "Error %d creating X52 virtual mouse"
msgstr "Erroray %d eatingcray X52 irtualvay ousemay" msgstr "Erroray %d eatingcray X52 irtualvay ousemay"