From 908ce556b6a232317a33dad5b9ca87293f342de9 Mon Sep 17 00:00:00 2001 From: p2rkw Date: Wed, 22 Jul 2015 01:20:15 +0200 Subject: [PATCH 1/3] REBASED from: size_pressure_touch_type Added support for touchpads with touch size and [ressure capabilities (like mine). Pressure will be favored over size on such devices. Simplified code, and fixed old bug. --- include/hwstate.h | 2 ++ include/mconfig.h | 5 +++- src/mtstate.c | 65 +++++++++++++++++++++++++++-------------------- 3 files changed, 44 insertions(+), 28 deletions(-) diff --git a/include/hwstate.h b/include/hwstate.h index ac4fd17..2268c69 100644 --- a/include/hwstate.h +++ b/include/hwstate.h @@ -26,7 +26,9 @@ #include "capabilities.h" struct FingerState { + /* The size of the contact area */ int touch_major, touch_minor; + /* The size of the approaching tool */ int width_major, width_minor; int orientation, pressure; int position_x, position_y; diff --git a/include/mconfig.h b/include/mconfig.h index a760464..0368979 100644 --- a/include/mconfig.h +++ b/include/mconfig.h @@ -84,7 +84,8 @@ #define MCFG_NONE 0 #define MCFG_SCALE 1 #define MCFG_SIZE 2 -#define MCFG_PRESSURE 3 +#define MCFG_PRESSURE_SIZE 3 +#define MCFG_PRESSURE 4 struct MConfig { /* Used by MTState */ @@ -94,6 +95,8 @@ struct MConfig { int touch_minor; // Does the touchpad report touches as ellipses? 0 or 1 int touch_min; // Minimum touch value. int touch_max; // Maximum touch value. + int pressure_min; // Minimum pressure value. + int pressure_max; // Maximum pressure value. int pad_width; // Width of the touchpad. int pad_height; // Height of the touchpad. diff --git a/src/mtstate.c b/src/mtstate.c index abe5096..4c651b9 100644 --- a/src/mtstate.c +++ b/src/mtstate.c @@ -33,19 +33,31 @@ static int inline touch_range_ratio(const struct MConfig* cfg, int value) return (double)(value - cfg->touch_min) / (double)(cfg->touch_max - cfg->touch_min) * 100; } +static int inline pressure_range_ratio(const struct MConfig* cfg, int value) +{ + return percentage(value - cfg->pressure_min, cfg->pressure_max - cfg->pressure_min); +} + +static int finger_touch_ratio(const struct MConfig* cfg, const struct FingerState* hw) +{ + switch(cfg->touch_type){ + case MCFG_SCALE: + return percentage(hw->touch_major, hw->width_major); /* = estimated pressure */ + case MCFG_SIZE: + return touch_range_ratio(cfg, hw->touch_major); + case MCFG_PRESSURE_SIZE: + case MCFG_PRESSURE: + return pressure_range_ratio(cfg, hw->pressure); + default: return 101; /* sholuld it be additional argument? or maybe it should return -1? */ + } +} + /* Check if a finger is touching the trackpad. */ static int is_touch(const struct MConfig* cfg, const struct FingerState* hw) { - if (cfg->touch_type == MCFG_SCALE) - return percentage(hw->touch_major, hw->width_major) > cfg->touch_down; - else if (cfg->touch_type == MCFG_SIZE) - return touch_range_ratio(cfg, hw->touch_major) > cfg->touch_down; - else if (cfg->touch_type == MCFG_PRESSURE) - return touch_range_ratio(cfg, hw->pressure) > cfg->touch_down; - else - return 1; + return finger_touch_ratio(cfg, hw) > cfg->touch_down; } /* Check if a finger is released from the touchpad. @@ -53,14 +65,7 @@ static int is_touch(const struct MConfig* cfg, static int is_release(const struct MConfig* cfg, const struct FingerState* hw) { - if (cfg->touch_type == MCFG_SCALE) - return percentage(hw->touch_major, hw->width_major) < cfg->touch_up; - else if (cfg->touch_type == MCFG_SIZE) - return touch_range_ratio(cfg, hw->touch_major) < cfg->touch_up; - else if (cfg->touch_type == MCFG_PRESSURE) - return touch_range_ratio(cfg, hw->pressure) < cfg->touch_up; - else - return 0; + return finger_touch_ratio(cfg, hw) < cfg->touch_up; } static int is_thumb(const struct MConfig* cfg, @@ -93,25 +98,31 @@ static int is_thumb(const struct MConfig* cfg, static int is_palm(const struct MConfig* cfg, const struct FingerState* hw) { - int size; - if ((cfg->touch_type == MCFG_SCALE) || (cfg->touch_type == MCFG_SIZE)) { - size = hw->touch_major; - } else if (cfg->touch_type == MCFG_PRESSURE) { - size = hw->pressure; - } else { - return 0; + int ratio; + switch(cfg->touch_type){ + case MCFG_SCALE: + ratio = percentage(hw->touch_major, hw->width_major); + break; + case MCFG_SIZE: + case MCFG_SIZE_PRESSURE: + case MCFG_PRESSURE_SIZE: + ratio = touch_range_ratio(cfg, hw->touch_major); + break; + case MCFG_PRESSURE: + ratio = pressure_range_ratio(cfg, hw->pressure); + break; + default: return 0; } - size = touch_range_ratio(cfg, size); - if (size > cfg->palm_size) { + if (ratio > cfg->palm_size) { #if DEBUG_MTSTATE - xf86Msg(X_INFO, "is_palm: yes %d > %d\n", size, cfg->palm_size); + xf86Msg(X_INFO, "is_palm: yes %d > %d\n", ratio, cfg->palm_size); #endif return 1; } else { #if DEBUG_MTSTATE - xf86Msg(X_INFO, "is_palm: no %d > %d\n", size, cfg->palm_size); + xf86Msg(X_INFO, "is_palm: no %d > %d\n", ratio, cfg->palm_size); #endif return 0; } From 358b0f41a22ea99e8e38748e5815dcc98e8ce596 Mon Sep 17 00:00:00 2001 From: p2rkw Date: Wed, 22 Jul 2015 12:10:27 +0200 Subject: [PATCH 2/3] REBASED from: size_pressure_touch_type For touchpads supporting both: touch size and pressure, source with higher resolution will be selected. --- include/mconfig.h | 3 ++- src/mconfig.c | 22 ++++++++++++++++++---- src/mtstate.c | 1 + 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/include/mconfig.h b/include/mconfig.h index 0368979..71b46e7 100644 --- a/include/mconfig.h +++ b/include/mconfig.h @@ -85,7 +85,8 @@ #define MCFG_SCALE 1 #define MCFG_SIZE 2 #define MCFG_PRESSURE_SIZE 3 -#define MCFG_PRESSURE 4 +#define MCFG_SIZE_PRESSURE 4 /* same capabilities as above, but with higher resolution of touches*/ +#define MCFG_PRESSURE 5 struct MConfig { /* Used by MTState */ diff --git a/src/mconfig.c b/src/mconfig.c index 5ebf357..13abb37 100644 --- a/src/mconfig.c +++ b/src/mconfig.c @@ -85,7 +85,7 @@ void mconfig_init(struct MConfig* cfg, cfg->touch_minor = caps->has_abs[MTDEV_TOUCH_MINOR]; cfg->pad_width = get_cap_xsize(caps); cfg->pad_height = get_cap_ysize(caps); - + if (caps->has_abs[MTDEV_TOUCH_MAJOR] && caps->has_abs[MTDEV_WIDTH_MAJOR]) { cfg->touch_type = MCFG_SCALE; cfg->touch_min = caps->abs[MTDEV_TOUCH_MAJOR].minimum; @@ -93,6 +93,20 @@ void mconfig_init(struct MConfig* cfg, xf86Msg(X_INFO, "Touchpad supports regular and approaching touches.\n"); xf86Msg(X_INFO, " touch_min = %d, touch_max = %d\n", cfg->touch_min, cfg->touch_max); } + else if (caps->has_abs[MTDEV_TOUCH_MAJOR] && caps->has_abs[MTDEV_PRESSURE]) { + cfg->touch_min = caps->abs[MTDEV_TOUCH_MAJOR].minimum; + cfg->touch_max = caps->abs[MTDEV_TOUCH_MAJOR].maximum; + cfg->pressure_min = caps->abs[MTDEV_PRESSURE].minimum; + cfg->pressure_max = caps->abs[MTDEV_PRESSURE].maximum; + /* select source of the events basing on its resolution */ + if(cfg->pressure_max - cfg->pressure_min >= cfg->touch_max - cfg->touch_min) + cfg->touch_type = MCFG_PRESSURE_SIZE; + else + cfg->touch_type = MCFG_SIZE_PRESSURE; + xf86Msg(X_INFO, "Touchpad is pressure based, but supports regular touches also.\n"); + xf86Msg(X_INFO, " touch_min = %d, touch_max = %d\n", cfg->touch_min, cfg->touch_max); + xf86Msg(X_INFO, " pressure_min = %d, pressure_max = %d\n", cfg->pressure_min, cfg->pressure_max); + } else if (caps->has_abs[MTDEV_TOUCH_MAJOR]) { cfg->touch_type = MCFG_SIZE; cfg->touch_min = caps->abs[MTDEV_TOUCH_MAJOR].minimum; @@ -102,10 +116,10 @@ void mconfig_init(struct MConfig* cfg, } else if (caps->has_abs[MTDEV_PRESSURE]) { cfg->touch_type = MCFG_PRESSURE; - cfg->touch_min = caps->abs[MTDEV_PRESSURE].minimum; - cfg->touch_max = caps->abs[MTDEV_PRESSURE].maximum; + cfg->pressure_min = caps->abs[MTDEV_PRESSURE].minimum; + cfg->pressure_max = caps->abs[MTDEV_PRESSURE].maximum; xf86Msg(X_INFO, "Touchpad is pressure based.\n"); - xf86Msg(X_INFO, " touch_min = %d, touch_max = %d\n", cfg->touch_min, cfg->touch_max); + xf86Msg(X_INFO, " pressure_min = %d, pressure_max = %d\n", cfg->pressure_min, cfg->pressure_max); } else { cfg->touch_type = MCFG_NONE; diff --git a/src/mtstate.c b/src/mtstate.c index 4c651b9..d44c990 100644 --- a/src/mtstate.c +++ b/src/mtstate.c @@ -44,6 +44,7 @@ static int finger_touch_ratio(const struct MConfig* cfg, const struct FingerStat case MCFG_SCALE: return percentage(hw->touch_major, hw->width_major); /* = estimated pressure */ case MCFG_SIZE: + case MCFG_SIZE_PRESSURE: return touch_range_ratio(cfg, hw->touch_major); case MCFG_PRESSURE_SIZE: case MCFG_PRESSURE: From 6553ff1cbebe4970528c0c1b05629df22de1b7af Mon Sep 17 00:00:00 2001 From: p2rkw Date: Tue, 28 Jul 2015 00:03:36 +0200 Subject: [PATCH 3/3] Changed capabilities sets names. --- include/mconfig.h | 4 ++-- src/mconfig.c | 4 ++-- src/mtstate.c | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/mconfig.h b/include/mconfig.h index 71b46e7..75133f9 100644 --- a/include/mconfig.h +++ b/include/mconfig.h @@ -84,8 +84,8 @@ #define MCFG_NONE 0 #define MCFG_SCALE 1 #define MCFG_SIZE 2 -#define MCFG_PRESSURE_SIZE 3 -#define MCFG_SIZE_PRESSURE 4 /* same capabilities as above, but with higher resolution of touches*/ +#define MCFG_MAJOR_PRESSURE_AND_MINOR_SIZE 3 +#define MCFG_MAJOR_SIZE_AND_MINOR_PRESSURE 4 /* same capabilities as above, but with higher resolution of touches*/ #define MCFG_PRESSURE 5 struct MConfig { diff --git a/src/mconfig.c b/src/mconfig.c index 13abb37..ebf3554 100644 --- a/src/mconfig.c +++ b/src/mconfig.c @@ -100,9 +100,9 @@ void mconfig_init(struct MConfig* cfg, cfg->pressure_max = caps->abs[MTDEV_PRESSURE].maximum; /* select source of the events basing on its resolution */ if(cfg->pressure_max - cfg->pressure_min >= cfg->touch_max - cfg->touch_min) - cfg->touch_type = MCFG_PRESSURE_SIZE; + cfg->touch_type = MCFG_MAJOR_PRESSURE_AND_MINOR_SIZE; else - cfg->touch_type = MCFG_SIZE_PRESSURE; + cfg->touch_type = MCFG_MAJOR_SIZE_AND_MINOR_PRESSURE; xf86Msg(X_INFO, "Touchpad is pressure based, but supports regular touches also.\n"); xf86Msg(X_INFO, " touch_min = %d, touch_max = %d\n", cfg->touch_min, cfg->touch_max); xf86Msg(X_INFO, " pressure_min = %d, pressure_max = %d\n", cfg->pressure_min, cfg->pressure_max); diff --git a/src/mtstate.c b/src/mtstate.c index d44c990..0904304 100644 --- a/src/mtstate.c +++ b/src/mtstate.c @@ -44,9 +44,9 @@ static int finger_touch_ratio(const struct MConfig* cfg, const struct FingerStat case MCFG_SCALE: return percentage(hw->touch_major, hw->width_major); /* = estimated pressure */ case MCFG_SIZE: - case MCFG_SIZE_PRESSURE: + case MCFG_MAJOR_SIZE_AND_MINOR_PRESSURE: return touch_range_ratio(cfg, hw->touch_major); - case MCFG_PRESSURE_SIZE: + case MCFG_MAJOR_PRESSURE_AND_MINOR_SIZE: case MCFG_PRESSURE: return pressure_range_ratio(cfg, hw->pressure); default: return 101; /* sholuld it be additional argument? or maybe it should return -1? */ @@ -105,8 +105,8 @@ static int is_palm(const struct MConfig* cfg, ratio = percentage(hw->touch_major, hw->width_major); break; case MCFG_SIZE: - case MCFG_SIZE_PRESSURE: - case MCFG_PRESSURE_SIZE: + case MCFG_MAJOR_SIZE_AND_MINOR_PRESSURE: + case MCFG_MAJOR_PRESSURE_AND_MINOR_SIZE: ratio = touch_range_ratio(cfg, hw->touch_major); break; case MCFG_PRESSURE: