summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorJacob Palecki <[email protected]>2020-07-28 17:21:39 -0700
committerJacob Palecki <[email protected]>2020-07-28 17:21:39 -0700
commitcdd82efdfdd7c2e9b4c2ed9777792f9921eedb9e (patch)
tree64620804479337358e5c5d2dfd1e54407a032de2 /common
parentRename acceleration constants, arguments (diff)
downloadrawaccel-cdd82efdfdd7c2e9b4c2ed9777792f9921eedb9e.tar.xz
rawaccel-cdd82efdfdd7c2e9b4c2ed9777792f9921eedb9e.zip
Get rid of enum and use types\tags directly
Diffstat (limited to 'common')
-rw-r--r--common/rawaccel-userspace.hpp14
-rw-r--r--common/rawaccel.hpp24
2 files changed, 12 insertions, 26 deletions
diff --git a/common/rawaccel-userspace.hpp b/common/rawaccel-userspace.hpp
index 5996364..82a9e98 100644
--- a/common/rawaccel-userspace.hpp
+++ b/common/rawaccel-userspace.hpp
@@ -68,34 +68,34 @@ mouse_modifier parse(int argc, char** argv) {
// modes
auto noaccel_mode = "no-accel mode" % (
- clipp::command("off", "noaccel").set(accel_args.accel_mode, mode::noaccel)
+ clipp::command("off", "noaccel").set(accel_args.accel_mode, accel_implementation_t::id<accel_noaccel>)
);
auto lin_mode = "linear accel mode:" % (
- clipp::command("linear").set(accel_args.accel_mode, mode::linear),
+ clipp::command("linear").set(accel_args.accel_mode, accel_implementation_t::id<accel_linear>),
accel_var
);
auto classic_mode = "classic accel mode:" % (
- clipp::command("classic").set(accel_args.accel_mode, mode::classic),
+ clipp::command("classic").set(accel_args.accel_mode, accel_implementation_t::id<accel_classic>),
accel_var,
(clipp::required("exponent") & clipp::number("num", accel_args.lim_exp)) % "exponent"
);
auto nat_mode = "natural accel mode:" % (
- clipp::command("natural").set(accel_args.accel_mode, mode::natural),
+ clipp::command("natural").set(accel_args.accel_mode, accel_implementation_t::id<accel_natural>),
accel_var,
limit_var
);
auto log_mode = "logarithmic accel mode:" % (
- clipp::command("logarithmic").set(accel_args.accel_mode, mode::logarithmic),
+ clipp::command("logarithmic").set(accel_args.accel_mode, accel_implementation_t::id<accel_logarithmic>),
accel_var
);
auto sig_mode = "sigmoid accel mode:" % (
- clipp::command("sigmoid").set(accel_args.accel_mode, mode::sigmoid),
+ clipp::command("sigmoid").set(accel_args.accel_mode, accel_implementation_t::id<accel_sigmoid>),
accel_var,
limit_var,
(clipp::required("midpoint") & clipp::number("speed", accel_args.midpoint)) % "midpoint"
);
auto pow_mode = "power accel mode:" % (
- clipp::command("power").set(accel_args.accel_mode, mode::power) >> [&] { accel_args.accel = 1; },
+ clipp::command("power").set(accel_args.accel_mode, accel_implementation_t::id<accel_power>) >> [&] { accel_args.accel = 1; },
(clipp::required("exponent") & clipp::number("num", accel_args.lim_exp)) % "exponent",
(clipp::option("scale") & clipp::number("num", accel_args.accel)) % "scale factor"
);
diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp
index e904350..08829dd 100644
--- a/common/rawaccel.hpp
+++ b/common/rawaccel.hpp
@@ -9,9 +9,6 @@
namespace rawaccel {
- /// <summary> Enum to hold acceleration implementation types (i.e. types of curves.) </summary>
- enum class mode { noaccel, linear, classic, natural, logarithmic, sigmoid, power };
-
/// <summary> Struct to hold vector rotation details. </summary>
struct rotator {
@@ -80,7 +77,7 @@ namespace rawaccel {
/// <summary> Struct to hold arguments for an acceleration function. </summary>
struct accel_args {
- mode accel_mode = mode::noaccel;
+ int accel_mode = 0;
milliseconds time_min = 0.4;
double offset = 0;
double accel = 0;
@@ -282,20 +279,8 @@ namespace rawaccel {
vec2<accel_scale_clamp> clamp;
accel_function(accel_args args) {
- switch (args.accel_mode)
- {
- case mode::linear: accel = accel_linear(args);
- break;
- case mode::classic: accel = accel_classic(args);
- break;
- case mode::natural: accel = accel_natural(args);
- break;
- case mode::logarithmic: accel = accel_logarithmic(args);
- break;
- case mode::sigmoid: accel = accel_sigmoid(args);
- break;
- case mode::power: accel = accel_power(args);
- }
+ accel.tag = args.accel_mode;
+ accel.visit([&](auto& a){ a = {args}; });
// Verification is performed by the accel_implementation object
// and therefore must occur after the object has been instantiated
@@ -365,7 +350,8 @@ namespace rawaccel {
if (apply_rotate) rotate = rotator(degrees);
else rotate = rotator();
- apply_accel = accel_args.accel_mode != mode::noaccel;
+ apply_accel = (accel_args.accel_mode != 0 &&
+ accel_args.accel_mode != accel_implementation_t::id<accel_noaccel>);
if (sens.x == 0) sens.x = 1;
if (sens.y == 0) sens.y = 1;