add more spacing
[personal-kdebase.git] / workspace / kwin / kcmkwin / kwinoptions / mouse.cpp
blob88ce18584f198811bc3d878bb86bc03b7a231aa2
1 /*
3 * Copyright (c) 1998 Matthias Ettrich <ettrich@kde.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "mouse.h"
22 #include <QLabel>
23 #include <QComboBox>
25 #include <QLayout>
26 #include <QSizePolicy>
27 #include <QBitmap>
29 #include <QGroupBox>
30 #include <QPixmap>
31 #include <QVBoxLayout>
32 #include <QHBoxLayout>
33 #include <QFormLayout>
35 #include <kconfig.h>
36 #include <kdialog.h>
37 #include <kdebug.h>
38 #include <kglobalsettings.h>
39 #include <kcolorscheme.h>
40 #include <kseparator.h>
41 #include <QtDBus/QtDBus>
43 #include <X11/X.h>
44 #include <X11/Xlib.h>
45 #include <X11/Xutil.h>
47 #include <stdlib.h>
49 #include "mouse.moc"
51 namespace {
53 char const * const cnf_Max[] = {
54 "MaximizeButtonLeftClickCommand",
55 "MaximizeButtonMiddleClickCommand",
56 "MaximizeButtonRightClickCommand",
59 char const * const tbl_Max[] = {
60 "Maximize",
61 "Maximize (vertical only)",
62 "Maximize (horizontal only)",
63 "" };
65 QPixmap maxButtonPixmaps[3];
67 void createMaxButtonPixmaps()
69 char const * maxButtonXpms[][3 + 13] = {
70 {0, 0, 0,
71 "...............",
72 ".......#.......",
73 "......###......",
74 ".....#####.....",
75 "..#....#....#..",
76 ".##....#....##.",
77 "###############",
78 ".##....#....##.",
79 "..#....#....#..",
80 ".....#####.....",
81 "......###......",
82 ".......#.......",
83 "..............."},
84 {0, 0, 0,
85 "...............",
86 ".......#.......",
87 "......###......",
88 ".....#####.....",
89 ".......#.......",
90 ".......#.......",
91 ".......#.......",
92 ".......#.......",
93 ".......#.......",
94 ".....#####.....",
95 "......###......",
96 ".......#.......",
97 "..............."},
98 {0, 0, 0,
99 "...............",
100 "...............",
101 "...............",
102 "...............",
103 "..#.........#..",
104 ".##.........##.",
105 "###############",
106 ".##.........##.",
107 "..#.........#..",
108 "...............",
109 "...............",
110 "...............",
111 "..............."},
114 QByteArray baseColor(". c " + KColorScheme(QPalette::Active, KColorScheme::View).background().color().name().toAscii());
115 QByteArray textColor("# c " + KColorScheme(QPalette::Active, KColorScheme::View).foreground().color().name().toAscii());
116 for (int t = 0; t < 3; ++t)
118 maxButtonXpms[t][0] = "15 13 2 1";
119 maxButtonXpms[t][1] = baseColor.constData();
120 maxButtonXpms[t][2] = textColor.constData();
121 maxButtonPixmaps[t] = QPixmap(maxButtonXpms[t]);
122 maxButtonPixmaps[t].setMask(maxButtonPixmaps[t].createHeuristicMask());
126 } // namespace
128 void KTitleBarActionsConfig::paletteChanged()
130 createMaxButtonPixmaps();
131 for (int b = 0; b < 3; ++b)
132 for (int t = 0; t < 3; ++t)
133 coMax[b]->setItemIcon(t, maxButtonPixmaps[t]);
137 KTitleBarActionsConfig::KTitleBarActionsConfig (bool _standAlone, KConfig *_config, const KComponentData &inst, QWidget * parent)
138 : KCModule(inst, parent), config(_config), standAlone(_standAlone)
140 QString strWin1, strWin2, strWin3, strAllKey, strAll1, strAll2, strAll3;
141 QGridLayout *grid;
142 QGroupBox *box;
143 QLabel *label;
144 QString strMouseButton1, strMouseButton3;
145 QString txtButton1, txtButton3;
146 QStringList items;
147 bool leftHandedMouse = ( KGlobalSettings::mouseSettings().handed == KGlobalSettings::KMouseSettings::LeftHanded);
149 QVBoxLayout *layout = new QVBoxLayout(this);
150 layout->setMargin(0);
151 layout->setSpacing(KDialog::spacingHint());
153 /** Titlebar doubleclick ************/
155 QGridLayout *gLayout = new QGridLayout();
156 layout->addLayout( gLayout );
158 QComboBox* combo = new QComboBox(this);
159 combo->addItem(i18n("Maximize"));
160 combo->addItem(i18n("Maximize (vertical only)"));
161 combo->addItem(i18n("Maximize (horizontal only)"));
162 combo->addItem(i18n("Minimize"));
163 combo->addItem(i18n("Shade"));
164 combo->addItem(i18n("Lower"));
165 combo->addItem(i18n("On All Desktops"));
166 combo->addItem(i18n("Nothing"));
167 combo->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
168 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
169 coTiDbl = combo;
170 combo->setWhatsThis( i18n("Behavior on <em>double</em> click into the titlebar."));
172 combo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
173 label = new QLabel(i18n("&Titlebar double-click:"), this);
174 label->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
175 label->setBuddy(combo);
176 gLayout->addWidget(label, 0, 0);
177 gLayout->addWidget(combo, 0, 1);
179 /** Mouse Wheel Events **************/
180 // Titlebar and frame mouse Wheel
181 QComboBox* comboW = new QComboBox(this);
182 comboW->addItem(i18n("Raise/Lower"));
183 comboW->addItem(i18n("Shade/Unshade"));
184 comboW->addItem(i18n("Maximize/Restore"));
185 comboW->addItem(i18n("Keep Above/Below"));
186 comboW->addItem(i18n("Move to Previous/Next Desktop"));
187 comboW->addItem(i18n("Change Opacity"));
188 comboW->addItem(i18n("Nothing"));
189 comboW->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
190 connect(comboW, SIGNAL(activated(int)), SLOT(changed()));
191 coTiAct4 = comboW;
192 comboW->setWhatsThis( i18n("Handle mouse wheel events"));
194 comboW->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
195 label = new QLabel(i18n("Titlebar wheel event:"), this);
196 label->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
197 label->setBuddy(comboW);
198 gLayout->addWidget(label, 1, 0);
199 gLayout->addWidget(comboW, 1, 1);
201 /** Titlebar and frame **************/
203 box = new QGroupBox(i18n("Titlebar && Frame"), this);
204 layout->addWidget(box);
205 box->setObjectName(QString::fromLatin1("Titlebar and Frame"));
206 box->setWhatsThis( i18n("Here you can customize mouse click behavior when clicking on the"
207 " titlebar or the frame of a window.") );
209 grid = new QGridLayout(box);
210 grid->setMargin(KDialog::marginHint());
211 grid->setSpacing(KDialog::spacingHint());
214 strMouseButton1 = i18n("Left button:");
215 txtButton1 = i18n("In this row you can customize left click behavior when clicking into"
216 " the titlebar or the frame.");
218 strMouseButton3 = i18n("Right button:");
219 txtButton3 = i18n("In this row you can customize right click behavior when clicking into"
220 " the titlebar or the frame." );
222 if ( leftHandedMouse )
224 qSwap(strMouseButton1, strMouseButton3);
225 qSwap(txtButton1, txtButton3);
228 label = new QLabel(strMouseButton1, box);
229 label->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
230 grid->addWidget(label, 1, 0);
231 label->setWhatsThis( txtButton1);
233 label = new QLabel(i18n("Middle button:"), box);
234 label->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
235 grid->addWidget(label, 2, 0);
236 label->setWhatsThis( i18n("In this row you can customize middle click behavior when clicking into"
237 " the titlebar or the frame.") );
239 label = new QLabel(strMouseButton3, box);
240 label->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
241 grid->addWidget(label, 3, 0);
242 label->setWhatsThis( txtButton3);
245 label = new QLabel(i18n("Active"), box);
246 grid->addWidget(label, 0, 1);
247 label->setAlignment(Qt::AlignCenter);
248 label->setWhatsThis( i18n("In this column you can customize mouse clicks into the titlebar"
249 " or the frame of an active window.") );
251 // Titlebar and frame, active, mouse button 1
252 combo = new QComboBox(box);
253 combo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
254 grid->addWidget(combo, 1, 1);
255 combo->addItem(i18n("Raise"));
256 combo->addItem(i18n("Lower"));
257 combo->addItem(i18n("Operations Menu"));
258 combo->addItem(i18n("Toggle Raise & Lower"));
259 combo->addItem(i18n("Nothing"));
260 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
261 coTiAct1 = combo;
263 txtButton1 = i18n("Behavior on <em>left</em> click into the titlebar or frame of an "
264 "<em>active</em> window.");
266 txtButton3 = i18n("Behavior on <em>right</em> click into the titlebar or frame of an "
267 "<em>active</em> window.");
269 // Be nice to left handed users
270 if ( leftHandedMouse ) qSwap(txtButton1, txtButton3);
272 combo->setWhatsThis( txtButton1);
274 // Titlebar and frame, active, mouse button 2
276 items << i18n("Raise")
277 << i18n("Lower")
278 << i18n("Operations Menu")
279 << i18n("Toggle Raise & Lower")
280 << i18n("Nothing")
281 << i18n("Shade");
283 combo = new QComboBox(box);
284 combo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
285 grid->addWidget(combo, 2, 1);
286 combo->addItems(items);
287 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
288 coTiAct2 = combo;
289 combo->setWhatsThis( i18n("Behavior on <em>middle</em> click into the titlebar or frame of an <em>active</em> window."));
291 // Titlebar and frame, active, mouse button 3
292 combo = new QComboBox(box);
293 combo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
294 grid->addWidget(combo, 3, 1);
295 combo->addItems(items);
296 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
297 coTiAct3 = combo;
298 combo->setWhatsThis( txtButton3 );
300 txtButton1 = i18n("Behavior on <em>left</em> click into the titlebar or frame of an "
301 "<em>inactive</em> window.");
303 txtButton3 = i18n("Behavior on <em>right</em> click into the titlebar or frame of an "
304 "<em>inactive</em> window.");
306 // Be nice to left handed users
307 if ( leftHandedMouse ) qSwap(txtButton1, txtButton3);
309 label = new QLabel(i18n("Inactive"), box);
310 grid->addWidget(label, 0, 2);
311 label->setAlignment(Qt::AlignCenter);
312 label->setWhatsThis( i18n("In this column you can customize mouse clicks into the titlebar"
313 " or the frame of an inactive window.") );
315 items.clear();
316 items << i18n("Activate & Raise")
317 << i18n("Activate & Lower")
318 << i18n("Activate")
319 << i18n("Shade")
320 << i18n("Operations Menu")
321 << i18n("Raise")
322 << i18n("Lower")
323 << i18n("Nothing");
325 combo = new QComboBox(box);
326 combo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
327 grid->addWidget(combo, 1, 2);
328 combo->addItems(items);
329 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
330 coTiInAct1 = combo;
331 combo->setWhatsThis( txtButton1);
333 combo = new QComboBox(box);
334 combo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
335 grid->addWidget(combo, 2, 2);
336 combo->addItems(items);
337 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
338 coTiInAct2 = combo;
339 combo->setWhatsThis( i18n("Behavior on <em>middle</em> click into the titlebar or frame of an <em>inactive</em> window."));
341 combo = new QComboBox(box);
342 combo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
343 grid->addWidget(combo, 3, 2);
344 combo->addItems(items);
345 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
346 coTiInAct3 = combo;
347 combo->setWhatsThis( txtButton3);
349 /** Maximize Button ******************/
351 box = new QGroupBox(i18n("Maximize Button"), this);
352 layout->addWidget(box);
353 box->setObjectName(QString::fromLatin1("Maximize Button"));
354 box->setWhatsThis(
355 i18n("Here you can customize behavior when clicking on the maximize button.") );
357 QHBoxLayout* hlayout = new QHBoxLayout(box);
358 hlayout->setMargin(KDialog::marginHint());
359 hlayout->setSpacing(KDialog::spacingHint());
361 QString strMouseButton[] = {
362 i18n("Left button:"),
363 i18n("Middle button:"),
364 i18n("Right button:")};
366 QString txtButton[] = {
367 i18n("Behavior on <em>left</em> click onto the maximize button." ),
368 i18n("Behavior on <em>middle</em> click onto the maximize button." ),
369 i18n("Behavior on <em>right</em> click onto the maximize button." )};
371 if ( leftHandedMouse ) // Be nice to lefties
373 qSwap(strMouseButton[0], strMouseButton[2]);
374 qSwap(txtButton[0], txtButton[2]);
377 createMaxButtonPixmaps();
378 for (int b = 0; b < 3; ++b)
380 if (b != 0) hlayout->addItem(new QSpacerItem(5, 5, QSizePolicy::MinimumExpanding, QSizePolicy::Minimum)); // Spacer
382 QLabel * label = new QLabel(strMouseButton[b], box);
383 hlayout->addWidget(label);
384 label->setWhatsThis( txtButton[b] );
385 label->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Minimum );
387 coMax[b] = new ToolTipComboBox(box, tbl_Max);
388 hlayout->addWidget(coMax[b]);
389 for (int t = 0; t < 3; ++t) coMax[b]->addItem(maxButtonPixmaps[t], QString());
390 connect(coMax[b], SIGNAL(activated(int)), SLOT(changed()));
391 connect(coMax[b], SIGNAL(activated(int)), coMax[b], SLOT(changed()));
392 coMax[b]->setWhatsThis( txtButton[b] );
393 coMax[b]->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Minimum );
396 connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), SLOT(paletteChanged()));
398 layout->addStretch();
400 load();
403 KTitleBarActionsConfig::~KTitleBarActionsConfig()
405 if (standAlone)
406 delete config;
409 // do NOT change the texts below, they are written to config file
410 // and are not shown in the GUI
411 // they have to match the order of items in GUI elements though
412 const char* const tbl_TiDbl[] = {
413 "Maximize",
414 "Maximize (vertical only)",
415 "Maximize (horizontal only)",
416 "Minimize",
417 "Shade",
418 "Lower",
419 "OnAllDesktops",
420 "Nothing",
421 "" };
423 const char* const tbl_TiAc[] = {
424 "Raise",
425 "Lower",
426 "Operations menu",
427 "Toggle raise and lower",
428 "Nothing",
429 "Shade",
430 "" };
432 const char* const tbl_TiInAc[] = {
433 "Activate and raise",
434 "Activate and lower",
435 "Activate",
436 "Shade",
437 "Operations menu",
438 "Raise",
439 "Lower",
440 "Nothing",
441 "" };
443 const char* const tbl_Win[] = {
444 "Activate, raise and pass click",
445 "Activate and pass click",
446 "Activate",
447 "Activate and raise",
448 "" };
450 const char* const tbl_AllKey[] = {
451 "Meta",
452 "Alt",
453 "" };
455 const char* const tbl_All[] = {
456 "Move",
457 "Activate, raise and move",
458 "Toggle raise and lower",
459 "Resize",
460 "Raise",
461 "Lower",
462 "Minimize",
463 "Nothing",
464 "" };
466 const char* tbl_TiWAc[] = {
467 "Raise/Lower",
468 "Shade/Unshade",
469 "Maximize/Restore",
470 "Above/Below",
471 "Previous/Next Desktop",
472 "Change Opacity",
473 "Nothing",
474 "" };
476 const char* tbl_AllW[] = {
477 "Raise/Lower",
478 "Shade/Unshade",
479 "Maximize/Restore",
480 "Above/Below",
481 "Previous/Next Desktop",
482 "Change Opacity",
483 "Nothing",
484 "" };
486 static const char* tbl_num_lookup( const char* const arr[], int pos )
488 for( int i = 0;
489 arr[ i ][ 0 ] != '\0' && pos >= 0;
490 ++i )
492 if( pos == 0 )
493 return arr[ i ];
494 --pos;
496 abort(); // should never happen this way
499 static int tbl_txt_lookup( const char* const arr[], const char* txt )
501 int pos = 0;
502 for( int i = 0;
503 arr[ i ][ 0 ] != '\0';
504 ++i )
506 if( qstricmp( txt, arr[ i ] ) == 0 )
507 return pos;
508 ++pos;
510 return 0;
513 void KTitleBarActionsConfig::setComboText( QComboBox* combo, const char*txt )
515 if( combo == coTiDbl )
516 combo->setCurrentIndex( tbl_txt_lookup( tbl_TiDbl, txt ));
517 else if( combo == coTiAct1 || combo == coTiAct2 || combo == coTiAct3 )
518 combo->setCurrentIndex( tbl_txt_lookup( tbl_TiAc, txt ));
519 else if( combo == coTiInAct1 || combo == coTiInAct2 || combo == coTiInAct3 )
520 combo->setCurrentIndex( tbl_txt_lookup( tbl_TiInAc, txt ));
521 else if( combo == coTiAct4 )
522 combo->setCurrentIndex( tbl_txt_lookup( tbl_TiWAc, txt ));
523 else if( combo == coMax[0] || combo == coMax[1] || combo == coMax[2] )
525 combo->setCurrentIndex( tbl_txt_lookup( tbl_Max, txt ));
526 static_cast<ToolTipComboBox *>(combo)->changed();
528 else
529 abort();
532 const char* KTitleBarActionsConfig::functionTiDbl( int i )
534 return tbl_num_lookup( tbl_TiDbl, i );
537 const char* KTitleBarActionsConfig::functionTiAc( int i )
539 return tbl_num_lookup( tbl_TiAc, i );
542 const char* KTitleBarActionsConfig::functionTiInAc( int i )
544 return tbl_num_lookup( tbl_TiInAc, i );
547 const char* KTitleBarActionsConfig::functionTiWAc(int i)
549 return tbl_num_lookup( tbl_TiWAc, i );
552 const char* KTitleBarActionsConfig::functionMax( int i )
554 return tbl_num_lookup( tbl_Max, i );
557 void KTitleBarActionsConfig::load()
559 KConfigGroup windowsConfig(config, "Windows");
560 setComboText(coTiDbl, windowsConfig.readEntry("TitlebarDoubleClickCommand","Maximize").toAscii());
561 for (int t = 0; t < 3; ++t)
562 setComboText(coMax[t],windowsConfig.readEntry(cnf_Max[t], tbl_Max[t]).toAscii());
564 KConfigGroup cg(config, "MouseBindings");
565 setComboText(coTiAct1,cg.readEntry("CommandActiveTitlebar1","Raise").toAscii());
566 setComboText(coTiAct2,cg.readEntry("CommandActiveTitlebar2","Lower").toAscii());
567 setComboText(coTiAct3,cg.readEntry("CommandActiveTitlebar3","Operations menu").toAscii());
568 setComboText(coTiAct4,cg.readEntry("CommandTitlebarWheel","Nothing").toAscii());
569 setComboText(coTiInAct1,cg.readEntry("CommandInactiveTitlebar1","Activate and raise").toAscii());
570 setComboText(coTiInAct2,cg.readEntry("CommandInactiveTitlebar2","Activate and lower").toAscii());
571 setComboText(coTiInAct3,cg.readEntry("CommandInactiveTitlebar3","Operations menu").toAscii());
574 void KTitleBarActionsConfig::save()
576 KConfigGroup windowsConfig(config, "Windows");
577 windowsConfig.writeEntry("TitlebarDoubleClickCommand", functionTiDbl( coTiDbl->currentIndex() ) );
578 for (int t = 0; t < 3; ++t)
579 windowsConfig.writeEntry(cnf_Max[t], functionMax(coMax[t]->currentIndex()));
581 KConfigGroup cg(config, "MouseBindings");
582 cg.writeEntry("CommandActiveTitlebar1", functionTiAc(coTiAct1->currentIndex()));
583 cg.writeEntry("CommandActiveTitlebar2", functionTiAc(coTiAct2->currentIndex()));
584 cg.writeEntry("CommandActiveTitlebar3", functionTiAc(coTiAct3->currentIndex()));
585 cg.writeEntry("CommandInactiveTitlebar1", functionTiInAc(coTiInAct1->currentIndex()));
586 cg.writeEntry("CommandTitlebarWheel", functionTiWAc(coTiAct4->currentIndex()));
587 cg.writeEntry("CommandInactiveTitlebar2", functionTiInAc(coTiInAct2->currentIndex()));
588 cg.writeEntry("CommandInactiveTitlebar3", functionTiInAc(coTiInAct3->currentIndex()));
590 if (standAlone)
592 config->sync();
593 // Send signal to all kwin instances
594 QDBusMessage message =
595 QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig");
596 QDBusConnection::sessionBus().send(message);
601 void KTitleBarActionsConfig::defaults()
603 setComboText(coTiDbl, "Shade");
604 setComboText(coTiAct1,"Raise");
605 setComboText(coTiAct2,"Lower");
606 setComboText(coTiAct3,"Operations menu");
607 setComboText(coTiAct4,"Nothing");
608 setComboText(coTiInAct1,"Activate and raise");
609 setComboText(coTiInAct2,"Activate and lower");
610 setComboText(coTiInAct3,"Operations menu");
611 for (int t = 0; t < 3; ++t)
612 setComboText(coMax[t], tbl_Max[t]);
616 KWindowActionsConfig::KWindowActionsConfig (bool _standAlone, KConfig *_config, const KComponentData &inst, QWidget * parent)
617 : KCModule(inst, parent), config(_config), standAlone(_standAlone)
619 QString strWin1, strWin2, strWin3, strAllKey, strAll1, strAll2, strAll3, strAllW;
620 QGroupBox *box;
621 QString strMouseButton1, strMouseButton2, strMouseButton3;
622 QString txtButton1, txtButton2, txtButton3;
623 QStringList items;
624 bool leftHandedMouse = ( KGlobalSettings::mouseSettings().handed == KGlobalSettings::KMouseSettings::LeftHanded);
626 QVBoxLayout *layout = new QVBoxLayout(this);
627 layout->setMargin(0);
628 layout->setSpacing(KDialog::spacingHint());
630 /** Inactive inner window ******************/
632 box = new QGroupBox(i18n("Inactive Inner Window"), this);
633 layout->addWidget(box);
634 box->setObjectName(QString::fromLatin1("Inactive Inner Window"));
635 box->setWhatsThis( i18n("Here you can customize mouse click behavior when clicking on an inactive"
636 " inner window ('inner' means: not titlebar, not frame).") );
638 QGridLayout *gridLayout = new QGridLayout(box);
639 gridLayout->setMargin(KDialog::marginHint());
640 gridLayout->setSpacing(KDialog::spacingHint());
642 strMouseButton1 = i18n("Left button:");
643 txtButton1 = i18n("In this row you can customize left click behavior when clicking into"
644 " the titlebar or the frame.");
646 strMouseButton2 = i18n("Middle button:");
647 txtButton2 = i18n("In this row you can customize middle click behavior when clicking into"
648 " the titlebar or the frame." );
650 strMouseButton3 = i18n("Right button:");
651 txtButton3 = i18n("In this row you can customize right click behavior when clicking into"
652 " the titlebar or the frame." );
654 if ( leftHandedMouse )
656 qSwap(strMouseButton1, strMouseButton3);
657 qSwap(txtButton1, txtButton3);
660 strWin1 = i18n("In this row you can customize left click behavior when clicking into"
661 " an inactive inner window ('inner' means: not titlebar, not frame).");
663 strWin2 = i18n("In this row you can customize middle click behavior when clicking into"
664 " an inactive inner window ('inner' means: not titlebar, not frame).");
666 strWin3 = i18n("In this row you can customize right click behavior when clicking into"
667 " an inactive inner window ('inner' means: not titlebar, not frame).");
669 // Be nice to lefties
670 if ( leftHandedMouse ) qSwap(strWin1, strWin3);
672 items.clear();
673 items << i18n("Activate, Raise & Pass Click")
674 << i18n("Activate & Pass Click")
675 << i18n("Activate")
676 << i18n("Activate & Raise");
678 QComboBox* combo = new QComboBox(box);
679 coWin1 = combo;
680 combo->addItems(items);
681 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
682 combo->setWhatsThis( strWin1 );
683 combo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
684 QLabel* label = new QLabel(strMouseButton1, this);
685 label->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
686 label->setBuddy(combo);
687 gridLayout->addWidget(label, 0, 0);
688 gridLayout->addWidget(combo, 0, 1);
690 combo = new QComboBox(box);
691 combo->addItems(items);
692 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
693 coWin2 = combo;
694 combo->setWhatsThis( strWin2 );
695 combo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
696 label = new QLabel(strMouseButton2, this);
697 label->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
698 label->setBuddy(combo);
699 gridLayout->addWidget(label, 1, 0);
700 gridLayout->addWidget(combo, 1, 1);
702 combo = new QComboBox(box);
703 combo->addItems(items);
704 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
705 coWin3 = combo;
706 combo->setWhatsThis( strWin3 );
707 combo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
708 label = new QLabel(strMouseButton3, this);
709 label->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
710 label->setBuddy(combo);
711 gridLayout->addWidget(label, 2, 0);
712 gridLayout->addWidget(combo, 2, 1);
715 /** Inner window, titlebar and frame **************/
717 box = new QGroupBox(i18n("Inner Window, Titlebar && Frame"), this);
718 layout->addWidget(box);
719 box->setObjectName(QString::fromLatin1("Inner Window, Titlebar and Frame"));
720 box->setWhatsThis( i18n("Here you can customize KDE's behavior when clicking somewhere into"
721 " a window while pressing a modifier key."));
723 QHBoxLayout* innerLay=new QHBoxLayout(box);
724 innerLay->setContentsMargins(0,0,0,0);
725 innerLay->setSpacing(KDialog::spacingHint());
726 QHBoxLayout* fLay=new QHBoxLayout;
727 fLay->setMargin(KDialog::marginHint());
728 fLay->setSpacing(KDialog::spacingHint());
729 gridLayout = new QGridLayout;
730 gridLayout->setMargin(KDialog::marginHint());
731 gridLayout->setSpacing(KDialog::spacingHint());
732 innerLay->addLayout(fLay);
733 innerLay->addLayout(gridLayout);
735 // Labels
736 strMouseButton1 = i18n("Left button:");
737 strAll1 = i18n("In this row you can customize left click behavior when clicking into"
738 " the titlebar or the frame.");
740 strMouseButton2 = i18n("Middle button:");
741 strAll2 = i18n("In this row you can customize middle click behavior when clicking into"
742 " the titlebar or the frame." );
744 strMouseButton3 = i18n("Right button:");
745 strAll3 = i18n("In this row you can customize right click behavior when clicking into"
746 " the titlebar or the frame." );
748 if ( leftHandedMouse )
750 qSwap(strMouseButton1, strMouseButton3);
751 qSwap(strAll1, strAll3);
754 // Combo's
755 combo = new QComboBox(box);
756 combo->addItem(i18n("Meta"));
757 combo->addItem(i18n("Alt"));
758 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
759 coAllKey = combo;
760 combo->setWhatsThis( i18n("Here you select whether holding the Meta key or Alt key "
761 "will allow you to perform the following actions.") );
762 combo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
763 label = new QLabel(i18n("Modifier key:"), this);
764 label->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
765 label->setBuddy(combo);
766 fLay->addWidget(label);
767 fLay->addWidget(combo);
768 fLay->addWidget(new QLabel(" + ", this));
771 items.clear();
772 items << i18n("Move")
773 << i18n("Activate, Raise and Move")
774 << i18n("Toggle Raise & Lower")
775 << i18n("Resize")
776 << i18n("Raise")
777 << i18n("Lower")
778 << i18n("Minimize")
779 << i18n("Nothing");
781 combo = new QComboBox(box);
782 combo->addItems(items);
783 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
784 coAll1 = combo;
785 combo->setWhatsThis( strAll1 );
786 combo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
787 label = new QLabel(strMouseButton1, this);
788 label->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
789 label->setBuddy(combo);
790 gridLayout->addWidget(label, 0, 0);
791 gridLayout->addWidget(combo, 0, 1);
794 combo = new QComboBox(box);
795 combo->addItems(items);
796 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
797 coAll2 = combo;
798 combo->setWhatsThis( strAll2 );
799 combo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
800 label = new QLabel(strMouseButton2, this);
801 label->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
802 label->setBuddy(combo);
803 gridLayout->addWidget(label, 1, 0);
804 gridLayout->addWidget(combo, 1, 1);
806 combo = new QComboBox(box);
807 combo->addItems(items);
808 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
809 coAll3 = combo;
810 combo->setWhatsThis( strAll3 );
811 combo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
812 label = new QLabel(strMouseButton3, this);
813 label->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
814 label->setBuddy(combo);
815 gridLayout->addWidget(label, 2, 0);
816 gridLayout->addWidget(combo, 2, 1);
819 combo = new QComboBox(box);
820 combo->addItem(i18n("Raise/Lower"));
821 combo->addItem(i18n("Shade/Unshade"));
822 combo->addItem(i18n("Maximize/Restore"));
823 combo->addItem(i18n("Keep Above/Below"));
824 combo->addItem(i18n("Move to Previous/Next Desktop"));
825 combo->addItem(i18n("Change Opacity"));
826 combo->addItem(i18n("Nothing"));
827 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
828 coAllW = combo;
829 combo->setWhatsThis( i18n("Here you can customize KDE's behavior when scrolling with the mouse wheel"
830 " in a window while pressing the modifier key.") );
831 combo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
832 label = new QLabel(i18n("Mouse wheel:"), this);
833 label->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
834 label->setBuddy(combo);
835 gridLayout->addWidget(label, 3, 0);
836 gridLayout->addWidget(combo, 3, 1);
839 layout->addStretch();
840 load();
843 KWindowActionsConfig::~KWindowActionsConfig()
845 if (standAlone)
846 delete config;
849 void KWindowActionsConfig::setComboText( QComboBox* combo, const char*txt )
851 if( combo == coWin1 || combo == coWin2 || combo == coWin3 )
852 combo->setCurrentIndex( tbl_txt_lookup( tbl_Win, txt ));
853 else if( combo == coAllKey )
854 combo->setCurrentIndex( tbl_txt_lookup( tbl_AllKey, txt ));
855 else if( combo == coAll1 || combo == coAll2 || combo == coAll3 )
856 combo->setCurrentIndex( tbl_txt_lookup( tbl_All, txt ));
857 else if( combo == coAllW )
858 combo->setCurrentIndex( tbl_txt_lookup( tbl_AllW, txt ));
859 else
860 abort();
863 const char* KWindowActionsConfig::functionWin( int i )
865 return tbl_num_lookup( tbl_Win, i );
868 const char* KWindowActionsConfig::functionAllKey( int i )
870 return tbl_num_lookup( tbl_AllKey, i );
873 const char* KWindowActionsConfig::functionAll( int i )
875 return tbl_num_lookup( tbl_All, i );
878 const char* KWindowActionsConfig::functionAllW(int i)
880 return tbl_num_lookup( tbl_AllW, i );
883 void KWindowActionsConfig::load()
885 KConfigGroup cg(config, "MouseBindings");
886 setComboText(coWin1,cg.readEntry("CommandWindow1","Activate, raise and pass click").toAscii());
887 setComboText(coWin2,cg.readEntry("CommandWindow2","Activate and pass click").toAscii());
888 setComboText(coWin3,cg.readEntry("CommandWindow3","Activate and pass click").toAscii());
889 setComboText(coAllKey,cg.readEntry("CommandAllKey","Alt").toAscii());
890 setComboText(coAll1,cg.readEntry("CommandAll1","Move").toAscii());
891 setComboText(coAll2,cg.readEntry("CommandAll2","Toggle raise and lower").toAscii());
892 setComboText(coAll3,cg.readEntry("CommandAll3","Resize").toAscii());
893 setComboText(coAllW,cg.readEntry("CommandAllWheel","Nothing").toAscii());
896 void KWindowActionsConfig::save()
898 KConfigGroup cg(config, "MouseBindings");
899 cg.writeEntry("CommandWindow1", functionWin(coWin1->currentIndex()));
900 cg.writeEntry("CommandWindow2", functionWin(coWin2->currentIndex()));
901 cg.writeEntry("CommandWindow3", functionWin(coWin3->currentIndex()));
902 cg.writeEntry("CommandAllKey", functionAllKey(coAllKey->currentIndex()));
903 cg.writeEntry("CommandAll1", functionAll(coAll1->currentIndex()));
904 cg.writeEntry("CommandAll2", functionAll(coAll2->currentIndex()));
905 cg.writeEntry("CommandAll3", functionAll(coAll3->currentIndex()));
906 cg.writeEntry("CommandAllWheel", functionAllW(coAllW->currentIndex()));
908 if (standAlone)
910 config->sync();
911 // Send signal to all kwin instances
912 QDBusMessage message =
913 QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig");
914 QDBusConnection::sessionBus().send(message);
918 void KWindowActionsConfig::defaults()
920 setComboText(coWin1,"Activate, raise and pass click");
921 setComboText(coWin2,"Activate and pass click");
922 setComboText(coWin3,"Activate and pass click");
923 setComboText(coAllKey,"Alt");
924 setComboText (coAll1,"Move");
925 setComboText(coAll2,"Toggle raise and lower");
926 setComboText(coAll3,"Resize");
927 setComboText(coAllW,"Nothing");