Raise/Map and Focus a window: BadMatch error

Andrew Troschinetz ast at arlut.utexas.edu
Tue Dec 18 12:14:14 PST 2007


On Dec 18, 2007, at 1:18 PM, Peter Harris wrote:

> (Are you sure you want to overwrite the window's event mask? I don't  
> see
> you restoring the previous event mask anywhere.)

Oh I see now, XSelectEvent() modifies the window's event mask. Thanks  
for pointing that out I totally missed it.  I rewrote the function to  
first use XGetWindowAttributes() and then save/restore the  
your_event_mask field.

> First, you should make sure that this function is only called on
> toplevel windows (or that all the window's parents are already  
> mapped).

This is actually handled outside of this function, I make sure not to  
call it without knowing that the given Window is a toplevel (with  
parents already mapped).

> XNextEvent isn't polite, as you are consuming events that the rest of
> the application may need. You probably want to use XWindowEvent or
> XPeekIfEvent instead of XNextEvent.

Ah, didn't know that either. I was going off the Xlib tutorial found  
at http://www.tronche.com/gui/x/

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.

> That aside, checking for an Expose
> event (on any window) is not a reliable indicator that this window has
> been mapped. Even if there are no other windows that this application
> has created, you may receive an early expose event if BackingStores  
> (or
> maybe Composite) is enabled. Instead, you should check for a MapNotify
> event on only the window you are interested in. Select
> StructureNotifyMask instead of ExposureNotifyMask to get this event.

Thanks again for that point, I was able to use (StructureNotifyMask |  
SubstructureNotifyMask) to pickup the MapNotify event instead of the  
Expose event. But first I had to check that the window wasn't already  
mapped or I'd enter an indefinite loop waiting for a map event.

> Note that you might be waiting for a long time if the window manager
> decides to start your window minimized, or (in the case of twm) if the
> user is away from the screen. It might be better to set a flag, and
> check the flag inside the main loop's MapNotify handler.

Thankfully this application will only ever run in a strictly regulated  
environment so I can ignore these issues, but thanks for the note. At  
least I know now that I might have to rework the code later if the  
environment changes in the future (though I don't expect this to ever  
be a real problem in my situation).

--
Andrew Troschinetz
Applied Research Laboratories
(512) 835-3410



More information about the xorg mailing list