Line 0
Link Here
|
|
|
1 |
--- src/conky.c.orig 2010-03-25 22:27:32.000000000 +0200 |
2 |
+++ src/conky.c 2010-06-11 23:10:56.000000000 +0300 |
3 |
@@ -166,9 +166,7 @@ |
4 |
#ifdef IOSTATS |
5 |
int top_io; |
6 |
#endif |
7 |
-#ifdef __linux__ |
8 |
int top_running; |
9 |
-#endif |
10 |
int output_methods; |
11 |
static int extra_newline; |
12 |
enum x_initialiser_state x_initialised = NO; |
13 |
@@ -269,9 +267,6 @@ |
14 |
#ifdef IMLIB2 |
15 |
" * Imlib2\n" |
16 |
#endif /* IMLIB2 */ |
17 |
-#ifdef MIXER_IS_ALSA |
18 |
- " * ALSA mixer support\n" |
19 |
-#endif /* MIXER_IS_ALSA */ |
20 |
#ifdef APCUPSD |
21 |
" * apcupsd\n" |
22 |
#endif /* APCUPSD */ |
23 |
@@ -463,7 +458,7 @@ |
24 |
} |
25 |
fclose(where); |
26 |
} else { |
27 |
- NORM_ERR("Could not open the file"); |
28 |
+ NORM_ERR("Could not open the file '%s'", f); |
29 |
} |
30 |
return ret; |
31 |
} |
32 |
@@ -512,6 +507,7 @@ |
33 |
char *ps, *pe; |
34 |
int special_index = 0; /* specials index */ |
35 |
|
36 |
+ if(! b) return; |
37 |
for (ps = b, pe = b; *pe; pe++) { |
38 |
if (*pe == '\n') { |
39 |
*pe = '\0'; |
40 |
@@ -765,6 +761,8 @@ |
41 |
buff_in[0] = 0; |
42 |
#endif /* HAVE_ICONV */ |
43 |
|
44 |
+ if(! p) return; |
45 |
+ |
46 |
p[0] = 0; |
47 |
obj = root.next; |
48 |
while (obj && p_max_size > 0) { |
49 |
@@ -1330,7 +1328,7 @@ |
50 |
DO_JUMP; |
51 |
} else if (spc) { |
52 |
*spc = '\0'; |
53 |
- if (check_contains(obj->data.s, spc + 1)) |
54 |
+ if (!check_contains(obj->data.s, spc + 1)) |
55 |
DO_JUMP; |
56 |
*spc = ' '; |
57 |
} |
58 |
@@ -1503,6 +1501,15 @@ |
59 |
OBJ(nodename) { |
60 |
snprintf(p, p_max_size, "%s", cur->uname_s.nodename); |
61 |
} |
62 |
+ OBJ(nodename_short) { |
63 |
+ char *pos; |
64 |
+ pos = strstr(cur->uname_s.nodename, "."); |
65 |
+ if(pos != NULL) { |
66 |
+ snprintf(p, MIN(pos-cur->uname_s.nodename+1, p_max_size), "%s", cur->uname_s.nodename); |
67 |
+ } else { |
68 |
+ snprintf(p, p_max_size, "%s", cur->uname_s.nodename); |
69 |
+ } |
70 |
+ } |
71 |
OBJ(outlinecolor) { |
72 |
new_outline(p, obj->data.l); |
73 |
} |
74 |
@@ -2062,9 +2069,11 @@ |
75 |
OBJ(xmms2_percent) { |
76 |
snprintf(p, p_max_size, "%2.0f", cur->xmms2.progress * 100); |
77 |
} |
78 |
+#ifdef X11 |
79 |
OBJ(xmms2_bar) { |
80 |
new_bar(obj, p, p_max_size, (int) (cur->xmms2.progress * 255.0f)); |
81 |
} |
82 |
+#endif /* X11 */ |
83 |
OBJ(xmms2_playlist) { |
84 |
snprintf(p, p_max_size, "%s", cur->xmms2.playlist); |
85 |
} |
86 |
@@ -2140,6 +2149,7 @@ |
87 |
snprintf(p, p_max_size, "%s", |
88 |
cur->audacious.items[AUDACIOUS_MAIN_VOLUME]); |
89 |
} |
90 |
+#ifdef X11 |
91 |
OBJ(audacious_bar) { |
92 |
double progress; |
93 |
|
94 |
@@ -2148,6 +2158,7 @@ |
95 |
atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]); |
96 |
new_bar(obj, p, p_max_size, (int) (progress * 255.0f)); |
97 |
} |
98 |
+#endif /* X11 */ |
99 |
#endif /* AUDACIOUS */ |
100 |
|
101 |
#ifdef BMPX |
102 |
@@ -2173,7 +2184,6 @@ |
103 |
/* we have four different types of top (top, top_mem, |
104 |
* top_time and top_io). To avoid having almost-same code four |
105 |
* times, we have this special handler. */ |
106 |
-#ifdef __linux__ |
107 |
break; |
108 |
case OBJ_top: |
109 |
case OBJ_top_mem: |
110 |
@@ -2182,7 +2192,6 @@ |
111 |
case OBJ_top_io: |
112 |
#endif |
113 |
print_top(obj, p, p_max_size); |
114 |
-#endif /* __linux__ */ |
115 |
OBJ(tail) { |
116 |
print_tailhead("tail", obj, p, p_max_size); |
117 |
} |
118 |
@@ -2375,13 +2384,7 @@ |
119 |
#ifdef HAVE_ICONV |
120 |
iconv_convert(&a, buff_in, p, p_max_size); |
121 |
#endif /* HAVE_ICONV */ |
122 |
- if (obj->type != OBJ_text && obj->type != OBJ_execp && obj->type != OBJ_execpi |
123 |
-#ifdef HAVE_LUA |
124 |
- && obj->type != OBJ_lua && obj->type != OBJ_lua_parse |
125 |
-#endif /* HAVE_LUA */ |
126 |
- ) { |
127 |
- substitute_newlines(p, a - 2); |
128 |
- } |
129 |
+ substitute_newlines(p, a - 2); |
130 |
p += a; |
131 |
p_max_size -= a; |
132 |
(*p) = 0; |
133 |
@@ -3119,36 +3122,49 @@ |
134 |
if (seconds != 0) { |
135 |
timeunits = seconds / 86400; seconds %= 86400; |
136 |
if (timeunits > 0) { |
137 |
- asprintf(&tmp_day_str, "%dd", timeunits); |
138 |
+ if (asprintf(&tmp_day_str, "%dd", timeunits) < 0) { |
139 |
+ tmp_day_str = 0; |
140 |
+ } |
141 |
} else { |
142 |
tmp_day_str = strdup(""); |
143 |
} |
144 |
timeunits = seconds / 3600; seconds %= 3600; |
145 |
if (timeunits > 0) { |
146 |
- asprintf(&tmp_hour_str, "%dh", timeunits); |
147 |
+ if (asprintf(&tmp_hour_str, "%dh", timeunits) < 0) { |
148 |
+ tmp_day_str = 0; |
149 |
+ } |
150 |
} else { |
151 |
tmp_hour_str = strdup(""); |
152 |
} |
153 |
timeunits = seconds / 60; seconds %= 60; |
154 |
if (timeunits > 0) { |
155 |
- asprintf(&tmp_min_str, "%dm", timeunits); |
156 |
+ if (asprintf(&tmp_min_str, "%dm", timeunits) < 0) { |
157 |
+ tmp_min_str = 0; |
158 |
+ } |
159 |
} else { |
160 |
tmp_min_str = strdup(""); |
161 |
} |
162 |
if (seconds > 0) { |
163 |
- asprintf(&tmp_sec_str, "%ds", seconds); |
164 |
+ if (asprintf(&tmp_sec_str, "%ds", seconds) < 0) { |
165 |
+ tmp_sec_str = 0; |
166 |
+ } |
167 |
} else { |
168 |
tmp_sec_str = strdup(""); |
169 |
} |
170 |
- asprintf(&tmp_str, "%s%s%s%s", tmp_day_str, tmp_hour_str, tmp_min_str, tmp_sec_str); |
171 |
- free(tmp_day_str); free(tmp_hour_str); free(tmp_min_str); free(tmp_sec_str); |
172 |
+ if (asprintf(&tmp_str, "%s%s%s%s", tmp_day_str, |
173 |
+ tmp_hour_str, tmp_min_str, tmp_sec_str) < 0) { |
174 |
+ tmp_str = 0; |
175 |
+ } |
176 |
+#define FREE(a) if ((a)) free((a)); |
177 |
+ FREE(tmp_day_str); FREE(tmp_hour_str); FREE(tmp_min_str); FREE(tmp_sec_str); |
178 |
} else { |
179 |
- asprintf(&tmp_str, "Range not possible"); // should never happen, but better safe then sorry |
180 |
+ tmp_str = strdup("Range not possible"); /* should never happen, but better safe then sorry */ |
181 |
} |
182 |
cur_x += (w / 2) - (font_ascent() * (strlen(tmp_str) / 2)); |
183 |
cur_y += font_h / 2; |
184 |
draw_string(tmp_str); |
185 |
- free(tmp_str); |
186 |
+ FREE(tmp_str); |
187 |
+#undef FREE |
188 |
cur_x = tmp_x; |
189 |
cur_y = tmp_y; |
190 |
} |
191 |
@@ -3974,11 +3990,39 @@ |
192 |
initialisation(argc_copy, argv_copy); |
193 |
} |
194 |
|
195 |
-void clean_up(void *memtofree1, void* memtofree2) |
196 |
-{ |
197 |
- int i; |
198 |
+#ifdef X11 |
199 |
+void clean_up_x11() { |
200 |
+ if(window_created == 1) { |
201 |
+ XClearArea(display, window.window, text_start_x - window.border_inner_margin - window.border_outer_margin - window.border_width, |
202 |
+ text_start_y - window.border_inner_margin - window.border_outer_margin - window.border_width, |
203 |
+ text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2, |
204 |
+ text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2, 0); |
205 |
+ } |
206 |
+ destroy_window(); |
207 |
+ free_fonts(); |
208 |
+ fonts = NULL; |
209 |
+ if(x11_stuff.region) { |
210 |
+ XDestroyRegion(x11_stuff.region); |
211 |
+ x11_stuff.region = NULL; |
212 |
+ } |
213 |
+ if(display) { |
214 |
+ XCloseDisplay(display); |
215 |
+ display = NULL; |
216 |
+ } |
217 |
+ if(info.x11.desktop.all_names) { |
218 |
+ free(info.x11.desktop.all_names); |
219 |
+ info.x11.desktop.all_names = NULL; |
220 |
+ } |
221 |
+ if (info.x11.desktop.name) { |
222 |
+ free(info.x11.desktop.name); |
223 |
+ info.x11.desktop.name = NULL; |
224 |
+ } |
225 |
+ x_initialised = NO; |
226 |
+} |
227 |
+#endif |
228 |
|
229 |
- free_update_callbacks(); |
230 |
+void clean_up_without_threads(void *memtofree1, void* memtofree2) { |
231 |
+ int i; |
232 |
|
233 |
#ifdef NCURSES |
234 |
if(output_methods & TO_NCURSES) { |
235 |
@@ -4001,29 +4045,7 @@ |
236 |
} |
237 |
#ifdef X11 |
238 |
if (x_initialised == YES) { |
239 |
- if(window_created == 1) { |
240 |
- XClearArea(display, window.window, text_start_x - window.border_inner_margin - window.border_outer_margin - window.border_width, |
241 |
- text_start_y - window.border_inner_margin - window.border_outer_margin - window.border_width, |
242 |
- text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2, |
243 |
- text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2, 0); |
244 |
- } |
245 |
- destroy_window(); |
246 |
- free_fonts(); |
247 |
- if(x11_stuff.region) { |
248 |
- XDestroyRegion(x11_stuff.region); |
249 |
- x11_stuff.region = NULL; |
250 |
- } |
251 |
- XCloseDisplay(display); |
252 |
- display = NULL; |
253 |
- if(info.x11.desktop.all_names) { |
254 |
- free(info.x11.desktop.all_names); |
255 |
- info.x11.desktop.all_names = NULL; |
256 |
- } |
257 |
- if (info.x11.desktop.name) { |
258 |
- free(info.x11.desktop.name); |
259 |
- info.x11.desktop.name = NULL; |
260 |
- } |
261 |
- x_initialised = NO; |
262 |
+ clean_up_x11(); |
263 |
}else{ |
264 |
free(fonts); //in set_default_configurations a font is set but not loaded |
265 |
font_count = -1; |
266 |
@@ -4097,6 +4119,12 @@ |
267 |
} |
268 |
} |
269 |
|
270 |
+void clean_up(void *memtofree1, void* memtofree2) |
271 |
+{ |
272 |
+ free_update_callbacks(); |
273 |
+ clean_up_without_threads(memtofree1, memtofree2); |
274 |
+} |
275 |
+ |
276 |
static int string_to_bool(const char *s) |
277 |
{ |
278 |
if (!s) { |
279 |
@@ -4200,9 +4228,7 @@ |
280 |
#ifdef IOSTATS |
281 |
top_io = 0; |
282 |
#endif |
283 |
-#ifdef __linux__ |
284 |
top_running = 0; |
285 |
-#endif |
286 |
#ifdef MPD |
287 |
mpd_env_host = getenv("MPD_HOST"); |
288 |
mpd_env_port = getenv("MPD_PORT"); |
289 |
@@ -4252,6 +4278,9 @@ |
290 |
output_methods = TO_STDOUT; |
291 |
#endif |
292 |
#ifdef X11 |
293 |
+#ifdef BUILD_XFT |
294 |
+ use_xft = 0; |
295 |
+#endif |
296 |
show_graph_scale = 0; |
297 |
show_graph_range = 0; |
298 |
draw_shades = 1; |
299 |
@@ -4282,11 +4311,11 @@ |
300 |
text_alignment = BOTTOM_LEFT; |
301 |
info.x11.monitor.number = 1; |
302 |
info.x11.monitor.current = 0; |
303 |
- info.x11.desktop.current = 1; |
304 |
+ info.x11.desktop.current = 1; |
305 |
info.x11.desktop.number = 1; |
306 |
info.x11.desktop.nitems = 0; |
307 |
- info.x11.desktop.all_names = NULL; |
308 |
- info.x11.desktop.name = NULL; |
309 |
+ info.x11.desktop.all_names = NULL; |
310 |
+ info.x11.desktop.name = NULL; |
311 |
#endif /* X11 */ |
312 |
|
313 |
free_templates(); |
314 |
@@ -4518,13 +4547,13 @@ |
315 |
int a = string_to_alignment(value); |
316 |
|
317 |
if (a <= 0) { |
318 |
- if(setbyconffile == true) { |
319 |
+ if (setbyconffile) { |
320 |
CONF_ERR; |
321 |
} else NORM_ERR("'%s' is not a alignment setting", value); |
322 |
} else { |
323 |
*ltext_alignment = a; |
324 |
} |
325 |
- } else if(setbyconffile == true) { |
326 |
+ } else if (setbyconffile) { |
327 |
CONF_ERR; |
328 |
} |
329 |
} |
330 |
@@ -4552,15 +4581,12 @@ |
331 |
|
332 |
#ifdef X11 |
333 |
CONF2("out_to_x") { |
334 |
- /* don't listen if X is already initialised or |
335 |
- * if we already know we don't want it */ |
336 |
- if(x_initialised != YES) { |
337 |
- if (string_to_bool(value)) { |
338 |
- output_methods &= TO_X; |
339 |
- } else { |
340 |
- output_methods &= ~TO_X; |
341 |
- x_initialised = NEVER; |
342 |
- } |
343 |
+ if (string_to_bool(value)) { |
344 |
+ output_methods &= TO_X; |
345 |
+ } else { |
346 |
+ clean_up_x11(); |
347 |
+ output_methods &= ~TO_X; |
348 |
+ x_initialised = NEVER; |
349 |
} |
350 |
} |
351 |
CONF("display") { |
352 |
@@ -4573,7 +4599,7 @@ |
353 |
} |
354 |
} |
355 |
CONF("alignment") { |
356 |
- setalignment(&text_alignment, window.type, value, f, line, true); |
357 |
+ setalignment(&text_alignment, window.type, value, f, line, 1); |
358 |
} |
359 |
CONF("background") { |
360 |
fork_to_background = string_to_bool(value); |
361 |
@@ -4609,7 +4635,7 @@ |
362 |
CONF("border_width") { |
363 |
if (value) { |
364 |
window.border_width = strtol(value, 0, 0); |
365 |
- if (window.border_width < 0) window.border_width = 0; |
366 |
+ if (window.border_width < 1) window.border_width = 1; |
367 |
} else { |
368 |
CONF_ERR; |
369 |
} |
370 |
@@ -5696,7 +5722,7 @@ |
371 |
set_first_font(optarg); |
372 |
break; |
373 |
case 'a': |
374 |
- setalignment(&text_alignment, window.type, optarg, NULL, 0, false); |
375 |
+ setalignment(&text_alignment, window.type, optarg, NULL, 0, 0); |
376 |
break; |
377 |
|
378 |
#ifdef OWN_WINDOW |
379 |
@@ -5895,7 +5921,9 @@ |
380 |
current_config = strndup(optarg, max_user_text); |
381 |
break; |
382 |
case 'q': |
383 |
- freopen("/dev/null", "w", stderr); |
384 |
+ if (!freopen("/dev/null", "w", stderr)) { |
385 |
+ NORM_ERR("unable to redirect stderr to /dev/null"); |
386 |
+ } |
387 |
break; |
388 |
case 'h': |
389 |
print_help(argv[0]); |
390 |
@@ -5929,7 +5957,13 @@ |
391 |
#endif /* XOAP */ |
392 |
|
393 |
#ifdef HAVE_SYS_INOTIFY_H |
394 |
- inotify_fd = inotify_init1(IN_NONBLOCK); |
395 |
+ inotify_fd = inotify_init(); |
396 |
+ if(inotify_fd != -1) { |
397 |
+ int fl; |
398 |
+ |
399 |
+ fl = fcntl(inotify_fd, F_GETFL); |
400 |
+ fcntl(inotify_fd, F_SETFL, fl | O_NONBLOCK); |
401 |
+ } |
402 |
#endif /* HAVE_SYS_INOTIFY_H */ |
403 |
|
404 |
initialisation(argc, argv); |