#include "battery.h"
#include "clock.h"
-PangoFontDescription *bat1_font_desc;
-PangoFontDescription *bat2_font_desc;
+PangoFontDescription *bat1_font_desc=0;
+PangoFontDescription *bat2_font_desc=0;
struct batstate battery_state;
int battery_enabled;
static char buf_bat_time[20];
int8_t battery_low_status;
-char *battery_low_cmd;
-char *path_energy_now, *path_energy_full, *path_current_now, *path_status;
+char *battery_low_cmd=0;
+char *path_energy_now=0;
+char *path_energy_full=0;
+char *path_current_now=0;
+char *path_status=0;
void init_battery()
if (!battery_enabled) return;
- path_energy_now = path_energy_full = path_current_now = path_status = 0;
directory = g_dir_open("/sys/class/power_supply", 0, &error);
if (error)
g_error_free(error);
if (directory)
g_dir_close(directory);
if (!battery_dir) {
- battery_enabled = 0;
+ cleanup_battery();
fprintf(stderr, "ERROR: battery applet can't found power_supply\n");
return;
}
fp3 = fopen(path_current_now, "r");
fp4 = fopen(path_status, "r");
if (fp1 == NULL || fp2 == NULL || fp3 == NULL || fp4 == NULL) {
- battery_enabled = 0;
+ cleanup_battery();
fprintf(stderr, "ERROR: battery applet can't open energy_now\n");
- g_free(path_energy_now);
- g_free(path_energy_full);
- g_free(path_current_now);
- g_free(path_status);
- path_energy_now = path_energy_full = path_current_now = path_status = 0;
}
fclose(fp1);
fclose(fp2);
}
+void cleanup_battery()
+{
+ battery_enabled = 0;
+ if (bat1_font_desc)
+ pango_font_description_free(bat1_font_desc);
+ if (bat2_font_desc)
+ pango_font_description_free(bat2_font_desc);
+ if (path_energy_now)
+ g_free(path_energy_now);
+ 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);
+ if (battery_low_cmd)
+ g_free(battery_low_cmd);
+
+ battery_low_cmd = path_energy_now = path_energy_full = path_current_now = path_status = 0;
+ bat1_font_desc = bat2_font_desc = 0;
+}
+
+
void init_battery_panel(void *p)
{
Panel *panel = (Panel*)p;
void init_battery();
void init_battery_panel(void *panel);
+void cleanup_battery();
void draw_battery(void *obj, cairo_t *c, int active);
#include "clock.h"
-char *time1_format;
-char *time2_format;
-char *clock_lclick_command;
-char *clock_rclick_command;
+char *time1_format=0;
+char *time2_format=0;
+char *clock_lclick_command=0;
+char *clock_rclick_command=0;
struct timeval time_clock;
int time_precision;
-PangoFontDescription *time1_font_desc;
-PangoFontDescription *time2_font_desc;
+PangoFontDescription *time1_font_desc=0;
+PangoFontDescription *time2_font_desc=0;
static char buf_time[40];
static char buf_date[40];
+int clock_enabled;
void init_precision()
clock->area._resize = resize_clock;
clock->area.resize = 1;
clock->area.redraw = 1;
+ clock->area.on_screen = 1;
strftime(buf_time, sizeof(buf_time), time1_format, localtime(&time_clock.tv_sec));
get_text_size(time1_font_desc, &time_height_ink, &time_height, panel->area.height, buf_time, strlen(buf_time));
}
+void cleanup_clock()
+{
+ clock_enabled = 0;
+ if (time1_font_desc)
+ pango_font_description_free(time1_font_desc);
+ 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 (clock_lclick_command)
+ g_free(clock_lclick_command);
+ if (clock_rclick_command)
+ g_free(clock_rclick_command);
+ time1_font_desc = time2_font_desc = 0;
+ time1_format = time2_format = 0;
+ clock_lclick_command = clock_rclick_command = 0;
+}
+
+
void draw_clock (void *obj, cairo_t *c, int active)
{
Clock *clock = obj;
extern PangoFontDescription *time2_font_desc;
extern char *clock_lclick_command;
extern char *clock_rclick_command;
+extern int clock_enabled;
// initialize clock : y position, precision, ...
void init_clock();
void init_clock_panel(void *panel);
void init_precision();
+void cleanup_clock();
void draw_clock (void *obj, cairo_t *c, int active);
// append full transparency background
list_back = g_slist_append(0, calloc(1, sizeof(Area)));
+ // tint2 could reload config, so we cleanup objects
+ cleanup_systray();
+ cleanup_battery();
+ cleanup_clock();
+ cleanup_tooltip();
+
+ // panel's default value
memset(&panel_config, 0, sizeof(Panel));
panel_config.g_task.alpha = 100;
panel_config.g_task.alpha_active = 100;
panel_config.monitor = atoi (value);
if (panel_config.monitor > 0) panel_config.monitor -= 1;
}
+ if (panel_config.monitor > (server.nb_monitor-1)) {
+ // server.nb_monitor minimum value is 1 (see get_monitors())
+ fprintf(stderr, "warning : monitor not found. tint2 default to all monitors.\n");
+ panel_config.monitor = 0;
+ }
}
else if (strcmp (key, "panel_size") == 0) {
extract_values(value, &value1, &value2, &value3);
}
else if (strcmp (key, "battery_low_cmd") == 0) {
#ifdef ENABLE_BATTERY
- if (battery_low_cmd) g_free(battery_low_cmd);
- if (strlen(value) > 0) battery_low_cmd = strdup (value);
- else battery_low_cmd = 0;
+ if (strlen(value) > 0)
+ battery_low_cmd = strdup (value);
#endif
}
else if (strcmp (key, "bat1_font") == 0) {
/* Clock */
else if (strcmp (key, "time1_format") == 0) {
- if (time1_format) g_free(time1_format);
if (strlen(value) > 0) {
time1_format = strdup (value);
- panel_config.clock.area.on_screen = 1;
- }
- else {
- time1_format = 0;
- panel_config.clock.area.on_screen = 0;
+ clock_enabled = 1;
}
}
else if (strcmp (key, "time2_format") == 0) {
- if (time2_format) g_free(time2_format);
- if (strlen(value) > 0) time2_format = strdup (value);
- else time2_format = 0;
+ if (strlen(value) > 0)
+ time2_format = strdup (value);
}
else if (strcmp (key, "time1_font") == 0) {
if (save_file_config) old_time1_font = strdup (value);
memcpy(&panel_config.clock.area.pix.border, &a->pix.border, sizeof(Border));
}
else if (strcmp(key, "clock_lclick_command") == 0) {
- if (clock_lclick_command) g_free(clock_lclick_command);
- if (strlen(value) > 0) clock_lclick_command = strdup(value);
- else clock_lclick_command = 0;
+ if (strlen(value) > 0)
+ clock_lclick_command = strdup(value);
}
else if (strcmp(key, "clock_rclick_command") == 0) {
- if (clock_rclick_command) g_free(clock_rclick_command);
- if (strlen(value) > 0) clock_rclick_command = strdup(value);
- else clock_rclick_command = 0;
+ if (strlen(value) > 0)
+ clock_rclick_command = strdup(value);
}
/* Taskbar */
}
/* Systray */
+ else if (strcmp (key, "systray") == 0) {
+ if(atoi(value) == 1)
+ systray_enabled = 1;
+ }
else if (strcmp (key, "systray_padding") == 0) {
extract_values(value, &value1, &value2, &value3);
systray.area.paddingxlr = systray.area.paddingx = atoi (value1);
if (value2) systray.area.paddingy = atoi (value2);
if (value3) systray.area.paddingx = atoi (value3);
- systray.area.on_screen = 1;
}
else if (strcmp (key, "systray_background_id") == 0) {
int id = atoi (value);
}
-void config_finish ()
-{
- if (panel_config.monitor > (server.nb_monitor-1)) {
- // server.nb_monitor minimum value is 1 (see get_monitors())
- // and panel_config->monitor is higher
- fprintf(stderr, "warning : monitor not found. tint2 default to all monitors.\n");
- panel_config.monitor = 0;
- }
-
- // TODO: user can configure layout => ordered objects in panel.area.list
- // clock and systray before taskbar because resize(clock) can resize others object ??
- init_tooltip();
- init_clock();
-#ifdef ENABLE_BATTERY
- init_battery();
-#endif
- init_systray();
- init_panel();
-
- cleanup_config();
-}
-
-
int config_read ()
{
const gchar * const * system_dirs;
void cleanup_config();
int config_read_file (const char *path);
int config_read ();
-void config_finish ();
void save_config ();
#endif
int i, old_nb_panel;
Panel *new_panel, *p;
+ init_tooltip();
+ init_systray();
+ init_clock();
+#ifdef ENABLE_BATTERY
+ init_battery();
+#endif
+
cleanup_taskbar();
for (i=0 ; i < nb_panel ; i++) {
free_area(&panel1[i].area);
init_panel_size_and_position(p);
// add childs
- if (p->clock.area.on_screen) {
+ if (clock_enabled) {
init_clock_panel(p);
p->area.list = g_slist_append(p->area.list, &p->clock);
}
// freedesktop specification doesn't allow multi systray
Systraybar systray;
int refresh_systray;
+int systray_enabled;
void init_systray()
{
- if (systray.area.on_screen)
- systray.area.on_screen = init_net();
+ start_net();
- if (!systray.area.on_screen)
+ if (!systray_enabled)
return;
systray.area._draw_foreground = draw_systray;
systray.area._resize = resize_systray;
systray.area.resize = 1;
systray.area.redraw = 1;
+ systray.area.on_screen = 1;
refresh_systray = 0;
}
void cleanup_systray()
{
- if (systray.list_icons) {
- // remove_icon change systray.list_icons
- while(systray.list_icons)
- remove_icon((TrayWindow*)systray.list_icons->data);
-
- g_slist_free(systray.list_icons);
- systray.list_icons = 0;
- }
-
+ systray_enabled = 0;
+ systray.area.on_screen = 0;
free_area(&systray.area);
- cleanup_net();
}
// ***********************************************
// systray protocol
-int init_net()
+void start_net()
{
+ if (net_sel_win) {
+ // protocol already started
+ if (!systray_enabled)
+ stop_net();
+ return;
+ }
+ else
+ if (!systray_enabled)
+ return;
+
Window win = XGetSelectionOwner(server.dsp, server.atom._NET_SYSTEM_TRAY_SCREEN);
// freedesktop systray specification
fprintf(stderr, " pid=%d", pid);
}
fprintf(stderr, "\n");
- return 0;
+ return;
}
// init systray protocol
XSetSelectionOwner(server.dsp, server.atom._NET_SYSTEM_TRAY_SCREEN, net_sel_win, CurrentTime);
if (XGetSelectionOwner(server.dsp, server.atom._NET_SYSTEM_TRAY_SCREEN) != net_sel_win) {
+ stop_net();
fprintf(stderr, "tint2 : can't get systray manager\n");
- return 0;
+ return;
}
+ //fprintf(stderr, "tint2 : systray started\n");
XClientMessageEvent ev;
ev.type = ClientMessage;
ev.window = server.root_win;
ev.data.l[3] = 0;
ev.data.l[4] = 0;
XSendEvent(server.dsp, server.root_win, False, StructureNotifyMask, (XEvent*)&ev);
- return 1;
}
-void cleanup_net()
+void stop_net()
{
+ //fprintf(stderr, "tint2 : systray stopped\n");
+ if (systray.list_icons) {
+ // remove_icon change systray.list_icons
+ while(systray.list_icons)
+ remove_icon((TrayWindow*)systray.list_icons->data);
+
+ g_slist_free(systray.list_icons);
+ systray.list_icons = 0;
+ }
+
if (net_sel_win != None) {
XDestroyWindow(server.dsp, net_sel_win);
net_sel_win = None;
} TrayWindow;
+// net_sel_win != None when protocol started
extern Window net_sel_win;
extern Systraybar systray;
extern int refresh_systray;
-
+extern int systray_enabled;
void init_systray();
void init_systray_panel(void *p);
// systray protocol
// many tray icon doesn't manage stop/restart of the systray manager
-int init_net();
-void cleanup_net();
+void start_net();
+void stop_net();
void net_message(XClientMessageEvent *e);
gboolean add_icon(Window id);
void cleanup()
{
cleanup_systray();
+ stop_net();
cleanup_panel();
+ cleanup_tooltip();
+ cleanup_clock();
+#ifdef ENABLE_BATTERY
+ cleanup_battery();
+#endif
if (default_icon) {
imlib_context_set_image(default_icon);
imlib_free_image();
}
- if (g_tooltip.window) {
- XDestroyWindow(server.dsp, g_tooltip.window);
- g_tooltip.window = 0;
- }
- if (g_tooltip.font_desc) {
- pango_font_description_free(g_tooltip.font_desc);
- g_tooltip.font_desc = 0;
- }
- if (time1_font_desc) pango_font_description_free(time1_font_desc);
- 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_now) g_free(path_energy_now);
- 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);
if (config_path) g_free(config_path);
if (thumbnail_path) g_free(thumbnail_path);
cleanup();
exit(1);
}
- config_finish();
+ init_panel();
+ cleanup_config();
if (thumbnail_path) {
// usage: tint2 -j <file> for internal use
printf("file %s\n", thumbnail_path);
}
+void cleanup_tooltip()
+{
+ tooltip_hide();
+ g_tooltip.enabled = False;
+ if (g_tooltip.task) {
+ alarm(0);
+ g_tooltip.task = 0;
+ }
+ if (g_tooltip.window) {
+ XDestroyWindow(server.dsp, g_tooltip.window);
+ g_tooltip.window = 0;
+ }
+ if (g_tooltip.font_desc) {
+ pango_font_description_free(g_tooltip.font_desc);
+ g_tooltip.font_desc = 0;
+ }
+}
+
+
void tooltip_sighandler(int sig)
{
if (g_tooltip.current_state == TOOLTIP_ABOUT_TO_SHOW)
void init_tooltip();
+void cleanup_tooltip();
void tooltip_sighandler(int sig);
void tooltip_trigger_show(Task* task, int x, int y);
void tooltip_show();