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
) {
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 grid
->addWidget(ql
, 0, 0);
123 KCMXinerama::~KCMXinerama() {
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()) {
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
);
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
);
175 org::kde::KWin
kwin("org.kde.kwin", "/KWin", QDBusConnection::sessionBus());
179 KMessageBox::information(this, i18n("Some settings may affect only newly started applications."), i18n("KDE Multiple Monitors"), "nomorexineramaplease");
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());
199 void KCMXinerama::indicateWindows() {
203 for (int i
= 0; i
< _displays
; i
++)
204 _indicators
.append(indicator(i
));
209 void KCMXinerama::windowIndicator(int dpy
) {
210 if (dpy
>= _displays
)
216 _indicators
.append(indicator(dpy
));
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);
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
);
240 void KCMXinerama::clearIndicator() {
241 qDeleteAll(_indicators
);
245 #include "kcmxinerama.moc"