Skip to content

Commit

Permalink
Add lasso stabilization.
Browse files Browse the repository at this point in the history
Ported from master branch, commit b4541b4
  • Loading branch information
mk authored and StollD committed Jul 18, 2022
1 parent 28d94e4 commit f20c82b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
5 changes: 4 additions & 1 deletion etc/ipts.conf
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@
# Distance = 1600

[Stability]
## How far an input can move between two frames to be considered stable.
## How much an input can change in size between two frames to be considered stable.
# Threshold = 0.1

## How much an input must move between two frames to be considered stable
# PositionThreshold = 8
7 changes: 7 additions & 0 deletions src/daemon/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <algorithm>
#include <cctype>
#include <cmath>
#include <configure.h>
#include <filesystem>
#include <ini.h>
Expand Down Expand Up @@ -96,6 +97,12 @@ static int parse_conf(void *user, const char *c_section, const char *c_name, con
if (section == "Stability" && name == "Threshold")
config->stability_threshold = std::stof(value);

if (section == "Stability" && name == "PositionThreshold") {
config->position_stability_threshold = std::stof(value);
config->position_stability_threshold_square =
std::pow(config->position_stability_threshold, 2);
}

return 1;
}

Expand Down
2 changes: 2 additions & 0 deletions src/daemon/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class Config {
f32 cone_distance = 1600;

f32 stability_threshold = 0.1;
f32 position_stability_threshold = 8;
f64 position_stability_threshold_square = 8 * 8;

i16 vendor;
i16 product;
Expand Down
19 changes: 19 additions & 0 deletions src/daemon/touch-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,25 @@ void TouchManager::track()
dev2 < this->conf.stability_threshold) ||
!this->conf.touch_stability;

f64 dx = this->inputs[i].x - this->last[j].x;
f64 dy = this->inputs[i].y - this->last[j].y;
f64 sqdist = dx * dx + dy * dy;

// Is the position stable?
if (sqdist < this->conf.position_stability_threshold_square) {
this->inputs[i].x = this->last[j].x;
this->inputs[i].y = this->last[j].y;
} else {
f64 dist = std::sqrt(sqdist);
f64 x = this->inputs[i].x -
this->conf.position_stability_threshold * (dx / dist);
f64 y = this->inputs[i].y -
this->conf.position_stability_threshold * (dy / dist);

this->inputs[i].x = gsl::narrow_cast<i32>(x);
this->inputs[i].y = gsl::narrow_cast<i32>(y);
}

// Set the distance of all pairs that contain one of i and j
// to something even higher than the distance chosen above.
// This prevents i and j from getting selected again.
Expand Down

0 comments on commit f20c82b

Please sign in to comment.