~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kcontrol/xinerama/kcmxinerama.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * kcmxinerama.cpp
 
3
 *
 
4
 * Copyright (c) 2002-2004 George Staikos <staikos@kde.org>
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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.
 
19
 */
 
20
 
 
21
 
 
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>
 
34
 
 
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"
 
46
 
 
47
K_PLUGIN_FACTORY(KCMXineramaFactory, registerPlugin<KCMXinerama>();)
 
48
K_EXPORT_PLUGIN(KCMXineramaFactory("kcmxinerama"))
 
49
 
 
50
 
 
51
KCMXinerama::KCMXinerama(QWidget *parent, const QVariantList &)
 
52
  : KCModule(KCMXineramaFactory::componentData(), parent), xw(0) {
 
53
 
 
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"));
 
59
 
 
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."));
 
65
 
 
66
        config = new KConfig("kdeglobals", KConfig::NoGlobals);
 
67
        ksplashrc = new KConfig("ksplashrc", KConfig::NoGlobals);
 
68
 
 
69
        _timer.setSingleShot(true);
 
70
        connect(&_timer, SIGNAL(timeout()), this, SLOT(clearIndicator()));
 
71
 
 
72
        QGridLayout *grid = new QGridLayout(this );
 
73
        grid->setMargin( KDialog::marginHint() );
 
74
        grid->setSpacing( KDialog::spacingHint() );
 
75
 
 
76
        // Setup the panel
 
77
        _displays = QApplication::desktop()->numScreens();
 
78
 
 
79
        if (QApplication::desktop()->isVirtualDesktop()) {
 
80
                QStringList dpyList;
 
81
                xw = new XineramaWidget(this);
 
82
                grid->addWidget(xw, 0, 0);
 
83
 
 
84
                xw->headTable->setRowCount(_displays);
 
85
 
 
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);
 
103
                }
 
104
 
 
105
                xw->_unmanagedDisplay->addItem(i18n("Display Containing the Pointer"));
 
106
 
 
107
                xw->headTable->setVerticalHeaderLabels(dpyList);
 
108
 
 
109
                connect(xw->_unmanagedDisplay, SIGNAL(activated(int)),
 
110
                        this, SLOT(windowIndicator(int)));
 
111
                connect(xw->_identify, SIGNAL(clicked()),
 
112
                        this, SLOT(indicateWindows()));
 
113
 
 
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);
 
119
        }
 
120
 
 
121
        grid->activate();
 
122
}
 
123
 
 
124
KCMXinerama::~KCMXinerama() {
 
125
        _timer.stop();
 
126
        delete ksplashrc;
 
127
        ksplashrc = 0;
 
128
        delete config;
 
129
        config = 0;
 
130
        clearIndicator();
 
131
}
 
132
 
 
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"
 
138
 
 
139
void KCMXinerama::load() {
 
140
        if (QApplication::desktop()->isVirtualDesktop() && xw) {
 
141
                int item = 0;
 
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);
 
154
        }
 
155
        emit changed(false);
 
156
}
 
157
 
 
158
 
 
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);
 
174
                group.sync();
 
175
 
 
176
                org::kde::KWin kwin("org.kde.kwin", "/KWin", QDBusConnection::sessionBus());
 
177
                kwin.reconfigure();
 
178
        }
 
179
 
 
180
        KMessageBox::information(this, i18n("Some settings may affect only newly started applications."), i18n("KDE Multiple Monitors"), "nomorexineramaplease");
 
181
 
 
182
        emit changed(false);
 
183
}
 
184
 
 
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());
 
194
                emit changed(true);
 
195
        } else {
 
196
                emit changed(false);
 
197
        }
 
198
}
 
199
 
 
200
void KCMXinerama::indicateWindows() {
 
201
        _timer.stop();
 
202
 
 
203
        clearIndicator();
 
204
        for (int i = 0; i < _displays; i++)
 
205
                _indicators.append(indicator(i));
 
206
 
 
207
        _timer.start(1500);
 
208
}
 
209
 
 
210
void KCMXinerama::windowIndicator(int dpy) {
 
211
        if (dpy >= _displays)
 
212
                return;
 
213
 
 
214
        _timer.stop();
 
215
 
 
216
        clearIndicator();
 
217
        _indicators.append(indicator(dpy));
 
218
 
 
219
        _timer.start(1500);
 
220
}
 
221
 
 
222
QWidget *KCMXinerama::indicator(int dpy) {
 
223
        QLabel *si = new QLabel(QString::number(dpy+1), 0, Qt::X11BypassWindowManagerHint);
 
224
 
 
225
        QFont fnt = KGlobalSettings::generalFont();
 
226
        fnt.setPixelSize(100);
 
227
        si->setFont(fnt);
 
228
        si->setFrameStyle(QFrame::Panel);
 
229
        si->setFrameShadow(QFrame::Plain);
 
230
        si->setAlignment(Qt::AlignCenter);
 
231
 
 
232
        QPoint screenCenter(QApplication::desktop()->screenGeometry(dpy).center());
 
233
        QRect targetGeometry(QPoint(0,0), si->sizeHint());
 
234
        targetGeometry.moveCenter(screenCenter);
 
235
        si->setGeometry(targetGeometry);
 
236
        si->show();
 
237
 
 
238
        return si;
 
239
}
 
240
 
 
241
void KCMXinerama::clearIndicator() {
 
242
        qDeleteAll(_indicators);
 
243
        _indicators.clear();
 
244
}
 
245
 
 
246
#include "kcmxinerama.moc"
 
247