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

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.9.1
This website is maintained by Timothy Pearson.