Raise/Map and Focus a window: BadMatch error

Andrew Troschinetz ast at arlut.utexas.edu
Tue Dec 18 13:48:32 PST 2007


On Dec 18, 2007, at 2:14 PM, Andrew Troschinetz wrote:
> I got the function to work reliably using XWindowEvent() instead but I
> assume that eventually I want to move to XPeekIfEvent() so that I'm
> not arbitrarily pulling events off the queue.

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);
	if (e->type == MapNotify &&
		e->xmap.window == window &&
		e->xmap.display == display)
	{
		return True;
	}
	return False;
}

void map_raise_focus(Display *display, Window window) {
	XWindowAttributes atts;
	XGetWindowAttributes (display, window, &atts);

	if (atts.map_state == IsUnmapped) {
		unsigned long old_mask = atts.your_event_mask;
		XSelectInput (display, window, old_mask | StructureNotifyMask);

		XMapRaised (display, window);

		XEvent e;
		// predicate function won't return till I get exactly what I want,  
do-while not needed here:
		XPeekIfEvent (display, &e, map_notify_for_window,
			reinterpret_cast<XPointer> (window));
			
		XSelectInput (display, window, old_mask);
	}

	XSetInputFocus (display, window, RevertToParent, CurrentTime);
}

With the above I sometimes get BadMatch errors just like before.  
Perhaps there's something wrong with my predicate function?


If I go with the XWindowEvent() and a do-while loop instead of  
XPeekIfEvent() would it be ok for me to keep track of the events I  
remove and then put them all back on the queue once I leave the do- 
while loop? Or is that sort of reordering of the queue going to cause  
all kinds of problems? After testing it doesn't seem to, but I'm not  
sure that there aren't any hidden consequences...

--
Andrew Troschinetz
Applied Research Laboratories



More information about the xorg mailing list