diff --git a/CHANGELOG.md b/CHANGELOG.md index 532530a..ade384d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -115,6 +115,8 @@ * network: missing SSID (recent kernels, or possibly wireless drivers, no longer provide the SSID in the `NL80211_CMD_NEW_STATION` response) ([#226][226]). +* sway-xkb: crash when compositor presents multiple inputs with + identical IDs ([#229][229]). [169]: https://codeberg.org/dnkl/yambar/issues/169 [172]: https://codeberg.org/dnkl/yambar/issues/172 @@ -123,6 +125,7 @@ [198]: https://codeberg.org/dnkl/yambar/issues/198 [221]: https://codeberg.org/dnkl/yambar/issues/221 [226]: https://codeberg.org/dnkl/yambar/issues/226 +[229]: https://codeberg.org/dnkl/yambar/issues/229 ### Security diff --git a/modules/sway-xkb.c b/modules/sway-xkb.c index 6ee3e3a..3f2e965 100644 --- a/modules/sway-xkb.c +++ b/modules/sway-xkb.c @@ -67,6 +67,7 @@ content(struct module *mod) mtx_lock(&mod->lock); + assert(m->num_existing_inputs <= m->num_inputs); struct exposable *particles[max(m->num_existing_inputs, 1)]; for (size_t i = 0, j = 0; i < m->num_inputs; i++) { @@ -120,9 +121,12 @@ handle_input_reply(int type, const struct json_object *json, void *_mod) struct input *input = NULL; for (size_t i = 0; i < m->num_inputs; i++) { struct input *maybe_input = &m->inputs[i]; - if (strcmp(maybe_input->identifier, id) == 0) { + if (strcmp(maybe_input->identifier, id) == 0 && !maybe_input->exists) + { input = maybe_input; + LOG_DBG("adding: %s", id); + mtx_lock(&mod->lock); input->exists = true; m->num_existing_inputs++; @@ -209,6 +213,8 @@ handle_input_event(int type, const struct json_object *json, void *_mod) if (is_removed) { if (input->exists) { + LOG_DBG("removing: %s", id); + mtx_lock(&mod->lock); input->exists = false; m->num_existing_inputs--; @@ -220,6 +226,8 @@ handle_input_event(int type, const struct json_object *json, void *_mod) if (is_added) { if (!input->exists) { + LOG_DBG("adding: %s", id); + mtx_lock(&mod->lock); input->exists = true; m->num_existing_inputs++;