• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • twin
 

twin

  • twin
useractions.cpp
1 /*****************************************************************
2  KWin - the KDE window manager
3  This file is part of the KDE project.
4 
5 Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
6 Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
7 
8 You can Freely distribute this program under the GNU General Public
9 License. See the file "COPYING" for the exact licensing terms.
10 ******************************************************************/
11 
12 /*
13 
14  This file contains things relevant to direct user actions, such as
15  responses to global keyboard shortcuts, or selecting actions
16  from the window operations menu.
17 
18 */
19 
20 #include <tqhbox.h>
21 #include <tqpushbutton.h>
22 #include <tqslider.h>
23 #include <tqtooltip.h>
24 #include <tqpopupmenu.h>
25 #include <tdeglobalsettings.h>
26 #include <kiconloader.h>
27 #include <tdelocale.h>
28 #include <tdeconfig.h>
29 #include <kglobalaccel.h>
30 #include <tdeapplication.h>
31 #include <tqregexp.h>
32 
33 #include "client.h"
34 #include "workspace.h"
35 #include <fixx11h.h>
36 
37 #include "killwindow.h"
38 #include "tabbox.h"
39 
40 namespace KWinInternal
41 {
42 
43 //****************************************
44 // Workspace
45 //****************************************
46 
47 TQPopupMenu* Workspace::clientPopup()
48  {
49  if ( !popup )
50  {
51  popup = new TQPopupMenu;
52  popup->setCheckable( TRUE );
53  popup->setFont(TDEGlobalSettings::menuFont());
54  connect( popup, TQT_SIGNAL( aboutToShow() ), this, TQT_SLOT( clientPopupAboutToShow() ) );
55  connect( popup, TQT_SIGNAL( activated(int) ), this, TQT_SLOT( clientPopupActivated(int) ) );
56 
57  advanced_popup = new TQPopupMenu( popup );
58  advanced_popup->setCheckable( TRUE );
59  advanced_popup->setFont(TDEGlobalSettings::menuFont());
60  connect( advanced_popup, TQT_SIGNAL( activated(int) ), this, TQT_SLOT( clientPopupActivated(int) ) );
61  advanced_popup->insertItem( SmallIconSet( "go-up" ),
62  i18n("Keep &Above Others")+'\t'+keys->shortcut("Window Above Other Windows").seq(0).toString(), Options::KeepAboveOp );
63  advanced_popup->insertItem( SmallIconSet( "go-down" ),
64  i18n("Keep &Below Others")+'\t'+keys->shortcut("Window Below Other Windows").seq(0).toString(), Options::KeepBelowOp );
65  advanced_popup->insertItem( SmallIconSet( "view-fullscreen" ),
66  i18n("&Fullscreen")+'\t'+keys->shortcut("Window Fullscreen").seq(0).toString(), Options::FullScreenOp );
67  advanced_popup->insertItem( i18n("&No Border")+'\t'+keys->shortcut("Window No Border").seq(0).toString(), Options::NoBorderOp );
68  advanced_popup->insertItem( i18n("Shad&ow"), Options::ShadowOp );
69  advanced_popup->insertItem( SmallIconSet("key_bindings"),
70  i18n("Window &Shortcut...")+'\t'+keys->shortcut("Setup Window Shortcut").seq(0).toString(), Options::SetupWindowShortcutOp );
71  advanced_popup->insertSeparator();
72  advanced_popup->insertItem( SmallIconSet( "suspend" ), i18n("&Suspend Application"), Options::SuspendWindowOp );
73  advanced_popup->insertItem( SmallIconSet( "application-x-executable" ), i18n("&Resume Application"), Options::ResumeWindowOp );
74  advanced_popup->insertSeparator();
75  advanced_popup->insertItem( SmallIconSet( "wizard" ), i18n("&Special Window Settings..."), Options::WindowRulesOp );
76  advanced_popup->insertItem( SmallIconSet( "wizard" ), i18n("&Special Application Settings..."), Options::ApplicationRulesOp );
77 
78  popup->insertItem(i18n("Ad&vanced"), advanced_popup );
79  desk_popup_index = popup->count();
80 
81  if (options->useTranslucency){
82  TQPopupMenu *trans_popup = new TQPopupMenu( popup );
83  TQVBox *transBox = new TQVBox(trans_popup);
84  transButton = new TQPushButton(transBox, "transButton");
85  TQToolTip::add(transButton, i18n("Reset opacity to default value"));
86  transSlider = new TQSlider(0, 100, 1, 100, Qt::Horizontal, transBox, "transSlider");
87  TQToolTip::add(transSlider, i18n("Slide this to set the window's opacity"));
88  connect(transButton, TQT_SIGNAL(clicked()), TQT_SLOT(resetClientOpacity()));
89  connect(transButton, TQT_SIGNAL(clicked()), trans_popup, TQT_SLOT(hide()));
90  connect(transSlider, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(setTransButtonText(int)));
91  connect(transSlider, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(setPopupClientOpacity(int)));
92 // connect(transSlider, TQT_SIGNAL(sliderReleased()), trans_popup, TQT_SLOT(hide()));
93  trans_popup->insertItem(transBox);
94  popup->insertItem(i18n("&Opacity"), trans_popup );
95  }
96 
97  popup->insertItem( SmallIconSet( "move" ), i18n("&Move")+'\t'+keys->shortcut("Window Move").seq(0).toString(), Options::MoveOp );
98  popup->insertItem( i18n("Re&size")+'\t'+keys->shortcut("Window Resize").seq(0).toString(), Options::ResizeOp );
99  popup->insertItem( i18n("Mi&nimize")+'\t'+keys->shortcut("Window Minimize").seq(0).toString(), Options::MinimizeOp );
100  popup->insertItem( i18n("Ma&ximize")+'\t'+keys->shortcut("Window Maximize").seq(0).toString(), Options::MaximizeOp );
101  popup->insertItem( i18n("Sh&ade")+'\t'+keys->shortcut("Window Shade").seq(0).toString(), Options::ShadeOp );
102 
103  popup->insertSeparator();
104 
105  if (!TDEGlobal::config()->isImmutable() &&
106  !kapp->authorizeControlModules(Workspace::configModules(true)).isEmpty())
107  {
108  popup->insertItem(SmallIconSet( "configure" ), i18n("Configur&e Window Behavior..."), this, TQT_SLOT( configureWM() ));
109  popup->insertSeparator();
110  }
111 
112  popup->insertItem( SmallIconSet( "window-close" ), i18n("&Close")+'\t'+keys->shortcut("Window Close").seq(0).toString(), Options::CloseOp );
113  }
114  return popup;
115  }
116 
117 //sets the transparency of the client to given value(given by slider)
118 void Workspace::setPopupClientOpacity(int value)
119  {
120  active_popup_client->setCustomOpacityFlag(true);
121  value = 100 - value;
122  value<100?active_popup_client->setOpacity(true, (uint)((value/100.0)*0xffffffff)):active_popup_client->setOpacity(false,0xffffffff);
123  }
124 
125 void Workspace::setTransButtonText(int value)
126  {
127  value = 100 - value;
128  if(value < 0)
129  transButton->setText(" 0 %");
130  else if (value >= 100 )
131  transButton->setText("100 %");
132  else if(value < 10)
133  transButton->setText(" "+TQString::number(value)+" %");
134  else if(value < 100)
135  transButton->setText(" "+TQString::number(value)+" %");
136  }
137 
138 void Workspace::resetClientOpacity()
139  {
140  active_popup_client->setCustomOpacityFlag(false);
141  active_popup_client->updateOpacity();
142  transSlider->setValue(100-active_popup_client->opacityPercentage());
143  setTransButtonText(100-active_popup_client->opacityPercentage());
144  }
145 
146 
152 void Workspace::clientPopupAboutToShow()
153  {
154  if ( !active_popup_client || !popup )
155  return;
156 
157  if ( numberOfDesktops() == 1 )
158  {
159  delete desk_popup;
160  desk_popup = 0;
161  }
162  else
163  {
164  initDesktopPopup();
165  }
166 
167  popup->setItemEnabled( Options::ResizeOp, active_popup_client->isResizable() );
168  popup->setItemEnabled( Options::MoveOp, active_popup_client->isMovable() );
169  popup->setItemEnabled( Options::MaximizeOp, active_popup_client->isMaximizable() );
170  popup->setItemChecked( Options::MaximizeOp, active_popup_client->maximizeMode() == Client::MaximizeFull );
171  // This should be checked also when hover unshaded
172  popup->setItemChecked( Options::ShadeOp, active_popup_client->shadeMode() != ShadeNone );
173  popup->setItemEnabled( Options::ShadeOp, active_popup_client->isShadeable());
174  advanced_popup->setItemChecked( Options::KeepAboveOp, active_popup_client->keepAbove() );
175  advanced_popup->setItemChecked( Options::KeepBelowOp, active_popup_client->keepBelow() );
176  advanced_popup->setItemChecked( Options::FullScreenOp, active_popup_client->isFullScreen() );
177  advanced_popup->setItemEnabled( Options::FullScreenOp, active_popup_client->userCanSetFullScreen() );
178  advanced_popup->setItemEnabled( Options::SuspendWindowOp, active_popup_client->isSuspendable() );
179  advanced_popup->setItemEnabled( Options::ResumeWindowOp, active_popup_client->isResumeable() );
180  advanced_popup->setItemChecked( Options::NoBorderOp, active_popup_client->noBorder() );
181  advanced_popup->setItemEnabled( Options::NoBorderOp, active_popup_client->userCanSetNoBorder() );
182 
183  advanced_popup->setItemEnabled( Options::ShadowOp, (options->shadowWindowType(active_popup_client->windowType()) && options->shadowEnabled(active_popup_client->isActive())) );
184  advanced_popup->setItemChecked( Options::ShadowOp, active_popup_client->isShadowed() );
185 
186  popup->setItemEnabled( Options::MinimizeOp, active_popup_client->isMinimizable() );
187  popup->setItemEnabled( Options::CloseOp, active_popup_client->isCloseable() );
188  if (options->useTranslucency)
189  {
190  transSlider->setValue(100-active_popup_client->opacityPercentage());
191  setTransButtonText(100-active_popup_client->opacityPercentage());
192  }
193  }
194 
195 
196 void Workspace::initDesktopPopup()
197  {
198  if (desk_popup)
199  return;
200 
201  desk_popup = new TQPopupMenu( popup );
202  desk_popup->setCheckable( TRUE );
203  desk_popup->setFont(TDEGlobalSettings::menuFont());
204  connect( desk_popup, TQT_SIGNAL( activated(int) ),
205  this, TQT_SLOT( slotSendToDesktop(int) ) );
206  connect( desk_popup, TQT_SIGNAL( aboutToShow() ),
207  this, TQT_SLOT( desktopPopupAboutToShow() ) );
208 
209  popup->insertItem(i18n("To &Desktop"), desk_popup, -1, desk_popup_index );
210  }
211 
216 void Workspace::desktopPopupAboutToShow()
217  {
218  if ( !desk_popup )
219  return;
220 
221  desk_popup->clear();
222  desk_popup->insertItem( i18n("&All Desktops"), 0 );
223  if ( active_popup_client && active_popup_client->isOnAllDesktops() )
224  desk_popup->setItemChecked( 0, TRUE );
225  desk_popup->insertSeparator( -1 );
226  int id;
227  const int BASE = 10;
228  for ( int i = 1; i <= numberOfDesktops(); i++ )
229  {
230  TQString basic_name("%1 %2");
231  if (i<BASE)
232  {
233  basic_name.prepend('&');
234  }
235  id = desk_popup->insertItem(
236  basic_name
237  .arg(i)
238  .arg( desktopName(i).replace( '&', "&&" )),
239  i );
240  if ( active_popup_client &&
241  !active_popup_client->isOnAllDesktops() && active_popup_client->desktop() == i )
242  desk_popup->setItemChecked( id, TRUE );
243  }
244  }
245 
246 void Workspace::closeActivePopup()
247  {
248  if( active_popup )
249  {
250  active_popup->close();
251  active_popup = NULL;
252  active_popup_client = NULL;
253  }
254  }
255 
259 void Workspace::initShortcuts()
260  {
261  keys = new TDEGlobalAccel( this );
262  // a separate TDEGlobalAccel is needed for the shortcut for disabling global shortcuts,
263  // otherwise it would also disable itself
264  disable_shortcuts_keys = new TDEGlobalAccel( this );
265  disable_shortcuts_keys->disableBlocking( true );
266 #define IN_KWIN
267 #include "twinbindings.cpp"
268  readShortcuts();
269  }
270 
271 void Workspace::readShortcuts()
272  {
273  keys->readSettings();
274  disable_shortcuts_keys->readSettings();
275 
276  cutWalkThroughDesktops = keys->shortcut("Walk Through Desktops");
277  cutWalkThroughDesktopsReverse = keys->shortcut("Walk Through Desktops (Reverse)");
278  cutWalkThroughDesktopList = keys->shortcut("Walk Through Desktop List");
279  cutWalkThroughDesktopListReverse = keys->shortcut("Walk Through Desktop List (Reverse)");
280  cutWalkThroughWindows = keys->shortcut("Walk Through Windows");
281  cutWalkThroughWindowsReverse = keys->shortcut("Walk Through Windows (Reverse)");
282  cutWalkThroughApps = keys->shortcut("Walk Through Windows of Same Application");
283  cutWalkThroughAppsReverse = keys->shortcut("Walk Through Windows of Same Application (Reverse)");
284 
285  keys->updateConnections();
286  disable_shortcuts_keys->updateConnections();
287 
288  delete popup;
289  popup = NULL; // so that it's recreated next time
290  desk_popup = NULL;
291  }
292 
293 
294 void Workspace::setupWindowShortcut( Client* c )
295  {
296  assert( client_keys_dialog == NULL );
297  keys->suspend( true );
298  disable_shortcuts_keys->suspend( true );
299  client_keys->suspend( true );
300  client_keys_dialog = new ShortcutDialog( c->shortcut());
301  client_keys_client = c;
302  connect( client_keys_dialog, TQT_SIGNAL( dialogDone( bool )), TQT_SLOT( setupWindowShortcutDone( bool )));
303  TQRect r = clientArea( ScreenArea, c );
304  TQSize size = client_keys_dialog->sizeHint();
305  TQPoint pos = c->pos() + c->clientPos();
306  if( pos.x() + size.width() >= r.right())
307  pos.setX( r.right() - size.width());
308  if( pos.y() + size.height() >= r.bottom())
309  pos.setY( r.bottom() - size.height());
310  client_keys_dialog->move( pos );
311  client_keys_dialog->show();
312  active_popup = client_keys_dialog;
313  active_popup_client = c;
314  }
315 
316 void Workspace::setupWindowShortcutDone( bool ok )
317  {
318  keys->suspend( false );
319  disable_shortcuts_keys->suspend( false );
320  client_keys->suspend( false );
321  if( ok )
322  {
323  client_keys_client->setShortcut( TDEShortcut( client_keys_dialog->shortcut()).toString());
324  }
325  closeActivePopup();
326  delete client_keys_dialog;
327  client_keys_dialog = NULL;
328  client_keys_client = NULL;
329  }
330 
331 void Workspace::clientShortcutUpdated( Client* c )
332  {
333  TQString key = TQString::number( c->window());
334  client_keys->remove( key );
335  if( !c->shortcut().isNull())
336  {
337  client_keys->insert( key, key );
338  client_keys->setShortcut( key, c->shortcut());
339  client_keys->setSlot( key, c, TQT_SLOT( shortcutActivated()));
340  client_keys->setActionEnabled( key, true );
341  }
342  client_keys->updateConnections();
343  }
344 
345 void Workspace::clientPopupActivated( int id )
346  {
347  WindowOperation op = static_cast< WindowOperation >( id );
348  Client* c = active_popup_client ? active_popup_client : active_client;
349  TQString type;
350  switch( op )
351  {
352  case FullScreenOp:
353  if( !c->isFullScreen() && c->userCanSetFullScreen())
354  type = "fullscreenaltf3";
355  break;
356  case NoBorderOp:
357  if( !c->noBorder() && c->userCanSetNoBorder())
358  type = "noborderaltf3";
359  break;
360  default:
361  break;
362  };
363  if( !type.isEmpty())
364  helperDialog( type, c );
365  performWindowOperation( c, op );
366  }
367 
368 
369 void Workspace::performWindowOperation( Client* c, Options::WindowOperation op )
370  {
371  if ( !c )
372  return;
373 
374  if (op == Options::MoveOp || op == Options::UnrestrictedMoveOp )
375  TQCursor::setPos( c->geometry().center() );
376  if (op == Options::ResizeOp || op == Options::UnrestrictedResizeOp )
377  TQCursor::setPos( c->geometry().bottomRight());
378  switch ( op )
379  {
380  case Options::MoveOp:
381  c->performMouseCommand( Options::MouseMove, TQCursor::pos() );
382  break;
383  case Options::UnrestrictedMoveOp:
384  c->performMouseCommand( Options::MouseUnrestrictedMove, TQCursor::pos() );
385  break;
386  case Options::ResizeOp:
387  c->performMouseCommand( Options::MouseResize, TQCursor::pos() );
388  break;
389  case Options::UnrestrictedResizeOp:
390  c->performMouseCommand( Options::MouseUnrestrictedResize, TQCursor::pos() );
391  break;
392  case Options::CloseOp:
393  c->closeWindow();
394  break;
395  case Options::MaximizeOp:
396  c->maximize( c->maximizeMode() == Client::MaximizeFull
397  ? Client::MaximizeRestore : Client::MaximizeFull );
398  break;
399  case Options::HMaximizeOp:
400  c->maximize( c->maximizeMode() ^ Client::MaximizeHorizontal );
401  break;
402  case Options::VMaximizeOp:
403  c->maximize( c->maximizeMode() ^ Client::MaximizeVertical );
404  break;
405  case Options::RestoreOp:
406  c->maximize( Client::MaximizeRestore );
407  break;
408  case Options::MinimizeOp:
409  c->minimize();
410  break;
411  case Options::ShadeOp:
412  c->performMouseCommand( Options::MouseShade, TQCursor::pos());
413  break;
414  case Options::ShadowOp:
415  c->setShadowed( !c->isShadowed() );
416  break;
417  case Options::OnAllDesktopsOp:
418  c->setOnAllDesktops( !c->isOnAllDesktops() );
419  break;
420  case Options::FullScreenOp:
421  c->setFullScreen( !c->isFullScreen(), true );
422  break;
423  case Options::NoBorderOp:
424  c->setUserNoBorder( !c->isUserNoBorder());
425  break;
426  case Options::KeepAboveOp:
427  {
428  StackingUpdatesBlocker blocker( this );
429  bool was = c->keepAbove();
430  c->setKeepAbove( !c->keepAbove() );
431  if( was && !c->keepAbove())
432  raiseClient( c );
433  break;
434  }
435  case Options::KeepBelowOp:
436  {
437  StackingUpdatesBlocker blocker( this );
438  bool was = c->keepBelow();
439  c->setKeepBelow( !c->keepBelow() );
440  if( was && !c->keepBelow())
441  lowerClient( c );
442  break;
443  }
444  case Options::OperationsOp:
445  c->performMouseCommand( Options::MouseShade, TQCursor::pos());
446  break;
447  case Options::SuspendWindowOp:
448  c->suspendWindow();
449  break;
450  case Options::ResumeWindowOp:
451  c->resumeWindow();
452  break;
453  case Options::WindowRulesOp:
454  editWindowRules( c, false );
455  break;
456  case Options::ApplicationRulesOp:
457  editWindowRules( c, true );
458  break;
459  case Options::SetupWindowShortcutOp:
460  setupWindowShortcut( c );
461  break;
462  case Options::LowerOp:
463  lowerClient(c);
464  break;
465  case Options::NoOp:
466  break;
467  }
468  }
469 
473 bool Client::performMouseCommand( Options::MouseCommand command, TQPoint globalPos, bool handled )
474  {
475  bool replay = FALSE;
476  switch (command)
477  {
478  case Options::MouseRaise:
479  workspace()->raiseClient( this );
480  break;
481  case Options::MouseLower:
482  workspace()->lowerClient( this );
483  break;
484  case Options::MouseShade :
485  toggleShade();
486  cancelShadeHover();
487  break;
488  case Options::MouseSetShade:
489  setShade( ShadeNormal );
490  cancelShadeHover();
491  break;
492  case Options::MouseUnsetShade:
493  setShade( ShadeNone );
494  cancelShadeHover();
495  break;
496  case Options::MouseOperationsMenu:
497  if ( isActive() && options->clickRaise )
498  autoRaise();
499  workspace()->showWindowMenu( globalPos, this );
500  break;
501  case Options::MouseToggleRaiseAndLower:
502  workspace()->raiseOrLowerClient( this );
503  break;
504  case Options::MouseActivateAndRaise:
505  replay = isActive(); // for clickraise mode
506  workspace()->takeActivity( this, ActivityFocus | ActivityRaise, handled && replay );
507  workspace()->setActiveScreenMouse( globalPos );
508  break;
509  case Options::MouseActivateAndLower:
510  workspace()->requestFocus( this );
511  workspace()->lowerClient( this );
512  workspace()->setActiveScreenMouse( globalPos );
513  break;
514  case Options::MouseActivate:
515  replay = isActive(); // for clickraise mode
516  workspace()->takeActivity( this, ActivityFocus, handled && replay );
517  workspace()->setActiveScreenMouse( globalPos );
518  break;
519  case Options::MouseActivateRaiseAndPassClick:
520  workspace()->takeActivity( this, ActivityFocus | ActivityRaise, handled );
521  workspace()->setActiveScreenMouse( globalPos );
522  replay = TRUE;
523  break;
524  case Options::MouseActivateAndPassClick:
525  workspace()->takeActivity( this, ActivityFocus, handled );
526  workspace()->setActiveScreenMouse( globalPos );
527  replay = TRUE;
528  break;
529  case Options::MouseActivateRaiseAndMove:
530  case Options::MouseActivateRaiseAndUnrestrictedMove:
531  workspace()->raiseClient( this );
532  workspace()->requestFocus( this );
533  workspace()->setActiveScreenMouse( globalPos );
534  if( options->moveMode == Options::Transparent && isMovable())
535  move_faked_activity = workspace()->fakeRequestedActivity( this );
536  // fallthrough
537  case Options::MouseMove:
538  case Options::MouseUnrestrictedMove:
539  {
540  if (!isMovable())
541  break;
542  if( moveResizeMode )
543  finishMoveResize( false );
544  mode = PositionCenter;
545  buttonDown = TRUE;
546  moveOffset = TQPoint( globalPos.x() - x(), globalPos.y() - y()); // map from global
547  invertedMoveOffset = rect().bottomRight() - moveOffset;
548  unrestrictedMoveResize = ( command == Options::MouseActivateRaiseAndUnrestrictedMove
549  || command == Options::MouseUnrestrictedMove );
550  setCursor( mode );
551  if( !startMoveResize())
552  {
553  buttonDown = false;
554  setCursor( mode );
555  }
556  break;
557  }
558  case Options::MouseResize:
559  case Options::MouseUnrestrictedResize:
560  {
561  if (!isResizable() || isShade())
562  break;
563  if( moveResizeMode )
564  finishMoveResize( false );
565  buttonDown = TRUE;
566  moveOffset = TQPoint( globalPos.x() - x(), globalPos.y() - y()); // map from global
567  int x = moveOffset.x(), y = moveOffset.y();
568  bool left = x < width() / 3;
569  bool right = x >= 2 * width() / 3;
570  bool top = y < height() / 3;
571  bool bot = y >= 2 * height() / 3;
572  if (top)
573  mode = left ? PositionTopLeft : (right ? PositionTopRight : PositionTop);
574  else if (bot)
575  mode = left ? PositionBottomLeft : (right ? PositionBottomRight : PositionBottom);
576  else
577  mode = (x < width() / 2) ? PositionLeft : PositionRight;
578  invertedMoveOffset = rect().bottomRight() - moveOffset;
579  unrestrictedMoveResize = ( command == Options::MouseUnrestrictedResize );
580  setCursor( mode );
581  if( !startMoveResize())
582  {
583  buttonDown = false;
584  setCursor( mode );
585  }
586  break;
587  }
588  case Options::MouseMaximize:
589  maximize( Client::MaximizeFull );
590  break;
591  case Options::MouseRestore:
592  maximize( Client::MaximizeRestore );
593  break;
594  case Options::MouseMinimize:
595  minimize();
596  break;
597  case Options::MouseAbove:
598  {
599  StackingUpdatesBlocker blocker( workspace());
600  if( keepBelow())
601  setKeepBelow( false );
602  else
603  setKeepAbove( true );
604  break;
605  }
606  case Options::MouseBelow:
607  {
608  StackingUpdatesBlocker blocker( workspace());
609  if( keepAbove())
610  setKeepAbove( false );
611  else
612  setKeepBelow( true );
613  break;
614  }
615  case Options::MousePreviousDesktop:
616  workspace()->windowToPreviousDesktop( this );
617  break;
618  case Options::MouseNextDesktop:
619  workspace()->windowToNextDesktop( this );
620  break;
621  case Options::MouseOpacityMore:
622  if (opacity_ < 0xFFFFFFFF)
623  {
624  if (opacity_ < 0xF3333333)
625  {
626  setOpacity(TRUE, opacity_ + 0xCCCCCCC);
627  custom_opacity = true;
628  }
629  else
630  {
631  setOpacity(FALSE, 0xFFFFFFFF);
632  custom_opacity = false;
633  }
634  }
635  break;
636  case Options::MouseOpacityLess:
637  if (opacity_ > 0)
638  {
639  setOpacity(TRUE, (opacity_ > 0xCCCCCCC) ? opacity_ - 0xCCCCCCC : 0);
640  custom_opacity = true;
641  }
642  break;
643  case Options::MouseNothing:
644  replay = TRUE;
645  break;
646  }
647  return replay;
648  }
649 
650 // KDE4 remove me
651 void Workspace::showWindowMenuAt( unsigned long, int, int )
652  {
653  slotWindowOperations();
654  }
655 
656 void Workspace::slotActivateAttentionWindow()
657  {
658  if( attention_chain.count() > 0 )
659  activateClient( attention_chain.first());
660  }
661 
662 void Workspace::slotSwitchDesktopNext()
663  {
664  int d = currentDesktop() + 1;
665  if ( d > numberOfDesktops() )
666  {
667  if ( options->rollOverDesktops )
668  {
669  d = 1;
670  }
671  else
672  {
673  return;
674  }
675  }
676  setCurrentDesktop(d);
677  }
678 
679 void Workspace::slotSwitchDesktopPrevious()
680  {
681  int d = currentDesktop() - 1;
682  if ( d <= 0 )
683  {
684  if ( options->rollOverDesktops )
685  d = numberOfDesktops();
686  else
687  return;
688  }
689  setCurrentDesktop(d);
690  }
691 
692 void Workspace::slotSwitchDesktopRight()
693  {
694  int desktop = desktopToRight( currentDesktop());
695  if( desktop == currentDesktop())
696  return;
697  setCurrentDesktop( desktop );
698  }
699 
700 void Workspace::slotSwitchDesktopLeft()
701  {
702  int desktop = desktopToLeft( currentDesktop());
703  if( desktop == currentDesktop())
704  return;
705  setCurrentDesktop( desktop );
706  }
707 
708 void Workspace::slotSwitchDesktopUp()
709  {
710  int desktop = desktopUp( currentDesktop());
711  if( desktop == currentDesktop())
712  return;
713  setCurrentDesktop( desktop );
714  }
715 
716 void Workspace::slotSwitchDesktopDown()
717  {
718  int desktop = desktopDown( currentDesktop());
719  if( desktop == currentDesktop())
720  return;
721  setCurrentDesktop( desktop );
722  }
723 
724 void Workspace::slotSwitchToDesktop( int i )
725  {
726  setCurrentDesktop( i );
727  }
728 
729 
730 void Workspace::slotWindowToDesktop( int i )
731  {
732  Client* c = active_popup_client ? active_popup_client : active_client;
733  if( i >= 1 && i <= numberOfDesktops() && c
734  && !c->isDesktop()
735  && !c->isDock()
736  && !c->isTopMenu())
737  sendClientToDesktop( c, i, true );
738  }
739 
740 void Workspace::slotSwitchToScreen( int i )
741  {
742  setCurrentScreen( i );
743  }
744 
745 void Workspace::slotSwitchToNextScreen()
746  {
747  slotSwitchToScreen(( activeScreen() + 1 ) % numScreens());
748  }
749 
750 void Workspace::slotWindowToScreen( int i )
751  {
752  Client* c = active_popup_client ? active_popup_client : active_client;
753  if( i >= 0 && i <= numScreens() && c
754  && !c->isDesktop()
755  && !c->isDock()
756  && !c->isTopMenu())
757  {
758  sendClientToScreen( c, i );
759  }
760  }
761 
762 void Workspace::slotWindowToNextScreen()
763  {
764  Client* c = active_popup_client ? active_popup_client : active_client;
765  if( c
766  && !c->isDesktop()
767  && !c->isDock()
768  && !c->isTopMenu())
769  {
770  sendClientToScreen( c, ( c->screen() + 1 ) % numScreens());
771  }
772  }
773 
777 void Workspace::slotWindowMaximize()
778  {
779  Client* c = active_popup_client ? active_popup_client : active_client;
780  if ( c )
781  performWindowOperation( c, Options::MaximizeOp );
782  }
783 
787 void Workspace::slotWindowMaximizeVertical()
788  {
789  Client* c = active_popup_client ? active_popup_client : active_client;
790  if ( c )
791  performWindowOperation( c, Options::VMaximizeOp );
792  }
793 
797 void Workspace::slotWindowMaximizeHorizontal()
798  {
799  Client* c = active_popup_client ? active_popup_client : active_client;
800  if ( c )
801  performWindowOperation( c, Options::HMaximizeOp );
802  }
803 
804 
808 void Workspace::slotWindowMinimize()
809  {
810  Client* c = active_popup_client ? active_popup_client : active_client;
811  performWindowOperation( c, Options::MinimizeOp );
812  }
813 
817 void Workspace::slotWindowShade()
818  {
819  Client* c = active_popup_client ? active_popup_client : active_client;
820  performWindowOperation( c, Options::ShadeOp );
821  }
822 
826 void Workspace::slotWindowRaise()
827  {
828  Client* c = active_popup_client ? active_popup_client : active_client;
829  if ( c )
830  raiseClient( c );
831  }
832 
836 void Workspace::slotWindowLower()
837  {
838  Client* c = active_popup_client ? active_popup_client : active_client;
839  if ( c )
840  lowerClient( c );
841  }
842 
846 void Workspace::slotWindowRaiseOrLower()
847  {
848  Client* c = active_popup_client ? active_popup_client : active_client;
849  if ( c )
850  raiseOrLowerClient( c );
851  }
852 
853 void Workspace::slotWindowOnAllDesktops()
854  {
855  Client* c = active_popup_client ? active_popup_client : active_client;
856  if( c )
857  c->setOnAllDesktops( !c->isOnAllDesktops());
858  }
859 
860 void Workspace::slotWindowFullScreen()
861  {
862  Client* c = active_popup_client ? active_popup_client : active_client;
863  if( c )
864  performWindowOperation( c, Options::FullScreenOp );
865  }
866 
867 void Workspace::slotWindowNoBorder()
868  {
869  Client* c = active_popup_client ? active_popup_client : active_client;
870  if( c )
871  performWindowOperation( c, Options::NoBorderOp );
872  }
873 
874 void Workspace::slotWindowAbove()
875  {
876  Client* c = active_popup_client ? active_popup_client : active_client;
877  if( c )
878  performWindowOperation( c, Options::KeepAboveOp );
879  }
880 
881 void Workspace::slotWindowBelow()
882  {
883  Client* c = active_popup_client ? active_popup_client : active_client;
884  if( c )
885  performWindowOperation( c, Options::KeepBelowOp );
886  }
887 void Workspace::slotSetupWindowShortcut()
888  {
889  Client* c = active_popup_client ? active_popup_client : active_client;
890  if( c )
891  performWindowOperation( c, Options::SetupWindowShortcutOp );
892  }
893 
897 void Workspace::slotWindowToNextDesktop()
898  {
899  windowToNextDesktop( active_popup_client ? active_popup_client : active_client );
900  }
901 
902 void Workspace::windowToNextDesktop( Client* c )
903  {
904  int d = currentDesktop() + 1;
905  if ( d > numberOfDesktops() )
906  d = 1;
907  if (c && !c->isDesktop()
908  && !c->isDock() && !c->isTopMenu())
909  {
910  setClientIsMoving( c );
911  setCurrentDesktop( d );
912  setClientIsMoving( NULL );
913  }
914  }
915 
919 void Workspace::slotWindowToPreviousDesktop()
920  {
921  windowToPreviousDesktop( active_popup_client ? active_popup_client : active_client );
922  }
923 
924 void Workspace::windowToPreviousDesktop( Client* c )
925  {
926  int d = currentDesktop() - 1;
927  if ( d <= 0 )
928  d = numberOfDesktops();
929  if (c && !c->isDesktop()
930  && !c->isDock() && !c->isTopMenu())
931  {
932  setClientIsMoving( c );
933  setCurrentDesktop( d );
934  setClientIsMoving( NULL );
935  }
936  }
937 
938 void Workspace::slotWindowToDesktopRight()
939  {
940  int d = desktopToRight( currentDesktop());
941  if( d == currentDesktop())
942  return;
943  Client* c = active_popup_client ? active_popup_client : active_client;
944  if (c && !c->isDesktop()
945  && !c->isDock() && !c->isTopMenu())
946  {
947  setClientIsMoving( c );
948  setCurrentDesktop( d );
949  setClientIsMoving( NULL );
950  }
951  }
952 
953 void Workspace::slotWindowToDesktopLeft()
954  {
955  int d = desktopToLeft( currentDesktop());
956  if( d == currentDesktop())
957  return;
958  Client* c = active_popup_client ? active_popup_client : active_client;
959  if (c && !c->isDesktop()
960  && !c->isDock() && !c->isTopMenu())
961  {
962  setClientIsMoving( c );
963  setCurrentDesktop( d );
964  setClientIsMoving( NULL );
965  }
966  }
967 
968 void Workspace::slotWindowToDesktopUp()
969  {
970  int d = desktopUp( currentDesktop());
971  if( d == currentDesktop())
972  return;
973  Client* c = active_popup_client ? active_popup_client : active_client;
974  if (c && !c->isDesktop()
975  && !c->isDock() && !c->isTopMenu())
976  {
977  setClientIsMoving( c );
978  setCurrentDesktop( d );
979  setClientIsMoving( NULL );
980  }
981  }
982 
983 void Workspace::slotWindowToDesktopDown()
984  {
985  int d = desktopDown( currentDesktop());
986  if( d == currentDesktop())
987  return;
988  Client* c = active_popup_client ? active_popup_client : active_client;
989  if (c && !c->isDesktop()
990  && !c->isDock() && !c->isTopMenu())
991  {
992  setClientIsMoving( c );
993  setCurrentDesktop( d );
994  setClientIsMoving( NULL );
995  }
996  }
997 
998 
1002 void Workspace::slotKillWindow()
1003  {
1004  KillWindow kill( this );
1005  kill.start();
1006  }
1007 
1011 void Workspace::slotSuspendWindow()
1012  {
1013  active_popup_client->suspendWindow();
1014  }
1015 
1019 void Workspace::slotResumeWindow()
1020  {
1021  active_popup_client->resumeWindow();
1022  }
1023 
1029 void Workspace::slotSendToDesktop( int desk )
1030  {
1031  if ( !active_popup_client )
1032  return;
1033  if ( desk == 0 )
1034  { // the 'on_all_desktops' menu entry
1035  active_popup_client->setOnAllDesktops( !active_popup_client->isOnAllDesktops());
1036  return;
1037  }
1038 
1039  sendClientToDesktop( active_popup_client, desk, false );
1040 
1041  }
1042 
1046 void Workspace::slotWindowOperations()
1047  {
1048  if ( !active_client )
1049  return;
1050  TQPoint pos = active_client->pos() + active_client->clientPos();
1051  showWindowMenu( pos.x(), pos.y(), active_client );
1052  }
1053 
1054 void Workspace::showWindowMenu( const TQRect &pos, Client* cl )
1055  {
1056  if (!kapp->authorizeTDEAction("twin_rmb"))
1057  return;
1058  if( !cl )
1059  return;
1060  if( active_popup_client != NULL ) // recursion
1061  return;
1062  if ( cl->isDesktop()
1063  || cl->isDock()
1064  || cl->isTopMenu()
1065  || cl->isModalSystemNotification())
1066  return;
1067 
1068  active_popup_client = cl;
1069  TQPopupMenu* p = clientPopup();
1070  active_popup = p;
1071  int x = pos.left();
1072  int y = pos.bottom();
1073  if (y == pos.top())
1074  p->exec( TQPoint( x, y ) );
1075  else
1076  {
1077  TQRect area = clientArea(ScreenArea, TQPoint(x, y), currentDesktop());
1078  clientPopupAboutToShow(); // needed for sizeHint() to be correct :-/
1079  int popupHeight = p->sizeHint().height();
1080  if (y + popupHeight < area.height())
1081  p->exec( TQPoint( x, y ) );
1082  else
1083  p->exec( TQPoint( x, pos.top() - popupHeight ) );
1084  }
1085  // active popup may be already changed (e.g. the window shortcut dialog)
1086  if( active_popup == p )
1087  closeActivePopup();
1088  }
1089 
1093 void Workspace::slotWindowClose()
1094  {
1095  if ( tab_box->isVisible())
1096  return;
1097  Client* c = active_popup_client ? active_popup_client : active_client;
1098  performWindowOperation( c, Options::CloseOp );
1099  }
1100 
1104 void Workspace::slotWindowMove()
1105  {
1106  Client* c = active_popup_client ? active_popup_client : active_client;
1107  performWindowOperation( c, Options::UnrestrictedMoveOp );
1108  }
1109 
1113 void Workspace::slotWindowResize()
1114  {
1115  Client* c = active_popup_client ? active_popup_client : active_client;
1116  performWindowOperation( c, Options::UnrestrictedResizeOp );
1117  }
1118 
1119 void Client::setShortcut( const TQString& _cut )
1120  {
1121  TQString cut = rules()->checkShortcut( _cut );
1122  if( cut.isEmpty())
1123  return setShortcutInternal( TDEShortcut());
1124 // Format:
1125 // base+(abcdef)<space>base+(abcdef)
1126 // E.g. Alt+Ctrl+(ABCDEF) Win+X,Win+(ABCDEF)
1127  if( !cut.contains( '(' ) && !cut.contains( ')' ) && !cut.contains( ' ' ))
1128  {
1129  if( workspace()->shortcutAvailable( TDEShortcut( cut ), this ))
1130  setShortcutInternal( TDEShortcut( cut ));
1131  else
1132  setShortcutInternal( TDEShortcut());
1133  return;
1134  }
1135  TQValueList< TDEShortcut > keys;
1136  TQStringList groups = TQStringList::split( ' ', cut );
1137  for( TQStringList::ConstIterator it = groups.begin();
1138  it != groups.end();
1139  ++it )
1140  {
1141  TQRegExp reg( "(.*\\+)\\((.*)\\)" );
1142  if( reg.search( *it ) > -1 )
1143  {
1144  TQString base = reg.cap( 1 );
1145  TQString list = reg.cap( 2 );
1146  for( unsigned int i = 0;
1147  i < list.length();
1148  ++i )
1149  {
1150  TDEShortcut c( base + list[ i ] );
1151  if( !c.isNull())
1152  keys.append( c );
1153  }
1154  }
1155  }
1156  for( TQValueList< TDEShortcut >::ConstIterator it = keys.begin();
1157  it != keys.end();
1158  ++it )
1159  {
1160  if( _shortcut == *it ) // current one is in the list
1161  return;
1162  }
1163  for( TQValueList< TDEShortcut >::ConstIterator it = keys.begin();
1164  it != keys.end();
1165  ++it )
1166  {
1167  if( workspace()->shortcutAvailable( *it, this ))
1168  {
1169  setShortcutInternal( *it );
1170  return;
1171  }
1172  }
1173  setShortcutInternal( TDEShortcut());
1174  }
1175 
1176 void Client::setShortcutInternal( const TDEShortcut& cut )
1177  {
1178  if( _shortcut == cut )
1179  return;
1180  _shortcut = cut;
1181  updateCaption();
1182  workspace()->clientShortcutUpdated( this );
1183  }
1184 
1185 bool Workspace::shortcutAvailable( const TDEShortcut& cut, Client* ignore ) const
1186  {
1187  // TODO check global shortcuts etc.
1188  for( ClientList::ConstIterator it = clients.begin();
1189  it != clients.end();
1190  ++it )
1191  {
1192  if( (*it) != ignore && (*it)->shortcut() == cut )
1193  return false;
1194  }
1195  return true;
1196  }
1197 
1198 } // namespace

twin

Skip menu "twin"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members

twin

Skip menu "twin"
  • kate
  • libkonq
  • twin
  •   lib
Generated for twin by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.