diff options
Diffstat (limited to 'swaybar/bar.c')
-rw-r--r-- | swaybar/bar.c | 56 |
1 files changed, 47 insertions, 9 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c index a95464f5..35e1662b 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c | |||
@@ -216,8 +216,16 @@ static void output_scale(void *data, struct wl_output *wl_output, | |||
216 | int32_t factor) { | 216 | int32_t factor) { |
217 | struct swaybar_output *output = data; | 217 | struct swaybar_output *output = data; |
218 | output->scale = factor; | 218 | output->scale = factor; |
219 | if (output == output->bar->pointer.current) { | 219 | |
220 | update_cursor(output->bar); | 220 | bool render = false; |
221 | struct swaybar_seat *seat; | ||
222 | wl_list_for_each(seat, &output->bar->seats, link) { | ||
223 | if (output == seat->pointer.current) { | ||
224 | update_cursor(seat); | ||
225 | render = true; | ||
226 | } | ||
227 | }; | ||
228 | if (render) { | ||
221 | render_frame(output); | 229 | render_frame(output); |
222 | } | 230 | } |
223 | } | 231 | } |
@@ -318,9 +326,16 @@ static void handle_global(void *data, struct wl_registry *registry, | |||
318 | bar->compositor = wl_registry_bind(registry, name, | 326 | bar->compositor = wl_registry_bind(registry, name, |
319 | &wl_compositor_interface, 4); | 327 | &wl_compositor_interface, 4); |
320 | } else if (strcmp(interface, wl_seat_interface.name) == 0) { | 328 | } else if (strcmp(interface, wl_seat_interface.name) == 0) { |
321 | bar->seat = wl_registry_bind(registry, name, | 329 | struct swaybar_seat *seat = calloc(1, sizeof(struct swaybar_seat)); |
322 | &wl_seat_interface, 3); | 330 | if (!seat) { |
323 | wl_seat_add_listener(bar->seat, &seat_listener, bar); | 331 | sway_abort("Failed to allocate swaybar_seat"); |
332 | return; | ||
333 | } | ||
334 | seat->bar = bar; | ||
335 | seat->wl_name = name; | ||
336 | seat->wl_seat = wl_registry_bind(registry, name, &wl_seat_interface, 3); | ||
337 | wl_seat_add_listener(seat->wl_seat, &seat_listener, seat); | ||
338 | wl_list_insert(&bar->seats, &seat->link); | ||
324 | } else if (strcmp(interface, wl_shm_interface.name) == 0) { | 339 | } else if (strcmp(interface, wl_shm_interface.name) == 0) { |
325 | bar->shm = wl_registry_bind(registry, name, | 340 | bar->shm = wl_registry_bind(registry, name, |
326 | &wl_shm_interface, 1); | 341 | &wl_shm_interface, 1); |
@@ -355,7 +370,14 @@ static void handle_global_remove(void *data, struct wl_registry *registry, | |||
355 | wl_list_for_each_safe(output, tmp, &bar->outputs, link) { | 370 | wl_list_for_each_safe(output, tmp, &bar->outputs, link) { |
356 | if (output->wl_name == name) { | 371 | if (output->wl_name == name) { |
357 | swaybar_output_free(output); | 372 | swaybar_output_free(output); |
358 | break; | 373 | return; |
374 | } | ||
375 | } | ||
376 | struct swaybar_seat *seat, *tmp_seat; | ||
377 | wl_list_for_each_safe(seat, tmp_seat, &bar->seats, link) { | ||
378 | if (seat->wl_name == name) { | ||
379 | swaybar_seat_free(seat); | ||
380 | return; | ||
359 | } | 381 | } |
360 | } | 382 | } |
361 | } | 383 | } |
@@ -369,6 +391,7 @@ bool bar_setup(struct swaybar *bar, const char *socket_path) { | |||
369 | bar->visible = true; | 391 | bar->visible = true; |
370 | bar->config = init_config(); | 392 | bar->config = init_config(); |
371 | wl_list_init(&bar->outputs); | 393 | wl_list_init(&bar->outputs); |
394 | wl_list_init(&bar->seats); | ||
372 | bar->eventloop = loop_create(); | 395 | bar->eventloop = loop_create(); |
373 | 396 | ||
374 | bar->ipc_socketfd = ipc_open_socket(socket_path); | 397 | bar->ipc_socketfd = ipc_open_socket(socket_path); |
@@ -397,9 +420,16 @@ bool bar_setup(struct swaybar *bar, const char *socket_path) { | |||
397 | // Second roundtrip for xdg-output | 420 | // Second roundtrip for xdg-output |
398 | wl_display_roundtrip(bar->display); | 421 | wl_display_roundtrip(bar->display); |
399 | 422 | ||
400 | struct swaybar_pointer *pointer = &bar->pointer; | 423 | struct swaybar_seat *seat; |
401 | pointer->cursor_surface = wl_compositor_create_surface(bar->compositor); | 424 | wl_list_for_each(seat, &bar->seats, link) { |
402 | assert(pointer->cursor_surface); | 425 | struct swaybar_pointer *pointer = &seat->pointer; |
426 | if (!pointer) { | ||
427 | continue; | ||
428 | } | ||
429 | pointer->cursor_surface = | ||
430 | wl_compositor_create_surface(bar->compositor); | ||
431 | assert(pointer->cursor_surface); | ||
432 | } | ||
403 | 433 | ||
404 | #if HAVE_TRAY | 434 | #if HAVE_TRAY |
405 | if (!bar->config->tray_hidden) { | 435 | if (!bar->config->tray_hidden) { |
@@ -468,11 +498,19 @@ static void free_outputs(struct wl_list *list) { | |||
468 | } | 498 | } |
469 | } | 499 | } |
470 | 500 | ||
501 | static void free_seats(struct wl_list *list) { | ||
502 | struct swaybar_seat *seat, *tmp; | ||
503 | wl_list_for_each_safe(seat, tmp, list, link) { | ||
504 | swaybar_seat_free(seat); | ||
505 | } | ||
506 | } | ||
507 | |||
471 | void bar_teardown(struct swaybar *bar) { | 508 | void bar_teardown(struct swaybar *bar) { |
472 | #if HAVE_TRAY | 509 | #if HAVE_TRAY |
473 | destroy_tray(bar->tray); | 510 | destroy_tray(bar->tray); |
474 | #endif | 511 | #endif |
475 | free_outputs(&bar->outputs); | 512 | free_outputs(&bar->outputs); |
513 | free_seats(&bar->seats); | ||
476 | if (bar->config) { | 514 | if (bar->config) { |
477 | free_config(bar->config); | 515 | free_config(bar->config); |
478 | } | 516 | } |