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

« back to all changes in this revision

Viewing changes to kwin/kcmkwin/kwinoptions/windows.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
 * windows.cpp
 
3
 *
 
4
 * Copyright (c) 1997 Patrick Dowler dowler@morgul.fsh.uvic.ca
 
5
 * Copyright (c) 2001 Waldo Bastian bastian@kde.org
 
6
 *
 
7
 *  This program is free software; you can redistribute it and/or modify
 
8
 *  it under the terms of the GNU General Public License as published by
 
9
 *  the Free Software Foundation; either version 2 of the License, or
 
10
 *  (at your option) any later version.
 
11
 *
 
12
 *  This program is distributed in the hope that it will be useful,
 
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 *  GNU General Public License for more details.
 
16
 *
 
17
 *  You should have received a copy of the GNU General Public License
 
18
 *  along with this program; if not, write to the Free Software
 
19
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
20
 *
 
21
 *
 
22
 */
 
23
 
 
24
#include <config-workspace.h>
 
25
 
 
26
#include <QApplication>
 
27
#include <QCheckBox>
 
28
#include <QRadioButton>
 
29
#include <QLabel>
 
30
#include <KComboBox>
 
31
#include <QHBoxLayout>
 
32
#include <QFormLayout>
 
33
#include <QtDBus/QtDBus>
 
34
 
 
35
#include <KButtonGroup>
 
36
#include <klocale.h>
 
37
#include <knuminput.h>
 
38
#include <kdialog.h>
 
39
 
 
40
#include <X11/X.h>
 
41
#include <X11/Xlib.h>
 
42
#include <X11/Xutil.h>
 
43
 
 
44
#include "windows.h"
 
45
 
 
46
#include <kephal/screens.h>
 
47
 
 
48
// kwin config keywords
 
49
#define KWIN_FOCUS                 "FocusPolicy"
 
50
#define KWIN_PLACEMENT             "Placement"
 
51
#define KWIN_MOVE                  "MoveMode"
 
52
#define KWIN_RESIZE_OPAQUE         "ResizeMode"
 
53
#define KWIN_GEOMETRY              "GeometryTip"
 
54
#define KWIN_AUTORAISE_INTERVAL    "AutoRaiseInterval"
 
55
#define KWIN_AUTORAISE             "AutoRaise"
 
56
#define KWIN_DELAYFOCUS_INTERVAL   "DelayFocusInterval"
 
57
#define KWIN_DELAYFOCUS            "DelayFocus"
 
58
#define KWIN_CLICKRAISE            "ClickRaise"
 
59
#define KWIN_MOVE_RESIZE_MAXIMIZED "MoveResizeMaximizedWindows"
 
60
#define KWIN_SHADEHOVER            "ShadeHover"
 
61
#define KWIN_SHADEHOVER_INTERVAL   "ShadeHoverInterval"
 
62
#define KWIN_FOCUS_STEALING        "FocusStealingPreventionLevel"
 
63
#define KWIN_HIDE_UTILITY          "HideUtilityWindowsForInactive"
 
64
#define KWIN_INACTIVE_SKIP_TASKBAR "InactiveTabsSkipTaskbar"
 
65
#define KWIN_AUTOGROUP_SIMILAR     "AutogroupSimilarWindows"
 
66
#define KWIN_AUTOGROUP_FOREGROUND  "AutogroupInForeground"
 
67
#define KWIN_SEPARATE_SCREEN_FOCUS "SeparateScreenFocus"
 
68
#define KWIN_ACTIVE_MOUSE_SCREEN   "ActiveMouseScreen"
 
69
#define KWIN_TILINGON              "TilingOn"
 
70
#define KWIN_TILING_DEFAULT_LAYOUT "TilingDefaultLayout"
 
71
#define KWIN_TILING_RAISE_POLICY   "TilingRaisePolicy"
 
72
 
 
73
//CT 15mar 98 - magics
 
74
#define KWM_BRDR_SNAP_ZONE                   "BorderSnapZone"
 
75
#define KWM_BRDR_SNAP_ZONE_DEFAULT           10
 
76
#define KWM_WNDW_SNAP_ZONE                   "WindowSnapZone"
 
77
#define KWM_WNDW_SNAP_ZONE_DEFAULT           10
 
78
#define KWM_CNTR_SNAP_ZONE                   "CenterSnapZone"
 
79
#define KWM_CNTR_SNAP_ZONE_DEFAULT           0
 
80
 
 
81
#define MAX_BRDR_SNAP                          100
 
82
#define MAX_WNDW_SNAP                          100
 
83
#define MAX_CNTR_SNAP                          100
 
84
#define MAX_EDGE_RES                          1000
 
85
 
 
86
 
 
87
KFocusConfig::~KFocusConfig()
 
88
{
 
89
    if (standAlone)
 
90
        delete config;
 
91
}
 
92
 
 
93
// removed the LCD display over the slider - this is not good GUI design :) RNolden 051701
 
94
KFocusConfig::KFocusConfig(bool _standAlone, KConfig *_config, const KComponentData &inst, QWidget * parent)
 
95
    : KCModule(inst, parent), config(_config), standAlone(_standAlone)
 
