Skip to content

Commit

Permalink
Add mouse_discard_* into profile::device
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Feb 29, 2024
1 parent c062388 commit 6c46064
Show file tree
Hide file tree
Showing 8 changed files with 242 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,27 @@ class simple_modifications_manipulator_manager final {
swap.push_back("wheels");
}

if (flip.size() > 0 || swap.size() > 0) {
auto discard = nlohmann::json::array();
if (device.get_mouse_discard_x()) {
discard.push_back("x");
}
if (device.get_mouse_discard_y()) {
discard.push_back("y");
}
if (device.get_mouse_discard_vertical_wheel()) {
discard.push_back("vertical_wheel");
}
if (device.get_mouse_discard_horizontal_wheel()) {
discard.push_back("horizontal_wheel");
}

if (flip.size() > 0 || swap.size() > 0 || discard.size() > 0) {
try {
auto json = nlohmann::json::object({
{"type", "mouse_basic"},
{"flip", flip},
{"swap", swap},
{"discard", discard},
});
auto parameters = krbn::core_configuration::details::complex_modifications_parameters();
auto m = std::make_shared<manipulator::manipulators::mouse_basic::mouse_basic>(json,
Expand Down
84 changes: 84 additions & 0 deletions src/share/core_configuration/details/profile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,90 @@ class profile final {
}
}

bool get_device_mouse_discard_x(const device_identifiers& identifiers) const {
for (const auto& d : devices_) {
if (d.get_identifiers() == identifiers) {
return d.get_mouse_discard_x();
}
}
return false;
}

void set_device_mouse_discard_x(const device_identifiers& identifiers,
bool value) {
add_device(identifiers);

for (auto&& device : devices_) {
if (device.get_identifiers() == identifiers) {
device.set_mouse_discard_x(value);
return;
}
}
}

bool get_device_mouse_discard_y(const device_identifiers& identifiers) const {
for (const auto& d : devices_) {
if (d.get_identifiers() == identifiers) {
return d.get_mouse_discard_y();
}
}
return false;
}

void set_device_mouse_discard_y(const device_identifiers& identifiers,
bool value) {
add_device(identifiers);

for (auto&& device : devices_) {
if (device.get_identifiers() == identifiers) {
device.set_mouse_discard_y(value);
return;
}
}
}

bool get_device_mouse_discard_vertical_wheel(const device_identifiers& identifiers) const {
for (const auto& d : devices_) {
if (d.get_identifiers() == identifiers) {
return d.get_mouse_discard_vertical_wheel();
}
}
return false;
}

void set_device_mouse_discard_vertical_wheel(const device_identifiers& identifiers,
bool value) {
add_device(identifiers);

for (auto&& device : devices_) {
if (device.get_identifiers() == identifiers) {
device.set_mouse_discard_vertical_wheel(value);
return;
}
}
}

bool get_device_mouse_discard_horizontal_wheel(const device_identifiers& identifiers) const {
for (const auto& d : devices_) {
if (d.get_identifiers() == identifiers) {
return d.get_mouse_discard_horizontal_wheel();
}
}
return false;
}

void set_device_mouse_discard_horizontal_wheel(const device_identifiers& identifiers,
bool value) {
add_device(identifiers);

for (auto&& device : devices_) {
if (device.get_identifiers() == identifiers) {
device.set_mouse_discard_horizontal_wheel(value);
return;
}
}
}

bool get_device_game_pad_swap_sticks(const device_identifiers& identifiers) const {
for (const auto& d : devices_) {
if (d.get_identifiers() == identifiers) {
Expand Down
68 changes: 68 additions & 0 deletions src/share/core_configuration/details/profile/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ if (abs(cos(radian)) <= abs(sin(radian))) {
mouse_flip_horizontal_wheel_(false),
mouse_swap_xy_(false),
mouse_swap_wheels_(false),
mouse_discard_x_(false),
mouse_discard_y_(false),
mouse_discard_vertical_wheel_(false),
mouse_discard_horizontal_wheel_(false),
game_pad_swap_sticks_(false) {
auto ignore_configured = false;
auto manipulate_caps_lock_led_configured = false;
Expand Down Expand Up @@ -156,6 +160,26 @@ if (abs(cos(radian)) <= abs(sin(radian))) {

mouse_swap_wheels_ = value.get<bool>();

} else if (key == "mouse_discard_x") {
pqrs::json::requires_boolean(value, "`" + key + "`");

mouse_discard_x_ = value.get<bool>();

} else if (key == "mouse_discard_y") {
pqrs::json::requires_boolean(value, "`" + key + "`");

mouse_discard_y_ = value.get<bool>();

} else if (key == "mouse_discard_vertical_wheel") {
pqrs::json::requires_boolean(value, "`" + key + "`");

mouse_discard_vertical_wheel_ = value.get<bool>();

} else if (key == "mouse_discard_horizontal_wheel") {
pqrs::json::requires_boolean(value, "`" + key + "`");

mouse_discard_horizontal_wheel_ = value.get<bool>();

} else if (key == "game_pad_swap_sticks") {
pqrs::json::requires_boolean(value, "`" + key + "`");

Expand Down Expand Up @@ -276,6 +300,10 @@ if (abs(cos(radian)) <= abs(sin(radian))) {
j["mouse_flip_horizontal_wheel"] = mouse_flip_horizontal_wheel_;
j["mouse_swap_xy"] = mouse_swap_xy_;
j["mouse_swap_wheels"] = mouse_swap_wheels_;
j["mouse_discard_x"] = mouse_discard_x_;
j["mouse_discard_y"] = mouse_discard_y_;
j["mouse_discard_vertical_wheel"] = mouse_discard_vertical_wheel_;
j["mouse_discard_horizontal_wheel"] = mouse_discard_horizontal_wheel_;
j["game_pad_swap_sticks"] = game_pad_swap_sticks_;

#define OPTIONAL_SETTING(name) \
Expand Down Expand Up @@ -411,6 +439,42 @@ if (abs(cos(radian)) <= abs(sin(radian))) {
coordinate_between_properties();
}

bool get_mouse_discard_x(void) const {
return mouse_discard_x_;
}
void set_mouse_discard_x(bool value) {
mouse_discard_x_ = value;

coordinate_between_properties();
}

bool get_mouse_discard_y(void) const {
return mouse_discard_y_;
}
void set_mouse_discard_y(bool value) {
mouse_discard_y_ = value;

coordinate_between_properties();
}

bool get_mouse_discard_vertical_wheel(void) const {
return mouse_discard_vertical_wheel_;
}
void set_mouse_discard_vertical_wheel(bool value) {
mouse_discard_vertical_wheel_ = value;

coordinate_between_properties();
}

bool get_mouse_discard_horizontal_wheel(void) const {
return mouse_discard_horizontal_wheel_;
}
void set_mouse_discard_horizontal_wheel(bool value) {
mouse_discard_horizontal_wheel_ = value;

coordinate_between_properties();
}

bool get_game_pad_swap_sticks(void) const {
return game_pad_swap_sticks_;
}
Expand Down Expand Up @@ -601,6 +665,10 @@ if (abs(cos(radian)) <= abs(sin(radian))) {
bool mouse_flip_horizontal_wheel_;
bool mouse_swap_xy_;
bool mouse_swap_wheels_;
bool mouse_discard_x_;
bool mouse_discard_y_;
bool mouse_discard_vertical_wheel_;
bool mouse_discard_horizontal_wheel_;
bool game_pad_swap_sticks_;
std::optional<double> game_pad_xy_stick_continued_movement_absolute_magnitude_threshold_;
std::optional<int> game_pad_xy_stick_continued_movement_interval_milliseconds_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,46 @@
"error": "`mouse_swap_wheels` must be boolean, but is `null`"
},

// mouse_discard_x

{
"class": "devices",
"input": {
"mouse_discard_x": null
},
"error": "`mouse_discard_x` must be boolean, but is `null`"
},

// mouse_discard_y

{
"class": "devices",
"input": {
"mouse_discard_y": null
},
"error": "`mouse_discard_y` must be boolean, but is `null`"
},

// mouse_discard_vertical_wheel

{
"class": "devices",
"input": {
"mouse_discard_vertical_wheel": null
},
"error": "`mouse_discard_vertical_wheel` must be boolean, but is `null`"
},

// mouse_discard_horizontal_wheel

{
"class": "devices",
"input": {
"mouse_discard_horizontal_wheel": null
},
"error": "`mouse_discard_horizontal_wheel` must be boolean, but is `null`"
},

// game_pad_swap_sticks

{
Expand Down
4 changes: 4 additions & 0 deletions tests/src/core_configuration/json/example.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@
"is_pointing_device": false
},
"ignore": false,
"mouse_discard_horizontal_wheel": false,
"mouse_discard_vertical_wheel": false,
"mouse_discard_x": false,
"mouse_discard_y": false,
"mouse_flip_horizontal_wheel": false,
"mouse_flip_vertical_wheel": false,
"mouse_flip_x": false,
Expand Down
12 changes: 12 additions & 0 deletions tests/src/core_configuration/json/to_json_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@
},
"ignore": false,
"manipulate_caps_lock_led": true,
"mouse_discard_horizontal_wheel": false,
"mouse_discard_vertical_wheel": false,
"mouse_discard_x": false,
"mouse_discard_y": false,
"mouse_flip_horizontal_wheel": false,
"mouse_flip_vertical_wheel": false,
"mouse_flip_x": false,
Expand Down Expand Up @@ -172,6 +176,10 @@
},
"ignore": true,
"manipulate_caps_lock_led": true,
"mouse_discard_horizontal_wheel": false,
"mouse_discard_vertical_wheel": false,
"mouse_discard_x": false,
"mouse_discard_y": false,
"mouse_flip_horizontal_wheel": false,
"mouse_flip_vertical_wheel": false,
"mouse_flip_x": false,
Expand Down Expand Up @@ -215,6 +223,10 @@
},
"ignore": false,
"manipulate_caps_lock_led": true,
"mouse_discard_horizontal_wheel": false,
"mouse_discard_vertical_wheel": false,
"mouse_discard_x": false,
"mouse_discard_y": false,
"mouse_flip_horizontal_wheel": false,
"mouse_flip_vertical_wheel": false,
"mouse_flip_x": false,
Expand Down
8 changes: 8 additions & 0 deletions tests/src/core_configuration/src/core_configuration_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,10 @@ void run_core_configuration_test(void) {
{"ignore", true},
{"disable_built_in_keyboard_if_exists", true},
{"manipulate_caps_lock_led", false},
{"mouse_discard_horizontal_wheel", false},
{"mouse_discard_vertical_wheel", false},
{"mouse_discard_x", false},
{"mouse_discard_y", false},
{"mouse_flip_horizontal_wheel", false},
{"mouse_flip_vertical_wheel", false},
{"mouse_flip_x", false},
Expand Down Expand Up @@ -853,6 +857,10 @@ void run_core_configuration_test(void) {
{"fn_function_keys", nlohmann::json::array()},
{"game_pad_swap_sticks", false},
{"manipulate_caps_lock_led", false},
{"mouse_discard_horizontal_wheel", false},
{"mouse_discard_vertical_wheel", false},
{"mouse_discard_x", false},
{"mouse_discard_y", false},
{"mouse_flip_horizontal_wheel", false},
{"mouse_flip_vertical_wheel", false},
{"mouse_flip_x", false},
Expand Down
10 changes: 10 additions & 0 deletions tests/src/core_configuration/src/device_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ void run_device_test(void) {
}},
{"ignore", false},
{"manipulate_caps_lock_led", false},
{"mouse_discard_horizontal_wheel", false},
{"mouse_discard_vertical_wheel", false},
{"mouse_discard_x", false},
{"mouse_discard_y", false},
{"mouse_flip_horizontal_wheel", false},
{"mouse_flip_vertical_wheel", false},
{"mouse_flip_x", false},
Expand Down Expand Up @@ -351,6 +355,8 @@ void run_device_test(void) {
{"ignore", true},
{"manipulate_caps_lock_led", true},
{"treat_as_built_in_keyboard", true},
{"mouse_discard_vertical_wheel", true},
{"mouse_discard_y", true},
{"mouse_flip_horizontal_wheel", true},
{"mouse_flip_x", true},
{"mouse_swap_wheels", true},
Expand Down Expand Up @@ -416,6 +422,10 @@ void run_device_test(void) {
{"game_pad_stick_vertical_wheel_formula", "sgn(sin(radian))"},
{"game_pad_stick_horizontal_wheel_formula", "sgn(cos(radian))"},
{"manipulate_caps_lock_led", true},
{"mouse_discard_horizontal_wheel", false},
{"mouse_discard_vertical_wheel", true},
{"mouse_discard_x", false},
{"mouse_discard_y", true},
{"mouse_flip_horizontal_wheel", true},
{"mouse_flip_vertical_wheel", false},
{"mouse_flip_x", true},
Expand Down

0 comments on commit 6c46064

Please sign in to comment.