xdbe replaced with more generic pixmap based buffering but there are 2 bugs:
[monky] / src / conky.c
index c8c55e7..7f5ec00 100644 (file)
@@ -70,6 +70,9 @@
 #ifdef XOAP
 #include <libxml/parser.h>
 #endif /* XOAP */
+#ifdef HAVE_CURL
+#include <curl/curl.h>
+#endif
 
 /* local headers */
 #include "core.h"
@@ -603,7 +606,7 @@ void human_readable(long long num, char *buf, int size)
                spaced_print(buf, size, "%d", 6, round_to_int(num));
                return;
        }
-       if (short_units) {
+       if (short_units || llabs(num) < 1000LL) {
                width = 5;
                format = "%.*f%.1s";
        } else {
@@ -630,11 +633,11 @@ void human_readable(long long num, char *buf, int size)
         * adjusting the decimal part of the number. Sample output:
         *  123MiB
         * 23.4GiB
-        * 5.12B   
+        * 5.12B
         * so the point of alignment resides between number and unit. The
         * upside of this is that there is minimal padding necessary, though
         * there should be a way to make alignment take place at the decimal
-        * dot (then with fixed width decimal part). 
+        * dot (then with fixed width decimal part).
         *
         * Note the repdigits below: when given a precision value, printf()
         * rounds the float to it, not just cuts off the remaining digits. So
@@ -876,6 +879,12 @@ void generate_text_internal(char *p, int p_max_size,
                        OBJ(battery_time) {
                                get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
                        }
+                       OBJ(battery_volts) {
+                               get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_VOLTS);
+                       }
+                       OBJ(battery_temp) {
+                               get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TEMP);
+                       }
                        OBJ(battery_percent) {
                                percent_print(p, p_max_size, get_battery_perct(obj->data.s));
                        }
@@ -885,6 +894,12 @@ void generate_text_internal(char *p, int p_max_size,
                        OBJ(battery_short) {
                                get_battery_short_status(p, p_max_size, obj->data.s);
                        }
+                       OBJ(cell_radio_dbm) {
+                               get_dbus_stuff(p, p_max_size, DBUS_CELL_DBM);
+                       }
+                       OBJ(cell_radio_percent) {
+                               get_dbus_stuff(p, p_max_size, DBUS_CELL_PERCENT);
+                       }
 #endif /* __OpenBSD__ */
 
                        OBJ(buffers) {
@@ -2069,9 +2084,11 @@ void generate_text_internal(char *p, int p_max_size,
                        OBJ(xmms2_percent) {
                                snprintf(p, p_max_size, "%2.0f", cur->xmms2.progress * 100);
                        }
+#ifdef X11
                        OBJ(xmms2_bar) {
                                new_bar(obj, p, p_max_size, (int) (cur->xmms2.progress * 255.0f));
                        }
+#endif /* X11 */
                        OBJ(xmms2_playlist) {
                                snprintf(p, p_max_size, "%s", cur->xmms2.playlist);
                        }
@@ -2147,6 +2164,7 @@ void generate_text_internal(char *p, int p_max_size,
                                snprintf(p, p_max_size, "%s",
                                        cur->audacious.items[AUDACIOUS_MAIN_VOLUME]);
                        }
+#ifdef X11
                        OBJ(audacious_bar) {
                                double progress;
 
@@ -2155,6 +2173,7 @@ void generate_text_internal(char *p, int p_max_size,
                                        atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
                                new_bar(obj, p, p_max_size, (int) (progress * 255.0f));
                        }
+#endif /* X11 */
 #endif /* AUDACIOUS */
 
 #ifdef BMPX
@@ -2277,18 +2296,26 @@ void generate_text_internal(char *p, int p_max_size,
                                        }
                                }
                        }
-                       OBJ(to_bytes) {
+                       OBJ(to_bytes) {//commented code is original - not working when input value contains a decimal point
                                char buf[max_user_text];
-                               long long bytes;
+                               //long long bytes;
+                               long double bytes;
                                char unit[16];  // 16 because we can also have long names (like mega-bytes)
 
                                generate_text_internal(buf, max_user_text, *obj->sub, cur);
-                               if(sscanf(buf, "%lli%s", &bytes, unit) == 2 && strlen(unit) < 16){
-                                       if(strncasecmp("b", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes);
-                                       else if(strncasecmp("k", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024);
-                                       else if(strncasecmp("m", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024 * 1024);
-                                       else if(strncasecmp("g", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024 * 1024 * 1024);
-                                       else if(strncasecmp("t", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024 * 1024 * 1024 * 1024);
+//                             if(sscanf(buf, "%lli%s", &bytes, unit) == 2 && strlen(unit) < 16){
+//                                     if(strncasecmp("b", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes);
+//                                     else if(strncasecmp("k", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024);
+//                                     else if(strncasecmp("m", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024 * 1024);
+//                                     else if(strncasecmp("g", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024 * 1024 * 1024);
+//                                     else if(strncasecmp("t", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024 * 1024 * 1024 * 1024);
+//                             }
+                               if(sscanf(buf, "%Lf%s", &bytes, unit) == 2 && strlen(unit) < 16){
+                                       if(strncasecmp("b", unit, 1) == 0) snprintf(buf, max_user_text, "%Lf", bytes);
+                                       else if(strncasecmp("k", unit, 1) == 0) snprintf(buf, max_user_text, "%Lf", bytes * 1024);
+                                       else if(strncasecmp("m", unit, 1) == 0) snprintf(buf, max_user_text, "%Lf", bytes * 1024 * 1024);
+                                       else if(strncasecmp("g", unit, 1) == 0) snprintf(buf, max_user_text, "%Lf", bytes * 1024 * 1024 * 1024);
+                                       else if(strncasecmp("t", unit, 1) == 0) snprintf(buf, max_user_text, "%Lf", bytes * 1024 * 1024 * 1024 * 1024);
                                }
                                snprintf(p, p_max_size, "%s", buf);
                        }
@@ -2300,7 +2327,7 @@ void generate_text_internal(char *p, int p_max_size,
                        }
 #ifdef NVIDIA
                        OBJ(nvidia) {
-                               print_nvidia_value(obj, display, p, p_max_size);
+                               print_nvidia_value(obj, p, p_max_size);
                        }
 #endif /* NVIDIA */
 #ifdef APCUPSD
@@ -3081,12 +3108,14 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
                                                                                  );
                                                                }
 #endif /* DEBUG_lol */
-                                                               XSetForeground(display, window.gc, tmpcolour[
-                                                                               (int)((float)(w - 2) - specials[special_index].graph[j] *
-                                                                                       (w - 2) / (float)specials[special_index].graph_scale)
-                                                                               ]);
+                                                                               set_foreground_color(tmpcolour[
+                                                                                               (int)((float)(w - 2) -
+                                                                                                       specials[special_index].graph[j]
+                                                                                                       * (w - 2) /
+                                                                                                       (float)specials[special_index].graph_scale)
+                                                                                               ]);
                                                        } else {
-                                                               XSetForeground(display, window.gc, tmpcolour[colour_idx++]);
+                                                               set_foreground_color(tmpcolour[colour_idx++]);
                                                        }
                                                }
                                                /* this is mugfugly, but it works */
@@ -3465,8 +3494,20 @@ static void clear_text(int exposures)
 {
 #ifdef HAVE_XDBE
        if (use_xdbe) {
-               /* The swap action is XdbeBackground, which clears */
+/*
+                The swap action is XdbeBackground, which clears 
                return;
+*/
+       if (display && window.back_buffer) { // make sure these are !null
+               /* there is some extra space for borders and outlines */
+               XFillRectangle(display, window.back_buffer, window.gc_back,
+                        text_start_x - window.border_inner_margin - window.border_outer_margin - window.border_width,
+                       text_start_y - window.border_inner_margin - window.border_outer_margin - window.border_width,
+                       text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2,
+                       text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2);
+       }
+            
+            
        } else
 #endif
        if (display && window.window) { // make sure these are !null
@@ -3531,7 +3572,7 @@ static void main_loop(void)
                if(update_interval_bat != NOBATTERY && update_interval_bat != update_interval_old) {
                        char buf[max_user_text];
 
-                       get_battery_short_status(buf, max_user_text, "BAT0");
+                       get_battery_short_status(buf, max_user_text, "bq27200-0"); //why is this even hardcoded here? oh well.
                        if(buf[0] == 'D') {
                                update_interval = update_interval_bat;
                        } else {
@@ -3604,6 +3645,20 @@ static void main_loop(void)
                                                draw_stuff(); /* redraw everything in our newly sized window */
                                                XResizeWindow(display, window.window, window.width,
                                                                window.height); /* resize window */
+                                               fprintf(stderr, PACKAGE_NAME": resizing window to %d x %d\n",window.width,window.height);
+#ifdef HAVE_XDBE
+                                               if (use_xdbe) {
+                                                       XFreePixmap(display, window.back_buffer);
+                                                       window.back_buffer = XCreatePixmap(display, window.window,
+                                                                                                                          window.width, window.height, window.depth);
+                                                       if (window.back_buffer != None)
+                                                               window.drawable = window.back_buffer;
+                                                       else {
+                                                               window.drawable = window.window;
+                                                               use_xdbe = 0;
+                                                       }
+                                               }
+#endif
                                                set_transparent_background(window.window, own_window_argb_value);
 #ifdef HAVE_XDBE
                                                /* swap buffers */
@@ -3729,7 +3784,21 @@ static void main_loop(void)
                                                                                        window.window, &attrs)) {
                                                                                window.width = attrs.width;
                                                                                window.height = attrs.height;
+                                                                               fprintf(stderr, PACKAGE_NAME": x11? resized our window to %d x %d\n",window.width,window.height);
+                                                                       }
+#ifdef HAVE_XDBE
+                                                                       if (use_xdbe) {
+                                                                               XFreePixmap(display, window.back_buffer);
+                                                                               window.back_buffer = XCreatePixmap(display, window.window,
+                                                                                                                                                  window.width, window.height, window.depth);
+                                                                               if (window.back_buffer != None)
+                                                                                       window.drawable = window.back_buffer;
+                                                                               else {
+                                                                                       window.drawable = window.window;
+                                                                                       use_xdbe = 0;
+                                                                               }
                                                                        }
+#endif
                                                                }
 
                                                                text_width = window.width - window.border_inner_margin * 2 - window.border_outer_margin * 2 - window.border_width * 2;
@@ -3763,6 +3832,17 @@ static void main_loop(void)
                                                                        window.type == TYPE_DESKTOP) {
                                                                /* allow conky to hold input focus. */
                                                                break;
+                                                       } else if(TEST_HINT(window.hints,HINT_FULLSCREEN)) {
+                                                               //detect top right click
+                                                               if (ev.xbutton.x > 750 && ev.xbutton.y < 50)
+                                                               {
+                                                                       terminate = 1;
+                                                               }
+                                                               if (ev.xbutton.x <= 50 && ev.xbutton.y <= 50)
+                                                               {       //minimize / goto task switcher
+                                                                       dbus_exit_app_view();
+                                                               }
+                                                               break;
                                                        } else {
                                                                /* forward the click to the desktop window */
                                                                XUngrabPointer(display, ev.xbutton.time);
@@ -3848,6 +3928,7 @@ static void main_loop(void)
                } else {
 #endif /* X11 */
                        t = (next_update_time - get_time()) * 1000000;
+                       fprintf(stderr, PACKAGE_NAME": trying to sleep %d microseconds\n",t);
                        if(t > 0) usleep((useconds_t)t);
                        update_text();
                        draw_stuff();
@@ -4055,6 +4136,9 @@ void clean_up_without_threads(void *memtofree1, void* memtofree2) {
                font_count = -1;
        }
 
+#ifdef NVIDIA
+       set_nvidia_display(NULL);
+#endif
 #endif /* X11 */
 
        free_templates();
@@ -4602,6 +4686,12 @@ char load_config_file(const char *f)
                                disp = strdup(value);
                        }
                }
+#ifdef NVIDIA
+               CONF("nvidia_display") {
+                       if(value)
+                               set_nvidia_display(value);
+               }
+#endif
                CONF("alignment") {
                        setalignment(&text_alignment, window.type, value, f, line, 1);
                }
@@ -5054,8 +5144,8 @@ char load_config_file(const char *f)
                                                        SET_HINT(window.hints, HINT_STICKY);
                                                } else if (strncmp(p_hint, "skip_taskbar", 12) == EQUAL) {
                                                        SET_HINT(window.hints, HINT_SKIP_TASKBAR);
-                                               } else if (strncmp(p_hint, "skip_pager", 10) == EQUAL) {
-                                                       SET_HINT(window.hints, HINT_SKIP_PAGER);
+                                               } else if (strncmp(p_hint, "fullscreen", 10) == EQUAL) {
+                                                       SET_HINT(window.hints, HINT_FULLSCREEN);
                                                } else {
                                                        CONF_ERR;
                                                }
@@ -5704,6 +5794,7 @@ void initialisation(int argc, char **argv) {
                        "kvm_open")) == NULL) {
                CRIT_ERR(NULL, NULL, "cannot read kvm");
        }
+       pthread_mutex_init(&kvm_proc_mutex, NULL);
 #endif
 
        while (1) {
@@ -5885,6 +5976,11 @@ int main(int argc, char **argv)
        tcp_portmon_set_max_connections(0);
 #endif
 
+#ifdef HAVE_CURL
+       if(curl_global_init(CURL_GLOBAL_ALL))
+               NORM_ERR("curl_global_init() failed, you may not be able to use curl variables");
+#endif
+
        /* handle command line parameters that don't change configs */
 #ifdef X11
        if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) && *s)
@@ -5976,8 +6072,13 @@ int main(int argc, char **argv)
 
        main_loop();
 
+#ifdef HAVE_CURL
+       curl_global_cleanup();
+#endif
+
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
        kvm_close(kd);
+       pthread_mutex_destroy(&kvm_proc_mutex);
 #endif
 
        return 0;
@@ -5994,7 +6095,7 @@ static void signal_handler(int sig)
 {
        /* signal handler is light as a feather, as it should be.
         * we will poll g_signal_pending with each loop of conky
-        * and do any signal processing there, NOT here (except 
+        * and do any signal processing there, NOT here (except
         * SIGALRM because this is caused when conky is hanging) */
        if(sig == SIGALRM) {
                alarm_handler();