96
{
 
97
    QString wtstr;
 
98
    QBoxLayout *lay = new QVBoxLayout(this);
 
99
    QLabel *label;
 
100
 
 
101
    //iTLabel = new QLabel(i18n("  Allowed overlap:\n"
 
102
    //                         "(% of desktop space)"),
 
103
    //             plcBox);
 
104
    //iTLabel->setAlignment(AlignTop|AlignHCenter);
 
105
    //pLay->addWidget(iTLabel,1,1);
 
106
 
 
107
    //interactiveTrigger = new QSpinBox(0, 500, 1, plcBox);
 
108
    //pLay->addWidget(interactiveTrigger,1,2);
 
109
 
 
110
    //pLay->addRowSpacing(2,KDialog::spacingHint());
 
111
 
 
112
    //lay->addWidget(plcBox);
 
113
 
 
114
    // focus policy
 
115
    //fcsBox = new QGroupBox(i18n("Focus"),this);
 
116
    fcsBox = new QWidget(this);
 
117
 
 
118
    QGridLayout *gLay = new QGridLayout();
 
119
 
 
120
    fcsBox->setLayout(gLay);
 
121
 
 
122
    focusStealing = new KComboBox(this);
 
123
    focusStealing->addItem(i18nc("Focus Stealing Prevention Level", "None"));
 
124
    focusStealing->addItem(i18nc("Focus Stealing Prevention Level", "Low"));
 
125
    focusStealing->addItem(i18nc("Focus Stealing Prevention Level", "Medium"));
 
126
    focusStealing->addItem(i18nc("Focus Stealing Prevention Level", "High"));
 
127
    focusStealing->addItem(i18nc("Focus Stealing Prevention Level", "Extreme"));
 
128
    wtstr = i18n("<p>This option specifies how much KWin will try to prevent unwanted focus stealing "
 
129
                 "caused by unexpected activation of new windows. (Note: This feature does not "
 
130
                 "work with the Focus Under Mouse or Focus Strictly Under Mouse focus policies.)"
 
131
                 "<ul>"
 
132
                 "<li><em>None:</em> Prevention is turned off "
 
133
                 "and new windows always become activated.</li>"
 
134
                 "<li><em>Low:</em> Prevention is enabled; when some window does not have support "
 
135
                 "for the underlying mechanism and KWin cannot reliably decide whether to "
 
136
                 "activate the window or not, it will be activated. This setting may have both "
 
137
                 "worse and better results than the medium level, depending on the applications.</li>"
 
138
                 "<li><em>Medium:</em> Prevention is enabled.</li>"
 
139
                 "<li><em>High:</em> New windows get activated only if no window is currently active "
 
140
                 "or if they belong to the currently active application. This setting is probably "
 
141
                 "not really usable when not using mouse focus policy.</li>"
 
142
                 "<li><em>Extreme:</em> All windows must be explicitly activated by the user.</li>"
 
143
                 "</ul></p>"
 
144
                 "<p>Windows that are prevented from stealing focus are marked as demanding attention, "
 
145
                 "which by default means their taskbar entry will be highlighted. This can be changed "
 
146
                 "in the Notifications control module.</p>");
 
147
    focusStealing->setWhatsThis(wtstr);
 
148
    connect(focusStealing, SIGNAL(activated(int)), SLOT(changed()));
 
149
    focusStealing->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
 
150
    label = new QLabel(i18n("Focus stealing prevention level:"), this);
 
151
    label->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
 
152
    label->setBuddy(focusStealing);
 
153
    gLay->addWidget(label, 0, 0, 1, 2);
 
154
    gLay->addWidget(focusStealing, 0, 2);
 
155
 
 
156
    focusCombo =  new KComboBox(fcsBox);
 
157
    focusCombo->setEditable(false);
 
158
    focusCombo->addItem(i18n("Click to Focus"), CLICK_TO_FOCUS);
 
159
    focusCombo->addItem(i18n("Focus Follows Mouse"), FOCUS_FOLLOWS_MOUSE);
 
160
    focusCombo->addItem(i18n("Focus Under Mouse"), FOCUS_UNDER_MOUSE);
 
161
    focusCombo->addItem(i18n("Focus Strictly Under Mouse"), FOCUS_STRICTLY_UNDER_MOUSE);
 
162
    focusCombo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
 
163
    label = new QLabel(i18n("&Policy:"), this);
 
164
    label->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
 
165
    label->setBuddy(focusCombo);
 
166
    gLay->addWidget(label, 1, 0, 1, 2);
 
167
    gLay->addWidget(focusCombo, 1, 2);
 
168
 
 
169
 
 
170
    // FIXME, when more policies have been added to KWin
 
171
    wtstr = i18n("The focus policy is used to determine the active window, i.e."
 
172
                 " the window you can work in. <ul>"
 
173
                 " <li><em>Click to focus:</em> A window becomes active when you click into it."
 
174
                 " This is the behavior you might know from other operating systems.</li>"
 
175
                 " <li><em>Focus follows mouse:</em> Moving the mouse pointer actively on to a"
 
176
                 " normal window activates it. New windows will receive the focus,"
 
177
                 " without you having to point the mouse at them explicitly."
 
178
                 " Very practical if you are using the mouse a lot.</li>"
 
179
                 " <li><em>Focus under mouse:</em> The window that happens to be under the"
 
180
                 " mouse pointer is active. If the mouse points nowhere, the last window"
 
181
                 " that was under the mouse has focus."
 
182
                 " New windows will not automatically receive the focus.</li>"
 
183
                 " <li><em>Focus strictly under mouse:</em> Only the window under the mouse pointer is"
 
184
                 " active. If the mouse points nowhere, nothing has focus.</li>"
 
185
                 " </ul>"
 
186
                 "Note that 'Focus under mouse' and 'Focus strictly under mouse' prevent certain"
 
187
                 " features such as the Alt+Tab walk through windows dialog in the KDE mode"
 
188
                 " from working properly."
 
189
                );
 
190
    focusCombo->setWhatsThis(wtstr);
 
191
 
 
192
    connect(focusCombo, SIGNAL(activated(int)), this, SLOT(focusPolicyChanged()));
 
193
 
 
194
    // autoraise delay
 
195
    autoRaiseOn = new QCheckBox(fcsBox);
 
196
    connect(autoRaiseOn, SIGNAL(toggled(bool)), this, SLOT(autoRaiseOnTog(bool)));
 
197
    autoRaise = new KIntNumInput(500, fcsBox);
 
198
    autoRaise->setRange(0, 3000, 100);
 
199
    autoRaise->setSteps(100, 100);
 
200
    autoRaise->setSuffix(i18n(" ms"));
 
201
    autoRaise->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
 
202
    autoRaiseOnLabel = new QLabel(i18n("&Raise, with the following delay:"), this);
 
203
    autoRaiseOnLabel->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
 
204
    autoRaiseOnLabel->setBuddy(autoRaise);
 
205
    gLay->addWidget(autoRaiseOn, 2, 0);
 
206
    gLay->addWidget(autoRaiseOnLabel, 2, 1);
 
207
    gLay->addWidget(autoRaise, 2, 2);
 
208
 
 
209
    connect(focusCombo, SIGNAL(activated(int)), this, SLOT(setDelayFocusEnabled()));
 
210
 
 
211
    delayFocusOn = new QCheckBox(fcsBox);
 
212
    connect(delayFocusOn, SIGNAL(toggled(bool)), this, SLOT(delayFocusOnTog(bool)));
 
213
    delayFocus = new KIntNumInput(500, fcsBox);
 
214
    delayFocus->setRange(0, 3000, 100);
 
215
    delayFocus->setSteps(100, 100);
 
216
    delayFocus->setSuffix(i18n(" ms"));
 
217
    delayFocus->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
 
218
    delayFocusOnLabel = new QLabel(i18n("Delay focus by:"), this);
 
219
    delayFocusOnLabel->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
 
220
    delayFocusOnLabel->setBuddy(delayFocus);
 
221
    gLay->addWidget(delayFocusOn, 3, 0);
 
222
    gLay->addWidget(delayFocusOnLabel, 3, 1);
 
223
    gLay->addWidget(delayFocus, 3, 2);
 
224
 
 
225
    clickRaiseOn = new QCheckBox(i18n("C&lick raises active window"), fcsBox);
 
226
    connect(clickRaiseOn, SIGNAL(toggled(bool)), this, SLOT(clickRaiseOnTog(bool)));
 
227
    gLay->addWidget(clickRaiseOn, 4, 0, 1, 3);
 
228
 
 
229
    autoRaiseOn->setWhatsThis(i18n("When this option is enabled, a window in the background will automatically"
 
230
                                   " come to the front when the mouse pointer has been over it for some time."));
 
231
    wtstr = i18n("This is the delay after which the window that the mouse pointer is over will automatically"
 
232
                 " come to the front.");
 
233
    autoRaise->setWhatsThis(wtstr);
 
234
 
 
235
    clickRaiseOn->setWhatsThis(i18n("When this option is enabled, the active window will be brought to the"
 
236
                                    " front when you click somewhere into the window contents. To change"
 
237
                                    " it for inactive windows, you need to change the settings"
 
238
                                    " in the Actions tab."));
 
239
 
 
240
    delayFocusOn->setWhatsThis(i18n("When this option is enabled, there will be a delay after which the"
 
241
                                    " window the mouse pointer is over will become active (receive focus)."));
 
242
    delayFocus->setWhatsThis(i18n("This is the delay after which the window the mouse pointer is over"
 
243
                                  " will automatically receive focus."));
 
244
 
 
245
    separateScreenFocus = new QCheckBox(i18n("S&eparate screen focus"), fcsBox);
 
246
    gLay->addWidget(separateScreenFocus, 5, 0, 1, 3);
 
247
    wtstr = i18n("When this option is enabled, focus operations are limited only to the active Xinerama screen");
 
248
    separateScreenFocus->setWhatsThis(wtstr);
 
249
 
 
250
    activeMouseScreen = new QCheckBox(i18n("Active screen follows &mouse"), fcsBox);
 
251
    gLay->addWidget(activeMouseScreen, 6, 0, 1, 3);
 
252
    wtstr = i18n("When this option is enabled, the active Xinerama screen (where new windows appear, for example)"
 
253
                 " is the screen containing the mouse pointer. When disabled, the active Xinerama screen is the "
 
254
                 " screen containing the focused window. By default this option is disabled for Click to focus and"
 
255
                 " enabled for other focus policies.");
 
256
    activeMouseScreen->setWhatsThis(wtstr);
 
257
    connect(focusCombo, SIGNAL(activated(int)), this, SLOT(updateActiveMouseScreen()));
 
258
 
 
259
    if (Kephal::ScreenUtils::numScreens() == 1) { // No Ximerama
 
260
        separateScreenFocus->hide();
 
261
        activeMouseScreen->hide();
 
262
    }
 
263
 
 
264
    lay->addWidget(fcsBox);
 
265
 
 
266
    lay->addStretch();
 
267
 
 
268
    // Any changes goes to slotChanged()
 
269
    connect(focusCombo, SIGNAL(activated(int)), SLOT(changed()));
 
270
    connect(autoRaiseOn, SIGNAL(clicked()), SLOT(changed()));
 
271
    connect(delayFocusOn, SIGNAL(clicked()), SLOT(changed()));
 
272
    connect(clickRaiseOn, SIGNAL(clicked()), SLOT(changed()));
 
273
    connect(autoRaise, SIGNAL(valueChanged(int)), SLOT(changed()));
 
274
    connect(delayFocus, SIGNAL(valueChanged(int)), SLOT(changed()));
 
275
    connect(separateScreenFocus, SIGNAL(clicked()), SLOT(changed()));
 
276
    connect(activeMouseScreen, SIGNAL(clicked()), SLOT(changed()));
 
277
 
 
278
    load();
 
279
}
 
