Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. #include "mainwindow.h"
  2. #include <xcb/xcb.h>
  3. #include <assert.h>
  4. #include <QAbstractNativeEventFilter>
  5. #include <QApplication>
  6. #include <QDebug>
  7.  
  8. class NativeAppEventFilter : public QAbstractNativeEventFilter {
  9.  
  10. public:
  11. NativeAppEventFilter();
  12. virtual ~NativeAppEventFilter();
  13.  
  14. public:
  15. virtual bool nativeEventFilter(const QByteArray &eventType, void *m, long *);
  16. };
  17.  
  18.  
  19. NativeAppEventFilter::NativeAppEventFilter()
  20. {
  21. QCoreApplication* app = QCoreApplication::instance();
  22. assert(app);
  23.  
  24. if (app) {
  25. app -> installNativeEventFilter(this);
  26. }
  27. }
  28.  
  29. NativeAppEventFilter::~NativeAppEventFilter()
  30. {
  31. }
  32.  
  33. bool NativeAppEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *)
  34. {
  35. bool filtered = false;
  36.  
  37. if (message) {
  38. if (eventType == "xcb_generic_event_t") {
  39. const xcb_generic_event_t* xge = static_cast<const xcb_generic_event_t*>(message);
  40. uint8_t responseType = xge -> response_type & ~0x80;
  41. qDebug() << "Obtained response type: " << responseType;
  42.  
  43. if (responseType == XCB_BUTTON_PRESS) {
  44. qDebug() << "Got a mouse button press!";
  45. }
  46. } else {
  47. assert(false);
  48. }
  49. }
  50.  
  51. return filtered;
  52. }
  53.  
  54. int main(int argc, char *argv[])
  55. {
  56. QApplication a(argc, argv);
  57. NativeAppEventFilter filter;
  58. MainWindow w;
  59. w.show();
  60.  
  61. return a.exec();
  62. }
  63. #include "mainwindow.h"
  64. #include <xcb/xcb.h>
  65. #include <assert.h>
  66. #include <QAbstractNativeEventFilter>
  67. #include <QApplication>
  68. #include <QDebug>
  69.  
  70. class NativeAppEventFilter : public QAbstractNativeEventFilter {
  71.  
  72. public:
  73. NativeAppEventFilter();
  74. virtual ~NativeAppEventFilter();
  75.  
  76. public:
  77. virtual bool nativeEventFilter(const QByteArray &eventType, void *m, long *);
  78. };
  79.  
  80.  
  81. NativeAppEventFilter::NativeAppEventFilter()
  82. {
  83. QCoreApplication* app = QCoreApplication::instance();
  84. assert(app);
  85.  
  86. if (app) {
  87. app -> installNativeEventFilter(this);
  88. }
  89. }
  90.  
  91. NativeAppEventFilter::~NativeAppEventFilter()
  92. {
  93. }
  94.  
  95. bool NativeAppEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *)
  96. {
  97. bool filtered = false;
  98.  
  99. if (message) {
  100. if (eventType == "xcb_generic_event_t") {
  101. const xcb_generic_event_t* xge = static_cast<const xcb_generic_event_t*>(message);
  102. uint8_t responseType = xge -> response_type & ~0x80;
  103. qDebug() << "Obtained response type: " << responseType;
  104.  
  105. if (responseType == XCB_BUTTON_PRESS) {
  106. qDebug() << "Got a mouse button press!";
  107. }
  108. } else {
  109. assert(false);
  110. }
  111. }
  112.  
  113. return filtered;
  114. }
  115.  
  116. int main(int argc, char *argv[])
  117. {
  118. QApplication a(argc, argv);
  119. NativeAppEventFilter filter;
  120. MainWindow w;
  121. w.show();
  122.  
  123. return a.exec();
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement