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 "dbusscreens.h"
25 #include "../simplescreen.h"
26 #include "screens_interface.h"
27 #include "kephal/outputs.h"
32 DBusScreens::DBusScreens(QObject
* parent
)
35 m_interface
= new org::kde::Kephal::Screens(
38 QDBusConnection::sessionBus(),
41 if (! m_interface
->isValid()) {
48 int numScreens
= m_interface
->numScreens();
49 for (int i
= 0; i
< numScreens
; ++i
) {
50 int id
= m_interface
->id(i
);
51 QPoint pos
= m_interface
->position(id
);
52 QSize size
= m_interface
->size(id
);
53 //qDebug() << "adding a screen" << id << "with geom: " << pos << size;
55 SimpleScreen
* screen
= new SimpleScreen(this,
60 m_screens
.append(screen
);
62 const QStringList outputIds
= m_interface
->outputs(id
);
63 foreach (const QString
& outputId
, outputIds
) {
64 Output
* output
= Outputs::self()->output(outputId
);
66 screen
->_outputs() << output
;
71 connect(m_interface
, SIGNAL(screenResized(int)), this, SLOT(screenResizedSlot(int)));
72 connect(m_interface
, SIGNAL(screenMoved(int)), this, SLOT(screenMovedSlot(int)));
73 connect(m_interface
, SIGNAL(screenAdded(int)), this, SLOT(screenAddedSlot(int)));
74 connect(m_interface
, SIGNAL(screenRemoved(int)), this, SLOT(screenRemovedSlot(int)));
77 void DBusScreens::screenResizedSlot(int id
) {
78 SimpleScreen
* s
= (SimpleScreen
*) screen(id
);
80 QSize prev
= s
->size();
81 s
->_setSize(m_interface
->size(id
));
82 emit
screenResized(s
, prev
, s
->size());
86 void DBusScreens::screenMovedSlot(int id
) {
87 SimpleScreen
* s
= (SimpleScreen
*) screen(id
);
89 QPoint prev
= s
->position();
90 s
->_setPosition(m_interface
->position(id
));
91 emit
screenMoved(s
, prev
, s
->position());
95 void DBusScreens::screenAddedSlot(int id
) {
96 QPoint pos
= m_interface
->position(id
);
97 QSize size
= m_interface
->size(id
);
98 //qDebug() << "adding a screen" << id << "with geom: " << pos << size;
100 SimpleScreen
* screen
= new SimpleScreen(this,
105 m_screens
.append(screen
);
107 const QStringList outputIds
= m_interface
->outputs(id
);
108 foreach (const QString
& outputId
, outputIds
) {
109 Output
* output
= Outputs::self()->output(outputId
);
111 screen
->_outputs() << output
;
115 emit
screenAdded(screen
);
118 void DBusScreens::screenRemovedSlot(int id
) {
119 SimpleScreen
* s
= (SimpleScreen
*) screen(id
);
121 m_screens
.removeAll(s
);
123 emit
screenRemoved(id
);
128 DBusScreens::~DBusScreens() {
129 foreach(Screen
* screen
, m_screens
) {
135 QList
<Screen
*> DBusScreens::screens()
137 QList
<Screen
*> result
;
138 foreach(SimpleScreen
* screen
, m_screens
) {
139 result
.append(screen
);
144 bool DBusScreens::isValid() {