/* Press LMB to draw a rect with solid line: visible Press RMB to draw a rect with dash line: invisible */ #include #include #define WINW 1000 #define WINH 800 int main(int argc, char **argv) { Display *dpy; Window win; XSetWindowAttributes attr; XEvent event; int depth, screen; Visual *visual; XSizeHints hints; XWMHints wmhints; dpy = XOpenDisplay(0); screen = DefaultScreen(dpy); depth = DefaultDepth(dpy, screen); visual=DefaultVisual(dpy, screen); attr.background_pixel = 0; attr.backing_store = WhenMapped; win = XCreateWindow(dpy, DefaultRootWindow(dpy), 0, 0, WINW, WINH, 0, depth, InputOutput, visual, CWBackPixel|CWBackingStore, &attr); hints.flags=PPosition; hints.x=100; hints.y=100; XSetNormalHints(dpy, win, &hints); wmhints.flags=StateHint|InputHint; wmhints.initial_state=NormalState; wmhints.input=True; XSetWMHints(dpy, win, &wmhints); XSelectInput(dpy, win, ButtonPressMask|PropertyChangeMask); XSelectInput(dpy, DefaultRootWindow(dpy), PropertyChangeMask); XMapRaised(dpy, win); XSync(dpy, False); XGCValues gcv; gcv.line_width=1; gcv.foreground=0xffffffff; gcv.dashes = 10; GC gc = XCreateGC(dpy, win, GCLineWidth | GCForeground | GCDashList, &gcv); XFlush(dpy); while (1) { short x1 = 330, y1 = -15000; #ifndef BREAK short x2 = 530, y2 = 31340; #else short x2 = 530, y2 = 31341; #endif XNextEvent(dpy, &event); if (event.type==ButtonPress) { XClearWindow(dpy, win); if (event.xbutton.button==1) /* LMB */ { gcv.line_style = LineSolid; } else { gcv.line_style = LineOnOffDash; } XChangeGC(dpy, gc, GCLineStyle, &gcv); XDrawLine(dpy, win, gc, x1, y1, x2, y2); XFlush(dpy); } } return 0; }