~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to libs/kephal/kephal/desktopwidgetoutputs.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright 2008 Aike J Sommer <dev@aikesommer.name>
 
3
 *
 
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.
 
8
 *
 
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
 
13
 *
 
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.
 
18
 */
 
19
 
 
20
 
 
21
#include "desktopwidgetoutputs.h"
 
22
#include "simpleoutput.h"
 
23
 
 
24
#include <QDesktopWidget>
 
25
#include <QApplication>
 
26
#include <QDebug>
 
27
 
 
28
 
 
29
namespace Kephal {
 
30
 
 
31
    DesktopWidgetOutputs::DesktopWidgetOutputs(QObject * parent)
 
32
            : Outputs(parent)
 
33
    {
 
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*/
 
37
            /*
 
38
            if (! isVirtual) {
 
39
                i = desktop->primaryScreen();
 
40
            }
 
41
            */
 
42
 
 
43
            QRect geom = desktop->screenGeometry(i);
 
44
            qDebug() << "adding an output" << i << "with geom: " << geom;
 
45
 
 
46
            SimpleOutput * output = new SimpleOutput(this,
 
47
                    "SCREEN-" + QString::number(i),
 
48
                    geom.size(),
 
49
                    geom.topLeft(),
 
50
                    true,
 
51
                    true);
 
52
            m_outputs.append(output);
 
53
 
 
54
            /* See above, this only ensures the loop exits with multiple screens*/
 
55
            /*
 
56
            if (! isVirtual) {
 
57
                break;
 
58
            }
 
59
            */
 
60
        }
 
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
 
63
         */
 
64
        /*
 
65
        if (isVirtual) {
 
66
            for (int i = desktop->numScreens(); i < 4; i++) {
 
67
                qDebug() << "adding a disconnected output" << i;
 
68
 
 
69
                SimpleOutput * output = new SimpleOutput(this,
 
70
                        "SCREEN-" + QString::number(i),
 
71
                        QSize(0, 0),
 
72
                        QPoint(0, 0),
 
73
                        false,
 
74
                        false);
 
75
                m_outputs.append(output);
 
76
            }
 
77
        }
 
78
 
 
79
        */
 
80
        connect(desktop, SIGNAL(resized(int)), this, SLOT(screenChanged(int)));
 
81
    }
 
82
 
 
83
    DesktopWidgetOutputs::~DesktopWidgetOutputs() {
 
84
        foreach(Output * output, m_outputs) {
 
85
            delete output;
 
86
        }
 
87
        m_outputs.clear();
 
88
    }
 
89
 
 
90
    QList<Output *> DesktopWidgetOutputs::outputs()
 
91
    {
 
92
        QList<Output *> result;
 
93
        foreach(SimpleOutput * output, m_outputs) {
 
94
            result.append(output);
 
95
        }
 
96
        return result;
 
97
    }
 
98
 
 
99
    void DesktopWidgetOutputs::activateLayout(const QMap<Output *, QRect> & layout)
 
100
    {
 
101
        Q_UNUSED(layout)
 
102
    }
 
103
 
 
104
    void DesktopWidgetOutputs::screenChanged(int screen)
 
105
    {
 
106
        Q_UNUSED(screen)
 
107
 
 
108
        QDesktopWidget * desktop = QApplication::desktop();
 
109
        bool isVirtual = desktop->isVirtualDesktop();
 
110
 
 
111
        if (isVirtual) {
 
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);
 
120
                }
 
121
            }
 
122
        }
 
123
 
 
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),
 
128
                    QSize(0, 0),
 
129
                    QPoint(0, 0),
 
130
                    false,
 
131
                    false));
 
132
            }
 
133
 
 
134
            SimpleOutput * output = m_outputs[i];
 
135
            if (! isVirtual) {
 
136
                i = desktop->primaryScreen();
 
137
            }
 
138
 
 
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());
 
145
 
 
146
                emit outputConnected(output);
 
147
                emit outputActivated(output);
 
148
            }
 
149
            if (output->position() != geom.topLeft()) {
 
150
                QPoint oldPos = output->position();
 
151
                QPoint newPos = geom.topLeft();
 
152
                qDebug() << "output" << i << "moved" << oldPos << "->" << newPos;
 
153
 
 
154
                output->_setPosition(newPos);
 
155
                emit outputMoved(output, oldPos, newPos);
 
156
            }
 
157
            if (output->size() != geom.size()) {
 
158
                QSize oldSize = output->size();
 
159
                QSize newSize = geom.size();
 
160
                qDebug() << "output" << i << "resized" << oldSize << "->" << newSize;
 
161
 
 
162
                output->_setSize(newSize);
 
163
                emit outputResized(output, oldSize, newSize);
 
164
            }
 
165
 
 
166
            if (! isVirtual) {
 
167
                break;
 
168
            }
 
169
        }
 
170
    }
 
171
 
 
172
}
 
173