… | |
… | |
39 | |
39 | |
40 | #if HAS_REGEX |
40 | #if HAS_REGEX |
41 | #include <regex.h> |
41 | #include <regex.h> |
42 | #endif |
42 | #endif |
43 | |
43 | |
|
|
44 | #define SHADE_X 2 |
|
|
45 | #define SHADE_Y 2 |
|
|
46 | |
44 | /* data structures */ |
47 | /* data structures */ |
45 | struct logfile_entry |
48 | struct logfile_entry |
46 | { |
49 | { |
47 | struct logfile_entry *next; |
50 | struct logfile_entry *next; |
48 | |
51 | |
… | |
… | |
68 | /* global variables */ |
71 | /* global variables */ |
69 | struct linematrix *lines; |
72 | struct linematrix *lines; |
70 | int width = STD_WIDTH, height = STD_HEIGHT, listlen; |
73 | int width = STD_WIDTH, height = STD_HEIGHT, listlen; |
71 | int win_x = LOC_X, win_y = LOC_Y; |
74 | int win_x = LOC_X, win_y = LOC_Y; |
72 | int font_ascent, font_height; |
75 | int font_ascent, font_height; |
|
|
76 | int effect_x_space, effect_y_space; /* how much space does shading / outlining take up */ |
|
|
77 | int effect_x_offset, effect_y_offset; /* and how does it offset the usable space */ |
73 | int do_reopen; |
78 | int do_reopen; |
74 | struct timeval interval = { 2, 400000 }; |
79 | struct timeval interval = { 2, 400000 }; |
75 | XFontSet fontset; |
80 | XFontSet fontset; |
76 | |
81 | |
77 | /* command line options */ |
82 | /* command line options */ |
… | |
… | |
297 | if (geom_mask & XNegative) |
302 | if (geom_mask & XNegative) |
298 | win_x = win_x + ScreenWidth - width; |
303 | win_x = win_x + ScreenWidth - width; |
299 | if (geom_mask & YNegative) |
304 | if (geom_mask & YNegative) |
300 | win_y = win_y + ScreenHeight - height; |
305 | win_y = win_y + ScreenHeight - height; |
301 | |
306 | |
|
|
307 | if (opt_outline) |
|
|
308 | { |
|
|
309 | /* adding outline increases the total width and height by 2 |
|
|
310 | pixels each, and offsets the text one pixel right and one |
|
|
311 | pixel down */ |
|
|
312 | effect_x_space = effect_y_space = 2; |
|
|
313 | effect_x_offset = effect_y_offset = 1; |
|
|
314 | } |
|
|
315 | else if (opt_shade) |
|
|
316 | { |
|
|
317 | /* adding a shadow increases the space used */ |
|
|
318 | effect_x_space = abs(SHADE_X); |
|
|
319 | effect_y_space = abs(SHADE_Y); |
|
|
320 | /* if the shadow is to the right and below then we don't need |
|
|
321 | * to move the text to make space for it, but shadows to the left |
|
|
322 | * and above need accomodating */ |
|
|
323 | effect_x_offset = SHADE_X > 0 ? 0 : -SHADE_X; |
|
|
324 | effect_y_offset = SHADE_Y > 0 ? 0 : -SHADE_Y; |
|
|
325 | } |
|
|
326 | else |
|
|
327 | { |
|
|
328 | effect_x_space = effect_y_space = 0; |
|
|
329 | effect_x_offset = effect_y_offset = 0; |
|
|
330 | } |
|
|
331 | |
|
|
332 | /* if we are using -shade or -outline, there will be less usable |
|
|
333 | * space for output */ |
302 | listlen = height / font_height; |
334 | listlen = (height - effect_y_space) / font_height; |
303 | |
335 | |
304 | if (!listlen) |
336 | if (!listlen) |
305 | { |
337 | { |
306 | fprintf (stderr, "height too small for a single line, setting to %d\n", |
338 | fprintf (stderr, "height too small for a single line, setting to %d\n", |
307 | font_height); |
339 | font_height); |
308 | listlen = 1; |
340 | listlen = 1; |
309 | } |
341 | } |
310 | |
342 | |
311 | height = listlen * font_height; |
343 | /* leave the height how the user requested it. it might not all be |
312 | |
344 | * used, but this will allow the geometry to be tuned more accurately |
|
|
345 | * (with the -frame option) |
|
|
346 | * the old code did this: |
|
|
347 | * height = listlen * font_height + effect_y_space; */ |
|
|
348 | |
313 | XSelectInput (disp, root, ExposureMask | FocusChangeMask); |
349 | XSelectInput (disp, root, ExposureMask | FocusChangeMask); |
314 | } |
350 | } |
315 | |
351 | |
316 | /* |
352 | /* |
317 | * redraw does a complete redraw, rather than an update (i.e. the area |
353 | * redraw does a complete redraw, rather than an update (i.e. the area |
… | |
… | |
347 | |
383 | |
348 | if (offset < miny || offset > maxy) |
384 | if (offset < miny || offset > maxy) |
349 | continue; |
385 | continue; |
350 | |
386 | |
351 | if (clear && opt_noflicker) |
387 | if (clear && opt_noflicker) |
352 | XClearArea (disp, root, win_x, win_y + offset - font_ascent, width, font_height, False); |
388 | XClearArea (disp, root, win_x, win_y + offset - font_height, |
|
|
389 | width + effect_x_space, font_height + effect_y_space, False); |
353 | |
390 | |
354 | if (opt_outline) |
391 | if (opt_outline) |
355 | { |
392 | { |
|
|
393 | int x, y; |
356 | XSetForeground (disp, WinGC, black_color); |
394 | XSetForeground (disp, WinGC, black_color); |
|
|
395 | |
|
|
396 | for (x = -1; x < 2; x += 2) |
|
|
397 | for (y = -1; y < 2; y += 2) |
357 | XmbDrawString (disp, root, fontset, WinGC, win_x - 1, |
398 | XmbDrawString (disp, root, fontset, WinGC, |
358 | win_y + offset + 1, line->line, line->len); |
399 | win_x + effect_x_offset + x, |
359 | XmbDrawString (disp, root, fontset, WinGC, win_x + 1, |
400 | win_y + effect_y_offset + y + offset - font_height + font_ascent, |
360 | win_y + offset + 1, line->line, line->len); |
401 | line->line, line->len); |
361 | XmbDrawString (disp, root, fontset, WinGC, win_x - 1, |
|
|
362 | win_y + offset - 1, line->line, line->len); |
|
|
363 | XmbDrawString (disp, root, fontset, WinGC, win_x + 1, |
|
|
364 | win_y + offset - 1, line->line, line->len); |
|
|
365 | } |
402 | } |
366 | else if (opt_shade) |
403 | else if (opt_shade) |
367 | { |
404 | { |
368 | XSetForeground (disp, WinGC, black_color); |
405 | XSetForeground (disp, WinGC, black_color); |
369 | XmbDrawString (disp, root, fontset, WinGC, win_x + 2, |
406 | XmbDrawString (disp, root, fontset, WinGC, |
370 | win_y + offset + 2, line->line, line->len); |
407 | win_x + effect_x_offset + SHADE_X, |
|
|
408 | win_y + effect_y_offset + offset + SHADE_Y - font_height + font_ascent, |
|
|
409 | line->line, line->len); |
371 | } |
410 | } |
372 | |
411 | |
373 | XSetForeground (disp, WinGC, line->color); |
412 | XSetForeground (disp, WinGC, line->color); |
374 | XmbDrawString (disp, root, fontset, WinGC, win_x, win_y + offset, |
413 | XmbDrawString (disp, root, fontset, WinGC, |
|
|
414 | win_x + effect_x_offset, |
|
|
415 | win_y + effect_y_offset + offset - font_height + font_ascent, |
375 | line->line, line->len); |
416 | line->line, line->len); |
376 | } |
417 | } |
377 | |
418 | |
378 | if (opt_frame) |
419 | if (opt_frame) |
379 | { |
420 | { |
380 | XSetForeground (disp, WinGC, GetColor (def_color)); |
421 | XSetForeground (disp, WinGC, GetColor (def_color)); |
381 | XDrawRectangle (disp, root, WinGC, win_x - 2, win_y - 2, width + 4, height + 4); |
422 | XDrawRectangle (disp, root, WinGC, win_x - 0, win_y - 0, width - 1, height - 1); |
382 | } |
423 | } |
383 | } |
424 | } |
384 | |
425 | |
385 | #if HAS_REGEX |
426 | #if HAS_REGEX |
386 | void |
427 | void |
… | |
… | |
665 | if (len <= 0) |
706 | if (len <= 0) |
666 | len = 1; /* ignore (don't skip) illegal character sequences */ |
707 | len = 1; /* ignore (don't skip) illegal character sequences */ |
667 | |
708 | |
668 | /* find the width in pixels of the next character */ |
709 | /* find the width in pixels of the next character */ |
669 | int cw = XmbTextEscapement (fontset, p, len); |
710 | int cw = XmbTextEscapement (fontset, p, len); |
670 | if (cw + w >= width) |
711 | if (cw + w > width - effect_x_space) |
671 | { |
712 | { |
672 | wrapped = 1; |
713 | wrapped = 1; |
673 | break; |
714 | break; |
674 | } |
715 | } |
675 | |
716 | |
… | |
… | |
1022 | e->fname = xstrdup (fname); |
1063 | e->fname = xstrdup (fname); |
1023 | if (openlog (e) == NULL) |
1064 | if (openlog (e) == NULL) |
1024 | perror (fname), exit (1); |
1065 | perror (fname), exit (1); |
1025 | |
1066 | |
1026 | l = strlen (desc); |
1067 | l = strlen (desc); |
|
|
1068 | /* HACK on this - width is in pixels now */ |
1027 | if (l > width - 2) /* must account for [ ] */ |
1069 | if (l > width - 2) /* must account for [ ] */ |
1028 | l = width - 2; |
1070 | l = width - 2; |
1029 | e->desc = xmalloc (l + 1); |
1071 | e->desc = xmalloc (l + 1); |
1030 | memcpy (e->desc, desc, l); |
1072 | memcpy (e->desc, desc, l); |
1031 | *(e->desc + l) = '\0'; |
1073 | *(e->desc + l) = '\0'; |
… | |
… | |
1051 | } |
1093 | } |
1052 | |
1094 | |
1053 | if (opt_partial && opt_whole) |
1095 | if (opt_partial && opt_whole) |
1054 | { |
1096 | { |
1055 | fprintf (stderr, "Specify at most one of -partial and -whole\n"); |
1097 | fprintf (stderr, "Specify at most one of -partial and -whole\n"); |
|
|
1098 | exit (1); |
|
|
1099 | } |
|
|
1100 | |
|
|
1101 | /* HACK this - do we want to allow both -shade and -outline? */ |
|
|
1102 | if (opt_shade && opt_outline) |
|
|
1103 | { |
|
|
1104 | fprintf (stderr, "Specify at most one of -shade and -outline\n"); |
1056 | exit (1); |
1105 | exit (1); |
1057 | } |
1106 | } |
1058 | |
1107 | |
1059 | if (opt_partial) |
1108 | if (opt_partial) |
1060 | /* if we specifically requested to see partial lines then don't insist on whole lines */ |
1109 | /* if we specifically requested to see partial lines then don't insist on whole lines */ |