Correction de pixmap2.c
/* pixmap d'arriere plan de fenetre */
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "fond1"
#include "fond0"
GC gc;
Display *display;
int screen, bascule = 1, prof;
Window win, subwin, root;
unsigned long white_pixel, black_pixel;
Pixmap fond1, fond0;
XSetWindowAttributes attributs;
unsigned long masque_valeur;
Colormap palette;
XColor red, navy, exact;
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, 100, 100, 5, black_pixel, white_pixel);
XSelectInput (display, win, ExposureMask);
XStoreName (display, win, "pixmap2");
palette = DefaultColormap(display, screen);
prof = DefaultDepth(display, screen);
if (XAllocNamedColor(display, palette, "navy", &navy, &exact) == 0)
exit(2);
if (XAllocNamedColor(display, palette, "red", &red, &exact) == 0)
exit(3);
fond1 = XCreatePixmapFromBitmapData(display, win, fond1_bits, fond1_width,
fond1_height, red.pixel, navy.pixel, prof);
fond0 = XCreatePixmapFromBitmapData(display, win, fond0_bits, fond0_width,
fond0_height, navy.pixel, red.pixel, prof );
masque_valeur = 0;
attributs.background_pixel = fond1;
masque_valeur |= CWBackPixmap;
attributs.border_pixel = black_pixel;
masque_valeur |= CWBorderPixel;
attributs.event_mask = ButtonPressMask;
masque_valeur |= CWEventMask;
subwin = XCreateWindow (display, win, 10, 20, 30, 40, 5, CopyFromParent,
InputOutput, CopyFromParent, masque_valeur, &attributs);
XMapWindow (display, win);
XMapSubwindows (display, win);
for (;;) {
XEvent ev;
XNextEvent (display, &ev);
switch (ev.type) {
case Expose :
break;
case ButtonPress :
if (ev.xbutton.window == subwin) {
if ((bascule = (bascule + 1) % 2) == 0)
XSetWindowBackgroundPixmap(display, subwin, fond0);
else
XSetWindowBackgroundPixmap(display, subwin, fond1);
XClearWindow(display, subwin);
}
break;
default :
break;
}
}
}