aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands.c
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2017-12-11 04:17:14 -0500
committerLibravatar Tony Crisci <tony@dubstepdish.com>2017-12-11 07:55:01 -0500
commit462a451328a1d6f0b17d34b431d6bf3dec87c1ba (patch)
tree56649e0702d13e8a7dd5143b5b7d2b9db094a1a7 /sway/commands.c
parentsway pointer (diff)
downloadsway-462a451328a1d6f0b17d34b431d6bf3dec87c1ba.tar.gz
sway-462a451328a1d6f0b17d34b431d6bf3dec87c1ba.tar.zst
sway-462a451328a1d6f0b17d34b431d6bf3dec87c1ba.zip
input config
Diffstat (limited to 'sway/commands.c')
-rw-r--r--sway/commands.c90
1 files changed, 64 insertions, 26 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 05a66a7f..7710c6ab 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -9,6 +9,7 @@
9#include "sway/commands.h" 9#include "sway/commands.h"
10#include "sway/config.h" 10#include "sway/config.h"
11#include "sway/security.h" 11#include "sway/security.h"
12#include "sway/input/input-manager.h"
12#include "stringop.h" 13#include "stringop.h"
13#include "log.h" 14#include "log.h"
14 15
@@ -56,6 +57,44 @@ struct cmd_results *checkarg(int argc, const char *name, enum expected_args type
56 return error; 57 return error;
57} 58}
58 59
60void input_cmd_apply(struct input_config *input) {
61 int i;
62 i = list_seq_find(config->input_configs, input_identifier_cmp, input->identifier);
63 if (i >= 0) {
64 // merge existing config
65 struct input_config *ic = config->input_configs->items[i];
66 merge_input_config(ic, input);
67 free_input_config(input);
68 input = ic;
69 } else {
70 list_add(config->input_configs, input);
71 }
72
73 current_input_config = input;
74
75 if (input->identifier) {
76 // Try to find the input device and apply configuration now. If
77 // this is during startup then there will be no container and config
78 // will be applied during normal "new input" event from wlc.
79 /* TODO WLR
80 struct libinput_device *device = NULL;
81 for (int i = 0; i < input_devices->length; ++i) {
82 device = input_devices->items[i];
83 char* dev_identifier = libinput_dev_unique_id(device);
84 if (!dev_identifier) {
85 break;
86 }
87 int match = dev_identifier && strcmp(dev_identifier, input->identifier) == 0;
88 free(dev_identifier);
89 if (match) {
90 apply_input_config(input, device);
91 break;
92 }
93 }
94 */
95 }
96}
97
59/** 98/**
60 * Check and add color to buffer. 99 * Check and add color to buffer.
61 * 100 *
@@ -96,6 +135,7 @@ static struct cmd_handler handlers[] = {
96 { "exec_always", cmd_exec_always }, 135 { "exec_always", cmd_exec_always },
97 { "exit", cmd_exit }, 136 { "exit", cmd_exit },
98 { "include", cmd_include }, 137 { "include", cmd_include },
138 { "input", cmd_input },
99}; 139};
100 140
101static int handler_compare(const void *_a, const void *_b) { 141static int handler_compare(const void *_a, const void *_b) {
@@ -104,37 +144,35 @@ static int handler_compare(const void *_a, const void *_b) {
104 return strcasecmp(a->command, b->command); 144 return strcasecmp(a->command, b->command);
105} 145}
106 146
147static struct cmd_handler input_handlers[] = {
148 { "accel_profile", input_cmd_accel_profile },
149 { "click_method", input_cmd_click_method },
150 { "drag_lock", input_cmd_drag_lock },
151 { "dwt", input_cmd_dwt },
152 { "events", input_cmd_events },
153 { "left_handed", input_cmd_left_handed },
154 { "middle_emulation", input_cmd_middle_emulation },
155 { "natural_scroll", input_cmd_natural_scroll },
156 { "pointer_accel", input_cmd_pointer_accel },
157 { "scroll_method", input_cmd_scroll_method },
158 { "tap", input_cmd_tap },
159};
160
107static struct cmd_handler *find_handler(char *line, enum cmd_status block) { 161static struct cmd_handler *find_handler(char *line, enum cmd_status block) {
108 struct cmd_handler d = { .command=line }; 162 struct cmd_handler d = { .command=line };
109 struct cmd_handler *res = NULL; 163 struct cmd_handler *res = NULL;
110 sway_log(L_DEBUG, "find_handler(%s) %d", line, block == CMD_BLOCK_INPUT); 164 sway_log(L_DEBUG, "find_handler(%s) %d", line, block == CMD_BLOCK_INPUT);
111 /* TODO 165
112 if (block == CMD_BLOCK_BAR) { 166 if (block == CMD_BLOCK_INPUT) {
113 res = bsearch(&d, bar_handlers,
114 sizeof(bar_handlers) / sizeof(struct cmd_handler),
115 sizeof(struct cmd_handler), handler_compare);
116 } else if (block == CMD_BLOCK_BAR_COLORS){
117 res = bsearch(&d, bar_colors_handlers,
118 sizeof(bar_colors_handlers) / sizeof(struct cmd_handler),
119 sizeof(struct cmd_handler), handler_compare);
120 } else if (block == CMD_BLOCK_INPUT) {
121 res = bsearch(&d, input_handlers, 167 res = bsearch(&d, input_handlers,
122 sizeof(input_handlers) / sizeof(struct cmd_handler), 168 sizeof(input_handlers) / sizeof(struct cmd_handler),
123 sizeof(struct cmd_handler), handler_compare); 169 sizeof(struct cmd_handler), handler_compare);
124 } else if (block == CMD_BLOCK_IPC) {
125 res = bsearch(&d, ipc_handlers,
126 sizeof(ipc_handlers) / sizeof(struct cmd_handler),
127 sizeof(struct cmd_handler), handler_compare);
128 } else if (block == CMD_BLOCK_IPC_EVENTS) {
129 res = bsearch(&d, ipc_event_handlers,
130 sizeof(ipc_event_handlers) / sizeof(struct cmd_handler),
131 sizeof(struct cmd_handler), handler_compare);
132 } else { 170 } else {
133 */
134 res = bsearch(&d, handlers, 171 res = bsearch(&d, handlers,
135 sizeof(handlers) / sizeof(struct cmd_handler), 172 sizeof(handlers) / sizeof(struct cmd_handler),
136 sizeof(struct cmd_handler), handler_compare); 173 sizeof(struct cmd_handler), handler_compare);
137 //} 174 }
175
138 return res; 176 return res;
139} 177}
140 178
@@ -238,8 +276,8 @@ struct cmd_results *config_command(char *exec, enum cmd_status block) {
238 argv[i] = do_var_replacement(argv[i]); 276 argv[i] = do_var_replacement(argv[i]);
239 unescape_string(argv[i]); 277 unescape_string(argv[i]);
240 } 278 }
241 /* Strip quotes for first argument. 279 // Strip quotes for first argument.
242 * TODO This part needs to be handled much better */ 280 // TODO This part needs to be handled much better
243 if (argc>1 && (*argv[1] == '\"' || *argv[1] == '\'')) { 281 if (argc>1 && (*argv[1] == '\"' || *argv[1] == '\'')) {
244 strip_quotes(argv[1]); 282 strip_quotes(argv[1]);
245 } 283 }