]> Dogcows Code - chaz/tint2/blobdiff - src/config.c
*fix* once again issue 192
[chaz/tint2] / src / config.c
index 0e7eae43f47a6374a4f356bf8bd8731cfe65b6b2..62a8c585e6aaab32fbb350dec0cbe242be5d8664 100644 (file)
@@ -32,6 +32,7 @@
 #include <ctype.h>
 #include <glib/gstdio.h>
 #include <pango/pangocairo.h>
+#include <pango/pangoxft.h>
 #include <Imlib2.h>
 
 #include "common.h"
@@ -44,6 +45,7 @@
 #include "config.h"
 #include "window.h"
 #include "tooltip.h"
+#include "timer.h"
 
 #ifdef ENABLE_BATTERY
 #include "battery.h"
 
 // global path
 char *config_path = 0;
-char *thumbnail_path = 0;
+char *snapshot_path = 0;
 
 // --------------------------------------------------
 // backward compatibility
 static int old_task_icon_size;
-static char *old_task_font;
-static char *old_time1_font;
-static char *old_time2_font;
-static Area *area_task, *area_task_active;
-
+static Area *area_task;
+static Area *area_task_active;
+// detect if it's an old config file
+// ==1
+static int old_config_file;
 
 // temporary list of background
 static GSList *list_back;
+static int back_count;
 
 
 
@@ -71,22 +74,35 @@ void init_config()
 {
        // append full transparency background
        list_back = g_slist_append(0, calloc(1, sizeof(Area)));
+       back_count = 1;
 
        // 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));
        panel_config.g_task.alpha = 100;
        panel_config.g_task.alpha_active = 100;
+       systray.alpha = 100;
        systray.sort = 3;
+       old_config_file = 1;
 
        // 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);
 }
 
 
@@ -161,6 +177,10 @@ void get_action (char *event, int *action)
                *action = DESKTOP_LEFT;
        else if (strcmp (event, "desktop_right") == 0)
                *action = DESKTOP_RIGHT;
+       else if (strcmp (event, "next_task") == 0)
+               *action = NEXT_TASK;
+       else if (strcmp (event, "prev_task") == 0)
+               *action = PREV_TASK;
 }
 
 
@@ -174,6 +194,7 @@ void add_entry (char *key, char *value)
                Area *a = calloc(1, sizeof(Area));
                a->pix.border.rounded = atoi (value);
                list_back = g_slist_append(list_back, a);
