Reputation: 181
I am creating library for Xlib (like gtk/qt, but simplified). And i don't see window at my desktop. GDB says nothing. What i must do to fix this bug? Already tried to move display declaration to main function. Used -g flag as compiling (to check with GDB). And no window! Seriously, it's awesome glitch!
FXL++ library:
#include <iostream>
#include <X11/Xlib.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
using namespace std;
class fxlpp{
public:
void init(){
disp = XOpenDisplay(NULL);
if(disp == NULL){ //error 1 if can't open display
cerr << "Can't open display" << endl;
exit(1);
}
screen = DefaultScreen(disp);
}
void mkWin(int winID, int x1, int y1, unsigned x2, unsigned y2){
win[winID] = XCreateSimpleWindow(disp, RootWindow(disp, screen), x1, y1, x2, y2, 0, BlackPixel(disp, screen), WhitePixel(disp, screen));
XSelectInput(disp, win[winID], ExposureMask | KeyPressMask);
XMapWindow(disp, win[winID]);
}
void mkCWin(int cWinID, int pWinID, int x1, int y1, int x2, int y2){
cWin[pWinID][cWinID] = XCreateSimpleWindow(disp, win[pWinID], x1, y1, x2, y2, 1, BlackPixel(disp, screen), WhitePixel(disp, screen));
XSelectInput(disp, cWin[pWinID][cWinID], ExposureMask | KeyPressMask);
XMapWindow(disp, cWin[pWinID][cWinID]);
}
protected:
Display *disp; //declare display pointer
int screen; //declare display num integer
Window win[129]; //declare window
Window cWin[129][129]; //declare child win array
XEvent event; //declare event handler
};
Code to test library:
#include <iostream>
#include "fxlpp.hpp"
using namespace std;
int main(){
class fxlpp fxlpp;
fxlpp.init();
fxlpp.mkWin(1, 100, 100, 500, 300);
sleep(2);
return 0;
}
Upvotes: 2
Views: 1613
Reputation: 785
Although event loop is important most times, in this simple case you just need to call XFlush()
after drawing.
Upvotes: 0
Reputation: 3106
As I wrote before, there's a lot more to X11 than just create a window, paint some lines on it and expect output. You must setup the X event loop to receive events, handle at a minumum exposure events, but also keyboard, mouse, etc. in the proper way. So I'm afraid it's not a bug, it's a design flaw in your program.
For a short tutorial, see here.
Upvotes: 2