Skip to content

Commit

Permalink
Merge pull request #3857 from pqrs-org/add-helper_values-to-complex_m…
Browse files Browse the repository at this point in the history
…odifications_parameters

Add helper values to complex modifications parameters
  • Loading branch information
tekezo authored Jun 30, 2024
2 parents 9e32011 + 28e58f4 commit 8a4adb0
Show file tree
Hide file tree
Showing 43 changed files with 578 additions and 681 deletions.
40 changes: 15 additions & 25 deletions src/apps/share/swift/LibKrbn/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,20 @@ extension LibKrbn {
updateComplexModificationsRules()

complexModificationsParameterToIfAloneTimeoutMilliseconds = Int(
libkrbn_core_configuration_get_selected_profile_complex_modifications_parameter(
"basic.to_if_alone_timeout_milliseconds"
))
libkrbn_core_configuration_get_selected_profile_complex_modifications_parameter_basic_to_if_alone_timeout_milliseconds()
)
complexModificationsParameterToIfHeldDownThresholdMilliseconds = Int(
libkrbn_core_configuration_get_selected_profile_complex_modifications_parameter(
"basic.to_if_held_down_threshold_milliseconds"
))
libkrbn_core_configuration_get_selected_profile_complex_modifications_parameter_basic_to_if_held_down_threshold_milliseconds()
)
complexModificationsParameterToDelayedActionDelayMilliseconds = Int(
libkrbn_core_configuration_get_selected_profile_complex_modifications_parameter(
"basic.to_delayed_action_delay_milliseconds"
))
libkrbn_core_configuration_get_selected_profile_complex_modifications_parameter_basic_to_delayed_action_delay_milliseconds()
)
complexModificationsParameterSimultaneousThresholdMilliseconds = Int(
libkrbn_core_configuration_get_selected_profile_complex_modifications_parameter(
"basic.simultaneous_threshold_milliseconds"
))
libkrbn_core_configuration_get_selected_profile_complex_modifications_parameter_basic_simultaneous_threshold_milliseconds()
)
complexModificationsParameterMouseMotionToScrollSpeed = Int(
libkrbn_core_configuration_get_selected_profile_complex_modifications_parameter(
"mouse_motion_to_scroll.speed"
))
libkrbn_core_configuration_get_selected_profile_complex_modifications_parameter_mouse_motion_to_scroll_speed()
)

updateConnectedDeviceSettings()

