11/11/06 23:07:33.73 .net
#include <X11/Xlib.h>
Display *dpy;
Window w;
GC gc;
void init_window() {
int screen;
unsigned long black, white;
dpy = XOpenDisplay(NULL);
screen = DefaultScreen(dpy);
white = WhitePixel(dpy, screen);
black = BlackPixel(dpy, screen);
w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 100, 100, 0, white, white);
gc = XCreateGC(dpy, w, 0, NULL);
XSetForeground(dpy, gc, black);
}
void pset(int x, int y) {
XDrawPoint(dpy, w, gc, x, y);
}
int main() {
XEvent evt;Atom atom;
init_window();
atom = XInternAtom(dpy, "WM_DELETE_WINDOW", 1);
XSetWMProtocols(dpy, w, &atom, 1);
XSelectInput(dpy, w, ExposureMask);XMapWindow(dpy, w);
while ( 1 ) {XNextEvent(dpy, &evt);
switch ( evt.type ) {
case Expose:
pset(3, 3);break;
case ClientMessage:
if ( evt.xclient.data.l[0] == atom ) {
XFreeGC(dpy, gc);XDestroyWindow(dpy, w);
XCloseDisplay(dpy);return 0;}}}}