Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sensitivity: Handle sensitivities < 1.0 without rounding errors #111

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*~
*.la
*.lo
*.o
Expand Down
6 changes: 3 additions & 3 deletions driver/mprops.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void mprops_init(struct MConfig* cfg, InputInfoPtr local) {
ivals[0] = cfg->trackpad_disable;
mprops.trackpad_disable = atom_init_integer(local->dev, MTRACK_PROP_TRACKPAD_DISABLE, 1, ivals, 8);

fvals[0] = (float)cfg->sensitivity;
fvals[0] = (float)mconfig_get_sensitivity(cfg);
mprops.sensitivity = atom_init_float(local->dev, MTRACK_PROP_SENSITIVITY, 1, fvals, mprops.float_type);

ivals[0] = cfg->touch_down;
Expand Down Expand Up @@ -230,9 +230,9 @@ int mprops_set_property(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop
return BadMatch;

if (!checkonly) {
cfg->sensitivity = fvals[0];
mconfig_set_sensitivity(cfg, fvals[0]);
#ifdef DEBUG_PROPS
xf86Msg(X_INFO, "mtrack: set sensitivity to %f\n", cfg->sensitivity);
xf86Msg(X_INFO, "mtrack: set sensitivity to %f\n", mconfig_get_sensitivity(cfg));
#endif
}
}
Expand Down
8 changes: 4 additions & 4 deletions driver/mtrack.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ static int device_init(DeviceIntPtr dev, LocalDevicePtr local)
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
axes_labels[0],
#endif
mt->caps.abs[MTDEV_POSITION_X].minimum,
mt->caps.abs[MTDEV_POSITION_X].maximum,
mt->caps.abs[MTDEV_POSITION_X].minimum * mt->cfg.sensitivity_smalldiv,
mt->caps.abs[MTDEV_POSITION_X].maximum * mt->cfg.sensitivity_smalldiv,
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 12
1, 0, 1, Absolute);
#else
Expand All @@ -145,8 +145,8 @@ static int device_init(DeviceIntPtr dev, LocalDevicePtr local)
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
axes_labels[1],
#endif
mt->caps.abs[MTDEV_POSITION_Y].minimum,
mt->caps.abs[MTDEV_POSITION_Y].maximum,
mt->caps.abs[MTDEV_POSITION_Y].minimum * mt->cfg.sensitivity_smalldiv,
mt->caps.abs[MTDEV_POSITION_Y].maximum * mt->cfg.sensitivity_smalldiv,
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 12
1, 0, 1, Absolute);
#else
Expand Down
13 changes: 12 additions & 1 deletion include/mconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,24 @@ struct MConfig {
int drag_timeout; // How long to wait for a move after tapping? > 0
int drag_wait; // How long to wait before triggering button down? >= 0
int drag_dist; // How far is the finger allowed to move during wait time? >= 0
double sensitivity; // Mouse movement multiplier. >= 0
double sensitivity_big; // Mouse movement multiplier. >= 1.0 } real sensitivity is
double sensitivity_smalldiv; // Mouse movement divisor. >= 1.0 } big * smalldiv
};

/* Load the MConfig struct with its defaults.
*/
void mconfig_defaults(struct MConfig* cfg);

/* Set and read ->sensitivity_big and _small.
*
* Configuration code must always use these get/set functions.
*
* Runtime code which uses the sensitivity to process events is
* expected to access the value in cfg directly.
*/
void mconfig_set_sensitivity(struct MConfig *cfg, double sensitivity);
double mconfig_get_sensitivity(const struct MConfig *cfg);

/* Initialize the MConfig struct.
*/
void mconfig_init(struct MConfig* cfg,
Expand Down
4 changes: 2 additions & 2 deletions src/gestures.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ static void trigger_move(struct Gestures* gs,
{
if ((gs->move_type == GS_MOVE || !timercmp(&gs->time, &gs->move_wait, <)) && (dx != 0 || dy != 0)) {
if (trigger_drag_start(gs, cfg, dx, dy)) {
gs->move_dx = (int)(dx*cfg->sensitivity);
gs->move_dy = (int)(dy*cfg->sensitivity);
gs->move_dx = (int)(dx*cfg->sensitivity_big);
gs->move_dy = (int)(dy*cfg->sensitivity_big);
gs->move_type = GS_MOVE;
gs->move_dist = 0;
gs->move_dir = TR_NONE;
Expand Down
20 changes: 18 additions & 2 deletions src/mconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@

#include "mconfig.h"

void mconfig_set_sensitivity(struct MConfig *cfg, double sensitivity)
{
if (sensitivity >= 1.0) {
cfg->sensitivity_big = sensitivity;
cfg->sensitivity_smalldiv = 1.0;
} else {
cfg->sensitivity_big = 1.0;
cfg->sensitivity_smalldiv = 1.0 / sensitivity;
}
}

double mconfig_get_sensitivity(const struct MConfig * cfg)
{
return cfg->sensitivity_big / cfg->sensitivity_smalldiv;
}

void mconfig_defaults(struct MConfig* cfg)
{
// Configure MTState
Expand Down Expand Up @@ -76,7 +92,7 @@ void mconfig_defaults(struct MConfig* cfg)
cfg->rotate_rt_btn = DEFAULT_ROTATE_RT_BTN;
cfg->drag_enable = DEFAULT_DRAG_ENABLE;
cfg->drag_timeout = DEFAULT_DRAG_TIMEOUT;
cfg->sensitivity = DEFAULT_SENSITIVITY;
mconfig_set_sensitivity(cfg, DEFAULT_SENSITIVITY);
}

void mconfig_init(struct MConfig* cfg,
Expand Down Expand Up @@ -177,6 +193,6 @@ void mconfig_configure(struct MConfig* cfg,
cfg->drag_dist = MAXVAL(xf86SetIntOption(opts, "TapDragDist", DEFAULT_DRAG_DIST), 0);
cfg->axis_x_invert = xf86SetBoolOption(opts, "AxisXInvert", DEFAULT_AXIS_X_INVERT);
cfg->axis_y_invert = xf86SetBoolOption(opts, "AxisYInvert", DEFAULT_AXIS_Y_INVERT);
cfg->sensitivity = MAXVAL(xf86SetRealOption(opts, "Sensitivity", DEFAULT_SENSITIVITY), 0);
mconfig_set_sensitivity(cfg, MAXVAL(xf86SetRealOption(opts, "Sensitivity", DEFAULT_SENSITIVITY), 0));
}