Correction de copy.c
/* copy.c */
/* copie entre 2 sous-fenetres */
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
GC gc;
Display *display;
int screen, i;
Window win, subwin[2], root;
unsigned long white_pixel, black_pixel;
main() {
if ((display = XOpenDisplay ("")) == NULL) {
fprintf (stderr, "Can't open Display\n");
exit (1);
}
gc = DefaultGC (display, screen);
screen = DefaultScreen (display);
root = RootWindow (display, screen);
white_pixel = WhitePixel (display, screen);
black_pixel = BlackPixel (display, screen);
win = XCreateSimpleWindow (display, root,
0, 0, 430, 200, 5, black_pixel, white_pixel);
XStoreName (display, win, "copy");
XMapWindow (display, win);
for (i=0; i<2; ++i) {
subwin[i] = XCreateSimpleWindow (display, win, 10+i*210, 10, 200, 180, 2,
black_pixel, white_pixel);
XSelectInput (display, subwin[i], ButtonPressMask);
XMapWindow (display, subwin[i]);
}
for (;;) {
XEvent ev;
XNextEvent (display, &ev);
switch (ev.type) {
case ButtonPress :
if (ev.xbutton.button == Button1) {
if (ev.xbutton.window == subwin[0])
XDrawString (display, subwin[0], gc,
ev.xbutton.x, ev.xbutton.y, "ici", 3);
if (ev.xbutton.window == subwin[1])
XDrawString (display, subwin[1], gc,
ev.xbutton.x, ev.xbutton.y, "la", 2);
} else if (ev.xbutton.button == Button3)
XCopyArea (display, subwin[0], subwin[1], gc, 0, 0, 200, 180, 0, 0);
break;
default :
break;
}
}
}