Skip to content

Commit

Permalink
ENH: Add AC power detection for *BSD systems
Browse files Browse the repository at this point in the history
  • Loading branch information
kernc committed Feb 17, 2019
1 parent 7d45933 commit 4e44970
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/events.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "events.h"

#include <glib.h>

#include <libwnck/libwnck.h>

#include <sys/param.h>
#include <time.h>

#include "entry.h"
Expand Down Expand Up @@ -234,6 +235,20 @@ is_on_ac_power ()
return TRUE;
}
return FALSE;

#elif defined(__unix__) && defined(BSD) && !defined(__APPLE__)
// On *BSD, run `apm -a` which returns '1' when AC is online
g_autoptr (GError) err = NULL;
g_autofree char *standard_output = NULL;
char *argv[] = {"apm", "-a", NULL};

g_spawn_sync (NULL, argv, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL,
NULL, NULL, &standard_output, NULL, NULL, &err);
if (err)
g_warning ("Unexpected `apm -a` execution error: %s", err->message);

return standard_output && 0 == g_strcmp0 (g_strstrip (standard_output), "1");

#else
#warning "No battery / AC status support for your platform."
#warning "Defaulting to as if 'always on battery' behavior. Patches welcome!"
Expand Down

0 comments on commit 4e44970

Please sign in to comment.