patch by Christian Ruppert, configure option for battery
git-svn-id: http://tint2.googlecode.com/svn/trunk@115 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
This commit is contained in:
parent
81930a6861
commit
ce50e9c159
12 changed files with 160 additions and 119 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
2009-06-18
|
||||||
|
- patch by Christian Ruppert, configure option for battery
|
||||||
|
|
||||||
2009-06-14
|
2009-06-14
|
||||||
- revert r78, fixed issue 100
|
- revert r78, fixed issue 100
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,15 @@ AC_FUNC_FORK
|
||||||
AC_FUNC_MALLOC
|
AC_FUNC_MALLOC
|
||||||
AC_CHECK_FUNCS([gettimeofday memset select setlocale strcasecmp strchr strdup])
|
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],
|
AC_ARG_ENABLE([examples],
|
||||||
[AS_HELP_STRING([--enable-examples], [Install additional $(PACKAGE_NAME)rc examples])],
|
[AS_HELP_STRING([--enable-examples], [Install additional $(PACKAGE_NAME)rc examples])],
|
||||||
[case "${enableval}" in
|
[case "${enableval}" in
|
||||||
|
|
|
@ -3,10 +3,10 @@ AM_CFLAGS += @PANGOCAIRO_CFLAGS@ @PANGO_CFLAGS@ @CAIRO_CFLAGS@ @GLIB2_CFLAGS@ @G
|
||||||
|
|
||||||
AM_LDFLAGS = -Wl,--as-needed
|
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@
|
LIBS = @PANGOCAIRO_LIBS@ @PANGO_LIBS@ @CAIRO_LIBS@ @GLIB2_LIBS@ @GOBJECT2_LIBS@ @X11_LIBS@ @XINERAMA_LIBS@ @IMLIB2_LIBS@
|
||||||
#noinst_LIBRARIES
|
INCLUDES = -Iutil -Iclock -Itaskbar -Isystray
|
||||||
INCLUDES = -Iutil -Ibattery -Iclock -Itaskbar -Isystray
|
|
||||||
|
bin_PROGRAMS = tint2
|
||||||
tint2_SOURCES = config.c \
|
tint2_SOURCES = config.c \
|
||||||
util/area.h \
|
util/area.h \
|
||||||
util/common.h \
|
util/common.h \
|
||||||
|
@ -26,9 +26,15 @@ tint2_SOURCES = config.c \
|
||||||
taskbar/taskbar.c \
|
taskbar/taskbar.c \
|
||||||
taskbar/task.c \
|
taskbar/task.c \
|
||||||
taskbar/taskbar.h \
|
taskbar/taskbar.h \
|
||||||
taskbar/task.h \
|
taskbar/task.h
|
||||||
battery/battery.c \
|
|
||||||
battery/battery.h
|
if ENABLE_BATTERY
|
||||||
|
AM_CFLAGS += -DENABLE_BATTERY
|
||||||
|
INCLUDES += -Ibattery
|
||||||
|
tint2_SOURCES += battery/battery.c \
|
||||||
|
battery/battery.h
|
||||||
|
endif
|
||||||
|
|
||||||
DISTCLEANFILES = Makefile.in
|
DISTCLEANFILES = Makefile.in
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,76 +44,6 @@ char *battery_low_cmd;
|
||||||
char *path_energy_now, *path_energy_full, *path_current_now, *path_status;
|
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()
|
void init_battery()
|
||||||
{
|
{
|
||||||
// check battery
|
// check battery
|
||||||
|
@ -172,13 +102,14 @@ void init_battery()
|
||||||
panel = &panel1[i];
|
panel = &panel1[i];
|
||||||
battery = &panel->battery;
|
battery = &panel->battery;
|
||||||
|
|
||||||
|
if (battery_dir == 0) battery->area.on_screen = 0;
|
||||||
|
if (!battery->area.on_screen) continue;
|
||||||
|
|
||||||
battery->area.parent = panel;
|
battery->area.parent = panel;
|
||||||
battery->area.panel = panel;
|
battery->area.panel = panel;
|
||||||
battery->area._draw_foreground = draw_battery;
|
battery->area._draw_foreground = draw_battery;
|
||||||
battery->area._resize = resize_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) {
|
if((fp = fopen(path_energy_now, "r")) == NULL) {
|
||||||
fprintf(stderr, "ERROR: battery applet can't open energy_now\n");
|
fprintf(stderr, "ERROR: battery applet can't open energy_now\n");
|
||||||
panel->battery.area.on_screen = 0;
|
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)
|
void draw_battery (void *obj, cairo_t *c, int active)
|
||||||
{
|
{
|
||||||
Battery *battery = obj;
|
Battery *battery = obj;
|
||||||
|
|
|
@ -54,7 +54,7 @@ extern char *path_energy_now, *path_energy_full, *path_current_now, *path_status
|
||||||
|
|
||||||
|
|
||||||
// initialize clock : y position, ...
|
// initialize clock : y position, ...
|
||||||
void update_battery(struct batstate *data);
|
void update_battery();
|
||||||
|
|
||||||
void init_battery();
|
void init_battery();
|
||||||
|
|
||||||
|
|
|
@ -185,7 +185,9 @@ void resize_clock (void *obj)
|
||||||
|
|
||||||
// resize other objects on panel
|
// resize other objects on panel
|
||||||
panel->area.resize = 1;
|
panel->area.resize = 1;
|
||||||
|
#ifdef ENABLE_BATTERY
|
||||||
panel->battery.area.resize = 1;
|
panel->battery.area.resize = 1;
|
||||||
|
#endif
|
||||||
systray.area.resize = 1;
|
systray.area.resize = 1;
|
||||||
panel_refresh = 1;
|
panel_refresh = 1;
|
||||||
}
|
}
|
||||||
|
|
22
src/config.c
22
src/config.c
|
@ -40,11 +40,15 @@
|
||||||
#include "taskbar.h"
|
#include "taskbar.h"
|
||||||
#include "systraybar.h"
|
#include "systraybar.h"
|
||||||
#include "clock.h"
|
#include "clock.h"
|
||||||
#include "battery.h"
|
|
||||||
#include "panel.h"
|
#include "panel.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
|
||||||
|
#ifdef ENABLE_BATTERY
|
||||||
|
#include "battery.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------
|
// --------------------------------------------------
|
||||||
// backward compatibility
|
// backward compatibility
|
||||||
static int save_file_config;
|
static int save_file_config;
|
||||||
|
@ -54,8 +58,10 @@ static char *old_time1_font;
|
||||||
static char *old_time2_font;
|
static char *old_time2_font;
|
||||||
static Area *area_task, *area_task_active;
|
static Area *area_task, *area_task_active;
|
||||||
|
|
||||||
|
#ifdef ENABLE_BATTERY
|
||||||
static char *old_bat1_font;
|
static char *old_bat1_font;
|
||||||
static char *old_bat2_font;
|
static char *old_bat2_font;
|
||||||
|
#endif
|
||||||
|
|
||||||
// temporary panel
|
// temporary panel
|
||||||
static Panel *panel_config = 0;
|
static Panel *panel_config = 0;
|
||||||
|
@ -75,8 +81,8 @@ void init_config()
|
||||||
list_back = g_slist_append(0, calloc(1, sizeof(Area)));
|
list_back = g_slist_append(0, calloc(1, sizeof(Area)));
|
||||||
|
|
||||||
panel_config = calloc(1, sizeof(Panel));
|
panel_config = calloc(1, sizeof(Panel));
|
||||||
// window manager's menu default value == true
|
// window manager's menu default value == false
|
||||||
wm_menu = 1;
|
wm_menu = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -314,6 +320,7 @@ void add_entry (char *key, char *value)
|
||||||
wm_menu = atoi (value);
|
wm_menu = atoi (value);
|
||||||
|
|
||||||
/* Battery */
|
/* Battery */
|
||||||
|
#ifdef ENABLE_BATTERY
|
||||||
else if (strcmp (key, "battery") == 0) {
|
else if (strcmp (key, "battery") == 0) {
|
||||||
if(atoi(value) == 1)
|
if(atoi(value) == 1)
|
||||||
panel_config->battery.area.on_screen = 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.back, &a->pix.back, sizeof(Color));
|
||||||
memcpy(&panel_config->battery.area.pix.border, &a->pix.border, sizeof(Border));
|
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 */
|
/* Clock */
|
||||||
else if (strcmp (key, "time1_format") == 0) {
|
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 ??
|
// clock and systray before taskbar because resize(clock) can resize others object ??
|
||||||
init_panel();
|
init_panel();
|
||||||
init_clock();
|
init_clock();
|
||||||
|
#ifdef ENABLE_BATTERY
|
||||||
init_battery();
|
init_battery();
|
||||||
|
#endif
|
||||||
init_systray();
|
init_systray();
|
||||||
init_taskbar();
|
init_taskbar();
|
||||||
visible_object();
|
visible_object();
|
||||||
|
@ -850,6 +864,7 @@ void save_config ()
|
||||||
fputs("clock_padding = 2 2\n", fp);
|
fputs("clock_padding = 2 2\n", fp);
|
||||||
fputs("clock_background_id = 0\n", fp);
|
fputs("clock_background_id = 0\n", fp);
|
||||||
|
|
||||||
|
#ifdef ENABLE_BATTERY
|
||||||
fputs("\n#---------------------------------------------\n", fp);
|
fputs("\n#---------------------------------------------\n", fp);
|
||||||
fputs("# BATTERY\n", fp);
|
fputs("# BATTERY\n", fp);
|
||||||
fputs("#---------------------------------------------\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));
|
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_padding = 2 2\n", fp);
|
||||||
fputs("battery_background_id = 0\n", fp);
|
fputs("battery_background_id = 0\n", fp);
|
||||||
|
#endif
|
||||||
|
|
||||||
fputs("\n#---------------------------------------------\n", fp);
|
fputs("\n#---------------------------------------------\n", fp);
|
||||||
fputs("# MOUSE ACTION ON TASK\n", fp);
|
fputs("# MOUSE ACTION ON TASK\n", fp);
|
||||||
|
|
|
@ -73,12 +73,13 @@ void init_panel()
|
||||||
// add childs
|
// add childs
|
||||||
if (p->clock.area.on_screen)
|
if (p->clock.area.on_screen)
|
||||||
p->area.list = g_slist_append(p->area.list, &p->clock);
|
p->area.list = g_slist_append(p->area.list, &p->clock);
|
||||||
|
#ifdef ENABLE_BATTERY
|
||||||
if (p->battery.area.on_screen)
|
if (p->battery.area.on_screen)
|
||||||
p->area.list = g_slist_append(p->area.list, &p->battery);
|
p->area.list = g_slist_append(p->area.list, &p->battery);
|
||||||
if (systray.area.on_screen && i == 0) {
|
#endif
|
||||||
// systray only on first panel
|
// systray only on first panel
|
||||||
|
if (systray.area.on_screen && i == 0)
|
||||||
p->area.list = g_slist_append(p->area.list, &systray);
|
p->area.list = g_slist_append(p->area.list, &systray);
|
||||||
}
|
|
||||||
|
|
||||||
// detect panel size
|
// detect panel size
|
||||||
if (p->pourcentx)
|
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);
|
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)
|
if (panel->clock.area.on_screen && panel->clock.area.width)
|
||||||
taskbar_width -= (panel->clock.area.width + panel->area.paddingx);
|
taskbar_width -= (panel->clock.area.width + panel->area.paddingx);
|
||||||
|
#ifdef ENABLE_BATTERY
|
||||||
if (panel->battery.area.on_screen && panel->battery.area.width)
|
if (panel->battery.area.on_screen && panel->battery.area.width)
|
||||||
taskbar_width -= (panel->battery.area.width + panel->area.paddingx);
|
taskbar_width -= (panel->battery.area.width + panel->area.paddingx);
|
||||||
|
#endif
|
||||||
// TODO : systray only on first panel. search better implementation !
|
// TODO : systray only on first panel. search better implementation !
|
||||||
if (systray.area.on_screen && systray.area.width && panel == &panel1[0])
|
if (systray.area.on_screen && systray.area.width && panel == &panel1[0])
|
||||||
taskbar_width -= (systray.area.width + panel->area.paddingx);
|
taskbar_width -= (systray.area.width + panel->area.paddingx);
|
||||||
|
|
|
@ -14,13 +14,15 @@
|
||||||
#include <pango/pangocairo.h>
|
#include <pango/pangocairo.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
#include "battery.h"
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "clock.h"
|
#include "clock.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
#include "taskbar.h"
|
#include "taskbar.h"
|
||||||
#include "systraybar.h"
|
#include "systraybar.h"
|
||||||
|
|
||||||
|
#ifdef ENABLE_BATTERY
|
||||||
|
#include "battery.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
extern int signal_pending;
|
extern int signal_pending;
|
||||||
|
@ -82,8 +84,9 @@ typedef struct {
|
||||||
|
|
||||||
// --------------------------------------------------
|
// --------------------------------------------------
|
||||||
// battery
|
// battery
|
||||||
|
#ifdef ENABLE_BATTERY
|
||||||
Battery battery;
|
Battery battery;
|
||||||
|
#endif
|
||||||
} Panel;
|
} Panel;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -267,6 +267,8 @@ next:
|
||||||
}
|
}
|
||||||
|
|
||||||
// detect number of desktops
|
// 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++) {
|
for (i=0 ; i < 15 ; i++) {
|
||||||
server.nb_desktop = server_get_number_of_desktop ();
|
server.nb_desktop = server_get_number_of_desktop ();
|
||||||
if (server.nb_desktop > 0) break;
|
if (server.nb_desktop > 0) break;
|
||||||
|
|
|
@ -66,8 +66,10 @@ void init_systray()
|
||||||
systray.area.posx = panel->area.width - panel->area.paddingxlr - panel->area.pix.border.width - systray.area.width;
|
systray.area.posx = panel->area.width - panel->area.paddingxlr - panel->area.pix.border.width - systray.area.width;
|
||||||
if (panel->clock.area.on_screen)
|
if (panel->clock.area.on_screen)
|
||||||
systray.area.posx -= (panel->clock.area.width + panel->area.paddingx);
|
systray.area.posx -= (panel->clock.area.width + panel->area.paddingx);
|
||||||
|
#ifdef ENABLE_BATTERY
|
||||||
if (panel->battery.area.on_screen)
|
if (panel->battery.area.on_screen)
|
||||||
systray.area.posx -= (panel->battery.area.width + panel->area.paddingx);
|
systray.area.posx -= (panel->battery.area.width + panel->area.paddingx);
|
||||||
|
#endif
|
||||||
|
|
||||||
systray.area.redraw = 1;
|
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;
|
systray.area.posx = panel->area.width - panel->area.pix.border.width - panel->area.paddingxlr - systray.area.width;
|
||||||
if (panel->clock.area.on_screen)
|
if (panel->clock.area.on_screen)
|
||||||
systray.area.posx -= (panel->clock.area.width + panel->area.paddingx);
|
systray.area.posx -= (panel->clock.area.width + panel->area.paddingx);
|
||||||
|
#ifdef ENABLE_BATTERY
|
||||||
if (panel->battery.area.on_screen)
|
if (panel->battery.area.on_screen)
|
||||||
systray.area.posx -= (panel->battery.area.width + panel->area.paddingx);
|
systray.area.posx -= (panel->battery.area.width + panel->area.paddingx);
|
||||||
|
#endif
|
||||||
|
|
||||||
systray.area.redraw = 1;
|
systray.area.redraw = 1;
|
||||||
|
|
||||||
|
@ -257,29 +261,28 @@ void fix_geometry()
|
||||||
gboolean error;
|
gboolean error;
|
||||||
int window_error_handler(Display *d, XErrorEvent *e)
|
int window_error_handler(Display *d, XErrorEvent *e)
|
||||||
{
|
{
|
||||||
d=d;e=e;
|
d=d;e=e;
|
||||||
if (e->error_code == BadWindow) {
|
error = TRUE;
|
||||||
error = TRUE;
|
if (e->error_code != BadWindow) {
|
||||||
} else {
|
printf("error_handler %d\n", e->error_code);
|
||||||
printf("error_handler %d\n", e->error_code);
|
}
|
||||||
abort();
|
return 0;
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
gboolean icon_swallow(Window id)
|
gboolean icon_swallow(Window id)
|
||||||
{
|
{
|
||||||
XErrorHandler old;
|
XErrorHandler old;
|
||||||
Panel *panel = systray.area.panel;
|
Panel *panel = systray.area.panel;
|
||||||
|
|
||||||
error = FALSE;
|
error = FALSE;
|
||||||
old = XSetErrorHandler(window_error_handler);
|
old = XSetErrorHandler(window_error_handler);
|
||||||
XReparentWindow(server.dsp, id, panel->main_win, 0, 0);
|
XReparentWindow(server.dsp, id, panel->main_win, 0, 0);
|
||||||
XSync(server.dsp, False);
|
printf("icon_swallow %lx %lx\n", id, panel->main_win);
|
||||||
XSetErrorHandler(old);
|
XSync(server.dsp, False);
|
||||||
|
XSetErrorHandler(old);
|
||||||
|
|
||||||
return !error;
|
return !error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -306,19 +309,6 @@ gboolean add_icon(Window id)
|
||||||
panel->area.resize = 1;
|
panel->area.resize = 1;
|
||||||
panel_refresh = 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;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
src/tint.c
12
src/tint.c
|
@ -50,8 +50,9 @@ void init ()
|
||||||
{
|
{
|
||||||
// Set signal handler
|
// Set signal handler
|
||||||
signal(SIGUSR1, signal_handler);
|
signal(SIGUSR1, signal_handler);
|
||||||
signal(SIGINT, signal_handler);
|
signal(SIGINT, signal_handler);
|
||||||
signal(SIGTERM, signal_handler);
|
signal(SIGTERM, signal_handler);
|
||||||
|
signal(SIGHUP, signal_handler);
|
||||||
|
|
||||||
// set global data
|
// set global data
|
||||||
memset(&server, 0, sizeof(Server_global));
|
memset(&server, 0, sizeof(Server_global));
|
||||||
|
@ -92,6 +93,7 @@ void cleanup()
|
||||||
if (time2_font_desc) pango_font_description_free(time2_font_desc);
|
if (time2_font_desc) pango_font_description_free(time2_font_desc);
|
||||||
if (time1_format) g_free(time1_format);
|
if (time1_format) g_free(time1_format);
|
||||||
if (time2_format) g_free(time2_format);
|
if (time2_format) g_free(time2_format);
|
||||||
|
#ifdef ENABLE_BATTERY
|
||||||
if (bat1_font_desc) pango_font_description_free(bat1_font_desc);
|
if (bat1_font_desc) pango_font_description_free(bat1_font_desc);
|
||||||
if (bat2_font_desc) pango_font_description_free(bat2_font_desc);
|
if (bat2_font_desc) pango_font_description_free(bat2_font_desc);
|
||||||
if (battery_low_cmd) g_free(battery_low_cmd);
|
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_energy_full) g_free(path_energy_full);
|
||||||
if (path_current_now) g_free(path_current_now);
|
if (path_current_now) g_free(path_current_now);
|
||||||
if (path_status) g_free(path_status);
|
if (path_status) g_free(path_status);
|
||||||
|
#endif
|
||||||
if (clock_lclick_command) g_free(clock_lclick_command);
|
if (clock_lclick_command) g_free(clock_lclick_command);
|
||||||
if (clock_rclick_command) g_free(clock_rclick_command);
|
if (clock_rclick_command) g_free(clock_rclick_command);
|
||||||
|
|
||||||
|
@ -513,11 +516,13 @@ void event_timer()
|
||||||
}
|
}
|
||||||
|
|
||||||
// update battery
|
// update battery
|
||||||
|
#ifdef ENABLE_BATTERY
|
||||||
if (panel1[0].battery.area.on_screen) {
|
if (panel1[0].battery.area.on_screen) {
|
||||||
update_battery(&battery_state);
|
update_battery();
|
||||||
for (i=0 ; i < nb_panel ; i++)
|
for (i=0 ; i < nb_panel ; i++)
|
||||||
panel1[i].battery.area.resize = 1;
|
panel1[i].battery.area.resize = 1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// update clock
|
// update clock
|
||||||
if (time1_format) {
|
if (time1_format) {
|
||||||
|
@ -626,6 +631,7 @@ load_config:
|
||||||
goto load_config;
|
goto load_config;
|
||||||
case SIGINT:
|
case SIGINT:
|
||||||
case SIGTERM:
|
case SIGTERM:
|
||||||
|
case SIGHUP:
|
||||||
cleanup ();
|
cleanup ();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue