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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
#include <cstdlib>
#include <iostream>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
//Dessin de la fenêtre
void DrawContenu(Display *dpy, Drawable src, Window win, GC gc, int width, int height){
//XClearWindow(dpy, win);
XCopyArea(dpy, src, win, gc, 0, 0, width, height, 0, 0) //On copie une zone de la fenêtre listée sur la fenêtre donnée
XFlush(dpy); //On force l'affichage de dpy
}
void EnumWin(GC gc, Window win){
//Variables pour les gestions de l'affichage...
Display *display;
Window root;
int ecran, je;
//Variables pour le listing
Window root_return, parent_return, *children_return=NULL, tmp;
uint nchildren_return=0;
display = XOpenDisplay (NULL); //Display par défaut
ecran = DefaultScreen (display); //Ecran par défaut
root = XRootWindow (display, ecran); //Fenêtre principale
//system("clear"); //Pour faire joli...
//On liste les fenêtres...
std::cout << "Appel XQueryTree: "
<< XQueryTree(display, root, &root_return, &parent_return, &children_return, &nchildren_return)
<< std::endl;
je=0;
if(children_return == NULL) printf("Tatare");
else{
tmp=children_return[0]; //On se positionne sur la première fenêtre fille
char *name;
int status;
XWindowAttributes winattributes; //infos de la fenêtre
for(uint i=0; i<nchildren_return; i++, tmp=children_return[i]){ //Pour chaque enfant...
XGetWindowAttributes(display, tmp, &winattributes); //Attributs de la fenêtre...
if(winattributes.map_state != IsViewable) continue; //Si elle n'est pas affichable, on passe au suivant
status = XFetchName(display, tmp, &name); //Nom de la fenêtre
if(status !=0 && status != BadWindow){ //Si la fenêtre est valable
std::cout << "-" << (unsigned int)tmp << " " << name << " : "<< winattributes.depth << std::endl; //On affiche des infos dessus
//display = XOpenDisplay (NULL);
if(*name == 'm') DrawContenu(display, tmp, win, gc, 400, 400);
XFree(name); //Libération du nom
} //fin de si fenêtre valable
} //fin de la boucle
} //fin du else
}
//Dessin de la fenêtre
void redessiner_fenetre (GC gc, Window win)
{
EnumWin(gc, win);
return;
}
int main ()
{
Display *display;
Window root, win;
GC gc;
int ecran;
XGCValues ValeursGC;
// Pixmap pixmap;
// Screen screen;
/* Connection au serveur X */
display = XOpenDisplay (NULL);
/* Preparation des variables pour XCreateSimpleWindow */
ecran = DefaultScreen (display);
root = XRootWindow (display, ecran);
gc = DefaultGC(display, ecran);
//création de la fenêtre
win = XCreateSimpleWindow(display, root, 100, 100, 700, 700, 5, XBlackPixel(display, ecran), XWhitePixel(display, ecran));
ValeursGC.foreground = BlackPixel(display, ecran);
ValeursGC.line_width = 4;
gc = XCreateGC(display, win,
GCForeground | GCLineWidth, &ValeursGC);
XStoreName(display, win, "Xlib Copie..."); //Titre de la fenêtre
//EnumWin(gc, win); //Enumération des fenêtres
XMapWindow(display, win); //Affichage
XSelectInput (display, win, ExposureMask); //Callback
XSelectInput (display, win, VisibilityChangeMask); //Callback
XSelectInput (display, win, PointerMotionMask); //Callback
//boucle
while(1){
if (XPending (display) > 0)
{
XEvent ev;
XNextEvent(display, &ev);
switch (ev.type)
{
case Expose:
redessiner_fenetre (gc, win);
break;
case VisibilityNotify :
redessiner_fenetre (gc, win);
break;
case MotionNotify :
redessiner_fenetre(gc, win);
default:
break;
}
}
}
return 0;
} |
Partager