Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / kwin / kcmkwin / kwinoptions / mouse.cpp
blob6518d765a1f738a77bed5c38b714d03a53fae0c1
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 <QLabel>
21 #include <QComboBox>
23 #include <QLayout>
24 #include <QSizePolicy>
25 #include <QBitmap>
27 #include <QGroupBox>
28 #include <QPixmap>
29 #include <QVBoxLayout>
30 #include <QHBoxLayout>
32 #include <klocale.h>
33 #include <kconfig.h>
34 #include <kdialog.h>
35 #include <kglobalsettings.h>
36 #include <kcolorscheme.h>
37 #include <kseparator.h>
38 #include <QtDBus/QtDBus>
40 #include <X11/X.h>
41 #include <X11/Xlib.h>
42 #include <X11/Xutil.h>
44 #include <stdlib.h>
46 #include "mouse.h"
47 #include "mouse.moc"
49 namespace {
51 char const * const cnf_Max[] = {
52 "MaximizeButtonLeftClickCommand",
53 "MaximizeButtonMiddleClickCommand",
54 "MaximizeButtonRightClickCommand",
57 char const * const tbl_Max[] = {
58 "Maximize",
59 "Maximize (vertical only)",
60 "Maximize (horizontal only)",
61 "" };
63 QPixmap maxButtonPixmaps[3];
65 void createMaxButtonPixmaps()
67 char const * maxButtonXpms[][3 + 13] = {
68 {0, 0, 0,
69 "...............",
70 ".......#.......",
71 "......###......",
72 ".....#####.....",
73 "..#....#....#..",
74 ".##....#....##.",
75 "###############",
76 ".##....#....##.",
77 "..#....#....#..",
78 ".....#####.....",
79 "......###......",
80 ".......#.......",
81 "..............."},
82 {0, 0, 0,
83 "...............",
84 ".......#.......",
85 "......###......",
86 ".....#####.....",
87 ".......#.......",
88 ".......#.......",
89 ".......#.......",
90 ".......#.......",
91 ".......#.......",
92 ".....#####.....",
93 "......###......",
94 ".......#.......",
95 "..............."},
96 {0, 0, 0,
97 "...............",
98 "...............",
99 "...............",
100 "...............",
101 "..#.........#..",
102 ".##.........##.",
103 "###############",
104 ".##.........##.",
105 "..#.........#..",
106 "...............",
107 "...............",
108 "...............",
109 "..............."},
112 QByteArray baseColor(". c " + KColorScheme(QPalette::Active, KColorScheme::View).background().color().name().toAscii());
113 QByteArray textColor("# c " + KColorScheme(QPalette::Active, KColorScheme::View).foreground().color().name().toAscii());
114 for (int t = 0; t < 3; ++t)
116 maxButtonXpms[t][0] = "15 13 2 1";
117 maxButtonXpms[t][1] = baseColor.constData();
118 maxButtonXpms[t][2] = textColor.constData();
119 maxButtonPixmaps[t] = QPixmap(maxButtonXpms[t]);
120 maxButtonPixmaps[t].setMask(maxButtonPixmaps[t].createHeuristicMask());
124 } // namespace
126 void KTitleBarActionsConfig::paletteChanged()
128 createMaxButtonPixmaps();
129 for (int b = 0; b < 3; ++b)
130 for (int t = 0; t < 3; ++t)
131 coMax[b]->setItemIcon(t, maxButtonPixmaps[t]);
135 KTitleBarActionsConfig::KTitleBarActionsConfig (bool _standAlone, KConfig *_config, const KComponentData &inst, QWidget * parent)
136 : KCModule(inst, parent), config(_config), standAlone(_standAlone)
138 QString strWin1, strWin2, strWin3, strAllKey, strAll1, strAll2, strAll3;
139 QGridLayout *grid;
140 QGroupBox *box;
141 QLabel *label;
142 QString strMouseButton1, strMouseButton3, strMouseWheel;
143 QString txtButton1, txtButton3, txtButton4;
144 QStringList items;
145 bool leftHandedMouse = ( KGlobalSettings::mouseSettings().handed == KGlobalSettings::KMouseSettings::LeftHanded);
147 QVBoxLayout *layout = new QVBoxLayout(this);
148 layout->setMargin(0);
149 layout->setSpacing(KDialog::spacingHint());
151 /** Titlebar doubleclick ************/
153 QHBoxLayout *hlayout = new QHBoxLayout();
154 layout->addLayout( hlayout );
156 label = new QLabel(i18n("&Titlebar double-click:"), this);
157 hlayout->addWidget(label);
158 label->setWhatsThis( i18n("Here you can customize mouse click behavior when double clicking on the"
159 " titlebar of a window.") );
161 QComboBox* combo = new QComboBox(this);
162 combo->addItem(i18n("Maximize"));
163 combo->addItem(i18n("Maximize (vertical only)"));
164 combo->addItem(i18n("Maximize (horizontal only)"));
165 combo->addItem(i18n("Minimize"));
166 combo->addItem(i18n("Shade"));
167 combo->addItem(i18n("Lower"));
168 combo->addItem(i18n("On All Desktops"));
169 combo->addItem(i18n("Nothing"));
170 combo->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed));
171 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
172 hlayout->addWidget(combo);
173 coTiDbl = combo;
174 combo->setWhatsThis( i18n("Behavior on <em>double</em> click into the titlebar."));
176 label->setBuddy(combo);
178 /** Mouse Wheel Events **************/
179 QHBoxLayout *hlayoutW = new QHBoxLayout();
180 layout->addLayout( hlayoutW );
181 strMouseWheel = i18n("Titlebar wheel event:");
182 label = new QLabel(strMouseWheel, this);
183 hlayoutW->addWidget(label);
184 txtButton4 = i18n("Handle mouse wheel events");
185 label->setWhatsThis( txtButton4);
187 // Titlebar and frame mouse Wheel
188 QComboBox* comboW = new QComboBox(this);
189 comboW->addItem(i18n("Raise/Lower"));
190 comboW->addItem(i18n("Shade/Unshade"));
191 comboW->addItem(i18n("Maximize/Restore"));
192 comboW->addItem(i18n("Keep Above/Below"));
193 comboW->addItem(i18n("Move to Previous/Next Desktop"));
194 comboW->addItem(i18n("Change Opacity"));
195 comboW->addItem(i18n("Nothing"));
196 comboW->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed));
197 connect(comboW, SIGNAL(activated(int)), SLOT(changed()));
198 hlayoutW->addWidget(comboW);
199 coTiAct4 = comboW;
200 comboW->setWhatsThis( txtButton4);
201 label->setBuddy(comboW);
203 /** Titlebar and frame **************/
205 box = new QGroupBox(i18n("Titlebar && Frame"), this);
206 layout->addWidget(box);
207 box->setObjectName(QString::fromLatin1("Titlebar and Frame"));
208 box->setWhatsThis( i18n("Here you can customize mouse click behavior when clicking on the"
209 " titlebar or the frame of a window.") );
211 grid = new QGridLayout(box);
212 grid->setMargin(KDialog::marginHint());
213 grid->setSpacing(KDialog::spacingHint());
216 strMouseButton1 = i18n("Left button:");
217 txtButton1 = i18n("In this row you can customize left click behavior when clicking into"
218 " the titlebar or the frame.");
220 strMouseButton3 = i18n("Right button:");
221 txtButton3 = i18n("In this row you can customize right click behavior when clicking into"
222 " the titlebar or the frame." );
224 if ( leftHandedMouse )
226 qSwap(strMouseButton1, strMouseButton3);
227 qSwap(txtButton1, txtButton3);
230 label = new QLabel(strMouseButton1, box);
231 grid->addWidget(label, 1, 0);
232 label->setWhatsThis( txtButton1);
234 label = new QLabel(i18n("Middle button:"), box);
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 grid->addWidget(label, 3, 0);
241 label->setWhatsThis( txtButton3);
244 label = new QLabel(i18n("Active"), box);
245 grid->addWidget(label, 0, 1);
246 label->setAlignment(Qt::AlignCenter);
247 label->setWhatsThis( i18n("In this column you can customize mouse clicks into the titlebar"
248 " or the frame of an active window.") );
250 // Titlebar and frame, active, mouse button 1
251 combo = new QComboBox(box);
252 grid->addWidget(combo, 1, 1);
253 combo->addItem(i18n("Raise"));
254 combo->addItem(i18n("Lower"));
255 combo->addItem(i18n("Operations Menu"));
256 combo->addItem(i18n("Toggle Raise & Lower"));
257 combo->addItem(i18n("Nothing"));
258 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
259 coTiAct1 = combo;
261 txtButton1 = i18n("Behavior on <em>left</em> click into the titlebar or frame of an "
262 "<em>active</em> window.");
264 txtButton3 = i18n("Behavior on <em>right</em> click into the titlebar or frame of an "
265 "<em>active</em> window.");
267 // Be nice to left handed users
268 if ( leftHandedMouse ) qSwap(txtButton1, txtButton3);
270 combo->setWhatsThis( txtButton1);
272 // Titlebar and frame, active, mouse button 2
274 items << i18n("Raise")
275 << i18n("Lower")
276 << i18n("Operations Menu")
277 << i18n("Toggle Raise & Lower")
278 << i18n("Nothing")
279 << i18n("Shade");
281 combo = new QComboBox(box);
282 grid->addWidget(combo, 2, 1);
283 combo->addItems(items);
284 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
285 coTiAct2 = combo;
286 combo->setWhatsThis( i18n("Behavior on <em>middle</em> click into the titlebar or frame of an <em>active</em> window."));
288 // Titlebar and frame, active, mouse button 3
289 combo = new QComboBox(box);
290 grid->addWidget(combo, 3, 1);
291 combo->addItems(items);
292 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
293 coTiAct3 = combo;
294 combo->setWhatsThis( txtButton3 );
296 txtButton1 = i18n("Behavior on <em>left</em> click into the titlebar or frame of an "
297 "<em>inactive</em> window.");
299 txtButton3 = i18n("Behavior on <em>right</em> click into the titlebar or frame of an "
300 "<em>inactive</em> window.");
302 // Be nice to left handed users
303 if ( leftHandedMouse ) qSwap(txtButton1, txtButton3);
305 label = new QLabel(i18n("Inactive"), box);
306 grid->addWidget(label, 0, 2);
307 label->setAlignment(Qt::AlignCenter);
308 label->setWhatsThis( i18n("In this column you can customize mouse clicks into the titlebar"
309 " or the frame of an inactive window.") );
311 items.clear();
312 items << i18n("Activate & Raise")
313 << i18n("Activate & Lower")
314 << i18n("Activate")
315 << i18n("Shade")
316 << i18n("Operations Menu")
317 << i18n("Raise")
318 << i18n("Lower")
319 << i18n("Nothing");
321 combo = new QComboBox(box);
322 grid->addWidget(combo, 1, 2);
323 combo->addItems(items);
324 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
325 coTiInAct1 = combo;
326 combo->setWhatsThis( txtButton1);
328 combo = new QComboBox(box);
329 grid->addWidget(combo, 2, 2);
330 combo->addItems(items);
331 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
332 coTiInAct2 = combo;
333 combo->setWhatsThis( i18n("Behavior on <em>middle</em> click into the titlebar or frame of an <em>inactive</em> window."));
335 combo = new QComboBox(box);
336 grid->addWidget(combo, 3, 2);
337 combo->addItems(items);
338 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
339 coTiInAct3 = combo;
340 combo->setWhatsThis( txtButton3);
342 /** Maximize Button ******************/
344 box = new QGroupBox(i18n("Maximize Button"), this);
345 layout->addWidget(box);
346 box->setObjectName(QString::fromLatin1("Maximize Button"));
347 box->setWhatsThis(
348 i18n("Here you can customize behavior when clicking on the maximize button.") );
350 hlayout = new QHBoxLayout(box);
351 hlayout->setMargin(KDialog::marginHint());
352 hlayout->setSpacing(KDialog::spacingHint());
354 QString strMouseButton[] = {
355 i18n("Left button:"),
356 i18n("Middle button:"),
357 i18n("Right button:")};
359 QString txtButton[] = {
360 i18n("Behavior on <em>left</em> click onto the maximize button." ),
361 i18n("Behavior on <em>middle</em> click onto the maximize button." ),
362 i18n("Behavior on <em>right</em> click onto the maximize button." )};
364 if ( leftHandedMouse ) // Be nice to lefties
366 qSwap(strMouseButton[0], strMouseButton[2]);
367 qSwap(txtButton[0], txtButton[2]);
370 createMaxButtonPixmaps();
371 for (int b = 0; b < 3; ++b)
373 if (b != 0) hlayout->addItem(new QSpacerItem(5, 5, QSizePolicy::MinimumExpanding, QSizePolicy::Minimum)); // Spacer
375 QLabel * label = new QLabel(strMouseButton[b], box);
376 hlayout->addWidget(label);
377 label->setWhatsThis( txtButton[b] );
378 label ->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Minimum ));
380 coMax[b] = new ToolTipComboBox(box, tbl_Max);
381 hlayout->addWidget(coMax[b]);
382 for (int t = 0; t < 3; ++t) coMax[b]->addItem(maxButtonPixmaps[t], QString());
383 connect(coMax[b], SIGNAL(activated(int)), SLOT(changed()));
384 connect(coMax[b], SIGNAL(activated(int)), coMax[b], SLOT(changed()));
385 coMax[b]->setWhatsThis( txtButton[b] );
386 coMax[b]->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Minimum ));
389 connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), SLOT(paletteChanged()));
391 layout->addStretch();
393 load();
396 KTitleBarActionsConfig::~KTitleBarActionsConfig()
398 if (standAlone)
399 delete config;
402 // do NOT change the texts below, they are written to config file
403 // and are not shown in the GUI
404 // they have to match the order of items in GUI elements though
405 const char* const tbl_TiDbl[] = {
406 "Maximize",
407 "Maximize (vertical only)",
408 "Maximize (horizontal only)",
409 "Minimize",
410 "Shade",
411 "Lower",
412 "OnAllDesktops",
413 "Nothing",
414 "" };
416 const char* const tbl_TiAc[] = {
417 "Raise",
418 "Lower",
419 "Operations menu",
420 "Toggle raise and lower",
421 "Nothing",
422 "Shade",
423 "" };
425 const char* const tbl_TiInAc[] = {
426 "Activate and raise",
427 "Activate and lower",
428 "Activate",
429 "Shade",
430 "Operations menu",
431 "Raise",
432 "Lower",
433 "Nothing",
434 "" };
436 const char* const tbl_Win[] = {
437 "Activate, raise and pass click",
438 "Activate and pass click",
439 "Activate",
440 "Activate and raise",
441 "" };
443 const char* const tbl_AllKey[] = {
444 "Meta",
445 "Alt",
446 "" };
448 const char* const tbl_All[] = {
449 "Move",
450 "Activate, raise and move",
451 "Toggle raise and lower",
452 "Resize",
453 "Raise",
454 "Lower",
455 "Minimize",
456 "Nothing",
457 "" };
459 const char* tbl_TiWAc[] = {
460 "Raise/Lower",
461 "Shade/Unshade",
462 "Maximize/Restore",
463 "Above/Below",
464 "Previous/Next Desktop",
465 "Change Opacity",
466 "Nothing",
467 "" };
469 const char* tbl_AllW[] = {
470 "Raise/Lower",
471 "Shade/Unshade",
472 "Maximize/Restore",
473 "Above/Below",
474 "Previous/Next Desktop",
475 "Change Opacity",
476 "Nothing",
477 "" };
479 static const char* tbl_num_lookup( const char* const arr[], int pos )
481 for( int i = 0;
482 arr[ i ][ 0 ] != '\0' && pos >= 0;
483 ++i )
485 if( pos == 0 )
486 return arr[ i ];
487 --pos;
489 abort(); // should never happen this way
492 static int tbl_txt_lookup( const char* const arr[], const char* txt )
494 int pos = 0;
495 for( int i = 0;
496 arr[ i ][ 0 ] != '\0';
497 ++i )
499 if( qstricmp( txt, arr[ i ] ) == 0 )
500 return pos;
501 ++pos;
503 return 0;
506 void KTitleBarActionsConfig::setComboText( QComboBox* combo, const char*txt )
508 if( combo == coTiDbl )
509 combo->setCurrentIndex( tbl_txt_lookup( tbl_TiDbl, txt ));
510 else if( combo == coTiAct1 || combo == coTiAct2 || combo == coTiAct3 )
511 combo->setCurrentIndex( tbl_txt_lookup( tbl_TiAc, txt ));
512 else if( combo == coTiInAct1 || combo == coTiInAct2 || combo == coTiInAct3 )
513 combo->setCurrentIndex( tbl_txt_lookup( tbl_TiInAc, txt ));
514 else if( combo == coTiAct4 )
515 combo->setCurrentIndex( tbl_txt_lookup( tbl_TiWAc, txt ));
516 else if( combo == coMax[0] || combo == coMax[1] || combo == coMax[2] )
518 combo->setCurrentIndex( tbl_txt_lookup( tbl_Max, txt ));
519 static_cast<ToolTipComboBox *>(combo)->changed();
521 else
522 abort();
525 const char* KTitleBarActionsConfig::functionTiDbl( int i )
527 return tbl_num_lookup( tbl_TiDbl, i );
530 const char* KTitleBarActionsConfig::functionTiAc( int i )
532 return tbl_num_lookup( tbl_TiAc, i );
535 const char* KTitleBarActionsConfig::functionTiInAc( int i )
537 return tbl_num_lookup( tbl_TiInAc, i );
540 const char* KTitleBarActionsConfig::functionTiWAc(int i)
542 return tbl_num_lookup( tbl_TiWAc, i );
545 const char* KTitleBarActionsConfig::functionMax( int i )
547 return tbl_num_lookup( tbl_Max, i );
550 void KTitleBarActionsConfig::load()
552 KConfigGroup windowsConfig(config, "Windows");
553 setComboText(coTiDbl, windowsConfig.readEntry("TitlebarDoubleClickCommand","Shade").toAscii());
554 for (int t = 0; t < 3; ++t)
555 setComboText(coMax[t],windowsConfig.readEntry(cnf_Max[t], tbl_Max[t]).toAscii());
557 KConfigGroup cg(config, "MouseBindings");
558 setComboText(coTiAct1,cg.readEntry("CommandActiveTitlebar1","Raise").toAscii());
559 setComboText(coTiAct2,cg.readEntry("CommandActiveTitlebar2","Lower").toAscii());
560 setComboText(coTiAct3,cg.readEntry("CommandActiveTitlebar3","Operations menu").toAscii());
561 setComboText(coTiAct4,cg.readEntry("CommandTitlebarWheel","Nothing").toAscii());
562 setComboText(coTiInAct1,cg.readEntry("CommandInactiveTitlebar1","Activate and raise").toAscii());
563 setComboText(coTiInAct2,cg.readEntry("CommandInactiveTitlebar2","Activate and lower").toAscii());
564 setComboText(coTiInAct3,cg.readEntry("CommandInactiveTitlebar3","Operations menu").toAscii());
567 void KTitleBarActionsConfig::save()
569 KConfigGroup windowsConfig(config, "Windows");
570 windowsConfig.writeEntry("TitlebarDoubleClickCommand", functionTiDbl( coTiDbl->currentIndex() ) );
571 for (int t = 0; t < 3; ++t)
572 windowsConfig.writeEntry(cnf_Max[t], functionMax(coMax[t]->currentIndex()));
574 KConfigGroup cg(config, "MouseBindings");
575 cg.writeEntry("CommandActiveTitlebar1", functionTiAc(coTiAct1->currentIndex()));
576 cg.writeEntry("CommandActiveTitlebar2", functionTiAc(coTiAct2->currentIndex()));
577 cg.writeEntry("CommandActiveTitlebar3", functionTiAc(coTiAct3->currentIndex()));
578 cg.writeEntry("CommandInactiveTitlebar1", functionTiInAc(coTiInAct1->currentIndex()));
579 cg.writeEntry("CommandTitlebarWheel", functionTiWAc(coTiAct4->currentIndex()));
580 cg.writeEntry("CommandInactiveTitlebar2", functionTiInAc(coTiInAct2->currentIndex()));
581 cg.writeEntry("CommandInactiveTitlebar3", functionTiInAc(coTiInAct3->currentIndex()));
583 if (standAlone)
585 config->sync();
586 // Send signal to all kwin instances
587 QDBusMessage message =
588 QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig");
589 QDBusConnection::sessionBus().send(message);
594 void KTitleBarActionsConfig::defaults()
596 setComboText(coTiDbl, "Shade");
597 setComboText(coTiAct1,"Raise");
598 setComboText(coTiAct2,"Lower");
599 setComboText(coTiAct3,"Operations menu");
600 setComboText(coTiAct4,"Nothing");
601 setComboText(coTiInAct1,"Activate and raise");
602 setComboText(coTiInAct2,"Activate and lower");
603 setComboText(coTiInAct3,"Operations menu");
604 for (int t = 0; t < 3; ++t)
605 setComboText(coMax[t], tbl_Max[t]);
609 KWindowActionsConfig::KWindowActionsConfig (bool _standAlone, KConfig *_config, const KComponentData &inst, QWidget * parent)
610 : KCModule(inst, parent), config(_config), standAlone(_standAlone)
612 QString strWin1, strWin2, strWin3, strAllKey, strAll1, strAll2, strAll3, strAllW;
613 QGridLayout *grid;
614 QGroupBox *box;
615 QLabel *label;
616 QString strMouseButton1, strMouseButton3;
617 QString txtButton1, txtButton3;
618 QStringList items;
619 bool leftHandedMouse = ( KGlobalSettings::mouseSettings().handed == KGlobalSettings::KMouseSettings::LeftHanded);
621 QVBoxLayout *layout = new QVBoxLayout(this);
622 layout->setMargin(0);
623 layout->setSpacing(KDialog::spacingHint());
625 /** Inactive inner window ******************/
627 box = new QGroupBox(i18n("Inactive Inner Window"), this);
628 layout->addWidget(box);
629 box->setObjectName(QString::fromLatin1("Inactive Inner Window"));
630 box->setWhatsThis( i18n("Here you can customize mouse click behavior when clicking on an inactive"
631 " inner window ('inner' means: not titlebar, not frame).") );
633 grid = new QGridLayout(box);
634 grid->setMargin(KDialog::marginHint());
635 grid->setSpacing(KDialog::spacingHint());
637 strMouseButton1 = i18n("Left button:");
638 txtButton1 = i18n("In this row you can customize left click behavior when clicking into"
639 " the titlebar or the frame.");
641 strMouseButton3 = i18n("Right button:");
642 txtButton3 = i18n("In this row you can customize right click behavior when clicking into"
643 " the titlebar or the frame." );
645 if ( leftHandedMouse )
647 qSwap(strMouseButton1, strMouseButton3);
648 qSwap(txtButton1, txtButton3);
651 strWin1 = i18n("In this row you can customize left click behavior when clicking into"
652 " an inactive inner window ('inner' means: not titlebar, not frame).");
654 strWin3 = i18n("In this row you can customize right click behavior when clicking into"
655 " an inactive inner window ('inner' means: not titlebar, not frame).");
657 // Be nice to lefties
658 if ( leftHandedMouse ) qSwap(strWin1, strWin3);
660 label = new QLabel(strMouseButton1, box);
661 grid->addWidget(label, 0, 0);
662 label->setWhatsThis( strWin1 );
664 label = new QLabel(i18n("Middle button:"), box);
665 grid->addWidget(label, 1, 0);
666 strWin2 = i18n("In this row you can customize middle click behavior when clicking into"
667 " an inactive inner window ('inner' means: not titlebar, not frame).");
668 label->setWhatsThis( strWin2 );
670 label = new QLabel(strMouseButton3, box);
671 grid->addWidget(label, 2, 0);
672 label->setWhatsThis( strWin3 );
674 items.clear();
675 items << i18n("Activate, Raise & Pass Click")
676 << i18n("Activate & Pass Click")
677 << i18n("Activate")
678 << i18n("Activate & Raise");
680 QComboBox* combo = new QComboBox(box);
681 grid->addWidget(combo, 0, 1);
682 combo->addItems(items);
683 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
684 coWin1 = combo;
685 combo->setWhatsThis( strWin1 );
687 combo = new QComboBox(box);
688 grid->addWidget(combo, 1, 1);
689 combo->addItems(items);
690 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
691 coWin2 = combo;
692 combo->setWhatsThis( strWin2 );
694 combo = new QComboBox(box);
695 grid->addWidget(combo, 2, 1);
696 combo->addItems(items);
697 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
698 coWin3 = combo;
699 combo->setWhatsThis( strWin3 );
702 /** Inner window, titlebar and frame **************/
704 box = new QGroupBox(i18n("Inner Window, Titlebar && Frame"), this);
705 layout->addWidget(box);
706 box->setObjectName(QString::fromLatin1("Inner Window, Titlebar and Frame"));
707 box->setWhatsThis( i18n("Here you can customize KDE's behavior when clicking somewhere into"
708 " a window while pressing a modifier key."));
710 grid = new QGridLayout(box);
711 grid->setMargin(KDialog::marginHint());
712 grid->setSpacing(KDialog::spacingHint());
714 // Labels
715 label = new QLabel(i18n("Modifier key:"), box);
716 grid->addWidget(label, 0, 0);
718 strAllKey = i18n("Here you select whether holding the Meta key or Alt key "
719 "will allow you to perform the following actions.");
720 label->setWhatsThis( strAllKey );
723 strMouseButton1 = i18n("Modifier key + left button:");
724 strAll1 = i18n("In this row you can customize left click behavior when clicking into"
725 " the titlebar or the frame.");
727 strMouseButton3 = i18n("Modifier key + right button:");
728 strAll3 = i18n("In this row you can customize right click behavior when clicking into"
729 " the titlebar or the frame." );
731 if ( leftHandedMouse )
733 qSwap(strMouseButton1, strMouseButton3);
734 qSwap(strAll1, strAll3);
737 label = new QLabel(strMouseButton1, box);
738 grid->addWidget(label, 1, 0);
739 label->setWhatsThis( strAll1);
741 label = new QLabel(i18n("Modifier key + middle button:"), box);
742 grid->addWidget(label, 2, 0);
743 strAll2 = i18n("Here you can customize KDE's behavior when middle clicking into a window"
744 " while pressing the modifier key.");
745 label->setWhatsThis( strAll2 );
747 label = new QLabel(strMouseButton3, box);
748 grid->addWidget(label, 3, 0);
749 label->setWhatsThis( strAll3);
751 label = new QLabel(i18n("Modifier key + mouse wheel:"), box);
752 grid->addWidget(label, 4, 0);
753 strAllW = i18n("Here you can customize KDE's behavior when scrolling with the mouse wheel"
754 " in a window while pressing the modifier key.");
755 label->setWhatsThis( strAllW);
757 // Combo's
758 combo = new QComboBox(box);
759 grid->addWidget(combo, 0, 1);
760 combo->addItem(i18n("Meta"));
761 combo->addItem(i18n("Alt"));
762 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
763 coAllKey = combo;
764 combo->setWhatsThis( strAllKey );
766 items.clear();
767 items << i18n("Move")
768 << i18n("Activate, Raise and Move")
769 << i18n("Toggle Raise & Lower")
770 << i18n("Resize")
771 << i18n("Raise")
772 << i18n("Lower")
773 << i18n("Minimize")
774 << i18n("Nothing");
776 combo = new QComboBox(box);
777 grid->addWidget(combo, 1, 1);
778 combo->addItems(items);
779 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
780 coAll1 = combo;
781 combo->setWhatsThis( strAll1 );
783 combo = new QComboBox(box);
784 grid->addWidget(combo, 2, 1);
785 combo->addItems(items);
786 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
787 coAll2 = combo;
788 combo->setWhatsThis( strAll2 );
790 combo = new QComboBox(box);
791 grid->addWidget(combo, 3, 1);
792 combo->addItems(items);
793 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
794 coAll3 = combo;
795 combo->setWhatsThis( strAll3 );
797 combo = new QComboBox(box);
798 grid->addWidget(combo, 4, 1);
799 combo->addItem(i18n("Raise/Lower"));
800 combo->addItem(i18n("Shade/Unshade"));
801 combo->addItem(i18n("Maximize/Restore"));
802 combo->addItem(i18n("Keep Above/Below"));
803 combo->addItem(i18n("Move to Previous/Next Desktop"));
804 combo->addItem(i18n("Change Opacity"));
805 combo->addItem(i18n("Nothing"));
806 connect(combo, SIGNAL(activated(int)), SLOT(changed()));
807 coAllW = combo;
808 combo->setWhatsThis( strAllW );
810 layout->addStretch();
812 load();
815 KWindowActionsConfig::~KWindowActionsConfig()
817 if (standAlone)
818 delete config;
821 void KWindowActionsConfig::setComboText( QComboBox* combo, const char*txt )
823 if( combo == coWin1 || combo == coWin2 || combo == coWin3 )
824 combo->setCurrentIndex( tbl_txt_lookup( tbl_Win, txt ));
825 else if( combo == coAllKey )
826 combo->setCurrentIndex( tbl_txt_lookup( tbl_AllKey, txt ));
827 else if( combo == coAll1 || combo == coAll2 || combo == coAll3 )
828 combo->setCurrentIndex( tbl_txt_lookup( tbl_All, txt ));
829 else if( combo == coAllW )
830 combo->setCurrentIndex( tbl_txt_lookup( tbl_AllW, txt ));
831 else
832 abort();
835 const char* KWindowActionsConfig::functionWin( int i )
837 return tbl_num_lookup( tbl_Win, i );
840 const char* KWindowActionsConfig::functionAllKey( int i )
842 return tbl_num_lookup( tbl_AllKey, i );
845 const char* KWindowActionsConfig::functionAll( int i )
847 return tbl_num_lookup( tbl_All, i );
850 const char* KWindowActionsConfig::functionAllW(int i)
852 return tbl_num_lookup( tbl_AllW, i );
855 void KWindowActionsConfig::load()
857 KConfigGroup cg(config, "MouseBindings");
858 setComboText(coWin1,cg.readEntry("CommandWindow1","Activate, raise and pass click").toAscii());
859 setComboText(coWin2,cg.readEntry("CommandWindow2","Activate and pass click").toAscii());
860 setComboText(coWin3,cg.readEntry("CommandWindow3","Activate and pass click").toAscii());
861 setComboText(coAllKey,cg.readEntry("CommandAllKey","Alt").toAscii());
862 setComboText(coAll1,cg.readEntry("CommandAll1","Move").toAscii());
863 setComboText(coAll2,cg.readEntry("CommandAll2","Toggle raise and lower").toAscii());
864 setComboText(coAll3,cg.readEntry("CommandAll3","Resize").toAscii());
865 setComboText(coAllW,cg.readEntry("CommandAllWheel","Nothing").toAscii());
868 void KWindowActionsConfig::save()
870 KConfigGroup cg(config, "MouseBindings");
871 cg.writeEntry("CommandWindow1", functionWin(coWin1->currentIndex()));
872 cg.writeEntry("CommandWindow2", functionWin(coWin2->currentIndex()));
873 cg.writeEntry("CommandWindow3", functionWin(coWin3->currentIndex()));
874 cg.writeEntry("CommandAllKey", functionAllKey(coAllKey->currentIndex()));
875 cg.writeEntry("CommandAll1", functionAll(coAll1->currentIndex()));
876 cg.writeEntry("CommandAll2", functionAll(coAll2->currentIndex()));
877 cg.writeEntry("CommandAll3", functionAll(coAll3->currentIndex()));
878 cg.writeEntry("CommandAllWheel", functionAllW(coAllW->currentIndex()));
880 if (standAlone)
882 config->sync();
883 // Send signal to all kwin instances
884 QDBusMessage message =
885 QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig");
886 QDBusConnection::sessionBus().send(message);
890 void KWindowActionsConfig::defaults()
892 setComboText(coWin1,"Activate, raise and pass click");
893 setComboText(coWin2,"Activate and pass click");
894 setComboText(coWin3,"Activate and pass click");
895 setComboText(coAllKey,"Alt");
896 setComboText (coAll1,"Move");
897 setComboText(coAll2,"Toggle raise and lower");
898 setComboText(coAll3,"Resize");
899 setComboText(coAllW,"Nothing");