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.
24 #include <QDBusConnection>
25 #include <QApplication>
26 #include <QAbstractEventDispatcher>
30 #include "outputs/desktopwidget/desktopwidgetoutputs.h"
31 #include "screens/configuration/configurationscreens.h"
33 #include "outputs/xrandr/xrandroutputs.h"
35 #include "dbus/dbusapi_screens.h"
36 #include "dbus/dbusapi_outputs.h"
37 #include "dbus/dbusapi_configurations.h"
38 #include "configurations/xml/xmlconfigurations.h"
40 #include "xrandr12/randrdisplay.h"
41 #include "xrandr12/randrscreen.h"
46 using namespace Kephal
;
49 int main(int argc
, char *argv
[])
51 KephalD
app(argc
, argv
);
57 KephalD::KephalD(int & argc
, char ** argv
)
58 : QApplication(argc
, argv
),
61 qDebug() << "kephald starting up";
63 parseArgs(argc
, argv
);
71 void KephalD::parseArgs(int & argc
, char ** argv
) {
72 for (int i
= 0; i
< argc
; ++i
) {
74 qDebug() << "arg:" << i
<< arg
;
76 if (arg
== "--no-xrandr") {
82 void KephalD::init() {
83 RandRDisplay
* display
;
85 display
= new RandRDisplay();
88 if ((! m_noXRandR
) && display
->isValid()) {
89 m_outputs
= new XRandROutputs(this, display
);
92 new DesktopWidgetOutputs(this);
95 foreach (Output
* output
, Outputs::self()->outputs()) {
96 qDebug() << "output:" << output
->id() << output
->geom() << output
->rotation() << output
->reflectX() << output
->reflectY();
99 new XMLConfigurations(this);
100 new ConfigurationScreens(this);
102 foreach (Kephal::Screen
* screen
, Screens::self()->screens()) {
103 qDebug() << "screen:" << screen
->id() << screen
->geom();
106 activateConfiguration();
107 connect(Outputs::self(), SIGNAL(outputDisconnected(Kephal::Output
*)), this, SLOT(outputDisconnected(Kephal::Output
*)));
108 connect(Outputs::self(), SIGNAL(outputConnected(Kephal::Output
*)), this, SLOT(outputConnected(Kephal::Output
*)));
110 qDebug() << "will check for possible positions...";
111 foreach (Output
* output
, Outputs::self()->outputs()) {
112 qDebug() << "possible positions for:" << output
->id() << Configurations::self()->possiblePositions(output
);
115 QDBusConnection dbus
= QDBusConnection::sessionBus();
116 bool result
= dbus
.registerService("org.kde.Kephal");
117 qDebug() << "registered the service:" << result
;
119 new DBusAPIScreens(this);
120 new DBusAPIOutputs(this);
121 new DBusAPIConfigurations(this);
124 m_pollTimer
= new QTimer(this);
125 connect(m_pollTimer
, SIGNAL(timeout()), this, SLOT(poll()));
126 if (Configurations::self()->polling()) {
127 m_pollTimer
->start(10000);
134 void KephalD::pollingActivated() {
135 if (m_pollTimer
&& m_outputs
) {
136 m_pollTimer
->start(10000);
140 void KephalD::pollingDeactivated() {
141 if (m_pollTimer
&& m_outputs
) {
146 void KephalD::poll() {
148 m_outputs
->display()->screen(0)->pollState();
153 bool KephalD::x11EventFilter(XEvent
* e
)
155 if (m_outputs
&& m_outputs
->display()->canHandle(e
)) {
156 m_outputs
->display()->handleEvent(e
);
159 return QApplication::x11EventFilter(e
);
163 void KephalD::activateConfiguration() {
164 BackendConfigurations
* configs
= BackendConfigurations::self();
165 Configuration
* config
= configs
->findConfiguration();
166 configs
->applyOutputSettings();
170 qDebug() << "couldnt find matching configuration!!";
174 void KephalD::outputDisconnected(Output
* output
) {
175 // activateConfiguration();
178 void KephalD::outputConnected(Output
* output
) {
179 // activateConfiguration();