2017-12-11 20:17:14 +11:00
|
|
|
#include <string.h>
|
|
|
|
#include <strings.h>
|
|
|
|
#include "sway/commands.h"
|
|
|
|
#include "sway/input/input-manager.h"
|
2019-05-23 17:06:28 +10:00
|
|
|
#include "sway/input/keyboard.h"
|
2017-12-11 20:17:14 +11:00
|
|
|
#include "log.h"
|
2018-05-31 03:20:02 +10:00
|
|
|
#include "stringop.h"
|
|
|
|
|
|
|
|
// must be in order for the bsearch
|
|
|
|
static struct cmd_handler input_handlers[] = {
|
|
|
|
{ "accel_profile", input_cmd_accel_profile },
|
2019-06-17 19:38:41 +10:00
|
|
|
{ "calibration_matrix", input_cmd_calibration_matrix },
|
2018-05-31 03:20:02 +10:00
|
|
|
{ "click_method", input_cmd_click_method },
|
2018-09-29 19:49:41 +10:00
|
|
|
{ "drag", input_cmd_drag },
|
2018-05-31 03:20:02 +10:00
|
|
|
{ "drag_lock", input_cmd_drag_lock },
|
|
|
|
{ "dwt", input_cmd_dwt },
|
|
|
|
{ "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 },
|
|
|
|
{ "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 },
|
2018-07-12 06:03:06 +10:00
|
|
|
{ "scroll_button", input_cmd_scroll_button },
|
2018-11-18 06:31:33 +11:00
|
|
|
{ "scroll_factor", input_cmd_scroll_factor },
|
2018-05-31 03:20:02 +10:00
|
|
|
{ "scroll_method", input_cmd_scroll_method },
|
|
|
|
{ "tap", input_cmd_tap },
|
2018-07-14 15:01:47 +10:00
|
|
|
{ "tap_button_map", input_cmd_tap_button_map },
|
2019-07-13 12:04:29 +10:00
|
|
|
{ "xkb_file", input_cmd_xkb_file },
|
2018-05-31 03:20:02 +10: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-10 04:17:28 +10:00
|
|
|
{ "xkb_switch_layout", input_cmd_xkb_switch_layout },
|
2018-05-31 03:20:02 +10:00
|
|
|
{ "xkb_variant", input_cmd_xkb_variant },
|
|
|
|
};
|
2017-12-11 20:17:14 +11:00
|
|
|
|
2018-07-26 01:08:47 +10:00
|
|
|
// must be in order for the bsearch
|
|
|
|
static struct cmd_handler input_config_handlers[] = {
|
|
|
|
{ "xkb_capslock", input_cmd_xkb_capslock },
|
|
|
|
{ "xkb_numlock", input_cmd_xkb_numlock },
|
|
|
|
};
|
|
|
|
|
2019-02-18 03:08:22 +11:00
|
|
|
/**
|
|
|
|
* Re-translate keysyms if a change in the input config could affect them.
|
|
|
|
*/
|
|
|
|
static void retranslate_keysyms(struct input_config *input_config) {
|
|
|
|
for (int i = 0; i < config->input_configs->length; ++i) {
|
|
|
|
struct input_config *ic = config->input_configs->items[i];
|
2019-07-13 12:04:29 +10:00
|
|
|
if (ic->xkb_layout || ic->xkb_file) {
|
|
|
|
// this is the first config with xkb_layout or xkb_file
|
2019-02-20 05:17:07 +11:00
|
|
|
if (ic->identifier == input_config->identifier) {
|
2019-02-20 22:54:59 +11:00
|
|
|
translate_keysyms(ic);
|
2019-02-18 03:08:22 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-11 20:17:14 +11:00
|
|
|
struct cmd_results *cmd_input(int argc, char **argv) {
|
|
|
|
struct cmd_results *error = NULL;
|
2018-06-27 23:40:44 +10:00
|
|
|
if ((error = checkarg(argc, "input", EXPECTED_AT_LEAST, 2))) {
|
2017-12-11 20:17:14 +11:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2019-01-21 05:51:12 +11:00
|
|
|
sway_log(SWAY_DEBUG, "entering input block: %s", argv[0]);
|
2017-12-11 20:17:14 +11:00
|
|
|
|
2018-05-31 03:20:02 +10:00
|
|
|
config->handler_context.input_config = new_input_config(argv[0]);
|
|
|
|
if (!config->handler_context.input_config) {
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_FAILURE, "Couldn't allocate config");
|
2018-01-21 03:32:07 +11:00
|
|
|
}
|
|
|
|
|
2018-07-26 01:08:47 +10: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 10:27:21 +11:00
|
|
|
res = cmd_results_new(CMD_FAILURE,
|
2018-07-26 01:08:47 +10:00
|
|
|
"Can only be used in config file.");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
res = config_subcommand(argv + 1, argc - 1,
|
2018-05-31 12:23:11 +10:00
|
|
|
input_handlers, sizeof(input_handlers));
|
2018-07-26 01:08:47 +10:00
|
|
|
}
|
2017-12-19 21:26:55 +11:00
|
|
|
|
2019-06-10 04:17:28 +10:00
|
|
|
if ((!res || res->status == CMD_SUCCESS) &&
|
|
|
|
strcmp(argv[1], "xkb_switch_layout") != 0) {
|
2019-05-23 17:06:28 +10:00
|
|
|
char *error = NULL;
|
2019-06-06 04:16:37 +10: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 17:06:28 +10: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 09:56:52 +10:00
|
|
|
|
2018-10-18 22:20:00 +11:00
|
|
|
input_manager_apply_input_config(ic);
|
2019-02-18 03:08:22 +11:00
|
|
|
retranslate_keysyms(ic);
|
2018-09-24 09:56:52 +10:00
|
|
|
} else {
|
|
|
|
free_input_config(config->handler_context.input_config);
|
|
|
|
}
|
|
|
|
|
2018-05-31 03:20:02 +10:00
|
|
|
config->handler_context.input_config = NULL;
|
2018-01-21 03:32:07 +11:00
|
|
|
|
2017-12-19 21:26:55 +11:00
|
|
|
return res;
|
2017-12-11 20:17:14 +11:00
|
|
|
}
|