not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / kcontrol / xinerama / kcmxinerama.cpp
blob044977d11ad1dca8f5e0cc449d4a6256574a50d8
1 /**
2 * kcmxinerama.cpp
4 * Copyright (c) 2002-2004 George Staikos <staikos@kde.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include "kcmxinerama.h"
23 #include <kaboutdata.h>
24 #include <kapplication.h>
25 #include <kconfig.h>
26 #include <kdialog.h>
27 #include <kglobal.h>
28 #include <kglobalsettings.h>
29 #include <klocale.h>
30 #include <kmessagebox.h>
31 #include <kpluginfactory.h>
32 #include <kpluginloader.h>
33 #include <QtDBus/QtDBus>
35 #include <QCheckBox>
36 #include <QtGui/QDesktopWidget>
37 #include <QLayout>
38 #include <QLabel>
39 #include <QComboBox>
40 #include <QColor>
41 #include <QPushButton>
42 //Added by qt3to4:
43 #include <QFrame>
44 #include <QGridLayout>
45 #include "kwin_interface.h"
47 K_PLUGIN_FACTORY(KCMXineramaFactory, registerPlugin<KCMXinerama>();)
48 K_EXPORT_PLUGIN(KCMXineramaFactory("kcmxinerama"))
51 KCMXinerama::KCMXinerama(QWidget *parent, const QVariantList &)
52 : KCModule(KCMXineramaFactory::componentData(), parent) {
54 KAboutData *about =
55 new KAboutData(I18N_NOOP("kcmxinerama"), 0,
56 ki18n("KDE Multiple Monitor Configurator"),
57 0, KLocalizedString(), KAboutData::License_GPL,
58 ki18n("(c) 2002-2003 George Staikos"));
60 about->addAuthor(ki18n("George Staikos"), KLocalizedString(), "staikos@kde.org");
61 setAboutData( about );
62 setButtons(Apply);
63 setQuickHelp( i18n("<h1>Multiple Monitors</h1> This module allows you to configure KDE support"
64 " for multiple monitors."));
66 config = new KConfig("kdeglobals", KConfig::NoGlobals);
67 ksplashrc = new KConfig("ksplashrc", KConfig::NoGlobals);
69 _timer.setSingleShot(true);
70 connect(&_timer, SIGNAL(timeout()), this, SLOT(clearIndicator()));
72 QGridLayout *grid = new QGridLayout(this );
73 grid->setMargin( KDialog::marginHint() );
74 grid->setSpacing( KDialog::spacingHint() );
76 // Setup the panel
77 _displays = QApplication::desktop()->numScreens();
79 if (QApplication::desktop()->isVirtualDesktop()) {
80 QStringList dpyList;
81 xw = new XineramaWidget(this);
82 grid->addWidget(xw, 0, 0);
84 xw->headTable->setRowCount(_displays);
86 for (int i = 0; i < _displays; i++) {
87 QString l = i18n("Display %1", i+1);
88 QRect geom = QApplication::desktop()->screenGeometry(i);
89 xw->_unmanagedDisplay->addItem(l);
90 dpyList.append(l);
91 QTableWidgetItem *item = new QTableWidgetItem(QString::number(geom.x()));
92 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
93 xw->headTable->setItem(i, 0, item);
94 item = new QTableWidgetItem(QString::number(geom.y()));
95 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
96 xw->headTable->setItem(i, 1, item);
97 item = new QTableWidgetItem(QString::number(geom.width()));
98 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
99 xw->headTable->setItem(i, 2, item);
100 item = new QTableWidgetItem(QString::number(geom.height()));
101 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
102 xw->headTable->setItem(i, 3, item);
105 xw->_unmanagedDisplay->addItem(i18n("Display Containing the Pointer"));
107 xw->headTable->setVerticalHeaderLabels(dpyList);
109 connect(xw->_unmanagedDisplay, SIGNAL(activated(int)),
110 this, SLOT(windowIndicator(int)));
111 connect(xw->_identify, SIGNAL(clicked()),
112 this, SLOT(indicateWindows()));
114 connect(xw, SIGNAL(configChanged()), this, SLOT(changed()));
115 } else { // no Xinerama
116 QLabel *ql = new QLabel(i18n("<qt><p>This module is only for configuring systems with a single desktop spread across multiple monitors. You do not appear to have this configuration.</p></qt>"), this);
117 grid->addWidget(ql, 0, 0);
120 grid->activate();
123 KCMXinerama::~KCMXinerama() {
124 _timer.stop();
125 delete ksplashrc;
126 ksplashrc = 0;
127 delete config;
128 config = 0;
129 clearIndicator();
132 #define KWIN_XINERAMA "XineramaEnabled"
133 #define KWIN_XINERAMA_MOVEMENT "XineramaMovementEnabled"
134 #define KWIN_XINERAMA_PLACEMENT "XineramaPlacementEnabled"
135 #define KWIN_XINERAMA_MAXIMIZE "XineramaMaximizeEnabled"
136 #define KWIN_XINERAMA_FULLSCREEN "XineramaFullscreenEnabled"
138 void KCMXinerama::load() {
139 if (QApplication::desktop()->isVirtualDesktop()) {
140 int item = 0;
141 KConfigGroup group = config->group("Windows");
142 xw->_enableXinerama->setChecked(group.readEntry(KWIN_XINERAMA, true));
143 xw->_enableResistance->setChecked(group.readEntry(KWIN_XINERAMA_MOVEMENT, true));
144 xw->_enablePlacement->setChecked(group.readEntry(KWIN_XINERAMA_PLACEMENT, true));
145 xw->_enableMaximize->setChecked(group.readEntry(KWIN_XINERAMA_MAXIMIZE, true));
146 xw->_enableFullscreen->setChecked(group.readEntry(KWIN_XINERAMA_FULLSCREEN, true));
147 item = group.readEntry("Unmanaged", QApplication::desktop()->primaryScreen());
148 if ((item < 0 || item >= _displays) && (item != -3))
149 xw->_unmanagedDisplay->setCurrentIndex(QApplication::desktop()->primaryScreen());
150 else if (item == -3) // pointer warp
151 xw->_unmanagedDisplay->setCurrentIndex(_displays);
152 else xw->_unmanagedDisplay->setCurrentIndex(item);
154 emit changed(false);
158 void KCMXinerama::save() {
159 if (QApplication::desktop()->isVirtualDesktop()) {
160 KConfigGroup group = config->group("Windows");
161 group.writeEntry(KWIN_XINERAMA,
162 xw->_enableXinerama->isChecked());
163 group.writeEntry(KWIN_XINERAMA_MOVEMENT,
164 xw->_enableResistance->isChecked());
165 group.writeEntry(KWIN_XINERAMA_PLACEMENT,
166 xw->_enablePlacement->isChecked());
167 group.writeEntry(KWIN_XINERAMA_MAXIMIZE,
168 xw->_enableMaximize->isChecked());
169 group.writeEntry(KWIN_XINERAMA_FULLSCREEN,
170 xw->_enableFullscreen->isChecked());
171 int item = xw->_unmanagedDisplay->currentIndex();
172 group.writeEntry("Unmanaged", item == _displays ? -3 : item);
173 group.sync();
175 org::kde::KWin kwin("org.kde.kwin", "/KWin", QDBusConnection::sessionBus());
176 kwin.reconfigure();
179 KMessageBox::information(this, i18n("Some settings may affect only newly started applications."), i18n("KDE Multiple Monitors"), "nomorexineramaplease");
181 emit changed(false);
184 void KCMXinerama::defaults() {
185 if (QApplication::desktop()->isVirtualDesktop()) {
186 xw->_enableXinerama->setChecked(true);
187 xw->_enableResistance->setChecked(true);
188 xw->_enablePlacement->setChecked(true);
189 xw->_enableMaximize->setChecked(true);
190 xw->_enableFullscreen->setChecked(true);
191 xw->_unmanagedDisplay->setCurrentIndex(
192 QApplication::desktop()->primaryScreen());
193 emit changed(true);
194 } else {
195 emit changed(false);
199 void KCMXinerama::indicateWindows() {
200 _timer.stop();
202 clearIndicator();
203 for (int i = 0; i < _displays; i++)
204 _indicators.append(indicator(i));
206 _timer.start(1500);
209 void KCMXinerama::windowIndicator(int dpy) {
210 if (dpy >= _displays)
211 return;
213 _timer.stop();
215 clearIndicator();
216 _indicators.append(indicator(dpy));
218 _timer.start(1500);
221 QWidget *KCMXinerama::indicator(int dpy) {
222 QLabel *si = new QLabel(QString::number(dpy+1), 0, Qt::X11BypassWindowManagerHint);
224 QFont fnt = KGlobalSettings::generalFont();
225 fnt.setPixelSize(100);
226 si->setFont(fnt);
227 si->setFrameStyle(QFrame::Panel);
228 si->setFrameShadow(QFrame::Plain);
229 si->setAlignment(Qt::AlignCenter);
231 QPoint screenCenter(QApplication::desktop()->screenGeometry(dpy).center());
232 QRect targetGeometry(QPoint(0,0), si->sizeHint());
233 targetGeometry.moveCenter(screenCenter);
234 si->setGeometry(targetGeometry);
235 si->show();
237 return si;
240 void KCMXinerama::clearIndicator() {
241 qDeleteAll(_indicators);
242 _indicators.clear();
245 #include "kcmxinerama.moc"