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

kwin

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

kwin

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

kwin

Skip menu "kwin"
  • kate
  • kwin
  •   lib
  • libkonq
Generated for kwin by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |