From: Thierry Lorthiois Date: Fri, 15 May 2009 20:44:42 +0000 (+0000) Subject: merge battery applet from Sebastian Reichel X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=3b8e1d7fae07407b54d7ec5f61a64420a4993234;p=chaz%2Ftint2 merge battery applet from Sebastian Reichel --- diff --git a/ChangeLog b/ChangeLog index 272059f..95bb471 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ + +2009-05-15 +- merge battery applet from Sebastian Reichel + 2009-03-14 - add systray option when convert tint-0.6 config file but you need to stop other systemtray program diff --git a/src/Makefile b/src/Makefile index cc79c83..34172db 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2,7 +2,7 @@ CFLAGS= -O2 CC = gcc FLAGS=-Wall -g `pkg-config --cflags --libs cairo pangocairo x11 xinerama xrandr imlib2 glib-2.0` PROGNAME=tint2 -FILES=tint.c server.c panel.c config.c taskbar/task.c taskbar/taskbar.c clock/clock.c systray/systraybar.c util/window.c util/area.c +FILES=tint.c server.c panel.c config.c taskbar/task.c taskbar/taskbar.c battery/battery.c clock/clock.c systray/systraybar.c util/window.c util/area.c ifndef DESTDIR ifndef PREFIX @@ -22,7 +22,7 @@ endif $(PROGNAME): $(FILES) $(SYSTRAYOBJ) - $(CC) $(CFLAGS) -I. -Iutil -Iclock -Itaskbar -Isystray -o $(PROGNAME) $(FILES) $(FLAGS) + $(CC) $(CFLAGS) -I. -Iutil -Ibattery -Iclock -Itaskbar -Isystray -o $(PROGNAME) $(FILES) $(FLAGS) install: install-strip diff --git a/src/config.c b/src/config.c index ab84eb5..d861ba5 100644 --- a/src/config.c +++ b/src/config.c @@ -40,6 +40,7 @@ #include "taskbar.h" #include "systraybar.h" #include "clock.h" +#include "battery.h" #include "panel.h" #include "config.h" #include "window.h" @@ -53,6 +54,8 @@ static char *old_time1_font; static char *old_time2_font; static Area *area_task, *area_task_active; +static char *old_bat1_font; +static char *old_bat2_font; // temporary panel static Panel *panel_config = 0; @@ -306,6 +309,50 @@ void add_entry (char *key, char *value) memcpy(&panel_config->area.pix.border, &a->pix.border, sizeof(Border)); } + /* Battery */ + else if (strcmp (key, "battery") == 0) { + if(atoi(value) == 1) + panel_config->battery.area.on_screen = 1; + } + else if (strcmp (key, "battery_low_status") == 0) { + battery_low_status = atoi(value); + if(battery_low_status < 0 || battery_low_status > 100) + battery_low_status = 0; + } + else if (strcmp (key, "battery_low_cmd") == 0) { + if (battery_low_cmd) g_free(battery_low_cmd); + if (strlen(value) > 0) battery_low_cmd = strdup (value); + else battery_low_cmd = 0; + } + else if (strcmp (key, "bat1_font") == 0) { + if (save_file_config) old_bat1_font = strdup (value); + if (bat1_font_desc) pango_font_description_free(bat1_font_desc); + bat1_font_desc = pango_font_description_from_string (value); + } + else if (strcmp (key, "bat2_font") == 0) { + if (save_file_config) old_bat2_font = strdup (value); + if (bat2_font_desc) pango_font_description_free(bat2_font_desc); + bat2_font_desc = pango_font_description_from_string (value); + } + else if (strcmp (key, "battery_font_color") == 0) { + extract_values(value, &value1, &value2, &value3); + get_color (value1, panel_config->battery.font.color); + if (value2) panel_config->battery.font.alpha = (atoi (value2) / 100.0); + else panel_config->battery.font.alpha = 0.5; + } + else if (strcmp (key, "battery_padding") == 0) { + extract_values(value, &value1, &value2, &value3); + panel_config->battery.area.paddingxlr = panel_config->battery.area.paddingx = atoi (value1); + if (value2) panel_config->battery.area.paddingy = atoi (value2); + if (value3) panel_config->battery.area.paddingx = atoi (value3); + } + else if (strcmp (key, "battery_background_id") == 0) { + int id = atoi (value); + 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)); + } + /* Clock */ else if (strcmp (key, "time1_format") == 0) { if (time1_format) g_free(time1_format); @@ -586,9 +633,10 @@ void config_finish () // clock and systray before taskbar because resize(clock) can resize others object ?? init_panel(); init_clock(); + init_battery(); init_systray(); - init_taskbar(); - visible_object(); + init_taskbar(); + visible_object(); cleanup_config(); @@ -777,6 +825,18 @@ void save_config () fputs("clock_padding = 2 2\n", fp); fputs("clock_background_id = 0\n", fp); + fputs("\n#---------------------------------------------\n", fp); + fputs("# BATTERY\n", fp); + fputs("#---------------------------------------------\n", fp); + fprintf(fp, "battery = %d\n", panel_config->battery.area.on_screen); + fprintf(fp, "battery_low_status = %d\n", battery_low_status); + fprintf(fp, "battery_low_cmd = %s\n", battery_low_cmd); + fprintf(fp, "bat1_font = %s\n", old_bat1_font); + 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); + fputs("\n#---------------------------------------------\n", fp); fputs("# MOUSE ACTION ON TASK\n", fp); fputs("#---------------------------------------------\n", fp); diff --git a/src/panel.c b/src/panel.c index adccfea..3a8bb8f 100644 --- a/src/panel.c +++ b/src/panel.c @@ -71,6 +71,8 @@ void init_panel() // add childs if (p->clock.area.on_screen) p->area.list = g_slist_append(p->area.list, &p->clock); + 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 p->area.list = g_slist_append(p->area.list, &systray); @@ -180,6 +182,8 @@ 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); + if (panel->battery.area.on_screen && panel->battery.area.width) + taskbar_width -= (panel->battery.area.width + panel->area.paddingx); // 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); diff --git a/src/panel.h b/src/panel.h index 67c995c..f7fc0ff 100644 --- a/src/panel.h +++ b/src/panel.h @@ -14,6 +14,7 @@ #include #include +#include "battery.h" #include "common.h" #include "clock.h" #include "task.h" @@ -77,6 +78,10 @@ typedef struct { // clock Clock clock; + // -------------------------------------------------- + // battery + Battery battery; + } Panel; diff --git a/src/systray/systraybar.c b/src/systray/systraybar.c index 160cbca..5840bef 100644 --- a/src/systray/systraybar.c +++ b/src/systray/systraybar.c @@ -66,6 +66,8 @@ 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); + if (panel->battery.area.on_screen) + systray.area.posx -= (panel->battery.area.width + panel->area.paddingx); systray.area.redraw = 1; } @@ -141,6 +143,8 @@ 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); + if (panel->battery.area.on_screen) + systray.area.posx -= (panel->battery.area.width + panel->area.paddingx); systray.area.redraw = 1; diff --git a/src/tint.c b/src/tint.c index 6c4aa68..afb83cb 100644 --- a/src/tint.c +++ b/src/tint.c @@ -92,6 +92,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); + if (battery_low_cmd) g_free(battery_low_cmd); if (server.monitor) free(server.monitor); XFreeGC(server.dsp, server.gc); @@ -136,7 +137,7 @@ void event_button_press (XEvent *e) GSList *l0; Taskbar *tskbar; int x = e->xbutton.x; - int y = e->xbutton.y; + //int y = e->xbutton.y; // unused for (l0 = panel->area.list; l0 ; l0 = l0->next) { tskbar = l0->data; if (!tskbar->area.on_screen) continue; @@ -168,7 +169,7 @@ void event_button_release (XEvent *e) int action = TOGGLE_ICONIFY; int x = e->xbutton.x; - int y = e->xbutton.y; + //int y = e->xbutton.y; // unused switch (e->xbutton.button) { case 2: action = mouse_middle; @@ -466,15 +467,19 @@ void event_timer() if (abs(stv.tv_sec - time_clock.tv_sec) < time_precision) return; - // update clock - time_clock.tv_sec = stv.tv_sec; - time_clock.tv_sec -= time_clock.tv_sec % time_precision; + // update battery + update_battery(&battery_state); + + // update clock + time_clock.tv_sec = stv.tv_sec; + time_clock.tv_sec -= time_clock.tv_sec % time_precision; int i; for (i=0 ; i < nb_panel ; i++) { panel1[i].clock.area.resize = 1; + panel1[i].battery.area.resize = 1; } - panel_refresh = 1; + panel_refresh = 1; } diff --git a/src/tint2 b/src/tint2 index 93633a7..e1830e3 100755 Binary files a/src/tint2 and b/src/tint2 differ diff --git a/tintrc01 b/tintrc01 index 49978ba..1371d1f 100644 --- a/tintrc01 +++ b/tintrc01 @@ -69,6 +69,19 @@ clock_font_color = #ffffff 76 clock_padding = 1 0 clock_background_id = 0 +#--------------------------------------------- +# BATTERY +#--------------------------------------------- +battery = 0 +battery_low_status = 7 +battery_low_cmd = notify-send "battery low" +bat1_font = sans 8 +bat2_font = sans 6 +battery_font_color = #ffffff 76 +battery_padding = 1 0 +battery_background_id = 0 + + #--------------------------------------------- # MOUSE ACTION ON TASK #--------------------------------------------- diff --git a/tintrc02 b/tintrc02 index 8b72566..f4eca84 100644 --- a/tintrc02 +++ b/tintrc02 @@ -71,6 +71,18 @@ clock_font_color = #ffffff 100 clock_padding = 1 0 clock_background_id = 0 +#--------------------------------------------- +# BATTERY +#--------------------------------------------- +battery = 1 +battery_low_status = 7 +battery_low_cmd = notify-send "battery low" +bat1_font = sans 7 +bat2_font = sans 7 +battery_font_color = #ffffff 100 +battery_padding = 1 0 +battery_background_id = 0 + #--------------------------------------------- # MOUSE ACTION ON TASK #--------------------------------------------- diff --git a/tintrc03 b/tintrc03 index 448368f..177563c 100644 --- a/tintrc03 +++ b/tintrc03 @@ -65,6 +65,18 @@ clock_font_color = #000000 80 clock_padding = 8 0 clock_background_id = 1 +#--------------------------------------------- +# BATTERY +#--------------------------------------------- +battery = 0 +battery_low_status = 7 +battery_low_cmd = notify-send "battery low" +bat1_font = sans 7 +bat2_font = sans 7 +battery_font_color = #ffffff 100 +battery_padding = 1 0 +battery_background_id = 0 + #--------------------------------------------- # MOUSE ACTION ON TASK #--------------------------------------------- diff --git a/tintrc04 b/tintrc04 index 0256d4f..15d1f17 100644 --- a/tintrc04 +++ b/tintrc04 @@ -64,6 +64,18 @@ clock_font_color = #ffffff 60 clock_padding = 5 0 clock_background_id = 1 +#--------------------------------------------- +# BATTERY +#--------------------------------------------- +battery = 0 +battery_low_status = 7 +battery_low_cmd = notify-send "battery low" +bat1_font = sans 7 +bat2_font = sans 7 +battery_font_color = #ffffff 100 +battery_padding = 1 0 +battery_background_id = 0 + #--------------------------------------------- # MOUSE ACTION ON TASK #--------------------------------------------- diff --git a/tintrc05 b/tintrc05 index 8b076e0..5de0bfe 100644 --- a/tintrc05 +++ b/tintrc05 @@ -64,6 +64,18 @@ clock_font_color = #ffffff 90 clock_padding = 4 0 clock_background_id = 0 +#--------------------------------------------- +# BATTERY +#--------------------------------------------- +battery = 1 +battery_low_status = 7 +battery_low_cmd = notify-send "battery low" +bat1_font = sans 8 +bat2_font = sans 6 +battery_font_color = #ffffff 100 +battery_padding = 1 0 +battery_background_id = 0 + #--------------------------------------------- # MOUSE ACTION ON TASK #--------------------------------------------- diff --git a/tintrc06 b/tintrc06 index 9ac45e7..c0f2ddb 100644 --- a/tintrc06 +++ b/tintrc06 @@ -70,6 +70,18 @@ clock_font_color = #ffffff 65 clock_padding = 6 0 clock_background_id = 1 +#--------------------------------------------- +# BATTERY +#--------------------------------------------- +battery = 0 +battery_low_status = 7 +battery_low_cmd = notify-send "battery low" +bat1_font = sans 8 +bat2_font = sans 6 +battery_font_color = #ffffff 100 +battery_padding = 1 0 +battery_background_id = 0 + #--------------------------------------------- # MOUSE ACTION ON TASK #--------------------------------------------- diff --git a/tintrc07 b/tintrc07 index 199ef00..a2f6cda 100644 --- a/tintrc07 +++ b/tintrc07 @@ -64,6 +64,18 @@ clock_font_color = #ffffff 60 clock_padding = 2 0 clock_background_id = 1 +#--------------------------------------------- +# BATTERY +#--------------------------------------------- +battery = 1 +battery_low_status = 7 +battery_low_cmd = notify-send "battery low" +bat1_font = sans bold 7 +bat2_font = sans 7 +battery_font_color = #ffffff 60 +battery_padding = 1 0 +battery_background_id = 1 + #--------------------------------------------- # MOUSE ACTION ON TASK #---------------------------------------------