#ifndef UKUIINPUTGATHERCLIENT_H
#define UKUIINPUTGATHERCLIENT_H
#include "ukuiinputgatherclient_global.h"

#include <X11/extensions/XInput.h>
#include <X11/Xatom.h>
#include "event.h"
#include <functional>
#include <string>



/**
 * Unix domain socket (abstract namespace).
 */
static const std::string SOCKET_NAME{"\0/InputGatherServer", 10}; // NOLINT


class UKUIINPUTGATHERCLIENT_EXPORT UKUIInputGatherClient
{
public:
    UKUIInputGatherClient();
    ~UKUIInputGatherClient();

    void startToReceiveEvent();
    void setEventCallBack(std::function<void(Event*)> sendEvent);
    /*
     * 获取当前设备列表并对设备进行遍历
     *
    */
    void obtainDeviceList();
    /*
     * 检测触控板属性(Device Enable)变化情况，属性变化时候禁用手势
    */
    void checkTouchpadState();
    /*
     * 获取触控板的状态
     * 属于触控板的话查询当前触控板的状态
    */
    void findTouchpadState(Display* display,XDeviceInfo *deviceInfo);
    /*
     *  根据名称获取属性
    */
    Atom hasPropertyFromName (Display *display,const char *propertyName);
    bool deviceHasProperty (Display *display,XDevice    *device,char *propertyName);
    /*
     * 判断当前设备是否是触控板
    */
    XDevice* deviceIsTouchpad (Display *display,XDeviceInfo *deviceinfo);

    /*! \param libinputTabletSwitchState()
     *  \return return 1 if has device with capability of LIBINPUT_SWITCH_TABLET_MODE
     *          and state is LIBINPUT_SWITCH_STATE_ON
     *          return 0 if has device with capability of LIBINPUT_SWITCH_TABLET_MODE
     *          amd state is LIBINPUT_SWITCH_STATE_OFF
     *          return -1 if dose not have device with capability of
     *          LIBINPUT_SWITCH_TABLET_MODE
    */
    int libinputTabletSwitchState();

private:
    bool connectToServer();

    Event* m_event;
    bool m_flagGesture = true;
    std::function<void(Event*)> m_sendEventCallBack;

    int m_socket;
};

#endif // UKUIINPUTGATHERCLIENT_H
