1 /*************************************************************************************
2  *  Copyright 2012, 2013  Daniel Vrátil <dvratil@redhat.com>                         *
3  *                                                                                   *
4  *  This library is free software; you can redistribute it and/or                    *
5  *  modify it under the terms of the GNU Lesser General Public                       *
6  *  License as published by the Free Software Foundation; either                     *
7  *  version 2.1 of the License, or (at your option) any later version.               *
8  *                                                                                   *
9  *  This library is distributed in the hope that it will be useful,                  *
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of                   *
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                *
12  *  Lesser General Public License for more details.                                  *
13  *                                                                                   *
14  *  You should have received a copy of the GNU Lesser General Public                 *
15  *  License along with this library; if not, write to the Free Software              *
16  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA       *
17  *************************************************************************************/
18 #pragma once
19 
20 #include "output.h"
21 
22 #include "xcbwrapper.h"
23 #include "xrandrmode.h"
24 
25 #include <QObject>
26 
27 class XRandRConfig;
28 class XRandRCrtc;
29 namespace Disman
30 {
31 class Config;
32 class Output;
33 }
34 
35 class XRandROutput : public QObject
36 {
37     Q_OBJECT
38 
39 public:
40     using Map = std::map<xcb_randr_output_t, XRandROutput*>;
41 
42     explicit XRandROutput(xcb_randr_output_t id, XRandRConfig* config);
43     ~XRandROutput() override;
44 
45     void disconnected();
46 
47     void update();
48     void
49     update(xcb_randr_crtc_t crtc, xcb_randr_mode_t mode, xcb_randr_connection_t conn, bool primary);
50 
51     void setIsPrimary(bool primary);
52 
53     xcb_randr_output_t id() const;
54 
55     bool enabled() const;
56     bool isConnected() const;
57     bool isPrimary() const;
58 
59     QPoint position() const;
60     QSize size() const;
61     QSizeF logicalSize() const;
62 
63     std::string currentModeId() const;
64     XRandRMode::Map modes() const;
65     XRandRMode* currentMode() const;
66 
67     Disman::Output::Rotation rotation() const;
68     bool isHorizontal() const;
69 
70     QByteArray edid() const;
71     XRandRCrtc* crtc() const;
72 
73     void updateDismanOutput(Disman::OutputPtr& dismanOutput) const;
74 
75     void updateLogicalSize(const Disman::OutputPtr& output, XRandRCrtc* crtc = nullptr);
76 
77 private:
78     void init();
79     void updateModes(const XCB::OutputInfo& outputInfo);
80     std::string description() const;
81     std::string hash() const;
82 
83     static Disman::Output::Type fetchOutputType(xcb_randr_output_t outputId, const QString& name);
84     static QByteArray typeFromProperty(xcb_randr_output_t outputId);
85 
86     xcb_render_transform_t currentTransform() const;
87 
88     XRandRConfig* m_config;
89     xcb_randr_output_t m_id;
90     QString m_name;
91     mutable QByteArray m_edid;
92 
93     xcb_randr_connection_t m_connected;
94     bool m_primary;
95     Disman::Output::Type m_type;
96 
97     XRandRMode::Map m_modes;
98     std::vector<std::string> m_preferredModes;
99 
100     unsigned int m_widthMm;
101     unsigned int m_heightMm;
102 
103     bool m_hotplugModeUpdate = false;
104     XRandRCrtc* m_crtc;
105 };
106 
107 Q_DECLARE_METATYPE(XRandROutput::Map)
108