summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndri Yngvason <andri@yngvason.is>2020-01-03 15:38:29 +0000
committerDrew DeVault <sir@cmpwn.com>2020-01-08 10:27:20 -0500
commitc1cab4bf0eefc54bb9c477af3289ec7f6ac0da52 (patch)
tree5bb92313353a6a1742f431edaed1089151a6069e
parent5539fb3abc0576d32fdea233a35325941af967f5 (diff)
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 8b83eab49..7f68caece 100644
--- a/swaybar/input.c
+++ b/swaybar/input.c
@@ -405,15 +405,14 @@ static const struct wl_touch_listener touch_listener = {
static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
enum wl_seat_capability caps) {
struct swaybar_seat *seat = data;
- if (seat->pointer.pointer != NULL) {
+
+ bool have_pointer = caps & WL_SEAT_CAPABILITY_POINTER;
+ bool have_touch = caps & WL_SEAT_CAPABILITY_TOUCH;
+
+ if (!have_pointer && seat->pointer.pointer != NULL) {
wl_pointer_release(seat->pointer.pointer);
seat->pointer.pointer = NULL;
- }
- if (seat->touch.touch != NULL) {
- wl_touch_release(seat->touch.touch);
- seat->touch.touch = NULL;
- }
- if ((caps & WL_SEAT_CAPABILITY_POINTER)) {
+ } else if (have_pointer && seat->pointer.pointer == NULL) {
seat->pointer.pointer = wl_seat_get_pointer(wl_seat);
if (seat->bar->running && !seat->pointer.cursor_surface) {
seat->pointer.cursor_surface =
@@ -422,7 +421,10 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
}
wl_pointer_add_listener(seat->pointer.pointer, &pointer_listener, seat);
}
- if ((caps & WL_SEAT_CAPABILITY_TOUCH)) {
+ if (!have_touch && seat->touch.touch != NULL) {
+ wl_touch_release(seat->touch.touch);
+ seat->touch.touch = NULL;
+ } else if (have_touch && seat->touch.touch == NULL) {
seat->touch.touch = wl_seat_get_touch(wl_seat);
wl_touch_add_listener(seat->touch.touch, &touch_listener, seat);
}