not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / libs / kephal / kephald / kephald.cpp
blob69319d07006b2a14d5686b64aac88bd7377f4f3e
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"
23 #include <QDebug>
24 #include <QDBusConnection>
25 #include <QApplication>
26 #include <QAbstractEventDispatcher>
27 #include <QThread>
30 #include "outputs/desktopwidget/desktopwidgetoutputs.h"
31 #include "screens/configuration/configurationscreens.h"
32 #ifdef Q_WS_X11
33 #include "outputs/xrandr/xrandroutputs.h"
34 #endif
35 #include "dbus/dbusapi_screens.h"
36 #include "dbus/dbusapi_outputs.h"
37 #include "dbus/dbusapi_configurations.h"
38 #include "configurations/xml/xmlconfigurations.h"
39 #ifdef Q_WS_X11
40 #include "xrandr12/randrdisplay.h"
41 #include "xrandr12/randrscreen.h"
42 #endif
46 using namespace Kephal;
49 int main(int argc, char *argv[])
51 KephalD app(argc, argv);
53 return app.exec();
57 KephalD::KephalD(int & argc, char ** argv)
58 : QApplication(argc, argv),
59 m_noXRandR(false)
61 qDebug() << "kephald starting up";
63 parseArgs(argc, argv);
64 init();
67 KephalD::~KephalD()
71 void KephalD::parseArgs(int & argc, char ** argv) {
72 for (int i = 0; i < argc; ++i) {
73 QString arg(argv[i]);
74 qDebug() << "arg:" << i << arg;
76 if (arg == "--no-xrandr") {
77 m_noXRandR = true;
82 void KephalD::init() {
83 RandRDisplay * display;
84 if (! m_noXRandR) {
85 display = new RandRDisplay();
88 if ((! m_noXRandR) && display->isValid()) {
89 m_outputs = new XRandROutputs(this, display);
90 } else {
91 m_outputs = 0;
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);
123 if (m_outputs) {
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);
129 } else {
130 m_pollTimer = 0;
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) {
142 m_pollTimer->stop();
146 void KephalD::poll() {
147 if (m_outputs) {
148 m_outputs->display()->screen(0)->pollState();
152 #ifdef Q_WS_X11
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);
161 #endif
163 void KephalD::activateConfiguration() {
164 BackendConfigurations * configs = BackendConfigurations::self();
165 Configuration * config = configs->findConfiguration();
166 configs->applyOutputSettings();
167 if (config) {
168 config->activate();
169 } else {
170 qDebug() << "couldnt find matching configuration!!";
174 void KephalD::outputDisconnected(Output * output) {
175 // activateConfiguration();
178 void KephalD::outputConnected(Output * output) {
179 // activateConfiguration();