[Development] "Native event" filter

David Faure faure at kde.org
Tue Jun 26 12:48:56 CEST 2012


On Friday 22 June 2012 17:08:48 David Faure wrote:
> On Friday 22 June 2012 10:14:22 Thiago Macieira wrote:
> > On sexta-feira, 22 de junho de 2012 10.07.54, David Faure wrote:
> > > QWindow and QWidget have a virtual method nativeEvent(), but this only
> > > works for window-specific or widget-specific event handling.
> > > 
> > > Looking at the KDE code, I see a rather wide usage of process-level
> > > handling of native events.
> > > 
> > > http://lxr.kde.org/ident?i=installX11EventFilter shows about 30 uses of
> > > that.
> > > 
> > > >From idle detection to desktop-wide clipboard handling, color picking,
> > > >RANDR
> > > 
> > > event handling, and so on.
> > > This was all done via QApplication::x11EventFilter(), which doesn't seem
> > > to
> > > have a replacement in Qt5 yet.
> 
> It turns out that I'm wrong, there is
> QAbstractEventDispatcher::instance()->setEventFilter() already, for exactly
> this.
> 
> Strangely enough, there's QCoreApplication::setEventFilter too, but it says
> "It is not called for messages that are not meant for Qt objects."
> I guess this means "messages meant for a Qt window", in practice.

... but actually neither of these was working, except for the dispatcher one 
on Windows.
The port to QPA broke the sending of native events, in particular.

So I looked further into this, and discussed it with several people at QtCS, 
and decided that not only the implementation needed fixing, the API too. The 
current API can lead to crashes if removing install event filters in a different 
order than the reverse-order-of-setting, and leads to ugly code (global C 
function, which basically requires having a singleton).

In https://codereview.qt-project.org/#change,29260 I'm proposing a new API:

QCoreApplication::instance()->installNativeEventFilter(obj);

with obj deriving from this interface:

class QAbstractNativeEventFilter
{
   virtual bool nativeEventFilter(const QByteArray &eventType, void *message,
                                                 long *result) = 0;
};

This allows to provide removeNativeEventFilter(obj) as well.

I thought making the change request was enough, but I was asked to post here 
in order to get approval for the SIC change (replacing the old setEventFilter 
with the above API).

-- 
David Faure, faure at kde.org, http://www.davidfaure.fr
Sponsored by Nokia to work on KDE, incl. KDE Frameworks 5




More information about the Development mailing list