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>
28
#include <kglobalsettings.h>
30
#include <kmessagebox.h>
31
#include <kpluginfactory.h>
32
#include <kpluginloader.h>
33
#include <QtDBus/QtDBus>
36
#include <QtGui/QDesktopWidget>
41
#include <QPushButton>
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), xw(0) {
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 );
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() );
77
_displays = QApplication::desktop()->numScreens();
79
if (QApplication::desktop()->isVirtualDesktop()) {
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);
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
ql->setWordWrap(true);
118
grid->addWidget(ql, 0, 0);
124
KCMXinerama::~KCMXinerama() {
133
#define KWIN_XINERAMA "XineramaEnabled"
134
#define KWIN_XINERAMA_MOVEMENT "XineramaMovementEnabled"
135
#define KWIN_XINERAMA_PLACEMENT "XineramaPlacementEnabled"
136
#define KWIN_XINERAMA_MAXIMIZE "XineramaMaximizeEnabled"
137
#define KWIN_XINERAMA_FULLSCREEN "XineramaFullscreenEnabled"
139
void KCMXinerama::load() {
140
if (QApplication::desktop()->isVirtualDesktop() && xw) {
142
KConfigGroup group = config->group("Windows");
143
xw->_enableXinerama->setChecked(group.readEntry(KWIN_XINERAMA, true));
144
xw->_enableResistance->setChecked(group.readEntry(KWIN_XINERAMA_MOVEMENT, true));
145
xw->_enablePlacement->setChecked(group.readEntry(KWIN_XINERAMA_PLACEMENT, true));
146
xw->_enableMaximize->setChecked(group.readEntry(KWIN_XINERAMA_MAXIMIZE, true));
147
xw->_enableFullscreen->setChecked(group.readEntry(KWIN_XINERAMA_FULLSCREEN, true));
148
item = group.readEntry("Unmanaged", QApplication::desktop()->primaryScreen());
149
if ((item < 0 || item >= _displays) && (item != -3))
150
xw->_unmanagedDisplay->setCurrentIndex(QApplication::desktop()->primaryScreen());
151
else if (item == -3) // pointer warp
152
xw->_unmanagedDisplay->setCurrentIndex(_displays);
153
else xw->_unmanagedDisplay->setCurrentIndex(item);
159
void KCMXinerama::save() {
160
if (QApplication::desktop()->isVirtualDesktop() && xw) {
161
KConfigGroup group = config->group("Windows");
162
group.writeEntry(KWIN_XINERAMA,
163
xw->_enableXinerama->isChecked());
164
group.writeEntry(KWIN_XINERAMA_MOVEMENT,
165
xw->_enableResistance->isChecked());
166
group.writeEntry(KWIN_XINERAMA_PLACEMENT,
167
xw->_enablePlacement->isChecked());
168
group.writeEntry(KWIN_XINERAMA_MAXIMIZE,
169
xw->_enableMaximize->isChecked());
170
group.writeEntry(KWIN_XINERAMA_FULLSCREEN,
171
xw->_enableFullscreen->isChecked());
172
int item = xw->_unmanagedDisplay->currentIndex();
173
group.writeEntry("Unmanaged", item == _displays ? -3 : item);
176
org::kde::KWin kwin("org.kde.kwin", "/KWin", QDBusConnection::sessionBus());
180
KMessageBox::information(this, i18n("Some settings may affect only newly started applications."), i18n("KDE Multiple Monitors"), "nomorexineramaplease");
185
void KCMXinerama::defaults() {
186
if (QApplication::desktop()->isVirtualDesktop() && xw) {
187
xw->_enableXinerama->setChecked(true);
188
xw->_enableResistance->setChecked(true);
189
xw->_enablePlacement->setChecked(true);
190
xw->_enableMaximize->setChecked(true);
191
xw->_enableFullscreen->setChecked(true);
192
xw->_unmanagedDisplay->setCurrentIndex(
193
QApplication::desktop()->primaryScreen());
200
void KCMXinerama::indicateWindows() {
204
for (int i = 0; i < _displays; i++)
205
_indicators.append(indicator(i));
210
void KCMXinerama::windowIndicator(int dpy) {
211
if (dpy >= _displays)
217
_indicators.append(indicator(dpy));
222
QWidget *KCMXinerama::indicator(int dpy) {
223
QLabel *si = new QLabel(QString::number(dpy+1), 0, Qt::X11BypassWindowManagerHint);
225
QFont fnt = KGlobalSettings::generalFont();
226
fnt.setPixelSize(100);
228
si->setFrameStyle(QFrame::Panel);
229
si->setFrameShadow(QFrame::Plain);
230
si->setAlignment(Qt::AlignCenter);
232
QPoint screenCenter(QApplication::desktop()->screenGeometry(dpy).center());
233
QRect targetGeometry(QPoint(0,0), si->sizeHint());
234
targetGeometry.moveCenter(screenCenter);
235
si->setGeometry(targetGeometry);
241
void KCMXinerama::clearIndicator() {
242
qDeleteAll(_indicators);
246
#include "kcmxinerama.moc"