summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/common.vcxitems2
-rw-r--r--common/external/nillable.h30
-rw-r--r--common/rawaccel-io.hpp6
-rw-r--r--common/rawaccel-userspace.hpp128
-rw-r--r--common/rawaccel.hpp2
-rw-r--r--common/tagged-union-single.h (renamed from common/external/tagged-union-single.h)0
-rw-r--r--console/console.cpp3
-rw-r--r--console/console.vcxproj3
-rw-r--r--console/external/clipp.h (renamed from common/external/clipp.h)0
-rw-r--r--console/parse.hpp128
-rw-r--r--rawaccel.sln2
11 files changed, 142 insertions, 162 deletions
diff --git a/common/common.vcxitems b/common/common.vcxitems
index aeeaa95..7102164 100644
--- a/common/common.vcxitems
+++ b/common/common.vcxitems
@@ -24,8 +24,8 @@
<ClInclude Include="$(MSBuildThisFileDirectory)accel-sigmoid.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)accel-error.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-io.hpp" />
- <ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-userspace.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)rawaccel.hpp" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)tagged-union-single.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)x64-util.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)vec2.h" />
</ItemGroup>
diff --git a/common/external/nillable.h b/common/external/nillable.h
deleted file mode 100644
index 40cf01c..0000000
--- a/common/external/nillable.h
+++ /dev/null
@@ -1,30 +0,0 @@
-inline constexpr struct nil_t {} nil;
-
-// Requirements: T is default-constructible and trivially-destructible
-template<typename T>
-struct nillable {
- bool has_value = false;
- T value;
-
- nillable() = default;
-
- nillable(nil_t) : nillable() {}
- nillable(const T& v) : has_value(true), value(v) {}
-
- nillable& operator=(nil_t) {
- has_value = false;
- return *this;
- }
- nillable& operator=(const T& v) {
- value = v;
- has_value = true;
- return *this;
- }
-
- const T* operator->() const { return &value; }
- T* operator->() { return &value; }
-
- explicit operator bool() const { return has_value; }
-};
-
-template<typename T> nillable(T)->nillable<T>;
diff --git a/common/rawaccel-io.hpp b/common/rawaccel-io.hpp
index 7a4c59c..4050f07 100644
--- a/common/rawaccel-io.hpp
+++ b/common/rawaccel-io.hpp
@@ -9,6 +9,9 @@
#define RA_IOCTL CTL_CODE(0x8888, 0x888, METHOD_BUFFERED, FILE_ANY_ACCESS)
+#pragma warning(push)
+#pragma warning(disable:4245) // int -> DWORD conversion while passing RA_IOCTL
+
namespace rawaccel {
mouse_modifier read() {
@@ -43,6 +46,7 @@ namespace rawaccel {
return mod;
}
+
void write(mouse_modifier mod) {
HANDLE ra_handle = INVALID_HANDLE_VALUE;
@@ -73,3 +77,5 @@ namespace rawaccel {
}
}
+
+#pragma warning(pop)
diff --git a/common/rawaccel-userspace.hpp b/common/rawaccel-userspace.hpp
deleted file mode 100644
index c80262c..0000000
--- a/common/rawaccel-userspace.hpp
+++ /dev/null
@@ -1,128 +0,0 @@
-#pragma once
-
-#include <iostream>
-
-#include "external/clipp.h"
-
-#include "accel-error.hpp"
-#include "rawaccel.hpp"
-
-namespace rawaccel {
-
-inline constexpr int SYSTEM_ERROR = -1;
-inline constexpr int PARSE_ERROR = 1;
-inline constexpr int INVALID_ARGUMENT = 2;
-
-template<typename Accel, typename StrFirst, typename... StrRest>
-clipp::parameter make_accel_cmd(modifier_args& args, StrFirst&& first_flag, StrRest&&... rest) {
- return clipp::command(first_flag, rest...)
- .set(args.acc_fn_args.accel_mode, accel_impl_t::id<Accel>);
-}
-
-mouse_modifier parse(int argc, char** argv) {
- modifier_args args{};
-
- auto make_opt_vec = [](vec2d& v, auto first_flag, auto... rest) {
- return clipp::option(first_flag, rest...) & (
- clipp::number("xy", v.x, v.y) | (
- (clipp::required("x") & clipp::number("num", v.x)),
- (clipp::required("y") & clipp::number("num", v.y))
- )
- );
- };
-
- auto make_doc_fmt = [] {
- return clipp::doc_formatting{}
- .first_column(4)
- .doc_column(28)
- .last_column(80)
- // min value to not split optional vec2 alternatives
- .alternatives_min_split_size(5);
- };
-
- // default options
- auto opt_sens = "sensitivity (default = 1)" % make_opt_vec(args.sens, "sens");
-
- auto opt_rot = "counter-clockwise rotation (default = 0)" % (
- clipp::option("rotate") &
- clipp::number("degrees", args.degrees)
- );
-
- // mode-independent accel options
- auto opt_weight = "accel multiplier (default = 1)" %
- 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)
- );
-
- auto opt_cap = "accel scale cap (default = 9)" %
- make_opt_vec(args.acc_fn_args.cap, "cap");
-
- auto opt_tmin = "minimum time between polls (default = 0.4)" % (
- clipp::option("tmin") &
- clipp::number("ms", args.acc_fn_args.time_min)
- );
-
- auto accel_var = (clipp::required("accel") & clipp::number("num", args.acc_fn_args.acc_args.accel)) % "ramp rate";
- auto limit_var = (clipp::required("limit") & clipp::number("scale", args.acc_fn_args.acc_args.limit)) % "limit";
- auto exp_var = (clipp::required("exponent") & clipp::number("num", args.acc_fn_args.acc_args.exponent)) % "exponent";
-
- // modes
- auto noaccel_mode = "no-accel mode" % make_accel_cmd<accel_noaccel>(args, "off", "noaccel");
-
- auto lin_mode = "linear accel mode:" % (
- make_accel_cmd<accel_linear>(args, "linear"),
- accel_var
- );
- auto classic_mode = "classic accel mode:" % (
- make_accel_cmd<accel_classic>(args, "classic"),
- accel_var,
- exp_var
- );
- auto nat_mode = "natural accel mode:" % (
- make_accel_cmd<accel_natural>(args, "natural"),
- accel_var,
- limit_var
- );
- auto log_mode = "logarithmic accel mode:" % (
- make_accel_cmd<accel_logarithmic>(args, "logarithmic"),
- accel_var
- );
- auto sig_mode = "sigmoid accel mode:" % (
- make_accel_cmd<accel_sigmoid>(args, "sigmoid"),
- accel_var,
- limit_var,
- (clipp::required("midpoint") & clipp::number("speed", args.acc_fn_args.acc_args.midpoint)) % "midpoint"
- );
- auto pow_mode = "power accel mode:" % (
- make_accel_cmd<accel_power>(args, "power"),
- exp_var,
- (clipp::option("scale") & clipp::number("num", args.acc_fn_args.acc_args.power_scale)) % "scale factor"
- );
-
- auto accel_mode_exclusive = (lin_mode | classic_mode | nat_mode | log_mode | sig_mode | pow_mode);
- auto accel_opts = "mode-independent accel options:" % (opt_cap, opt_weight, opt_offset, opt_tmin);
-
- bool help = false;
-
- auto cli = clipp::group(clipp::command("help").set(help)) | (
- noaccel_mode | (accel_mode_exclusive, accel_opts),
- opt_sens,
- opt_rot
- );
-
- if (!clipp::parse(argc, argv, cli)) {
- std::cout << clipp::usage_lines(cli, "rawaccel", make_doc_fmt());
- std::exit(PARSE_ERROR);
- }
-
- if (help) {
- std::cout << clipp::make_man_page(cli, "rawaccel", make_doc_fmt());
- std::exit(0);
- }
-
- return mouse_modifier(args);
-}
-
-} // rawaccel
diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp
index 59a0360..474f2aa 100644
--- a/common/rawaccel.hpp
+++ b/common/rawaccel.hpp
@@ -4,7 +4,7 @@
#include <math.h>
#include "x64-util.hpp"
-#include "external/tagged-union-single.h"
+#include "tagged-union-single.h"
#include "accel-linear.hpp"
#include "accel-classic.hpp"
diff --git a/common/external/tagged-union-single.h b/common/tagged-union-single.h
index f0de097..f0de097 100644
--- a/common/external/tagged-union-single.h
+++ b/common/tagged-union-single.h
diff --git a/console/console.cpp b/console/console.cpp
index 00dc481..9a1d66f 100644
--- a/console/console.cpp
+++ b/console/console.cpp
@@ -1,8 +1,9 @@
#include <iostream>
-#include <rawaccel-userspace.hpp>
#include <rawaccel-io.hpp>
+#include "parse.hpp"
+
namespace ra = rawaccel;
int main(int argc, char** argv) {
diff --git a/console/console.vcxproj b/console/console.vcxproj
index d0ad292..0f87d94 100644
--- a/console/console.vcxproj
+++ b/console/console.vcxproj
@@ -91,6 +91,9 @@
<ItemGroup>
<ClCompile Include="console.cpp" />
</ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="parse.hpp" />
+ </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
diff --git a/common/external/clipp.h b/console/external/clipp.h
index cca1554..cca1554 100644
--- a/common/external/clipp.h
+++ b/console/external/clipp.h
diff --git a/console/parse.hpp b/console/parse.hpp
new file mode 100644
index 0000000..1cdb3fb
--- /dev/null
+++ b/console/parse.hpp
@@ -0,0 +1,128 @@
+#pragma once
+
+#include <iostream>
+
+#include <rawaccel.hpp>
+#include <accel-error.hpp>
+
+#include "external/clipp.h"
+
+namespace rawaccel {
+
+ inline constexpr int SYSTEM_ERROR = -1;
+ inline constexpr int PARSE_ERROR = 1;
+ inline constexpr int INVALID_ARGUMENT = 2;
+
+ template<typename Accel, typename StrFirst, typename... StrRest>
+ clipp::parameter make_accel_cmd(modifier_args& args, StrFirst&& first_flag, StrRest&&... rest) {
+ return clipp::command(first_flag, rest...)
+ .set(args.acc_fn_args.accel_mode, accel_impl_t::id<Accel>);
+ }
+
+ mouse_modifier parse(int argc, char** argv) {
+ modifier_args args{};
+
+ auto make_opt_vec = [](vec2d& v, auto first_flag, auto... rest) {
+ return clipp::option(first_flag, rest...) & (
+ clipp::number("xy", v.x, v.y) | (
+ (clipp::required("x") & clipp::number("num", v.x)),
+ (clipp::required("y") & clipp::number("num", v.y))
+ )
+ );
+ };
+
+ auto make_doc_fmt = [] {
+ return clipp::doc_formatting{}
+ .first_column(4)
+ .doc_column(28)
+ .last_column(80)
+ // min value to not split optional vec2 alternatives
+ .alternatives_min_split_size(5);
+ };
+
+ // default options
+ auto opt_sens = "sensitivity (default = 1)" % make_opt_vec(args.sens, "sens");
+
+ auto opt_rot = "counter-clockwise rotation (default = 0)" % (
+ clipp::option("rotate") &
+ clipp::number("degrees", args.degrees)
+ );
+
+ // mode-independent accel options
+ auto opt_weight = "accel multiplier (default = 1)" %
+ 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)
+ );
+
+ auto opt_cap = "accel scale cap (default = 9)" %
+ make_opt_vec(args.acc_fn_args.cap, "cap");
+
+ auto opt_tmin = "minimum time between polls (default = 0.4)" % (
+ clipp::option("tmin") &
+ clipp::number("ms", args.acc_fn_args.time_min)
+ );
+
+ auto accel_var = (clipp::required("accel") & clipp::number("num", args.acc_fn_args.acc_args.accel)) % "ramp rate";
+ auto limit_var = (clipp::required("limit") & clipp::number("scale", args.acc_fn_args.acc_args.limit)) % "limit";
+ auto exp_var = (clipp::required("exponent") & clipp::number("num", args.acc_fn_args.acc_args.exponent)) % "exponent";
+
+ // modes
+ auto noaccel_mode = "no-accel mode" % make_accel_cmd<accel_noaccel>(args, "off", "noaccel");
+
+ auto lin_mode = "linear accel mode:" % (
+ make_accel_cmd<accel_linear>(args, "linear"),
+ accel_var
+ );
+ auto classic_mode = "classic accel mode:" % (
+ make_accel_cmd<accel_classic>(args, "classic"),
+ accel_var,
+ exp_var
+ );
+ auto nat_mode = "natural accel mode:" % (
+ make_accel_cmd<accel_natural>(args, "natural"),
+ accel_var,
+ limit_var
+ );
+ auto log_mode = "logarithmic accel mode:" % (
+ make_accel_cmd<accel_logarithmic>(args, "logarithmic"),
+ accel_var
+ );
+ auto sig_mode = "sigmoid accel mode:" % (
+ make_accel_cmd<accel_sigmoid>(args, "sigmoid"),
+ accel_var,
+ limit_var,
+ (clipp::required("midpoint") & clipp::number("speed", args.acc_fn_args.acc_args.midpoint)) % "midpoint"
+ );
+ auto pow_mode = "power accel mode:" % (
+ make_accel_cmd<accel_power>(args, "power"),
+ exp_var,
+ (clipp::option("scale") & clipp::number("num", args.acc_fn_args.acc_args.power_scale)) % "scale factor"
+ );
+
+ auto accel_mode_exclusive = (lin_mode | classic_mode | nat_mode | log_mode | sig_mode | pow_mode);
+ auto accel_opts = "mode-independent accel options:" % (opt_cap, opt_weight, opt_offset, opt_tmin);
+
+ bool help = false;
+
+ auto cli = clipp::group(clipp::command("help").set(help)) | (
+ noaccel_mode | (accel_mode_exclusive, accel_opts),
+ opt_sens,
+ opt_rot
+ );
+
+ if (!clipp::parse(argc, argv, cli)) {
+ std::cout << clipp::usage_lines(cli, "rawaccel", make_doc_fmt());
+ std::exit(PARSE_ERROR);
+ }
+
+ if (help) {
+ std::cout << clipp::make_man_page(cli, "rawaccel", make_doc_fmt());
+ std::exit(0);
+ }
+
+ return mouse_modifier(args);
+ }
+
+} // rawaccel
diff --git a/rawaccel.sln b/rawaccel.sln
index 0db5ecb..3325e47 100644
--- a/rawaccel.sln
+++ b/rawaccel.sln
@@ -23,9 +23,9 @@ Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
common-install\common-install.vcxitems*{058d66c6-d88b-4fdb-b0e4-0a6fe7483b95}*SharedItemsImports = 9
common\common.vcxitems*{24b4226f-1461-408f-a1a4-1371c97153ea}*SharedItemsImports = 9
- common\common.vcxitems*{28a3656f-a1de-405c-b547-191c32ec555f}*SharedItemsImports = 4
common-install\common-install.vcxitems*{896950d1-520a-420a-b6b1-73014b92a68c}*SharedItemsImports = 4
common-install\common-install.vcxitems*{a4097ff6-a6f0-44e8-b8d0-538d0fb75936}*SharedItemsImports = 4
+ common\common.vcxitems*{ab7b3759-b85f-4067-8935-fb4539b41869}*SharedItemsImports = 4
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU