From b59cf98c2f326abeb6b993d8ecc5759d23096253 Mon Sep 17 00:00:00 2001
From: a1xd <68629610+a1xd@users.noreply.github.com>
Date: Thu, 30 Jul 2020 22:04:44 -0400
Subject: Make weight a member of accel_base
This exposes weight to derived accel types, which now supply a method to transform acceleration into scale.
---
common/accel-base.hpp | 21 +++++++++++++++++++--
common/accel-power.hpp | 10 +++++++++-
common/rawaccel-userspace.hpp | 2 +-
common/rawaccel.hpp | 24 ++++++------------------
4 files changed, 35 insertions(+), 22 deletions(-)
diff --git a/common/accel-base.hpp b/common/accel-base.hpp
index ed79bdb..e87b463 100644
--- a/common/accel-base.hpp
+++ b/common/accel-base.hpp
@@ -1,5 +1,7 @@
#pragma once
+#include "vec2.h"
+
namespace rawaccel {
// Error throwing calls std libraries which are unavailable in kernel mode.
@@ -15,14 +17,18 @@ namespace rawaccel {
double exponent = 2;
double midpoint = 0;
double power_scale = 1;
+ vec2d weight = { 1, 1 };
};
///
/// Struct to hold common acceleration curve implementation details.
///
struct accel_base {
-
- /// Generally, the acceleration ramp rate.
+
+ /// Coefficients applied to acceleration per axis.
+ vec2d weight = { 1, 1 };
+
+ /// Generally, the acceleration ramp rate.
double speed_coeff = 0;
///
@@ -34,6 +40,17 @@ namespace rawaccel {
verify(args);
speed_coeff = args.accel;
+ weight = args.weight;
+ }
+
+ ///
+ /// Default transformation of acceleration -> mouse input multipliers.
+ ///
+ inline vec2d scale(double accel_val) const {
+ return {
+ weight.x * accel_val + 1,
+ weight.y * accel_val + 1
+ };
}
///
diff --git a/common/accel-power.hpp b/common/accel-power.hpp
index c8b12cd..d96cb96 100644
--- a/common/accel-power.hpp
+++ b/common/accel-power.hpp
@@ -14,6 +14,7 @@ namespace rawaccel {
accel_power(accel_args args) {
verify(args);
+ weight = args.weight;
speed_coeff = args.power_scale;
exponent = args.exponent;
offset = args.offset;
@@ -24,8 +25,15 @@ namespace rawaccel {
return (offset > 0 && speed < 1) ? 1 : pow(speed * speed_coeff, exponent);
}
+ inline vec2d scale(double accel_val) const {
+ return {
+ weight.x * accel_val,
+ weight.y * accel_val
+ };
+ }
+
void verify(accel_args args) const {
- if (args.power_scale < 0) error("scale can not be negative");
+ if (args.power_scale <= 0) error("scale must be positive");
if (args.exponent <= 0) error("exponent must be greater than 0");
}
};
diff --git a/common/rawaccel-userspace.hpp b/common/rawaccel-userspace.hpp
index 49c0fcd..6a79d23 100644
--- a/common/rawaccel-userspace.hpp
+++ b/common/rawaccel-userspace.hpp
@@ -50,7 +50,7 @@ mouse_modifier parse(int argc, char** argv) {
// mode-independent accel options
auto opt_weight = "accel multiplier (default = 1)" %
- make_opt_vec(args.acc_fn_args.weight, "weight");
+ make_opt_vec(args.acc_fn_args.acc_args.weight, "weight");
auto opt_offset = "speed (dots/ms) where accel kicks in (default = 0)" % (
clipp::option("offset") & clipp::number("speed", args.acc_fn_args.acc_args.offset)
diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp
index 0aeb42d..7be37c2 100644
--- a/common/rawaccel.hpp
+++ b/common/rawaccel.hpp
@@ -81,7 +81,6 @@ namespace rawaccel {
accel_args acc_args;
int accel_mode = accel_impl_t::id;
milliseconds time_min = 0.4;
- vec2d weight = { 1, 1 };
vec2d cap = { 0, 0 };
};
@@ -102,26 +101,17 @@ namespace rawaccel {
/// The acceleration implementation (i.e. curve)
accel_impl_t accel;
- /// The weight of acceleration applied in {x, y} dimensions.
- vec2d weight = { 1, 1 };
-
- /// The constant added to weighted accel values to get the acceleration scale.
- double scale_base = 1;
-
/// The object which sets a min and max for the acceleration scale.
vec2 clamp;
- accel_function(accel_fn_args args) : accel_function() {
+ accel_function(accel_fn_args args) {
verify(args);
accel.tag = args.accel_mode;
accel.visit([&](auto& impl){ impl = { args.acc_args }; });
- if (accel.tag == accel_impl_t::id) scale_base = 0;
-
time_min = args.time_min;
speed_offset = args.acc_args.offset;
- weight = args.weight;
clamp.x = accel_scale_clamp(args.cap.x);
clamp.y = accel_scale_clamp(args.cap.y);
}
@@ -146,16 +136,14 @@ namespace rawaccel {
double time_clamped = clampsd(time, time_min, 100);
double speed = maxsd(mag / time_clamped - speed_offset, 0);
- double accel_val = accel.visit([=](auto&& impl) {
- return impl.accelerate(speed);
+ vec2d scale = accel.visit([=](auto&& impl) {
+ double accel_val = impl.accelerate(speed);
+ return impl.scale(accel_val);
});
- double scale_x = weight.x * accel_val + scale_base;
- double scale_y = weight.y * accel_val + scale_base;
-
return {
- input.x * clamp.x(scale_x),
- input.y * clamp.y(scale_y)
+ input.x * clamp.x(scale.x),
+ input.y * clamp.y(scale.y)
};
}
--
cgit v1.2.3