Bonjour tout le monde,

Je suis débutant sur la programmation X11 et je suis en train de faire un projet sur ça.

Voici mon petit bout de code qui affiche tout simplement une fenêtre avec un boucle pour gérer les événements (la première partie est réservée à la connection au framebuffer pour avoir la résolution d'écran si je travaille sur Embedded Linux):

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
 
#include <unistd.h>
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <stropts.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
 
int main (int argc, char **argv)
 
  {
 
 
	/* Connection to Framebuffer to known the full-sreen size if we don't have X11 - For Linux Embedded ***************************************************************************/
 
	int fbfd = 0;
        struct fb_var_screeninfo vinfo;
        struct fb_fix_screeninfo finfo;
 
        // Open the file for reading and writing
 
        fbfd = open("/dev/fb0", O_RDWR);
        if (!fbfd) {
            printf("Error: cannot open framebuffer device.\n");
            exit(1);
        }
 
        //printf("The framebuffer device was opened successfully.\n");
 
        // Get fixed screen information
 
        if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) {
            printf("Error reading fixed information.\n");
            exit(2);
        }
 
        // Get variable screen information
 
 
        if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
            printf("Error reading variable information.\n");
            exit(3);
        }
 
 
	//printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);
 
	// xinfo.xres = width and yinfo.xres = height
 
	/// X11's operations **********************************************************
 
    	Display *display;
    	Window fenetre, root;
    	int ecran;
    	unsigned long black, white;
    	unsigned int width=500, height=350;    
 
    	// Connection au serveur X
    	display = XOpenDisplay (NULL);
 
    	// Preparation des variables pour XCreateSimpleWindow
 
    	ecran = XDefaultScreen (display);
    	root = XRootWindow (display, ecran);
    	black = XBlackPixel (display, ecran);
    	white = XWhitePixel (display, ecran);
 
    	// Creation de la fenetre
    	fenetre = XCreateSimpleWindow (display, root, 0, 0, DisplayWidth(display,0)/2, DisplayHeight(display,0)/2, 0, 10, black);
 
    	// Selection des evenements a gerer
        //XSelectInput (display, fenetre, StructureNotifyMask);
 
    	// Change le titre de la fenêtre
    	XStoreName(display, fenetre, "X11 - Test");
 
    	// DisplayWidth(display,0) -> renvoit la largeur de l'ecran (résolution)
    	// DisplayHeight(display,0) -> renvoit la hauteur de l'ecran (résolution)
 
    	// Affiche la fenetre
    	XMapWindow (display, fenetre);
 
    	// Boucle pour traiter les evenements
 
	XEvent ev;
        while (ev.type != DestroyNotify)
    	{   
    	  if (XPending (display) > 0)
    	   {
 
    	   XNextEvent(display, &ev);
    	   switch  (ev.type)
    	   {
              default:
    	        break;
            }   
    	    } 
    	 }
 
	return (fenetre);
  }
Mon problème c'est qu'après avoir créer cette fenêtre, j'arrive plus à le détruire en utilisant la fonction XDestroyWindow(), même si que ma fenêtre attend un seul événement : DestroyNotify.

J'ai pensé à écrit un autre programme qui se connecte avec le serveur X et puis envoit le signal "DestroyNotify" à cette fenêtre là mais j'arrive pas non plus.

Donc, je voudrais demander si quelqu'un peut m'aider à résoudre ce problème.

La solution préférence, c'est d'écrire deux fonctions dans une seule programme, l'une qui crée la fenêtre puis l'autre qui le détruit après. Peut-etre il y a un sleep de 5 second entre ces deux fonctions pour voir comment ca fonctionne sur l'écran.

Votre aide est hautement bienvenue.

Merci beaucoup !!!

bsp_epoto.