280
 
 
281
 
 
282
int KFocusConfig::getFocus()
 
283
{
 
284
    return focusCombo->currentIndex();
 
285
}
 
286
 
 
287
void KFocusConfig::setFocus(int foc)
 
288
{
 
289
    focusCombo->setCurrentIndex(foc);
 
290
 
 
291
    // this will disable/hide the auto raise delay widget if focus==click
 
292
    focusPolicyChanged();
 
293
}
 
294
 
 
295
void KFocusConfig::setAutoRaiseInterval(int tb)
 
296
{
 
297
    autoRaise->setValue(tb);
 
298
}
 
299
 
 
300
void KFocusConfig::setDelayFocusInterval(int tb)
 
301
{
 
302
    delayFocus->setValue(tb);
 
303
}
 
304
 
 
305
int KFocusConfig::getAutoRaiseInterval()
 
306
{
 
307
    return autoRaise->value();
 
308
}
 
309
 
 
310
int KFocusConfig::getDelayFocusInterval()
 
311
{
 
312
    return delayFocus->value();
 
313
}
 
314
 
 
315
void KFocusConfig::setAutoRaise(bool on)
 
316
{
 
317
    autoRaiseOn->setChecked(on);
 
318
}
 
319
 
 
320
void KFocusConfig::setDelayFocus(bool on)
 
321
{
 
322
    delayFocusOn->setChecked(on);
 
323
}
 
324
 
 
325
void KFocusConfig::setClickRaise(bool on)
 
326
{
 
327
    clickRaiseOn->setChecked(on);
 
328
}
 
329
 
 
330
void KFocusConfig::focusPolicyChanged()
 
331
{
 
332
    int policyIndex = focusCombo->currentIndex();
 
333
 
 
334
    // the auto raise related widgets are: autoRaise
 
335
    autoRaiseOn->setEnabled(policyIndex != CLICK_TO_FOCUS);
 
336
    autoRaiseOnLabel->setEnabled(policyIndex != CLICK_TO_FOCUS);
 
337
    autoRaiseOnTog(policyIndex != CLICK_TO_FOCUS && autoRaiseOn->isChecked());
 
338
 
 
339
    focusStealing->setDisabled(policyIndex == FOCUS_UNDER_MOUSE || policyIndex == FOCUS_STRICTLY_UNDER_MOUSE);
 
340
 
 
341
}
 
342
 
 
343
void KFocusConfig::setDelayFocusEnabled()
 
344
{
 
345
    int policyIndex = focusCombo->currentIndex();
 
346
 
 
347
    // the delayed focus related widgets are: delayFocus
 
348
    delayFocusOn->setEnabled(policyIndex != CLICK_TO_FOCUS);
 
349
    delayFocusOnLabel->setEnabled(policyIndex != CLICK_TO_FOCUS);
 
350
    delayFocusOnTog(policyIndex != CLICK_TO_FOCUS && delayFocusOn->isChecked());
 
351
}
 
352
 
 
353
void KFocusConfig::autoRaiseOnTog(bool a)
 
354
{
 
355
    autoRaise->setEnabled(a);
 
356
    clickRaiseOn->setEnabled(!a);
 
357
}
 
358
 
 
359
void KFocusConfig::delayFocusOnTog(bool a)
 
360
{
 
361
    delayFocus->setEnabled(a);
 
362
}
 
363
 
 
364
void KFocusConfig::clickRaiseOnTog(bool)
 
365
{
 
366
}
 
367
 
 
368
void KFocusConfig::setFocusStealing(int l)
 
369
{
 
370
    l = qMax(0, qMin(4, l));
 
371
    focusStealing->setCurrentIndex(l);
 
372
}
 
373
 
 
374
void KFocusConfig::setSeparateScreenFocus(bool s)
 
375
{
 
376
    separateScreenFocus->setChecked(s);
 
377
}
 
378
 
 
379
void KFocusConfig::setActiveMouseScreen(bool a)
 
380
{
 
381
    activeMouseScreen->setChecked(a);
 
382
}
 
383
 
 
384
void KFocusConfig::updateActiveMouseScreen()
 
385
{
 
386
    // on by default for non click to focus policies
 
387
    KConfigGroup cfg(config, "Windows");
 
388
    if (!cfg.hasKey(KWIN_ACTIVE_MOUSE_SCREEN))
 
389
        setActiveMouseScreen(focusCombo->currentIndex() != 0);
 
390
}
 
391
 
 
392
void KFocusConfig::showEvent(QShowEvent *ev)
 
393
{
 
394
    if (!standAlone) {
 
395
        QWidget::showEvent(ev);
 
396
        return;
 
397
    }
 
398
    KCModule::showEvent(ev);
 
399
}
 
400
 
 
401
void KFocusConfig::load(void)
 
402
{
 
403
    QString key;
 
404
 
 
405
    KConfigGroup cg(config, "Windows");
 
406
 
 
407
    key = cg.readEntry(KWIN_FOCUS);
 
408
    if (key == "ClickToFocus")
 
409
        setFocus(CLICK_TO_FOCUS);
 
410
    else if (key == "FocusFollowsMouse")
 
411
        setFocus(FOCUS_FOLLOWS_MOUSE);
 
412
    else if (key == "FocusUnderMouse")
 
413
        setFocus(FOCUS_UNDER_MOUSE);
 
414
    else if (key == "FocusStrictlyUnderMouse")
 
415
        setFocus(FOCUS_STRICTLY_UNDER_MOUSE);
 
416
 
 
417
    int k = cg.readEntry(KWIN_AUTORAISE_INTERVAL, 750);
 
418
    setAutoRaiseInterval(k);
 
419
 
 
420
    k = cg.readEntry(KWIN_DELAYFOCUS_INTERVAL, 750);
 
421
    setDelayFocusInterval(k);
 
422
 
 
423
    setAutoRaise(cg.readEntry(KWIN_AUTORAISE, false));
 
424
    setDelayFocus(cg.readEntry(KWIN_DELAYFOCUS, false));
 
425
    setClickRaise(cg.readEntry(KWIN_CLICKRAISE, true));
 
426
    focusPolicyChanged();      // this will disable/hide the auto raise delay widget if focus==click
 
427
    setDelayFocusEnabled();
 
428
 
 
429
    setSeparateScreenFocus(cg.readEntry(KWIN_SEPARATE_SCREEN_FOCUS, false));
 
430
    // on by default for non click to focus policies
 
431
    setActiveMouseScreen(cg.readEntry(KWIN_ACTIVE_MOUSE_SCREEN, focusCombo->currentIndex() != 0));
 
432
 
 
433
//    setFocusStealing( cg.readEntry(KWIN_FOCUS_STEALING, 2 ));
 
434
    // TODO default to low for now
 
435
    setFocusStealing(cg.readEntry(KWIN_FOCUS_STEALING, 1));
 
436
 
 
437
    emit KCModule::changed(false);
 
438
}
 
439
 
 
440
void KFocusConfig::save(void)
 
441
{
 
442
    int v;
 
443
 
 
444
    KConfigGroup cg(config, "Windows");
 
445
 
 
446
    v = getFocus();
 
447
    if (v == CLICK_TO_FOCUS)
 
448
        cg.writeEntry(KWIN_FOCUS, "ClickToFocus");
 
449
    else if (v == FOCUS_UNDER_MOUSE)
 
450
        cg.writeEntry(KWIN_FOCUS, "FocusUnderMouse");
 
451
    else if (v == FOCUS_STRICTLY_UNDER_MOUSE)
 
452
        cg.writeEntry(KWIN_FOCUS, "FocusStrictlyUnderMouse");
 
453
    else
 
454
        cg.writeEntry(KWIN_FOCUS, "FocusFollowsMouse");
 
455
 
 
456
    v = getAutoRaiseInterval();
 
457
    if (v < 0) v = 0;
 
458
    cg.writeEntry(KWIN_AUTORAISE_INTERVAL, v);
 
459
 
 
460
    v = getDelayFocusInterval();
 
461
    if (v < 0) v = 0;
 
462
    cg.writeEntry(KWIN_DELAYFOCUS_INTERVAL, v);
 
463
 
 
464
    cg.writeEntry(KWIN_AUTORAISE, autoRaiseOn->isChecked());
 
465
 
 
466
    cg.writeEntry(KWIN_DELAYFOCUS, delayFocusOn->isChecked());
 
467
 
 
468
    cg.writeEntry(KWIN_CLICKRAISE, clickRaiseOn->isChecked());
 
469
 
 
470
    cg.writeEntry(KWIN_SEPARATE_SCREEN_FOCUS, separateScreenFocus->isChecked());
 
471
    cg.writeEntry(KWIN_ACTIVE_MOUSE_SCREEN, activeMouseScreen->isChecked());
 
472
 
 
473
    cg.writeEntry(KWIN_FOCUS_STEALING, focusStealing->currentIndex());
 
474
 
 
475
 
 
476
    if (standAlone) {
 
477
        config->sync();
 
478
        // Send signal to all kwin instances
 
479
        QDBusMessage message =
 
480
            QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig");
 
481
        QDBusConnection::sessionBus().send(message);
 
482
    }
 
483
    emit KCModule::changed(false);
 
484
}
 
