File indexing completed on 2024-03-24 15:44:19

0001 /***************************************************************************
0002  *   Copyright (C) 2012-2016 by Daniel Nicoletti <dantti12@gmail.com>      *
0003  *                                                                         *
0004  *   This program is free software; you can redistribute it and/or modify  *
0005  *   it under the terms of the GNU General Public License as published by  *
0006  *   the Free Software Foundation; either version 2 of the License, or     *
0007  *   (at your option) any later version.                                   *
0008  *                                                                         *
0009  *   This program is distributed in the hope that it will be useful,       *
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0012  *   GNU General Public License for more details.                          *
0013  *                                                                         *
0014  *   You should have received a copy of the GNU General Public License     *
0015  *   along with this program; see the file COPYING. If not, write to       *
0016  *   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,  *
0017  *   Boston, MA 02110-1301, USA.                                           *
0018  ***************************************************************************/
0019 
0020 #pragma once
0021 
0022 #include "Output.h"
0023 
0024 #include <KDEDModule>
0025 
0026 #include "xlibandxrandr.h"
0027 
0028 class CdInterface;
0029 class XEventHandler;
0030 class ProfilesWatcher;
0031 
0032 class Q_DECL_EXPORT ColorD : public KDEDModule
0033 {
0034     Q_OBJECT
0035 public:
0036     explicit ColorD(QObject *parent, const QVariantList &);
0037     ~ColorD() override;
0038     void reset();
0039     int eventBase() const;
0040     bool isValid() const;
0041 
0042 private Q_SLOTS:
0043     void init();
0044     void checkOutputs();
0045 
0046     void profileAdded(const QDBusObjectPath &objectPath);
0047     void deviceAdded(const QDBusObjectPath &objectPath);
0048     void deviceChanged(const QDBusObjectPath &objectPath);
0049 
0050     void serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner);
0051 
0052 private:
0053     quint8 *readEdidData(RROutput output, size_t &len);
0054     XRRScreenResources *connectToDisplay();
0055     void connectToColorD();
0056     void addOutput(const Output::Ptr &output);
0057     void outputChanged(const Output::Ptr &output);
0058     void removeOutput(const Output::Ptr &output);
0059     void addEdidProfileToDevice(const Output::Ptr &output);
0060     CdStringMap getProfileMetadata(const QDBusObjectPath &profilePath);
0061     QString profilesPath() const;
0062 
0063     struct X11Monitor {
0064         QString name;
0065         RRCrtc crtc;
0066         bool isPrimary;
0067         int atomId;
0068     };
0069 
0070     int getPrimaryCRTCId(XID primary) const;
0071     QList<X11Monitor> getAtomIds() const;
0072 
0073     Output::List m_connectedOutputs;
0074 
0075     Display *m_dpy = nullptr;
0076     XRRScreenResources *m_resources = nullptr;
0077     Window m_root;
0078 
0079     QString m_errorCode;
0080 
0081     bool m_has_1_3;
0082     int m_errorBase;
0083     XEventHandler *m_x11EventHandler = nullptr;
0084     ProfilesWatcher *m_profilesWatcher = nullptr;
0085     CdInterface *m_cdInterface = nullptr;
0086 };