summaryrefslogtreecommitdiffstats
path: root/sway/input
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2018-04-02 16:09:27 -0400
committerLibravatar Tony Crisci <tony@dubstepdish.com>2018-04-02 16:09:27 -0400
commitd434da563239c43c5fe417ce83b23b417f2ab635 (patch)
treee154daaf43c42d11c5afb8b7739ae6b52dd01215 /sway/input
parentfix workspace splits (diff)
parentMerge pull request #1699 from acrisci/seat-fixes (diff)
downloadsway-d434da563239c43c5fe417ce83b23b417f2ab635.tar.gz
sway-d434da563239c43c5fe417ce83b23b417f2ab635.tar.zst
sway-d434da563239c43c5fe417ce83b23b417f2ab635.zip
Merge branch 'wlroots' into split-containers
Diffstat (limited to 'sway/input')
-rw-r--r--sway/input/cursor.c10
-rw-r--r--sway/input/input-manager.c144
-rw-r--r--sway/input/keyboard.c2
-rw-r--r--sway/input/seat.c102
4 files changed, 141 insertions, 117 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index d608a9cf..7d05e942 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -84,7 +84,7 @@ static struct sway_container *container_at_cursor(struct sway_cursor *cursor,
84 84
85 // find the focused workspace on the output for this seat 85 // find the focused workspace on the output for this seat
86 struct sway_container *ws = 86 struct sway_container *ws =
87 sway_seat_get_focus_inactive(cursor->seat, output->swayc); 87 seat_get_focus_inactive(cursor->seat, output->swayc);
88 if (ws && ws->type != C_WORKSPACE) { 88 if (ws && ws->type != C_WORKSPACE) {
89 ws = container_parent(ws, C_WORKSPACE); 89 ws = container_parent(ws, C_WORKSPACE);
90 } 90 }
@@ -129,7 +129,7 @@ static void cursor_send_pointer_motion(struct sway_cursor *cursor,
129 double sx, sy; 129 double sx, sy;
130 struct sway_container *c = container_at_cursor(cursor, &surface, &sx, &sy); 130 struct sway_container *c = container_at_cursor(cursor, &surface, &sx, &sy);
131 if (c && config->focus_follows_mouse) { 131 if (c && config->focus_follows_mouse) {
132 sway_seat_set_focus_warp(cursor->seat, c, false); 132 seat_set_focus_warp(cursor->seat, c, false);
133 } 133 }
134 134
135 // reset cursor if switching between clients 135 // reset cursor if switching between clients
@@ -191,15 +191,15 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) {
191 if (new_ws && new_ws->type != C_WORKSPACE) { 191 if (new_ws && new_ws->type != C_WORKSPACE) {
192 new_ws = container_parent(new_ws, C_WORKSPACE); 192 new_ws = container_parent(new_ws, C_WORKSPACE);
193 } 193 }
194 struct sway_container *old_ws = sway_seat_get_focus(cursor->seat); 194 struct sway_container *old_ws = seat_get_focus(cursor->seat);
195 if (old_ws && old_ws->type != C_WORKSPACE) { 195 if (old_ws && old_ws->type != C_WORKSPACE) {
196 old_ws = container_parent(old_ws, C_WORKSPACE); 196 old_ws = container_parent(old_ws, C_WORKSPACE);
197 } 197 }
198 if (new_ws != old_ws) { 198 if (new_ws != old_ws) {
199 sway_seat_set_focus(cursor->seat, cont); 199 seat_set_focus(cursor->seat, cont);
200 } 200 }
201 } else { 201 } else {
202 sway_seat_set_focus(cursor->seat, cont); 202 seat_set_focus(cursor->seat, cont);
203 } 203 }
204 204
205 wlr_seat_pointer_notify_button(cursor->seat->wlr_seat, event->time_msec, 205 wlr_seat_pointer_notify_button(cursor->seat->wlr_seat, event->time_msec,
diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c
index d421a03f..c3507f65 100644
--- a/sway/input/input-manager.c
+++ b/sway/input/input-manager.c
@@ -26,7 +26,7 @@ struct seat_config *current_seat_config = NULL;
26struct sway_seat *input_manager_current_seat(struct sway_input_manager *input) { 26struct sway_seat *input_manager_current_seat(struct sway_input_manager *input) {
27 struct sway_seat *seat = config->handler_context.seat; 27 struct sway_seat *seat = config->handler_context.seat;
28 if (!seat) { 28 if (!seat) {
29 seat = sway_input_manager_get_default_seat(input_manager); 29 seat = input_manager_get_default_seat(input_manager);
30 } 30 }
31 return seat; 31 return seat;
32} 32}
@@ -40,7 +40,7 @@ struct sway_seat *input_manager_get_seat(
40 } 40 }
41 } 41 }
42 42
43 return sway_seat_create(input, seat_name); 43 return seat_create(input, seat_name);
44} 44}
45 45
46static char *get_device_identifier(struct wlr_input_device *device) { 46static char *get_device_identifier(struct wlr_input_device *device) {
@@ -83,7 +83,8 @@ static struct sway_input_device *input_sway_device_from_wlr(
83static bool input_has_seat_configuration(struct sway_input_manager *input) { 83static bool input_has_seat_configuration(struct sway_input_manager *input) {
84 struct sway_seat *seat = NULL; 84 struct sway_seat *seat = NULL;
85 wl_list_for_each(seat, &input->seats, link) { 85 wl_list_for_each(seat, &input->seats, link) {
86 if (seat->config) { 86 struct seat_config *seat_config = seat_get_config(seat);
87 if (seat_config) {
87 return true; 88 return true;
88 } 89 }
89 } 90 }
@@ -91,9 +92,10 @@ static bool input_has_seat_configuration(struct sway_input_manager *input) {
91 return false; 92 return false;
92} 93}
93 94
94static void sway_input_manager_libinput_config_pointer(struct sway_input_device *input_device) { 95static void input_manager_libinput_config_pointer(
96 struct sway_input_device *input_device) {
95 struct wlr_input_device *wlr_device = input_device->wlr_device; 97 struct wlr_input_device *wlr_device = input_device->wlr_device;
96 struct input_config *ic = input_device->config; 98 struct input_config *ic = input_device_get_config(input_device);
97 struct libinput_device *libinput_device; 99 struct libinput_device *libinput_device;
98 100
99 if (!ic || !wlr_input_device_is_libinput(wlr_device)) { 101 if (!ic || !wlr_input_device_is_libinput(wlr_device)) {
@@ -101,22 +103,27 @@ static void sway_input_manager_libinput_config_pointer(struct sway_input_device
101 } 103 }
102 104
103 libinput_device = wlr_libinput_get_device_handle(wlr_device); 105 libinput_device = wlr_libinput_get_device_handle(wlr_device);
104 wlr_log(L_DEBUG, "sway_input_manager_libinput_config_pointer(%s)", ic->identifier); 106 wlr_log(L_DEBUG, "input_manager_libinput_config_pointer(%s)",
107 ic->identifier);
105 108
106 if (ic->accel_profile != INT_MIN) { 109 if (ic->accel_profile != INT_MIN) {
107 wlr_log(L_DEBUG, "libinput_config_pointer(%s) accel_set_profile(%d)", 110 wlr_log(L_DEBUG, "libinput_config_pointer(%s) accel_set_profile(%d)",
108 ic->identifier, ic->accel_profile); 111 ic->identifier, ic->accel_profile);
109 libinput_device_config_accel_set_profile(libinput_device, ic->accel_profile); 112 libinput_device_config_accel_set_profile(libinput_device,
113 ic->accel_profile);
110 } 114 }
111 if (ic->click_method != INT_MIN) { 115 if (ic->click_method != INT_MIN) {
112 wlr_log(L_DEBUG, "libinput_config_pointer(%s) click_set_method(%d)", 116 wlr_log(L_DEBUG, "libinput_config_pointer(%s) click_set_method(%d)",
113 ic->identifier, ic->click_method); 117 ic->identifier, ic->click_method);
114 libinput_device_config_click_set_method(libinput_device, ic->click_method); 118 libinput_device_config_click_set_method(libinput_device,
119 ic->click_method);
115 } 120 }
116 if (ic->drag_lock != INT_MIN) { 121 if (ic->drag_lock != INT_MIN) {
117 wlr_log(L_DEBUG, "libinput_config_pointer(%s) tap_set_drag_lock_enabled(%d)", 122 wlr_log(L_DEBUG,
123 "libinput_config_pointer(%s) tap_set_drag_lock_enabled(%d)",
118 ic->identifier, ic->click_method); 124 ic->identifier, ic->click_method);
119 libinput_device_config_tap_set_drag_lock_enabled(libinput_device, ic->drag_lock); 125 libinput_device_config_tap_set_drag_lock_enabled(libinput_device,
126 ic->drag_lock);
120 } 127 }
121 if (ic->dwt != INT_MIN) { 128 if (ic->dwt != INT_MIN) {
122 wlr_log(L_DEBUG, "libinput_config_pointer(%s) dwt_set_enabled(%d)", 129 wlr_log(L_DEBUG, "libinput_config_pointer(%s) dwt_set_enabled(%d)",
@@ -124,34 +131,43 @@ static void sway_input_manager_libinput_config_pointer(struct sway_input_device
124 libinput_device_config_dwt_set_enabled(libinput_device, ic->dwt); 131 libinput_device_config_dwt_set_enabled(libinput_device, ic->dwt);
125 } 132 }
126 if (ic->left_handed != INT_MIN) { 133 if (ic->left_handed != INT_MIN) {
127 wlr_log(L_DEBUG, "libinput_config_pointer(%s) left_handed_set_enabled(%d)", 134 wlr_log(L_DEBUG,
135 "libinput_config_pointer(%s) left_handed_set_enabled(%d)",
128 ic->identifier, ic->left_handed); 136 ic->identifier, ic->left_handed);
129 libinput_device_config_left_handed_set(libinput_device, ic->left_handed); 137 libinput_device_config_left_handed_set(libinput_device,
138 ic->left_handed);
130 } 139 }
131 if (ic->middle_emulation != INT_MIN) { 140 if (ic->middle_emulation != INT_MIN) {
132 wlr_log(L_DEBUG, "libinput_config_pointer(%s) middle_emulation_set_enabled(%d)", 141 wlr_log(L_DEBUG,
142 "libinput_config_pointer(%s) middle_emulation_set_enabled(%d)",
133 ic->identifier, ic->middle_emulation); 143 ic->identifier, ic->middle_emulation);
134 libinput_device_config_middle_emulation_set_enabled(libinput_device, ic->middle_emulation); 144 libinput_device_config_middle_emulation_set_enabled(libinput_device,
145 ic->middle_emulation);
135 } 146 }
136 if (ic->natural_scroll != INT_MIN) { 147 if (ic->natural_scroll != INT_MIN) {
137 wlr_log(L_DEBUG, "libinput_config_pointer(%s) natural_scroll_set_enabled(%d)", 148 wlr_log(L_DEBUG,
149 "libinput_config_pointer(%s) natural_scroll_set_enabled(%d)",
138 ic->identifier, ic->natural_scroll); 150 ic->identifier, ic->natural_scroll);
139 libinput_device_config_scroll_set_natural_scroll_enabled(libinput_device, ic->natural_scroll); 151 libinput_device_config_scroll_set_natural_scroll_enabled(
152 libinput_device, ic->natural_scroll);
140 } 153 }
141 if (ic->pointer_accel != FLT_MIN) { 154 if (ic->pointer_accel != FLT_MIN) {
142 wlr_log(L_DEBUG, "libinput_config_pointer(%s) accel_set_speed(%f)", 155 wlr_log(L_DEBUG, "libinput_config_pointer(%s) accel_set_speed(%f)",
143 ic->identifier, ic->pointer_accel); 156 ic->identifier, ic->pointer_accel);
144 libinput_device_config_accel_set_speed(libinput_device, ic->pointer_accel); 157 libinput_device_config_accel_set_speed(libinput_device,
158 ic->pointer_accel);
145 } 159 }
146 if (ic->scroll_method != INT_MIN) { 160 if (ic->scroll_method != INT_MIN) {
147 wlr_log(L_DEBUG, "libinput_config_pointer(%s) scroll_set_method(%d)", 161 wlr_log(L_DEBUG, "libinput_config_pointer(%s) scroll_set_method(%d)",
148 ic->identifier, ic->scroll_method); 162 ic->identifier, ic->scroll_method);
149 libinput_device_config_scroll_set_method(libinput_device, ic->scroll_method); 163 libinput_device_config_scroll_set_method(libinput_device,
164 ic->scroll_method);
150 } 165 }
151 if (ic->send_events != INT_MIN) { 166 if (ic->send_events != INT_MIN) {
152 wlr_log(L_DEBUG, "libinput_config_pointer(%s) send_events_set_mode(%d)", 167 wlr_log(L_DEBUG, "libinput_config_pointer(%s) send_events_set_mode(%d)",
153 ic->identifier, ic->send_events); 168 ic->identifier, ic->send_events);
154 libinput_device_config_send_events_set_mode(libinput_device, ic->send_events); 169 libinput_device_config_send_events_set_mode(libinput_device,
170 ic->send_events);
155 } 171 }
156 if (ic->tap != INT_MIN) { 172 if (ic->tap != INT_MIN) {
157 wlr_log(L_DEBUG, "libinput_config_pointer(%s) tap_set_enabled(%d)", 173 wlr_log(L_DEBUG, "libinput_config_pointer(%s) tap_set_enabled(%d)",
@@ -175,12 +191,11 @@ static void handle_device_destroy(struct wl_listener *listener, void *data) {
175 191
176 struct sway_seat *seat = NULL; 192 struct sway_seat *seat = NULL;
177 wl_list_for_each(seat, &input_manager->seats, link) { 193 wl_list_for_each(seat, &input_manager->seats, link) {
178 sway_seat_remove_device(seat, input_device); 194 seat_remove_device(seat, input_device);
179 } 195 }
180 196
181 wl_list_remove(&input_device->link); 197 wl_list_remove(&input_device->link);
182 wl_list_remove(&input_device->device_destroy.link); 198 wl_list_remove(&input_device->device_destroy.link);
183 free_input_config(input_device->config);
184 free(input_device->identifier); 199 free(input_device->identifier);
185 free(input_device); 200 free(input_device);
186} 201}
@@ -203,44 +218,36 @@ static void handle_new_input(struct wl_listener *listener, void *data) {
203 wlr_log(L_DEBUG, "adding device: '%s'", 218 wlr_log(L_DEBUG, "adding device: '%s'",
204 input_device->identifier); 219 input_device->identifier);
205 220
206 // find config
207 for (int i = 0; i < config->input_configs->length; ++i) {
208 struct input_config *input_config = config->input_configs->items[i];
209 if (strcmp(input_config->identifier, input_device->identifier) == 0) {
210 free_input_config(input_device->config);
211 input_device->config = copy_input_config(input_config);
212 break;
213 }
214 }
215
216 if (input_device->wlr_device->type == WLR_INPUT_DEVICE_POINTER) { 221 if (input_device->wlr_device->type == WLR_INPUT_DEVICE_POINTER) {
217 sway_input_manager_libinput_config_pointer(input_device); 222 input_manager_libinput_config_pointer(input_device);
218 } 223 }
219 224
220 struct sway_seat *seat = NULL; 225 struct sway_seat *seat = NULL;
221 if (!input_has_seat_configuration(input)) { 226 if (!input_has_seat_configuration(input)) {
222 wlr_log(L_DEBUG, "no seat configuration, using default seat"); 227 wlr_log(L_DEBUG, "no seat configuration, using default seat");
223 seat = input_manager_get_seat(input, default_seat); 228 seat = input_manager_get_seat(input, default_seat);
224 sway_seat_add_device(seat, input_device); 229 seat_add_device(seat, input_device);
225 return; 230 return;
226 } 231 }
227 232
228 bool added = false; 233 bool added = false;
229 wl_list_for_each(seat, &input->seats, link) { 234 wl_list_for_each(seat, &input->seats, link) {
230 bool has_attachment = seat->config && 235 struct seat_config *seat_config = seat_get_config(seat);
231 (seat_config_get_attachment(seat->config, input_device->identifier) || 236 bool has_attachment = seat_config &&
232 seat_config_get_attachment(seat->config, "*")); 237 (seat_config_get_attachment(seat_config, input_device->identifier) ||
238 seat_config_get_attachment(seat_config, "*"));
233 239
234 if (has_attachment) { 240 if (has_attachment) {
235 sway_seat_add_device(seat, input_device); 241 seat_add_device(seat, input_device);
236 added = true; 242 added = true;
237 } 243 }
238 } 244 }
239 245
240 if (!added) { 246 if (!added) {
241 wl_list_for_each(seat, &input->seats, link) { 247 wl_list_for_each(seat, &input->seats, link) {
242 if (seat->config && seat->config->fallback == 1) { 248 struct seat_config *seat_config = seat_get_config(seat);
243 sway_seat_add_device(seat, input_device); 249 if (seat_config && seat_config->fallback == 1) {
250 seat_add_device(seat, input_device);
244 added = true; 251 added = true;
245 } 252 }
246 } 253 }
@@ -256,7 +263,7 @@ static void handle_new_input(struct wl_listener *listener, void *data) {
256 input_device->device_destroy.notify = handle_device_destroy; 263 input_device->device_destroy.notify = handle_device_destroy;
257} 264}
258 265
259struct sway_input_manager *sway_input_manager_create( 266struct sway_input_manager *input_manager_create(
260 struct sway_server *server) { 267 struct sway_server *server) {
261 struct sway_input_manager *input = 268 struct sway_input_manager *input =
262 calloc(1, sizeof(struct sway_input_manager)); 269 calloc(1, sizeof(struct sway_input_manager));
@@ -277,11 +284,11 @@ struct sway_input_manager *sway_input_manager_create(
277 return input; 284 return input;
278} 285}
279 286
280bool sway_input_manager_has_focus(struct sway_input_manager *input, 287bool input_manager_has_focus(struct sway_input_manager *input,
281 struct sway_container *container) { 288 struct sway_container *container) {
282 struct sway_seat *seat = NULL; 289 struct sway_seat *seat = NULL;
283 wl_list_for_each(seat, &input->seats, link) { 290 wl_list_for_each(seat, &input->seats, link) {
284 if (sway_seat_get_focus(seat) == container) { 291 if (seat_get_focus(seat) == container) {
285 return true; 292 return true;
286 } 293 }
287 } 294 }
@@ -289,35 +296,32 @@ bool sway_input_manager_has_focus(struct sway_input_manager *input,
289 return false; 296 return false;
290} 297}
291 298
292void sway_input_manager_set_focus(struct sway_input_manager *input, 299void input_manager_set_focus(struct sway_input_manager *input,
293 struct sway_container *container) { 300 struct sway_container *container) {
294 struct sway_seat *seat ; 301 struct sway_seat *seat ;
295 wl_list_for_each(seat, &input->seats, link) { 302 wl_list_for_each(seat, &input->seats, link) {
296 sway_seat_set_focus(seat, container); 303 seat_set_focus(seat, container);
297 } 304 }
298} 305}
299 306
300void sway_input_manager_apply_input_config(struct sway_input_manager *input, 307void input_manager_apply_input_config(struct sway_input_manager *input,
301 struct input_config *input_config) { 308 struct input_config *input_config) {
302 struct sway_input_device *input_device = NULL; 309 struct sway_input_device *input_device = NULL;
303 wl_list_for_each(input_device, &input->devices, link) { 310 wl_list_for_each(input_device, &input->devices, link) {
304 if (strcmp(input_device->identifier, input_config->identifier) == 0) { 311 if (strcmp(input_device->identifier, input_config->identifier) == 0) {
305 free_input_config(input_device->config);
306 input_device->config = copy_input_config(input_config);
307
308 if (input_device->wlr_device->type == WLR_INPUT_DEVICE_POINTER) { 312 if (input_device->wlr_device->type == WLR_INPUT_DEVICE_POINTER) {
309 sway_input_manager_libinput_config_pointer(input_device); 313 input_manager_libinput_config_pointer(input_device);
310 } 314 }
311 315
312 struct sway_seat *seat = NULL; 316 struct sway_seat *seat = NULL;
313 wl_list_for_each(seat, &input->seats, link) { 317 wl_list_for_each(seat, &input->seats, link) {
314 sway_seat_configure_device(seat, input_device); 318 seat_configure_device(seat, input_device);
315 } 319 }
316 } 320 }
317 } 321 }
318} 322}
319 323
320void sway_input_manager_apply_seat_config(struct sway_input_manager *input, 324void input_manager_apply_seat_config(struct sway_input_manager *input,
321 struct seat_config *seat_config) { 325 struct seat_config *seat_config) {
322 wlr_log(L_DEBUG, "applying new seat config for seat %s", 326 wlr_log(L_DEBUG, "applying new seat config for seat %s",
323 seat_config->name); 327 seat_config->name);
@@ -326,7 +330,7 @@ void sway_input_manager_apply_seat_config(struct sway_input_manager *input,
326 return; 330 return;
327 } 331 }
328 332
329 sway_seat_set_config(seat, seat_config); 333 seat_apply_config(seat, seat_config);
330 334
331 // for every device, try to add it to a seat and if no seat has it 335 // for every device, try to add it to a seat and if no seat has it
332 // attached, add it to the fallback seats. 336 // attached, add it to the fallback seats.
@@ -335,11 +339,12 @@ void sway_input_manager_apply_seat_config(struct sway_input_manager *input,
335 list_t *seat_list = create_list(); 339 list_t *seat_list = create_list();
336 struct sway_seat *seat = NULL; 340 struct sway_seat *seat = NULL;
337 wl_list_for_each(seat, &input->seats, link) { 341 wl_list_for_each(seat, &input->seats, link) {
338 if (!seat->config) { 342 struct seat_config *seat_config = seat_get_config(seat);
343 if (!seat_config) {
339 continue; 344 continue;
340 } 345 }
341 if (seat_config_get_attachment(seat->config, "*") || 346 if (seat_config_get_attachment(seat_config, "*") ||
342 seat_config_get_attachment(seat->config, 347 seat_config_get_attachment(seat_config,
343 input_device->identifier)) { 348 input_device->identifier)) {
344 list_add(seat_list, seat); 349 list_add(seat_list, seat);
345 } 350 }
@@ -355,17 +360,18 @@ void sway_input_manager_apply_seat_config(struct sway_input_manager *input,
355 } 360 }
356 } 361 }
357 if (attached) { 362 if (attached) {
358 sway_seat_add_device(seat, input_device); 363 seat_add_device(seat, input_device);
359 } else { 364 } else {
360 sway_seat_remove_device(seat, input_device); 365 seat_remove_device(seat, input_device);
361 } 366 }
362 } 367 }
363 } else { 368 } else {
364 wl_list_for_each(seat, &input->seats, link) { 369 wl_list_for_each(seat, &input->seats, link) {
365 if (seat->config && seat->config->fallback == 1) { 370 struct seat_config *seat_config = seat_get_config(seat);
366 sway_seat_add_device(seat, input_device); 371 if (seat_config && seat_config->fallback == 1) {
372 seat_add_device(seat, input_device);
367 } else { 373 } else {
368 sway_seat_remove_device(seat, input_device); 374 seat_remove_device(seat, input_device);
369 } 375 }
370 } 376 }
371 } 377 }
@@ -373,14 +379,14 @@ void sway_input_manager_apply_seat_config(struct sway_input_manager *input,
373 } 379 }
374} 380}
375 381
376void sway_input_manager_configure_xcursor(struct sway_input_manager *input) { 382void input_manager_configure_xcursor(struct sway_input_manager *input) {
377 struct sway_seat *seat = NULL; 383 struct sway_seat *seat = NULL;
378 wl_list_for_each(seat, &input->seats, link) { 384 wl_list_for_each(seat, &input->seats, link) {
379 sway_seat_configure_xcursor(seat); 385 seat_configure_xcursor(seat);
380 } 386 }
381} 387}
382 388
383struct sway_seat *sway_input_manager_get_default_seat( 389struct sway_seat *input_manager_get_default_seat(
384 struct sway_input_manager *input) { 390 struct sway_input_manager *input) {
385 struct sway_seat *seat = NULL; 391 struct sway_seat *seat = NULL;
386 wl_list_for_each(seat, &input->seats, link) { 392 wl_list_for_each(seat, &input->seats, link) {
@@ -390,3 +396,15 @@ struct sway_seat *sway_input_manager_get_default_seat(
390 } 396 }
391 return seat; 397 return seat;
392} 398}
399
400struct input_config *input_device_get_config(struct sway_input_device *device) {
401 struct input_config *input_config = NULL;
402 for (int i = 0; i < config->input_configs->length; ++i) {
403 input_config = config->input_configs->items[i];
404 if (strcmp(input_config->identifier, device->identifier) == 0) {
405 return input_config;
406 }
407 }
408
409 return NULL;
410}
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c
index 8d22b684..dbb0c359 100644
--- a/sway/input/keyboard.c
+++ b/sway/input/keyboard.c
@@ -428,7 +428,7 @@ void sway_keyboard_configure(struct sway_keyboard *keyboard) {
428 struct xkb_rule_names rules; 428 struct xkb_rule_names rules;
429 memset(&rules, 0, sizeof(rules)); 429 memset(&rules, 0, sizeof(rules));
430 struct input_config *input_config = 430 struct input_config *input_config =
431 keyboard->seat_device->input_device->config; 431 input_device_get_config(keyboard->seat_device->input_device);
432 struct wlr_input_device *wlr_device = 432 struct wlr_input_device *wlr_device =
433 keyboard->seat_device->input_device->wlr_device; 433 keyboard->seat_device->input_device->wlr_device;
434 434
diff --git a/sway/input/seat.c b/sway/input/seat.c
index 1fd204d4..c41f7b2e 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -26,8 +26,7 @@ static void seat_device_destroy(struct sway_seat_device *seat_device) {
26 free(seat_device); 26 free(seat_device);
27} 27}
28 28
29void sway_seat_destroy(struct sway_seat *seat) { 29void seat_destroy(struct sway_seat *seat) {
30 // TODO destroy seat containers
31 struct sway_seat_device *seat_device, *next; 30 struct sway_seat_device *seat_device, *next;
32 wl_list_for_each_safe(seat_device, next, &seat->devices, link) { 31 wl_list_for_each_safe(seat_device, next, &seat->devices, link) {
33 seat_device_destroy(seat_device); 32 seat_device_destroy(seat_device);
@@ -90,7 +89,7 @@ static void handle_seat_container_destroy(struct wl_listener *listener,
90 struct sway_seat *seat = seat_con->seat; 89 struct sway_seat *seat = seat_con->seat;
91 struct sway_container *con = seat_con->container; 90 struct sway_container *con = seat_con->container;
92 struct sway_container *parent = con->parent; 91 struct sway_container *parent = con->parent;
93 struct sway_container *focus = sway_seat_get_focus(seat); 92 struct sway_container *focus = seat_get_focus(seat);
94 93
95 bool set_focus = 94 bool set_focus =
96 focus != NULL && 95 focus != NULL &&
@@ -102,7 +101,7 @@ static void handle_seat_container_destroy(struct wl_listener *listener,
102 if (set_focus) { 101 if (set_focus) {
103 struct sway_container *next_focus = NULL; 102 struct sway_container *next_focus = NULL;
104 while (next_focus == NULL) { 103 while (next_focus == NULL) {
105 next_focus = sway_seat_get_focus_by_type(seat, parent, C_VIEW); 104 next_focus = seat_get_focus_by_type(seat, parent, C_VIEW);
106 105
107 if (next_focus == NULL && parent->type == C_WORKSPACE) { 106 if (next_focus == NULL && parent->type == C_WORKSPACE) {
108 next_focus = parent; 107 next_focus = parent;
@@ -114,10 +113,10 @@ static void handle_seat_container_destroy(struct wl_listener *listener,
114 113
115 // the structure change might have caused it to move up to the top of 114 // the structure change might have caused it to move up to the top of
116 // the focus stack without sending focus notifications to the view 115 // the focus stack without sending focus notifications to the view
117 if (sway_seat_get_focus(seat) == next_focus) { 116 if (seat_get_focus(seat) == next_focus) {
118 seat_send_focus(seat, next_focus); 117 seat_send_focus(seat, next_focus);
119 } else { 118 } else {
120 sway_seat_set_focus(seat, next_focus); 119 seat_set_focus(seat, next_focus);
121 } 120 }
122 } 121 }
123} 122}
@@ -171,7 +170,7 @@ static void collect_focus_iter(struct sway_container *con, void *data) {
171 wl_list_insert(&seat->focus_stack, &seat_con->link); 170 wl_list_insert(&seat->focus_stack, &seat_con->link);
172} 171}
173 172
174struct sway_seat *sway_seat_create(struct sway_input_manager *input, 173struct sway_seat *seat_create(struct sway_input_manager *input,
175 const char *seat_name) { 174 const char *seat_name) {
176 struct sway_seat *seat = calloc(1, sizeof(struct sway_seat)); 175 struct sway_seat *seat = calloc(1, sizeof(struct sway_seat));
177 if (!seat) { 176 if (!seat) {
@@ -194,7 +193,8 @@ struct sway_seat *sway_seat_create(struct sway_input_manager *input,
194 // init the focus stack 193 // init the focus stack
195 wl_list_init(&seat->focus_stack); 194 wl_list_init(&seat->focus_stack);
196 195
197 container_for_each_descendant_dfs(&root_container, collect_focus_iter, seat); 196 container_for_each_descendant_dfs(&root_container,
197 collect_focus_iter, seat);
198 198
199 wl_signal_add(&root_container.sway_root->events.new_container, 199 wl_signal_add(&root_container.sway_root->events.new_container,
200 &seat->new_container); 200 &seat->new_container);
@@ -208,7 +208,7 @@ struct sway_seat *sway_seat_create(struct sway_input_manager *input,
208 WL_SEAT_CAPABILITY_POINTER | 208 WL_SEAT_CAPABILITY_POINTER |
209 WL_SEAT_CAPABILITY_TOUCH); 209 WL_SEAT_CAPABILITY_TOUCH);
210 210
211 sway_seat_configure_xcursor(seat); 211 seat_configure_xcursor(seat);
212 212
213 wl_list_insert(&input->seats, &seat->link); 213 wl_list_insert(&input->seats, &seat->link);
214 214
@@ -226,11 +226,12 @@ static void seat_configure_keyboard(struct sway_seat *seat,
226 if (!seat_device->keyboard) { 226 if (!seat_device->keyboard) {
227 sway_keyboard_create(seat, seat_device); 227 sway_keyboard_create(seat, seat_device);
228 } 228 }
229 struct wlr_keyboard *wlr_keyboard = seat_device->input_device->wlr_device->keyboard; 229 struct wlr_keyboard *wlr_keyboard =
230 seat_device->input_device->wlr_device->keyboard;
230 sway_keyboard_configure(seat_device->keyboard); 231 sway_keyboard_configure(seat_device->keyboard);
231 wlr_seat_set_keyboard(seat->wlr_seat, 232 wlr_seat_set_keyboard(seat->wlr_seat,
232 seat_device->input_device->wlr_device); 233 seat_device->input_device->wlr_device);
233 struct sway_container *focus = sway_seat_get_focus(seat); 234 struct sway_container *focus = seat_get_focus(seat);
234 if (focus && focus->type == C_VIEW) { 235 if (focus && focus->type == C_VIEW) {
235 // force notify reenter to pick up the new configuration 236 // force notify reenter to pick up the new configuration
236 wlr_seat_keyboard_clear_focus(seat->wlr_seat); 237 wlr_seat_keyboard_clear_focus(seat->wlr_seat);
@@ -240,7 +241,7 @@ static void seat_configure_keyboard(struct sway_seat *seat,
240 } 241 }
241} 242}
242 243
243static struct sway_seat_device *sway_seat_get_device(struct sway_seat *seat, 244static struct sway_seat_device *seat_get_device(struct sway_seat *seat,
244 struct sway_input_device *input_device) { 245 struct sway_input_device *input_device) {
245 struct sway_seat_device *seat_device = NULL; 246 struct sway_seat_device *seat_device = NULL;
246 wl_list_for_each(seat_device, &seat->devices, link) { 247 wl_list_for_each(seat_device, &seat->devices, link) {
@@ -252,19 +253,14 @@ static struct sway_seat_device *sway_seat_get_device(struct sway_seat *seat,
252 return NULL; 253 return NULL;
253} 254}
254 255
255void sway_seat_configure_device(struct sway_seat *seat, 256void seat_configure_device(struct sway_seat *seat,
256 struct sway_input_device *input_device) { 257 struct sway_input_device *input_device) {
257 struct sway_seat_device *seat_device = 258 struct sway_seat_device *seat_device =
258 sway_seat_get_device(seat, input_device); 259 seat_get_device(seat, input_device);
259 if (!seat_device) { 260 if (!seat_device) {
260 return; 261 return;
261 } 262 }
262 263
263 if (seat->config) {
264 seat_device->attachment_config =
265 seat_config_get_attachment(seat->config, input_device->identifier);
266 }
267
268 switch (input_device->wlr_device->type) { 264 switch (input_device->wlr_device->type) {
269 case WLR_INPUT_DEVICE_POINTER: 265 case WLR_INPUT_DEVICE_POINTER:
270 seat_configure_pointer(seat, seat_device); 266 seat_configure_pointer(seat, seat_device);
@@ -280,10 +276,10 @@ void sway_seat_configure_device(struct sway_seat *seat,
280 } 276 }
281} 277}
282 278
283void sway_seat_add_device(struct sway_seat *seat, 279void seat_add_device(struct sway_seat *seat,
284 struct sway_input_device *input_device) { 280 struct sway_input_device *input_device) {
285 if (sway_seat_get_device(seat, input_device)) { 281 if (seat_get_device(seat, input_device)) {
286 sway_seat_configure_device(seat, input_device); 282 seat_configure_device(seat, input_device);
287 return; 283 return;
288 } 284 }
289 285
@@ -301,13 +297,13 @@ void sway_seat_add_device(struct sway_seat *seat,
301 seat_device->input_device = input_device; 297 seat_device->input_device = input_device;
302 wl_list_insert(&seat->devices, &seat_device->link); 298 wl_list_insert(&seat->devices, &seat_device->link);
303 299
304 sway_seat_configure_device(seat, input_device); 300 seat_configure_device(seat, input_device);
305} 301}
306 302
307void sway_seat_remove_device(struct sway_seat *seat, 303void seat_remove_device(struct sway_seat *seat,
308 struct sway_input_device *input_device) { 304 struct sway_input_device *input_device) {
309 struct sway_seat_device *seat_device = 305 struct sway_seat_device *seat_device =
310 sway_seat_get_device(seat, input_device); 306 seat_get_device(seat, input_device);
311 307
312 if (!seat_device) { 308 if (!seat_device) {
313 return; 309 return;
@@ -319,7 +315,7 @@ void sway_seat_remove_device(struct sway_seat *seat,
319 seat_device_destroy(seat_device); 315 seat_device_destroy(seat_device);
320} 316}
321 317
322void sway_seat_configure_xcursor(struct sway_seat *seat) { 318void seat_configure_xcursor(struct sway_seat *seat) {
323 // TODO configure theme and size 319 // TODO configure theme and size
324 const char *cursor_theme = NULL; 320 const char *cursor_theme = NULL;
325 321
@@ -334,7 +330,8 @@ void sway_seat_configure_xcursor(struct sway_seat *seat) {
334 } 330 }
335 331
336 for (int i = 0; i < root_container.children->length; ++i) { 332 for (int i = 0; i < root_container.children->length; ++i) {
337 struct sway_container *output_container = root_container.children->items[i]; 333 struct sway_container *output_container =
334 root_container.children->items[i];
338 struct wlr_output *output = 335 struct wlr_output *output =
339 output_container->sway_output->wlr_output; 336 output_container->sway_output->wlr_output;
340 bool result = 337 bool result =
@@ -353,9 +350,9 @@ void sway_seat_configure_xcursor(struct sway_seat *seat) {
353 seat->cursor->cursor->y); 350 seat->cursor->cursor->y);
354} 351}
355 352
356void sway_seat_set_focus_warp(struct sway_seat *seat, 353void seat_set_focus_warp(struct sway_seat *seat,
357 struct sway_container *container, bool warp) { 354 struct sway_container *container, bool warp) {
358 struct sway_container *last_focus = sway_seat_get_focus(seat); 355 struct sway_container *last_focus = seat_get_focus(seat);
359 356
360 if (container && last_focus == container) { 357 if (container && last_focus == container) {
361 return; 358 return;
@@ -409,7 +406,7 @@ void sway_seat_set_focus_warp(struct sway_seat *seat,
409 } 406 }
410 407
411 if (last_focus && last_focus->type == C_VIEW && 408 if (last_focus && last_focus->type == C_VIEW &&
412 !sway_input_manager_has_focus(seat->input, last_focus)) { 409 !input_manager_has_focus(seat->input, last_focus)) {
413 struct sway_view *view = last_focus->sway_view; 410 struct sway_view *view = last_focus->sway_view;
414 view_set_activated(view, false); 411 view_set_activated(view, false);
415 } 412 }
@@ -417,24 +414,24 @@ void sway_seat_set_focus_warp(struct sway_seat *seat,
417 seat->has_focus = (container != NULL); 414 seat->has_focus = (container != NULL);
418} 415}
419 416
420void sway_seat_set_focus(struct sway_seat *seat, 417void seat_set_focus(struct sway_seat *seat,
421 struct sway_container *container) { 418 struct sway_container *container) {
422 sway_seat_set_focus_warp(seat, container, true); 419 seat_set_focus_warp(seat, container, true);
423} 420}
424 421
425struct sway_container *sway_seat_get_focus_inactive(struct sway_seat *seat, 422struct sway_container *seat_get_focus_inactive(struct sway_seat *seat,
426 struct sway_container *container) { 423 struct sway_container *container) {
427 return sway_seat_get_focus_by_type(seat, container, C_TYPES); 424 return seat_get_focus_by_type(seat, container, C_TYPES);
428} 425}
429 426
430struct sway_container *sway_seat_get_focus(struct sway_seat *seat) { 427struct sway_container *sway_seat_get_focus(struct sway_seat *seat) {
431 if (!seat->has_focus) { 428 if (!seat->has_focus) {
432 return NULL; 429 return NULL;
433 } 430 }
434 return sway_seat_get_focus_inactive(seat, &root_container); 431 return seat_get_focus_inactive(seat, &root_container);
435} 432}
436 433
437struct sway_container *sway_seat_get_focus_by_type(struct sway_seat *seat, 434struct sway_container *seat_get_focus_by_type(struct sway_seat *seat,
438 struct sway_container *container, enum sway_container_type type) { 435 struct sway_container *container, enum sway_container_type type) {
439 struct sway_seat_container *current = NULL; 436 struct sway_seat_container *current = NULL;
440 struct sway_container *parent = NULL; 437 struct sway_container *parent = NULL;
@@ -458,25 +455,34 @@ struct sway_container *sway_seat_get_focus_by_type(struct sway_seat *seat,
458 return NULL; 455 return NULL;
459} 456}
460 457
461void sway_seat_set_config(struct sway_seat *seat, 458struct sway_container *seat_get_focus(struct sway_seat *seat) {
462 struct seat_config *seat_config) { 459 if (!seat->has_focus) {
463 // clear configs 460 return NULL;
464 free_seat_config(seat->config); 461 }
465 seat->config = NULL; 462 return seat_get_focus_inactive(seat, &root_container);
463}
466 464
465void seat_apply_config(struct sway_seat *seat,
466 struct seat_config *seat_config) {
467 struct sway_seat_device *seat_device = NULL; 467 struct sway_seat_device *seat_device = NULL;
468 wl_list_for_each(seat_device, &seat->devices, link) {
469 seat_device->attachment_config = NULL;
470 }
471 468
472 if (!seat_config) { 469 if (!seat_config) {
473 return; 470 return;
474 } 471 }
475 472
476 // add configs
477 seat->config = copy_seat_config(seat_config);
478
479 wl_list_for_each(seat_device, &seat->devices, link) { 473 wl_list_for_each(seat_device, &seat->devices, link) {
480 sway_seat_configure_device(seat, seat_device->input_device); 474 seat_configure_device(seat, seat_device->input_device);
475 }
476}
477
478struct seat_config *seat_get_config(struct sway_seat *seat) {
479 struct seat_config *seat_config = NULL;
480 for (int i = 0; i < config->seat_configs->length; ++i ) {
481 seat_config = config->seat_configs->items[i];
482 if (strcmp(seat->wlr_seat->name, seat_config->name) == 0) {
483 return seat_config;
484 }
481 } 485 }
486
487 return NULL;
482} 488}