• 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
5Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
6Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
7
8You can Freely distribute this program under the GNU General Public
9License. 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
40namespace KWinInternal
41{
42
43//****************************************
44// Workspace
45//****************************************
46
47TQPopupMenu* Workspace::clientPopup()
48 {
49 if ( !popup )
50 {
51 popup = new TQPopupMenu;
52 popup->setCheckable( TRUE );
53 popup->setFont(TDEGlobalSettings::menuFont());
54 connect( popup, TQ_SIGNAL( aboutToShow() ), this, TQ_SLOT( clientPopupAboutToShow() ) );
55 connect( popup, TQ_SIGNAL( activated(int) ), this, TQ_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, TQ_SIGNAL( activated(int) ), this, TQ_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, TQt::Horizontal, transBox, "transSlider");
87 TQToolTip::add(transSlider, i18n("Slide this to set the window's opacity"));
88 connect(transButton, TQ_SIGNAL(clicked()), TQ_SLOT(resetClientOpacity()));
89 connect(transButton, TQ_SIGNAL(clicked()), trans_popup, TQ_SLOT(hide()));
90 connect(transSlider, TQ_SIGNAL(valueChanged(int)), TQ_SLOT(setTransButtonText(int)));
91 connect(transSlider, TQ_SIGNAL(valueChanged(int)), this, TQ_SLOT(setPopupClientOpacity(int)));
92// connect(transSlider, TQ_SIGNAL(sliderReleased()), trans_popup, TQ_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, TQ_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)
118void 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
125void 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
138void 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
152void 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
196void 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, TQ_SIGNAL( activated(int) ),
205 this, TQ_SLOT( slotSendToDesktop(int) ) );
206 connect( desk_popup, TQ_SIGNAL( aboutToShow() ),
207 this, TQ_SLOT( desktopPopupAboutToShow() ) );
208
209 popup->insertItem(i18n("To &Desktop"), desk_popup, -1, desk_popup_index );
210 }
211
216void 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
246void Workspace::closeActivePopup()
247 {
248 if( active_popup )
249 {
250 active_popup->close();
251 active_popup = NULL;
252 active_popup_client = NULL;
253 }
254 }
255
259void 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
271void 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
294void 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, TQ_SIGNAL( dialogDone( bool )), TQ_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
316void 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
331void 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, TQ_SLOT( shortcutActivated()));
340 client_keys->setActionEnabled( key, true );
341 }
342 client_keys->updateConnections();
343 }
344
345void 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
369void 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
473bool 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
650void Workspace::showWindowMenuAt( unsigned long window, int x, int y )
651 {
652 Client *client;
653 if ((client = findClient(WindowMatchPredicate((WId)window))))
654 showWindowMenu( x, y, client );
655 }
656
657void Workspace::showWindowMenu( unsigned long window )
658 {
659 Client *client;
660 if ((client = findClient(WindowMatchPredicate((WId)window))))
661 {
662 TQPoint pos = client->pos() + client->clientPos();
663 showWindowMenu( pos, client );
664 }
665 }
666
667void Workspace::tileWindowToBorder(unsigned long w1, int location) {
668 if (location < ActiveTop || location >= ACTIVE_BORDER_COUNT) return;
669
670 Client *c1 = findClient(WindowMatchPredicate((WId)w1));
671 if (!c1) return;
672
673 c1->tileToBorder((ActiveBorder)location);
674}
675
676void Workspace::tileTwoWindowsHorizontally(unsigned long w1, unsigned long w2) {
677 if (w1 == w2) return;
678
679 Client *c1 = findClient(WindowMatchPredicate((WId)w1));
680 Client *c2 = findClient(WindowMatchPredicate((WId)w2));
681 if (!c1 || !c2) return;
682
683 c1->tileToBorder(ActiveTop);
684 c2->tileToBorder(ActiveBottom);
685}
686
687void Workspace::tileTwoWindowsVertically(unsigned long w1, unsigned long w2) {
688 if (w1 == w2) return;
689
690 Client *c1 = findClient(WindowMatchPredicate((WId)w1));
691 Client *c2 = findClient(WindowMatchPredicate((WId)w2));
692 if (!c1 || !c2) return;
693
694 c1->tileToBorder(ActiveLeft);
695 c2->tileToBorder(ActiveRight);
696}
697
698void Workspace::tileFourWindowsInGrid(unsigned long w1, unsigned long w2, unsigned long w3, unsigned long w4) {
699 if (w1 == w2 || w1 == w3 || w1 == w4 || w2 == w3 || w2 == w4 || w3 == w4)
700 return;
701
702 Client *c1 = findClient(WindowMatchPredicate((WId)w1));
703 Client *c2 = findClient(WindowMatchPredicate((WId)w2));
704 Client *c3 = findClient(WindowMatchPredicate((WId)w3));
705 Client *c4 = findClient(WindowMatchPredicate((WId)w4));
706 if (!c1 || !c2 || !c3 || !c4) return;
707
708 c1->tileToBorder(ActiveTopLeft);
709 c2->tileToBorder(ActiveTopRight);
710 c3->tileToBorder(ActiveBottomLeft);
711 c4->tileToBorder(ActiveBottomRight);
712}
713
714void Workspace::slotActivateAttentionWindow()
715 {
716 if( attention_chain.count() > 0 )
717 activateClient( attention_chain.first());
718 }
719
720void Workspace::slotSwitchDesktopNext()
721 {
722 int d = currentDesktop() + 1;
723 if ( d > numberOfDesktops() )
724 {
725 if ( options->rollOverDesktops )
726 {
727 d = 1;
728 }
729 else
730 {
731 return;
732 }
733 }
734 setCurrentDesktop(d);
735 }
736
737void Workspace::slotSwitchDesktopPrevious()
738 {
739 int d = currentDesktop() - 1;
740 if ( d <= 0 )
741 {
742 if ( options->rollOverDesktops )
743 d = numberOfDesktops();
744 else
745 return;
746 }
747 setCurrentDesktop(d);
748 }
749
750void Workspace::slotSwitchDesktopRight()
751 {
752 int desktop = desktopToRight( currentDesktop());
753 if( desktop == currentDesktop())
754 return;
755 setCurrentDesktop( desktop );
756 }
757
758void Workspace::slotSwitchDesktopLeft()
759 {
760 int desktop = desktopToLeft( currentDesktop());
761 if( desktop == currentDesktop())
762 return;
763 setCurrentDesktop( desktop );
764 }
765
766void Workspace::slotSwitchDesktopUp()
767 {
768 int desktop = desktopUp( currentDesktop());
769 if( desktop == currentDesktop())
770 return;
771 setCurrentDesktop( desktop );
772 }
773
774void Workspace::slotSwitchDesktopDown()
775 {
776 int desktop = desktopDown( currentDesktop());
777 if( desktop == currentDesktop())
778 return;
779 setCurrentDesktop( desktop );
780 }
781
782void Workspace::slotSwitchToDesktop( int i )
783 {
784 setCurrentDesktop( i );
785 }
786
787
788void Workspace::slotWindowToDesktop( int i )
789 {
790 Client* c = active_popup_client ? active_popup_client : active_client;
791 if( i >= 1 && i <= numberOfDesktops() && c
792 && !c->isDesktop()
793 && !c->isDock()
794 && !c->isTopMenu())
795 sendClientToDesktop( c, i, true );
796 }
797
798void Workspace::slotSwitchToScreen( int i )
799 {
800 setCurrentScreen( i );
801 }
802
803void Workspace::slotSwitchToNextScreen()
804 {
805 slotSwitchToScreen(( activeScreen() + 1 ) % numScreens());
806 }
807
808void Workspace::slotWindowToScreen( int i )
809 {
810 Client* c = active_popup_client ? active_popup_client : active_client;
811 if( i >= 0 && i <= numScreens() && c
812 && !c->isDesktop()
813 && !c->isDock()
814 && !c->isTopMenu())
815 {
816 sendClientToScreen( c, i );
817 }
818 }
819
820void Workspace::slotWindowToNextScreen()
821 {
822 Client* c = active_popup_client ? active_popup_client : active_client;
823 if( c
824 && !c->isDesktop()
825 && !c->isDock()
826 && !c->isTopMenu())
827 {
828 sendClientToScreen( c, ( c->screen() + 1 ) % numScreens());
829 }
830 }
831
835void Workspace::slotWindowMaximize()
836 {
837 Client* c = active_popup_client ? active_popup_client : active_client;
838 if ( c )
839 performWindowOperation( c, Options::MaximizeOp );
840 }
841
845void Workspace::slotWindowMaximizeVertical()
846 {
847 Client* c = active_popup_client ? active_popup_client : active_client;
848 if ( c )
849 performWindowOperation( c, Options::VMaximizeOp );
850 }
851
855void Workspace::slotWindowMaximizeHorizontal()
856 {
857 Client* c = active_popup_client ? active_popup_client : active_client;
858 if ( c )
859 performWindowOperation( c, Options::HMaximizeOp );
860 }
861
862
866void Workspace::slotWindowMinimize()
867 {
868 Client* c = active_popup_client ? active_popup_client : active_client;
869 performWindowOperation( c, Options::MinimizeOp );
870 }
871
875void Workspace::slotWindowShade()
876 {
877 Client* c = active_popup_client ? active_popup_client : active_client;
878 performWindowOperation( c, Options::ShadeOp );
879 }
880
884void Workspace::slotWindowRaise()
885 {
886 Client* c = active_popup_client ? active_popup_client : active_client;
887 if ( c )
888 raiseClient( c );
889 }
890
894void Workspace::slotWindowLower()
895 {
896 Client* c = active_popup_client ? active_popup_client : active_client;
897 if ( c )
898 lowerClient( c );
899 }
900
904void Workspace::slotWindowRaiseOrLower()
905 {
906 Client* c = active_popup_client ? active_popup_client : active_client;
907 if ( c )
908 raiseOrLowerClient( c );
909 }
910
911void Workspace::slotWindowOnAllDesktops()
912 {
913 Client* c = active_popup_client ? active_popup_client : active_client;
914 if( c )
915 c->setOnAllDesktops( !c->isOnAllDesktops());
916 }
917
918void Workspace::slotWindowFullScreen()
919 {
920 Client* c = active_popup_client ? active_popup_client : active_client;
921 if( c )
922 performWindowOperation( c, Options::FullScreenOp );
923 }
924
925void Workspace::slotWindowNoBorder()
926 {
927 Client* c = active_popup_client ? active_popup_client : active_client;
928 if( c )
929 performWindowOperation( c, Options::NoBorderOp );
930 }
931
932void Workspace::slotWindowAbove()
933 {
934 Client* c = active_popup_client ? active_popup_client : active_client;
935 if( c )
936 performWindowOperation( c, Options::KeepAboveOp );
937 }
938
939void Workspace::slotWindowBelow()
940 {
941 Client* c = active_popup_client ? active_popup_client : active_client;
942 if( c )
943 performWindowOperation( c, Options::KeepBelowOp );
944 }
945void Workspace::slotSetupWindowShortcut()
946 {
947 Client* c = active_popup_client ? active_popup_client : active_client;
948 if( c )
949 performWindowOperation( c, Options::SetupWindowShortcutOp );
950 }
951
955void Workspace::slotWindowToNextDesktop()
956 {
957 windowToNextDesktop( active_popup_client ? active_popup_client : active_client );
958 }
959
960void Workspace::windowToNextDesktop( Client* c )
961 {
962 int d = currentDesktop() + 1;
963 if ( d > numberOfDesktops() )
964 d = 1;
965 if (c && !c->isDesktop()
966 && !c->isDock() && !c->isTopMenu())
967 {
968 setClientIsMoving( c );
969 setCurrentDesktop( d );
970 setClientIsMoving( NULL );
971 }
972 }
973
977void Workspace::slotWindowToPreviousDesktop()
978 {
979 windowToPreviousDesktop( active_popup_client ? active_popup_client : active_client );
980 }
981
982void Workspace::windowToPreviousDesktop( Client* c )
983 {
984 int d = currentDesktop() - 1;
985 if ( d <= 0 )
986 d = numberOfDesktops();
987 if (c && !c->isDesktop()
988 && !c->isDock() && !c->isTopMenu())
989 {
990 setClientIsMoving( c );
991 setCurrentDesktop( d );
992 setClientIsMoving( NULL );
993 }
994 }
995
996void Workspace::slotWindowToDesktopRight()
997 {
998 int d = desktopToRight( currentDesktop());
999 if( d == currentDesktop())
1000 return;
1001 Client* c = active_popup_client ? active_popup_client : active_client;
1002 if (c && !c->isDesktop()
1003 && !c->isDock() && !c->isTopMenu())
1004 {
1005 setClientIsMoving( c );
1006 setCurrentDesktop( d );
1007 setClientIsMoving( NULL );
1008 }
1009 }
1010
1011void Workspace::slotWindowToDesktopLeft()
1012 {
1013 int d = desktopToLeft( currentDesktop());
1014 if( d == currentDesktop())
1015 return;
1016 Client* c = active_popup_client ? active_popup_client : active_client;
1017 if (c && !c->isDesktop()
1018 && !c->isDock() && !c->isTopMenu())
1019 {
1020 setClientIsMoving( c );
1021 setCurrentDesktop( d );
1022 setClientIsMoving( NULL );
1023 }
1024 }
1025
1026void Workspace::slotWindowToDesktopUp()
1027 {
1028 int d = desktopUp( currentDesktop());
1029 if( d == currentDesktop())
1030 return;
1031 Client* c = active_popup_client ? active_popup_client : active_client;
1032 if (c && !c->isDesktop()
1033 && !c->isDock() && !c->isTopMenu())
1034 {
1035 setClientIsMoving( c );
1036 setCurrentDesktop( d );
1037 setClientIsMoving( NULL );
1038 }
1039 }
1040
1041void Workspace::slotWindowToDesktopDown()
1042 {
1043 int d = desktopDown( currentDesktop());
1044 if( d == currentDesktop())
1045 return;
1046 Client* c = active_popup_client ? active_popup_client : active_client;
1047 if (c && !c->isDesktop()
1048 && !c->isDock() && !c->isTopMenu())
1049 {
1050 setClientIsMoving( c );
1051 setCurrentDesktop( d );
1052 setClientIsMoving( NULL );
1053 }
1054 }
1055
1056
1060void Workspace::slotKillWindow()
1061 {
1062 KillWindow kill( this );
1063 kill.start();
1064 }
1065
1069void Workspace::slotSuspendWindow()
1070 {
1071 active_popup_client->suspendWindow();
1072 }
1073
1077void Workspace::slotResumeWindow()
1078 {
1079 active_popup_client->resumeWindow();
1080 }
1081
1087void Workspace::slotSendToDesktop( int desk )
1088 {
1089 if ( !active_popup_client )
1090 return;
1091 if ( desk == 0 )
1092 { // the 'on_all_desktops' menu entry
1093 active_popup_client->setOnAllDesktops( !active_popup_client->isOnAllDesktops());
1094 return;
1095 }
1096
1097 sendClientToDesktop( active_popup_client, desk, false );
1098
1099 }
1100
1104void Workspace::slotWindowOperations()
1105 {
1106 if ( !active_client )
1107 return;
1108 TQPoint pos = active_client->pos() + active_client->clientPos();
1109 showWindowMenu( pos.x(), pos.y(), active_client );
1110 }
1111
1112void Workspace::showWindowMenu( const TQRect &pos, Client* cl )
1113 {
1114 if (!kapp->authorizeTDEAction("twin_rmb"))
1115 return;
1116 if( !cl )
1117 return;
1118 if( active_popup_client != NULL ) // recursion
1119 return;
1120 if ( cl->isDesktop()
1121 || cl->isDock()
1122 || cl->isTopMenu()
1123 || cl->isModalSystemNotification())
1124 return;
1125
1126 active_popup_client = cl;
1127 TQPopupMenu* p = clientPopup();
1128 active_popup = p;
1129 int x = pos.left();
1130 int y = pos.bottom();
1131 clientPopupAboutToShow(); // needed for sizeHint() to be correct :-/
1132
1133 TQRect area = clientArea(ScreenArea, TQPoint(x, y), currentDesktop());
1134 TQSize hint = p->sizeHint();
1135 if (x < 0) x = area.right() - hint.width() + x;
1136 if (y < 0) y = area.bottom() - hint.height() + y;
1137
1138 if (pos.bottom() == pos.top())
1139 p->exec( TQPoint( x, y ) );
1140 else
1141 {
1142 if (y + hint.height() < area.height())
1143 p->exec( TQPoint( x, y ) );
1144 else
1145 p->exec( TQPoint( x, pos.top() - hint.height() ) );
1146 }
1147 // active popup may be already changed (e.g. the window shortcut dialog)
1148 if( active_popup == p )
1149 closeActivePopup();
1150 }
1151
1155void Workspace::slotWindowClose()
1156 {
1157 if ( tab_box->isVisible())
1158 return;
1159 Client* c = active_popup_client ? active_popup_client : active_client;
1160 performWindowOperation( c, Options::CloseOp );
1161 }
1162
1166void Workspace::slotWindowMove()
1167 {
1168 Client* c = active_popup_client ? active_popup_client : active_client;
1169 performWindowOperation( c, Options::UnrestrictedMoveOp );
1170 }
1171
1175void Workspace::slotWindowResize()
1176 {
1177 Client* c = active_popup_client ? active_popup_client : active_client;
1178 performWindowOperation( c, Options::UnrestrictedResizeOp );
1179 }
1180
1181void Client::setShortcut( const TQString& _cut )
1182 {
1183 TQString cut = rules()->checkShortcut( _cut );
1184 if( cut.isEmpty())
1185 return setShortcutInternal( TDEShortcut());
1186// Format:
1187// base+(abcdef)<space>base+(abcdef)
1188// E.g. Alt+Ctrl+(ABCDEF) Win+X,Win+(ABCDEF)
1189 if( !cut.contains( '(' ) && !cut.contains( ')' ) && !cut.contains( ' ' ))
1190 {
1191 if( workspace()->shortcutAvailable( TDEShortcut( cut ), this ))
1192 setShortcutInternal( TDEShortcut( cut ));
1193 else
1194 setShortcutInternal( TDEShortcut());
1195 return;
1196 }
1197 TQValueList< TDEShortcut > keys;
1198 TQStringList groups = TQStringList::split( ' ', cut );
1199 for( TQStringList::ConstIterator it = groups.begin();
1200 it != groups.end();
1201 ++it )
1202 {
1203 TQRegExp reg( "(.*\\+)\\((.*)\\)" );
1204 if( reg.search( *it ) > -1 )
1205 {
1206 TQString base = reg.cap( 1 );
1207 TQString list = reg.cap( 2 );
1208 for( unsigned int i = 0;
1209 i < list.length();
1210 ++i )
1211 {
1212 TDEShortcut c( base + list[ i ] );
1213 if( !c.isNull())
1214 keys.append( c );
1215 }
1216 }
1217 }
1218 for( TQValueList< TDEShortcut >::ConstIterator it = keys.begin();
1219 it != keys.end();
1220 ++it )
1221 {
1222 if( _shortcut == *it ) // current one is in the list
1223 return;
1224 }
1225 for( TQValueList< TDEShortcut >::ConstIterator it = keys.begin();
1226 it != keys.end();
1227 ++it )
1228 {
1229 if( workspace()->shortcutAvailable( *it, this ))
1230 {
1231 setShortcutInternal( *it );
1232 return;
1233 }
1234 }
1235 setShortcutInternal( TDEShortcut());
1236 }
1237
1238void Client::setShortcutInternal( const TDEShortcut& cut )
1239 {
1240 if( _shortcut == cut )
1241 return;
1242 _shortcut = cut;
1243 updateCaption();
1244 workspace()->clientShortcutUpdated( this );
1245 }
1246
1247bool Workspace::shortcutAvailable( const TDEShortcut& cut, Client* ignore ) const
1248 {
1249 // TODO check global shortcuts etc.
1250 for( ClientList::ConstIterator it = clients.begin();
1251 it != clients.end();
1252 ++it )
1253 {
1254 if( (*it) != ignore && (*it)->shortcut() == cut )
1255 return false;
1256 }
1257 return true;
1258 }
1259
1260} // 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:473
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.8
This website is maintained by Timothy Pearson.