Raise/Map and Focus a window: BadMatch error

Andrew Troschinetz ast at arlut.utexas.edu
Tue Dec 18 15:31:38 PST 2007


On Dec 18, 2007, at 4:16 PM, Peter Harris wrote:

> Andrew Troschinetz wrote:
>> After trying to use XPeekIfEvent() I had the same problem as before I
>> moved to XWindowEvent().
>>
>> Bool map_notify_for_window(Display *display, XEvent *e, XPointer
>> user_data) {
>> 	Window window = *reinterpret_cast<Window*> (user_data);
>
> I'm not all that familiar with C++, but it looks like you're
> dereferencing a user_data (which is a Window, not a pointer to a  
> Window).
>
>> 		XPeekIfEvent (display, &e, map_notify_for_window,
>> 			reinterpret_cast<XPointer> (window));

Good eye, I must apologize again for having to transcribe my actual  
code. My only machine here with internet access is a Mac and the  
program I'm writing/testing is on a classified RHEL4-AS machine so my  
only option is to transcribe the code as best I can. Sorry.

In the actual code I've got XPeekIfEvent (display, &e,  
map_notify_for_window, reinterpret_cast<XPointer> (&window));

So we've got a Window* being cast to a char* (XPointer) to conform to  
the required predicate signature for XPeekIfEvent()'s 3rd parameter,  
then map_notify_for_window() is casting the char* back to a Window*  
and dereferencing it to get the Window value. I'm pretty sure that's  
not the problem.

> Did you leave out a try/catch around this? I expect your
> map_notify_for_window to cause a core dump.

There's no exception code in our entire code base here.


The problem, as I see it, is that the predicate function I've defined  
returns True for some case which I just don't understand. Basically I  
want map_notify_for_window() to return True only for exactly the same  
event for which this loop will exit upon:

// This works as desired, but I have a bad feeling mucking with the  
event queue will cause me problems later.
XEvent e;
XMapRaised (display, window);
do {
	XWindowEvent (display, window, StructureNotifyMask, &e);
	// save the event in a vector
} while (e.type != MapNotify);
// use the vector to push all collected events back on to the event  
queue


In short:  *** I simply want to know when a window I've called  
XMapRaised() on has been mapped so that I can safely call  
XSetInputFocus() on it. ***

--
Andrew Troschinetz
Applied Research Laboratories



More information about the xorg mailing list