#include #include #include #include char *wname = "xline"; #define XDIM 300 #define YDIM 300 XPoint points[4] = { { 74, 31029}, { 74, 177}, { 108, 143}, { 108, -384}, }; main(int ac, char **av) { Display *disp; Window wind; int scr, y; unsigned long fg, bg; GC gc, gcc; XEvent xev; XSizeHints hints; XWMHints whints; XGCValues gcv; Pixmap pix; if (ac > 1) { y = atoi(av[1]); if (y != 0) points[0].y = y; } disp = XOpenDisplay(NULL); if( disp == NULL ){ fprintf(stderr, "couldn't open display\n"); exit(1); } scr = DefaultScreen(disp); bg = WhitePixel(disp, scr); fg = BlackPixel(disp, scr); hints.width = XDIM; hints.height = YDIM; hints.flags = USSize; wind = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, XDIM, YDIM, 0, bg, bg); XSetStandardProperties(disp, wind, wname, wname, None, av, ac, &hints); whints.flags = InputHint; whints.input = 1; XSetWMHints(disp, wind, &whints); gcv.foreground = bg; gcc = XCreateGC(disp, wind, GCForeground, &gcv); pix = XCreatePixmap(disp, wind, XDIM, YDIM, DefaultDepth(disp, scr)); XFillRectangle(disp, pix, gcc, 0, 0, XDIM, YDIM); gcv.foreground = fg; gcv.line_width = 2; gc = XCreateGC(disp, wind, GCForeground | GCLineWidth, &gcv); XDrawLines(disp, pix, gc, points, 4, CoordModeOrigin); XSelectInput(disp, wind, ExposureMask); XMapRaised(disp, wind); for (;;) { XNextEvent(disp, &xev); switch (xev.type) { case Expose: if (xev.xexpose.count == 0) XCopyArea(disp, pix, wind, gcc, 0, 0, XDIM, YDIM, 0, 0); break; } } XFreeGC(disp, gc); XDestroyWindow(disp, wind); XCloseDisplay(disp); exit(0); }