485
 
 
486
void KFocusConfig::defaults()
 
487
{
 
488
    setAutoRaiseInterval(0);
 
489
    setDelayFocusInterval(0);
 
490
    setFocus(CLICK_TO_FOCUS);
 
491
    setAutoRaise(false);
 
492
    setDelayFocus(false);
 
493
    setClickRaise(true);
 
494
    setSeparateScreenFocus(false);
 
495
 
 
496
//    setFocusStealing(2);
 
497
    // TODO default to low for now
 
498
    setFocusStealing(1);
 
499
 
 
500
    // on by default for non click to focus policies
 
501
    setActiveMouseScreen(focusCombo->currentIndex() != 0);
 
502
    setDelayFocusEnabled();
 
503
    emit KCModule::changed(true);
 
504
}
 
505
 
 
506
KAdvancedConfig::~KAdvancedConfig()
 
507
{
 
508
    if (standAlone)
 
509
        delete config;
 
510
}
 
511
 
 
512
KAdvancedConfig::KAdvancedConfig(bool _standAlone, KConfig *_config, const KComponentData &inst, QWidget *parent)
 
513
    : KCModule(inst, parent), config(_config), standAlone(_standAlone)
 
514
{
 
515
    QString wtstr;
 
516
    QLabel *label;
 
517
    QVBoxLayout *lay = new QVBoxLayout(this);
 
518
 
 
519
    //iTLabel = new QLabel(i18n("  Allowed overlap:\n"
 
520
    //                         "(% of desktop space)"),
 
521
    //             plcBox);
 
522
    //iTLabel->setAlignment(AlignTop|AlignHCenter);
 
523
    //pLay->addWidget(iTLabel,1,1);
 
524
 
 
525
    //interactiveTrigger = new QSpinBox(0, 500, 1, plcBox);
 
526
    //pLay->addWidget(interactiveTrigger,1,2);
 
527
 
 
528
    //pLay->addRowSpacing(2,KDialog::spacingHint());
 
529
 
 
530
    //lay->addWidget(plcBox);
 
531
 
 
532
    shBox = new KButtonGroup(this);
 
533
    shBox->setTitle(i18n("Shading"));
 
534
    QGridLayout *kLay = new QGridLayout(shBox);
 
535
 
 
536
    shadeHoverOn = new QCheckBox(i18n("&Enable hover"), shBox);
 
537
 
 
538
    connect(shadeHoverOn, SIGNAL(toggled(bool)), this, SLOT(shadeHoverChanged(bool)));
 
539
    kLay->addWidget(shadeHoverOn, 0, 0, 1, 2);
 
540
 
 
541
    shadeHover = new KIntNumInput(500, shBox);
 
542
    shadeHover->setRange(0, 3000, 100);
 
543
    shadeHover->setSteps(100, 100);
 
544
    shadeHover->setSuffix(i18n(" ms"));
 
545
 
 
546
    shadeHoverOn->setWhatsThis(i18n("If Shade Hover is enabled, a shaded window will un-shade automatically "
 
547
                                    "when the mouse pointer has been over the title bar for some time."));
 
548
 
 
549
    wtstr = i18n("Sets the time in milliseconds before the window unshades "
 
550
                 "when the mouse pointer goes over the shaded window.");
 
551
    shadeHover->setWhatsThis(wtstr);
 
552
    shadeHover->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
 
553
    shadeHoverLabel = new QLabel(i18n("Dela&y:"), this);
 
554
    shadeHoverLabel->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
 
555
    shadeHoverLabel->setBuddy(shadeHover);
 
556
    kLay->addWidget(shadeHoverLabel, 1, 0);
 
557
    kLay->addWidget(shadeHover, 1, 1);
 
558
 
 
559
    lay->addWidget(shBox);
 
560
 
 
561
    //----------------
 
562
    // Window tabbing
 
563
 
 
564
    wtBox = new KButtonGroup(this);
 
565
    wtBox->setTitle(i18n("Window Tabbing"));
 
566
    QVBoxLayout *wtLay = new QVBoxLayout(wtBox);
 
567
 
 
568
    inactiveTabsSkipTaskbar = new QCheckBox(i18n("Hide inactive window tabs from the taskbar"), this);
 
569
    inactiveTabsSkipTaskbar->setVisible(false);   // TODO: We want translations in case this is fixed...
 
570
    inactiveTabsSkipTaskbar->setWhatsThis(
 
571
        i18n("When turned on hide all tabs that are not active from the taskbar."));
 
572
    connect(inactiveTabsSkipTaskbar, SIGNAL(toggled(bool)), SLOT(changed()));
 
573
    wtLay->addWidget(inactiveTabsSkipTaskbar);
 
574
 
 
575
    autogroupSimilarWindows = new QCheckBox(i18n("Automatically group similar windows"), this);
 
576
    autogroupSimilarWindows->setWhatsThis(
 
577
        i18n("When turned on attempt to automatically detect when a newly opened window is related"
 
578
             " to an existing one and place them in the same window group."));
 
579
    connect(autogroupSimilarWindows, SIGNAL(toggled(bool)), SLOT(changed()));
 
580
    wtLay->addWidget(autogroupSimilarWindows);
 
581
 
 
582
    autogroupInForeground = new QCheckBox(i18n("Switch to automatically grouped windows immediately"), this);
 
583
    autogroupInForeground->setWhatsThis(
 
584
        i18n("When turned on immediately switch to any new window tabs that were automatically added"
 
585
             " to the current group."));
 
586
    connect(autogroupInForeground, SIGNAL(toggled(bool)), SLOT(changed()));
 
587
    wtLay->addWidget(autogroupInForeground);
 
588
 
 
589
    lay->addWidget(wtBox);
 
590
 
 
591
    //----------------
 
592
 
 
593
    // Any changes goes to slotChanged()
 
594
    connect(shadeHoverOn, SIGNAL(toggled(bool)), SLOT(changed()));
 
595
    connect(shadeHover, SIGNAL(valueChanged(int)), SLOT(changed()));
 
596
 
 
597
    QGridLayout *vLay = new QGridLayout();
 
598
    lay->addLayout(vLay);
 
599
 
 
600
    placementCombo = new KComboBox(this);
 
601
    placementCombo->setEditable(false);
 
602
    placementCombo->addItem(i18n("Smart"), SMART_PLACEMENT);
 
603
    placementCombo->addItem(i18n("Maximizing"), MAXIMIZING_PLACEMENT);
 
604
    placementCombo->addItem(i18n("Cascade"), CASCADE_PLACEMENT);
 
605
    placementCombo->addItem(i18n("Random"), RANDOM_PLACEMENT);
 
606
    placementCombo->addItem(i18n("Centered"), CENTERED_PLACEMENT);
 
607
    placementCombo->addItem(i18n("Zero-Cornered"), ZEROCORNERED_PLACEMENT);
 
608
    // CT: disabling is needed as long as functionality misses in kwin
 
609
    //placementCombo->addItem(i18n("Interactive"), INTERACTIVE_PLACEMENT);
 
610
    //placementCombo->addItem(i18n("Manual"), MANUAL_PLACEMENT);
 
611
    placementCombo->setCurrentIndex(SMART_PLACEMENT);
 
612
 
 
613
    // FIXME, when more policies have been added to KWin
 
614
    wtstr = i18n("The placement policy determines where a new window"
 
615
                 " will appear on the desktop."
 
616
                 " <ul>"
 
617
                 " <li><em>Smart</em> will try to achieve a minimum overlap of windows</li>"
 
618
                 " <li><em>Maximizing</em> will try to maximize every window to fill the whole screen."
 
619
                 " It might be useful to selectively affect placement of some windows using"
 
620
                 " the window-specific settings.</li>"
 
621
                 " <li><em>Cascade</em> will cascade the windows</li>"
 
622
                 " <li><em>Random</em> will use a random position</li>"
 
623
                 " <li><em>Centered</em> will place the window centered</li>"
 
624
                 " <li><em>Zero-Cornered</em> will place the window in the top-left corner</li>"
 
625
                 "</ul>") ;
 
626
 
 
627
    placementCombo->setWhatsThis(wtstr);
 
628
 
 
629
    placementCombo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
 
630
    label = new QLabel(i18n("&Placement:"), this);
 
631
    label->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
 
632
    label->setBuddy(placementCombo);
 
633
    vLay->addWidget(label, 0, 0);
 
634
    vLay->addWidget(placementCombo, 0, 1);
 
635
 
 
636
    connect(placementCombo, SIGNAL(activated(int)), SLOT(changed()));
 
637
 
 
638
    hideUtilityWindowsForInactive = new QCheckBox(i18n("Hide utility windows for inactive applications"), this);
 
639
    hideUtilityWindowsForInactive->setWhatsThis(
 
640
        i18n("When turned on, utility windows (tool windows, torn-off menus,...) of inactive applications will be"
 
641
             " hidden and will be shown only when the application becomes active. Note that applications"
 
642
             " have to mark the windows with the proper window type for this feature to work."));
 
643
    connect(hideUtilityWindowsForInactive, SIGNAL(toggled(bool)), SLOT(changed()));
 
644
    vLay->addWidget(hideUtilityWindowsForInactive, 1, 0, 1, 2);
 
645
 
 
646
    tilBox = new KButtonGroup(this);
 
647
    tilBox->setTitle(i18n("Tiling"));
 
648
    QGridLayout *tilBoxLay = new QGridLayout(tilBox);
 
649
 
 
650
    tilingOn = new QCheckBox(i18n("Enable Tiling"), tilBox);
 
651
    tilingOn->setWhatsThis(
 
652
        i18n("A tiling window manager lays out all the windows in a non-overlapping manner."
 
653
             " This way all windows are always visible."));
 
654
    tilBoxLay->addWidget(tilingOn);
 
655
    connect(tilingOn, SIGNAL(toggled(bool)), SLOT(tilingOnChanged(bool)));
 
656
    connect(tilingOn, SIGNAL(toggled(bool)), SLOT(changed()));
 
657
 
 
658
    tilingLayoutLabel = new QLabel(i18n("Default Tiling &Layout"), tilBox);
 
659
    tilBoxLay->addWidget(tilingLayoutLabel, 1, 0);
 
660
 
 
661
    tilingLayoutCombo = new KComboBox(tilBox);
 
662
 
 
663
    // NOTE: add your layout to the bottom of this list
 
664
    tilingLayoutCombo->addItem(i18nc("Spiral tiling layout", "Spiral"));
 
665
    tilingLayoutCombo->addItem(i18nc("Two-column horizontal tiling layout", "Columns"));
 
666
    tilingLayoutCombo->addItem(i18nc("Floating layout, windows aren't tiled at all", "Floating"));
 
667
 
 
668
    tilingLayoutLabel->setBuddy(tilingLayoutCombo);
 
669
    connect(tilingLayoutCombo, SIGNAL(activated(int)), SLOT(changed()));
 
670
    tilBoxLay->addWidget(tilingLayoutCombo, 1, 1);
 
671
 
 
672
    tilingRaiseLabel = new QLabel(i18n("Floating &Windows Raising"), tilBox);
 
673
    tilBoxLay->addWidget(tilingRaiseLabel, 2, 0);
 
674
 
 
675
    tilingRaiseCombo = new KComboBox(tilBox);
 
676
    // when a floating window is activated, all other floating
 
677
    // windows are also brought to the front, above the tiled windows
 
678
    // when a tiled window is focused, all floating windows go to the back.
 
679
    // NOTE: If the user has explicitly set a client to "keep above others", that will be respected.
 
680
    tilingRaiseCombo->addItem(i18nc("Window Raising Policy", "Raise/Lower all floating windows"));
 
681
    tilingRaiseCombo->addItem(i18nc("Window Raising Policy", "Raise/Lower current window only"));
 
682
    tilingRaiseCombo->addItem(i18nc("Window Raising Policy", "Floating windows are always on top"));
 
683
    wtstr = i18n("The window raising policy determines how floating windows are stacked"
 
684
                 " <ul>"
 
685
                 " <li><em>Raise/Lower all</em> will raise all floating windows when a"
 
686
                 " floating window is activated.</li>"
 
687
                 " <li><em>Raise/Lower current</em> will raise only the current window.</li>"
 
688
                 " <li><em>Floating windows on top</em> will always keep floating windows on top, even"
 
689
                 " when a tiled window is activated."
 
690
                 "</ul>") ;
 
691
    tilingRaiseCombo->setWhatsThis(wtstr);
 
692
    connect(tilingRaiseCombo, SIGNAL(activated(int)), SLOT(changed()));
 
693
    tilingRaiseLabel->setBuddy(tilingRaiseCombo);
 
694
    tilBoxLay->addWidget(tilingRaiseCombo, 2, 1);
 
695
 
 
696
    lay->addWidget(tilBox);
 
697
 
 
698
    lay->addStretch();
 
699
    load();
 
700
 
 
701
}
 
