Correction de in_out2.c
/* in_out2.c */
/* evenement souris d'entree-sortie de fenetre */
#include <stdio.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
GC gc;
Display *display;
int screen;
Window win, subwin[2], subsubwin[2], root;
unsigned long white_pixel, black_pixel;
XSetWindowAttributes attrib;
int i;
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, 400, 400, 5, black_pixel, white_pixel);
XSelectInput (display, win, ExposureMask | ButtonPressMask |
EnterWindowMask | LeaveWindowMask );
XStoreName (display, win, "in_out2");
attrib.background_pixel = white_pixel ;
attrib.border_pixel = black_pixel ;
for (i = 0 ; i < 2 ; ++i ) {
subwin[i] = XCreateWindow (display, win, (i==0) ? 10:120, 30, 100, 100, 2,
CopyFromParent, InputOutput, CopyFromParent,
CWBackPixel | CWBorderPixel , &attrib);
XSelectInput (display, subwin[i], EnterWindowMask | LeaveWindowMask
| ExposureMask );
subsubwin[i] = XCreateWindow (display, subwin[i], 10, 40, 80, 50, 2,
CopyFromParent, InputOutput, CopyFromParent,
CWBackPixel | CWBorderPixel , &attrib);
XSelectInput (display, subsubwin[i], EnterWindowMask | LeaveWindowMask
| ExposureMask );
}
for (i = 0 ; i < 2 ; ++i )
XMapSubwindows (display, subwin[i]);
XMapSubwindows (display, win);
XMapWindow (display, win);
for (;;) {
XEvent ev;
char buf[40];
XNextEvent (display, &ev);
switch (ev.type) {
case Expose :
sprintf(buf, "w %ld", (int)ev.xexpose.window);
XDrawString (display, ev.xexpose.window, gc, 5, 10, buf, strlen(buf));
break;
case EnterNotify :
sprintf(buf, "evenement EnterNotify fenetre %ld\n",
(int)ev.xcrossing.window);
write(1, buf, strlen(buf));
break;
case LeaveNotify :
sprintf(buf, "evenement LeaveNotify fenetre %ld\n",
(int)ev.xcrossing.window);
write(1, buf, strlen(buf));
break;
default :
break;
}
}
}