Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "mainwindow.h"
- #include <xcb/xcb.h>
- #include <assert.h>
- #include <QAbstractNativeEventFilter>
- #include <QApplication>
- #include <QDebug>
- class NativeAppEventFilter : public QAbstractNativeEventFilter {
- public:
- NativeAppEventFilter();
- virtual ~NativeAppEventFilter();
- public:
- virtual bool nativeEventFilter(const QByteArray &eventType, void *m, long *);
- };
- NativeAppEventFilter::NativeAppEventFilter()
- {
- QCoreApplication* app = QCoreApplication::instance();
- assert(app);
- if (app) {
- app -> installNativeEventFilter(this);
- }
- }
- NativeAppEventFilter::~NativeAppEventFilter()
- {
- }
- bool NativeAppEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *)
- {
- bool filtered = false;
- if (message) {
- if (eventType == "xcb_generic_event_t") {
- const xcb_generic_event_t* xge = static_cast<const xcb_generic_event_t*>(message);
- uint8_t responseType = xge -> response_type & ~0x80;
- qDebug() << "Obtained response type: " << responseType;
- if (responseType == XCB_BUTTON_PRESS) {
- qDebug() << "Got a mouse button press!";
- }
- } else {
- assert(false);
- }
- }
- return filtered;
- }
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- NativeAppEventFilter filter;
- MainWindow w;
- w.show();
- return a.exec();
- }
- #include "mainwindow.h"
- #include <xcb/xcb.h>
- #include <assert.h>
- #include <QAbstractNativeEventFilter>
- #include <QApplication>
- #include <QDebug>
- class NativeAppEventFilter : public QAbstractNativeEventFilter {
- public:
- NativeAppEventFilter();
- virtual ~NativeAppEventFilter();
- public:
- virtual bool nativeEventFilter(const QByteArray &eventType, void *m, long *);
- };
- NativeAppEventFilter::NativeAppEventFilter()
- {
- QCoreApplication* app = QCoreApplication::instance();
- assert(app);
- if (app) {
- app -> installNativeEventFilter(this);
- }
- }
- NativeAppEventFilter::~NativeAppEventFilter()
- {
- }
- bool NativeAppEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *)
- {
- bool filtered = false;
- if (message) {
- if (eventType == "xcb_generic_event_t") {
- const xcb_generic_event_t* xge = static_cast<const xcb_generic_event_t*>(message);
- uint8_t responseType = xge -> response_type & ~0x80;
- qDebug() << "Obtained response type: " << responseType;
- if (responseType == XCB_BUTTON_PRESS) {
- qDebug() << "Got a mouse button press!";
- }
- } else {
- assert(false);
- }
- }
- return filtered;
- }
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- NativeAppEventFilter filter;
- MainWindow w;
- w.show();
- return a.exec();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement