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.
20
#include "kephalservice.h"
22
#include "config-kephal.h"
24
#include <QDBusConnection>
25
#include <QApplication>
28
#include <KApplication>
30
#include <KConfigGroup>
35
#include "xrandr12/randrdisplay.h"
36
#include "xrandr12/randrscreen.h"
37
#include "xrandroutputs.h"
40
#include "desktopwidgetoutputs.h"
41
#include "configurationscreens.h"
43
#include "dbus/dbusapi_screens.h"
44
#include "dbus/dbusapi_outputs.h"
45
#include "dbus/dbusapi_configurations.h"
46
#include "xmlconfigurations.h"
48
using namespace Kephal;
50
X11EventFilter::X11EventFilter(Kephal::XRandROutputs * outputs)
54
X11EventFilter::~X11EventFilter()
58
bool X11EventFilter::x11Event(XEvent * e) {
60
if (m_outputs && m_outputs->display()->canHandle(e)) {
61
m_outputs->display()->handleEvent(e);
68
KephalService::KephalService(QObject * parent)
72
kDebug() << "kephald starting up";
76
KephalService::~KephalService()
81
void KephalService::init()
82
{ KConfig config("kephalrc");
83
KConfigGroup general(&config, "General");
84
m_noXRandR = general.readEntry("NoXRandR", false);
88
RandRDisplay * display;
90
display = new RandRDisplay();
93
if ((! m_noXRandR) && display->isValid()) {
94
m_outputs = new XRandROutputs(this, display);
95
if (m_outputs->outputs().size() <= 1) {
102
//new DesktopWidgetOutputs(this);
106
foreach (Output * output, Outputs::self()->outputs()) {
107
kDebug() << "output:" << output->id() << output->geom() << output->rotation() << output->reflectX() << output->reflectY();
110
new XMLConfigurations(this);
111
//new ConfigurationScreens(this);
113
//X foreach (Kephal::Screen * screen, Screens::self()->screens()) {
114
//X kDebug() << "screen:" << screen->id() << screen->geom();
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 *)));
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);
126
QDBusConnection dbus = QDBusConnection::sessionBus();
127
bool result = dbus.registerService("org.kde.Kephal");
128
kDebug() << "registered the service:" << result;
130
//new DBusAPIScreens(this);
131
//new DBusAPIOutputs(this);
132
//new DBusAPIConfigurations(this);
135
m_eventFilter = new X11EventFilter(m_outputs);
136
kapp->installX11EventFilter(m_eventFilter);
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);
149
void KephalService::pollingActivated()
151
if (m_pollTimer && m_outputs) {
152
m_pollTimer->start(10000);
156
void KephalService::pollingDeactivated()
158
if (m_pollTimer && m_outputs) {
163
void KephalService::poll()
167
m_outputs->display()->screen(0)->pollState();
172
void KephalService::activateConfiguration()
174
//X BackendConfigurations * configs = BackendConfigurations::self();
175
//X Configuration * config = configs->findConfiguration();
176
//X configs->applyOutputSettings();
178
//X config->activate();
180
//X kDebug() << "couldnt find matching configuration!!";
184
void KephalService::outputDisconnected(Output * output)
187
// activateConfiguration();
190
void KephalService::outputConnected(Output * output)
193
// activateConfiguration();
196
#include "kephalservice.moc"
198
// vim: sw=4 sts=4 et tw=100