patch by Christian Ruppert, configure option for battery git-svn-id: http://tint2.googlecode.com/svn/trunk@115 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
@@ -60,6 +60,15 @@ AC_FUNC_FORK
AC_FUNC_MALLOC AC_CHECK_FUNCS([gettimeofday memset select setlocale strcasecmp strchr strdup]) +AC_ARG_ENABLE([battery], + [AS_HELP_STRING([--enable-battery=no], [Disable battery status, only useful for notebooks [default=yes]])], + [case "${enableval}" in + yes) battery=true ;; + no) battery=false ;; + *) AC_MSG_ERROR([bad value ${enableval} for --enable-battery]) ;; + esac], [battery=true]) +AM_CONDITIONAL([ENABLE_BATTERY], [test x$battery = xtrue]) + AC_ARG_ENABLE([examples], [AS_HELP_STRING([--enable-examples], [Install additional $(PACKAGE_NAME)rc examples])], [case "${enableval}" in
@@ -3,10 +3,10 @@ AM_CFLAGS += @PANGOCAIRO_CFLAGS@ @PANGO_CFLAGS@ @CAIRO_CFLAGS@ @GLIB2_CFLAGS@ @GOBJECT2_CFLAGS@ @X11_CFLAGS@ @XINERAMA_CFLAGS@ @IMLIB2_CFLAGS@
AM_LDFLAGS = -Wl,--as-needed -bin_PROGRAMS = tint2 LIBS = @PANGOCAIRO_LIBS@ @PANGO_LIBS@ @CAIRO_LIBS@ @GLIB2_LIBS@ @GOBJECT2_LIBS@ @X11_LIBS@ @XINERAMA_LIBS@ @IMLIB2_LIBS@ -#noinst_LIBRARIES -INCLUDES = -Iutil -Ibattery -Iclock -Itaskbar -Isystray +INCLUDES = -Iutil -Iclock -Itaskbar -Isystray + +bin_PROGRAMS = tint2 tint2_SOURCES = config.c \ util/area.h \ util/common.h \@@ -26,9 +26,15 @@ systray/systraybar.c \
taskbar/taskbar.c \ taskbar/task.c \ taskbar/taskbar.h \ - taskbar/task.h \ - battery/battery.c \ - battery/battery.h + taskbar/task.h + +if ENABLE_BATTERY +AM_CFLAGS += -DENABLE_BATTERY +INCLUDES += -Ibattery +tint2_SOURCES += battery/battery.c \ + battery/battery.h +endif DISTCLEANFILES = Makefile.in +
@@ -44,76 +44,6 @@ char *battery_low_cmd;
char *path_energy_now, *path_energy_full, *path_current_now, *path_status; -void update_battery(struct batstate *data) { - FILE *fp; - char tmp[25]; - int64_t energy_now = 0, energy_full = 0, current_now = 0; - int seconds = 0; - int8_t new_percentage = 0; - - fp = fopen(path_energy_now, "r"); - if(fp != NULL) { - fgets(tmp, sizeof tmp, fp); - energy_now = atoi(tmp); - fclose(fp); - } - - fp = fopen(path_energy_full, "r"); - if(fp != NULL) { - fgets(tmp, sizeof tmp, fp); - energy_full = atoi(tmp); - fclose(fp); - } - - fp = fopen(path_current_now, "r"); - if(fp != NULL) { - fgets(tmp, sizeof tmp, fp); - current_now = atoi(tmp); - fclose(fp); - } - - fp = fopen(path_status, "r"); - if(fp != NULL) { - fgets(tmp, sizeof tmp, fp); - fclose(fp); - } - - data->state = BATTERY_UNKNOWN; - if(strcasecmp(tmp, "Charging\n")==0) data->state = BATTERY_CHARGING; - if(strcasecmp(tmp, "Discharging\n")==0) data->state = BATTERY_DISCHARGING; - - if(current_now > 0) { - switch(data->state) { - case BATTERY_CHARGING: - seconds = 3600 * (energy_full - energy_now) / current_now; - break; - case BATTERY_DISCHARGING: - seconds = 3600 * energy_now / current_now; - break; - default: - seconds = 0; - break; - } - } else seconds = 0; - - data->time.hours = seconds / 3600; - seconds -= 3600 * data->time.hours; - data->time.minutes = seconds / 60; - seconds -= 60 * data->time.minutes; - data->time.seconds = seconds; - - if(energy_full > 0) - new_percentage = (energy_now*100)/energy_full; - - if(battery_low_status != 0 && battery_low_status == new_percentage && data->percentage > new_percentage) { - printf("battery low, executing: %s\n", battery_low_cmd); - if(battery_low_cmd) system(battery_low_cmd); - } - - data->percentage = new_percentage; -} - - void init_battery() { // check battery@@ -171,14 +101,15 @@
for (i=0 ; i < nb_panel ; i++) { panel = &panel1[i]; battery = &panel->battery; + + if (battery_dir == 0) battery->area.on_screen = 0; + if (!battery->area.on_screen) continue; battery->area.parent = panel; battery->area.panel = panel; battery->area._draw_foreground = draw_battery; battery->area._resize = resize_battery; - if (battery_dir == 0) panel->battery.area.on_screen = 0; - if (!battery->area.on_screen) continue; if((fp = fopen(path_energy_now, "r")) == NULL) { fprintf(stderr, "ERROR: battery applet can't open energy_now\n"); panel->battery.area.on_screen = 0;@@ -221,6 +152,76 @@
battery->bat1_posy -= ((bat_time_height_ink + 2) / 2); battery->bat2_posy = battery->bat1_posy + bat_percentage_height + 2 - (bat_percentage_height - bat_percentage_height_ink)/2 - (bat_time_height - bat_time_height_ink)/2; } +} + + +void update_battery() { + FILE *fp; + char tmp[25]; + int64_t energy_now = 0, energy_full = 0, current_now = 0; + int seconds = 0; + int8_t new_percentage = 0; + + fp = fopen(path_energy_now, "r"); + if(fp != NULL) { + fgets(tmp, sizeof tmp, fp); + energy_now = atoi(tmp); + fclose(fp); + } + + fp = fopen(path_energy_full, "r"); + if(fp != NULL) { + fgets(tmp, sizeof tmp, fp); + energy_full = atoi(tmp); + fclose(fp); + } + + fp = fopen(path_current_now, "r"); + if(fp != NULL) { + fgets(tmp, sizeof tmp, fp); + current_now = atoi(tmp); + fclose(fp); + } + + fp = fopen(path_status, "r"); + if(fp != NULL) { + fgets(tmp, sizeof tmp, fp); + fclose(fp); + } + + battery_state.state = BATTERY_UNKNOWN; + if(strcasecmp(tmp, "Charging\n")==0) battery_state.state = BATTERY_CHARGING; + if(strcasecmp(tmp, "Discharging\n")==0) battery_state.state = BATTERY_DISCHARGING; + + if(current_now > 0) { + switch(battery_state.state) { + case BATTERY_CHARGING: + seconds = 3600 * (energy_full - energy_now) / current_now; + break; + case BATTERY_DISCHARGING: + seconds = 3600 * energy_now / current_now; + break; + default: + seconds = 0; + break; + } + } else seconds = 0; + + battery_state.time.hours = seconds / 3600; + seconds -= 3600 * battery_state.time.hours; + battery_state.time.minutes = seconds / 60; + seconds -= 60 * battery_state.time.minutes; + battery_state.time.seconds = seconds; + + if(energy_full > 0) + new_percentage = (energy_now*100)/energy_full; + + if(battery_low_status != 0 && battery_low_status == new_percentage && battery_state.percentage > new_percentage) { + printf("battery low, executing: %s\n", battery_low_cmd); + if(battery_low_cmd) system(battery_low_cmd); + } + + battery_state.percentage = new_percentage; }
@@ -54,7 +54,7 @@ extern char *path_energy_now, *path_energy_full, *path_current_now, *path_status;
// initialize clock : y position, ... -void update_battery(struct batstate *data); +void update_battery(); void init_battery();
@@ -185,7 +185,9 @@ clock->area.posx = panel->area.width - clock->area.width - panel->area.paddingxlr - panel->area.pix.border.width;
// resize other objects on panel panel->area.resize = 1; +#ifdef ENABLE_BATTERY panel->battery.area.resize = 1; +#endif systray.area.resize = 1; panel_refresh = 1; }
@@ -40,10 +40,14 @@ #include "task.h"
#include "taskbar.h" #include "systraybar.h" #include "clock.h" -#include "battery.h" #include "panel.h" #include "config.h" #include "window.h" + +#ifdef ENABLE_BATTERY +#include "battery.h" +#endif + // -------------------------------------------------- // backward compatibility@@ -54,8 +58,10 @@ static char *old_time1_font;
static char *old_time2_font; static Area *area_task, *area_task_active; +#ifdef ENABLE_BATTERY static char *old_bat1_font; static char *old_bat2_font; +#endif // temporary panel static Panel *panel_config = 0;@@ -75,8 +81,8 @@ // append full transparency background
list_back = g_slist_append(0, calloc(1, sizeof(Area))); panel_config = calloc(1, sizeof(Panel)); - // window manager's menu default value == true - wm_menu = 1; + // window manager's menu default value == false + wm_menu = 0; }@@ -314,6 +320,7 @@ else if (strcmp (key, "wm_menu") == 0)
wm_menu = atoi (value); /* Battery */ +#ifdef ENABLE_BATTERY else if (strcmp (key, "battery") == 0) { if(atoi(value) == 1) panel_config->battery.area.on_screen = 1;@@ -356,6 +363,11 @@ Area *a = g_slist_nth_data(list_back, id);
memcpy(&panel_config->battery.area.pix.back, &a->pix.back, sizeof(Color)); memcpy(&panel_config->battery.area.pix.border, &a->pix.border, sizeof(Border)); } +#else + else if ((strcmp (key, "battery") == 0) || (strcmp (key, "battery_low_status") == 0) || (strcmp (key, "battery_low_cmd") == 0) || (strcmp (key, "bat1_font") == 0) || (strcmp (key, "bat2_font") == 0) || (strcmp (key, "battery_font_color") == 0) || (strcmp (key, "battery_padding") == 0) || (strcmp (key, "battery_background_id") == 0)) { + printf("tint2 is build without battery support\n"); + } +#endif /* Clock */ else if (strcmp (key, "time1_format") == 0) {@@ -646,7 +658,9 @@ // TODO: user can configure layout => ordered objects in panel.area.list
// clock and systray before taskbar because resize(clock) can resize others object ?? init_panel(); init_clock(); +#ifdef ENABLE_BATTERY init_battery(); +#endif init_systray(); init_taskbar(); visible_object();@@ -850,6 +864,7 @@ fprintf(fp, "clock_font_color = #%02x%02x%02x %d\n", (int)(panel_config->clock.font.color[0]*255), (int)(panel_config->clock.font.color[1]*255), (int)(panel_config->clock.font.color[2]*255), (int)(panel_config->clock.font.alpha*100));
fputs("clock_padding = 2 2\n", fp); fputs("clock_background_id = 0\n", fp); +#ifdef ENABLE_BATTERY fputs("\n#---------------------------------------------\n", fp); fputs("# BATTERY\n", fp); fputs("#---------------------------------------------\n", fp);@@ -861,6 +876,7 @@ fprintf(fp, "bat2_font = %s\n", old_bat2_font);
fprintf(fp, "battery_font_color = #%02x%02x%02x %d\n", (int)(panel_config->battery.font.color[0]*255), (int)(panel_config->battery.font.color[1]*255), (int)(panel_config->battery.font.color[2]*255), (int)(panel_config->battery.font.alpha*100)); fputs("battery_padding = 2 2\n", fp); fputs("battery_background_id = 0\n", fp); +#endif fputs("\n#---------------------------------------------\n", fp); fputs("# MOUSE ACTION ON TASK\n", fp);
@@ -73,12 +73,13 @@
// add childs if (p->clock.area.on_screen) p->area.list = g_slist_append(p->area.list, &p->clock); +#ifdef ENABLE_BATTERY if (p->battery.area.on_screen) p->area.list = g_slist_append(p->area.list, &p->battery); - if (systray.area.on_screen && i == 0) { - // systray only on first panel +#endif + // systray only on first panel + if (systray.area.on_screen && i == 0) p->area.list = g_slist_append(p->area.list, &systray); - } // detect panel size if (p->pourcentx)@@ -179,8 +180,10 @@
taskbar_width = panel->area.width - (2 * panel->area.paddingxlr) - (2 * panel->area.pix.border.width); if (panel->clock.area.on_screen && panel->clock.area.width) taskbar_width -= (panel->clock.area.width + panel->area.paddingx); +#ifdef ENABLE_BATTERY if (panel->battery.area.on_screen && panel->battery.area.width) taskbar_width -= (panel->battery.area.width + panel->area.paddingx); +#endif // TODO : systray only on first panel. search better implementation ! if (systray.area.on_screen && systray.area.width && panel == &panel1[0]) taskbar_width -= (systray.area.width + panel->area.paddingx);
@@ -14,13 +14,15 @@
#include <pango/pangocairo.h> #include <sys/time.h> -#include "battery.h" #include "common.h" #include "clock.h" #include "task.h" #include "taskbar.h" #include "systraybar.h" +#ifdef ENABLE_BATTERY +#include "battery.h" +#endif extern int signal_pending;@@ -82,8 +84,9 @@ Clock clock;
// -------------------------------------------------- // battery +#ifdef ENABLE_BATTERY Battery battery; - +#endif } Panel;
@@ -267,6 +267,8 @@ server.monitor[0].height = DisplayHeight (server.dsp, server.screen);
} // detect number of desktops + // wait 15s to leave some time for window manager startup + // FIXME: We should also provide a small warning about not respected NETWM specs. for (i=0 ; i < 15 ; i++) { server.nb_desktop = server_get_number_of_desktop (); if (server.nb_desktop > 0) break;
@@ -66,8 +66,10 @@
systray.area.posx = panel->area.width - panel->area.paddingxlr - panel->area.pix.border.width - systray.area.width; if (panel->clock.area.on_screen) systray.area.posx -= (panel->clock.area.width + panel->area.paddingx); +#ifdef ENABLE_BATTERY if (panel->battery.area.on_screen) systray.area.posx -= (panel->battery.area.width + panel->area.paddingx); +#endif systray.area.redraw = 1; }@@ -145,8 +147,10 @@
systray.area.posx = panel->area.width - panel->area.pix.border.width - panel->area.paddingxlr - systray.area.width; if (panel->clock.area.on_screen) systray.area.posx -= (panel->clock.area.width + panel->area.paddingx); +#ifdef ENABLE_BATTERY if (panel->battery.area.on_screen) systray.area.posx -= (panel->battery.area.width + panel->area.paddingx); +#endif systray.area.redraw = 1;@@ -257,29 +261,28 @@
gboolean error; int window_error_handler(Display *d, XErrorEvent *e) { - d=d;e=e; - if (e->error_code == BadWindow) { - error = TRUE; - } else { - printf("error_handler %d\n", e->error_code); - abort(); - } - return 0; + d=d;e=e; + error = TRUE; + if (e->error_code != BadWindow) { + printf("error_handler %d\n", e->error_code); + } + return 0; } gboolean icon_swallow(Window id) { - XErrorHandler old; - Panel *panel = systray.area.panel; + XErrorHandler old; + Panel *panel = systray.area.panel; - error = FALSE; - old = XSetErrorHandler(window_error_handler); - XReparentWindow(server.dsp, id, panel->main_win, 0, 0); - XSync(server.dsp, False); - XSetErrorHandler(old); + error = FALSE; + old = XSetErrorHandler(window_error_handler); + XReparentWindow(server.dsp, id, panel->main_win, 0, 0); + printf("icon_swallow %lx %lx\n", id, panel->main_win); + XSync(server.dsp, False); + XSetErrorHandler(old); - return !error; + return !error; }@@ -305,19 +308,6 @@ // changed in systray force resize on panel
Panel *panel = systray.area.panel; panel->area.resize = 1; panel_refresh = 1; - -// => calcul x, y, width, height dans resize -/* - // find the positon for the systray app window - int count = g_slist_length(icons); - traywin->x = border + ((width % icon_size) / 2) + - (count % (width / icon_size)) * icon_size; - traywin->y = border + ((height % icon_size) / 2) + - (count / (height / icon_size)) * icon_size; - - // add the new icon to the list - icons = g_slist_append(icons, traywin); -*/ return TRUE; }
@@ -50,8 +50,9 @@ void init ()
{ // Set signal handler signal(SIGUSR1, signal_handler); - signal(SIGINT, signal_handler); - signal(SIGTERM, signal_handler); + signal(SIGINT, signal_handler); + signal(SIGTERM, signal_handler); + signal(SIGHUP, signal_handler); // set global data memset(&server, 0, sizeof(Server_global));@@ -92,6 +93,7 @@ if (time1_font_desc) pango_font_description_free(time1_font_desc);
if (time2_font_desc) pango_font_description_free(time2_font_desc); if (time1_format) g_free(time1_format); if (time2_format) g_free(time2_format); +#ifdef ENABLE_BATTERY if (bat1_font_desc) pango_font_description_free(bat1_font_desc); if (bat2_font_desc) pango_font_description_free(bat2_font_desc); if (battery_low_cmd) g_free(battery_low_cmd);@@ -99,6 +101,7 @@ if (path_energy_now) g_free(path_energy_now);
if (path_energy_full) g_free(path_energy_full); if (path_current_now) g_free(path_current_now); if (path_status) g_free(path_status); +#endif if (clock_lclick_command) g_free(clock_lclick_command); if (clock_rclick_command) g_free(clock_rclick_command);@@ -513,11 +516,13 @@ task_urgent->area.redraw = 1;
} // update battery +#ifdef ENABLE_BATTERY if (panel1[0].battery.area.on_screen) { - update_battery(&battery_state); + update_battery(); for (i=0 ; i < nb_panel ; i++) panel1[i].battery.area.resize = 1; } +#endif // update clock if (time1_format) {@@ -626,6 +631,7 @@ case SIGUSR1:
goto load_config; case SIGINT: case SIGTERM: + case SIGHUP: cleanup (); return 0; }