GCC Code Coverage Report


Directory: ./
File: backends/xrandr/xrandrcrtc.cpp
Date: 2023-04-20 22:59:23
Exec Total Coverage
Lines: 0 53 0.0%
Branches: 0 16 0.0%

Line Branch Exec Source
1 /*
2 * Copyright 2015 Daniel Vrátil <dvratil@redhat.com>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License or (at your option) version 3 or any later version
8 * accepted by the membership of KDE e.V. (or its successor approved
9 * by the membership of KDE e.V.), which shall act as a proxy
10 * defined in Section 14 of version 3 of the license.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21 #include "xrandrcrtc.h"
22
23 #include "xcbwrapper.h"
24 #include "xrandr.h"
25 #include "xrandrconfig.h"
26
27 #include "xrandr_logging.h"
28
29 XRandRCrtc::XRandRCrtc(xcb_randr_crtc_t crtc, XRandRConfig* config)
30 : QObject(config)
31 , m_crtc(crtc)
32 , m_mode(0)
33 , m_rotation(XCB_RANDR_ROTATION_ROTATE_0)
34 {
35 update();
36 }
37
38 xcb_randr_crtc_t XRandRCrtc::crtc() const
39 {
40 return m_crtc;
41 }
42
43 xcb_randr_mode_t XRandRCrtc::mode() const
44 {
45 return m_mode;
46 }
47
48 QRect XRandRCrtc::geometry() const
49 {
50 return m_geometry;
51 }
52
53 xcb_randr_rotation_t XRandRCrtc::rotation() const
54 {
55 return m_rotation;
56 }
57
58 QVector<xcb_randr_output_t> XRandRCrtc::possibleOutputs()
59 {
60 return m_possibleOutputs;
61 }
62
63 QVector<xcb_randr_output_t> XRandRCrtc::outputs() const
64 {
65 return m_outputs;
66 }
67
68 bool XRandRCrtc::connectOutput(xcb_randr_output_t output)
69 {
70 update();
71 qCDebug(DISMAN_XRANDR) << "Connected output" << output << "to CRTC" << m_crtc;
72
73 if (!m_possibleOutputs.contains(output)) {
74 qCDebug(DISMAN_XRANDR) << "Output" << output << "is not an allowed output for CRTC"
75 << m_crtc;
76 return false;
77 }
78
79 if (!m_outputs.contains(output)) {
80 m_outputs.append(output);
81 }
82 return true;
83 }
84
85 void XRandRCrtc::disconectOutput(xcb_randr_output_t output)
86 {
87 update();
88 qCDebug(DISMAN_XRANDR) << "Disconnected output" << output << "from CRTC" << m_crtc;
89
90 const int index = m_outputs.indexOf(output);
91 if (index > -1) {
92 m_outputs.remove(index);
93 }
94 }
95
96 bool XRandRCrtc::isFree() const
97 {
98 return m_outputs.isEmpty();
99 }
100
101 void XRandRCrtc::update()
102 {
103 XCB::CRTCInfo crtcInfo(m_crtc, XCB_TIME_CURRENT_TIME);
104 m_mode = crtcInfo->mode;
105
106 m_geometry = QRect(crtcInfo->x, crtcInfo->y, crtcInfo->width, crtcInfo->height);
107 m_rotation = (xcb_randr_rotation_t)crtcInfo->rotation;
108
109 m_possibleOutputs.clear();
110 m_possibleOutputs.reserve(crtcInfo->num_possible_outputs);
111
112 xcb_randr_output_t* possible = xcb_randr_get_crtc_info_possible(crtcInfo);
113 for (int i = 0; i < crtcInfo->num_possible_outputs; ++i) {
114 m_possibleOutputs.append(possible[i]);
115 }
116
117 m_outputs.clear();
118 xcb_randr_output_t* outputs = xcb_randr_get_crtc_info_outputs(crtcInfo);
119 for (int i = 0; i < crtcInfo->num_outputs; ++i) {
120 m_outputs.append(outputs[i]);
121 }
122 }
123
124 void XRandRCrtc::update(xcb_randr_mode_t mode, xcb_randr_rotation_t rotation, const QRect& geom)
125 {
126 m_mode = mode;
127 m_geometry = geom;
128 m_rotation = rotation;
129 }
130