all repos — tint2 @ db490247e07974a711bd9b3b52d4f917ee6a8f48

fork of the tint2 desktop panel for my custom setup - only minimized windows across all desktops for the taskbar

Battery: support for ac connection event cmd

This add two new config options "ac_connected_cmd" and
"ac_disconnected_cmd". These commands are executed when
AC (mains supply) is connected or disconnected.
Sebastian Reichel sre@ring0.de
commit

db490247e07974a711bd9b3b52d4f917ee6a8f48

parent

3c45cf29c7bfb05242dde4f55d12cc1972ff1b7d

4 files changed, 33 insertions(+), 0 deletions(-)

jump to
M src/battery/battery.csrc/battery/battery.c

@@ -44,6 +44,8 @@ static char buf_bat_time[20];

int8_t battery_low_status; unsigned char battery_low_cmd_sent; +char *ac_connected_cmd; +char *ac_disconnected_cmd; char *battery_low_cmd; char *battery_lclick_command; char *battery_mclick_command;

@@ -59,6 +61,7 @@ return;

int old_found = battery_found; int old_percentage = battery_state.percentage; + int old_ac_connected = battery_state.ac_connected; int16_t old_hours = battery_state.time.hours; int8_t old_minutes = battery_state.time.minutes;

@@ -71,6 +74,14 @@ init_battery();

// Try again update_battery(); } + + if (old_ac_connected != battery_state.ac_connected) { + if(battery_state.ac_connected) + tint_exec(ac_connected_cmd); + else + tint_exec(ac_disconnected_cmd); + } + if (old_found == battery_found && old_percentage == battery_state.percentage && old_hours == battery_state.time.hours &&

@@ -215,6 +226,7 @@

/* reset */ battery_state.state = BATTERY_UNKNOWN; battery_state.percentage = 0; + battery_state.ac_connected = FALSE; batstate_set_time(&battery_state, 0); err = battery_os_update(&battery_state);
M src/battery/battery.hsrc/battery/battery.h

@@ -44,6 +44,7 @@ typedef struct batstate {

int percentage; struct battime time; enum chargestate state; + gboolean ac_connected; } batstate; extern struct batstate battery_state;

@@ -55,6 +56,9 @@ extern int percentage_hide;

extern int8_t battery_low_status; extern char *battery_low_cmd; + +extern char *ac_connected_cmd; +extern char *ac_disconnected_cmd; extern char *battery_lclick_command; extern char *battery_mclick_command;
M src/battery/linux.csrc/battery/linux.c

@@ -343,6 +343,7 @@

gboolean charging = FALSE; gboolean discharging = FALSE; gboolean full = FALSE; + gboolean ac_connected = FALSE; for (l = batteries; l != NULL; l = l->next) { struct psy_battery *bat = l->data;

@@ -360,6 +361,7 @@

for (l = mains; l != NULL; l = l->next) { struct psy_mains *ac = l->data; update_linux_mains(ac); + ac_connected |= (ac->online); } /* build global state */

@@ -381,6 +383,9 @@ batstate_set_time(state, seconds);

/* calculate percentage */ state->percentage = energy_to_percent(total_energy_now, total_energy_full); + + /* AC state */ + state->ac_connected = ac_connected; return 0; }
M src/config.csrc/config.c

@@ -394,6 +394,18 @@ if (strlen(value) > 0)

battery_low_cmd = strdup (value); #endif } + else if (strcmp (key, "ac_connected_cmd") == 0) { +#ifdef ENABLE_BATTERY + if (strlen(value) > 0) + ac_connected_cmd = strdup (value); +#endif + } + else if (strcmp (key, "ac_disconnected_cmd") == 0) { +#ifdef ENABLE_BATTERY + if (strlen(value) > 0) + ac_disconnected_cmd = strdup (value); +#endif + } else if (strcmp (key, "bat1_font") == 0) { #ifdef ENABLE_BATTERY bat1_font_desc = pango_font_description_from_string (value);