module/sway-xkb: handle device being added again

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
This commit is contained in:
Daniel Eklöf 2022-06-02 21:27:06 +02:00
parent ca077447c2
commit f4ceaaad52
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -207,21 +207,27 @@ handle_input_event(int type, const struct json_object *json, void *_mod)
return true; return true;
} }
if (is_removed || is_added) { if (is_removed) {
mtx_lock(&mod->lock); if (input->exists) {
assert((is_removed && input->exists) || mtx_lock(&mod->lock);
(is_added && !input->exists)); input->exists = false;
m->num_existing_inputs--;
m->dirty = true;
mtx_unlock(&mod->lock);
}
return true;
}
input->exists = !input->exists; if (is_added) {
m->num_existing_inputs += is_added ? 1 : -1; if (!input->exists) {
m->dirty = true; mtx_lock(&mod->lock);
input->exists = true;
m->num_existing_inputs++;
m->dirty = true;
mtx_unlock(&mod->lock);
}
mtx_unlock(&mod->lock); /* “fallthrough”, to query current/active layout */
if (is_removed)
return true;
/* let is_added fall through, to update layout */
} }
/* Get current/active layout */ /* Get current/active layout */