1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| /*
* xsimple : Affiche une chaine dans une fenetre X...
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _X_SENTINEL(x)
#include <X11/Xlib.h>
GC gc;
Display *display;
int screen;
Window win1, win2, root;
unsigned long white_pixel, black_pixel;
/*
* fonction associee a l'evenement EXPOSE
*/
void expose (Window win)
{
XDrawString (display, win, gc, 10, 30, "Hello, world !", 14);
}
/*
* programme principal
*/
int main(int ac, char **av) {
char *dpyn = NULL;
/* selection du display en ligne */
if (ac == 3) {
if (strcmp (&av[1][1], "display") == 0) {
dpyn = av[2];
}
else {
fprintf (stderr, "Usage: xsimple [-display display_name]\n");
exit (1);
}
}
if ((display = XOpenDisplay (dpyn)) == NULL) {
fprintf (stderr, "Can't open Display\n");
exit (1);
}
// XSetCloseDownMode(display, RetainTemporary /*RetainPermanent*/);
screen = DefaultScreen (display);
gc = DefaultGC (display, screen);
root = RootWindow (display, screen);
white_pixel = WhitePixel (display, screen);
black_pixel = BlackPixel (display, screen);
win1 = XCreateSimpleWindow (display, root, 0, 0, 200, 100, 2, black_pixel, white_pixel);
win2 = XCreateSimpleWindow (display, root, 300, 0, 200, 100, 2, black_pixel, white_pixel);
XSelectInput (display, win1, ExposureMask);
XSelectInput (display, win2, ExposureMask);
XStoreName (display, win1, "xsimple 1");
XMapWindow (display, win1);
XStoreName (display, win2, "xsimple 2");
XMapWindow (display, win2);
for (;;) {
XEvent ev;
XNextEvent (display, &ev);
switch (ev.type) {
case Expose :
expose (ev.xany.window);
break;
default :
break;
}
}
} |
Partager