702
 
 
703
void KAdvancedConfig::setShadeHover(bool on)
 
704
{
 
705
    shadeHoverOn->setChecked(on);
 
706
    shadeHoverLabel->setEnabled(on);
 
707
    shadeHover->setEnabled(on);
 
708
}
 
709
 
 
710
void KAdvancedConfig::setShadeHoverInterval(int k)
 
711
{
 
712
    shadeHover->setValue(k);
 
713
}
 
714
 
 
715
int KAdvancedConfig::getShadeHoverInterval()
 
716
{
 
717
 
 
718
    return shadeHover->value();
 
719
}
 
720
 
 
721
void KAdvancedConfig::shadeHoverChanged(bool a)
 
722
{
 
723
    shadeHoverLabel->setEnabled(a);
 
724
    shadeHover->setEnabled(a);
 
725
}
 
726
 
 
727
void KAdvancedConfig::setTilingOn(bool on)
 
728
{
 
729
    tilingOn->setChecked(on);
 
730
    tilingLayoutLabel->setEnabled(on);
 
731
    tilingLayoutCombo->setEnabled(on);
 
732
    tilingRaiseLabel->setEnabled(on);
 
733
    tilingRaiseCombo->setEnabled(on);
 
734
}
 
735
 
 
736
void KAdvancedConfig::setTilingLayout(int l)
 
737
{
 
738
    tilingLayoutCombo->setCurrentIndex(l);
 
739
}
 
740
 
 
741
void KAdvancedConfig::setTilingRaisePolicy(int l)
 
742
{
 
743
    tilingRaiseCombo->setCurrentIndex(l);
 
744
}
 
745
 
 
746
void KAdvancedConfig::tilingOnChanged(bool a)
 
747
{
 
748
    tilingLayoutLabel->setEnabled(a);
 
749
    tilingLayoutCombo->setEnabled(a);
 
750
    tilingRaiseLabel->setEnabled(a);
 
751
    tilingRaiseCombo->setEnabled(a);
 
752
}
 
753
 
 
754
void KAdvancedConfig::showEvent(QShowEvent *ev)
 
755
{
 
756
    if (!standAlone) {
 
757
        QWidget::showEvent(ev);
 
758
        return;
 
759
    }
 
760
    KCModule::showEvent(ev);
 
761
}
 
762
 
 
763
void KAdvancedConfig::load(void)
 
