+2009-06-18
+- patch by Christian Ruppert, configure option for battery
+
2009-06-14
- revert r78, fixed issue 100
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
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 \
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
+
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
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;
}
+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;
+}
+
+
void draw_battery (void *obj, cairo_t *c, int active)
{
Battery *battery = obj;
// initialize clock : y position, ...
-void update_battery(struct batstate *data);
+void update_battery();
void init_battery();
// 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;
}
#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
static int save_file_config;
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;
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;
}
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;
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) {
// 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();
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);
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);
// 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)
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);
#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;
// --------------------------------------------------
// battery
+#ifdef ENABLE_BATTERY
Battery battery;
-
+#endif
} Panel;
}
// 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;
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;
}
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;
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;
}
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;
}
{
// 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));
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);
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);
}
// 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) {
goto load_config;
case SIGINT:
case SIGTERM:
+ case SIGHUP:
cleanup ();
return 0;
}