File indexing completed on 2024-06-23 05:29:39

0001 /*
0002     SPDX-FileCopyrightText: 2015 Weng Xuetian <wengxt@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QObject>
0010 #include <QSet>
0011 #include <QVariantHash>
0012 
0013 #include "propertyinfo.h"
0014 #include "xcbatom.h"
0015 #include <xcb/xcb.h>
0016 
0017 enum ParaType {
0018     PT_INT,
0019     PT_BOOL,
0020     PT_DOUBLE,
0021 };
0022 
0023 struct Parameter {
0024     const char *name; /* Name of parameter */
0025     enum ParaType type; /* Type of parameter */
0026     double min_val; /* Minimum allowed value */
0027     double max_val; /* Maximum allowed value */
0028     const char *prop_name; /* Property name */
0029     int prop_format; /* Property format (0 for floats) */
0030     unsigned prop_offset; /* Offset inside property */
0031 };
0032 
0033 class XlibTouchpad
0034 {
0035 public:
0036     XlibTouchpad(Display *display, int deviceId);
0037     virtual ~XlibTouchpad()
0038     {
0039     }
0040 
0041     int deviceId()
0042     {
0043         return m_deviceId;
0044     }
0045     const QStringList &supportedParameters() const
0046     {
0047         return m_supported;
0048     }
0049     bool applyConfig(const QVariantHash &p);
0050     bool getConfig(QVariantHash &p);
0051     virtual bool getConfig()
0052     {
0053         return false;
0054     }
0055     virtual bool applyConfig()
0056     {
0057         return false;
0058     }
0059     virtual bool getDefaultConfig()
0060     {
0061         return false;
0062     }
0063     virtual bool isChangedConfig()
0064     {
0065         return false;
0066     }
0067     void setEnabled(bool enable);
0068     bool enabled();
0069     virtual void setTouchpadOff(int /*touchpadOff*/)
0070     {
0071     }
0072     virtual int touchpadOff() = 0;
0073 
0074     virtual XcbAtom &touchpadOffAtom() = 0;
0075 
0076 protected:
0077     void loadSupportedProperties(const Parameter *props);
0078     bool setParameter(const struct Parameter *, const QVariant &);
0079     QVariant getParameter(const struct Parameter *);
0080     struct PropertyInfo *getDevProperty(const QLatin1String &propName);
0081     void flush();
0082     virtual double getPropertyScale(const QString &name) const;
0083     const Parameter *findParameter(const QString &name);
0084 
0085     Display *m_display;
0086     xcb_connection_t *m_connection;
0087     int m_deviceId;
0088 
0089     XcbAtom m_floatType, m_enabledAtom;
0090 
0091     QMap<QLatin1String, std::shared_ptr<XcbAtom>> m_atoms;
0092 
0093     QMap<QString, QString> m_negate;
0094     QMap<QLatin1String, struct PropertyInfo> m_props;
0095     QSet<QLatin1String> m_changed;
0096     QStringList m_supported;
0097     const struct Parameter *m_paramList;
0098 };