764
{
 
765
    KConfigGroup cg(config, "Windows");
 
766
 
 
767
    setShadeHover(cg.readEntry(KWIN_SHADEHOVER, false));
 
768
    setShadeHoverInterval(cg.readEntry(KWIN_SHADEHOVER_INTERVAL, 250));
 
769
 
 
770
    QString key;
 
771
    // placement policy --- CT 19jan98 ---
 
772
    key = cg.readEntry(KWIN_PLACEMENT);
 
773
    //CT 13mar98 interactive placement
 
774
//   if ( key.left(11) == "interactive") {
 
775
//     setPlacement(INTERACTIVE_PLACEMENT);
 
776
//     int comma_pos = key.find(',');
 
777
//     if (comma_pos < 0)
 
778
//       interactiveTrigger->setValue(0);
 
779
//     else
 
780
//       interactiveTrigger->setValue (key.right(key.length()
 
781
//                           - comma_pos).toUInt(0));
 
782
//     iTLabel->setEnabled(true);
 
783
//     interactiveTrigger->show();
 
784
//   }
 
785
//   else {
 
786
//     interactiveTrigger->setValue(0);
 
787
//     iTLabel->setEnabled(false);
 
788
//     interactiveTrigger->hide();
 
789
    if (key == "Random")
 
790
        setPlacement(RANDOM_PLACEMENT);
 
791
    else if (key == "Cascade")
 
792
        setPlacement(CASCADE_PLACEMENT); //CT 31jan98
 
793
    //CT 31mar98 manual placement
 
794
    else if (key == "manual")
 
795
        setPlacement(MANUAL_PLACEMENT);
 
796
    else if (key == "Centered")
 
797
        setPlacement(CENTERED_PLACEMENT);
 
798
    else if (key == "ZeroCornered")
 
799
        setPlacement(ZEROCORNERED_PLACEMENT);
 
800
    else if (key == "Maximizing")
 
801
        setPlacement(MAXIMIZING_PLACEMENT);
 
802
    else
 
803
        setPlacement(SMART_PLACEMENT);
 
804
//  }
 
805
 
 
806
    setHideUtilityWindowsForInactive(cg.readEntry(KWIN_HIDE_UTILITY, true));
 
807
    setInactiveTabsSkipTaskbar(cg.readEntry(KWIN_INACTIVE_SKIP_TASKBAR, false));
 
808
    setAutogroupSimilarWindows(cg.readEntry(KWIN_AUTOGROUP_SIMILAR, false));
 
809
    setAutogroupInForeground(cg.readEntry(KWIN_AUTOGROUP_FOREGROUND, true));
 
810
 
 
811
    setTilingOn(cg.readEntry(KWIN_TILINGON, false));
 
812
    setTilingLayout(cg.readEntry(KWIN_TILING_DEFAULT_LAYOUT, 0));
 
813
    setTilingRaisePolicy(cg.readEntry(KWIN_TILING_RAISE_POLICY, 0));
 
814
 
 
815
    emit KCModule::changed(false);
 
816
}
 
817
 
 
818
void KAdvancedConfig::save(void)
 
819
{
 
820
    int v;
 
821
 
 
822
    KConfigGroup cg(config, "Windows");
 
823
    cg.writeEntry(KWIN_SHADEHOVER, shadeHoverOn->isChecked());
 
824
 
 
825
    v = getShadeHoverInterval();
 
826
    if (v < 0) v = 0;
 
827
    cg.writeEntry(KWIN_SHADEHOVER_INTERVAL, v);
 
828
 
 
829
    // placement policy --- CT 31jan98 ---
 
830
    v = getPlacement();
 
831
    if (v == RANDOM_PLACEMENT)
 
832
        cg.writeEntry(KWIN_PLACEMENT, "Random");
 
833
    else if (v == CASCADE_PLACEMENT)
 
834
        cg.writeEntry(KWIN_PLACEMENT, "Cascade");
 
835
    else if (v == CENTERED_PLACEMENT)
 
836
        cg.writeEntry(KWIN_PLACEMENT, "Centered");
 
837
    else if (v == ZEROCORNERED_PLACEMENT)
 
838
        cg.writeEntry(KWIN_PLACEMENT, "ZeroCornered");
 
839
    else if (v == MAXIMIZING_PLACEMENT)
 
840
        cg.writeEntry(KWIN_PLACEMENT, "Maximizing");
 
841
//CT 13mar98 manual and interactive placement
 
842
//   else if (v == MANUAL_PLACEMENT)
 
843
//     cg.writeEntry(KWIN_PLACEMENT, "Manual");
 
844
//   else if (v == INTERACTIVE_PLACEMENT) {
 
845
//       QString tmpstr = QString("Interactive,%1").arg(interactiveTrigger->value());
 
846
//       cg.writeEntry(KWIN_PLACEMENT, tmpstr);
 
847
//   }
 
848
    else
 
849
        cg.writeEntry(KWIN_PLACEMENT, "Smart");
 
850
 
 
851
    cg.writeEntry(KWIN_HIDE_UTILITY, hideUtilityWindowsForInactive->isChecked());
 
852
    cg.writeEntry(KWIN_INACTIVE_SKIP_TASKBAR, inactiveTabsSkipTaskbar->isChecked());
 
853
    cg.writeEntry(KWIN_AUTOGROUP_SIMILAR, autogroupSimilarWindows->isChecked());
 
854
    cg.writeEntry(KWIN_AUTOGROUP_FOREGROUND, autogroupInForeground->isChecked());
 
855
 
 
856
    if (standAlone) {
 
857
        config->sync();
 
858
        // Send signal to all kwin instances
 
859
        QDBusMessage message =
 
860
            QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig");
 
861
        QDBusConnection::sessionBus().send(message);
 
862
 
 
863
    }
 
864
 
 
865
    cg.writeEntry(KWIN_TILINGON, tilingOn->isChecked());
 
866
    cg.writeEntry(KWIN_TILING_DEFAULT_LAYOUT, tilingLayoutCombo->currentIndex());
 
867
    cg.writeEntry(KWIN_TILING_RAISE_POLICY, tilingRaiseCombo->currentIndex());
 
868
    emit KCModule::changed(false);
 
869
}
 
870
 
 
871
void KAdvancedConfig::defaults()
 
872
{
 
873
    setShadeHover(false);
 
874
    setShadeHoverInterval(250);
 
875
    setPlacement(SMART_PLACEMENT);
 
876
    setHideUtilityWindowsForInactive(true);
 
877
    setTilingOn(false);
 
878
    setTilingLayout(0);
 
879
    setTilingRaisePolicy(0);
 
880
    setInactiveTabsSkipTaskbar(false);
 
881
    setAutogroupSimilarWindows(false);
 
882
    setAutogroupInForeground(true);
 
883
    emit KCModule::changed(true);
 
884
}
 
885
 
 
886
// placement policy --- CT 31jan98 ---
 
887
int KAdvancedConfig::getPlacement()
 
888
{
 
889
    return placementCombo->currentIndex();
 
890
}
 
891
 
 
892
void KAdvancedConfig::setPlacement(int plac)
 
893
{
 
894
    placementCombo->setCurrentIndex(plac);
 
895
}
 
896
 
 
897
 
 
898
void KAdvancedConfig::setHideUtilityWindowsForInactive(bool s)
 
899
{
 
900
    hideUtilityWindowsForInactive->setChecked(s);
 
901
}
 
902
 
 
903
void KAdvancedConfig::setInactiveTabsSkipTaskbar(bool s)
 
904
{
 
905
    inactiveTabsSkipTaskbar->setChecked(s);
 
906
}
 
907
 
 
908
void KAdvancedConfig::setAutogroupSimilarWindows(bool s)
 
909
{
 
910
    autogroupSimilarWindows->setChecked(s);
 
911
}
 
912
 
 
913
void KAdvancedConfig::setAutogroupInForeground(bool s)
 
914
{
 
915
    autogroupInForeground->setChecked(s);
 
916
}
 
917
 
 
918
KMovingConfig::~KMovingConfig()
 
919
{
 
920
    if (standAlone)
 
921
        delete config;
 
922
}
 
923
 
 
924
KMovingConfig::KMovingConfig(bool _standAlone, KConfig *_config, const KComponentData &inst, QWidget *parent)
 
925
    : KCModule(inst, parent), config(_config), standAlone(_standAlone)
 
