fix seat not updated for existing buttons

This commit is contained in:
2025-12-06 18:43:42 +09:00
parent 52ec8abc44
commit cc20b387f8
2 changed files with 17 additions and 22 deletions

View File

@@ -244,11 +244,14 @@ int manager_add_inhibitor(Manager *m, const char* id, Inhibitor **ret) {
int manager_add_button(Manager *m, const char *name, Button **ret_button) { int manager_add_button(Manager *m, const char *name, Button **ret_button) {
Button *b; Button *b;
bool is_new;
assert(m); assert(m);
assert(name); assert(name);
b = hashmap_get(m->buttons, name); b = hashmap_get(m->buttons, name);
is_new = !b;
if (!b) { if (!b) {
b = button_new(m, name); b = button_new(m, name);
if (!b) if (!b)
@@ -258,7 +261,7 @@ int manager_add_button(Manager *m, const char *name, Button **ret_button) {
if (ret_button) if (ret_button)
*ret_button = b; *ret_button = b;
return 0; return is_new;
} }
int manager_process_seat_device(Manager *m, sd_device *d) { int manager_process_seat_device(Manager *m, sd_device *d) {
@@ -329,7 +332,7 @@ int manager_process_seat_device(Manager *m, sd_device *d) {
} }
int manager_process_button_device(Manager *m, sd_device *d, Button **ret_button) { int manager_process_button_device(Manager *m, sd_device *d, Button **ret_button) {
const char *sysname, *sn; const char *sysname;
Button *b; Button *b;
int r; int r;
@@ -342,18 +345,16 @@ int manager_process_button_device(Manager *m, sd_device *d, Button **ret_button)
if (device_for_action(d, SD_DEVICE_REMOVE) || if (device_for_action(d, SD_DEVICE_REMOVE) ||
sd_device_has_current_tag(d, "power-switch") <= 0) { sd_device_has_current_tag(d, "power-switch") <= 0) {
button_free(hashmap_get(m->buttons, sysname)); b = hashmap_get(m->buttons, sysname);
goto no_match; goto unwatch;
} }
b = hashmap_get(m->buttons, sysname);
if (b)
goto no_match;
r = manager_add_button(m, sysname, &b); r = manager_add_button(m, sysname, &b);
if (r < 0) if (r < 0)
return r; return r;
bool is_new = r > 0;
const char *sn;
r = device_get_seat(d, &sn); r = device_get_seat(d, &sn);
if (r < 0) if (r < 0)
return r; return r;
@@ -361,19 +362,18 @@ int manager_process_button_device(Manager *m, sd_device *d, Button **ret_button)
button_set_seat(b, sn); button_set_seat(b, sn);
r = button_open(b); r = button_open(b);
if (r < 0) { if (r < 0) /* event device doesn't have any keys or switches relevant to us? (or any other error
/* event device doesn't have any keys or switches relevant to us? (or any other error * opening the device?) let's close the button again. */
* opening the device?) let's close the button again. */ goto unwatch;
button_free(b);
goto no_match;
}
if (ret_button) if (ret_button)
*ret_button = b; *ret_button = b;
return 1; return is_new;
unwatch:
button_free(b);
no_match:
if (ret_button) if (ret_button)
*ret_button = NULL; *ret_button = NULL;

View File

@@ -740,15 +740,10 @@ static int manager_dispatch_vcsa_udev(sd_device_monitor *monitor, sd_device *dev
static int manager_dispatch_button_udev(sd_device_monitor *monitor, sd_device *device, void *userdata) { static int manager_dispatch_button_udev(sd_device_monitor *monitor, sd_device *device, void *userdata) {
Manager *m = ASSERT_PTR(userdata); Manager *m = ASSERT_PTR(userdata);
Button *b; Button *b;
int r;
assert(device); assert(device);
r = manager_process_button_device(m, device, &b); if (manager_process_button_device(m, device, &b) > 0)
if (r < 0)
return 0;
if (r > 0)
(void) button_check_switches(b); (void) button_check_switches(b);
return 0; return 0;