• 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 <tdeglobalaccel.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::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
74TQPopupMenu* 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(setPopupClientTransparancy(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 !tdeApp->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)
146void Workspace::setPopupClientTransparancy(int value)
147 {
148 active_popup_client->setCustomOpacityFlag(true);
149 int opacityPercent = 100 - value;
150 active_popup_client->setOpacity(percentToUint(opacityPercent));
151 }
152
153void 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
166void 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
180void 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
225void 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
245void 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
275void Workspace::closeActivePopup()
276 {
277 if( active_popup )
278 {
279 active_popup->close();
280 active_popup = NULL;
281 active_popup_client = NULL;
282 }
283 }
284
288void 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
300void 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
323void 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
345void 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
360void 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
374void 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
398void 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
502bool 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_ < Opacity::Opaque)
652 {
653 if (opacity_ < Opacity::Opaque - Opacity::MouseStep)
654 {
655 custom_opacity = true;
656 setOpacity(opacity_ + Opacity::MouseStep);
657 }
658 else
659 {
660 if (defaultOpacity() == Opacity::Opaque)
661 custom_opacity = false;
662 setOpacity(Opacity::Opaque);
663 }
664 }
665 break;
666 case Options::MouseOpacityLess:
667 if (opacity_ > Opacity::Transparent)
668 {
669 custom_opacity = true;
670 setOpacity((opacity_ > Opacity::MouseStep) ? opacity_ - Opacity::MouseStep : Opacity::Transparent);
671 }
672 break;
673 case Options::MouseNothing:
674 replay = true;
675 break;
676 }
677 return replay;
678 }
679
680void Workspace::showWindowMenuAt( unsigned long window, int x, int y )
681 {
682 Client *client;
683 if ((client = findClient(WindowMatchPredicate((WId)window))))
684 showWindowMenu( x, y, client );
685 }
686
687void Workspace::showWindowMenu( unsigned long window )
688 {
689 Client *client;
690 if ((client = findClient(WindowMatchPredicate((WId)window))))
691 {
692 TQPoint pos = client->pos() + client->clientPos();
693 showWindowMenu( pos, client );
694 }
695 }
696
697void Workspace::tileCurrentWindowToBorder(int position)
698{
699 Client *c = active_popup_client ? active_popup_client : active_client;
700 if (!c) return;
701
702 c->tileToBorder((ActiveBorder)position);
703}
704
705void Workspace::tileWindowToBorder(unsigned long w1, int location) {
706 if (location < ActiveTop || location >= ACTIVE_BORDER_COUNT) return;
707
708 Client *c1 = findClient(WindowMatchPredicate((WId)w1));
709 if (!c1) return;
710
711 c1->tileToBorder((ActiveBorder)location);
712}
713
714void Workspace::tileTwoWindowsHorizontally(unsigned long w1, unsigned long w2) {
715 if (w1 == w2) return;
716
717 Client *c1 = findClient(WindowMatchPredicate((WId)w1));
718 Client *c2 = findClient(WindowMatchPredicate((WId)w2));
719 if (!c1 || !c2) return;
720
721 c1->tileToBorder(ActiveTop);
722 c2->tileToBorder(ActiveBottom);
723}
724
725void Workspace::tileTwoWindowsVertically(unsigned long w1, unsigned long w2) {
726 if (w1 == w2) return;
727
728 Client *c1 = findClient(WindowMatchPredicate((WId)w1));
729 Client *c2 = findClient(WindowMatchPredicate((WId)w2));
730 if (!c1 || !c2) return;
731
732 c1->tileToBorder(ActiveLeft);
733 c2->tileToBorder(ActiveRight);
734}
735
736void Workspace::tileFourWindowsInGrid(unsigned long w1, unsigned long w2, unsigned long w3, unsigned long w4) {
737 if (w1 == w2 || w1 == w3 || w1 == w4 || w2 == w3 || w2 == w4 || w3 == w4)
738 return;
739
740 Client *c1 = findClient(WindowMatchPredicate((WId)w1));
741 Client *c2 = findClient(WindowMatchPredicate((WId)w2));
742 Client *c3 = findClient(WindowMatchPredicate((WId)w3));
743 Client *c4 = findClient(WindowMatchPredicate((WId)w4));
744 if (!c1 || !c2 || !c3 || !c4) return;
745
746 c1->tileToBorder(ActiveTopLeft);
747 c2->tileToBorder(ActiveTopRight);
748 c3->tileToBorder(ActiveBottomLeft);
749 c4->tileToBorder(ActiveBottomRight);
750}
751
752void Workspace::slotActivateAttentionWindow()
753 {
754 if( attention_chain.count() > 0 )
755 activateClient( attention_chain.first());
756 }
757
758void Workspace::slotSwitchDesktopNext()
759 {
760 int d = currentDesktop() + 1;
761 if ( d > numberOfDesktops() )
762 {
763 if ( options->rollOverDesktops )
764 {
765 d = 1;
766 }
767 else
768 {
769 return;
770 }
771 }
772 setCurrentDesktop(d);
773 }
774
775void Workspace::slotSwitchDesktopPrevious()
776 {
777 int d = currentDesktop() - 1;
778 if ( d <= 0 )
779 {
780 if ( options->rollOverDesktops )
781 d = numberOfDesktops();
782 else
783 return;
784 }
785 setCurrentDesktop(d);
786 }
787
788void Workspace::slotSwitchDesktopRight()
789 {
790 int desktop = desktopToRight( currentDesktop());
791 if( desktop == currentDesktop())
792 return;
793 setCurrentDesktop( desktop );
794 }
795
796void Workspace::slotSwitchDesktopLeft()
797 {
798 int desktop = desktopToLeft( currentDesktop());
799 if( desktop == currentDesktop())
800 return;
801 setCurrentDesktop( desktop );
802 }
803
804void Workspace::slotSwitchDesktopUp()
805 {
806 int desktop = desktopUp( currentDesktop());
807 if( desktop == currentDesktop())
808 return;
809 setCurrentDesktop( desktop );
810 }
811
812void Workspace::slotSwitchDesktopDown()
813 {
814 int desktop = desktopDown( currentDesktop());
815 if( desktop == currentDesktop())
816 return;
817 setCurrentDesktop( desktop );
818 }
819
820void Workspace::slotSwitchToDesktop( int i )
821 {
822 setCurrentDesktop( i );
823 }
824
825
826void Workspace::slotWindowToDesktop( int i )
827 {
828 Client* c = active_popup_client ? active_popup_client : active_client;
829 if( i >= 1 && i <= numberOfDesktops() && c
830 && !c->isDesktop()
831 && !c->isDock()
832 && !c->isTopMenu())
833 sendClientToDesktop( c, i, true );
834 }
835
836void Workspace::slotSwitchToScreen( int i )
837 {
838 setCurrentScreen( i );
839 }
840
841void Workspace::slotSwitchToNextScreen()
842 {
843 slotSwitchToScreen(( activeScreen() + 1 ) % numScreens());
844 }
845
846void Workspace::slotWindowToScreen( int i )
847 {
848 Client* c = active_popup_client ? active_popup_client : active_client;
849 if( i >= 0 && i <= numScreens() && c
850 && !c->isDesktop()
851 && !c->isDock()
852 && !c->isTopMenu())
853 {
854 sendClientToScreen( c, i );
855 }
856 }
857
858void Workspace::slotWindowToNextScreen()
859 {
860 Client* c = active_popup_client ? active_popup_client : active_client;
861 if( c
862 && !c->isDesktop()
863 && !c->isDock()
864 && !c->isTopMenu())
865 {
866 sendClientToScreen( c, ( c->screen() + 1 ) % numScreens());
867 }
868 }
869
873void Workspace::slotWindowMaximize()
874 {
875 Client* c = active_popup_client ? active_popup_client : active_client;
876 if ( c )
877 performWindowOperation( c, Options::MaximizeOp );
878 }
879
883void Workspace::slotWindowMaximizeVertical()
884 {
885 Client* c = active_popup_client ? active_popup_client : active_client;
886 if ( c )
887 performWindowOperation( c, Options::VMaximizeOp );
888 }
889
893void Workspace::slotWindowMaximizeHorizontal()
894 {
895 Client* c = active_popup_client ? active_popup_client : active_client;
896 if ( c )
897 performWindowOperation( c, Options::HMaximizeOp );
898 }
899
900
904void Workspace::slotWindowMinimize()
905 {
906 Client* c = active_popup_client ? active_popup_client : active_client;
907 performWindowOperation( c, Options::MinimizeOp );
908 }
909
913void Workspace::slotWindowShade()
914 {
915 Client* c = active_popup_client ? active_popup_client : active_client;
916 performWindowOperation( c, Options::ShadeOp );
917 }
918
922void Workspace::slotWindowRaise()
923 {
924 Client* c = active_popup_client ? active_popup_client : active_client;
925 if ( c )
926 raiseClient( c );
927 }
928
932void Workspace::slotWindowLower()
933 {
934 Client* c = active_popup_client ? active_popup_client : active_client;
935 if ( c )
936 lowerClient( c );
937 }
938
942void Workspace::slotWindowRaiseOrLower()
943 {
944 Client* c = active_popup_client ? active_popup_client : active_client;
945 if ( c )
946 raiseOrLowerClient( c );
947 }
948
949void Workspace::slotWindowOnAllDesktops()
950 {
951 Client* c = active_popup_client ? active_popup_client : active_client;
952 if( c )
953 c->setOnAllDesktops( !c->isOnAllDesktops());
954 }
955
956void Workspace::slotWindowFullScreen()
957 {
958 Client* c = active_popup_client ? active_popup_client : active_client;
959 if( c )
960 performWindowOperation( c, Options::FullScreenOp );
961 }
962
963void Workspace::slotWindowNoBorder()
964 {
965 Client* c = active_popup_client ? active_popup_client : active_client;
966 if( c )
967 performWindowOperation( c, Options::NoBorderOp );
968 }
969
970void Workspace::slotWindowAbove()
971 {
972 Client* c = active_popup_client ? active_popup_client : active_client;
973 if( c )
974 performWindowOperation( c, Options::KeepAboveOp );
975 }
976
977void Workspace::slotWindowBelow()
978 {
979 Client* c = active_popup_client ? active_popup_client : active_client;
980 if( c )
981 performWindowOperation( c, Options::KeepBelowOp );
982 }
983void Workspace::slotSetupWindowShortcut()
984 {
985 Client* c = active_popup_client ? active_popup_client : active_client;
986 if( c )
987 performWindowOperation( c, Options::SetupWindowShortcutOp );
988 }
989
993void Workspace::slotWindowToNextDesktop()
994 {
995 windowToNextDesktop( active_popup_client ? active_popup_client : active_client );
996 }
997
998void Workspace::windowToNextDesktop( Client* c )
999 {
1000 int d = currentDesktop() + 1;
1001 if ( d > numberOfDesktops() )
1002 d = 1;
1003 if (c && !c->isDesktop()
1004 && !c->isDock() && !c->isTopMenu())
1005 {
1006 setClientIsMoving( c );
1007 setCurrentDesktop( d );
1008 setClientIsMoving( NULL );
1009 }
1010 }
1011
1015void Workspace::slotWindowToPreviousDesktop()
1016 {
1017 windowToPreviousDesktop( active_popup_client ? active_popup_client : active_client );
1018 }
1019
1020void Workspace::windowToPreviousDesktop( Client* c )
1021 {
1022 int d = currentDesktop() - 1;
1023 if ( d <= 0 )
1024 d = numberOfDesktops();
1025 if (c && !c->isDesktop()
1026 && !c->isDock() && !c->isTopMenu())
1027 {
1028 setClientIsMoving( c );
1029 setCurrentDesktop( d );
1030 setClientIsMoving( NULL );
1031 }
1032 }
1033
1034void Workspace::slotWindowToDesktopRight()
1035 {
1036 int d = desktopToRight( currentDesktop());
1037 if( d == currentDesktop())
1038 return;
1039 Client* c = active_popup_client ? active_popup_client : active_client;
1040 if (c && !c->isDesktop()
1041 && !c->isDock() && !c->isTopMenu())
1042 {
1043 setClientIsMoving( c );
1044 setCurrentDesktop( d );
1045 setClientIsMoving( NULL );
1046 }
1047 }
1048
1049void Workspace::slotWindowToDesktopLeft()
1050 {
1051 int d = desktopToLeft( currentDesktop());
1052 if( d == currentDesktop())
1053 return;
1054 Client* c = active_popup_client ? active_popup_client : active_client;
1055 if (c && !c->isDesktop()
1056 && !c->isDock() && !c->isTopMenu())
1057 {
1058 setClientIsMoving( c );
1059 setCurrentDesktop( d );
1060 setClientIsMoving( NULL );
1061 }
1062 }
1063
1064void Workspace::slotWindowToDesktopUp()
1065 {
1066 int d = desktopUp( currentDesktop());
1067 if( d == currentDesktop())
1068 return;
1069 Client* c = active_popup_client ? active_popup_client : active_client;
1070 if (c && !c->isDesktop()
1071 && !c->isDock() && !c->isTopMenu())
1072 {
1073 setClientIsMoving( c );
1074 setCurrentDesktop( d );
1075 setClientIsMoving( NULL );
1076 }
1077 }
1078
1079void Workspace::slotWindowToDesktopDown()
1080 {
1081 int d = desktopDown( currentDesktop());
1082 if( d == currentDesktop())
1083 return;
1084 Client* c = active_popup_client ? active_popup_client : active_client;
1085 if (c && !c->isDesktop()
1086 && !c->isDock() && !c->isTopMenu())
1087 {
1088 setClientIsMoving( c );
1089 setCurrentDesktop( d );
1090 setClientIsMoving( NULL );
1091 }
1092 }
1093
1094
1098void Workspace::slotKillWindow()
1099 {
1100 KillWindow kill( this );
1101 kill.start();
1102 }
1103
1107void Workspace::slotSuspendWindow()
1108 {
1109 active_popup_client->suspendWindow();
1110 }
1111
1115void Workspace::slotResumeWindow()
1116 {
1117 active_popup_client->resumeWindow();
1118 }
1119
1125void Workspace::slotSendToDesktop( int desk )
1126 {
1127 if ( !active_popup_client )
1128 return;
1129 if ( desk == 0 )
1130 { // the 'on_all_desktops' menu entry
1131 active_popup_client->setOnAllDesktops( !active_popup_client->isOnAllDesktops());
1132 return;
1133 }
1134
1135 sendClientToDesktop( active_popup_client, desk, false );
1136
1137 }
1138
1142void Workspace::slotWindowOperations()
1143 {
1144 if ( !active_client )
1145 return;
1146 TQPoint pos = active_client->pos() + active_client->clientPos();
1147 showWindowMenu( pos.x(), pos.y(), active_client );
1148 }
1149
1150void Workspace::showWindowMenu( const TQRect &pos, Client* cl )
1151 {
1152 if (!tdeApp->authorizeTDEAction("twin_rmb"))
1153 return;
1154 if( !cl )
1155 return;
1156 if( active_popup_client != NULL ) // recursion
1157 return;
1158 if ( cl->isDesktop()
1159 || cl->isDock()
1160 || cl->isTopMenu()
1161 || cl->isModalSystemNotification())
1162 return;
1163
1164 active_popup_client = cl;
1165 TQPopupMenu* p = clientPopup();
1166 active_popup = p;
1167 int x = pos.left();
1168 int y = pos.bottom();
1169 clientPopupAboutToShow(); // needed for sizeHint() to be correct :-/
1170
1171 TQRect area = clientArea(ScreenArea, TQPoint(x, y), currentDesktop());
1172 TQSize hint = p->sizeHint();
1173 if (x < 0) x = area.right() - hint.width() + x;
1174 if (y < 0) y = area.bottom() - hint.height() + y;
1175
1176 if (pos.bottom() == pos.top())
1177 p->exec( TQPoint( x, y ) );
1178 else
1179 {
1180 if (y + hint.height() < area.height())
1181 p->exec( TQPoint( x, y ) );
1182 else
1183 p->exec( TQPoint( x, pos.top() - hint.height() ) );
1184 }
1185 // active popup may be already changed (e.g. the window shortcut dialog)
1186 if( active_popup == p )
1187 closeActivePopup();
1188 }
1189
1193void Workspace::slotWindowClose()
1194 {
1195 if ( tab_box->isVisible())
1196 return;
1197 Client* c = active_popup_client ? active_popup_client : active_client;
1198 performWindowOperation( c, Options::CloseOp );
1199 }
1200
1204void Workspace::slotWindowMove()
1205 {
1206 Client* c = active_popup_client ? active_popup_client : active_client;
1207 performWindowOperation( c, Options::UnrestrictedMoveOp );
1208 }
1209
1213void Workspace::slotWindowResize()
1214 {
1215 Client* c = active_popup_client ? active_popup_client : active_client;
1216 performWindowOperation( c, Options::UnrestrictedResizeOp );
1217 }
1218
1219void Client::setShortcut( const TQString& _cut )
1220 {
1221 TQString cut = rules()->checkShortcut( _cut );
1222 if( cut.isEmpty())
1223 return setShortcutInternal( TDEShortcut());
1224// Format:
1225// base+(abcdef)<space>base+(abcdef)
1226// E.g. Alt+Ctrl+(ABCDEF) Win+X,Win+(ABCDEF)
1227 if( !cut.contains( '(' ) && !cut.contains( ')' ) && !cut.contains( ' ' ))
1228 {
1229 if( workspace()->shortcutAvailable( TDEShortcut( cut ), this ))
1230 setShortcutInternal( TDEShortcut( cut ));
1231 else
1232 setShortcutInternal( TDEShortcut());
1233 return;
1234 }
1235 TQValueList< TDEShortcut > keys;
1236 TQStringList groups = TQStringList::split( ' ', cut );
1237 for( TQStringList::ConstIterator it = groups.begin();
1238 it != groups.end();
1239 ++it )
1240 {
1241 TQRegExp reg( "(.*\\+)\\((.*)\\)" );
1242 if( reg.search( *it ) > -1 )
1243 {
1244 TQString base = reg.cap( 1 );
1245 TQString list = reg.cap( 2 );
1246 for( unsigned int i = 0;
1247 i < list.length();
1248 ++i )
1249 {
1250 TDEShortcut c( base + list[ i ] );
1251 if( !c.isNull())
1252 keys.append( c );
1253 }
1254 }
1255 }
1256 for( TQValueList< TDEShortcut >::ConstIterator it = keys.begin();
1257 it != keys.end();
1258 ++it )
1259 {
1260 if( _shortcut == *it ) // current one is in the list
1261 return;
1262 }
1263 for( TQValueList< TDEShortcut >::ConstIterator it = keys.begin();
1264 it != keys.end();
1265 ++it )
1266 {
1267 if( workspace()->shortcutAvailable( *it, this ))
1268 {
1269 setShortcutInternal( *it );
1270 return;
1271 }
1272 }
1273 setShortcutInternal( TDEShortcut());
1274 }
1275
1276void Client::setShortcutInternal( const TDEShortcut& cut )
1277 {
1278 if( _shortcut == cut )
1279 return;
1280 _shortcut = cut;
1281 updateCaption();
1282 workspace()->clientShortcutUpdated( this );
1283 }
1284
1285bool Workspace::shortcutAvailable( const TDEShortcut& cut, Client* ignore ) const
1286 {
1287 // TODO check global shortcuts etc.
1288 for( ClientList::ConstIterator it = clients.begin();
1289 it != clients.end();
1290 ++it )
1291 {
1292 if( (*it) != ignore && (*it)->shortcut() == cut )
1293 return false;
1294 }
1295 return true;
1296 }
1297
1298} // 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:657
KWinInternal::Client::minimize
void minimize(bool avoid_animation=false)
Definition: client.cpp:667
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.4
This website is maintained by Timothy Pearson.