aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands.c')
-rw-r--r--sway/commands.c104
1 files changed, 77 insertions, 27 deletions
diff --git a/sway/commands.c b/sway/commands.c
index d6cf7a64..7485f2f6 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,40 @@ 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 sway_input_manager_apply_input_config(input_manager, input);
75}
76
77void seat_cmd_apply(struct seat_config *seat) {
78 int i;
79 i = list_seq_find(config->seat_configs, seat_name_cmp, seat->name);
80 if (i >= 0) {
81 // merge existing config
82 struct seat_config *sc = config->seat_configs->items[i];
83 merge_seat_config(sc, seat);
84 free_seat_config(seat);
85 seat = sc;
86 } else {
87 list_add(config->seat_configs, seat);
88 }
89
90 current_seat_config = seat;
91 sway_input_manager_apply_seat_config(input_manager, seat);
92}
93
59/** 94/**
60 * Check and add color to buffer. 95 * Check and add color to buffer.
61 * 96 *
@@ -96,7 +131,9 @@ static struct cmd_handler handlers[] = {
96 { "exec_always", cmd_exec_always }, 131 { "exec_always", cmd_exec_always },
97 { "exit", cmd_exit }, 132 { "exit", cmd_exit },
98 { "include", cmd_include }, 133 { "include", cmd_include },
134 { "input", cmd_input },
99 { "output", cmd_output }, 135 { "output", cmd_output },
136 { "seat", cmd_seat },
100}; 137};
101 138
102static int handler_compare(const void *_a, const void *_b) { 139static int handler_compare(const void *_a, const void *_b) {
@@ -105,37 +142,50 @@ static int handler_compare(const void *_a, const void *_b) {
105 return strcasecmp(a->command, b->command); 142 return strcasecmp(a->command, b->command);
106} 143}
107 144
145// must be in order for the bsearch
146static struct cmd_handler input_handlers[] = {
147 { "accel_profile", input_cmd_accel_profile },
148 { "click_method", input_cmd_click_method },
149 { "drag_lock", input_cmd_drag_lock },
150 { "dwt", input_cmd_dwt },
151 { "events", input_cmd_events },
152 { "left_handed", input_cmd_left_handed },
153 { "middle_emulation", input_cmd_middle_emulation },
154 { "natural_scroll", input_cmd_natural_scroll },
155 { "pointer_accel", input_cmd_pointer_accel },
156 { "scroll_method", input_cmd_scroll_method },
157 { "tap", input_cmd_tap },
158 { "xkb_layout", input_cmd_xkb_layout },
159 { "xkb_model", input_cmd_xkb_model },
160 { "xkb_options", input_cmd_xkb_options },
161 { "xkb_rules", input_cmd_xkb_rules },
162 { "xkb_variant", input_cmd_xkb_variant },
163};
164
165// must be in order for the bsearch
166static struct cmd_handler seat_handlers[] = {
167 { "attach", seat_cmd_attach },
168};
169
108static struct cmd_handler *find_handler(char *line, enum cmd_status block) { 170static struct cmd_handler *find_handler(char *line, enum cmd_status block) {
109 struct cmd_handler d = { .command=line }; 171 struct cmd_handler d = { .command=line };
110 struct cmd_handler *res = NULL; 172 struct cmd_handler *res = NULL;
111 sway_log(L_DEBUG, "find_handler(%s) %d", line, block == CMD_BLOCK_INPUT); 173 sway_log(L_DEBUG, "find_handler(%s) %d", line, block == CMD_BLOCK_SEAT);
112 /* TODO 174
113 if (block == CMD_BLOCK_BAR) { 175 if (block == CMD_BLOCK_INPUT) {
114 res = bsearch(&d, bar_handlers,
115 sizeof(bar_handlers) / sizeof(struct cmd_handler),
116 sizeof(struct cmd_handler), handler_compare);
117 } else if (block == CMD_BLOCK_BAR_COLORS){
118 res = bsearch(&d, bar_colors_handlers,
119 sizeof(bar_colors_handlers) / sizeof(struct cmd_handler),
120 sizeof(struct cmd_handler), handler_compare);
121 } else if (block == CMD_BLOCK_INPUT) {
122 res = bsearch(&d, input_handlers, 176 res = bsearch(&d, input_handlers,
123 sizeof(input_handlers) / sizeof(struct cmd_handler), 177 sizeof(input_handlers) / sizeof(struct cmd_handler),
124 sizeof(struct cmd_handler), handler_compare); 178 sizeof(struct cmd_handler), handler_compare);
125 } else if (block == CMD_BLOCK_IPC) { 179 } else if (block == CMD_BLOCK_SEAT) {
126 res = bsearch(&d, ipc_handlers, 180 res = bsearch(&d, seat_handlers,
127 sizeof(ipc_handlers) / sizeof(struct cmd_handler), 181 sizeof(seat_handlers) / sizeof(struct cmd_handler),
128 sizeof(struct cmd_handler), handler_compare); 182 sizeof(struct cmd_handler), handler_compare);
129 } else if (block == CMD_BLOCK_IPC_EVENTS) {
130 res = bsearch(&d, ipc_event_handlers,
131 sizeof(ipc_event_handlers) / sizeof(struct cmd_handler),
132 sizeof(struct cmd_handler), handler_compare);
133 } else { 183 } else {
134 */
135 res = bsearch(&d, handlers, 184 res = bsearch(&d, handlers,
136 sizeof(handlers) / sizeof(struct cmd_handler), 185 sizeof(handlers) / sizeof(struct cmd_handler),
137 sizeof(struct cmd_handler), handler_compare); 186 sizeof(struct cmd_handler), handler_compare);
138 //} 187 }
188
139 return res; 189 return res;
140} 190}
141 191
@@ -239,8 +289,8 @@ struct cmd_results *config_command(char *exec, enum cmd_status block) {
239 argv[i] = do_var_replacement(argv[i]); 289 argv[i] = do_var_replacement(argv[i]);
240 unescape_string(argv[i]); 290 unescape_string(argv[i]);
241 } 291 }
242 /* Strip quotes for first argument. 292 // Strip quotes for first argument.
243 * TODO This part needs to be handled much better */ 293 // TODO This part needs to be handled much better
244 if (argc>1 && (*argv[1] == '\"' || *argv[1] == '\'')) { 294 if (argc>1 && (*argv[1] == '\"' || *argv[1] == '\'')) {
245 strip_quotes(argv[1]); 295 strip_quotes(argv[1]);
246 } 296 }