]> Dogcows Code - chaz/tint2/commitdiff
patch by Christian Ruppert, configure option for battery
authorThierry Lorthiois <lorthiois@bbsoft.fr>
Thu, 18 Jun 2009 20:26:40 +0000 (20:26 +0000)
committerThierry Lorthiois <lorthiois@bbsoft.fr>
Thu, 18 Jun 2009 20:26:40 +0000 (20:26 +0000)
12 files changed:
ChangeLog
configure.ac
src/Makefile.am
src/battery/battery.c
src/battery/battery.h
src/clock/clock.c
src/config.c
src/panel.c
src/panel.h
src/server.c
src/systray/systraybar.c
src/tint.c

index 92a0d3d6b2329232a2f02de975ffe90fbb6c957a..fd40836728c9fd09ee0ae66f54403cc0e61396a9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+2009-06-18
+- patch by Christian Ruppert, configure option for battery
+
 2009-06-14
 - revert r78, fixed issue 100
 
index 226e8cb338cb5a2c3883bc4a2eb82bb79c5b3e84..644c98a7c02f4152401dbbf97fbbd461d12affb0 100644 (file)
@@ -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
index 43d95e78acd2dadc500a8795634cc56f196c06b8..6b83cd4deb5d24b8354f9734abf08829cf5fbd7b 100644 (file)
@@ -3,10 +3,10 @@ AM_CFLAGS += @PANGOCAIRO_CFLAGS@ @PANGO_CFLAGS@ @CAIRO_CFLAGS@ @GLIB2_CFLAGS@ @G
 
 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 @@ tint2_SOURCES = config.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
 
+
index 222fbc5e1338634936a6ebac5f3edc19ef0aa937..74e93ec5e19e29a98336114a76088528aae41ff1 100644 (file)
@@ -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
@@ -172,13 +102,14 @@ void init_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;
@@ -224,6 +155,76 @@ void init_battery()
 }
 
 
+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;
index f6d227ab0a03cec3b5819e6ec2f36e281066befd..ac979b21eee25f3ef57ad7239c04a7949375611c 100644 (file)
@@ -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();
 
index 01b1991e247d090e85015c720403ef4b9cedd086..10778d4ee2d467adbb4a9e2999f41a7ec763ef47 100644 (file)
@@ -185,7 +185,9 @@ void resize_clock (void *obj)
 
       // 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;
    }
index e359e1c5be3c55e79aa0f01a267a3610d3e9f97d..f70b78a9a8db0cf055938bb4d05031f7f5aebb78 100644 (file)
 #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;
@@ -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 @@ void init_config()
    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 @@ void add_entry (char *key, char *value)
       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 @@ void add_entry (char *key, char *value)
       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 @@ void config_finish ()
        // 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 @@ void save_config ()
    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 @@ void save_config ()
        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);
index 11dafe16d497ccd7e167be34327e0fc160215b9c..825a382e64fb03da2accbaa1d8f924406f9a429e 100644 (file)
@@ -73,12 +73,13 @@ void init_panel()
                // 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 @@ void resize_panel(void *obj)
    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);
index 4de3c59335589b80f4e5824718f1cda100a2b382..dbae95df16a6638faf509ead11c5182333a3f6c1 100644 (file)
 #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 @@ typedef struct {
 
        // --------------------------------------------------
        // battery
+#ifdef ENABLE_BATTERY
        Battery battery;
-
+#endif
 } Panel;
 
 
index db069930a6bfdf3e9da783febad492fb823c5ca8..33e4014bf782c10cb98f5568b7e4110b9ff3dcef 100644 (file)
@@ -267,6 +267,8 @@ next:
    }
 
        // 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;
index 49f0253ed626872bc5b0ebaaa38db083aee07fd0..9687c9aa9e71d255ab2fbba7aa5573eb3b9c0fdd 100644 (file)
@@ -66,8 +66,10 @@ void init_systray()
        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 @@ void resize_systray(void *obj)
        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 @@ void fix_geometry()
 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;
 }
 
 
@@ -306,19 +309,6 @@ gboolean add_icon(Window id)
        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;
 }
 
index 5c93aaaf2e1ab3bd4adb7f3a6c96c02494212ad7..baaaf0326928a82b3a478d29304042830b9bc267 100644 (file)
@@ -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 @@ void cleanup()
    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 @@ void cleanup()
        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 @@ void event_timer()
        }
 
        // 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 @@ load_config:
             goto load_config;
                        case SIGINT:
                        case SIGTERM:
+                       case SIGHUP:
                           cleanup ();
                           return 0;
       }
This page took 0.040586 seconds and 4 git commands to generate.