aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Andri Yngvason <andri@yngvason.is>2020-01-03 15:38:29 +0000
committerLibravatar Drew DeVault <sir@cmpwn.com>2020-01-08 10:27:20 -0500
commitc1cab4bf0eefc54bb9c477af3289ec7f6ac0da52 (patch)
tree5bb92313353a6a1742f431edaed1089151a6069e
parentFix small typo in sway-input(5) (diff)
downloadsway-c1cab4bf0eefc54bb9c477af3289ec7f6ac0da52.tar.gz
sway-c1cab4bf0eefc54bb9c477af3289ec7f6ac0da52.tar.zst
sway-c1cab4bf0eefc54bb9c477af3289ec7f6ac0da52.zip
swaybar: Fix input device removal
Before swaybar would exit with a protocol error when a pointer or touch device was removed.
-rw-r--r--swaybar/input.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/swaybar/input.c b/swaybar/input.c
index 8b83eab4..7f68caec 100644
--- a/swaybar/input.c
+++ b/swaybar/input.c
@@ -405,15 +405,14 @@ static const struct wl_touch_listener touch_listener = {
405static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, 405static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
406 enum wl_seat_capability caps) { 406 enum wl_seat_capability caps) {
407 struct swaybar_seat *seat = data; 407 struct swaybar_seat *seat = data;
408 if (seat->pointer.pointer != NULL) { 408
409 bool have_pointer = caps & WL_SEAT_CAPABILITY_POINTER;
410 bool have_touch = caps & WL_SEAT_CAPABILITY_TOUCH;
411
412 if (!have_pointer && seat->pointer.pointer != NULL) {
409 wl_pointer_release(seat->pointer.pointer); 413 wl_pointer_release(seat->pointer.pointer);
410 seat->pointer.pointer = NULL; 414 seat->pointer.pointer = NULL;
411 } 415 } else if (have_pointer && seat->pointer.pointer == NULL) {
412 if (seat->touch.touch != NULL) {
413 wl_touch_release(seat->touch.touch);
414 seat->touch.touch = NULL;
415 }
416 if ((caps & WL_SEAT_CAPABILITY_POINTER)) {
417 seat->pointer.pointer = wl_seat_get_pointer(wl_seat); 416 seat->pointer.pointer = wl_seat_get_pointer(wl_seat);
418 if (seat->bar->running && !seat->pointer.cursor_surface) { 417 if (seat->bar->running && !seat->pointer.cursor_surface) {
419 seat->pointer.cursor_surface = 418 seat->pointer.cursor_surface =
@@ -422,7 +421,10 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
422 } 421 }
423 wl_pointer_add_listener(seat->pointer.pointer, &pointer_listener, seat); 422 wl_pointer_add_listener(seat->pointer.pointer, &pointer_listener, seat);
424 } 423 }
425 if ((caps & WL_SEAT_CAPABILITY_TOUCH)) { 424 if (!have_touch && seat->touch.touch != NULL) {
425 wl_touch_release(seat->touch.touch);
426 seat->touch.touch = NULL;
427 } else if (have_touch && seat->touch.touch == NULL) {
426 seat->touch.touch = wl_seat_get_touch(wl_seat); 428 seat->touch.touch = wl_seat_get_touch(wl_seat);
427 wl_touch_add_listener(seat->touch.touch, &touch_listener, seat); 429 wl_touch_add_listener(seat->touch.touch, &touch_listener, seat);
428 } 430 }