Don't pass mouse clicks when window is desktop type.
[monky] / src / conky.c
index b459a1f..8668d6d 100644 (file)
@@ -68,6 +68,9 @@
 #ifdef NCURSES
 #include <ncurses.h>
 #endif
+#ifdef XOAP
+#include <libxml/parser.h>
+#endif /* XOAP */
 
 /* local headers */
 #include "algebra.h"
@@ -1786,6 +1789,30 @@ static struct text_object *construct_text_object(const char *s,
                        current_text_color = obj->data.l;
                }
 #endif /* X11 */
+#ifdef NCURSES
+               if (output_methods & TO_NCURSES) {
+                       obj->data.l = COLOR_WHITE;
+                       if(arg) {
+                               if(strcasecmp(arg, "red") == 0) {
+                                       obj->data.l = COLOR_RED;
+                               }else if(strcasecmp(arg, "green") == 0) {
+                                       obj->data.l = COLOR_GREEN;
+                               }else if(strcasecmp(arg, "yellow") == 0) {
+                                       obj->data.l = COLOR_YELLOW;
+                               }else if(strcasecmp(arg, "blue") == 0) {
+                                       obj->data.l = COLOR_BLUE;
+                               }else if(strcasecmp(arg, "magenta") == 0) {
+                                       obj->data.l = COLOR_MAGENTA;
+                               }else if(strcasecmp(arg, "cyan") == 0) {
+                                       obj->data.l = COLOR_CYAN;
+                               }else if(strcasecmp(arg, "black") == 0) {
+                                       obj->data.l = COLOR_BLACK;
+                               }
+                       }
+                       current_text_color = obj->data.l;
+                       init_pair(obj->data.l, obj->data.l, COLOR_BLACK);
+               }
+#endif /* NCURSES */
        END OBJ(color0, 0)
                obj->data.l = color0;
                current_text_color = obj->data.l;
@@ -2121,7 +2148,7 @@ static struct text_object *construct_text_object(const char *s,
                        obj->type = OBJ_text;
                        return NULL;
                }
