here something sound like tricky for me, actualy i'm using Xlib to draw some windows. One is for plotting some 2D results in a image, so this one is drawn only when all calculus are done. another one is a simple window wich says, "calculus in process".
but the problem ams, I don't see the "show me the simple window "calculus in process"" during the calculus, I just see it one instant and disappears just when the image of results of calculs is shown. I try to put some sleep()
but that doesn't solve the problem. What kind of stuff can cause such problem ? I already met such problem during my C++ course, at that time I worked on console, I never found the reason of such problem.
Can somebody give me some explanation and tips to help me to deal with it like a boss ?
here a piece of sh.. of my code :
switch(e.type/*xlibevent*/){
.
.
.
case KeyRelease :
switch(keyRelease()){ // keyRelease just recognize wich key was released
.
.
. // w3w1 = window "calculus in process"
case 3 : w3w1.switcher(); doCalculus(&w1); w3w1.switcher(); break;
.
.
.
.
.
.
}
I just did a test, I swap doCalculus(&w1)
with sleep(3)
same result, I don't see my window "calculus in process"
there is the switcher()
corrected
void switcher(){
if(this->visible==0){
XMapWindow(dpy,this->window); // what I though before : has to map the window
// what I think now : request to map the window
XDrawString(dpy, this->window, this->gc, 10, 14, text.c_str(), text.length());
XFlush(dpy); // dats what missed, not sure that efficient to flush the dpy
// but I deal with the part of xlib I know, I will check further
// about that
visible=1;
}else{
XUnmapWindow(dpy,this->window);
XFlush(dpy); //...
visible=0;
}
Your main event loop is probably blocked by your calculation. Thus nothing can be displayed as long as you are busy computing. If you return to the X event loop at least once after displaying the temporary window it should appear (though it may not refresh properly because it won't respond to exposure events). The best solution is to run your calculations in another thread.
Your confusion about "why it doesn't wait to show me the simple window" is based on a misconception about how X clients work. There is more interaction between the client and the server (even to do simple things) than you might intuitively expect.