From b374c35758777f98e5ddbe4b0dc43bd7c80f36d7 Mon Sep 17 00:00:00 2001 From: Zandr Martin Date: Thu, 1 Sep 2016 21:39:08 -0500 Subject: refactor commands.c --- sway/commands/input/accel_profile.c | 26 ++++++++++++++++++++++++++ sway/commands/input/click_method.c | 29 +++++++++++++++++++++++++++++ sway/commands/input/drag_lock.c | 25 +++++++++++++++++++++++++ sway/commands/input/dwt.c | 25 +++++++++++++++++++++++++ sway/commands/input/events.c | 29 +++++++++++++++++++++++++++++ sway/commands/input/middle_emulation.c | 25 +++++++++++++++++++++++++ sway/commands/input/natural_scroll.c | 25 +++++++++++++++++++++++++ sway/commands/input/pointer_accel.c | 24 ++++++++++++++++++++++++ sway/commands/input/scroll_method.c | 29 +++++++++++++++++++++++++++++ sway/commands/input/tap.c | 28 ++++++++++++++++++++++++++++ 10 files changed, 265 insertions(+) create mode 100644 sway/commands/input/accel_profile.c create mode 100644 sway/commands/input/click_method.c create mode 100644 sway/commands/input/drag_lock.c create mode 100644 sway/commands/input/dwt.c create mode 100644 sway/commands/input/events.c create mode 100644 sway/commands/input/middle_emulation.c create mode 100644 sway/commands/input/natural_scroll.c create mode 100644 sway/commands/input/pointer_accel.c create mode 100644 sway/commands/input/scroll_method.c create mode 100644 sway/commands/input/tap.c (limited to 'sway/commands/input') diff --git a/sway/commands/input/accel_profile.c b/sway/commands/input/accel_profile.c new file mode 100644 index 00000000..bfc3c76d --- /dev/null +++ b/sway/commands/input/accel_profile.c @@ -0,0 +1,26 @@ +#include +#include "commands.h" +#include "input.h" + +struct cmd_results *input_cmd_accel_profile(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "accel_profile", EXPECTED_AT_LEAST, 1))) { + return error; + } + if (!current_input_config) { + return cmd_results_new(CMD_FAILURE, "accel_profile", "No input device defined."); + } + struct input_config *new_config = new_input_config(current_input_config->identifier); + + if (strcasecmp(argv[0], "adaptive") == 0) { + new_config->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE; + } else if (strcasecmp(argv[0], "flat") == 0) { + new_config->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT; + } else { + return cmd_results_new(CMD_INVALID, "accel_profile", + "Expected 'accel_profile '"); + } + + input_cmd_apply(new_config); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/commands/input/click_method.c b/sway/commands/input/click_method.c new file mode 100644 index 00000000..2001acf2 --- /dev/null +++ b/sway/commands/input/click_method.c @@ -0,0 +1,29 @@ +#include +#include "commands.h" +#include "input.h" +#include "log.h" + +struct cmd_results *input_cmd_click_method(int argc, char **argv) { + sway_log(L_DEBUG, "click_method for device: %d %s", current_input_config==NULL, current_input_config->identifier); + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "click_method", EXPECTED_AT_LEAST, 1))) { + return error; + } + if (!current_input_config) { + return cmd_results_new(CMD_FAILURE, "click_method", "No input device defined."); + } + struct input_config *new_config = new_input_config(current_input_config->identifier); + + if (strcasecmp(argv[0], "none") == 0) { + new_config->click_method = LIBINPUT_CONFIG_CLICK_METHOD_NONE; + } else if (strcasecmp(argv[0], "button_areas") == 0) { + new_config->click_method = LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS; + } else if (strcasecmp(argv[0], "clickfinger") == 0) { + new_config->click_method = LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER; + } else { + return cmd_results_new(CMD_INVALID, "click_method", "Expected 'click_method +#include "commands.h" +#include "input.h" + +struct cmd_results *input_cmd_drag_lock(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "drag_lock", EXPECTED_AT_LEAST, 1))) { + return error; + } + if (!current_input_config) { + return cmd_results_new(CMD_FAILURE, "drag_lock", "No input device defined."); + } + struct input_config *new_config = new_input_config(current_input_config->identifier); + + if (strcasecmp(argv[0], "enabled") == 0) { + new_config->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_ENABLED; + } else if (strcasecmp(argv[0], "disabled") == 0) { + new_config->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_DISABLED; + } else { + return cmd_results_new(CMD_INVALID, "drag_lock", "Expected 'drag_lock '"); + } + + input_cmd_apply(new_config); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/commands/input/dwt.c b/sway/commands/input/dwt.c new file mode 100644 index 00000000..4010126d --- /dev/null +++ b/sway/commands/input/dwt.c @@ -0,0 +1,25 @@ +#include +#include "commands.h" +#include "input.h" + +struct cmd_results *input_cmd_dwt(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "dwt", EXPECTED_AT_LEAST, 1))) { + return error; + } + if (!current_input_config) { + return cmd_results_new(CMD_FAILURE, "dwt", "No input device defined."); + } + struct input_config *new_config = new_input_config(current_input_config->identifier); + + if (strcasecmp(argv[0], "enabled") == 0) { + new_config->dwt = LIBINPUT_CONFIG_DWT_ENABLED; + } else if (strcasecmp(argv[0], "disabled") == 0) { + new_config->dwt = LIBINPUT_CONFIG_DWT_DISABLED; + } else { + return cmd_results_new(CMD_INVALID, "dwt", "Expected 'dwt '"); + } + + input_cmd_apply(new_config); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/commands/input/events.c b/sway/commands/input/events.c new file mode 100644 index 00000000..9bf9aa95 --- /dev/null +++ b/sway/commands/input/events.c @@ -0,0 +1,29 @@ +#include +#include "commands.h" +#include "input.h" +#include "log.h" + +struct cmd_results *input_cmd_events(int argc, char **argv) { + sway_log(L_DEBUG, "events for device: %s", current_input_config->identifier); + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "events", EXPECTED_AT_LEAST, 1))) { + return error; + } + if (!current_input_config) { + return cmd_results_new(CMD_FAILURE, "events", "No input device defined."); + } + struct input_config *new_config = new_input_config(current_input_config->identifier); + + if (strcasecmp(argv[0], "enabled") == 0) { + new_config->send_events = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; + } else if (strcasecmp(argv[0], "disabled") == 0) { + new_config->send_events = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED; + } else if (strcasecmp(argv[0], "disabled_on_external_mouse") == 0) { + new_config->send_events = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE; + } else { + return cmd_results_new(CMD_INVALID, "events", "Expected 'events '"); + } + + input_cmd_apply(new_config); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/commands/input/middle_emulation.c b/sway/commands/input/middle_emulation.c new file mode 100644 index 00000000..e3087f3a --- /dev/null +++ b/sway/commands/input/middle_emulation.c @@ -0,0 +1,25 @@ +#include +#include "commands.h" +#include "input.h" + +struct cmd_results *input_cmd_middle_emulation(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "middle_emulation", EXPECTED_AT_LEAST, 1))) { + return error; + } + if (!current_input_config) { + return cmd_results_new(CMD_FAILURE, "middle_emulation", "No input device defined."); + } + struct input_config *new_config = new_input_config(current_input_config->identifier); + + if (strcasecmp(argv[0], "enabled") == 0) { + new_config->middle_emulation = LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED; + } else if (strcasecmp(argv[0], "disabled") == 0) { + new_config->middle_emulation = LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED; + } else { + return cmd_results_new(CMD_INVALID, "middle_emulation", "Expected 'middle_emulation '"); + } + + input_cmd_apply(new_config); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/commands/input/natural_scroll.c b/sway/commands/input/natural_scroll.c new file mode 100644 index 00000000..393f26a0 --- /dev/null +++ b/sway/commands/input/natural_scroll.c @@ -0,0 +1,25 @@ +#include +#include "commands.h" +#include "input.h" + +struct cmd_results *input_cmd_natural_scroll(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "natural_scroll", EXPECTED_AT_LEAST, 1))) { + return error; + } + if (!current_input_config) { + return cmd_results_new(CMD_FAILURE, "natural_scoll", "No input device defined."); + } + struct input_config *new_config = new_input_config(current_input_config->identifier); + + if (strcasecmp(argv[0], "enabled") == 0) { + new_config->natural_scroll = 1; + } else if (strcasecmp(argv[0], "disabled") == 0) { + new_config->natural_scroll = 0; + } else { + return cmd_results_new(CMD_INVALID, "natural_scroll", "Expected 'natural_scroll '"); + } + + input_cmd_apply(new_config); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/commands/input/pointer_accel.c b/sway/commands/input/pointer_accel.c new file mode 100644 index 00000000..e22c51c1 --- /dev/null +++ b/sway/commands/input/pointer_accel.c @@ -0,0 +1,24 @@ +#include +#include +#include "commands.h" +#include "input.h" + +struct cmd_results *input_cmd_pointer_accel(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "pointer_accel", EXPECTED_AT_LEAST, 1))) { + return error; + } + if (!current_input_config) { + return cmd_results_new(CMD_FAILURE, "pointer_accel", "No input device defined."); + } + struct input_config *new_config = new_input_config(current_input_config->identifier); + + float pointer_accel = atof(argv[0]); + if (pointer_accel < -1 || pointer_accel > 1) { + return cmd_results_new(CMD_INVALID, "pointer_accel", "Input out of range [-1, 1]"); + } + new_config->pointer_accel = pointer_accel; + + input_cmd_apply(new_config); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/commands/input/scroll_method.c b/sway/commands/input/scroll_method.c new file mode 100644 index 00000000..8e900a26 --- /dev/null +++ b/sway/commands/input/scroll_method.c @@ -0,0 +1,29 @@ +#include +#include "commands.h" +#include "input.h" + +struct cmd_results *input_cmd_scroll_method(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "scroll_method", EXPECTED_AT_LEAST, 1))) { + return error; + } + if (!current_input_config) { + return cmd_results_new(CMD_FAILURE, "scroll_method", "No input device defined."); + } + struct input_config *new_config = new_input_config(current_input_config->identifier); + + if (strcasecmp(argv[0], "none") == 0) { + new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_NO_SCROLL; + } else if (strcasecmp(argv[0], "two_finger") == 0) { + new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_2FG; + } else if (strcasecmp(argv[0], "edge") == 0) { + new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_EDGE; + } else if (strcasecmp(argv[0], "on_button_down") == 0) { + new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; + } else { + return cmd_results_new(CMD_INVALID, "scroll_method", "Expected 'scroll_method '"); + } + + input_cmd_apply(new_config); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/commands/input/tap.c b/sway/commands/input/tap.c new file mode 100644 index 00000000..8180dcea --- /dev/null +++ b/sway/commands/input/tap.c @@ -0,0 +1,28 @@ +#include +#include "commands.h" +#include "input.h" +#include "log.h" + +struct cmd_results *input_cmd_tap(int argc, char **argv) { + sway_log(L_DEBUG, "tap for device: %s", current_input_config->identifier); + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "tap", EXPECTED_AT_LEAST, 1))) { + return error; + } + if (!current_input_config) { + return cmd_results_new(CMD_FAILURE, "tap", "No input device defined."); + } + struct input_config *new_config = new_input_config(current_input_config->identifier); + + if (strcasecmp(argv[0], "enabled") == 0) { + new_config->tap = LIBINPUT_CONFIG_TAP_ENABLED; + } else if (strcasecmp(argv[0], "disabled") == 0) { + new_config->tap = LIBINPUT_CONFIG_TAP_DISABLED; + } else { + return cmd_results_new(CMD_INVALID, "tap", "Expected 'tap '"); + } + + sway_log(L_DEBUG, "apply-tap for device: %s", current_input_config->identifier); + input_cmd_apply(new_config); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} -- cgit v1.2.3 From 65ace5dec5c24695501056376e227fb9b1f84a3a Mon Sep 17 00:00:00 2001 From: Zandr Martin Date: Fri, 2 Sep 2016 14:11:48 -0500 Subject: merge in latest commits --- sway/commands/input/accel_profile.c | 4 ++-- sway/commands/input/click_method.c | 4 ++-- sway/commands/input/drag_lock.c | 4 ++-- sway/commands/input/dwt.c | 4 ++-- sway/commands/input/events.c | 4 ++-- sway/commands/input/middle_emulation.c | 4 ++-- sway/commands/input/natural_scroll.c | 4 ++-- sway/commands/input/pointer_accel.c | 4 ++-- sway/commands/input/scroll_method.c | 4 ++-- sway/commands/input/tap.c | 4 ++-- 10 files changed, 20 insertions(+), 20 deletions(-) (limited to 'sway/commands/input') diff --git a/sway/commands/input/accel_profile.c b/sway/commands/input/accel_profile.c index bfc3c76d..290129f5 100644 --- a/sway/commands/input/accel_profile.c +++ b/sway/commands/input/accel_profile.c @@ -1,6 +1,6 @@ #include -#include "commands.h" -#include "input.h" +#include "sway/commands.h" +#include "sway/input.h" struct cmd_results *input_cmd_accel_profile(int argc, char **argv) { struct cmd_results *error = NULL; diff --git a/sway/commands/input/click_method.c b/sway/commands/input/click_method.c index 2001acf2..0a7b7d23 100644 --- a/sway/commands/input/click_method.c +++ b/sway/commands/input/click_method.c @@ -1,6 +1,6 @@ #include -#include "commands.h" -#include "input.h" +#include "sway/commands.h" +#include "sway/input.h" #include "log.h" struct cmd_results *input_cmd_click_method(int argc, char **argv) { diff --git a/sway/commands/input/drag_lock.c b/sway/commands/input/drag_lock.c index 7bb2e334..0d100dd0 100644 --- a/sway/commands/input/drag_lock.c +++ b/sway/commands/input/drag_lock.c @@ -1,6 +1,6 @@ #include -#include "commands.h" -#include "input.h" +#include "sway/commands.h" +#include "sway/input.h" struct cmd_results *input_cmd_drag_lock(int argc, char **argv) { struct cmd_results *error = NULL; diff --git a/sway/commands/input/dwt.c b/sway/commands/input/dwt.c index 4010126d..82013730 100644 --- a/sway/commands/input/dwt.c +++ b/sway/commands/input/dwt.c @@ -1,6 +1,6 @@ #include -#include "commands.h" -#include "input.h" +#include "sway/commands.h" +#include "sway/input.h" struct cmd_results *input_cmd_dwt(int argc, char **argv) { struct cmd_results *error = NULL; diff --git a/sway/commands/input/events.c b/sway/commands/input/events.c index 9bf9aa95..2f13e30a 100644 --- a/sway/commands/input/events.c +++ b/sway/commands/input/events.c @@ -1,6 +1,6 @@ #include -#include "commands.h" -#include "input.h" +#include "sway/commands.h" +#include "sway/input.h" #include "log.h" struct cmd_results *input_cmd_events(int argc, char **argv) { diff --git a/sway/commands/input/middle_emulation.c b/sway/commands/input/middle_emulation.c index e3087f3a..b2e55468 100644 --- a/sway/commands/input/middle_emulation.c +++ b/sway/commands/input/middle_emulation.c @@ -1,6 +1,6 @@ #include -#include "commands.h" -#include "input.h" +#include "sway/commands.h" +#include "sway/input.h" struct cmd_results *input_cmd_middle_emulation(int argc, char **argv) { struct cmd_results *error = NULL; diff --git a/sway/commands/input/natural_scroll.c b/sway/commands/input/natural_scroll.c index 393f26a0..ac8cec12 100644 --- a/sway/commands/input/natural_scroll.c +++ b/sway/commands/input/natural_scroll.c @@ -1,6 +1,6 @@ #include -#include "commands.h" -#include "input.h" +#include "sway/commands.h" +#include "sway/input.h" struct cmd_results *input_cmd_natural_scroll(int argc, char **argv) { struct cmd_results *error = NULL; diff --git a/sway/commands/input/pointer_accel.c b/sway/commands/input/pointer_accel.c index e22c51c1..94f595d1 100644 --- a/sway/commands/input/pointer_accel.c +++ b/sway/commands/input/pointer_accel.c @@ -1,7 +1,7 @@ #include #include -#include "commands.h" -#include "input.h" +#include "sway/commands.h" +#include "sway/input.h" struct cmd_results *input_cmd_pointer_accel(int argc, char **argv) { struct cmd_results *error = NULL; diff --git a/sway/commands/input/scroll_method.c b/sway/commands/input/scroll_method.c index 8e900a26..de032b64 100644 --- a/sway/commands/input/scroll_method.c +++ b/sway/commands/input/scroll_method.c @@ -1,6 +1,6 @@ #include -#include "commands.h" -#include "input.h" +#include "sway/commands.h" +#include "sway/input.h" struct cmd_results *input_cmd_scroll_method(int argc, char **argv) { struct cmd_results *error = NULL; diff --git a/sway/commands/input/tap.c b/sway/commands/input/tap.c index 8180dcea..9b559447 100644 --- a/sway/commands/input/tap.c +++ b/sway/commands/input/tap.c @@ -1,6 +1,6 @@ #include -#include "commands.h" -#include "input.h" +#include "sway/commands.h" +#include "sway/input.h" #include "log.h" struct cmd_results *input_cmd_tap(int argc, char **argv) { -- cgit v1.2.3