/* evenement de modification de taille*/
#include <stdio.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
GC gc;
Display *display;
int screen;
Window win, root;
unsigned long white_pixel, black_pixel;
char buf[30];
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, 300, 300, 5, black_pixel, white_pixel);
XSelectInput (display, win, StructureNotifyMask);
XStoreName (display, win, "configur");
XMapWindow (display, win);
for (;;) {
XEvent ev;
XNextEvent (display, &ev);
switch (ev.type) {
case ConfigureNotify :
XClearWindow (display, win);
XDrawString (display, win, gc, 5, 10, "geometrie de la fenetre :", 25);
sprintf(buf, "coin en x=%d y=%d", ev.xconfigure.x, ev.xconfigure.y);
XDrawString (display, win, gc, 5, 25, buf, strlen(buf));
sprintf(buf, "largeur=%d hauteur=%d", ev.xconfigure.width,
ev.xconfigure.height);
XDrawString (display, win, gc, 5, 40, buf, strlen(buf));
break;
default :
break;
}
}
}
Du fait que WM habille la fenêtre win dans une autre pour une meilleure ergonomie, la modification de position de win dans une fenêtre parente est soit prise en compte bizarement soit pas du tout.
| chapitre de l'exercice | index général | fonctions de la XLib | événements | types dans XLib |