-               DBGP("parsed platform args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
+               DBGP("parsed platform args: '%s' '%s' %d %f %f", buf1, buf2, n, factor, offset);
                obj->data.sysfs.fd = open_platform_sensor((*buf1) ? buf1 : 0, buf2, n,
                                &obj->data.sysfs.arg, obj->data.sysfs.devtype);
                strncpy(obj->data.sysfs.type, buf2, 63);
@@ -2958,7 +2985,7 @@ static struct text_object *construct_text_object(const char *s,
        END OBJ(rss, 0)
                if (arg) {
                        float interval = 0;
-                       int argc, act_par;
+                       int argc, act_par = 0;
                        unsigned int nrspaces = 0;
                        char *uri = (char *) malloc(128 * sizeof(char));
                        char *action = (char *) malloc(64 * sizeof(char));
@@ -3047,15 +3074,15 @@ static struct text_object *construct_text_object(const char *s,
                                obj->data.weather_forecast.uri = uri;
                                obj->data.weather_forecast.data_type = data_type;
 
-                               /* Limit the day between 0 (today) and 4 */
-                               if (day > 4) {
-                                       day = 4;
+                               /* Limit the day between 0 (today) and FORECAST_DAYS */
+                               if (day >= FORECAST_DAYS) {
+                                       day = FORECAST_DAYS-1;
                                }
                                obj->data.weather_forecast.day = day;
 
-                               /* Limit the data retrieval interval to 2 hours and an half */
-                               if (interval < 150) {
-                                       interval = 150;
+                               /* Limit the data retrieval interval to 3 hours and an half */
+                               if (interval < 210) {
+                                       interval = 210;
                                }
 
                                /* Convert to seconds */
@@ -4155,9 +4182,11 @@ static void generate_text_internal(char *p, int p_max_size,
                                new_graph(p, obj->a, obj->b, obj->c, obj->d, cur->loadavg[0],
                                                obj->e, 1, obj->char_a, obj->char_b);
                        }
+#endif /* X11 */
                        OBJ(color) {
                                new_fg(p, obj->data.l);
                        }
+#ifdef X11
                        OBJ(color0) {
                                new_fg(p, color0);
                        }
@@ -6540,15 +6569,24 @@ static int text_size_updater(char *s, int special_index)
        last_font_height = font_height();
        return special_index;
 }
+#endif /* X11 */
 
 static inline void set_foreground_color(long c)
 {
-       if ((output_methods & TO_X) == 0)
-               return;
-       current_color = c;
-       XSetForeground(display, window.gc, c);
-}
+#ifdef X11
+       if (output_methods & TO_X) {
+               current_color = c;
+               XSetForeground(display, window.gc, c);
+       }
 #endif /* X11 */
+#ifdef NCURSES
+       if (output_methods & TO_NCURSES) {
+               attron(COLOR_PAIR(c));
+       }
+#endif /* NCURSES */
+       UNUSED(c);
+       return;
+}
 
 static void draw_string(const char *s)
 {
@@ -6585,7 +6623,7 @@ static void draw_string(const char *s)
        }
 #ifdef NCURSES
        if ((output_methods & TO_NCURSES) && draw_mode == FG) {
-               printw("%s\n", s_with_newlines);
+               printw("%s", s_with_newlines);
        }
 #endif
        free(s_with_newlines);
@@ -6665,18 +6703,21 @@ static void draw_string(const char *s)
        memcpy(tmpstring1, s, text_buffer_size);
 }
 
-#ifdef X11
 int draw_each_line_inner(char *s, int special_index, int last_special_applied)
 {
+#ifdef X11
        int font_h = font_height();
        int cur_y_add = 0;
+#endif /* X11 */
        char *recurse = 0;
        char *p = s;
        int last_special_needed = -1;
        int orig_special_index = special_index;
 
+#ifdef X11
        cur_x = text_start_x;
        cur_y += font_ascent();
+#endif /* X11 */
 
        while (*p) {
                if (*p == SECRIT_MULTILINE_CHAR) {
@@ -6686,7 +6727,9 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
                        break;
                }
                if (*p == SPECIAL_CHAR || last_special_applied > -1) {
+#ifdef X11
                        int w = 0;
+#endif /* X11 */
 
                        /* draw string before special, unless we're dealing multiline
                         * specials */
@@ -6700,6 +6743,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
                        }
                        /* draw special */
                        switch (specials[special_index].type) {
+#ifdef X11
                                case HORIZONTAL_LINE:
                                {
                                        int h = specials[special_index].height;
@@ -6994,12 +7038,14 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
                                        font_h = font_height();
                                        break;
                                }
+#endif /* X11 */
                                case FG:
                                        if (draw_mode == FG) {
                                                set_foreground_color(specials[special_index].arg);
                                        }
                                        break;
 
+#ifdef X11
                                case BG:
                                        if (draw_mode == BG) {
                                                set_foreground_color(specials[special_index].arg);
@@ -7081,9 +7127,12 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
                                        last_special_needed = special_index;
                                        break;
                                }
+#endif /* X11 */
                        }
 
+#ifdef X11
                        cur_x += w;
+#endif /* X11 */
 
                        if (special_index != last_special_applied) {
                                special_index++;
@@ -7095,31 +7144,40 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
                p++;
        }
 
+#ifdef X11
        cur_y += cur_y_add;
+#endif /* X11 */
        draw_string(s);
+#ifdef NCURSES
+       if (output_methods & TO_NCURSES) {
+               printw("\n");
+       }
+#endif /* NCURSES */
+#ifdef X11
        cur_y += font_descent();
+#endif /* X11 */
        if (recurse && *recurse) {
                special_index = draw_each_line_inner(recurse, special_index, last_special_needed);
                *(recurse - 1) = SECRIT_MULTILINE_CHAR;
        }
        return special_index;
 }
-#endif /* X11 */
 
 static int draw_line(char *s, int special_index)
 {
 #ifdef X11
-       if ((output_methods & TO_X) == 0) {
-#endif /* X11 */
-               draw_string(s);
-               //'special_index - special_index' instead of 0 otherwise gcc complains about not using special_index when build without X11
-               return special_index - special_index;
-#ifdef X11
+       if (output_methods & TO_X) {
+               return draw_each_line_inner(s, special_index, -1);
        }
-
-       /* find specials and draw stuff */
-       return draw_each_line_inner(s, special_index, -1);
 #endif /* X11 */
+#ifdef NCURSES
+       if (output_methods & TO_NCURSES) {
+               return draw_each_line_inner(s, special_index, -1);
+       }
+#endif /* NCURSES */
+       draw_string(s);
+       UNUSED(special_index);
+       return 0;
 }
 
 static void draw_text(void)
@@ -7154,6 +7212,10 @@ static void draw_text(void)
        }
        setup_fonts();
 #endif /* X11 */
+#ifdef NCURSES
+       init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK);
+       attron(COLOR_PAIR(COLOR_WHITE));
+#endif /* NCURSES */
        for_each_line(text_buffer, draw_line);
 #if defined(HAVE_LUA) && defined(X11)
        llua_draw_post_hook();
@@ -7525,9 +7587,10 @@ static void main_loop(void)
                                        case ButtonPress:
                                                if (own_window) {
                                                        /* if an ordinary window with decorations */
-                                                       if ((window.type == TYPE_NORMAL)
-                                                               && (!TEST_HINT(window.hints,
-                                                               HINT_UNDECORATED))) {
+                                                       if ((window.type == TYPE_NORMAL &&
+                                                                               (!TEST_HINT(window.hints,
+                                                                                                       HINT_UNDECORATED))) ||
+                                                                       window.type == TYPE_DESKTOP) {
                                                                /* allow conky to hold input focus. */
                                                                break;
                                                        } else {
@@ -7763,7 +7826,6 @@ void clean_up(void *memtofree1, void* memtofree2)
 
 #ifdef NCURSES
        if(output_methods & TO_NCURSES) {
-               delwin(stdscr);
                endwin();
        }
 #endif
@@ -7853,6 +7915,12 @@ void clean_up(void *memtofree1, void* memtofree2)
        llua_shutdown_hook();
        llua_close();
 #endif /* HAVE_LUA */
+#ifdef IMLIB2
+       cimlib_deinit();
+#endif /* IMLIB2 */
+#ifdef XOAP
+       xmlCleanupParser();
+#endif /* XOAP */
 
        if (specials) {
                for (i = 0; i < special_count; i++) {
@@ -8562,6 +8630,7 @@ char load_config_file(const char *f)
                CONF("out_to_ncurses") {
                        if(string_to_bool(value)) {
                                initscr();
+                               start_color();
                                output_methods |= TO_NCURSES;
                        }
                }
@@ -9478,6 +9547,9 @@ void initialisation(int argc, char **argv) {
 #ifdef HAVE_LUA
        llua_setup_info(&info, update_interval);
 #endif /* HAVE_LUA */
+#ifdef XOAP
+       xmlInitParser();
+#endif /* XOAP */
 
        /* Set signal handlers */
        act.sa_handler = signal_handler;