kwin Library API Documentation

useractions.cpp

00001 /*****************************************************************
00002  KWin - the KDE window manager
00003  This file is part of the KDE project.
00004 
00005 Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
00006 Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
00007 
00008 You can Freely distribute this program under the GNU General Public
00009 License. See the file "COPYING" for the exact licensing terms.
00010 ******************************************************************/
00011 
00012 /*
00013 
00014  This file contains things relevant to direct user actions, such as
00015  responses to global keyboard shortcuts, or selecting actions
00016  from the window operations menu.
00017 
00018 */
00019 
00020 #include "client.h"
00021 #include "workspace.h"
00022 
00023 #include <fixx11h.h>
00024 #include <qhbox.h>
00025 #include <qpushbutton.h>
00026 #include <qslider.h>
00027 #include <qtooltip.h>
00028 #include <qpopupmenu.h>
00029 #include <kglobalsettings.h>
00030 #include <kiconloader.h>
00031 #include <klocale.h>
00032 #include <kconfig.h>
00033 #include <kglobalaccel.h>
00034 #include <kapplication.h>
00035 #include <qregexp.h>
00036 
00037 #include "popupinfo.h"
00038 #include "killwindow.h"
00039 #include "tabbox.h"
00040 
00041 namespace KWinInternal
00042 {
00043 
00044 //****************************************
00045 // Workspace
00046 //****************************************
00047 
00048 QPopupMenu* Workspace::clientPopup()
00049     {
00050     if ( !popup )
00051         {
00052         popup = new QPopupMenu;
00053         popup->setCheckable( TRUE );
00054         popup->setFont(KGlobalSettings::menuFont());
00055         connect( popup, SIGNAL( aboutToShow() ), this, SLOT( clientPopupAboutToShow() ) );
00056         connect( popup, SIGNAL( activated(int) ), this, SLOT( clientPopupActivated(int) ) );
00057       
00058         advanced_popup = new QPopupMenu( popup );
00059         advanced_popup->setCheckable( TRUE );
00060         advanced_popup->setFont(KGlobalSettings::menuFont());
00061         connect( advanced_popup, SIGNAL( activated(int) ), this, SLOT( clientPopupActivated(int) ) );
00062         advanced_popup->insertItem( SmallIconSet( "up" ),
00063             i18n("Keep &Above Others")+'\t'+keys->shortcut("Window Above Other Windows").seq(0).toString(), Options::KeepAboveOp );
00064         advanced_popup->insertItem( SmallIconSet( "down" ),
00065             i18n("Keep &Below Others")+'\t'+keys->shortcut("Window Below Other Windows").seq(0).toString(), Options::KeepBelowOp );
00066         advanced_popup->insertItem( SmallIconSet( "window_fullscreen" ),
00067             i18n("&Fullscreen")+'\t'+keys->shortcut("Window Fullscreen").seq(0).toString(), Options::FullScreenOp );
00068         advanced_popup->insertItem( i18n("&No Border")+'\t'+keys->shortcut("Window No Border").seq(0).toString(), Options::NoBorderOp );
00069         advanced_popup->insertItem( SmallIconSet("key_bindings"),
00070             i18n("Window &Shortcut...")+'\t'+keys->shortcut("Setup Window Shortcut").seq(0).toString(), Options::SetupWindowShortcutOp );
00071         advanced_popup->insertItem( SmallIconSet( "wizard" ), i18n("&Special Window Settings..."), Options::WindowRulesOp );
00072 
00073         popup->insertItem(i18n("Ad&vanced"), advanced_popup );
00074         desk_popup_index = popup->count();
00075         
00076         if (options->useTranslucency){
00077             QPopupMenu *trans_popup = new QPopupMenu( popup );
00078             QVBox *transBox = new QVBox(trans_popup);
00079             transButton = new QPushButton(transBox, "transButton");
00080             QToolTip::add(transButton, i18n("Reset opacity to default value"));
00081             transSlider = new QSlider(0, 100, 1, 100, Qt::Vertical, transBox, "transSlider");
00082             QToolTip::add(transSlider, i18n("Slide this to set the window's opacity"));
00083             connect(transButton, SIGNAL(clicked()), SLOT(resetClientOpacity()));
00084             connect(transButton, SIGNAL(clicked()), trans_popup, SLOT(hide()));
00085             connect(transSlider, SIGNAL(valueChanged(int)), SLOT(setTransButtonText(int)));
00086             connect(transSlider, SIGNAL(valueChanged(int)), this, SLOT(setPopupClientOpacity(int)));
00087 //             connect(transSlider, SIGNAL(sliderReleased()), trans_popup, SLOT(hide()));
00088             trans_popup->insertItem(transBox);
00089             popup->insertItem(i18n("&Opacity"), trans_popup );
00090         }
00091         
00092         popup->insertItem( SmallIconSet( "move" ), i18n("&Move")+'\t'+keys->shortcut("Window Move").seq(0).toString(), Options::MoveOp );
00093         popup->insertItem( i18n("Re&size")+'\t'+keys->shortcut("Window Resize").seq(0).toString(), Options::ResizeOp );
00094         popup->insertItem( i18n("Mi&nimize")+'\t'+keys->shortcut("Window Minimize").seq(0).toString(), Options::MinimizeOp );
00095         popup->insertItem( i18n("Ma&ximize")+'\t'+keys->shortcut("Window Maximize").seq(0).toString(), Options::MaximizeOp );
00096         popup->insertItem( i18n("Sh&ade")+'\t'+keys->shortcut("Window Shade").seq(0).toString(), Options::ShadeOp );
00097 
00098         popup->insertSeparator();
00099 
00100         if (!KGlobal::config()->isImmutable() && 
00101             !kapp->authorizeControlModules(Workspace::configModules(true)).isEmpty())
00102             {
00103             popup->insertItem(SmallIconSet( "configure" ), i18n("Configur&e Window Behavior..."), this, SLOT( configureWM() ));
00104             popup->insertSeparator();
00105             }
00106 
00107         popup->insertItem( SmallIconSet( "fileclose" ), i18n("&Close")+'\t'+keys->shortcut("Window Close").seq(0).toString(), Options::CloseOp );
00108         }
00109     return popup;
00110     }
00111     
00112 //sets the transparency of the client to given value(given by slider)
00113 void Workspace::setPopupClientOpacity(int value)
00114     {
00115     active_popup_client->setCustomOpacityFlag(true);
00116     value = 100 - value;
00117     value<100?active_popup_client->setOpacity(true, (uint)((value/100.0)*0xffffffff)):active_popup_client->setOpacity(false,0xffffffff);
00118     }
00119 
00120 void Workspace::setTransButtonText(int value)
00121     {
00122     value = 100 - value;
00123     if(value < 0)
00124         transButton->setText("000 %");
00125     else if (value >= 100 )
00126         transButton->setText("100 %");
00127     else if(value < 10)
00128         transButton->setText("00"+QString::number(value)+" %");
00129     else if(value < 100)
00130         transButton->setText("0"+QString::number(value)+" %");
00131     }
00132 
00133 void Workspace::resetClientOpacity()
00134     {
00135     active_popup_client->setCustomOpacityFlag(false);
00136     active_popup_client->updateOpacity();
00137     transSlider->setValue(100-active_popup_client->opacityPercentage());
00138     setTransButtonText(100-active_popup_client->opacityPercentage());
00139     }
00140 
00141 
00147 void Workspace::clientPopupAboutToShow()
00148     {
00149     if ( !active_popup_client || !popup )
00150         return;
00151 
00152     if ( numberOfDesktops() == 1 )
00153         {
00154         delete desk_popup;
00155         desk_popup = 0;
00156         }
00157     else
00158         {
00159         initDesktopPopup();
00160         }
00161 
00162     popup->setItemEnabled( Options::ResizeOp, active_popup_client->isResizable() );
00163     popup->setItemEnabled( Options::MoveOp, active_popup_client->isMovable() );
00164     popup->setItemEnabled( Options::MaximizeOp, active_popup_client->isMaximizable() );
00165     popup->setItemChecked( Options::MaximizeOp, active_popup_client->maximizeMode() == Client::MaximizeFull );
00166     // This should be checked also when hover unshaded
00167     popup->setItemChecked( Options::ShadeOp, active_popup_client->shadeMode() != ShadeNone );
00168     popup->setItemEnabled( Options::ShadeOp, active_popup_client->isShadeable());
00169     advanced_popup->setItemChecked( Options::KeepAboveOp, active_popup_client->keepAbove() );
00170     advanced_popup->setItemChecked( Options::KeepBelowOp, active_popup_client->keepBelow() );
00171     advanced_popup->setItemChecked( Options::FullScreenOp, active_popup_client->isFullScreen() );
00172     advanced_popup->setItemEnabled( Options::FullScreenOp, active_popup_client->userCanSetFullScreen() );
00173     advanced_popup->setItemChecked( Options::NoBorderOp, active_popup_client->noBorder() );
00174     advanced_popup->setItemEnabled( Options::NoBorderOp, active_popup_client->userCanSetNoBorder() );
00175     popup->setItemEnabled( Options::MinimizeOp, active_popup_client->isMinimizable() );
00176     popup->setItemEnabled( Options::CloseOp, active_popup_client->isCloseable() );
00177     if (options->useTranslucency)
00178         {
00179         transSlider->setValue(100-active_popup_client->opacityPercentage());
00180         setTransButtonText(100-active_popup_client->opacityPercentage());
00181         }
00182     }
00183 
00184 
00185 void Workspace::initDesktopPopup()
00186     {
00187     if (desk_popup)
00188         return;
00189 
00190     desk_popup = new QPopupMenu( popup );
00191     desk_popup->setCheckable( TRUE );
00192     desk_popup->setFont(KGlobalSettings::menuFont());
00193     connect( desk_popup, SIGNAL( activated(int) ),
00194              this, SLOT( slotSendToDesktop(int) ) );
00195     connect( desk_popup, SIGNAL( aboutToShow() ),
00196              this, SLOT( desktopPopupAboutToShow() ) );
00197 
00198     popup->insertItem(i18n("To &Desktop"), desk_popup, -1, desk_popup_index );
00199     }
00200 
00205 void Workspace::desktopPopupAboutToShow()
00206     {
00207     if ( !desk_popup )
00208         return;
00209 
00210     desk_popup->clear();
00211     desk_popup->insertItem( i18n("&All Desktops"), 0 );
00212     if ( active_popup_client && active_popup_client->isOnAllDesktops() )
00213         desk_popup->setItemChecked( 0, TRUE );
00214     desk_popup->insertSeparator( -1 );
00215     int id;
00216     const int BASE = 10;
00217     for ( int i = 1; i <= numberOfDesktops(); i++ ) 
00218         {
00219         QString basic_name("%1  %2");
00220         if (i<BASE)
00221             {
00222             basic_name.prepend('&');
00223             }
00224         id = desk_popup->insertItem(
00225                 basic_name
00226                     .arg(i)
00227                     .arg( desktopName(i).replace( '&', "&&" )),
00228                 i );
00229         if ( active_popup_client &&
00230              !active_popup_client->isOnAllDesktops() && active_popup_client->desktop()  == i )
00231             desk_popup->setItemChecked( id, TRUE );
00232         }
00233     }
00234 
00235 void Workspace::closeActivePopup()
00236     {
00237     if( active_popup )
00238         {
00239         active_popup->close();
00240         active_popup = NULL;
00241         active_popup_client = NULL;
00242         }
00243     }
00244 
00248 void Workspace::initShortcuts()
00249     {
00250     keys = new KGlobalAccel( this );
00251 #include "kwinbindings.cpp"
00252     readShortcuts();
00253     }
00254 
00255 void Workspace::readShortcuts()
00256     {
00257     keys->readSettings();
00258 
00259     cutWalkThroughDesktops = keys->shortcut("Walk Through Desktops");
00260     cutWalkThroughDesktopsReverse = keys->shortcut("Walk Through Desktops (Reverse)");
00261     cutWalkThroughDesktopList = keys->shortcut("Walk Through Desktop List");
00262     cutWalkThroughDesktopListReverse = keys->shortcut("Walk Through Desktop List (Reverse)");
00263     cutWalkThroughWindows = keys->shortcut("Walk Through Windows");
00264     cutWalkThroughWindowsReverse = keys->shortcut("Walk Through Windows (Reverse)");
00265 
00266     keys->updateConnections();
00267     
00268     delete popup;
00269     popup = NULL; // so that it's recreated next time
00270     desk_popup = NULL;
00271     }
00272 
00273 
00274 void Workspace::setupWindowShortcut( Client* c )
00275     {
00276     assert( client_keys_dialog == NULL );
00277     keys->setEnabled( false );
00278     client_keys->setEnabled( false );
00279     client_keys_dialog = new ShortcutDialog( c->shortcut());
00280     client_keys_client = c;
00281     connect( client_keys_dialog, SIGNAL( dialogDone( bool )), SLOT( setupWindowShortcutDone( bool )));
00282     QRect r = clientArea( ScreenArea, c );
00283     QSize size = client_keys_dialog->sizeHint();
00284     QPoint pos = c->pos() + c->clientPos();
00285     if( pos.x() + size.width() >= r.right())
00286         pos.setX( r.right() - size.width());
00287     if( pos.y() + size.height() >= r.bottom())
00288         pos.setY( r.bottom() - size.height());
00289     client_keys_dialog->move( pos );
00290     client_keys_dialog->show();
00291     active_popup = client_keys_dialog;
00292     active_popup_client = c;
00293     }
00294 
00295 void Workspace::setupWindowShortcutDone( bool ok )
00296     {
00297     keys->setEnabled( true );
00298     client_keys->setEnabled( true );
00299     if( ok )
00300         {
00301         client_keys_client->setShortcut( KShortcut( client_keys_dialog->shortcut()).toString());
00302         }
00303     closeActivePopup();
00304     delete client_keys_dialog;
00305     client_keys_dialog = NULL;
00306     client_keys_client = NULL;
00307     }
00308 
00309 void Workspace::clientShortcutUpdated( Client* c )
00310     {
00311     QString key = QString::number( c->window());
00312     client_keys->remove( key );
00313     if( !c->shortcut().isNull())
00314         {
00315         client_keys->insert( key, key );
00316         client_keys->setShortcut( key, c->shortcut());
00317         client_keys->setSlot( key, c, SLOT( shortcutActivated()));
00318         client_keys->setActionEnabled( key, true );
00319         }
00320     client_keys->updateConnections();
00321     }
00322 
00323 void Workspace::clientPopupActivated( int id )
00324     {
00325     WindowOperation op = static_cast< WindowOperation >( id );
00326     Client* c = active_popup_client ? active_popup_client : active_client;
00327     QString type;
00328     switch( op )
00329         {
00330         case FullScreenOp:
00331             if( !c->isFullScreen() && c->userCanSetFullScreen())
00332                 type = "fullscreenaltf3";
00333           break;
00334         case NoBorderOp:
00335             if( !c->noBorder() && c->userCanSetNoBorder())
00336                 type = "noborderaltf3";
00337           break;
00338         default:
00339             break;
00340         };
00341     if( !type.isEmpty())
00342         helperDialog( type, c );
00343     performWindowOperation( c, op );
00344     }
00345 
00346 
00347 void Workspace::performWindowOperation( Client* c, Options::WindowOperation op ) 
00348     {
00349     if ( !c )
00350         return;
00351 
00352     if (op == Options::MoveOp || op == Options::UnrestrictedMoveOp )
00353         QCursor::setPos( c->geometry().center() );
00354     if (op == Options::ResizeOp || op == Options::UnrestrictedResizeOp )
00355         QCursor::setPos( c->geometry().bottomRight());
00356     switch ( op ) 
00357         {
00358         case Options::MoveOp:
00359             c->performMouseCommand( Options::MouseMove, QCursor::pos() );
00360             break;
00361         case Options::UnrestrictedMoveOp:
00362             c->performMouseCommand( Options::MouseUnrestrictedMove, QCursor::pos() );
00363             break;
00364         case Options::ResizeOp:
00365             c->performMouseCommand( Options::MouseResize, QCursor::pos() );
00366             break;
00367         case Options::UnrestrictedResizeOp:
00368             c->performMouseCommand( Options::MouseUnrestrictedResize, QCursor::pos() );
00369             break;
00370         case Options::CloseOp:
00371             c->closeWindow();
00372             break;
00373         case Options::MaximizeOp:
00374             c->maximize( c->maximizeMode() == Client::MaximizeFull
00375                 ? Client::MaximizeRestore : Client::MaximizeFull );
00376             break;
00377         case Options::HMaximizeOp:
00378             c->maximize( c->maximizeMode() ^ Client::MaximizeHorizontal );
00379             break;
00380         case Options::VMaximizeOp:
00381             c->maximize( c->maximizeMode() ^ Client::MaximizeVertical );
00382             break;
00383         case Options::MinimizeOp:
00384             c->minimize();
00385             break;
00386         case Options::ShadeOp:
00387             c->performMouseCommand( Options::MouseShade, QCursor::pos());
00388             break;
00389         case Options::OnAllDesktopsOp:
00390             c->setOnAllDesktops( !c->isOnAllDesktops() );
00391             break;
00392         case Options::FullScreenOp:
00393             c->setFullScreen( !c->isFullScreen(), true );
00394             break;
00395         case Options::NoBorderOp:
00396             c->setUserNoBorder( !c->isUserNoBorder());
00397             break;
00398         case Options::KeepAboveOp:
00399             c->setKeepAbove( !c->keepAbove() );
00400             break;
00401         case Options::KeepBelowOp:
00402             c->setKeepBelow( !c->keepBelow() );
00403             break;
00404         case Options::WindowRulesOp:
00405             editWindowRules( c );
00406             break;
00407         case Options::SetupWindowShortcutOp:
00408             setupWindowShortcut( c );
00409             break;
00410         case Options::LowerOp:
00411             lowerClient(c);
00412             break;
00413         default:
00414             break;
00415         }
00416     }
00417 
00421 bool Client::performMouseCommand( Options::MouseCommand command, QPoint globalPos, bool handled )
00422     {
00423     bool replay = FALSE;
00424     switch (command) 
00425         {
00426         case Options::MouseRaise:
00427             workspace()->raiseClient( this );
00428             break;
00429         case Options::MouseLower:
00430             workspace()->lowerClient( this );
00431             break;
00432         case Options::MouseShade :
00433             delete shadeHoverTimer;
00434             shadeHoverTimer = 0;
00435             toggleShade();
00436             break;
00437         case Options::MouseOperationsMenu:
00438             if ( isActive() & options->clickRaise )
00439                 autoRaise();
00440             workspace()->showWindowMenu( globalPos, this );
00441             break;
00442         case Options::MouseToggleRaiseAndLower:
00443             workspace()->raiseOrLowerClient( this );
00444             break;
00445         case Options::MouseActivateAndRaise:
00446             replay = isActive(); // for clickraise mode
00447             workspace()->takeActivity( this, ActivityFocus | ActivityRaise, handled && replay );
00448             break;
00449         case Options::MouseActivateAndLower:
00450             workspace()->requestFocus( this );
00451             workspace()->lowerClient( this );
00452             break;
00453         case Options::MouseActivate:
00454             replay = isActive(); // for clickraise mode
00455             workspace()->takeActivity( this, ActivityFocus, handled && replay );
00456             break;
00457         case Options::MouseActivateRaiseAndPassClick:
00458             workspace()->takeActivity( this, ActivityFocus | ActivityRaise, handled );
00459             replay = TRUE;
00460             break;
00461         case Options::MouseActivateAndPassClick:
00462             workspace()->takeActivity( this, ActivityFocus, handled );
00463             replay = TRUE;
00464             break;
00465         case Options::MouseActivateRaiseAndMove:
00466         case Options::MouseActivateRaiseAndUnrestrictedMove:
00467             workspace()->raiseClient( this );
00468             workspace()->requestFocus( this );
00469             if( options->moveMode == Options::Transparent && isMovable())
00470                 move_faked_activity = workspace()->fakeRequestedActivity( this );
00471         // fallthrough
00472         case Options::MouseMove:
00473         case Options::MouseUnrestrictedMove:
00474             {
00475             if (!isMovable())
00476                 break;
00477             if( moveResizeMode )
00478                 finishMoveResize( false );
00479             mode = PositionCenter;
00480             buttonDown = TRUE;
00481             moveOffset = QPoint( globalPos.x() - x(), globalPos.y() - y()); // map from global
00482             invertedMoveOffset = rect().bottomRight() - moveOffset;
00483             unrestrictedMoveResize = ( command == Options::MouseActivateRaiseAndUnrestrictedMove
00484                                     || command == Options::MouseUnrestrictedMove );
00485             setCursor( mode );
00486             if( !startMoveResize())
00487                 {
00488                 buttonDown = false;
00489                 setCursor( mode );
00490                 }
00491             break;
00492             }
00493         case Options::MouseResize:
00494         case Options::MouseUnrestrictedResize:
00495             {
00496             if (!isResizable() || isShade())
00497                 break;
00498             if( moveResizeMode )
00499                 finishMoveResize( false );
00500             buttonDown = TRUE;
00501             moveOffset = QPoint( globalPos.x() - x(), globalPos.y() - y()); // map from global
00502             int x = moveOffset.x(), y = moveOffset.y();
00503             bool left = x < width() / 3;
00504             bool right = x >= 2 * width() / 3;
00505             bool top = y < height() / 3;
00506             bool bot = y >= 2 * height() / 3;
00507             if (top)
00508                 mode = left ? PositionTopLeft : (right ? PositionTopRight : PositionTop);
00509             else if (bot)
00510                 mode = left ? PositionBottomLeft : (right ? PositionBottomRight : PositionBottom);
00511             else
00512                 mode = (x < width() / 2) ? PositionLeft : PositionRight;
00513             invertedMoveOffset = rect().bottomRight() - moveOffset;
00514             unrestrictedMoveResize = ( command == Options::MouseUnrestrictedResize );
00515             setCursor( mode );
00516             if( !startMoveResize())
00517                 {
00518                 buttonDown = false;
00519                 setCursor( mode );
00520                 }
00521             break;
00522             }
00523         case Options::MouseMinimize:
00524             minimize();
00525             break;
00526         case Options::MouseNothing:
00527         // fall through
00528         default:
00529             replay = TRUE;
00530             break;
00531         }
00532     return replay;
00533     }
00534 
00535 // KDE4 remove me
00536 void Workspace::showWindowMenuAt( unsigned long, int, int )
00537     {
00538     slotWindowOperations();
00539     }
00540 
00541 void Workspace::slotActivateAttentionWindow()
00542     {
00543     if( attention_chain.count() > 0 )
00544         activateClient( attention_chain.first());
00545     }
00546 
00547 void Workspace::slotSwitchDesktopNext()
00548     {
00549     int d = currentDesktop() + 1;
00550      if ( d > numberOfDesktops() ) 
00551         {
00552         if ( options->rollOverDesktops ) 
00553             {
00554             d = 1;
00555             }
00556         else 
00557             {
00558             return;
00559             }
00560         }
00561     setCurrentDesktop(d);
00562     popupinfo->showInfo( desktopName(currentDesktop()) );
00563     }
00564 
00565 void Workspace::slotSwitchDesktopPrevious()
00566     {
00567     int d = currentDesktop() - 1;
00568     if ( d <= 0 ) 
00569         {
00570         if ( options->rollOverDesktops )
00571           d = numberOfDesktops();
00572       else
00573           return;
00574         }
00575     setCurrentDesktop(d);
00576     popupinfo->showInfo( desktopName(currentDesktop()) );
00577     }
00578 
00579 void Workspace::slotSwitchDesktopRight()
00580     {
00581     int desktop = desktopToRight( currentDesktop());
00582     if( desktop == currentDesktop())
00583         return;
00584     setCurrentDesktop( desktop );
00585     popupinfo->showInfo( desktopName(currentDesktop()) );
00586     }
00587 
00588 void Workspace::slotSwitchDesktopLeft()
00589     {
00590     int desktop = desktopToLeft( currentDesktop());
00591     if( desktop == currentDesktop())
00592         return;
00593     setCurrentDesktop( desktop );
00594     popupinfo->showInfo( desktopName(currentDesktop()) );
00595     }
00596 
00597 void Workspace::slotSwitchDesktopUp()
00598     {
00599     int desktop = desktopUp( currentDesktop());
00600     if( desktop == currentDesktop())
00601         return;
00602     setCurrentDesktop( desktop );
00603     popupinfo->showInfo( desktopName(currentDesktop()) );
00604     }
00605 
00606 void Workspace::slotSwitchDesktopDown()
00607     {
00608     int desktop = desktopDown( currentDesktop());
00609     if( desktop == currentDesktop())
00610         return;
00611     setCurrentDesktop( desktop );
00612     popupinfo->showInfo( desktopName(currentDesktop()) );
00613     }
00614 
00615 void Workspace::slotSwitchToDesktop( int i )
00616     {
00617     setCurrentDesktop( i );
00618     popupinfo->showInfo( desktopName(currentDesktop()) );
00619     }
00620 
00621 
00622 void Workspace::slotWindowToDesktop( int i )
00623     {
00624     Client* c = active_popup_client ? active_popup_client : active_client;
00625     if( i >= 1 && i <= numberOfDesktops() && c
00626         && !c->isDesktop()
00627         && !c->isDock()
00628         && !c->isTopMenu())
00629             sendClientToDesktop( c, i, true );
00630     }
00631 
00635 void Workspace::slotWindowMaximize()
00636     {
00637     Client* c = active_popup_client ? active_popup_client : active_client;
00638     if ( c )
00639         performWindowOperation( c, Options::MaximizeOp );
00640     }
00641 
00645 void Workspace::slotWindowMaximizeVertical()
00646     {
00647     Client* c = active_popup_client ? active_popup_client : active_client;
00648     if ( c )
00649         performWindowOperation( c, Options::VMaximizeOp );
00650     }
00651 
00655 void Workspace::slotWindowMaximizeHorizontal()
00656     {
00657     Client* c = active_popup_client ? active_popup_client : active_client;
00658     if ( c )
00659         performWindowOperation( c, Options::HMaximizeOp );
00660     }
00661 
00662 
00666 void Workspace::slotWindowMinimize()
00667     {
00668     Client* c = active_popup_client ? active_popup_client : active_client;
00669     performWindowOperation( c, Options::MinimizeOp );
00670     }
00671 
00675 void Workspace::slotWindowShade()
00676     {
00677     Client* c = active_popup_client ? active_popup_client : active_client;
00678     performWindowOperation( c, Options::ShadeOp );
00679     }
00680 
00684 void Workspace::slotWindowRaise()
00685     {
00686     Client* c = active_popup_client ? active_popup_client : active_client;
00687     if ( c )
00688         raiseClient( c );
00689     }
00690 
00694 void Workspace::slotWindowLower()
00695     {
00696     Client* c = active_popup_client ? active_popup_client : active_client;
00697     if ( c )
00698         lowerClient( c );
00699     }
00700 
00704 void Workspace::slotWindowRaiseOrLower()
00705     {
00706     Client* c = active_popup_client ? active_popup_client : active_client;
00707     if  ( c )
00708         raiseOrLowerClient( c );
00709     }
00710 
00711 void Workspace::slotWindowOnAllDesktops()
00712     {
00713     Client* c = active_popup_client ? active_popup_client : active_client;
00714     if( c )
00715         c->setOnAllDesktops( !c->isOnAllDesktops());
00716     }
00717 
00718 void Workspace::slotWindowFullScreen()
00719     {
00720     Client* c = active_popup_client ? active_popup_client : active_client;
00721     if( c )
00722         performWindowOperation( c, Options::FullScreenOp );
00723     }
00724 
00725 void Workspace::slotWindowNoBorder()
00726     {
00727     Client* c = active_popup_client ? active_popup_client : active_client;
00728     if( c )
00729         performWindowOperation( c, Options::NoBorderOp );
00730     }
00731 
00732 void Workspace::slotWindowAbove()
00733     {
00734     Client* c = active_popup_client ? active_popup_client : active_client;
00735     if( c )
00736         performWindowOperation( c, Options::KeepAboveOp );
00737     }
00738 
00739 void Workspace::slotWindowBelow()
00740     {
00741     Client* c = active_popup_client ? active_popup_client : active_client;
00742     if( c )
00743         performWindowOperation( c, Options::KeepBelowOp );
00744     }
00745 void Workspace::slotSetupWindowShortcut()
00746     {
00747     Client* c = active_popup_client ? active_popup_client : active_client;
00748     if( c )
00749         performWindowOperation( c, Options::SetupWindowShortcutOp );
00750     }
00751 
00755 void Workspace::slotWindowToNextDesktop()
00756     {
00757     int d = currentDesktop() + 1;
00758     if ( d > numberOfDesktops() )
00759         d = 1;
00760     Client* c = active_popup_client ? active_popup_client : active_client;
00761     if (c && !c->isDesktop()
00762         && !c->isDock() && !c->isTopMenu())
00763         {
00764         setClientIsMoving( c );
00765         setCurrentDesktop( d );
00766         setClientIsMoving( NULL );
00767         popupinfo->showInfo( desktopName(currentDesktop()) );
00768         }
00769     }
00770 
00774 void Workspace::slotWindowToPreviousDesktop()
00775     {
00776     int d = currentDesktop() - 1;
00777     if ( d <= 0 )
00778         d = numberOfDesktops();
00779     Client* c = active_popup_client ? active_popup_client : active_client;
00780     if (c && !c->isDesktop()
00781         && !c->isDock() && !c->isTopMenu())
00782         {
00783         setClientIsMoving( c );
00784         setCurrentDesktop( d );
00785         setClientIsMoving( NULL );
00786         popupinfo->showInfo( desktopName(currentDesktop()) );
00787         }
00788     }
00789 
00790 void Workspace::slotWindowToDesktopRight()
00791     {
00792     int d = desktopToRight( currentDesktop());
00793     if( d == currentDesktop())
00794         return;
00795     Client* c = active_popup_client ? active_popup_client : active_client;
00796     if (c && !c->isDesktop()
00797         && !c->isDock() && !c->isTopMenu())
00798         {
00799         setClientIsMoving( c );
00800         setCurrentDesktop( d );
00801         setClientIsMoving( NULL );
00802         popupinfo->showInfo( desktopName(currentDesktop()) );
00803         }
00804     }
00805 
00806 void Workspace::slotWindowToDesktopLeft()
00807     {
00808     int d = desktopToLeft( currentDesktop());
00809     if( d == currentDesktop())
00810         return;
00811     Client* c = active_popup_client ? active_popup_client : active_client;
00812     if (c && !c->isDesktop()
00813         && !c->isDock() && !c->isTopMenu())
00814         {
00815         setClientIsMoving( c );
00816         setCurrentDesktop( d );
00817         setClientIsMoving( NULL );
00818         popupinfo->showInfo( desktopName(currentDesktop()) );
00819         }
00820     }
00821 
00822 void Workspace::slotWindowToDesktopUp()
00823     {
00824     int d = desktopUp( currentDesktop());
00825     if( d == currentDesktop())
00826         return;
00827     Client* c = active_popup_client ? active_popup_client : active_client;
00828     if (c && !c->isDesktop()
00829         && !c->isDock() && !c->isTopMenu())
00830         {
00831         setClientIsMoving( c );
00832         setCurrentDesktop( d );
00833         setClientIsMoving( NULL );
00834         popupinfo->showInfo( desktopName(currentDesktop()) );
00835         }
00836     }
00837 
00838 void Workspace::slotWindowToDesktopDown()
00839     {
00840     int d = desktopDown( currentDesktop());
00841     if( d == currentDesktop())
00842         return;
00843     Client* c = active_popup_client ? active_popup_client : active_client;
00844     if (c && !c->isDesktop()
00845         && !c->isDock() && !c->isTopMenu())
00846         {
00847         setClientIsMoving( c );
00848         setCurrentDesktop( d );
00849         setClientIsMoving( NULL );
00850         popupinfo->showInfo( desktopName(currentDesktop()) );
00851         }
00852     }
00853 
00854 
00858 void Workspace::slotKillWindow()
00859     {
00860     KillWindow kill( this );
00861     kill.start();
00862     }
00863 
00869 void Workspace::slotSendToDesktop( int desk )
00870     {
00871     if ( !active_popup_client )
00872         return;
00873     if ( desk == 0 ) 
00874         { // the 'on_all_desktops' menu entry
00875         active_popup_client->setOnAllDesktops( !active_popup_client->isOnAllDesktops());
00876         return;
00877         }
00878 
00879     sendClientToDesktop( active_popup_client, desk, false );
00880 
00881     }
00882 
00886 void Workspace::slotWindowOperations()
00887     {
00888     if ( !active_client )
00889         return;
00890     QPoint pos = active_client->pos() + active_client->clientPos();
00891     showWindowMenu( pos.x(), pos.y(), active_client );
00892     }
00893 
00894 void Workspace::showWindowMenu( const QRect &pos, Client* cl )
00895     {
00896     if (!kapp->authorizeKAction("kwin_rmb"))
00897         return;
00898     if( !cl )
00899         return;
00900     if( active_popup_client != NULL ) // recursion
00901         return;
00902     if ( cl->isDesktop()
00903         || cl->isDock()
00904         || cl->isTopMenu())
00905         return;
00906 
00907     active_popup_client = cl;
00908     QPopupMenu* p = clientPopup();
00909     active_popup = p;
00910     int x = pos.left();
00911     int y = pos.bottom();
00912     if (y == pos.top())
00913     p->exec( QPoint( x, y ) );
00914     else
00915         {
00916     QRect area = clientArea(ScreenArea, QPoint(x, y), currentDesktop());
00917     int popupHeight = p->sizeHint().height();
00918     if (y + popupHeight < area.height())
00919         p->exec( QPoint( x, y ) );
00920     else
00921         p->exec( QPoint( x, pos.top() - popupHeight ) );
00922         }
00923     // active popup may be already changed (e.g. the window shortcut dialog)
00924     if( active_popup == p )
00925         closeActivePopup();
00926     }
00927 
00931 void Workspace::slotWindowClose()
00932     {
00933     if ( tab_box->isVisible() || popupinfo->isVisible() )
00934         return;
00935     Client* c = active_popup_client ? active_popup_client : active_client;
00936     performWindowOperation( c, Options::CloseOp );
00937     }
00938 
00942 void Workspace::slotWindowMove()
00943     {
00944     Client* c = active_popup_client ? active_popup_client : active_client;
00945     performWindowOperation( c, Options::UnrestrictedMoveOp );
00946     }
00947 
00951 void Workspace::slotWindowResize()
00952     {
00953     Client* c = active_popup_client ? active_popup_client : active_client;
00954     performWindowOperation( c, Options::UnrestrictedResizeOp );
00955     }
00956 
00957 void Client::setShortcut( const QString& _cut )
00958     {
00959     QString cut = rules()->checkShortcut( _cut );
00960     if( cut.isEmpty())
00961         return setShortcutInternal( KShortcut());
00962 // Format:
00963 // base+(abcdef)<space>base+(abcdef)
00964 // E.g. Alt+Ctrl+(ABCDEF) Win+X,Win+(ABCDEF)
00965     if( !cut.contains( '(' ) && !cut.contains( ')' ) && !cut.contains( ' ' ))
00966         {
00967         if( workspace()->shortcutAvailable( KShortcut( cut ), this ))
00968             setShortcutInternal( KShortcut( cut ));
00969         else
00970             setShortcutInternal( KShortcut());
00971         return;
00972         }
00973     QValueList< KShortcut > keys;
00974     QStringList groups = QStringList::split( ' ', cut );
00975     for( QStringList::ConstIterator it = groups.begin();
00976          it != groups.end();
00977          ++it )
00978         {
00979         QRegExp reg( "(.*\\+)\\((.*)\\)" );
00980         if( reg.search( *it ) > -1 )
00981             {
00982             QString base = reg.cap( 1 );
00983             QString list = reg.cap( 2 );
00984             for( unsigned int i = 0;
00985                  i < list.length();
00986                  ++i )
00987                 {
00988                 KShortcut c( base + list[ i ] );
00989                 if( !c.isNull())
00990                     keys.append( c );
00991                 }
00992             }
00993         }
00994     for( QValueList< KShortcut >::ConstIterator it = keys.begin();
00995          it != keys.end();
00996          ++it )
00997         {
00998         if( _shortcut == *it ) // current one is in the list
00999             return;
01000         }
01001     for( QValueList< KShortcut >::ConstIterator it = keys.begin();
01002          it != keys.end();
01003          ++it )
01004         {
01005         if( workspace()->shortcutAvailable( *it, this ))
01006             {
01007             setShortcutInternal( *it );
01008             return;
01009             }
01010         }
01011     setShortcutInternal( KShortcut());
01012     }
01013 
01014 void Client::setShortcutInternal( const KShortcut& cut )
01015     {
01016     if( _shortcut == cut )
01017         return;
01018     _shortcut = cut;
01019     updateCaption();
01020     workspace()->clientShortcutUpdated( this );
01021     }
01022 
01023 bool Workspace::shortcutAvailable( const KShortcut& cut, Client* ignore ) const
01024     {
01025     // TODO check global shortcuts etc.
01026     for( ClientList::ConstIterator it = clients.begin();
01027          it != clients.end();
01028          ++it )
01029         {
01030         if( (*it) != ignore && (*it)->shortcut() == cut )
01031             return false;    
01032         }
01033     return true;
01034     }
01035 
01036 } // namespace
KDE Logo
This file is part of the documentation for kwin Library Version 3.4.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Apr 6 02:41:07 2005 by doxygen 1.4.0 written by Dimitri van Heesch, © 1997-2003