From f4ceaaad523854eb4c7876ad7fc6276eaa1b6ffe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 2 Jun 2022 21:27:06 +0200 Subject: [PATCH] module/sway-xkb: handle device being added again MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a device is removed while the computer is hibernating, and then reconnected after waking it up, Sway sends an “added” event without first sending a “removed” event. Yambar used to assert that an “added” event didn’t refer to an already tracked device. This patch changes this, and simply ignores duplicate “added” events. Closes #177 --- modules/sway-xkb.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/modules/sway-xkb.c b/modules/sway-xkb.c index 6632ab7..6ee3e3a 100644 --- a/modules/sway-xkb.c +++ b/modules/sway-xkb.c @@ -207,21 +207,27 @@ handle_input_event(int type, const struct json_object *json, void *_mod) return true; } - if (is_removed || is_added) { - mtx_lock(&mod->lock); - assert((is_removed && input->exists) || - (is_added && !input->exists)); + if (is_removed) { + if (input->exists) { + mtx_lock(&mod->lock); + input->exists = false; + m->num_existing_inputs--; + m->dirty = true; + mtx_unlock(&mod->lock); + } + return true; + } - input->exists = !input->exists; - m->num_existing_inputs += is_added ? 1 : -1; - m->dirty = true; + if (is_added) { + if (!input->exists) { + mtx_lock(&mod->lock); + input->exists = true; + m->num_existing_inputs++; + m->dirty = true; + mtx_unlock(&mod->lock); + } - mtx_unlock(&mod->lock); - - if (is_removed) - return true; - - /* let is_added fall through, to update layout */ + /* “fallthrough”, to query current/active layout */ } /* Get current/active layout */