From: Thierry Lorthiois Date: Fri, 30 Oct 2009 17:18:44 +0000 (+0000) Subject: fixed config reload SIGUSR1. added systray = 1 parameter to enable systray X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=83f23be9b6b5c2f1ae39d7d045353036b07f872d;p=chaz%2Ftint2 fixed config reload SIGUSR1. added systray = 1 parameter to enable systray --- diff --git a/src/battery/battery.c b/src/battery/battery.c index 4c82893..c88c3a5 100644 --- a/src/battery/battery.c +++ b/src/battery/battery.c @@ -32,8 +32,8 @@ #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; @@ -41,8 +41,11 @@ static char buf_bat_percentage[10]; 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() @@ -55,7 +58,6 @@ 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); @@ -75,7 +77,7 @@ void init_battery() 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; } @@ -107,13 +109,8 @@ void init_battery() 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); @@ -126,6 +123,29 @@ void init_battery() } +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; diff --git a/src/battery/battery.h b/src/battery/battery.h index fe3bb3a..9036f2e 100644 --- a/src/battery/battery.h +++ b/src/battery/battery.h @@ -62,6 +62,7 @@ void update_battery(); void init_battery(); void init_battery_panel(void *panel); +void cleanup_battery(); void draw_battery(void *obj, cairo_t *c, int active); diff --git a/src/clock/clock.c b/src/clock/clock.c index 2745a80..c1504be 100644 --- a/src/clock/clock.c +++ b/src/clock/clock.c @@ -32,16 +32,17 @@ #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() @@ -78,6 +79,7 @@ void init_clock_panel(void *p) 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)); @@ -110,6 +112,27 @@ void init_clock_panel(void *p) } +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; diff --git a/src/clock/clock.h b/src/clock/clock.h index b91c796..48538b3 100644 --- a/src/clock/clock.h +++ b/src/clock/clock.h @@ -32,12 +32,14 @@ extern PangoFontDescription *time1_font_desc; 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); diff --git a/src/config.c b/src/config.c index 02d0265..fae676e 100644 --- a/src/config.c +++ b/src/config.c @@ -77,6 +77,13 @@ void init_config() // 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; @@ -199,6 +206,11 @@ void add_entry (char *key, char *value) 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); @@ -289,9 +301,8 @@ void add_entry (char *key, char *value) } 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) { @@ -335,20 +346,14 @@ void add_entry (char *key, char *value) /* 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); @@ -379,14 +384,12 @@ void add_entry (char *key, char *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 */ @@ -482,12 +485,15 @@ void add_entry (char *key, char *value) } /* 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); @@ -638,29 +644,6 @@ void add_entry (char *key, char *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; diff --git a/src/config.h b/src/config.h index 42aafcf..2629e58 100644 --- a/src/config.h +++ b/src/config.h @@ -16,7 +16,6 @@ void init_config(); void cleanup_config(); int config_read_file (const char *path); int config_read (); -void config_finish (); void save_config (); #endif diff --git a/src/panel.c b/src/panel.c index 9ac62f2..0a09968 100644 --- a/src/panel.c +++ b/src/panel.c @@ -71,6 +71,13 @@ void init_panel() 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); @@ -123,7 +130,7 @@ void init_panel() 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); } diff --git a/src/systray/systraybar.c b/src/systray/systraybar.c index 16dd079..661b2c6 100644 --- a/src/systray/systraybar.c +++ b/src/systray/systraybar.c @@ -43,20 +43,21 @@ Window net_sel_win = None, hint_win = None; // 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; } @@ -80,17 +81,9 @@ void init_systray_panel(void *p) 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(); } @@ -177,8 +170,18 @@ void resize_systray(void *obj) // *********************************************** // 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 @@ -201,7 +204,7 @@ int init_net() fprintf(stderr, " pid=%d", pid); } fprintf(stderr, "\n"); - return 0; + return; } // init systray protocol @@ -214,10 +217,12 @@ int init_net() 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; @@ -229,12 +234,21 @@ int init_net() 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; diff --git a/src/systray/systraybar.h b/src/systray/systraybar.h index 778b892..9e3b990 100644 --- a/src/systray/systraybar.h +++ b/src/systray/systraybar.h @@ -38,10 +38,11 @@ typedef struct } 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); @@ -52,8 +53,8 @@ void resize_systray(void *obj); // 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); diff --git a/src/tint.c b/src/tint.c index edaa3cd..903a4cf 100644 --- a/src/tint.c +++ b/src/tint.c @@ -125,35 +125,18 @@ void init (int argc, char *argv[]) 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); @@ -730,7 +713,8 @@ int main (int argc, char *argv[]) cleanup(); exit(1); } - config_finish(); + init_panel(); + cleanup_config(); if (thumbnail_path) { // usage: tint2 -j for internal use printf("file %s\n", thumbnail_path); diff --git a/src/tooltip/tooltip.c b/src/tooltip/tooltip.c index 85ab223..157b65c 100644 --- a/src/tooltip/tooltip.c +++ b/src/tooltip/tooltip.c @@ -59,6 +59,25 @@ void init_tooltip() } +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) diff --git a/src/tooltip/tooltip.h b/src/tooltip/tooltip.h index 5089ea1..cddb73c 100644 --- a/src/tooltip/tooltip.h +++ b/src/tooltip/tooltip.h @@ -47,6 +47,7 @@ extern Tooltip g_tooltip; void init_tooltip(); +void cleanup_tooltip(); void tooltip_sighandler(int sig); void tooltip_trigger_show(Task* task, int x, int y); void tooltip_show();