Expand Down Expand Up @@ -467,8 +462,7 @@ extension LibKrbn {
@Published var complexModificationsParameterToIfAloneTimeoutMilliseconds: Int = 0 {
didSet {
if didSetEnabled {
libkrbn_core_configuration_set_selected_profile_complex_modifications_parameter(
"basic.to_if_alone_timeout_milliseconds",
libkrbn_core_configuration_set_selected_profile_complex_modifications_parameter_basic_to_if_alone_timeout_milliseconds(
Int32(complexModificationsParameterToIfAloneTimeoutMilliseconds)
)
save()
Expand All @@ -479,8 +473,7 @@ extension LibKrbn {
@Published var complexModificationsParameterToIfHeldDownThresholdMilliseconds: Int = 0 {
didSet {
if didSetEnabled {
libkrbn_core_configuration_set_selected_profile_complex_modifications_parameter(
"basic.to_if_held_down_threshold_milliseconds",
libkrbn_core_configuration_set_selected_profile_complex_modifications_parameter_basic_to_if_held_down_threshold_milliseconds(
Int32(complexModificationsParameterToIfHeldDownThresholdMilliseconds)
)
save()
Expand All @@ -491,8 +484,7 @@ extension LibKrbn {
@Published var complexModificationsParameterToDelayedActionDelayMilliseconds: Int = 0 {
didSet {
if didSetEnabled {
libkrbn_core_configuration_set_selected_profile_complex_modifications_parameter(
"basic.to_delayed_action_delay_milliseconds",
libkrbn_core_configuration_set_selected_profile_complex_modifications_parameter_basic_to_delayed_action_delay_milliseconds(
Int32(complexModificationsParameterToDelayedActionDelayMilliseconds)
)
save()
Expand All @@ -503,8 +495,7 @@ extension LibKrbn {
@Published var complexModificationsParameterSimultaneousThresholdMilliseconds: Int = 0 {
didSet {
if didSetEnabled {
libkrbn_core_configuration_set_selected_profile_complex_modifications_parameter(
"basic.simultaneous_threshold_milliseconds",
libkrbn_core_configuration_set_selected_profile_complex_modifications_parameter_basic_simultaneous_threshold_milliseconds(
Int32(complexModificationsParameterSimultaneousThresholdMilliseconds)
)
save()
Expand All @@ -515,8 +506,7 @@ extension LibKrbn {
@Published var complexModificationsParameterMouseMotionToScrollSpeed: Int = 0 {
didSet {
if didSetEnabled {
libkrbn_core_configuration_set_selected_profile_complex_modifications_parameter(
"mouse_motion_to_scroll.speed",
libkrbn_core_configuration_set_selected_profile_complex_modifications_parameter_mouse_motion_to_scroll_speed(
Int32(complexModificationsParameterMouseMotionToScrollSpeed)
)
save()
Expand Down
3 changes: 2 additions & 1 deletion src/bin/cli/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ int main(int argc, char** argv) {
}

try {
auto assets_file = krbn::complex_modifications_assets_file(file_path.string());
auto assets_file = krbn::complex_modifications_assets_file(file_path.string(),
krbn::core_configuration::error_handling::strict);
auto error_messages = assets_file.lint();
if (error_messages.empty()) {
if (!silent) {
Expand Down
10 changes: 5 additions & 5 deletions src/core/grabber/include/grabber/device_grabber.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -952,12 +952,12 @@ class device_grabber final : public pqrs::dispatcher::extra::dispatcher_client {
void update_complex_modifications_manipulators(void) {
complex_modifications_manipulator_manager_->invalidate_manipulators();

for (const auto& rule : core_configuration_->get_selected_profile().get_complex_modifications().get_rules()) {
for (const auto& manipulator : rule.get_manipulators()) {
for (const auto& rule : core_configuration_->get_selected_profile().get_complex_modifications()->get_rules()) {
for (const auto& manipulator : rule->get_manipulators()) {
try {
auto m = manipulator::manipulator_factory::make_manipulator(manipulator.get_json(),
manipulator.get_parameters());
for (const auto& c : manipulator.get_conditions()) {
auto m = manipulator::manipulator_factory::make_manipulator(manipulator->get_json(),
manipulator->get_parameters());
for (const auto& c : manipulator->get_conditions()) {
m->push_back_condition(manipulator::manipulator_factory::make_condition(c.get_json()));
}
complex_modifications_manipulator_manager_->push_back_manipulator(m);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class simple_modifications_manipulator_manager final {
{"swap", swap},
{"discard", discard},
});
auto parameters = krbn::core_configuration::details::complex_modifications_parameters();
auto parameters = std::make_shared<krbn::core_configuration::details::complex_modifications_parameters>();
auto m = std::make_shared<manipulator::manipulators::mouse_basic::mouse_basic>(json,
parameters);
auto c = manipulator::manipulator_factory::make_device_if_condition(*device);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class libkrbn_complex_modifications_assets_manager final {
}

void reload(void) const {
manager_->reload(krbn::constants::get_user_complex_modifications_assets_directory());
manager_->reload(krbn::constants::get_user_complex_modifications_assets_directory(),
krbn::core_configuration::error_handling::loose);
}

size_t get_files_size(void) const {
Expand Down Expand Up @@ -73,25 +74,25 @@ class libkrbn_complex_modifications_assets_manager final {
size_t index,
krbn::core_configuration::core_configuration& core_configuration) const {
if (auto r = find_rule(file_index, index)) {
core_configuration.get_selected_profile().push_front_complex_modifications_rule(*r);
core_configuration.get_selected_profile().get_complex_modifications()->push_front_rule(r);
}
}

private:
const krbn::complex_modifications_assets_file* find_file(size_t index) const {
std::shared_ptr<krbn::complex_modifications_assets_file> find_file(size_t index) const {
auto& files = manager_->get_files();
if (index < files.size()) {
return &(files[index]);
return files[index];
}
return nullptr;
}

const krbn::core_configuration::details::complex_modifications_rule* find_rule(size_t file_index,
size_t index) const {
std::shared_ptr<krbn::core_configuration::details::complex_modifications_rule> find_rule(size_t file_index,
size_t index) const {
if (auto f = find_file(file_index)) {
auto& rules = f->get_rules();
if (index < rules.size()) {
return &(rules[index]);
return rules[index];
}
}
return nullptr;
Expand Down
19 changes: 16 additions & 3 deletions src/lib/libkrbn/include/libkrbn/libkrbn.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,22 @@ void libkrbn_core_configuration_push_front_selected_profile_complex_modification
size_t error_message_buffer_length);
void libkrbn_core_configuration_erase_selected_profile_complex_modifications_rule(size_t index);
void libkrbn_core_configuration_move_selected_profile_complex_modifications_rule(size_t source_index, size_t destination_index);
int libkrbn_core_configuration_get_selected_profile_complex_modifications_parameter(const char* name);
void libkrbn_core_configuration_set_selected_profile_complex_modifications_parameter(const char* name,
int value);

int libkrbn_core_configuration_get_selected_profile_complex_modifications_parameter_basic_simultaneous_threshold_milliseconds(void);
void libkrbn_core_configuration_set_selected_profile_complex_modifications_parameter_basic_simultaneous_threshold_milliseconds(int value);

int libkrbn_core_configuration_get_selected_profile_complex_modifications_parameter_basic_to_if_alone_timeout_milliseconds(void);
void libkrbn_core_configuration_set_selected_profile_complex_modifications_parameter_basic_to_if_alone_timeout_milliseconds(int value);

int libkrbn_core_configuration_get_selected_profile_complex_modifications_parameter_basic_to_if_held_down_threshold_milliseconds(void);
void libkrbn_core_configuration_set_selected_profile_complex_modifications_parameter_basic_to_if_held_down_threshold_milliseconds(int value);

int libkrbn_core_configuration_get_selected_profile_complex_modifications_parameter_basic_to_delayed_action_delay_milliseconds(void);
void libkrbn_core_configuration_set_selected_profile_complex_modifications_parameter_basic_to_delayed_action_delay_milliseconds(int value);

int libkrbn_core_configuration_get_selected_profile_complex_modifications_parameter_mouse_motion_to_scroll_speed(void);
void libkrbn_core_configuration_set_selected_profile_complex_modifications_parameter_mouse_motion_to_scroll_speed(int value);

void libkrbn_core_configuration_get_new_complex_modifications_rule_json_string(char* buffer,
size_t length);

Expand Down
Loading

0 comments on commit 8a4adb0

Please sign in to comment.