#include #include #include #include #define GOOD 1 #define BIG_REQ 2 #define TOO_LONG 3 static Display *display; static Drawable d; static GC gc; static Window win; static int screen_num; static XPoint *points; static int npoints; static int mode; unsigned int display_width, display_height; unsigned int win_width, win_height; void prepare_points(int npoints) { int i, x, y; x = y = 10; points = (XPoint *)malloc(sizeof(XPoint)*npoints); if (points == NULL) { fprintf(stderr, "cannot allocate memory of %d XPoint\n", npoints); exit (1); } for (i = 0; i < npoints; i++) { (points+i)->x = x; (points+i)->y = y; x += 10; y += 10; if (x >= win_width) { x = 10; } if (y >= win_height) { y = 10; } } } void drawlines(Display* display, Window win, GC gc, int mode) { switch (mode) { case GOOD: npoints = (XMaxRequestSize(display) - 3)/2; prepare_points(npoints); break; case BIG_REQ: npoints = XExtendedMaxRequestSize(display); if (npoints) { npoints = ((npoints - 3) >> 2 ) << 2; prepare_points(npoints); } else { fprintf(stderr, "the server cannot support bigrequest extension\n"); return; } break; case TOO_LONG: npoints = XExtendedMaxRequestSize(display); if (npoints) { npoints = ((npoints + 3) >> 2 ) << 2; prepare_points(npoints); } else { fprintf(stderr, "the server cannot support bigrequest extension\n"); return; } break; } XDrawLines(display, win, gc, points, npoints, CoordModeOrigin); free(points); } void main(int argc, char* argv[]) { unsigned long valuemask = 0; XGCValues values; int win_border_width = 2; int mode = 0; char *display_name = getenv("DISPLAY"); display = XOpenDisplay(display_name); if (display == NULL) { fprintf(stderr, "%s: cannot connect to X server '%s'\n", argv[0], display_name); exit(1); } screen_num = DefaultScreen(display); display_width = DisplayWidth(display, screen_num); display_height = DisplayHeight(display, screen_num); win_width = (display_width / 2); win_height = (display_height / 2); printf("window width - '%d'; height - '%d'\n", win_width, win_height); win = XCreateSimpleWindow(display, RootWindow(display, screen_num), 0, 0, win_width, win_height, win_border_width, BlackPixel(display, screen_num), WhitePixel(display, screen_num)); XMapWindow(display, win); XFlush(display); gc = XCreateGC(display, win, valuemask, &values); if (gc < 0) { fprintf(stderr, "XCreateGC: \n"); } XSetForeground(display, gc, BlackPixel(display, screen_num)); XSetBackground(display, gc, WhitePixel(display, screen_num)); XSync(display, False); for (mode = GOOD; mode <= TOO_LONG; mode++) { drawlines(display, win, gc, mode); XFlush(display); sleep(5); XClearWindow(display, win); } XCloseDisplay(display); }