From: Thierry Lorthiois Date: Sun, 18 Apr 2010 14:28:45 +0000 (+0000) Subject: SIGUSR1 does now a full restat of tint2 X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=e050df33d29de6f7890b7111f6ea871aa5247743;p=chaz%2Ftint2 SIGUSR1 does now a full restat of tint2 --- diff --git a/src/battery/battery.c b/src/battery/battery.c index 82aabab..ff8e0a6 100644 --- a/src/battery/battery.c +++ b/src/battery/battery.c @@ -94,6 +94,7 @@ void default_battery() void cleanup_battery() { + printf("*** cleanup_battery()\n"); 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); @@ -133,7 +134,6 @@ void init_battery() if (directory) g_dir_close(directory); if (!battery_dir) { - cleanup_battery(); fprintf(stderr, "ERROR: battery applet can't found power_supply\n"); return; } @@ -166,6 +166,7 @@ void init_battery() fp4 = fopen(path_status, "r"); if (fp1 == NULL || fp2 == NULL || fp3 == NULL || fp4 == NULL) { cleanup_battery(); + default_battery(); fprintf(stderr, "ERROR: battery applet can't open energy_now\n"); } fclose(fp1); diff --git a/src/battery/battery.h b/src/battery/battery.h index 65a8a1e..fa46aee 100644 --- a/src/battery/battery.h +++ b/src/battery/battery.h @@ -57,8 +57,9 @@ extern int8_t battery_low_status; extern char *battery_low_cmd; extern char *path_energy_now, *path_energy_full, *path_current_now, *path_status; -// default values +// default global data void default_battery(); + // freed memory void cleanup_battery(); diff --git a/src/clock/clock.c b/src/clock/clock.c index 273fb81..c7ac910 100644 --- a/src/clock/clock.c +++ b/src/clock/clock.c @@ -71,6 +71,7 @@ void default_clock() void cleanup_clock() { +printf("*** cleanup_clock()\n"); 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); diff --git a/src/clock/clock.h b/src/clock/clock.h index 4db15c3..fa8c796 100644 --- a/src/clock/clock.h +++ b/src/clock/clock.h @@ -37,8 +37,9 @@ extern char *clock_rclick_command; extern int clock_enabled; -// default values +// default global data void default_clock(); + // freed memory void cleanup_clock(); diff --git a/src/config.c b/src/config.c index cc8cb55..4ea8d84 100644 --- a/src/config.c +++ b/src/config.c @@ -57,9 +57,7 @@ char *snapshot_path; // -------------------------------------------------- // backward compatibility -static int old_task_icon_size; -// detect if it's an old config file -// ==1 +// detect if it's an old config file (==1) static int old_config_file; @@ -77,43 +75,6 @@ void cleanup_config() } -void init_config() -{ - if (backgrounds) - g_array_free(backgrounds, 1); - backgrounds = g_array_new(0, 0, sizeof(Background)); - - // append full transparency background - 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(); -#ifdef ENABLE_BATTERY - cleanup_battery(); -#endif - cleanup_clock(); - cleanup_tooltip(); - - // panel's default value - if (panel_config.g_task.font_desc) { - pango_font_description_free(panel_config.g_task.font_desc); - } - memset(&panel_config, 0, sizeof(Panel)); - - // window manager's menu default value == false - wm_menu = 0; - max_tick_urgent = 7; - - // flush pango cache if possible - //pango_xft_shutdown_display(server.dsp, server.screen); - //PangoFontMap *font_map = pango_xft_get_font_map(server.dsp, server.screen); - //pango_fc_font_map_shutdown(font_map); -} - - void extract_values (const char *value, char **value1, char **value2, char **value3) { char *b=0, *c=0; @@ -705,9 +666,6 @@ int config_read_file (const char *path) } fclose (fp); - if (old_task_icon_size) { - panel_config.g_task.area.paddingy = ((int)panel_config.area.height - (2 * panel_config.area.paddingy) - old_task_icon_size) / 2; - } return 1; } diff --git a/src/config.h b/src/config.h index 68bf8a0..0999fb6 100644 --- a/src/config.h +++ b/src/config.h @@ -12,12 +12,12 @@ extern char *config_path; extern char *snapshot_path; -// default values +// default global data void default_config(); + // freed memory void cleanup_config(); -void init_config(); int config_read_file (const char *path); int config_read (); diff --git a/src/panel.c b/src/panel.c index 66fc90e..db66fc3 100644 --- a/src/panel.c +++ b/src/panel.c @@ -46,18 +46,18 @@ int mouse_tilt_right; int panel_mode; int wm_menu; -int panel_dock=0; // default not in the dock -int panel_layer=BOTTOM_LAYER; // default is bottom layer +int panel_dock; +int panel_layer; int panel_position; int panel_horizontal; int panel_refresh; -int task_dragged=0; +int task_dragged; -int panel_autohide = 0; -int panel_autohide_show_timeout = 0; -int panel_autohide_hide_timeout = 0; -int panel_autohide_height = 5; // for vertical panels this is of course the width -int panel_strut_policy = STRUT_MINIMUM; +int panel_autohide; +int panel_autohide_show_timeout; +int panel_autohide_hide_timeout; +int panel_autohide_height; +int panel_strut_policy; Task *task_active; Task *task_drag; @@ -66,18 +66,67 @@ int max_tick_urgent; // panel's initial config Panel panel_config; // panels (one panel per monitor) -Panel *panel1 = 0; -int nb_panel = 0; +Panel *panel1; +int nb_panel; -GArray* backgrounds = 0; +GArray* backgrounds; -Imlib_Image default_icon = NULL; +Imlib_Image default_icon; void autohide_hide(void* p); void autohide_show(void* p); +void default_panel() +{ + panel1 = 0; + nb_panel = 0; + default_icon = NULL; + task_active = 0; + task_drag = 0; + task_dragged = 0; + panel_autohide = 0; + panel_autohide_show_timeout = 0; + panel_autohide_hide_timeout = 0; + panel_autohide_height; // for vertical panels this is of course the width + panel_strut_policy = STRUT_MINIMUM; + panel_dock = 0; // default not in the dock + panel_layer = BOTTOM_LAYER; // default is bottom layer + wm_menu = 0; + max_tick_urgent = 7; + memset(&panel_config, 0, sizeof(Panel)); + backgrounds = g_array_new(0, 0, sizeof(Background)); + + // append full transparency background + Background transparent_bg; + memset(&transparent_bg, 0, sizeof(Background)); + g_array_append_val(backgrounds, transparent_bg); +} + +void cleanup_panel() +{ + if (!panel1) return; + +printf("*** cleanup_panel()\n"); + cleanup_taskbar(); + + int i; + Panel *p; + for (i=0 ; i < nb_panel ; i++) { + p = &panel1[i]; + + free_area(&p->area); + if (p->temp_pmap) XFreePixmap(server.dsp, p->temp_pmap); + if (p->hidden_pixmap) XFreePixmap(server.dsp, p->hidden_pixmap); + if (p->main_win) XDestroyWindow(server.dsp, p->main_win); + } + + if (panel1) free(panel1); + if (backgrounds) g_array_free(backgrounds, 1); + if (panel_config.g_task.font_desc) pango_font_description_free(panel_config.g_task.font_desc); +} + void init_panel() { int i, old_nb_panel; @@ -284,54 +333,6 @@ void init_panel_size_and_position(Panel *panel) } -void cleanup_panel() -{ - if (!panel1) return; - -printf("*** cleanup_panel()\n"); - task_active = 0; - task_drag = 0; - - cleanup_taskbar(); - - int i; - Panel *p; - for (i=0 ; i < nb_panel ; i++) { - p = &panel1[i]; - - free_area(&p->area); - - if (p->temp_pmap) { - XFreePixmap(server.dsp, p->temp_pmap); - p->temp_pmap = 0; - } - if (p->hidden_pixmap) - XFreePixmap(server.dsp, p->hidden_pixmap); - p->hidden_pixmap = 0; - if (p->main_win) { - XDestroyWindow(server.dsp, p->main_win); - p->main_win = 0; - } - } - - if (panel1) { - free(panel1); - panel1 = 0; - nb_panel = 0; - } - - if (panel_config.g_task.font_desc) { - pango_font_description_free(panel_config.g_task.font_desc); - panel_config.g_task.font_desc = 0; - } - - if (backgrounds) { - g_array_free(backgrounds, 1); - backgrounds = 0; - } -} - - void resize_panel(void *obj) { Panel *panel = (Panel*)obj; diff --git a/src/panel.h b/src/panel.h index 9e38fe0..257563a 100644 --- a/src/panel.h +++ b/src/panel.h @@ -121,12 +121,18 @@ extern Panel panel_config; extern Panel *panel1; extern int nb_panel; + +// default global data +void default_panel(); + +// freed memory +void cleanup_panel(); + // realloc panels according to number of monitor // use panel_config as default value void init_panel(); void init_panel_size_and_position(Panel *panel); -void cleanup_panel(); void resize_panel(void *obj); void set_panel_properties(Panel *p); diff --git a/src/systray/systraybar.c b/src/systray/systraybar.c index 81eba8f..cc14122 100644 --- a/src/systray/systraybar.c +++ b/src/systray/systraybar.c @@ -67,6 +67,7 @@ printf("*** default_systray()\n"); void cleanup_systray() { +printf("*** cleanup_systray()\n"); systray_enabled = 0; systray_max_icon_size = 0; systray.area.on_screen = 0; diff --git a/src/systray/systraybar.h b/src/systray/systraybar.h index 631e598..7b5e9fc 100644 --- a/src/systray/systraybar.h +++ b/src/systray/systraybar.h @@ -52,8 +52,9 @@ extern int refresh_systray; extern int systray_enabled; extern int systray_max_icon_size; -// default values +// default global data void default_systray(); + // freed memory void cleanup_systray(); diff --git a/src/taskbar/taskbar.c b/src/taskbar/taskbar.c index 34f49b0..10e0d13 100644 --- a/src/taskbar/taskbar.c +++ b/src/taskbar/taskbar.c @@ -184,6 +184,7 @@ void cleanup_taskbar() Taskbar *tskbar; int i, j; +printf("*** cleanup_taskbar()\n"); if (win_to_task_table) g_hash_table_foreach(win_to_task_table, taskbar_remove_task, 0); for (i=0 ; i < nb_panel ; i++) { panel = &panel1[i]; diff --git a/src/taskbar/taskbar.h b/src/taskbar/taskbar.h index a04060c..e2c55bb 100644 --- a/src/taskbar/taskbar.h +++ b/src/taskbar/taskbar.h @@ -34,8 +34,9 @@ typedef struct { } Global_taskbar; -// default values +// default global data void default_taskbar(); + // freed memory void cleanup_taskbar(); diff --git a/src/tint.c b/src/tint.c index 35141b0..f88b57f 100644 --- a/src/tint.c +++ b/src/tint.c @@ -55,6 +55,7 @@ void init (int argc, char *argv[]) int i; // set global data + default_config(); default_timeout(); default_systray(); memset(&server, 0, sizeof(Server_global)); @@ -62,7 +63,7 @@ void init (int argc, char *argv[]) default_clock(); default_taskbar(); default_tooltip(); - default_config(); + default_panel(); // read options for (i = 1; i < argc; ++i) { @@ -86,6 +87,7 @@ void init (int argc, char *argv[]) } } // Set signal handler + signal_pending = 0; struct sigaction sa = { .sa_handler = signal_handler }; sigaction(SIGUSR1, &sa, 0); sigaction(SIGINT, &sa, 0); @@ -147,7 +149,6 @@ void init_X11() void cleanup() { -printf("*** cleanup()\n"); cleanup_timeout(); cleanup_systray(); stop_net(); @@ -163,6 +164,7 @@ printf("*** cleanup()\n"); imlib_context_set_image(default_icon); imlib_free_image(); } + imlib_context_disconnect_display(); cleanup_server(); if (server.dsp) XCloseDisplay(server.dsp); @@ -191,7 +193,6 @@ void get_snapshot(const char *path) } imlib_save_image(path); imlib_free_image(); - XFreePixmap(server.dsp, panel->temp_pmap); } @@ -624,11 +625,7 @@ void event_configure_notify (Window win) { // change in root window (xrandr) if (win == server.root_win) { - get_monitors(); - init_config(); - config_read_file (config_path); - init_panel(); - cleanup_config(); + signal_pending = SIGUSR1; return; } @@ -704,8 +701,8 @@ int main (int argc, char *argv[]) GSList *it; struct timeval* timeout; +start: init (argc, argv); - init_config(); init_X11(); i = 0; @@ -720,7 +717,6 @@ int main (int argc, char *argv[]) } init_panel(); - cleanup_config(); if (snapshot_path) { get_snapshot(snapshot_path); cleanup(); @@ -899,19 +895,18 @@ int main (int argc, char *argv[]) callback_timeout_expired(); - switch (signal_pending) { - case SIGUSR1: // reload config file - signal_pending = 0; - init_config(); - config_read_file (config_path); - init_panel(); - cleanup_config(); - break; - case SIGINT: - case SIGTERM: - case SIGHUP: - cleanup (); - return 0; + if (signal_pending) { + cleanup(); + if (signal_pending == SIGUSR1) { + // restart tint2 + // SIGUSR1 used when : user's signal, composite manager stop/start or xrandr + FD_CLR (x11_fd, &fdset); + goto start; + } + else { + // SIGINT, SIGTERM, SIGHUP + return 0; + } } } } diff --git a/src/tooltip/tooltip.c b/src/tooltip/tooltip.c index a724473..1c19504 100644 --- a/src/tooltip/tooltip.c +++ b/src/tooltip/tooltip.c @@ -50,6 +50,7 @@ void default_tooltip() void cleanup_tooltip() { +printf("*** cleanup_tooltip()\n"); stop_tooltip_timeout(); tooltip_hide(0); tooltip_copy_text(0); diff --git a/src/tooltip/tooltip.h b/src/tooltip/tooltip.h index e4e54d3..fbf71b5 100644 --- a/src/tooltip/tooltip.h +++ b/src/tooltip/tooltip.h @@ -43,8 +43,9 @@ typedef struct { extern Tooltip g_tooltip; -// default values +// default global data void default_tooltip(); + // freed memory void cleanup_tooltip(); diff --git a/src/util/timer.c b/src/util/timer.c index b4db7f4..1dd2f11 100644 --- a/src/util/timer.c +++ b/src/util/timer.c @@ -55,6 +55,7 @@ void default_timeout() void cleanup_timeout() { +printf("*** cleanup_timeout()\n"); while (timeout_list) { timeout* t = timeout_list->data; if (t->multi_timeout) diff --git a/src/util/timer.h b/src/util/timer.h index 251b732..250e7e0 100644 --- a/src/util/timer.h +++ b/src/util/timer.h @@ -36,8 +36,9 @@ typedef struct _timeout timeout; * integral multiple of the other. **/ -/** default values **/ +/** default global data **/ void default_timeout(); + /** freed memory : stops all timeouts **/ void cleanup_timeout();