Results 1 to 5 of 5

Thread: Getting mouse release event system-wide

  1. #1
    Join Date
    Dec 2009
    Posts
    26
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Getting mouse release event system-wide

    Hi

    I want to get system wide mouse release event in Linux. I created a ruApplication class from QApplication.

    The header file is

    Qt Code:
    1. #include <QApplication>
    2. #include <QAbstractEventDispatcher>
    3.  
    4. #include <X11/Xlib.h>
    5. #include <X11/Xutil.h>
    6. #include <X11/Xos.h>
    7.  
    8. class ruApplication : public QApplication
    9. {
    10. Q_OBJECT
    11. public:
    12. explicit ruApplication(int c, char *v[]);
    13.  
    14. protected:
    15. bool x11EventFilter(XEvent *);
    16. static bool ruEventFilter(void *message);
    17.  
    18. public slots:
    19.  
    20. private:
    21.  
    22. };
    To copy to clipboard, switch view to plain text mode 

    The cpp file is

    Qt Code:
    1. ruApplication::ruApplication(int c, char *v[]) :
    2. {
    3. evInstance = QAbstractEventDispatcher::instance();
    4. evInstance->setEventFilter((QAbstractEventDispatcher::EventFilter)ruEventFilter);
    5. }
    6.  
    7. bool ruApplication::x11EventFilter(XEvent *evt)
    8. {
    9. if(evt->type == ButtonRelease)
    10. qDebug("x11Event Filter");
    11. return false;
    12. }
    13.  
    14. bool ruApplication::ruEventFilter(void *message)
    15. {
    16. XEvent *evt;
    17. evt = (XEvent *) message;
    18. if(evt->type == ButtonRelease)
    19. qDebug("ruEvent Filter");
    20. return false;
    21. }
    To copy to clipboard, switch view to plain text mode 

    The main.cpp is

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. ruApplication a(argc, argv);
    4. Dialog w();
    5. w.show();
    6.  
    7. return a.exec();
    8. }
    To copy to clipboard, switch view to plain text mode 

    But when I am clicking out side the client area of the dialog, I am not getting any mouse event. What am I doing wrong? If this is not the correct way of doing this, can you suggest me, how to get system wide mouse release event in Linux?

    thanks

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Getting mouse release event system-wide

    Does this event filter works ? I mean, are you getting other events ?
    Qt Code:
    1. bool ruApplication::x11EventFilter(XEvent *evt)
    2. {
    3. qDebug() << "x11EventFilter" << evt->type;
    4. if(evt->type == ButtonRelease)
    5. qDebug("x11Event Filter");
    6. return false;
    7. }
    8.  
    9. bool ruApplication::ruEventFilter(void *message)
    10. {
    11. XEvent *evt;
    12. evt = (XEvent *) message;
    13. qDebug() << "ruEventFilter" << evt->type;
    14. if(evt->type == ButtonRelease)
    15. qDebug("ruEvent Filter");
    16. return false;
    17. }
    To copy to clipboard, switch view to plain text mode 
    Sorry I can't help you more, can't test on linux right now.

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Getting mouse release event system-wide

    The suggested solution will work only for the event sent to this application, but the OP wants a system wide filter.
    For a system wide event filter, if at all possible, you will have to tell X to deliver all events first to your app... try Linux forums for that.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  4. The following user says thank you to high_flyer for this useful post:

    rittchat (8th April 2011)

  5. #4
    Join Date
    Dec 2009
    Posts
    26
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Getting mouse release event system-wide

    Hi,

    Thanks for reply. I will try other linux forums.

  6. #5
    Join Date
    Feb 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Getting mouse release event system-wide

    Hi,
    a little bit late. But maybe it helps somebody else:

    Have a look at project dwm at suckless dot org. See method void setup(int argc, char **argv) in dwm.c how to initialize a XLib Display and set the XEvent mask. Be sure to use the same Display for your QApplication. Use the constructor with the Display parameter, if you want to attach to a running X client:

    Qt Code:
    1. class MyApplication: public QApplication {
    2. public:
    3. MyApplication(Display* dpy, int& argc, char** argv): QApplication(dpy, argc, argv) {}
    4. bool x11EventFilter(XEvent *e);
    5. };
    To copy to clipboard, switch view to plain text mode 
    What I tried is to attach a QApplication to dwm and replaced the main event loop of dwm by the qt event loop. My implementation of x11EventFilter delivers XEvents back to dwms event handlers.

    Or you try this which I also tested successfully:
    Use method
    Display * QX11Info::display () [static]
    after intantiation of your ruApplication and then set/modify the event mask.

    Example:
    main.cpp:

    Qt Code:
    1. #include <QApplication>
    2. #include <QX11Info>
    3. #include <X11/Xlib.h>
    4. #include <X11/cursorfont.h>
    5.  
    6. class MyApplication: public QApplication {
    7. public:
    8. MyApplication(int& argc, char** argv): QApplication(argc, argv) {}
    9. bool x11EventFilter(XEvent *e);
    10. };
    11.  
    12. bool MyApplication::x11EventFilter(XEvent *e) {
    13. qDebug("x11Event Filter called");
    14.  
    15. return false;
    16. }
    17.  
    18. int main(int argc, char *argv[])
    19. {
    20. MyApplication a(argc, argv);
    21. Display* dpy = QX11Info::display();
    22.  
    23. XSetWindowAttributes wa;
    24. wa.cursor = XCreateFontCursor(dpy, XC_left_ptr);
    25. wa.event_mask = ButtonPressMask;
    26.  
    27. int screen = DefaultScreen(dpy);
    28. Window root = RootWindow(dpy, screen);
    29. XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa);
    30. XSelectInput(dpy, root, wa.event_mask);
    31.  
    32. return a.exec();
    33. }
    To copy to clipboard, switch view to plain text mode 

    qttest.pro:
    Qt Code:
    1. QT += core gui
    2.  
    3. TEMPLATE = app
    4.  
    5. SOURCES += main.cpp
    6.  
    7. LIBS += -L/usr/X11R6/lib -lX11
    To copy to clipboard, switch view to plain text mode 

    Start in a separate X Server:
    xinit ./qttest -- :1

Similar Threads

  1. Replies: 3
    Last Post: 28th July 2010, 14:14
  2. Replies: 3
    Last Post: 12th May 2010, 13:11
  3. Getting system wide X11 events problems
    By wandereq in forum Qt Programming
    Replies: 1
    Last Post: 19th March 2010, 20:13
  4. QContextMenuEvent appear on mouse release
    By bucksey in forum Qt Programming
    Replies: 1
    Last Post: 21st March 2009, 01:09
  5. problem with mouse release on the border, help me!
    By dungsivn in forum Qt Programming
    Replies: 1
    Last Post: 25th June 2007, 08:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.