926
{
 
927
    QString wtstr;
 
928
    QBoxLayout *lay = new QVBoxLayout(this);
 
929
 
 
930
    windowsBox = new KButtonGroup(this);
 
931
    windowsBox->setTitle(i18n("Windows"));
 
932
 
 
933
    QBoxLayout *wLay = new QVBoxLayout(windowsBox);
 
934
 
 
935
    QBoxLayout *bLay = new QVBoxLayout;
 
936
    wLay->addLayout(bLay);
 
937
 
 
938
    opaque = new QCheckBox(i18n("Di&splay content in moving windows"), windowsBox);
 
939
    bLay->addWidget(opaque);
 
940
    opaque->setWhatsThis(i18n("Enable this option if you want a window's content to be fully shown"
 
941
                              " while moving it, instead of just showing a window 'skeleton'. The result may not be satisfying"
 
942
                              " on slow machines without graphic acceleration."));
 
943
 
 
944
    resizeOpaqueOn = new QCheckBox(i18n("Display content in &resizing windows"), windowsBox);
 
945
    bLay->addWidget(resizeOpaqueOn);
 
946
    resizeOpaqueOn->setWhatsThis(i18n("Enable this option if you want a window's content to be shown"
 
947
                                      " while resizing it, instead of just showing a window 'skeleton'. The result may not be satisfying"
 
948
                                      " on slow machines."));
 
949
 
 
950
    geometryTipOn = new QCheckBox(i18n("Display window &geometry when moving or resizing"), windowsBox);
 
951
    bLay->addWidget(geometryTipOn);
 
952
    geometryTipOn->setWhatsThis(i18n("Enable this option if you want a window's geometry to be displayed"
 
953
                                     " while it is being moved or resized. The window position relative"
 
954
                                     " to the top-left corner of the screen is displayed together with"
 
955
                                     " its size."));
 
956
 
 
957
    moveResizeMaximized = new QCheckBox(i18n("Display borders on &maximized windows"), windowsBox);
 
958
    bLay->addWidget(moveResizeMaximized);
 
959
    moveResizeMaximized->setWhatsThis(i18n("When enabled, this feature activates the border of maximized windows"
 
960
                                           " and allows you to move or resize them,"
 
961
                                           " just like for normal windows"));
 
962
 
 
963
 
 
964
    lay->addWidget(windowsBox);
 
965
 
 
966
    //iTLabel = new QLabel(i18n("  Allowed overlap:\n"
 
967
    //                         "(% of desktop space)"),
 
968
    //             plcBox);
 
969
    //iTLabel->setAlignment(AlignTop|AlignHCenter);
 
970
    //pLay->addWidget(iTLabel,1,1);
 
971
 
 
972
    //interactiveTrigger = new QSpinBox(0, 500, 1, plcBox);
 
973
    //pLay->addWidget(interactiveTrigger,1,2);
 
974
 
 
975
    //pLay->addRowSpacing(2,KDialog::spacingHint());
 
976
 
 
977
    //lay->addWidget(plcBox);
 
978
 
 
979
 
 
980
 
 
981
 
 
982
 
 
983
    //CT 15mar98 - add EdgeResistance, BorderAttractor, WindowsAttractor config
 
984
    MagicBox = new KButtonGroup(this);
 
985
    MagicBox->setTitle(i18n("Snap Zones"));
 
986
    QGridLayout *kLay = new QGridLayout(MagicBox);
 
987
 
 
988
    BrdrSnap = new KIntNumInput(10, MagicBox);
 
989
    BrdrSnap->setSpecialValueText(i18nc("no border snap zone", "none"));
 
990
    BrdrSnap->setRange(0, MAX_BRDR_SNAP);
 
991
    BrdrSnap->setSteps(1, 10);
 
992
    BrdrSnap->setWhatsThis(i18n("Here you can set the snap zone for screen borders, i.e."
 
993
                                " the 'strength' of the magnetic field which will make windows snap to the border when"
 
994
                                " moved near it."));
 
995
    BrdrSnap->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
 
996
    BrdrSnapLabel = new QLabel(i18n("&Border snap zone:"), this);
 
997
    BrdrSnapLabel->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
 
998
    BrdrSnapLabel->setBuddy(BrdrSnap);
 
999
    kLay->addWidget(BrdrSnapLabel, 0, 0);
 
1000
    kLay->addWidget(BrdrSnap, 0, 1);
 
1001
 
 
1002
    WndwSnap = new KIntNumInput(10, MagicBox);
 
1003
    WndwSnap->setSpecialValueText(i18nc("no window snap zone", "none"));
 
1004
    WndwSnap->setRange(0, MAX_WNDW_SNAP);
 
1005
    WndwSnap->setSteps(1, 10);
 
1006
    WndwSnap->setWhatsThis(i18n("Here you can set the snap zone for windows, i.e."
 
1007
                                " the 'strength' of the magnetic field which will make windows snap to each other when"
 
1008
                                " they are moved near another window."));
 
1009
    BrdrSnap->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
 
1010
    WndwSnapLabel = new QLabel(i18n("&Window snap zone:"), this);
 
1011
    WndwSnapLabel->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
 
1012
    WndwSnapLabel->setBuddy(WndwSnap);
 
1013
    kLay->addWidget(WndwSnapLabel, 1, 0);
 
1014
    kLay->addWidget(WndwSnap, 1, 1);
 
1015
 
 
1016
    CntrSnap = new KIntNumInput(10, MagicBox);
 
1017
    CntrSnap->setSpecialValueText(i18nc("no center snap zone", "none"));
 
1018
    CntrSnap->setRange(0, MAX_CNTR_SNAP);
 
1019
    CntrSnap->setSteps(1, 10);
 
1020
    CntrSnap->setWhatsThis(i18n("Here you can set the snap zone for the screen center, i.e."
 
1021
                                " the 'strength' of the magnetic field which will make windows snap to the center of"
 
1022
                                " the screen when moved near it."));
 
1023
    BrdrSnap->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
 
1024
    CntrSnapLabel = new QLabel(i18n("&Center snap zone:"), this);
 
1025
    CntrSnapLabel->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
 
1026
    CntrSnapLabel->setBuddy(CntrSnap);
 
1027
    kLay->addWidget(CntrSnapLabel, 2, 0);
 
1028
    kLay->addWidget(CntrSnap, 2, 1);
 
1029
 
 
1030
    OverlapSnap = new QCheckBox(i18n("Snap windows onl&y when overlapping"), MagicBox);
 
1031
    OverlapSnap->setWhatsThis(i18n("Here you can set that windows will be only"
 
1032
                                   " snapped if you try to overlap them, i.e. they will not be snapped if the windows"
 
1033
                                   " comes only near another window or border."));
 
1034
    kLay->addWidget(OverlapSnap, 3, 0, 1, 2);
 
1035
 
 
1036
    lay->addWidget(MagicBox);
 
1037
    lay->addStretch();
 
1038
 
 
1039
    load();
 
1040
 
 
1041
    // Any changes goes to slotChanged()
 
1042
    connect(opaque, SIGNAL(clicked()), SLOT(changed()));
 
1043
    connect(resizeOpaqueOn, SIGNAL(clicked()), SLOT(changed()));
 
1044
    connect(geometryTipOn, SIGNAL(clicked()), SLOT(changed()));
 
1045
    connect(moveResizeMaximized, SIGNAL(toggled(bool)), SLOT(changed()));
 
1046
    connect(BrdrSnap, SIGNAL(valueChanged(int)), SLOT(changed()));
 
1047
    connect(BrdrSnap, SIGNAL(valueChanged(int)), SLOT(slotBrdrSnapChanged(int)));
 
1048
    connect(WndwSnap, SIGNAL(valueChanged(int)), SLOT(changed()));
 
1049
    connect(WndwSnap, SIGNAL(valueChanged(int)), SLOT(slotWndwSnapChanged(int)));
 
1050
    connect(CntrSnap, SIGNAL(valueChanged(int)), SLOT(changed()));
 
1051
    connect(CntrSnap, SIGNAL(valueChanged(int)), SLOT(slotCntrSnapChanged(int)));
 
1052
    connect(OverlapSnap, SIGNAL(clicked()), SLOT(changed()));
 
1053
 
 
1054
    // To get suffix to BrdrSnap, WndwSnap and CntrSnap inputs with default values.
 
1055
    slotBrdrSnapChanged(BrdrSnap->value());
 
1056
    slotWndwSnapChanged(WndwSnap->value());
 
1057
    slotCntrSnapChanged(CntrSnap->value());
 
1058
}
 
1059
 
 
1060
int KMovingConfig::getMove()
 
1061
{
 
1062
    return (opaque->isChecked()) ? OPAQUE : TRANSPARENT;
 
1063
}
 
1064
 
 
1065
void KMovingConfig::setMove(int trans)
 
1066
{
 
1067
    opaque->setChecked(trans == OPAQUE);
 
1068
}
 
1069
 
 
1070
void KMovingConfig::setGeometryTip(bool showGeometryTip)
 
1071
{
 
1072
    geometryTipOn->setChecked(showGeometryTip);
 
1073
}
 
1074
 
 
1075
bool KMovingConfig::getGeometryTip()
 
