You still need to update device->last, otherwise you'll get all the
initial events next time. A goto instead of continue would solve that.
If I start poweralertd with ignore_initial right now it indeed silences
everything on startup, but if I toggle the power of my mouse then I get
all the events that had been silenced.
Once the previous comment is addressed, you could just do this after
device->last = device->current.
It can alternatively be done whenever device->current is changed in
upower.c (such as in upower_device_update_state), which has the
side-effect of `device->last.serial != device->current.serial` meaning
that a change has occurred. This was a bit more in line with my
original idea, but either way works.
+ }+ }
finish:
diff --git a/upower.c b/upower.c
index 5ffa922..62678f2 100644
--- a/upower.c+++ b/upower.c
@@ -120,6 +120,15 @@ char* upower_device_type_string(struct upower_device *device) {
return "unknown";
}
+int upower_device_type_int(char *device) {+ for (int i=0; i < UPOWER_DEVICE_TYPE_LAST; i++) {+ if (!strcmp(upower_type_string[i], device)) {+ return i;+ }+ }+ return -1;+}+static int upower_device_update_state(sd_bus *bus, struct upower_device *device) {
sd_bus_error error = SD_BUS_ERROR_NULL;
int ret;
@@ -515,4 +524,4 @@ void destroy_upower(sd_bus *bus, struct upower *state) {
list_free(state->devices);
state->devices = NULL;
}
-}
\ No newline at end of file
+}
diff --git a/upower.h b/upower.h
index 81d3d41..a397c40 100644
--- a/upower.h+++ b/upower.h
@@ -62,6 +62,7 @@ enum change_slot {
struct upower_device_props {
int generation;
int online;
+ int serial; double percentage;
enum upower_device_state state;
enum upower_device_level warning_level;
@@ -98,9 +99,10 @@ char* upower_device_state_string(struct upower_device *device);
char* upower_device_warning_level_string(struct upower_device *device);
char* upower_device_battery_level_string(struct upower_device *device);
char* upower_device_type_string(struct upower_device *device);
+int upower_device_type_int(char *device);void upower_device_destroy(struct upower_device *device);
int init_upower(sd_bus *bus, struct upower *state);
void destroy_upower(sd_bus *bus, struct upower *state);
-#endif
\ No newline at end of file
+#endif
--
2.32.0