/* couper.c */
/* mecanisme couper-coller : couper */
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/keysym.h>
GC gc;
Display *display;
int screen;
Window win, root;
unsigned long white_pixel, black_pixel;
int nbre, pos=0;
char chaine[20], buf[80];
KeySym touche;
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, 90, 2, black_pixel, white_pixel);
XSelectInput (display, win, ExposureMask | KeyPressMask | ButtonPressMask);
XStoreName (display, win, "couper");
XMapWindow (display, win);
for (;;) {
XEvent ev;
XNextEvent (display, &ev);
switch (ev.type) {
case Expose :
XDrawString (display, win, gc, 10, 30, "tapez un texte", 14);
XDrawString (display, win, gc, 10, 50, "cliquez pour couper", 19);
break;
case KeyPress :
nbre = XLookupString(&ev, chaine, 20, &touche, 0);
if (touche==XK_space)
buf[pos++]=' ';
else
buf[pos++]=chaine[0];
XClearWindow (display, win);
XDrawString(display, win, gc, 10, 70, buf, pos);
break;
case ButtonPress :
XStoreBytes(display, buf, pos);
pos=0;
XClearWindow (display, win);
XDrawString (display, win, gc, 10, 30, "tapez un texte", 14);
XDrawString (display, win, gc, 10, 50, "cliquez pour couper", 19);
break;
default :
break;
}
}
}
XStoreBytes range les caractères dans le "presse-papier", c'est à dire la propriété XA_CUT_BUFFER0 de la fenêtre racine.
| programme suivant | compléments | index général | fonctions de la XLib | événements | types dans XLib |