1076
{
 
1077
    return geometryTipOn->isChecked();
 
1078
}
 
1079
 
 
1080
int KMovingConfig::getResizeOpaque()
 
1081
{
 
1082
    return (resizeOpaqueOn->isChecked()) ? RESIZE_OPAQUE : RESIZE_TRANSPARENT;
 
1083
}
 
1084
 
 
1085
void KMovingConfig::setResizeOpaque(int opaque)
 
1086
{
 
1087
    resizeOpaqueOn->setChecked(opaque == RESIZE_OPAQUE);
 
1088
}
 
1089
 
 
1090
void KMovingConfig::setMoveResizeMaximized(bool a)
 
1091
{
 
1092
    moveResizeMaximized->setChecked(a);
 
1093
}
 
1094
 
 
1095
void KMovingConfig::slotBrdrSnapChanged(int value)
 
1096
{
 
1097
    BrdrSnap->setSuffix(i18np(" pixel", " pixels", value));
 
1098
}
 
1099
 
 
1100
void KMovingConfig::slotWndwSnapChanged(int value)
 
1101
{
 
1102
    WndwSnap->setSuffix(i18np(" pixel", " pixels", value));
 
1103
}
 
1104
 
 
1105
void KMovingConfig::slotCntrSnapChanged(int value)
 
1106
{
 
1107
    CntrSnap->setSuffix(i18np(" pixel", " pixels", value));
 
1108
}
 
1109
 
 
1110
void KMovingConfig::showEvent(QShowEvent *ev)
 
1111
{
 
1112
    if (!standAlone) {
 
1113
        QWidget::showEvent(ev);
 
1114
        return;
 
1115
    }
 
1116
    KCModule::showEvent(ev);
 
1117
}
 
1118
 
 
1119
void KMovingConfig::load(void)
 
1120
{
 
1121
    QString key;
 
1122
 
 
1123
    KConfigGroup cg(config, "Windows");
 
1124
 
 
1125
    key = cg.readEntry(KWIN_MOVE, "Opaque");
 
1126
    if (key == "Transparent")
 
1127
        setMove(TRANSPARENT);
 
1128
    else if (key == "Opaque")
 
1129
        setMove(OPAQUE);
 
1130
 
 
1131
    // DF: please keep the default consistent with kwin (options.cpp line 145)
 
1132
    key = cg.readEntry(KWIN_RESIZE_OPAQUE, "Opaque");
 
1133
    if (key == "Opaque")
 
1134
        setResizeOpaque(RESIZE_OPAQUE);
 
1135
    else if (key == "Transparent")
 
1136
        setResizeOpaque(RESIZE_TRANSPARENT);
 
1137
 
 
1138
    //KS 10Jan2003 - Geometry Tip during window move/resize
 
1139
    bool showGeomTip = cg.readEntry(KWIN_GEOMETRY, false);
 
1140
    setGeometryTip(showGeomTip);
 
1141
 
 
1142
 
 
1143
    setMoveResizeMaximized(cg.readEntry(KWIN_MOVE_RESIZE_MAXIMIZED, false));
 
1144
 
 
1145
    int v;
 
1146
 
 
1147
    v = cg.readEntry(KWM_BRDR_SNAP_ZONE, KWM_BRDR_SNAP_ZONE_DEFAULT);
 
1148
    if (v > MAX_BRDR_SNAP) setBorderSnapZone(MAX_BRDR_SNAP);
 
1149
    else if (v < 0) setBorderSnapZone(0);
 
1150
    else setBorderSnapZone(v);
 
1151
 
 
1152
    v = cg.readEntry(KWM_WNDW_SNAP_ZONE, KWM_WNDW_SNAP_ZONE_DEFAULT);
 
1153
    if (v > MAX_WNDW_SNAP) setWindowSnapZone(MAX_WNDW_SNAP);
 
1154
    else if (v < 0) setWindowSnapZone(0);
 
1155
    else setWindowSnapZone(v);
 
1156
 
 
1157
    v = cg.readEntry(KWM_CNTR_SNAP_ZONE, KWM_CNTR_SNAP_ZONE_DEFAULT);
 
1158
    if (v > MAX_CNTR_SNAP) setCenterSnapZone(MAX_CNTR_SNAP);
 
1159
    else if (v < 0) setCenterSnapZone(0);
 
1160
    else setCenterSnapZone(v);
 
1161
 
 
1162
    OverlapSnap->setChecked(cg.readEntry("SnapOnlyWhenOverlapping", false));
 
1163
    emit KCModule::changed(false);
 
1164
}
 
1165
 
 
1166
void KMovingConfig::save(void)
 
1167
{
 
1168
    int v;
 
1169
 
 
1170
    KConfigGroup cg(config, "Windows");
 
1171
 
 
1172
    v = getMove();
 
1173
    if (v == TRANSPARENT)
 
1174
        cg.writeEntry(KWIN_MOVE, "Transparent");
 
1175
    else
 
1176
        cg.writeEntry(KWIN_MOVE, "Opaque");
 
1177
 
 
1178
    cg.writeEntry(KWIN_GEOMETRY, getGeometryTip());
 
1179
 
 
1180
    v = getResizeOpaque();
 
1181
    if (v == RESIZE_OPAQUE)
 
1182
        cg.writeEntry(KWIN_RESIZE_OPAQUE, "Opaque");
 
1183
    else
 
1184
        cg.writeEntry(KWIN_RESIZE_OPAQUE, "Transparent");
 
1185
 
 
1186
    cg.writeEntry(KWIN_MOVE_RESIZE_MAXIMIZED, moveResizeMaximized->isChecked());
 
1187
 
 
1188
 
 
1189
    cg.writeEntry(KWM_BRDR_SNAP_ZONE, getBorderSnapZone());
 
1190
    cg.writeEntry(KWM_WNDW_SNAP_ZONE, getWindowSnapZone());
 
1191
    cg.writeEntry(KWM_CNTR_SNAP_ZONE, getCenterSnapZone());
 
1192
    cg.writeEntry("SnapOnlyWhenOverlapping", OverlapSnap->isChecked());
 
1193
 
 
1194
    KConfigGroup(config, "Plugins").writeEntry("kwin4_effect_windowgeometryEnabled", getGeometryTip());
 
1195
 
 
1196
    if (standAlone) {
 
1197
        config->sync();
 
1198
        // Send signal to all kwin instances
 
1199
        QDBusMessage message =
 
1200
            QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig");
 
1201
        QDBusConnection::sessionBus().send(message);
 
1202
    }
 
1203
    emit KCModule::changed(false);
 
1204
}
 
1205
 
 
1206
void KMovingConfig::defaults()
 
1207
{
 
1208
    setMove(OPAQUE);
 
1209
    setResizeOpaque(RESIZE_TRANSPARENT);
 
1210
    setGeometryTip(false);
 
1211
    setMoveResizeMaximized(false);
 
1212
 
 
1213
    //copied from kcontrol/konq/kwindesktop, aleXXX
 
1214
    setWindowSnapZone(KWM_WNDW_SNAP_ZONE_DEFAULT);
 
1215
    setBorderSnapZone(KWM_BRDR_SNAP_ZONE_DEFAULT);
 
1216
    setCenterSnapZone(KWM_CNTR_SNAP_ZONE_DEFAULT);
 
1217
    OverlapSnap->setChecked(false);
 
1218
 
 
1219
    emit KCModule::changed(true);
 
1220
}
 
1221
 
 
1222
int KMovingConfig::getBorderSnapZone()
 
1223
{
 
1224
    return BrdrSnap->value();
 
1225
}
 
1226
 
 
1227
void KMovingConfig::setBorderSnapZone(int pxls)
 
1228
{
 
1229
    BrdrSnap->setValue(pxls);
 
1230
}
 
1231
 
 
1232
int KMovingConfig::getWindowSnapZone()
 
1233
{
 
1234
    return WndwSnap->value();
 
1235
}
 
1236
 
 
1237
void KMovingConfig::setWindowSnapZone(int pxls)
 
1238
{
 
1239
    WndwSnap->setValue(pxls);
 
1240
}
 
1241
 
 
1242
int KMovingConfig::getCenterSnapZone()
 
1243
{
 
1244
    return CntrSnap->value();
 
1245
}
 
1246
 
 
1247
void KMovingConfig::setCenterSnapZone(int pxls)
 
1248
{
 
1249
    CntrSnap->setValue(pxls);
 
1250
}
 
1251
 
 
1252
#include "windows.moc"