add more spacing
[personal-kdebase.git] / workspace / libs / kephal / kded_kephal / kephald.cpp
blob6809e1a4f1919a7458e6562ee24d664cb01f0bf8
1 /*
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 "kephald.h"
22 #include "config-kephal.h"
24 #include <QDebug>
25 #include <QDBusConnection>
26 #include <QApplication>
27 #include <QAbstractEventDispatcher>
29 #include <KConfig>
30 #include <KConfigGroup>
32 #ifdef HAS_RANDR_1_2
33 #include "xrandr12/randrdisplay.h"
34 #include "xrandr12/randrscreen.h"
35 #endif
37 #include "outputs/desktopwidget/desktopwidgetoutputs.h"
38 #include "screens/configuration/configurationscreens.h"
40 #ifdef HAS_RANDR_1_2
41 #include "outputs/xrandr/xrandroutputs.h"
42 #endif
44 #include "dbus/dbusapi_screens.h"
45 #include "dbus/dbusapi_outputs.h"
46 #include "dbus/dbusapi_configurations.h"
47 #include "configurations/xml/xmlconfigurations.h"
49 #include <kpluginfactory.h>
50 #include <kpluginloader.h>
51 #include <KApplication>
53 K_PLUGIN_FACTORY(KephalDFactory,
54 registerPlugin<KephalD>();
56 K_EXPORT_PLUGIN(KephalDFactory("kephal"))
60 using namespace Kephal;
64 KephalD::KephalD(QObject* parent, const QList<QVariant>&)
65 : KDEDModule(parent),
66 m_noXRandR(false)
68 qDebug() << "kephald starting up";
69 init();
72 KephalD::~KephalD()
74 if (m_eventFilter) {
75 delete m_eventFilter;
79 void KephalD::init() {
80 KConfig config("kephalrc");
81 KConfigGroup general(&config, "General");
82 m_noXRandR = general.readEntry("NoXRandR", false);
84 m_outputs = 0;
85 #ifdef HAS_RANDR_1_2
86 RandRDisplay * display;
87 if (! m_noXRandR) {
88 display = new RandRDisplay();
91 if ((! m_noXRandR) && display->isValid()) {
92 m_outputs = new XRandROutputs(this, display);
93 if (m_outputs->outputs().size() <= 1) {
94 delete m_outputs;
95 m_outputs = 0;
98 #endif
99 if (! m_outputs) {
100 new DesktopWidgetOutputs(this);
104 foreach (Output * output, Outputs::self()->outputs()) {
105 qDebug() << "output:" << output->id() << output->geom() << output->rotation() << output->reflectX() << output->reflectY();
108 new XMLConfigurations(this);
109 new ConfigurationScreens(this);
111 foreach (Kephal::Screen * screen, Screens::self()->screens()) {
112 qDebug() << "screen:" << screen->id() << screen->geom();
115 activateConfiguration();
116 connect(Outputs::self(), SIGNAL(outputDisconnected(Kephal::Output *)), this, SLOT(outputDisconnected(Kephal::Output *)));
117 connect(Outputs::self(), SIGNAL(outputConnected(Kephal::Output *)), this, SLOT(outputConnected(Kephal::Output *)));
119 QDBusConnection dbus = QDBusConnection::sessionBus();
120 bool result = dbus.registerService("org.kde.Kephal");
121 qDebug() << "registered the service:" << result;
123 new DBusAPIScreens(this);
124 new DBusAPIOutputs(this);
125 new DBusAPIConfigurations(this);
127 if (m_outputs) {
128 m_eventFilter = new X11EventFilter(m_outputs);
129 kapp->installX11EventFilter(m_eventFilter);
131 m_pollTimer = new QTimer(this);
132 connect(m_pollTimer, SIGNAL(timeout()), this, SLOT(poll()));
133 if (Configurations::self()->polling()) {
134 m_pollTimer->start(10000);
136 } else {
137 m_pollTimer = 0;
138 m_eventFilter = 0;
142 void KephalD::pollingActivated() {
143 if (m_pollTimer && m_outputs) {
144 m_pollTimer->start(10000);
148 void KephalD::pollingDeactivated() {
149 if (m_pollTimer && m_outputs) {
150 m_pollTimer->stop();
154 void KephalD::poll() {
155 #ifdef HAS_RANDR_1_2
156 if (m_outputs) {
157 m_outputs->display()->screen(0)->pollState();
159 #endif
162 void KephalD::activateConfiguration() {
163 BackendConfigurations * configs = BackendConfigurations::self();
164 Configuration * config = configs->findConfiguration();
165 configs->applyOutputSettings();
166 if (config) {
167 config->activate();
168 } else {
169 qDebug() << "couldnt find matching configuration!!";
173 void KephalD::outputDisconnected(Output * output) {
174 Q_UNUSED(output)
175 // activateConfiguration();
178 void KephalD::outputConnected(Output * output) {
179 Q_UNUSED(output)
180 // activateConfiguration();
183 #ifdef Q_WS_X11
184 bool X11EventFilter::x11Event(XEvent * e) {
185 #ifdef HAS_RANDR_1_2
186 if (m_outputs && m_outputs->display()->canHandle(e)) {
187 m_outputs->display()->handleEvent(e);
189 #endif
190 return false;
192 #endif
195 #include "kephald.moc"