From 919177454d4874c57e327e76fa74a8c7f946810f Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 24 Apr 2016 02:26:27 +0100 Subject: [PATCH] Sensitivity: Introduce mconfig_get_sensitivity and _set_ In a moment, we are going to make the in-use representation of the sensitivity more complicated. We will need accessor methods for use by the configuration machinery. Provide these accessor methods now, to reduce noise in the substantive patch. For now they just access the single double. Rename the variable so that we catch all of the references. Signed-off-by: Ian Jackson --- driver/mprops.c | 6 +++--- include/mconfig.h | 12 +++++++++++- src/gestures.c | 4 ++-- src/mconfig.c | 14 ++++++++++++-- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/driver/mprops.c b/driver/mprops.c index 59bc993..7003ded 100644 --- a/driver/mprops.c +++ b/driver/mprops.c @@ -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; @@ -231,9 +231,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 } } diff --git a/include/mconfig.h b/include/mconfig.h index e14d53c..fa44635 100644 --- a/include/mconfig.h +++ b/include/mconfig.h @@ -165,13 +165,23 @@ 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_val; // Mouse movement multiplier. >= 0 }; /* Load the MConfig struct with its defaults. */ void mconfig_defaults(struct MConfig* cfg); +/* Set and read ->sensitivity_val + * + * 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, diff --git a/src/gestures.c b/src/gestures.c index 867ed81..af6d42c 100644 --- a/src/gestures.c +++ b/src/gestures.c @@ -414,8 +414,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_val); + gs->move_dy = (int)(dy*cfg->sensitivity_val); gs->move_type = GS_MOVE; gs->move_dist = 0; gs->move_dir = TR_NONE; diff --git a/src/mconfig.c b/src/mconfig.c index b68c63c..ca29701 100644 --- a/src/mconfig.c +++ b/src/mconfig.c @@ -21,6 +21,16 @@ #include "mconfig.h" +void mconfig_set_sensitivity(struct MConfig *cfg, double sensitivity) +{ + cfg->sensitivity_val = sensitivity; +} + +double mconfig_get_sensitivity(const struct MConfig * cfg) +{ + return cfg->sensitivity_val; +} + void mconfig_defaults(struct MConfig* cfg) { // Configure MTState @@ -77,7 +87,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, @@ -181,6 +191,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)); } -- 2.30.2