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
|
#include <iostream>
#include <cstdlib>
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
GC gc;
Display *display;
int screen;
Window win, subwin, root;
unsigned long white_pixel, black_pixel;
using namespace std;
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, ExposureMask | ButtonPressMask);
XStoreName (display, win, "subwin");
subwin = XCreateSimpleWindow (display, win,
50, 30, 100, 30, 2, black_pixel, white_pixel);
XSelectInput (display, subwin, ExposureMask | ButtonPressMask);
XMapWindow (display, win);
XMapWindow (display, subwin);
for (;;) {
XEvent ev;
XNextEvent (display, &ev);
switch (ev.type) {
case Expose :
if (ev.xexpose.window == win) {
cout << "drawing win" << endl;
XDrawString (display, win, gc, 10, 10, "Bienvenue sous win !", 20);
XFlush(display);
sleep(2);
}
if (ev.xexpose.window == subwin) {
cout << "drawing subwin" << endl;
XDrawString (display, subwin, gc, 10, 10, "sous subwin", 11);
XFlush(display);
sleep(2);
}
break;
case ButtonPress :
if (ev.xbutton.window == win)
XDrawString (display, win, gc, ev.xbutton.x, ev.xbutton.y, "ici", 3);
if (ev.xbutton.window == subwin)
XDrawString (display, subwin, gc, ev.xbutton.x, ev.xbutton.y, "la", 2);
break;
default :
break;
}
}
} |
Partager