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.
22 #include "config-kephal.h"
25 #include <QDBusConnection>
26 #include <QApplication>
27 #include <QAbstractEventDispatcher>
30 #include <KConfigGroup>
33 #include "xrandr12/randrdisplay.h"
34 #include "xrandr12/randrscreen.h"
37 #include "outputs/desktopwidget/desktopwidgetoutputs.h"
38 #include "screens/configuration/configurationscreens.h"
41 #include "outputs/xrandr/xrandroutputs.h"
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
>&)
68 qDebug() << "kephald starting up";
79 void KephalD::init() {
80 KConfig
config("kephalrc");
81 KConfigGroup
general(&config
, "General");
82 m_noXRandR
= general
.readEntry("NoXRandR", false);
86 RandRDisplay
* display
;
88 display
= new RandRDisplay();
91 if ((! m_noXRandR
) && display
->isValid()) {
92 m_outputs
= new XRandROutputs(this, display
);
93 if (m_outputs
->outputs().size() <= 1) {
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);
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);
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
) {
154 void KephalD::poll() {
157 m_outputs
->display()->screen(0)->pollState();
162 void KephalD::activateConfiguration() {
163 BackendConfigurations
* configs
= BackendConfigurations::self();
164 Configuration
* config
= configs
->findConfiguration();
165 configs
->applyOutputSettings();
169 qDebug() << "couldnt find matching configuration!!";
173 void KephalD::outputDisconnected(Output
* output
) {
175 // activateConfiguration();
178 void KephalD::outputConnected(Output
* output
) {
180 // activateConfiguration();
184 bool X11EventFilter::x11Event(XEvent
* e
) {
186 if (m_outputs
&& m_outputs
->display()->canHandle(e
)) {
187 m_outputs
->display()->handleEvent(e
);
195 #include "kephald.moc"