#ifndef XEVENTMONITOR_H
#define XEVENTMONITOR_H

#include <QObject>

#include <QThread>
#include <X11/Xlib.h>
#include <X11/extensions/record.h>
#include <X11/Xlibint.h>
#include <X11/keysym.h>
#include <X11/XKBlib.h>
#include <QX11Info>
// Virtual button codes that are not defined by X11.
#define Button1			1
#define Button2			2
#define Button3			3
#define WheelUp			4
#define WheelDown		5
#define WheelLeft		6
#define WheelRight		7
#define XButton1		8
#define XButton2		9

class xEventMonitor : public QThread
{
    Q_OBJECT

public:
    xEventMonitor(QObject *parent = 0);
    void freeXres();
Q_SIGNALS:
    void mousePress(int x, int y);

protected:
    bool isWheelEvent(int detail);
    static void callback(XPointer trash, XRecordInterceptData* data);
    void handleRecordEvent(XRecordInterceptData *);
    void run();

private:
    bool isOpenDisplay = false;
    XRecordContext m_context;
    Display *m_displayDatalink = nullptr;
};

#endif // XEVENTMONITOR_H
