diff options
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 105 |
1 files changed, 78 insertions, 27 deletions
diff --git a/sway/commands.c b/sway/commands.c index d6cf7a64..34afb6a0 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 | ||
60 | void apply_input_config(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 | |||
77 | void apply_seat_config(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 | ||
102 | static int handler_compare(const void *_a, const void *_b) { | 139 | static int handler_compare(const void *_a, const void *_b) { |
@@ -105,37 +142,51 @@ 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 | ||
146 | static 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 | ||
166 | static struct cmd_handler seat_handlers[] = { | ||
167 | { "attach", seat_cmd_attach }, | ||
168 | { "fallback", seat_cmd_fallback }, | ||
169 | }; | ||
170 | |||
108 | static struct cmd_handler *find_handler(char *line, enum cmd_status block) { | 171 | static struct cmd_handler *find_handler(char *line, enum cmd_status block) { |
109 | struct cmd_handler d = { .command=line }; | 172 | struct cmd_handler d = { .command=line }; |
110 | struct cmd_handler *res = NULL; | 173 | struct cmd_handler *res = NULL; |
111 | sway_log(L_DEBUG, "find_handler(%s) %d", line, block == CMD_BLOCK_INPUT); | 174 | sway_log(L_DEBUG, "find_handler(%s) %d", line, block == CMD_BLOCK_SEAT); |
112 | /* TODO | 175 | |
113 | if (block == CMD_BLOCK_BAR) { | 176 | 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, | 177 | res = bsearch(&d, input_handlers, |
123 | sizeof(input_handlers) / sizeof(struct cmd_handler), | 178 | sizeof(input_handlers) / sizeof(struct cmd_handler), |
124 | sizeof(struct cmd_handler), handler_compare); | 179 | sizeof(struct cmd_handler), handler_compare); |
125 | } else if (block == CMD_BLOCK_IPC) { | 180 | } else if (block == CMD_BLOCK_SEAT) { |
126 | res = bsearch(&d, ipc_handlers, | 181 | res = bsearch(&d, seat_handlers, |
127 | sizeof(ipc_handlers) / sizeof(struct cmd_handler), | 182 | sizeof(seat_handlers) / sizeof(struct cmd_handler), |
128 | sizeof(struct cmd_handler), handler_compare); | 183 | 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 { | 184 | } else { |
134 | */ | ||
135 | res = bsearch(&d, handlers, | 185 | res = bsearch(&d, handlers, |
136 | sizeof(handlers) / sizeof(struct cmd_handler), | 186 | sizeof(handlers) / sizeof(struct cmd_handler), |
137 | sizeof(struct cmd_handler), handler_compare); | 187 | sizeof(struct cmd_handler), handler_compare); |
138 | //} | 188 | } |
189 | |||
139 | return res; | 190 | return res; |
140 | } | 191 | } |
141 | 192 | ||
@@ -239,8 +290,8 @@ struct cmd_results *config_command(char *exec, enum cmd_status block) { | |||
239 | argv[i] = do_var_replacement(argv[i]); | 290 | argv[i] = do_var_replacement(argv[i]); |
240 | unescape_string(argv[i]); | 291 | unescape_string(argv[i]); |
241 | } | 292 | } |
242 | /* Strip quotes for first argument. | 293 | // Strip quotes for first argument. |
243 | * TODO This part needs to be handled much better */ | 294 | // TODO This part needs to be handled much better |
244 | if (argc>1 && (*argv[1] == '\"' || *argv[1] == '\'')) { | 295 | if (argc>1 && (*argv[1] == '\"' || *argv[1] == '\'')) { |
245 | strip_quotes(argv[1]); | 296 | strip_quotes(argv[1]); |
246 | } | 297 | } |