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
/* This also looks wrong; all screens will receive id i*/
39
i = desktop->primaryScreen();
43
QRect geom = desktop->screenGeometry(i);
44
qDebug() << "adding an output" << i << "with geom: " << geom;
46
SimpleOutput * output = new SimpleOutput(this,
47
"SCREEN-" + QString::number(i),
52
m_outputs.append(output);
54
/* See above, this only ensures the loop exits with multiple screens*/
61
/* This is completely wrong, isVirtualDesktop() just returns true on x11 if Xinerama is in
62
* use - adding 4 disconnected outputs here makes no sens
66
for (int i = desktop->numScreens(); i < 4; i++) {
67
qDebug() << "adding a disconnected output" << i;
69
SimpleOutput * output = new SimpleOutput(this,
70
"SCREEN-" + QString::number(i),
75
m_outputs.append(output);
80
connect(desktop, SIGNAL(resized(int)), this, SLOT(screenChanged(int)));
83
DesktopWidgetOutputs::~DesktopWidgetOutputs() {
84
foreach(Output * output, m_outputs) {
90
QList<Output *> DesktopWidgetOutputs::outputs()
92
QList<Output *> result;
93
foreach(SimpleOutput * output, m_outputs) {
94
result.append(output);
99
void DesktopWidgetOutputs::activateLayout(const QMap<Output *, QRect> & layout)
104
void DesktopWidgetOutputs::screenChanged(int screen)
108
QDesktopWidget * desktop = QApplication::desktop();
109
bool isVirtual = desktop->isVirtualDesktop();
112
for(int i = m_outputs.size() - 1; i >= desktop->numScreens(); i--) {
113
SimpleOutput * output = m_outputs.at(i);
114
if (output->isConnected()) {
115
qDebug() << "disconnecting output" << i;
116
output->_setActivated(false);
117
emit outputDeactivated(output);
118
output->_setConnected(false);
119
emit outputDisconnected(output);
124
for(int i = 0; i < desktop->numScreens(); i++) {
125
if (m_outputs.size() <= i) {
126
m_outputs.append(new SimpleOutput(this,
127
"SCREEN-" + QString::number(i),
134
SimpleOutput * output = m_outputs[i];
136
i = desktop->primaryScreen();
139
QRect geom = desktop->screenGeometry(i);
140
if (! output->isConnected()) {
141
output->_setConnected(true);
142
output->_setActivated(true);
143
output->_setPosition(geom.topLeft());
144
output->_setSize(geom.size());
146
emit outputConnected(output);
147
emit outputActivated(output);
149
if (output->position() != geom.topLeft()) {
150
QPoint oldPos = output->position();
151
QPoint newPos = geom.topLeft();
152
qDebug() << "output" << i << "moved" << oldPos << "->" << newPos;
154
output->_setPosition(newPos);
155
emit outputMoved(output, oldPos, newPos);
157
if (output->size() != geom.size()) {
158
QSize oldSize = output->size();
159
QSize newSize = geom.size();
160
qDebug() << "output" << i << "resized" << oldSize << "->" << newSize;
162
output->_setSize(newSize);
163
emit outputResized(output, oldSize, newSize);