2 * Copyright 2008 Aike J Sommer <dev@aikesommer.name>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2,
7 * or (at your option) any later version.
9 * This program 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
12 * GNU General Public License for more details
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "desktopwidgetoutputs.h"
22 #include "../simpleoutput.h"
24 #include <QDesktopWidget>
25 #include <QApplication>
31 DesktopWidgetOutputs::DesktopWidgetOutputs(QObject
* parent
)
34 QDesktopWidget
* desktop
= QApplication::desktop();
35 for (int i
= 0; i
< desktop
->numScreens(); i
++) {
36 QRect geom
= desktop
->screenGeometry(i
);
37 qDebug() << "adding an output" << i
<< "with geom: " << geom
;
39 SimpleOutput
* output
= new SimpleOutput(this,
40 "SCREEN-" + QString::number(i
),
45 m_outputs
.append(output
);
47 for (int i
= desktop
->numScreens(); i
< 4; i
++) {
48 qDebug() << "adding a disconnected output" << i
;
50 SimpleOutput
* output
= new SimpleOutput(this,
51 "SCREEN-" + QString::number(i
),
56 m_outputs
.append(output
);
59 connect(desktop
, SIGNAL(resized(int)), this, SLOT(screenChanged(int)));
62 DesktopWidgetOutputs::~DesktopWidgetOutputs() {
63 foreach(Output
* output
, m_outputs
) {
69 QList
<Output
*> DesktopWidgetOutputs::outputs()
71 QList
<Output
*> result
;
72 foreach(SimpleOutput
* output
, m_outputs
) {
73 result
.append(output
);
78 void DesktopWidgetOutputs::activateLayout(const QMap
<Output
*, QRect
> & layout
)
83 void DesktopWidgetOutputs::screenChanged(int screen
)
87 QDesktopWidget
* desktop
= QApplication::desktop();
88 for(int i
= m_outputs
.size() - 1; i
>= desktop
->numScreens(); i
--) {
89 SimpleOutput
* output
= m_outputs
.at(i
);
90 if (output
->isConnected()) {
91 qDebug() << "disconnecting output" << i
;
92 output
->_setConnected(false);
93 emit
outputDisconnected(output
);
97 for(int i
= 0; i
< desktop
->numScreens(); i
++) {
98 if (m_outputs
.size() <= i
) {
99 m_outputs
.append(new SimpleOutput(this,
100 "SCREEN-" + QString::number(i
),
107 SimpleOutput
* output
= m_outputs
[i
];
108 QRect geom
= desktop
->screenGeometry(i
);
109 if (! output
->isConnected()) {
110 output
->_setConnected(true);
111 output
->_setActivated(true);
112 output
->_setPosition(geom
.topLeft());
113 output
->_setSize(geom
.size());
115 emit
outputConnected(output
);
117 if (output
->position() != geom
.topLeft()) {
118 QPoint oldPos
= output
->position();
119 QPoint newPos
= geom
.topLeft();
120 qDebug() << "output" << i
<< "moved" << oldPos
<< "->" << newPos
;
122 output
->_setPosition(newPos
);
123 emit
outputMoved(output
, oldPos
, newPos
);
125 if (output
->size() != geom
.size()) {
126 QSize oldSize
= output
->size();
127 QSize newSize
= geom
.size();
128 qDebug() << "output" << i
<< "resized" << oldSize
<< "->" << newSize
;
130 output
->_setSize(newSize
);
131 emit
outputResized(output
, oldSize
, newSize
);