Skip to content

Commit

Permalink
sys-power/poweralertd: add patch with '-o' to ignore notifications
Browse files Browse the repository at this point in the history
... over a certain battery-level
  • Loading branch information
SuperTux88 committed Jan 11, 2025
1 parent 5018de4 commit 305fecf
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ RDEPEND=sys-power/upower elogind? ( sys-auth/elogind ) systemd? ( sys-apps/syste
REQUIRED_USE=?? ( elogind systemd )
SLOT=0
SRC_URI=https://git.sr.ht/~kennylevinsen/poweralertd/archive/0.3.0.tar.gz -> poweralertd-0.3.0.tar.gz
_eclasses_=toolchain-funcs d3d42b22a610ce81c267b644bcec9b87 multilib b2a329026f2e404e9e371097dda47f96 flag-o-matic f14aba975c94ccaa9f357a27e3b17ffe multiprocessing 1e32df7deee68372153dca65f4a7c21f ninja-utils 2df4e452cea39a9ec8fb543ce059f8d6 python-utils-r1 2fee95c11e5f883024588d4837db6802 meson 99466844dd8d4fcfb07578a76f5a9922
_md5_=1ecf50b520e6278b02789b501d020091
_eclasses_=toolchain-funcs 14648d8795f7779e11e1bc7cf08b7536 multilib b2a329026f2e404e9e371097dda47f96 flag-o-matic f14aba975c94ccaa9f357a27e3b17ffe multiprocessing 1e32df7deee68372153dca65f4a7c21f ninja-utils 2df4e452cea39a9ec8fb543ce059f8d6 python-utils-r1 42c5abe4a656a4993a06a4fc61dbdd12 meson 99466844dd8d4fcfb07578a76f5a9922
_md5_=f6051b97092e6a276fe3e6b7bc4e1a1b
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
diff --git a/main.c b/main.c
index 99700e3..ec49327 100644
--- a/main.c
+++ b/main.c
@@ -156,6 +156,7 @@ static const char usage[] = "usage: %s [options]\n"
" -v show the version number\n"
" -s ignore the events at startup\n"
" -i <device_type> ignore this device type, can be use several times\n"
+" -o <percentage> ignores events over specified battery percentage\n"
" -S only use the events coming from power supplies\n";


@@ -163,6 +164,7 @@ int main(int argc, char *argv[]) {
int opt = 0;
int device_type = 0;
int ignore_types_mask = 0;
+ int ignore_over = 0;
bool ignore_initial = false;
bool ignore_non_power_supplies = false;
bool initialized = false;
@@ -173,7 +175,7 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE;
}

- while ((opt = getopt(argc, argv, "hvsi:S")) != -1) {
+ while ((opt = getopt(argc, argv, "hvsi:o:S")) != -1) {
switch (opt) {
case 'i':
device_type = upower_device_type_int(optarg);
@@ -184,6 +186,9 @@ int main(int argc, char *argv[]) {
printf("Unrecognized device type: %s\n", optarg);
}
break;
+ case 'o':
+ ignore_over = atoi(optarg);
+ break;
case 's':
ignore_initial = true;
break;
@@ -241,23 +246,27 @@ int main(int argc, char *argv[]) {
goto next_device;
}

- if (upower_device_has_battery(device)) {
- ret = send_state_update(user_bus, device);
- if (ret < 0) {
- fprintf(stderr, "could not send state update notification: %s\n", strerror(-ret));
- goto finish;
- }
- ret = send_warning_update(user_bus, device);
- if (ret < 0) {
- fprintf(stderr, "could not send warning update notification: %s\n", strerror(-ret));
- goto finish;
+ if (ignore_over == 0 || device->current.percentage < ignore_over) {
+ if (upower_device_has_battery(device)) {
+ ret = send_state_update(user_bus, device);
+ if (ret < 0) {
+ fprintf(stderr, "could not send state update notification: %s\n", strerror(-ret));
+ goto finish;
+ }
+ ret = send_warning_update(user_bus, device);
+ if (ret < 0) {
+ fprintf(stderr, "could not send warning update notification: %s\n", strerror(-ret));
+ goto finish;
+ }
+ } else {
+ ret = send_online_update(user_bus, device);
+ if (ret < 0) {
+ fprintf(stderr, "could not send online update notification: %s\n", strerror(-ret));
+ goto finish;
+ }
}
} else {
- ret = send_online_update(user_bus, device);
- if (ret < 0) {
- fprintf(stderr, "could not send online update notification: %s\n", strerror(-ret));
- goto finish;
- }
+ fprintf(stderr, "Ignored because -o: %i | percentage: %f\n", ignore_over, device->current.percentage);
}
next_device:
device->last = device->current;
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ DEPEND="
RDEPEND="${DEPEND}"
BDEPEND="man? ( app-text/scdoc )"

PATCHES=( "${FILESDIR}/${P}-43895-ignore-over-certain-level.patch" )

src_configure() {
local emesonargs=(
$(meson_feature man man-pages)
Expand Down

0 comments on commit 305fecf

Please sign in to comment.