merge battery applet from Sebastian Reichel
git-svn-id: http://tint2.googlecode.com/svn/trunk@73 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
This commit is contained in:
parent
3be419b59b
commit
3d07eeeb48
15 changed files with 177 additions and 10 deletions
|
@ -1,3 +1,7 @@
|
|||
|
||||
2009-05-15
|
||||
- merge battery applet from Sebastian Reichel <elektranox@gmail.com>
|
||||
|
||||
2009-03-14
|
||||
- add systray option when convert tint-0.6 config file
|
||||
but you need to stop other systemtray program
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
60
src/config.c
60
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,6 +633,7 @@ 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();
|
||||
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <pango/pangocairo.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#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;
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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,6 +467,9 @@ void event_timer()
|
|||
|
||||
if (abs(stv.tv_sec - time_clock.tv_sec) < time_precision) return;
|
||||
|
||||
// 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;
|
||||
|
@ -473,6 +477,7 @@ void event_timer()
|
|||
int i;
|
||||
for (i=0 ; i < nb_panel ; i++) {
|
||||
panel1[i].clock.area.resize = 1;
|
||||
panel1[i].battery.area.resize = 1;
|
||||
}
|
||||
panel_refresh = 1;
|
||||
}
|
||||
|
|
BIN
src/tint2
BIN
src/tint2
Binary file not shown.
13
tintrc01
13
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
|
||||
#---------------------------------------------
|
||||
|
|
12
tintrc02
12
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
|
||||
#---------------------------------------------
|
||||
|
|
12
tintrc03
12
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
|
||||
#---------------------------------------------
|
||||
|
|
12
tintrc04
12
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
|
||||
#---------------------------------------------
|
||||
|
|
12
tintrc05
12
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
|
||||
#---------------------------------------------
|
||||
|
|
12
tintrc06
12
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
|
||||
#---------------------------------------------
|
||||
|
|
12
tintrc07
12
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
|
||||
#---------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue