Results 1 to 1 of 1
I am having trouble writing an Xlib application that displays a window. The most frustrating thing is that I've written applications like this before, and never had any problems. For ...
- 03-13-2009 #1Just Joined!
- Join Date
- Mar 2009
- Posts
- 20
Can't get Xlib window to display
I am having trouble writing an Xlib application that displays a window. The most frustrating thing is that I've written applications like this before, and never had any problems. For some reason I cannot get this program to work properly. I'm running KDE and when I launch the program, a "button" for the application will appear on the application panel, however, no window will display. It is possible to right click on the panel button and select the Close item which will successfully close the window.
The following is source code that when built will exhibit the behaviour described above:
What is needed so this program will successfully display a window?Code:#include <cstring> #include <X11/Xlib.h> #include <GL/glx.h> int main() { Display* display = ::XOpenDisplay(NULL); int glXAttributes[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_DEPTH_SIZE, 1, GLX_DOUBLEBUFFER, None }; XVisualInfo* visualInfo = ::glXChooseVisual(display, 0, glXAttributes); Window rootWindow = DefaultRootWindow(display); XSetWindowAttributes attributes; ::memset(&attributes, 0, sizeof(attributes)); attributes.colormap = ::XCreateColormap(display, rootWindow, visualInfo->visual, AllocNone); int x = 0; int y = 0; unsigned int width = 640; unsigned int height = 480; Window window = ::XCreateWindow(display, rootWindow, x, y, width, height, 0, visualInfo->depth, InputOutput, visualInfo->visual, CWBorderPixel | CWColormap, &attributes); ::XFree(visualInfo); Atom atom = ::XInternAtom(display, "WM_DELETE_WINDOW", False); ::XSetWMProtocols(display, window, &atom, 1); ::XSelectInput(display, window, ExposureMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask | StructureNotifyMask); ::XMapWindow(display, window); bool loop = true; XEvent event; do{ ::XNextEvent(display, &event); if(ClientMessage == event.type){ if(event.xclient.data.l[0] == static_cast<long>(atom)){ loop = false; } } }while(loop); ::XDeleteProperty(display, window, atom); ::XDestroyWindow(display, window); ::XFlush(display); ::XCloseDisplay(display); return 0; }


Reply With Quote