Catching *every* event

Glynn Clements glynn at gclements.plus.com
Wed Aug 3 02:27:34 PDT 2005


Jon Wilson wrote:

> I want to be able to catch, in one X client, literally every X event
> which is sent to any window.  Furthermore, I want this one client to
> be able to catch all of these events before any other client gets
> them, and also have the ability to delay or prevent (a la substructure
> redirect) these events from reaching the client that owns the window
> they were sent to.  Does substructure redirect do this for all events,
> or just mapping/resizing/etc. events?

The latter.

> Is there a clean, simple way to do this at all?

Make your application a proxy X server, and require all other
applications to connect to it rather than to the real X server.

This is how protocol analysers such as xscope and xmon work.

> The purpose of this is to write an application that allows complete
> customization of what occurs on not only input, but also on any other
> event that might occur.  This application would eventually be one
> piece of a window manager I am beginning work on.
> 
> I've read through some documentation on Xlib, which is very helpful
> when it comes to telling me how to select various events, but not so
> helpful when it comes to telling me which events get sent where when,
> and if it is possible to intercept them.

You can't, apart from the specific redirects associated with
ResizeRedirectMask and SubstructureRedirectMask; even then, the
redirects don't apply to windows with the override_redirect flag.

> A few approaches I've thought of, but haven't been able to verify in
> any documentation I've found:
> 
> 1) select for every event on the root window.  However, I'm pretty
> sure that events get sent to childmost windows first, and then
> propogate up the chain, eventually landing on the root window if
> nobody else handles them.

Correct.

> 2) select for every event on *every* window that is on the server.

Some events (e.g. ButtonPress) can only be selected by one client at a
time.

> This seems like it might work, but it would probably be somewhat
> slower than I'd like, as the number of X windows can be very high at
> times, I believe.  Additionally, I suspect that this would not allow
> me to prevent event delivery to other clients.

Correct.

> 3) For every window on the server, create a child of that window which
> is transparent, the same dimensions, and always on top of its parent.
>   Then, select for every event on these transparent covers, and set
> the do not propagate mask for every event.  However, I don't believe
> that do not propagate stops events of every type.  This has the same
> bloat problems as 2) it would seem.  I suppose this could be slightly
> ameliorated, especially on multi-core/processor systems, by starting a
> new thread to catch events on every cover that is created.

I suspect that would only work for input events.

-- 
Glynn Clements <glynn at gclements.plus.com>



More information about the xorg mailing list