[Development] "Native event" filter
David Faure
faure at kde.org
Fri Jun 22 10:07:54 CEST 2012
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.
1) any objections against adding this to Qt 5? (for 5.1 if you want, assuming
it can be done without new virtual methods)
2) what could the API look like? Ideally similar to QEvent event filters, so
QGuiApplication::installEventFilter(Receiver *) ?
The problem is the type of Receiver. QObject can't be used here, since there
is no nativeEvent() there. So it's either QWidget (but this tends to make
people write 'fake widgets' just to receive these events), or a custom class,
something like:
class QNativeEventFilter
{
virtual bool nativeEvent(const QByteArray &eventType, void *message, long
*result) // same API as in QWindow/QWidget.
};
(not sure if it should be a QObject for easier memory management)
--
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