From 0caca7524827e38c9d076f33dc66416d189184e8 Mon Sep 17 00:00:00 2001 From: Thierry Lorthiois Date: Fri, 16 Apr 2010 18:50:03 +0000 Subject: [PATCH] cleanup default value on SIGUSR1 --- src/battery/battery.c | 38 +++++++++++++++++++---------- src/battery/battery.h | 2 ++ src/clock/clock.c | 52 +++++++++++++++++++++++++++++----------- src/clock/clock.h | 2 ++ src/config.c | 1 + src/systray/systraybar.c | 8 +++++-- src/systray/systraybar.h | 4 ++++ src/taskbar/taskbar.c | 6 ++++- src/taskbar/taskbar.h | 2 ++ 9 files changed, 86 insertions(+), 29 deletions(-) diff --git a/src/battery/battery.c b/src/battery/battery.c index fd2ffce..9124e16 100644 --- a/src/battery/battery.c +++ b/src/battery/battery.c @@ -37,15 +37,15 @@ PangoFontDescription *bat1_font_desc=0; PangoFontDescription *bat2_font_desc=0; struct batstate battery_state; int battery_enabled; -int percentage_hide = 101; +int percentage_hide; static timeout* battery_timeout=0; static char buf_bat_percentage[10]; static char buf_bat_time[20]; int8_t battery_low_status; +unsigned char battery_low_cmd_send; char *battery_low_cmd=0; -unsigned char battery_low_cmd_send=0; char *path_energy_now=0; char *path_energy_full=0; char *path_current_now=0; @@ -159,23 +159,37 @@ void init_battery() void cleanup_battery() { battery_enabled = 0; - if (bat1_font_desc) + percentage_hide = 101; + battery_low_cmd_send = 0; + + if (bat1_font_desc) { pango_font_description_free(bat1_font_desc); - if (bat2_font_desc) + bat1_font_desc = 0; + } + if (bat2_font_desc) { pango_font_description_free(bat2_font_desc); - if (path_energy_now) + bat2_font_desc = 0; + } + if (path_energy_now) { g_free(path_energy_now); - if (path_energy_full) + path_energy_now = 0; + } + if (path_energy_full) { g_free(path_energy_full); - if (path_current_now) + path_energy_full = 0; + } + if (path_current_now) { g_free(path_current_now); - if (path_status) + path_current_now = 0; + } + if (path_status) { g_free(path_status); - if (battery_low_cmd) + path_status = 0; + } + 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; + battery_low_cmd = 0; + } } diff --git a/src/battery/battery.h b/src/battery/battery.h index 39f9b11..2e99abd 100644 --- a/src/battery/battery.h +++ b/src/battery/battery.h @@ -63,6 +63,8 @@ void update_battery(); void init_battery(); void init_battery_panel(void *panel); + +// freed memory and set default values void cleanup_battery(); void draw_battery(void *obj, cairo_t *c); diff --git a/src/clock/clock.c b/src/clock/clock.c index e29c138..d020c52 100644 --- a/src/clock/clock.c +++ b/src/clock/clock.c @@ -163,22 +163,46 @@ void init_clock_panel(void *p) void cleanup_clock() { clock_enabled = 0; - if (time1_font_desc) + if (time1_font_desc) { pango_font_description_free(time1_font_desc); - if (time2_font_desc) + time1_font_desc = 0; + } + if (time2_font_desc) { pango_font_description_free(time2_font_desc); - g_free(time1_format); - g_free(time2_format); - g_free(time_tooltip_format); - g_free(time1_timezone); - g_free(time2_timezone); - g_free(time_tooltip_timezone); - g_free(clock_lclick_command); - g_free(clock_rclick_command); - time1_font_desc = time2_font_desc = 0; - time1_format = time2_format = time_tooltip_format = 0; - time1_timezone = time2_timezone = time_tooltip_timezone = 0; - clock_lclick_command = clock_rclick_command = 0; + time2_font_desc = 0; + } + if (time1_format) { + g_free(time1_format); + time1_format = 0; + } + if (time2_format) { + g_free(time2_format); + time2_format = 0; + } + if (time_tooltip_format) { + g_free(time_tooltip_format); + time_tooltip_format = 0; + } + if (time1_timezone) { + g_free(time1_timezone); + time1_timezone = 0; + } + if (time2_timezone) { + g_free(time2_timezone); + time2_timezone = 0; + } + if (time_tooltip_timezone) { + g_free(time_tooltip_timezone); + time_tooltip_timezone = 0; + } + if (clock_lclick_command) { + g_free(clock_lclick_command); + clock_lclick_command = 0; + } + if (clock_rclick_command) { + g_free(clock_rclick_command); + clock_rclick_command = 0; + } } diff --git a/src/clock/clock.h b/src/clock/clock.h index 6714f64..e86cbf6 100644 --- a/src/clock/clock.h +++ b/src/clock/clock.h @@ -40,6 +40,8 @@ extern int clock_enabled; // initialize clock : y position, precision, ... void init_clock(); void init_clock_panel(void *panel); + +// freed memory and set default values void cleanup_clock(); void draw_clock (void *obj, cairo_t *c); diff --git a/src/config.c b/src/config.c index 60c14f3..30aa6e1 100644 --- a/src/config.c +++ b/src/config.c @@ -73,6 +73,7 @@ void init_config() Background transparent_bg; memset(&transparent_bg, 0, sizeof(Background)); g_array_append_val(backgrounds, transparent_bg); +printf("*** init_config()\n"); // tint2 could reload config, so we cleanup objects cleanup_systray(); diff --git a/src/systray/systraybar.c b/src/systray/systraybar.c index 411f912..9719554 100644 --- a/src/systray/systraybar.c +++ b/src/systray/systraybar.c @@ -48,7 +48,7 @@ Window net_sel_win = None; Systraybar systray; int refresh_systray; int systray_enabled; -int systray_max_icon_size = 0; +int systray_max_icon_size; // background pixmap if we render ourselves the icons static Pixmap render_background = 0; @@ -95,9 +95,13 @@ void init_systray_panel(void *p) void cleanup_systray() { systray_enabled = 0; + systray_max_icon_size = 0; systray.area.on_screen = 0; free_area(&systray.area); - if (render_background) XFreePixmap(server.dsp, render_background); + if (render_background) { + XFreePixmap(server.dsp, render_background); + render_background = 0; + } } diff --git a/src/systray/systraybar.h b/src/systray/systraybar.h index f95001e..d18d12e 100644 --- a/src/systray/systraybar.h +++ b/src/systray/systraybar.h @@ -53,8 +53,12 @@ extern int systray_enabled; extern int systray_max_icon_size; void init_systray(); + void init_systray_panel(void *p); + +// freed memory and set default values void cleanup_systray(); + void draw_systray(void *obj, cairo_t *c); void resize_systray(void *obj); diff --git a/src/taskbar/taskbar.c b/src/taskbar/taskbar.c index 02c5c8e..38d1f09 100644 --- a/src/taskbar/taskbar.c +++ b/src/taskbar/taskbar.c @@ -166,7 +166,11 @@ void init_taskbar() } } -void taskbar_remove_task(gpointer key, gpointer value, gpointer user_data) {remove_task(task_get_task(*(Window*)key)); } +void taskbar_remove_task(gpointer key, gpointer value, gpointer user_data) +{ + remove_task(task_get_task(*(Window*)key)); +} + void cleanup_taskbar() { Panel *panel; diff --git a/src/taskbar/taskbar.h b/src/taskbar/taskbar.h index 74ee19a..25a8dd1 100644 --- a/src/taskbar/taskbar.h +++ b/src/taskbar/taskbar.h @@ -34,6 +34,8 @@ typedef struct { } Global_taskbar; void init_taskbar(); + +// freed memory and set default values void cleanup_taskbar(); Task *task_get_task (Window win); -- 2.44.0