kwin Library API Documentation

mouse.cpp

00001 /*
00002  *
00003  * Copyright (c) 1998 Matthias Ettrich <ettrich@kde.org>
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018  */
00019 
00020 #include <qlabel.h>
00021 #include <qcombobox.h>
00022 #include <qwhatsthis.h>
00023 #include <qlayout.h>
00024 #include <qvgroupbox.h>
00025 #include <qgrid.h>
00026 #include <qsizepolicy.h>
00027 
00028 #include <dcopclient.h>
00029 #include <klocale.h>
00030 #include <kapplication.h>
00031 #include <kconfig.h>
00032 #include <kdialog.h>
00033 #include <kglobalsettings.h>
00034 #include <kseparator.h>
00035 
00036 #include <X11/X.h>
00037 #include <X11/Xlib.h>
00038 #include <X11/Xutil.h>
00039 
00040 #include <stdlib.h>
00041 
00042 #include "mouse.h"
00043 #include "mouse.moc"
00044 
00045 
00046 KActionsConfig::KActionsConfig (bool _standAlone, KConfig *_config, QWidget * parent, const char *)
00047   : KCModule(parent, "kcmkwm"), config(_config), standAlone(_standAlone)
00048 {
00049   QString strWin1, strWin2, strWin3, strAllKey, strAll1, strAll2, strAll3;
00050   QVBoxLayout *layout = new QVBoxLayout(this, 0, KDialog::spacingHint());
00051   QGrid *grid;
00052   QGroupBox *box;
00053   QLabel *label;
00054   QString strMouseButton1, strMouseButton3;
00055   QString txtButton1, txtButton3;
00056   QStringList items;
00057   bool leftHandedMouse = ( KGlobalSettings::mouseSettings().handed == KGlobalSettings::KMouseSettings::LeftHanded);
00058 
00061   QHBoxLayout *hlayout = new QHBoxLayout(layout);
00062 
00063   label = new QLabel(i18n("&Titlebar double-click:"), this);
00064   hlayout->addWidget(label);
00065   QWhatsThis::add( label, i18n("Here you can customize mouse click behavior when double clicking on the"
00066     " titlebar of a window.") );
00067 
00068   QComboBox* combo = new QComboBox(this);
00069   combo->insertItem(i18n("Maximize"));
00070   combo->insertItem(i18n("Maximize (vertical only)"));
00071   combo->insertItem(i18n("Maximize (horizontal only)"));
00072   combo->insertItem(i18n("Minimize"));
00073   combo->insertItem(i18n("Shade"));
00074   combo->insertItem(i18n("Lower"));
00075   combo->insertItem(i18n("On All Desktops"));
00076   combo->insertItem(i18n("Nothing"));
00077   combo->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed));
00078   connect(combo, SIGNAL(activated(int)), SLOT(changed()));
00079   hlayout->addWidget(combo);
00080   coTiDbl = combo;
00081   QWhatsThis::add(combo, i18n("Behavior on <em>double</em> click into the titlebar."));
00082 
00083   label->setBuddy(combo);
00084 
00087   box = new QVGroupBox( i18n("Titlebar && Frame"), this, "Titlebar and Frame");
00088   box->layout()->setMargin(KDialog::marginHint());
00089   box->layout()->setSpacing(KDialog::spacingHint());
00090   layout->addWidget(box);
00091   QWhatsThis::add( box, i18n("Here you can customize mouse click behavior when clicking on the"
00092                              " titlebar or the frame of a window.") );
00093 
00094   grid = new QGrid(4, Qt::Vertical, box);
00095 
00096 
00097   new QLabel(grid); // dummy
00098 
00099   strMouseButton1 = i18n("Left button:");
00100   txtButton1 = i18n("In this row you can customize left click behavior when clicking into"
00101      " the titlebar or the frame.");
00102 
00103   strMouseButton3 = i18n("Right button:");
00104   txtButton3 = i18n("In this row you can customize right click behavior when clicking into"
00105      " the titlebar or the frame." );
00106 
00107   if ( leftHandedMouse )
00108   {
00109      qSwap(strMouseButton1, strMouseButton3);
00110      qSwap(txtButton1, txtButton3);
00111   }
00112 
00113   label = new QLabel(strMouseButton1, grid);
00114   QWhatsThis::add( label, txtButton1);
00115 
00116   label = new QLabel(i18n("Middle button:"), grid);
00117   QWhatsThis::add( label, i18n("In this row you can customize middle click behavior when clicking into"
00118     " the titlebar or the frame.") );
00119 
00120   label = new QLabel(strMouseButton3, grid);
00121   QWhatsThis::add( label, txtButton3);
00122 
00123 
00124   label = new QLabel(i18n("Active"), grid);
00125   label->setAlignment(AlignCenter);
00126   QWhatsThis::add( label, i18n("In this column you can customize mouse clicks into the titlebar"
00127                                " or the frame of an active window.") );
00128 
00129   // Titlebar and frame, active, mouse button 1
00130   combo = new QComboBox(grid);
00131   combo->insertItem(i18n("Raise"));
00132   combo->insertItem(i18n("Lower"));
00133   combo->insertItem(i18n("Operations Menu"));
00134   combo->insertItem(i18n("Toggle Raise & Lower"));
00135   combo->insertItem(i18n("Nothing"));
00136   connect(combo, SIGNAL(activated(int)), SLOT(changed()));
00137   coTiAct1 = combo;
00138 
00139   txtButton1 = i18n("Behavior on <em>left</em> click into the titlebar or frame of an "
00140      "<em>active</em> window.");
00141 
00142   txtButton3 = i18n("Behavior on <em>right</em> click into the titlebar or frame of an "
00143      "<em>active</em> window.");
00144 
00145   // Be nice to left handed users
00146   if ( leftHandedMouse ) qSwap(txtButton1, txtButton3);
00147 
00148   QWhatsThis::add(combo, txtButton1);
00149 
00150   // Titlebar and frame, active, mouse button 2
00151 
00152   items << i18n("Raise")
00153         << i18n("Lower")
00154         << i18n("Operations Menu")
00155         << i18n("Toggle Raise & Lower")
00156         << i18n("Nothing")
00157         << i18n("Shade");
00158 
00159   combo = new QComboBox(grid);
00160   combo->insertStringList(items);
00161   connect(combo, SIGNAL(activated(int)), SLOT(changed()));
00162   coTiAct2 = combo;
00163   QWhatsThis::add(combo, i18n("Behavior on <em>middle</em> click into the titlebar or frame of an <em>active</em> window."));
00164 
00165   // Titlebar and frame, active, mouse button 3
00166   combo = new QComboBox(grid);
00167   combo->insertStringList(items);
00168   connect(combo, SIGNAL(activated(int)), SLOT(changed()));
00169   coTiAct3 =  combo;
00170   QWhatsThis::add(combo, txtButton3 );
00171 
00172   txtButton1 = i18n("Behavior on <em>left</em> click into the titlebar or frame of an "
00173      "<em>inactive</em> window.");
00174 
00175   txtButton3 = i18n("Behavior on <em>right</em> click into the titlebar or frame of an "
00176      "<em>inactive</em> window.");
00177 
00178   // Be nice to left handed users
00179   if ( leftHandedMouse ) qSwap(txtButton1, txtButton3);
00180 
00181   label = new QLabel(i18n("Inactive"), grid);
00182   label->setAlignment(AlignCenter);
00183   QWhatsThis::add( label, i18n("In this column you can customize mouse clicks into the titlebar"
00184                                " or the frame of an inactive window.") );
00185 
00186   items.clear();
00187   items  << i18n("Activate & Raise")
00188          << i18n("Activate & Lower")
00189          << i18n("Activate")
00190          << i18n("Shade")
00191          << i18n("Operations Menu")
00192          << i18n("Raise")
00193          << i18n("Lower")
00194          << i18n("Nothing");
00195 
00196   combo = new QComboBox(grid);
00197   combo->insertStringList(items);
00198   connect(combo, SIGNAL(activated(int)), SLOT(changed()));
00199   coTiInAct1 = combo;
00200   QWhatsThis::add(combo, txtButton1);
00201 
00202   combo = new QComboBox(grid);
00203   combo->insertStringList(items);
00204   connect(combo, SIGNAL(activated(int)), SLOT(changed()));
00205   coTiInAct2 = combo;
00206   QWhatsThis::add(combo, i18n("Behavior on <em>middle</em> click into the titlebar or frame of an <em>inactive</em> window."));
00207 
00208   combo = new QComboBox(grid);
00209   combo->insertStringList(items);
00210   connect(combo, SIGNAL(activated(int)), SLOT(changed()));
00211   coTiInAct3 = combo;
00212   QWhatsThis::add(combo, txtButton3);
00213 
00216   box = new QVGroupBox(i18n("Inactive Inner Window"), this, "Inactive Inner Window");
00217   box->layout()->setMargin(KDialog::marginHint());
00218   box->layout()->setSpacing(KDialog::spacingHint());
00219   layout->addWidget(box);
00220   QWhatsThis::add( box, i18n("Here you can customize mouse click behavior when clicking on an inactive"
00221                              " inner window ('inner' means: not titlebar, not frame).") );
00222 
00223   grid = new QGrid(3, Qt::Vertical, box);
00224 
00225   strMouseButton1 = i18n("Left button:");
00226   txtButton1 = i18n("In this row you can customize left click behavior when clicking into"
00227      " the titlebar or the frame.");
00228 
00229   strMouseButton3 = i18n("Right button:");
00230   txtButton3 = i18n("In this row you can customize right click behavior when clicking into"
00231      " the titlebar or the frame." );
00232 
00233   if ( leftHandedMouse )
00234   {
00235      qSwap(strMouseButton1, strMouseButton3);
00236      qSwap(txtButton1, txtButton3);
00237   }
00238 
00239   strWin1 = i18n("In this row you can customize left click behavior when clicking into"
00240      " an inactive inner window ('inner' means: not titlebar, not frame).");
00241 
00242   strWin3 = i18n("In this row you can customize right click behavior when clicking into"
00243      " an inactive inner window ('inner' means: not titlebar, not frame).");
00244 
00245   // Be nice to lefties
00246   if ( leftHandedMouse ) qSwap(strWin1, strWin3);
00247 
00248   label = new QLabel(strMouseButton1, grid);
00249   QWhatsThis::add( label, strWin1 );
00250 
00251   label = new QLabel(i18n("Middle button:"), grid);
00252   strWin2 = i18n("In this row you can customize middle click behavior when clicking into"
00253      " an inactive inner window ('inner' means: not titlebar, not frame).");
00254   QWhatsThis::add( label, strWin2 );
00255 
00256   label = new QLabel(strMouseButton3, grid);
00257   QWhatsThis::add( label, strWin3 );
00258 
00259   items.clear();
00260   items   << i18n("Activate, Raise & Pass Click")
00261           << i18n("Activate & Pass Click")
00262           << i18n("Activate")
00263           << i18n("Activate & Raise");
00264 
00265   combo = new QComboBox(grid);
00266   combo->insertStringList(items);
00267   connect(combo, SIGNAL(activated(int)), SLOT(changed()));
00268   coWin1 = combo;
00269   QWhatsThis::add( combo, strWin1 );
00270 
00271   combo = new QComboBox(grid);
00272   combo->insertStringList(items);
00273   connect(combo, SIGNAL(activated(int)), SLOT(changed()));
00274   coWin2 = combo;
00275   QWhatsThis::add( combo, strWin2 );
00276 
00277   combo = new QComboBox(grid);
00278   combo->insertStringList(items);
00279   connect(combo, SIGNAL(activated(int)), SLOT(changed()));
00280   coWin3 = combo;
00281   QWhatsThis::add( combo, strWin3 );
00282 
00283 
00286   box = new QVGroupBox(i18n("Inner Window, Titlebar && Frame"), this, "Inner Window, Titlebar and Frame");
00287   box->layout()->setMargin(KDialog::marginHint());
00288   box->layout()->setSpacing(KDialog::spacingHint());
00289   layout->addWidget(box);
00290   QWhatsThis::add( box, i18n("Here you can customize KDE's behavior when clicking somewhere into"
00291                              " a window while pressing a modifier key."));
00292 
00293   grid = new QGrid(4, Qt::Vertical, box);
00294 
00295   // Labels
00296   label = new QLabel(i18n("Modifier key:"), grid);
00297 
00298   strAllKey = i18n("Here you select whether holding the Meta key or Alt key "
00299     "will allow you to perform the following actions.");
00300   QWhatsThis::add( label, strAllKey );
00301 
00302 
00303   strMouseButton1 = i18n("Modifier key + left button:");
00304   strAll1 = i18n("In this row you can customize left click behavior when clicking into"
00305                  " the titlebar or the frame.");
00306 
00307   strMouseButton3 = i18n("Modifier key + right button:");
00308   strAll3 = i18n("In this row you can customize right click behavior when clicking into"
00309                  " the titlebar or the frame." );
00310 
00311   if ( leftHandedMouse )
00312   {
00313      qSwap(strMouseButton1, strMouseButton3);
00314      qSwap(strAll1, strAll3);
00315   }
00316 
00317   label = new QLabel(strMouseButton1, grid);
00318   QWhatsThis::add( label, strAll1);
00319 
00320   label = new QLabel(i18n("Modifier key + middle button:"), grid);
00321   strAll2 = i18n("Here you can customize KDE's behavior when middle clicking into a window"
00322                  " while pressing the modifier key.");
00323   QWhatsThis::add( label, strAll2 );
00324 
00325   label = new QLabel(strMouseButton3, grid);
00326   QWhatsThis::add( label, strAll3);
00327 
00328   // Combo's
00329   combo = new QComboBox(grid);
00330   combo->insertItem(i18n("Meta"));
00331   combo->insertItem(i18n("Alt"));
00332   connect(combo, SIGNAL(activated(int)), SLOT(changed()));
00333   coAllKey = combo;
00334   QWhatsThis::add( combo, strAllKey );
00335 
00336   items.clear();
00337   items << i18n("Move")
00338         << i18n("Activate, Raise and Move")
00339         << i18n("Toggle Raise & Lower")
00340         << i18n("Resize")
00341         << i18n("Raise")
00342         << i18n("Lower")
00343         << i18n("Minimize")
00344         << i18n("Nothing");
00345 
00346   combo = new QComboBox(grid);
00347   combo->insertStringList(items);
00348   connect(combo, SIGNAL(activated(int)), SLOT(changed()));
00349   coAll1 = combo;
00350   QWhatsThis::add( combo, strAll1 );
00351 
00352   combo = new QComboBox(grid);
00353   combo->insertStringList(items);
00354   connect(combo, SIGNAL(activated(int)), SLOT(changed()));
00355   coAll2 = combo;
00356   QWhatsThis::add( combo, strAll2 );
00357 
00358   combo = new QComboBox(grid);
00359   combo->insertStringList(items);
00360   connect(combo, SIGNAL(activated(int)), SLOT(changed()));
00361   coAll3 =  combo;
00362   QWhatsThis::add( combo, strAll3 );
00363 
00364   layout->addStretch();
00365 
00366   load();
00367 }
00368 
00369 KActionsConfig::~KActionsConfig()
00370 {
00371   if (standAlone)
00372     delete config;
00373 }
00374 
00375 // do NOT change the texts below, they are written to config file
00376 // and are not shown in the GUI
00377 // they have to match the order of items in GUI elements though
00378 const char* tbl_TiDbl[] = {
00379     "Maximize",
00380     "Maximize (vertical only)",
00381     "Maximize (horizontal only)",
00382     "Minimize",
00383     "Shade",
00384     "Lower",
00385     "OnAllDesktops",
00386     "Nothing",
00387     "" };
00388 
00389 const char* tbl_TiAc[] = {
00390     "Raise",
00391     "Lower",
00392     "Operations menu",
00393     "Toggle raise and lower",
00394     "Nothing",
00395     "Shade",
00396     "" };
00397 
00398 const char* tbl_TiInAc[] = {
00399     "Activate and raise",
00400     "Activate and lower",
00401     "Activate",
00402     "Shade",
00403     "Operations menu",
00404     "Raise",
00405     "Lower",
00406     "Nothing",
00407     "" };
00408 
00409 const char* tbl_Win[] = {
00410     "Activate, raise and pass click",
00411     "Activate and pass click",
00412     "Activate",
00413     "Activate and raise",
00414     "" };
00415 
00416 const char* tbl_AllKey[] = {
00417     "Meta",
00418     "Alt",
00419     "" };
00420 
00421 const char* tbl_All[] = {
00422     "Move",
00423     "Activate, raise and move",
00424     "Toggle raise and lower",
00425     "Resize",
00426     "Raise",
00427     "Lower",
00428     "Minimize",
00429     "Nothing",
00430     "" };
00431 
00432 static const char* tbl_num_lookup( const char* arr[], int pos )
00433 {
00434     for( int i = 0;
00435          arr[ i ][ 0 ] != '\0' && pos >= 0;
00436          ++i )
00437     {
00438         if( pos == 0 )
00439             return arr[ i ];
00440         --pos;
00441     }
00442     abort(); // should never happen this way
00443 }
00444 
00445 static int tbl_txt_lookup( const char* arr[], const char* txt )
00446 {
00447     int pos = 0;
00448     for( int i = 0;
00449          arr[ i ][ 0 ] != '\0';
00450          ++i )
00451     {
00452         if( qstricmp( txt, arr[ i ] ) == 0 )
00453             return pos;
00454         ++pos;
00455     }
00456     return 0;
00457 }
00458 
00459 void KActionsConfig::setComboText( QComboBox* combo, const char*txt )
00460 {
00461     if( combo == coTiDbl )
00462         combo->setCurrentItem( tbl_txt_lookup( tbl_TiDbl, txt ));
00463     else if( combo == coTiAct1 || combo == coTiAct2 || combo == coTiAct3 )
00464         combo->setCurrentItem( tbl_txt_lookup( tbl_TiAc, txt ));
00465     else if( combo == coTiInAct1 || combo == coTiInAct2 || combo == coTiInAct3 )
00466         combo->setCurrentItem( tbl_txt_lookup( tbl_TiInAc, txt ));
00467     else if( combo == coWin1 || combo == coWin2 || combo == coWin3 )
00468         combo->setCurrentItem( tbl_txt_lookup( tbl_Win, txt ));
00469     else if( combo == coAllKey )
00470         combo->setCurrentItem( tbl_txt_lookup( tbl_AllKey, txt ));
00471     else if( combo == coAll1 || combo == coAll2 || combo == coAll3 )
00472         combo->setCurrentItem( tbl_txt_lookup( tbl_All, txt ));
00473     else
00474         abort();
00475 }
00476 
00477 const char* KActionsConfig::functionTiDbl( int i )
00478 {
00479     return tbl_num_lookup( tbl_TiDbl, i );
00480 }
00481 
00482 const char* KActionsConfig::functionTiAc( int i )
00483 {
00484     return tbl_num_lookup( tbl_TiAc, i );
00485 }
00486 
00487 const char* KActionsConfig::functionTiInAc( int i )
00488 {
00489     return tbl_num_lookup( tbl_TiInAc, i );
00490 }
00491 
00492 const char* KActionsConfig::functionWin( int i )
00493 {
00494     return tbl_num_lookup( tbl_Win, i );
00495 }
00496 
00497 const char* KActionsConfig::functionAllKey( int i )
00498 {
00499     return tbl_num_lookup( tbl_AllKey, i );
00500 }
00501 
00502 const char* KActionsConfig::functionAll( int i )
00503 {
00504     return tbl_num_lookup( tbl_All, i );
00505 }
00506 
00507 void KActionsConfig::load()
00508 {
00509   config->setGroup("Windows");
00510   setComboText(coTiDbl, config->readEntry("TitlebarDoubleClickCommand","Shade").ascii());
00511 
00512   config->setGroup( "MouseBindings");
00513   setComboText(coTiAct1,config->readEntry("CommandActiveTitlebar1","Raise").ascii());
00514   setComboText(coTiAct2,config->readEntry("CommandActiveTitlebar2","Lower").ascii());
00515   setComboText(coTiAct3,config->readEntry("CommandActiveTitlebar3","Operations menu").ascii());
00516   setComboText(coTiInAct1,config->readEntry("CommandInactiveTitlebar1","Activate and raise").ascii());
00517   setComboText(coTiInAct2,config->readEntry("CommandInactiveTitlebar2","Activate and lower").ascii());
00518   setComboText(coTiInAct3,config->readEntry("CommandInactiveTitlebar3","Operations menu").ascii());
00519   setComboText(coWin1,config->readEntry("CommandWindow1","Activate, raise and pass click").ascii());
00520   setComboText(coWin2,config->readEntry("CommandWindow2","Activate and pass click").ascii());
00521   setComboText(coWin3,config->readEntry("CommandWindow3","Activate and pass click").ascii());
00522   setComboText(coAllKey,config->readEntry("CommandAllKey","Alt").ascii());
00523   setComboText(coAll1,config->readEntry("CommandAll1","Move").ascii());
00524   setComboText(coAll2,config->readEntry("CommandAll2","Toggle raise and lower").ascii());
00525   setComboText(coAll3,config->readEntry("CommandAll3","Resize").ascii());
00526 }
00527 
00528 void KActionsConfig::save()
00529 {
00530   config->setGroup("Windows");
00531   config->writeEntry("TitlebarDoubleClickCommand", functionTiDbl( coTiDbl->currentItem() ) );
00532 
00533   config->setGroup("MouseBindings");
00534   config->writeEntry("CommandActiveTitlebar1", functionTiAc(coTiAct1->currentItem()));
00535   config->writeEntry("CommandActiveTitlebar2", functionTiAc(coTiAct2->currentItem()));
00536   config->writeEntry("CommandActiveTitlebar3", functionTiAc(coTiAct3->currentItem()));
00537   config->writeEntry("CommandInactiveTitlebar1", functionTiInAc(coTiInAct1->currentItem()));
00538   config->writeEntry("CommandInactiveTitlebar2", functionTiInAc(coTiInAct2->currentItem()));
00539   config->writeEntry("CommandInactiveTitlebar3", functionTiInAc(coTiInAct3->currentItem()));
00540   config->writeEntry("CommandWindow1", functionWin(coWin1->currentItem()));
00541   config->writeEntry("CommandWindow2", functionWin(coWin2->currentItem()));
00542   config->writeEntry("CommandWindow3", functionWin(coWin3->currentItem()));
00543   config->writeEntry("CommandAllKey", functionAllKey(coAllKey->currentItem()));
00544   config->writeEntry("CommandAll1", functionAll(coAll1->currentItem()));
00545   config->writeEntry("CommandAll2", functionAll(coAll2->currentItem()));
00546   config->writeEntry("CommandAll3", functionAll(coAll3->currentItem()));
00547   
00548   if (standAlone)
00549   {
00550     config->sync();
00551     if ( !kapp->dcopClient()->isAttached() )
00552       kapp->dcopClient()->attach();
00553     kapp->dcopClient()->send("kwin*", "", "reconfigure()", "");
00554   }
00555 }
00556 
00557 void KActionsConfig::defaults()
00558 {
00559   setComboText(coTiDbl, "Shade");
00560   setComboText(coTiAct1,"Raise");
00561   setComboText(coTiAct2,"Lower");
00562   setComboText(coTiAct3,"Operations menu");
00563   setComboText(coTiInAct1,"Activate and raise");
00564   setComboText(coTiInAct2,"Activate and lower");
00565   setComboText(coTiInAct3,"Operations menu");
00566   setComboText(coWin1,"Activate, raise and pass click");
00567   setComboText(coWin2,"Activate and pass click");
00568   setComboText(coWin3,"Activate and pass click");
00569   setComboText(coAllKey,"Alt");
00570   setComboText (coAll1,"Move");
00571   setComboText(coAll2,"Toggle raise and lower");
00572   setComboText(coAll3,"Resize");
00573 }
KDE Logo
This file is part of the documentation for kwin Library Version 3.3.90.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Apr 4 11:21:59 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003