… | |
… | |
144 | XColor Color; |
144 | XColor Color; |
145 | XWindowAttributes Attributes; |
145 | XWindowAttributes Attributes; |
146 | |
146 | |
147 | XGetWindowAttributes(disp, root, &Attributes); |
147 | XGetWindowAttributes(disp, root, &Attributes); |
148 | Color.pixel = 0; |
148 | Color.pixel = 0; |
|
|
149 | |
149 | if (!XParseColor(disp, Attributes.colormap, ColorName, &Color)) |
150 | if (!XParseColor(disp, Attributes.colormap, ColorName, &Color)) |
150 | fprintf(stderr, "can't parse %s\n", ColorName); |
151 | fprintf(stderr, "can't parse %s\n", ColorName); |
151 | else if (!XAllocColor(disp, Attributes.colormap, &Color)) |
152 | else if (!XAllocColor(disp, Attributes.colormap, &Color)) |
152 | fprintf(stderr, "can't allocate %s\n", ColorName); |
153 | fprintf(stderr, "can't allocate %s\n", ColorName); |
|
|
154 | |
153 | return Color.pixel; |
155 | return Color.pixel; |
154 | } |
156 | } |
155 | |
157 | |
156 | static Window root_window (Display *display, int screen_number) |
158 | static Window root_window (Display *display, int screen_number) |
157 | { |
159 | { |
158 | Atom __SWM_VROOT = XInternAtom (display, "__SWM_VROOT", False); |
160 | Atom __SWM_VROOT = XInternAtom (display, "__SWM_VROOT", False); |
159 | Window real_root_window = RootWindow (display, screen_number); |
161 | Window real_root_window = RootWindow (display, screen_number); |
|
|
162 | |
|
|
163 | if (root) /* root window set via option */ |
|
|
164 | return root; |
160 | |
165 | |
161 | if (__SWM_VROOT != None) |
166 | if (__SWM_VROOT != None) |
162 | { |
167 | { |
163 | Window unused, *windows; |
168 | Window unused, *windows; |
164 | unsigned int count; |
169 | unsigned int count; |
… | |
… | |
225 | exit(1); |
230 | exit(1); |
226 | } |
231 | } |
227 | screen = DefaultScreen(disp); |
232 | screen = DefaultScreen(disp); |
228 | ScreenHeight = DisplayHeight(disp, screen); |
233 | ScreenHeight = DisplayHeight(disp, screen); |
229 | ScreenWidth = DisplayWidth(disp, screen); |
234 | ScreenWidth = DisplayWidth(disp, screen); |
|
|
235 | |
230 | root = root_window (disp, screen); |
236 | root = root_window (disp, screen); |
|
|
237 | |
231 | gcm = GCBackground; |
238 | gcm = GCBackground; |
232 | gcv.graphics_exposures = True; |
239 | gcv.graphics_exposures = True; |
233 | WinGC = XCreateGC(disp, root, gcm, &gcv); |
240 | WinGC = XCreateGC(disp, root, gcm, &gcv); |
234 | XMapWindow(disp, root); |
241 | XMapWindow(disp, root); |
235 | XSetForeground(disp, WinGC, GetColor(DEF_COLOR)); |
242 | XSetForeground(disp, WinGC, GetColor(DEF_COLOR)); |
… | |
… | |
241 | font_descent = info->max_bounds.descent; |
248 | font_descent = info->max_bounds.descent; |
242 | font_height = info->max_bounds.ascent + font_descent; |
249 | font_height = info->max_bounds.ascent + font_descent; |
243 | |
250 | |
244 | w = width * font_width; |
251 | w = width * font_width; |
245 | h = listlen * font_height; |
252 | h = listlen * font_height; |
|
|
253 | |
246 | if (geom_mask & XNegative) |
254 | if (geom_mask & XNegative) |
247 | win_x = win_x + ScreenWidth - w; |
255 | win_x = win_x + ScreenWidth - w; |
248 | if (geom_mask & YNegative) |
256 | if (geom_mask & YNegative) |
249 | win_y = win_y + ScreenHeight - h; |
257 | win_y = win_y + ScreenHeight - h; |
250 | |
258 | |
… | |
… | |
632 | /* just a dummy to get the color lookups right */ |
640 | /* just a dummy to get the color lookups right */ |
633 | geom_mask = NoValue; |
641 | geom_mask = NoValue; |
634 | InitWindow(); |
642 | InitWindow(); |
635 | |
643 | |
636 | for (i = 1; i < argc; i++) { |
644 | for (i = 1; i < argc; i++) { |
|
|
645 | const char *arg = argv[i]; |
|
|
646 | |
637 | if (argv[i][0] == '-' && argv[i][1] != '\0' && argv[i][1] != ',') { |
647 | if (arg[0] == '-' && arg[1] != '\0' && arg[1] != ',') { |
|
|
648 | if (arg[1] == '-') |
|
|
649 | arg++; |
|
|
650 | |
638 | if (!strcmp(argv[i], "--?") || |
651 | if (!strcmp(arg, "-?") || |
639 | !strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) |
652 | !strcmp(arg, "-help") || !strcmp(arg, "-h")) |
640 | display_help(argv[0]); |
653 | display_help(argv[0]); |
641 | else if (!strcmp(argv[i], "-V")) |
654 | else if (!strcmp(arg, "-V")) |
642 | display_version(); |
655 | display_version(); |
643 | else if (!strcmp(argv[i], "-g") || !strcmp(argv[i], "-geometry")) |
656 | else if (!strcmp(arg, "-g") || !strcmp(arg, "-geometry")) |
644 | geom_mask = XParseGeometry(argv[++i], |
657 | geom_mask = XParseGeometry(argv[++i], |
645 | &win_x, &win_y, &width, &listlen); |
658 | &win_x, &win_y, &width, &listlen); |
646 | else if (!strcmp(argv[i], "-display")) |
659 | else if (!strcmp(arg, "-display")) |
647 | dispname = argv[++i]; |
660 | dispname = argv[++i]; |
648 | else if (!strcmp(argv[i], "-font") || !strcmp(argv[i], "-fn")) |
661 | else if (!strcmp(arg, "-font") || !strcmp(arg, "-fn")) |
649 | fontname = argv[++i]; |
662 | fontname = argv[++i]; |
650 | #if HAS_REGEX |
663 | #if HAS_REGEX |
651 | else if (!strcmp(argv[i], "-t")) |
664 | else if (!strcmp(arg, "-t")) |
652 | transform = argv[++i]; |
665 | transform = argv[++i]; |
653 | #endif |
666 | #endif |
654 | else if (!strcmp(argv[i], "-fork") || !strcmp(argv[i], "-f")) |
667 | else if (!strcmp(arg, "-fork") || !strcmp(arg, "-f")) |
655 | opt_daemonize = 1; |
668 | opt_daemonize = 1; |
656 | else if (!strcmp(argv[i], "-reload")) { |
669 | else if (!strcmp(arg, "-reload")) { |
657 | reload = atoi(argv[++i]); |
670 | reload = atoi(argv[++i]); |
658 | command = argv[++i]; |
671 | command = argv[++i]; |
659 | } |
672 | } |
660 | else if (!strcmp(argv[i], "-shade")) |
673 | else if (!strcmp(arg, "-shade")) |
661 | opt_shade = 1; |
674 | opt_shade = 1; |
662 | else if (!strcmp(argv[i], "-frame")) |
675 | else if (!strcmp(arg, "-frame")) |
663 | opt_frame = 1; |
676 | opt_frame = 1; |
664 | else if (!strcmp(argv[i], "-no-filename")) |
677 | else if (!strcmp(arg, "-no-filename")) |
665 | opt_nofilename = 1; |
678 | opt_nofilename = 1; |
666 | else if (!strcmp(argv[i], "-reverse")) |
679 | else if (!strcmp(arg, "-reverse")) |
667 | opt_reverse = 1; |
680 | opt_reverse = 1; |
668 | else if (!strcmp(argv[i], "-color")) |
681 | else if (!strcmp(arg, "-color")) |
669 | def_color = argv[++i]; |
682 | def_color = argv[++i]; |
670 | else if (!strcmp(argv[i], "-noinitial")) |
683 | else if (!strcmp(arg, "-noinitial")) |
671 | opt_noinitial = 1; |
684 | opt_noinitial = 1; |
|
|
685 | else if (!strcmp(arg, "-id")) |
|
|
686 | root = atoi (argv[++i]); |
672 | else if (!strcmp(argv[i], "-interval") || !strcmp(argv[i], "-i")) { |
687 | else if (!strcmp(arg, "-interval") || !strcmp(arg, "-i")) { |
673 | double iv = atof(argv[++i]); |
688 | double iv = atof(argv[++i]); |
674 | |
689 | |
675 | interval.tv_sec = (int) iv; |
690 | interval.tv_sec = (int) iv; |
676 | interval.tv_usec = (iv - interval.tv_sec) * 1e6; |
691 | interval.tv_usec = (iv - interval.tv_sec) * 1e6; |
677 | } else { |
692 | } else { |
678 | fprintf(stderr, "Unknown option '%s'.\n" |
693 | fprintf(stderr, "Unknown option '%s'.\n" |
679 | "Try --help for more information.\n", argv[i]); |
694 | "Try --help for more information.\n", arg); |
680 | exit(1); |
695 | exit(1); |
681 | } |
696 | } |
682 | } else { /* it must be a filename */ |
697 | } else { /* it must be a filename */ |
683 | struct logfile_entry *e; |
698 | struct logfile_entry *e; |
684 | const char *fname, *desc, *fcolor = def_color; |
699 | const char *fname, *desc, *fcolor = def_color; |
685 | char *p; |
700 | char *p; |
686 | |
701 | |
687 | /* this is not foolproof yet (',' in filenames are not allowed) */ |
702 | /* this is not foolproof yet (',' in filenames are not allowed) */ |
688 | fname = desc = argv[i]; |
703 | fname = desc = arg; |
689 | if ((p = strchr(argv[i], ','))) { |
704 | if ((p = strchr(arg, ','))) { |
690 | *p = '\0'; |
705 | *p = '\0'; |
691 | fcolor = p + 1; |
706 | fcolor = p + 1; |
692 | |
707 | |
693 | if ((p = strchr(fcolor, ','))) { |
708 | if ((p = strchr(fcolor, ','))) { |
694 | *p = '\0'; |
709 | *p = '\0'; |
695 | desc = p + 1; |
710 | desc = p + 1; |
696 | } |
711 | } |
697 | } |
712 | } |
698 | |
713 | |
699 | e = xmalloc(sizeof(struct logfile_entry)); |
714 | e = xmalloc(sizeof(struct logfile_entry)); |
700 | if (argv[i][0] == '-' && argv[i][1] == '\0') { |
715 | if (arg[0] == '-' && arg[1] == '\0') { |
701 | if ((e->fp = fdopen(0, "r")) == NULL) |
716 | if ((e->fp = fdopen(0, "r")) == NULL) |
702 | perror("fdopen"), exit(1); |
717 | perror("fdopen"), exit(1); |
703 | if (fcntl(0, F_SETFL, O_NONBLOCK) < 0) |
718 | if (fcntl(0, F_SETFL, O_NONBLOCK) < 0) |
704 | perror("fcntl"), exit(1); |
719 | perror("fcntl"), exit(1); |
705 | e->fname = NULL; |
720 | e->fname = NULL; |
… | |
… | |
808 | "[file2[,color[,desc]] ...]\n", myname); |
823 | "[file2[,color[,desc]] ...]\n", myname); |
809 | printf(" -g | -geometry geometry -g WIDTHxHEIGHT+X+Y\n" |
824 | printf(" -g | -geometry geometry -g WIDTHxHEIGHT+X+Y\n" |
810 | " -color color use color $color as default\n" |
825 | " -color color use color $color as default\n" |
811 | " -reload sec command reload after $sec and run command\n" |
826 | " -reload sec command reload after $sec and run command\n" |
812 | " by default -- 3 mins\n" |
827 | " by default -- 3 mins\n" |
|
|
828 | " -id id window id to use instead of the root window\n" |
813 | " -font FONTSPEC (-fn) font to use\n" |
829 | " -font FONTSPEC (-fn) font to use\n" |
814 | " -f | -fork fork into background\n" |
830 | " -f | -fork fork into background\n" |
815 | " -reverse print new lines at the top\n" |
831 | " -reverse print new lines at the top\n" |
816 | " -shade add shading to font\n" |
832 | " -shade add shading to font\n" |
817 | " -noinitial don't display the last file lines on\n" |
833 | " -noinitial don't display the last file lines on\n" |