+               back_count++;
        }
        else if (strcmp (key, "border_width") == 0) {
                Area *a = g_slist_last(list_back)->data;
@@ -266,6 +287,7 @@ void add_entry (char *key, char *value)
                panel_config.g_task.font_shadow = atoi (value);
        else if (strcmp (key, "panel_background_id") == 0) {
                int id = atoi (value);
+               id = (id < back_count && id >= 0) ? id : 0;
                Area *a = g_slist_nth_data(list_back, id);
                memcpy(&panel_config.area.pix.back, &a->pix.back, sizeof(Color));
                memcpy(&panel_config.area.pix.border, &a->pix.border, sizeof(Border));
@@ -276,6 +298,16 @@ void add_entry (char *key, char *value)
                panel_dock = atoi (value);
        else if (strcmp (key, "urgent_nb_of_blink") == 0)
                max_tick_urgent = (atoi (value) * 2) + 1;
+       else if (strcmp (key, "real_transparency") == 0)
+               real_transparency = atoi(value);
+       else if (strcmp (key, "panel_layer") == 0) {
+               if (strcmp(value, "bottom") == 0)
+                       panel_layer = BOTTOM_LAYER;
+               else if (strcmp(value, "normal") == 0)
+                       panel_layer = NORMAL_LAYER;
+               else if (strcmp(value, "top") == 0)
+                       panel_layer = TOP_LAYER;
+       }
 
        /* Battery */
        else if (strcmp (key, "battery") == 0) {
@@ -329,6 +361,7 @@ void add_entry (char *key, char *value)
        else if (strcmp (key, "battery_background_id") == 0) {
 #ifdef ENABLE_BATTERY
                int id = atoi (value);
+               id = (id < back_count && id >= 0) ? id : 0;
                Area *a = g_slist_nth_data(list_back, id);
                memcpy(&panel_config.battery.area.pix.back, &a->pix.back, sizeof(Color));
                memcpy(&panel_config.battery.area.pix.border, &a->pix.border, sizeof(Border));
@@ -349,6 +382,14 @@ void add_entry (char *key, char *value)
        else if (strcmp (key, "time1_font") == 0) {
                time1_font_desc = pango_font_description_from_string (value);
        }
+       else if (strcmp(key, "time1_timezone") == 0) {
+               if (strlen(value) > 0)
+                       time1_timezone = strdup(value);
+       }
+       else if (strcmp(key, "time2_timezone") == 0) {
+               if (strlen(value) > 0)
+                       time2_timezone = strdup(value);
+       }
        else if (strcmp (key, "time2_font") == 0) {
                time2_font_desc = pango_font_description_from_string (value);
        }
@@ -366,10 +407,19 @@ void add_entry (char *key, char *value)
        }
        else if (strcmp (key, "clock_background_id") == 0) {
                int id = atoi (value);
+               id = (id < back_count && id >= 0) ? id : 0;
                Area *a = g_slist_nth_data(list_back, id);
                memcpy(&panel_config.clock.area.pix.back, &a->pix.back, sizeof(Color));
                memcpy(&panel_config.clock.area.pix.border, &a->pix.border, sizeof(Border));
        }
+       else if (strcmp(key, "clock_tooltip") == 0) {
+               if (strlen(value) > 0)
+                       time_tooltip_format = strdup (value);
+       }
+       else if (strcmp(key, "clock_tooltip_timezone") == 0) {
+               if (strlen(value) > 0)
+                       time_tooltip_timezone = strdup(value);
+       }
        else if (strcmp(key, "clock_lclick_command") == 0) {
                if (strlen(value) > 0)
                        clock_lclick_command = strdup(value);
@@ -392,12 +442,14 @@ void add_entry (char *key, char *value)
        }
        else if (strcmp (key, "taskbar_background_id") == 0) {
                int id = atoi (value);
+               id = (id < back_count && id >= 0) ? id : 0;
                Area *a = g_slist_nth_data(list_back, id);
                memcpy(&panel_config.g_taskbar.pix.back, &a->pix.back, sizeof(Color));
                memcpy(&panel_config.g_taskbar.pix.border, &a->pix.border, sizeof(Border));
        }
        else if (strcmp (key, "taskbar_active_background_id") == 0) {
                int id = atoi (value);
+               id = (id < back_count && id >= 0) ? id : 0;
                Area *a = g_slist_nth_data(list_back, id);
                memcpy(&panel_config.g_taskbar.pix_active.back, &a->pix.back, sizeof(Color));
                memcpy(&panel_config.g_taskbar.pix_active.border, &a->pix.border, sizeof(Border));
@@ -458,12 +510,14 @@ void add_entry (char *key, char *value)
        }
        else if (strcmp (key, "task_background_id") == 0) {
                int id = atoi (value);
+               id = (id < back_count && id >= 0) ? id : 0;
                Area *a = g_slist_nth_data(list_back, id);
                memcpy(&panel_config.g_task.area.pix.back, &a->pix.back, sizeof(Color));
                memcpy(&panel_config.g_task.area.pix.border, &a->pix.border, sizeof(Border));
        }
        else if (strcmp (key, "task_active_background_id") == 0) {
                int id = atoi (value);
+               id = (id < back_count && id >= 0) ? id : 0;
                Area *a = g_slist_nth_data(list_back, id);
                memcpy(&panel_config.g_task.area.pix_active.back, &a->pix.back, sizeof(Color));
                memcpy(&panel_config.g_task.area.pix_active.border, &a->pix.border, sizeof(Border));
@@ -471,10 +525,13 @@ void add_entry (char *key, char *value)
 
        /* Systray */
        else if (strcmp (key, "systray") == 0) {
-               if(atoi(value) == 1)
-                       systray_enabled = 1;
+               systray_enabled = atoi(value);
+               // systray is latest option added. files without 'systray' are old.
+               old_config_file = 0;
        }
        else if (strcmp (key, "systray_padding") == 0) {
+               if (old_config_file)
+                       systray_enabled = 1;
                extract_values(value, &value1, &value2, &value3);
                systray.area.paddingxlr = systray.area.paddingx = atoi (value1);
                if (value2) systray.area.paddingy = atoi (value2);
@@ -482,6 +539,7 @@ void add_entry (char *key, char *value)
        }
        else if (strcmp (key, "systray_background_id") == 0) {
                int id = atoi (value);
+               id = (id < back_count && id >= 0) ? id : 0;
                Area *a = g_slist_nth_data(list_back, id);
                memcpy(&systray.area.pix.back, &a->pix.back, sizeof(Color));
                memcpy(&systray.area.pix.border, &a->pix.border, sizeof(Border));
@@ -496,21 +554,26 @@ void add_entry (char *key, char *value)
                else  if (strcmp(value, "right2left") == 0)
                        systray.sort = 3;
        }
+       else if (strcmp(key, "systray_icon_size") == 0) {
+               systray_max_icon_size = atoi(value);
+       }
+       else if (strcmp(key, "systray_icon_asb") == 0) {
+               extract_values(value, &value1, &value2, &value3);
+               systray.alpha = atoi(value1);
+               systray.saturation = atoi(value2);
+               systray.brightness = atoi(value3);
+       }
 
        /* Tooltip */
        else if (strcmp (key, "tooltip") == 0)
                g_tooltip.enabled = atoi(value);
        else if (strcmp (key, "tooltip_show_timeout") == 0) {
-               double timeout = atof(value);
-               int sec = (int)timeout;
-               int usec = (timeout-sec)*1e6;
-               g_tooltip.show_timeout.it_value = (struct timeval){.tv_sec=sec, .tv_usec=usec};
+               int timeout_msec = 1000*atof(value);
+               g_tooltip.show_timeout_msec = timeout_msec;
        }
        else if (strcmp (key, "tooltip_hide_timeout") == 0) {
-               double timeout = atof(value);
-               int sec = (int)timeout;
-               int usec = (timeout-sec)*1e6;
-               g_tooltip.hide_timeout.it_value = (struct timeval){.tv_sec=sec, .tv_usec=usec};
+               int timeout_msec = 1000*atof(value);
+               g_tooltip.hide_timeout_msec = timeout_msec;
        }
        else if (strcmp (key, "tooltip_padding") == 0) {
                extract_values(value, &value1, &value2, &value3);
@@ -519,6 +582,7 @@ void add_entry (char *key, char *value)
        }
        else if (strcmp (key, "tooltip_background_id") == 0) {
                int id = atoi (value);
+               id = (id < back_count && id >= 0) ? id : 0;
                Area *a = g_slist_nth_data(list_back, id);
                memcpy(&g_tooltip.background_color, &a->pix.back, sizeof(Color));
                memcpy(&g_tooltip.border, &a->pix.border, sizeof(Border));
@@ -645,7 +709,6 @@ int config_read ()
        g_free(path1);
 
        // copy tint2rc from system directory to user directory
-       g_free(path1);
        char *path2 = 0;
        system_dirs = g_get_system_config_dirs();
        for (i = 0; system_dirs[i]; i++) {
@@ -678,13 +741,10 @@ int config_read ()
 int config_read_file (const char *path)
 {
        FILE *fp;
-       char line[80];
+       char line[512];
        char *key, *value;
 
        if ((fp = fopen(path, "r")) == NULL) return 0;
-       old_task_font = 0;
-       old_time1_font = 0;
-       old_time2_font = 0;
 
        while (fgets(line, sizeof(line), fp) != NULL) {
                if (parse_line(line, &key, &value)) {
@@ -698,18 +758,6 @@ int config_read_file (const char *path)
        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;
        }
-       if (old_task_font) {
-               g_free(old_task_font);
-               old_task_font = 0;
-       }
-       if (old_time1_font) {
-               g_free(old_time1_font);
-               old_time1_font = 0;
-       }
-       if (old_time2_font) {
-               g_free(old_time2_font);
-               old_time2_font = 0;
-       }
        return 1;
 }
 
This page took 0.027422 seconds and 4 git commands to generate.