For a while now I was playing with XWindows programming on Suse 9.2 and everything was going well. I recently got a copy of the new Debian release (Sarge) and figured I'd try it on there. The program doesn't work. No windows are ever shown.
What appears to be happening is that the XNextEvent() function is never returning. I've copied the code that I'm using to show the windows into a small test program and it works just fine, but in the class everything stops at XNextEvent().
Here's the code I'm using to create the windows.
This block has all teh class variables used:
This block is in the class initialization function (called by thread 1)Code:Colormap ccmpColorMap; Display *cdisDisplay; int ciScreenNum; Screen *cscrScreenPtr; Colormap ccmpColorMap; Window Handle; //This is actually in a structure
This block is in a CreateWindow function (called by thread 1)Code:XInitThreads(); cdisDisplay = XOpenDisplay(NULL); if (cdisDisplay == NULL) {//Failed to connect to an X Server printf("\nFailed to connect to the display\n"); return; } else { //printf("\nConnected to server!\n"); ciScreenNum = DefaultScreen(cdisDisplay); cscrScreenPtr = DefaultScreenOfDisplay(cdisDisplay); ccmpColorMap = XDefaultColormap(cdisDisplay, ciScreenNum); }
And finally is the event loop (called by thread 2)Code:XWMHints *xwmhHints; XClassHint *xchClass; XTextProperty xtpWinName, xtpIconName; XSizeHints *xshSize; char *pcIconName = "", *pcWinName = "Window Name?", *pcProgName = ""; Atom aProt; Handle = XCreateSimpleWindow(cdisDisplay, RootWindow(cdisDisplay, ciScreenNum), 0, 0, 200, 200, 0, BlackPixel(cdisDisplay, ciScreenNum), WhitePixel(cdisDisplay, ciScreenNum)); //Allocate space for the hints xshSize = XAllocSizeHints(); xwmhHints = XAllocWMHints(); xchClass = XAllocClassHint(); xshSize->flags = PPosition | PSize; XStringListToTextProperty(&pcWinName, 1, &xtpWinName); XStringListToTextProperty(&pcIconName, 1, &xtpIconName); xwmhHints->initial_state = NormalState; xwmhHints->input = True; xwmhHints->flags = StateHint | InputHint; xchClass->res_name = pcProgName; xchClass->res_class = ""; XSetWMProperties(cdisDisplay, Handle, &xtpWinName, &xtpIconName, 0, 0, xshSize, xwmhHints, xchClass); //request the close event from the window manager aProt = XInternAtom(cdisDisplay, "WM_DELETE_WINDOW", True); XSetWMProtocols(cdisDisplay, Handle, &aProt, 1); XSelectInput(cdisDisplay, Handle, ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | StructureNotifyMask | EnterWindowMask | LeaveWindowMask); XMapWindow(cdisDisplay, Handle); //Show the window
There was more in the event loop before, but I've been stripping it out thinking there was a problem after the XNextEvent() call.Code:XEvent xeEvent; while (1) { XNextEvent(cdisDisplay, &xeEvent); }
The program is intended to be multithreaded, one thread setting up the window, and a second handling the events. I've made the test program work in that type of setup too.
I've checked the return values for the X functions, none appear to be returning an error. Though the man pages for them don't list what a success value should be so not sure I can guarentee no errors.
As I said when I run this with just this code in a test program everything works fine, its only when I put it in my full program do problems occur.
Any ideas what I should look at to find the error? I just don't get why it runs great on Suse, but not on Debian.



LinkBack URL
About LinkBacks


