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 <QObject>
21 
22 #include "xrandr.h"
23 #include "xrandrcrtc.h"
24 #include "xrandroutput.h"
25 
26 class XRandRScreen;
27 namespace Disman
28 {
29 class Config;
30 }
31 
32 class XRandRConfig : public QObject
33 {
34     Q_OBJECT
35 
36 public:
37     XRandRConfig();
38     ~XRandRConfig() override;
39 
40     XRandROutput::Map outputs() const;
41     XRandROutput* output(xcb_randr_output_t output) const;
42 
43     XRandRCrtc::Map crtcs() const;
44     XRandRCrtc* crtc(xcb_randr_crtc_t crtc) const;
45 
46     XRandRScreen* screen() const;
47 
48     void addNewOutput(xcb_randr_output_t id);
49     void addNewCrtc(xcb_randr_crtc_t crtc);
50     void removeOutput(xcb_randr_output_t id);
51 
52     Disman::ConfigPtr update_config(Disman::ConfigPtr& config) const;
53     bool applyDismanConfig(const Disman::ConfigPtr& config);
54 
55 private:
56     QSize screenSize(const Disman::ConfigPtr& config) const;
57     bool setScreenSize(const QSize& size) const;
58 
59     void setPrimaryOutput(xcb_randr_output_t outputId) const;
60 
61     bool disableOutput(const Disman::OutputPtr& output) const;
62     bool enableOutput(const Disman::OutputPtr& output, bool primary) const;
63     bool changeOutput(const Disman::OutputPtr& output, bool primary) const;
64 
65     bool sendConfig(const Disman::OutputPtr& dismanOutput, XRandRCrtc* crtc) const;
66 
67     /**
68      * We need to print stuff to discover the damn bug
69      * where currentMode is null
70      */
71     void printConfig(const Disman::ConfigPtr& config) const;
72     void printInternalCond() const;
73 
74     XRandROutput::Map m_outputs;
75     XRandRCrtc::Map m_crtcs;
76     XRandRScreen* m_screen;
77 };
78