]> Dogcows Code - chaz/tint2/commitdiff
fixed config reload SIGUSR1. added systray = 1 parameter to enable systray
authorThierry Lorthiois <lorthiois@bbsoft.fr>
Fri, 30 Oct 2009 17:18:44 +0000 (17:18 +0000)
committerThierry Lorthiois <lorthiois@bbsoft.fr>
Fri, 30 Oct 2009 17:18:44 +0000 (17:18 +0000)
12 files changed:
src/battery/battery.c
src/battery/battery.h
src/clock/clock.c
src/clock/clock.h
src/config.c
src/config.h
src/panel.c
src/systray/systraybar.c
src/systray/systraybar.h
src/tint.c
src/tooltip/tooltip.c
src/tooltip/tooltip.h

index 4c82893afc96fc99ebb08d7426c0a4cf4e26958d..c88c3a5b57d8ccdc5b4d42df5cc5062aa4487ede 100644 (file)
@@ -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;
index fe3bb3a8a17fa7679ef1d16533202630e2546e7b..9036f2e11ba26e0c05a812c8ca3ba71ad4a9fcad 100644 (file)
@@ -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);
 
index 2745a80bd920afe183c8bbcd036d92378fc37dfe..c1504bea8202272c553d243918ca2a374230b6f7 100644 (file)
 #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;
index b91c796dcf986159b576ca32570b86ceeb592159..48538b337fc7d61b6f525d27722b2bae2923cce3 100644 (file)
@@ -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);
 
index 02d0265d74fd9117f9c966f5d11b97e2c1a9b9fd..fae676e92e299171e1fc23245a611d6f63e53e52 100644 (file)
@@ -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;
index 42aafcf46f844b504188b341ac370d6ede934d3b..2629e58cfe1701b786c1e6b7833a1d97aa79d034 100644 (file)
@@ -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
index 9ac62f2d8fafb699fb7acac01c2b05eea4032581..0a09968ba96311441c74b9255b32cba5fd7d5059 100644 (file)
@@ -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);
                }
index 16dd079c57ce25060d414623bdd650e636a13900..661b2c6a5ed035bca9d0a3153193113880deff19 100644 (file)
@@ -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;
index 778b89261e883224372fce672b8dee9522bcc0ba..9e3b99012c4a5ac073692e22ef7ac2c78a68d1df 100644 (file)
@@ -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);
index edaa3cd6f3266cc16daedbcecc1238febf43d110..903a4cfc8dc701fa1c31f58fec0b62d9ff5234bb 100644 (file)
@@ -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 <file> for internal use
                printf("file %s\n", thumbnail_path);
index 85ab223f2fa11f70277ef0c1c31151447ce42dd9..157b65cd13376fe8462810798468a5f3a219e025 100644 (file)
@@ -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)
index 5089ea1d94d96a7332a8e3b71ec1502f1ae64755..cddb73c74de4a703476b812432a72308336f8c79 100644 (file)
@@ -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();
This page took 0.039625 seconds and 4 git commands to generate.