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

« back to all changes in this revision

Viewing changes to libs/kephal/service/kephalservice.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
#include "kephalservice.h"
 
21
 
 
22
#include "config-kephal.h"
 
23
 
 
24
#include <QDBusConnection>
 
25
#include <QApplication>
 
26
#include <QTimer>
 
27
 
 
28
#include <KApplication>
 
29
#include <KConfig>
 
30
#include <KConfigGroup>
 
31
#include <KDebug>
 
32
 
 
33
 
 
34
#ifdef HAS_RANDR_1_2
 
35
#include "xrandr12/randrdisplay.h"
 
36
#include "xrandr12/randrscreen.h"
 
37
#include "xrandroutputs.h"
 
38
#endif
 
39
 
 
40
#include "desktopwidgetoutputs.h"
 
41
#include "configurationscreens.h"
 
42
 
 
43
#include "dbus/dbusapi_screens.h"
 
44
#include "dbus/dbusapi_outputs.h"
 
45
#include "dbus/dbusapi_configurations.h"
 
46
#include "xmlconfigurations.h"
 
47
 
 
48
using namespace Kephal;
 
49
 
 
50
X11EventFilter::X11EventFilter(Kephal::XRandROutputs * outputs)
 
51
: m_outputs(outputs)
 
52
{}
 
53
 
 
54
X11EventFilter::~X11EventFilter()
 
55
{}
 
56
 
 
57
#ifdef Q_WS_X11
 
58
bool X11EventFilter::x11Event(XEvent * e) {
 
59
#ifdef HAS_RANDR_1_2
 
60
    if (m_outputs && m_outputs->display()->canHandle(e)) {
 
61
        m_outputs->display()->handleEvent(e);
 
62
    }
 
63
#endif
 
64
    return false;
 
65
}
 
66
#endif
 
67
 
 
68
KephalService::KephalService(QObject * parent)
 
69
    : QObject(parent),
 
70
    m_noXRandR(false)
 
71
{
 
72
    kDebug() << "kephald starting up";
 
73
    init();
 
74
}
 
75
 
 
76
KephalService::~KephalService()
 
77
{
 
78
    delete m_eventFilter;
 
79
}
 
80
 
 
81
void KephalService::init()
 
82
{ KConfig config("kephalrc");
 
83
    KConfigGroup general(&config, "General");
 
84
    m_noXRandR = general.readEntry("NoXRandR", false);
 
85
 
 
86
    m_outputs = 0;
 
87
#ifdef HAS_RANDR_1_2
 
88
    RandRDisplay * display;
 
89
    if (! m_noXRandR) {
 
90
        display = new RandRDisplay();
 
91
    }
 
92
 
 
93
    if ((! m_noXRandR) && display->isValid()) {
 
94
        m_outputs = new XRandROutputs(this, display);
 
95
        if (m_outputs->outputs().size() <= 1) {
 
96
            delete m_outputs;
 
97
            m_outputs = 0;
 
98
        }
 
99
    }
 
100
#endif
 
101
    if (! m_outputs) {
 
102
        //new DesktopWidgetOutputs(this);
 
103
 
 
104
    }
 
105
 
 
106
    foreach (Output * output, Outputs::self()->outputs()) {
 
107
        kDebug() << "output:" << output->id() << output->geom() << output->rotation() << output->reflectX() << output->reflectY();
 
108
    }
 
109
 
 
110
    new XMLConfigurations(this);
 
111
    //new ConfigurationScreens(this);
 
112
 
 
113
//X     foreach (Kephal::Screen * screen, Screens::self()->screens()) {
 
114
//X         kDebug() << "screen:" << screen->id() << screen->geom();
 
115
//X     }
 
116
//X 
 
117
    activateConfiguration();
 
118
    connect(Outputs::self(), SIGNAL(outputDisconnected(Kephal::Output *)), this, SLOT(outputDisconnected(Kephal::Output *)));
 
119
    connect(Outputs::self(), SIGNAL(outputConnected(Kephal::Output *)), this, SLOT(outputConnected(Kephal::Output *)));
 
120
 
 
121
//X     kDebug() << "will check for possible positions...";
 
122
//X     foreach (Output * output, Outputs::self()->outputs()) {
 
123
//X         kDebug() << "possible positions for:" << output->id() << Configurations::self()->possiblePositions(output);
 
124
//X     }
 
125
 
 
126
    QDBusConnection dbus = QDBusConnection::sessionBus();
 
127
    bool result = dbus.registerService("org.kde.Kephal");
 
128
    kDebug() << "registered the service:" << result;
 
129
 
 
130
    //new DBusAPIScreens(this);
 
131
    //new DBusAPIOutputs(this);
 
132
    //new DBusAPIConfigurations(this);
 
133
 
 
134
    if (m_outputs) {
 
135
        m_eventFilter = new X11EventFilter(m_outputs);
 
136
        kapp->installX11EventFilter(m_eventFilter);
 
137
 
 
138
        m_pollTimer = new QTimer(this);
 
139
        connect(m_pollTimer, SIGNAL(timeout()), this, SLOT(poll()));
 
140
//X         if (Configurations::self()->polling()) {
 
141
//X             m_pollTimer->start(10000);
 
142
//X         }
 
143
    } else {
 
144
        m_pollTimer = 0;
 
145
        m_eventFilter = 0;
 
146
    }
 
147
}
 
148
 
 
149
void KephalService::pollingActivated()
 
150
{
 
151
    if (m_pollTimer && m_outputs) {
 
152
        m_pollTimer->start(10000);
 
153
    }
 
154
}
 
155
 
 
156
void KephalService::pollingDeactivated()
 
157
{
 
158
    if (m_pollTimer && m_outputs) {
 
159
        m_pollTimer->stop();
 
160
    }
 
161
}
 
162
 
 
163
void KephalService::poll()
 
164
{
 
165
#ifdef HAS_RANDR_1_2
 
166
    if (m_outputs) {
 
167
        m_outputs->display()->screen(0)->pollState();
 
168
    }
 
169
#endif
 
170
}
 
171
 
 
172
void KephalService::activateConfiguration()
 
173
{
 
174
//X     BackendConfigurations * configs = BackendConfigurations::self();
 
175
//X     Configuration * config = configs->findConfiguration();
 
176
//X     configs->applyOutputSettings();
 
177
//X     if (config) {
 
178
//X         config->activate();
 
179
//X     } else {
 
180
//X         kDebug() << "couldnt find matching configuration!!";
 
181
//X     }
 
182
}
 
183
 
 
184
void KephalService::outputDisconnected(Output * output)
 
185
{
 
186
    Q_UNUSED(output)
 
187
//     activateConfiguration();
 
188
}
 
189
 
 
190
void KephalService::outputConnected(Output * output)
 
191
{
 
192
    Q_UNUSED(output)
 
193
//     activateConfiguration();
 
194
}
 
195
 
 
196
#include "kephalservice.moc"
 
197
 
 
198
// vim: sw=4 sts=4 et tw=100