Skip to content

Commit

Permalink
Add mouse_flip_x_, mouse_flip_y_, mouse_flip_vertical_wheel_, mouse_f…
Browse files Browse the repository at this point in the history
…lip_horizontal_wheel_ to core_configuration::details::profile::device
  • Loading branch information
tekezo committed Sep 20, 2023
1 parent e355c98 commit 7c07928
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 2 deletions.
70 changes: 69 additions & 1 deletion src/share/core_configuration/details/profile/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ class device final {
ignore_(false),
manipulate_caps_lock_led_(false),
treat_as_built_in_keyboard_(false),
disable_built_in_keyboard_if_exists_(false) {
disable_built_in_keyboard_if_exists_(false),
mouse_flip_x_(false),
mouse_flip_y_(false),
mouse_flip_vertical_wheel_(false),
mouse_flip_horizontal_wheel_(false) {
auto ignore_configured = false;
auto manipulate_caps_lock_led_configured = false;

Expand Down Expand Up @@ -57,6 +61,26 @@ class device final {

disable_built_in_keyboard_if_exists_ = value.get<bool>();

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

mouse_flip_x_ = value.get<bool>();

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

mouse_flip_y_ = value.get<bool>();

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

mouse_flip_vertical_wheel_ = value.get<bool>();

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

mouse_flip_horizontal_wheel_ = value.get<bool>();

} else if (key == "simple_modifications") {
try {
simple_modifications_.update(value);
Expand Down Expand Up @@ -124,6 +148,10 @@ class device final {
j["manipulate_caps_lock_led"] = manipulate_caps_lock_led_;
j["treat_as_built_in_keyboard"] = treat_as_built_in_keyboard_;
j["disable_built_in_keyboard_if_exists"] = disable_built_in_keyboard_if_exists_;
j["mouse_flip_x"] = mouse_flip_x_;
j["mouse_flip_y"] = mouse_flip_y_;
j["mouse_flip_vertical_wheel"] = mouse_flip_vertical_wheel_;
j["mouse_flip_horizontal_wheel"] = mouse_flip_horizontal_wheel_;
j["simple_modifications"] = simple_modifications_.to_json();
j["fn_function_keys"] = fn_function_keys_.to_json();
return j;
Expand Down Expand Up @@ -169,6 +197,42 @@ class device final {
coordinate_between_properties();
}

bool get_mouse_flip_x(void) const {
return mouse_flip_x_;
}
void set_mouse_flip_x(bool value) {
mouse_flip_x_ = value;

coordinate_between_properties();
}

bool get_mouse_flip_y(void) const {
return mouse_flip_y_;
}
void set_mouse_flip_y(bool value) {
mouse_flip_y_ = value;

coordinate_between_properties();
}

bool get_mouse_flip_vertical_wheel(void) const {
return mouse_flip_vertical_wheel_;
}
void set_mouse_flip_vertical_wheel(bool value) {
mouse_flip_vertical_wheel_ = value;

coordinate_between_properties();
}

bool get_mouse_flip_horizontal_wheel(void) const {
return mouse_flip_horizontal_wheel_;
}
void set_mouse_flip_horizontal_wheel(bool value) {
mouse_flip_horizontal_wheel_ = value;

coordinate_between_properties();
}

const simple_modifications& get_simple_modifications(void) const {
return simple_modifications_;
}
Expand Down Expand Up @@ -199,6 +263,10 @@ class device final {
bool manipulate_caps_lock_led_;
bool treat_as_built_in_keyboard_;
bool disable_built_in_keyboard_if_exists_;
bool mouse_flip_x_;
bool mouse_flip_y_;
bool mouse_flip_vertical_wheel_;
bool mouse_flip_horizontal_wheel_;
simple_modifications simple_modifications_;
simple_modifications fn_function_keys_;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,46 @@
"error": "`disable_built_in_keyboard_if_exists` must be boolean, but is `null`"
},

// mouse_flip_x

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

// mouse_flip_y

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

// mouse_flip_vertical_wheel

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

// mouse_flip_horizontal_wheel

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

// simple_modifications

{
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_flip_horizontal_wheel": false,
"mouse_flip_vertical_wheel": false,
"mouse_flip_x": false,
"mouse_flip_y": false,
"simple_modifications": [
{
"from": {
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 @@ -138,6 +138,10 @@
},
"ignore": false,
"manipulate_caps_lock_led": true,
"mouse_flip_horizontal_wheel": false,
"mouse_flip_vertical_wheel": false,
"mouse_flip_x": false,
"mouse_flip_y": false,
"simple_modifications": [
{
"from": {
Expand All @@ -164,6 +168,10 @@
},
"ignore": true,
"manipulate_caps_lock_led": true,
"mouse_flip_horizontal_wheel": false,
"mouse_flip_vertical_wheel": false,
"mouse_flip_x": false,
"mouse_flip_y": false,
"simple_modifications": [],
"treat_as_built_in_keyboard": false
},
Expand Down Expand Up @@ -200,6 +208,10 @@
},
"ignore": false,
"manipulate_caps_lock_led": true,
"mouse_flip_horizontal_wheel": false,
"mouse_flip_vertical_wheel": false,
"mouse_flip_x": false,
"mouse_flip_y": false,
"simple_modifications": [
{
"from": {
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_flip_horizontal_wheel", false},
{"mouse_flip_vertical_wheel", false},
{"mouse_flip_x", false},
{"mouse_flip_y", false},
{"treat_as_built_in_keyboard", false},
},
}},
Expand Down Expand Up @@ -845,6 +849,10 @@ void run_core_configuration_test(void) {
{"disable_built_in_keyboard_if_exists", true},
{"fn_function_keys", nlohmann::json::array()},
{"manipulate_caps_lock_led", false},
{"mouse_flip_horizontal_wheel", false},
{"mouse_flip_vertical_wheel", false},
{"mouse_flip_x", false},
{"mouse_flip_y", false},
{"simple_modifications", nlohmann::json::array()},
{"treat_as_built_in_keyboard", 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 @@ -290,6 +290,10 @@ void run_device_test(void) {
{"ignore", false},
{"fn_function_keys", nlohmann::json::array()},
{"manipulate_caps_lock_led", false},
{"mouse_flip_horizontal_wheel", false},
{"mouse_flip_vertical_wheel", false},
{"mouse_flip_x", false},
{"mouse_flip_y", false},
{"simple_modifications", nlohmann::json::array()},
{"treat_as_built_in_keyboard", false},
});
Expand All @@ -314,6 +318,8 @@ void run_device_test(void) {
{"ignore", true},
{"manipulate_caps_lock_led", true},
{"treat_as_built_in_keyboard", true},
{"mouse_flip_horizontal_wheel", true},
{"mouse_flip_x", true},
});
krbn::core_configuration::details::device device(json);
nlohmann::json expected({
Expand Down Expand Up @@ -348,6 +354,10 @@ void run_device_test(void) {
}},
{"ignore", true},
{"manipulate_caps_lock_led", true},
{"mouse_flip_horizontal_wheel", true},
{"mouse_flip_vertical_wheel", false},
{"mouse_flip_x", true},
{"mouse_flip_y", false},
{"simple_modifications", nlohmann::json::array()},
{"treat_as_built_in_keyboard", true},
});
Expand Down
2 changes: 1 addition & 1 deletion tests/src/core_configuration/src/errors_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void run_errors_test(void) {
handle_json(e);
expect(false);
} catch (pqrs::json::unmarshal_error& ex) {
expect(e.at("error").get<std::string>() == ex.what());
expect(std::string_view(e.at("error").get<std::string>()) == ex.what());
} catch (...) {
expect(false);
}
Expand Down

0 comments on commit 7c07928

Please sign in to comment.