2017-12-11 10:17:14 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <strings.h>
|
|
|
|
#include "sway/commands.h"
|
|
|
|
#include "sway/input/input-manager.h"
|
2019-05-23 09:06:28 +02:00
|
|
|
#include "sway/input/keyboard.h"
|
2017-12-11 10:17:14 +01:00
|
|
|
#include "log.h"
|
2018-05-30 19:20:02 +02:00
|
|
|
#include "stringop.h"
|
|
|
|
|
|
|
|
// must be in order for the bsearch
|
2021-02-03 01:54:35 +01:00
|
|
|
static const struct cmd_handler input_handlers[] = {
|
2018-05-30 19:20:02 +02:00
|
|
|
{ "accel_profile", input_cmd_accel_profile },
|
2019-06-17 11:38:41 +02:00
|
|
|
{ "calibration_matrix", input_cmd_calibration_matrix },
|
2018-05-30 19:20:02 +02:00
|
|
|
{ "click_method", input_cmd_click_method },
|
2018-09-29 11:49:41 +02:00
|
|
|
{ "drag", input_cmd_drag },
|
2018-05-30 19:20:02 +02:00
|
|
|
{ "drag_lock", input_cmd_drag_lock },
|
|
|
|
{ "dwt", input_cmd_dwt },
|
2022-08-24 01:13:12 +02:00
|
|
|
{ "dwtp", input_cmd_dwtp },
|
2018-05-30 19:20:02 +02:00
|
|
|
{ "events", input_cmd_events },
|
|
|
|
{ "left_handed", input_cmd_left_handed },
|
|
|
|
{ "map_from_region", input_cmd_map_from_region },
|
|
|
|
{ "map_to_output", input_cmd_map_to_output },
|
2019-10-29 01:26:00 +01:00
|
|
|
{ "map_to_region", input_cmd_map_to_region },
|
2018-05-30 19:20:02 +02:00
|
|
|
{ "middle_emulation", input_cmd_middle_emulation },
|
|
|
|
{ "natural_scroll", input_cmd_natural_scroll },
|
|
|
|
{ "pointer_accel", input_cmd_pointer_accel },
|
|
|
|
{ "repeat_delay", input_cmd_repeat_delay },
|
|
|
|
{ "repeat_rate", input_cmd_repeat_rate },
|
2022-12-09 22:22:09 +01:00
|
|
|
{ "rotation_angle", input_cmd_rotation_angle },
|
2018-07-11 22:03:06 +02:00
|
|
|
{ "scroll_button", input_cmd_scroll_button },
|
2023-06-16 11:28:30 +02:00
|
|
|
{ "scroll_button_lock", input_cmd_scroll_button_lock },
|
2018-11-17 20:31:33 +01:00
|
|
|
{ "scroll_factor", input_cmd_scroll_factor },
|
2018-05-30 19:20:02 +02:00
|
|
|
{ "scroll_method", input_cmd_scroll_method },
|
|
|
|
{ "tap", input_cmd_tap },
|
2018-07-14 07:01:47 +02:00
|
|
|
{ "tap_button_map", input_cmd_tap_button_map },
|
2020-06-19 20:11:57 +02:00
|
|
|
{ "tool_mode", input_cmd_tool_mode },
|
2019-07-13 04:04:29 +02:00
|
|
|
{ "xkb_file", input_cmd_xkb_file },
|
2018-05-30 19:20:02 +02:00
|
|
|
{ "xkb_layout", input_cmd_xkb_layout },
|
|
|
|
{ "xkb_model", input_cmd_xkb_model },
|
|
|
|
{ "xkb_options", input_cmd_xkb_options },
|
|
|
|
{ "xkb_rules", input_cmd_xkb_rules },
|
2019-06-09 20:17:28 +02:00
|
|
|
{ "xkb_switch_layout", input_cmd_xkb_switch_layout },
|
2018-05-30 19:20:02 +02:00
|
|
|
{ "xkb_variant", input_cmd_xkb_variant },
|
|
|
|
};
|
2017-12-11 10:17:14 +01:00
|
|
|
|
2018-07-25 17:08:47 +02:00
|
|
|
// must be in order for the bsearch
|
2021-02-03 01:54:35 +01:00
|
|
|
static const struct cmd_handler input_config_handlers[] = {
|
2018-07-25 17:08:47 +02:00
|
|
|
{ "xkb_capslock", input_cmd_xkb_capslock },
|
|
|
|
{ "xkb_numlock", input_cmd_xkb_numlock },
|
|
|
|
};
|
|
|
|
|
2017-12-11 10:17:14 +01:00
|
|
|
struct cmd_results *cmd_input(int argc, char **argv) {
|
|
|
|
struct cmd_results *error = NULL;
|
2018-06-27 15:40:44 +02:00
|
|
|
if ((error = checkarg(argc, "input", EXPECTED_AT_LEAST, 2))) {
|
2017-12-11 10:17:14 +01:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2019-01-20 19:51:12 +01:00
|
|
|
sway_log(SWAY_DEBUG, "entering input block: %s", argv[0]);
|
2017-12-11 10:17:14 +01:00
|
|
|
|
2018-05-30 19:20:02 +02:00
|
|
|
config->handler_context.input_config = new_input_config(argv[0]);
|
|
|
|
if (!config->handler_context.input_config) {
|
2019-01-11 00:27:21 +01:00
|
|
|
return cmd_results_new(CMD_FAILURE, "Couldn't allocate config");
|
2018-01-20 17:32:07 +01:00
|
|
|
}
|
|
|
|
|
2018-07-25 17:08:47 +02:00
|
|
|
struct cmd_results *res;
|
|
|
|
|
|
|
|
if (find_handler(argv[1], input_config_handlers,
|
|
|
|
sizeof(input_config_handlers))) {
|
|
|
|
if (config->reading) {
|
|
|
|
res = config_subcommand(argv + 1, argc - 1,
|
|
|
|
input_config_handlers, sizeof(input_config_handlers));
|
|
|
|
} else {
|
2019-01-11 00:27:21 +01:00
|
|
|
res = cmd_results_new(CMD_FAILURE,
|
2018-07-25 17:08:47 +02:00
|
|
|
"Can only be used in config file.");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
res = config_subcommand(argv + 1, argc - 1,
|
2018-05-31 04:23:11 +02:00
|
|
|
input_handlers, sizeof(input_handlers));
|
2018-07-25 17:08:47 +02:00
|
|
|
}
|
2017-12-19 11:26:55 +01:00
|
|
|
|
2019-06-09 20:17:28 +02:00
|
|
|
if ((!res || res->status == CMD_SUCCESS) &&
|
|
|
|
strcmp(argv[1], "xkb_switch_layout") != 0) {
|
2019-05-23 09:06:28 +02:00
|
|
|
char *error = NULL;
|
2019-06-05 20:16:37 +02:00
|
|
|
struct input_config *ic =
|
|
|
|
store_input_config(config->handler_context.input_config, &error);
|
|
|
|
if (!ic) {
|
|
|
|
free_input_config(config->handler_context.input_config);
|
2019-05-23 09:06:28 +02:00
|
|
|
if (res) {
|
|
|
|
free_cmd_results(res);
|
|
|
|
}
|
|
|
|
res = cmd_results_new(CMD_FAILURE, "Failed to compile keymap: %s",
|
|
|
|
error ? error : "(details unavailable)");
|
|
|
|
free(error);
|
|
|
|
return res;
|
|
|
|
}
|
2018-09-24 01:56:52 +02:00
|
|
|
|
2019-11-27 01:43:06 +01:00
|
|
|
if (!config->reloading) {
|
|
|
|
input_manager_apply_input_config(ic);
|
|
|
|
}
|
2018-09-24 01:56:52 +02:00
|
|
|
} else {
|
|
|
|
free_input_config(config->handler_context.input_config);
|
|
|
|
}
|
|
|
|
|
2018-05-30 19:20:02 +02:00
|
|
|
config->handler_context.input_config = NULL;
|
2018-01-20 17:32:07 +01:00
|
|
|
|
2017-12-19 11:26:55 +01:00
|
|
|
return res;
|
2017-12-11 10:17:14 +01:00
|
|
|
}
|