layers.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 #include <assert.h>
00066
00067 #include <kdebug.h>
00068
00069 #include "utils.h"
00070 #include "client.h"
00071 #include "workspace.h"
00072 #include "tabbox.h"
00073 #include "popupinfo.h"
00074 #include "group.h"
00075 #include "rules.h"
00076
00077 extern Time qt_x_time;
00078
00079 namespace KWinInternal
00080 {
00081
00082
00083
00084
00085
00086 void Workspace::updateClientLayer( Client* c )
00087 {
00088 if( c == NULL )
00089 return;
00090 if( c->layer() == c->belongsToLayer())
00091 return;
00092 StackingUpdatesBlocker blocker( this );
00093 c->invalidateLayer();
00094 for( ClientList::ConstIterator it = c->transients().begin();
00095 it != c->transients().end();
00096 ++it )
00097 updateClientLayer( *it );
00098 }
00099
00100 void Workspace::updateStackingOrder( bool propagate_new_clients )
00101 {
00102 if( block_stacking_updates > 0 )
00103 {
00104 blocked_propagating_new_clients |= propagate_new_clients;
00105 return;
00106 }
00107 ClientList new_stacking_order = constrainedStackingOrder();
00108 bool changed = ( new_stacking_order != stacking_order );
00109 stacking_order = new_stacking_order;
00110 #if 0
00111 kdDebug() << "stacking:" << changed << endl;
00112 if( changed || propagate_new_clients )
00113 {
00114 for( ClientList::ConstIterator it = stacking_order.begin();
00115 it != stacking_order.end();
00116 ++it )
00117 kdDebug() << (void*)(*it) << *it << endl;
00118 }
00119 #endif
00120 if( changed || propagate_new_clients )
00121 propagateClients( propagate_new_clients );
00122 }
00123
00128 void Workspace::propagateClients( bool propagate_new_clients )
00129 {
00130 Window *cl;
00131
00132
00133
00134 Window* new_stack = new Window[ stacking_order.count() + 2 ];
00135 int pos = 0;
00136
00137
00138
00139
00140
00141 new_stack[ pos++ ] = supportWindow->winId();
00142 int topmenu_space_pos = 1;
00143 for( ClientList::ConstIterator it = stacking_order.fromLast();
00144 it != stacking_order.end();
00145 --it )
00146 {
00147 new_stack[ pos++ ] = (*it)->frameId();
00148 if( (*it)->belongsToLayer() >= DockLayer )
00149 topmenu_space_pos = pos;
00150 }
00151 if( topmenu_space != NULL )
00152 {
00153 for( int i = pos;
00154 i > topmenu_space_pos;
00155 --i )
00156 new_stack[ i ] = new_stack[ i - 1 ];
00157 new_stack[ topmenu_space_pos ] = topmenu_space->winId();
00158 ++pos;
00159 }
00160
00161
00162 assert( new_stack[ 0 ] = supportWindow->winId());
00163 XRestackWindows(qt_xdisplay(), new_stack, pos);
00164 delete [] new_stack;
00165
00166 if ( propagate_new_clients )
00167 {
00168 cl = new Window[ desktops.count() + clients.count()];
00169 pos = 0;
00170
00171 for ( ClientList::ConstIterator it = desktops.begin(); it != desktops.end(); ++it )
00172 cl[pos++] = (*it)->window();
00173 for ( ClientList::ConstIterator it = clients.begin(); it != clients.end(); ++it )
00174 cl[pos++] = (*it)->window();
00175 rootInfo->setClientList( cl, pos );
00176 delete [] cl;
00177 }
00178
00179 cl = new Window[ stacking_order.count()];
00180 pos = 0;
00181 for ( ClientList::ConstIterator it = stacking_order.begin(); it != stacking_order.end(); ++it)
00182 cl[pos++] = (*it)->window();
00183 rootInfo->setClientListStacking( cl, pos );
00184 delete [] cl;
00185
00186 #if 0 // not necessary anymore?
00187 if ( tab_box->isVisible() )
00188 tab_box->raise();
00189
00190 if ( popupinfo->isVisible() )
00191 popupinfo->raise();
00192
00193 raiseElectricBorders();
00194 #endif
00195 }
00196
00197
00203
00204 Client* Workspace::topClientOnDesktop( int desktop, bool unconstrained ) const
00205 {
00206
00207 ClientList::ConstIterator begin, end;
00208 if( !unconstrained )
00209 {
00210 begin = stacking_order.fromLast();
00211 end = stacking_order.end();
00212 }
00213 else
00214 {
00215 begin = unconstrained_stacking_order.fromLast();
00216 end = unconstrained_stacking_order.end();
00217 }
00218 for( ClientList::ConstIterator it = begin;
00219 it != end;
00220 --it )
00221 {
00222 if ( (*it)->isOnDesktop( desktop ) && !(*it)->isSpecialWindow()
00223 && (*it)->isShown( false ) && (*it)->wantsTabFocus())
00224 return *it;
00225 }
00226 return 0;
00227 }
00228
00229 Client* Workspace::findDesktop( bool topmost, int desktop ) const
00230 {
00231
00232 if( topmost )
00233 {
00234 for ( ClientList::ConstIterator it = stacking_order.fromLast(); it != stacking_order.end(); --it)
00235 {
00236 if ( (*it)->isOnDesktop( desktop ) && (*it)->isDesktop()
00237 && (*it)->isShown( true ))
00238 return *it;
00239 }
00240 }
00241 else
00242 {
00243 for ( ClientList::ConstIterator it = stacking_order.begin(); it != stacking_order.end(); ++it)
00244 {
00245 if ( (*it)->isOnDesktop( desktop ) && (*it)->isDesktop()
00246 && (*it)->isShown( true ))
00247 return *it;
00248 }
00249 }
00250 return NULL;
00251 }
00252
00253 void Workspace::raiseOrLowerClient( Client *c)
00254 {
00255 if (!c) return;
00256 Client* topmost = NULL;
00257
00258 if ( most_recently_raised && stacking_order.contains( most_recently_raised ) &&
00259 most_recently_raised->isShown( true ) && c->isOnCurrentDesktop())
00260 topmost = most_recently_raised;
00261 else
00262 topmost = topClientOnDesktop( c->isOnAllDesktops() ? currentDesktop() : c->desktop());
00263
00264 if( c == topmost)
00265 lowerClient(c);
00266 else
00267 raiseClient(c);
00268 }
00269
00270
00271 void Workspace::lowerClient( Client* c )
00272 {
00273 if ( !c )
00274 return;
00275 if( c->isTopMenu())
00276 return;
00277
00278 c->cancelAutoRaise();
00279
00280 StackingUpdatesBlocker blocker( this );
00281
00282 unconstrained_stacking_order.remove( c );
00283 unconstrained_stacking_order.prepend( c );
00284 if( c->isTransient())
00285 {
00286
00287 ClientList mainclients = ensureStackingOrder( c->mainClients());
00288 for( ClientList::ConstIterator it = mainclients.fromLast();
00289 it != mainclients.end();
00290 ++it )
00291 lowerClient( *it );
00292 }
00293
00294 if ( c == most_recently_raised )
00295 most_recently_raised = 0;
00296 }
00297
00298 void Workspace::lowerClientWithinApplication( Client* c )
00299 {
00300 if ( !c )
00301 return;
00302 if( c->isTopMenu())
00303 return;
00304
00305 c->cancelAutoRaise();
00306
00307 StackingUpdatesBlocker blocker( this );
00308
00309 unconstrained_stacking_order.remove( c );
00310 bool lowered = false;
00311
00312 for( ClientList::Iterator it = unconstrained_stacking_order.begin();
00313 it != unconstrained_stacking_order.end();
00314 ++it )
00315 if( Client::belongToSameApplication( *it, c ))
00316 {
00317 unconstrained_stacking_order.insert( it, c );
00318 lowered = true;
00319 break;
00320 }
00321 if( !lowered )
00322 unconstrained_stacking_order.prepend( c );
00323
00324 }
00325
00326 void Workspace::raiseClient( Client* c )
00327 {
00328 if ( !c )
00329 return;
00330 if( c->isTopMenu())
00331 return;
00332
00333 c->cancelAutoRaise();
00334
00335 StackingUpdatesBlocker blocker( this );
00336
00337 if( c->isTransient())
00338 {
00339 ClientList mainclients = ensureStackingOrder( c->mainClients());
00340 for( ClientList::ConstIterator it = mainclients.begin();
00341 it != mainclients.end();
00342 ++it )
00343 raiseClient( *it );
00344 }
00345
00346 unconstrained_stacking_order.remove( c );
00347 unconstrained_stacking_order.append( c );
00348
00349 if( !c->isSpecialWindow())
00350 {
00351 most_recently_raised = c;
00352 pending_take_activity = NULL;
00353 }
00354 }
00355
00356 void Workspace::raiseClientWithinApplication( Client* c )
00357 {
00358 if ( !c )
00359 return;
00360 if( c->isTopMenu())
00361 return;
00362
00363 c->cancelAutoRaise();
00364
00365 StackingUpdatesBlocker blocker( this );
00366
00367
00368
00369 for( ClientList::Iterator it = unconstrained_stacking_order.fromLast();
00370 it != unconstrained_stacking_order.end();
00371 --it )
00372 {
00373 if( *it == c )
00374 return;
00375 if( Client::belongToSameApplication( *it, c ))
00376 {
00377 unconstrained_stacking_order.remove( c );
00378 ++it;
00379 unconstrained_stacking_order.insert( it, c );
00380 return;
00381 }
00382 }
00383 }
00384
00385 void Workspace::raiseClientRequest( Client* c, NET::RequestSource src, Time timestamp )
00386 {
00387 if( src == NET::FromTool || allowFullClientRaising( c, timestamp ))
00388 raiseClient( c );
00389 else
00390 {
00391 raiseClientWithinApplication( c );
00392 c->demandAttention();
00393 }
00394 }
00395
00396 void Workspace::lowerClientRequest( Client* c, NET::RequestSource src, Time )
00397 {
00398
00399
00400
00401
00402 if( src == NET::FromTool || !c->hasUserTimeSupport())
00403 lowerClient( c );
00404 else
00405 lowerClientWithinApplication( c );
00406 }
00407
00408 void Workspace::restackClientUnderActive( Client* c )
00409 {
00410 if( c->isTopMenu())
00411 return;
00412 if( !active_client || active_client == c )
00413 {
00414 raiseClient( c );
00415 return;
00416 }
00417
00418
00419 assert( unconstrained_stacking_order.contains( active_client ));
00420 for( ClientList::Iterator it = unconstrained_stacking_order.begin();
00421 it != unconstrained_stacking_order.end();
00422 ++it )
00423 {
00424 if( Client::belongToSameApplication( active_client, *it ))
00425 {
00426 if( *it != c )
00427 {
00428 unconstrained_stacking_order.remove( c );
00429 unconstrained_stacking_order.insert( it, c );
00430 }
00431 break;
00432 }
00433 }
00434 assert( unconstrained_stacking_order.contains( c ));
00435 if( c->wantsTabFocus() && focus_chain.contains( active_client ))
00436 {
00437
00438 focus_chain.remove( c );
00439 for( ClientList::Iterator it = focus_chain.fromLast();
00440 it != focus_chain.end();
00441 --it )
00442 {
00443 if( Client::belongToSameApplication( active_client, *it ))
00444 {
00445 focus_chain.insert( it, c );
00446 break;
00447 }
00448 }
00449 }
00450 updateStackingOrder();
00451 }
00452
00453 void Workspace::circulateDesktopApplications()
00454 {
00455 if ( desktops.count() > 1 )
00456 {
00457 bool change_active = activeClient()->isDesktop();
00458 raiseClient( findDesktop( false, currentDesktop()));
00459 if( change_active )
00460 activateClient( findDesktop( true, currentDesktop()));
00461 }
00462
00463 if( desktops.count() > 0 && activeClient() == NULL && should_get_focus.count() == 0 )
00464 activateClient( findDesktop( true, currentDesktop()));
00465 }
00466
00467
00471 ClientList Workspace::constrainedStackingOrder()
00472 {
00473 ClientList layer[ NumLayers ];
00474
00475 #if 0
00476 kdDebug() << "stacking1:" << endl;
00477 #endif
00478
00479 for( ClientList::ConstIterator it = unconstrained_stacking_order.begin();
00480 it != unconstrained_stacking_order.end();
00481 ++it )
00482 {
00483 #if 0
00484 kdDebug() << (void*)(*it) << *it << endl;
00485 #endif
00486 layer[ (*it)->layer() ].append( *it );
00487 }
00488 ClientList stacking;
00489 for( Layer lay = FirstLayer;
00490 lay < NumLayers;
00491 ++lay )
00492 stacking += layer[ lay ];
00493 #if 0
00494 kdDebug() << "stacking2:" << endl;
00495 for( ClientList::ConstIterator it = stacking.begin();
00496 it != stacking.end();
00497 ++it )
00498 kdDebug() << (void*)(*it) << *it << endl;
00499 #endif
00500
00501
00502 for( ClientList::Iterator it = stacking.fromLast();
00503 it != stacking.end();
00504 )
00505 {
00506 if( !(*it)->isTransient())
00507 {
00508 --it;
00509 continue;
00510 }
00511 ClientList::Iterator it2 = stacking.end();
00512 if( (*it)->groupTransient())
00513 {
00514 if( (*it)->group()->members().count() > 0 )
00515 {
00516 for( it2 = stacking.fromLast();
00517 it2 != stacking.end();
00518 --it2 )
00519 {
00520 if( *it2 == *it )
00521 {
00522 it2 = stacking.end();
00523 break;
00524 }
00525 if( (*it2)->hasTransient( *it, true ) && keepTransientAbove( *it2, *it ))
00526 break;
00527 }
00528 }
00529 }
00530 else
00531 {
00532 for( it2 = stacking.fromLast();
00533 it2 != stacking.end();
00534 --it2 )
00535 {
00536 if( *it2 == *it )
00537 {
00538 it2 = stacking.end();
00539 break;
00540 }
00541 if( *it2 == (*it)->transientFor() && keepTransientAbove( *it2, *it ))
00542 break;
00543 }
00544 }
00545
00546 if( it2 == stacking.end())
00547 {
00548 --it;
00549 continue;
00550 }
00551 Client* current = *it;
00552 ClientList::Iterator remove_it = it;
00553 --it;
00554 stacking.remove( remove_it );
00555 if( !current->transients().isEmpty())
00556 it = it2;
00557 ++it2;
00558 stacking.insert( it2, current );
00559 }
00560 #if 0
00561 kdDebug() << "stacking3:" << endl;
00562 for( ClientList::ConstIterator it = stacking.begin();
00563 it != stacking.end();
00564 ++it )
00565 kdDebug() << (void*)(*it) << *it << endl;
00566 kdDebug() << "\n\n" << endl;
00567 #endif
00568 return stacking;
00569 }
00570
00571 void Workspace::blockStackingUpdates( bool block )
00572 {
00573 if( block )
00574 {
00575 if( block_stacking_updates == 0 )
00576 blocked_propagating_new_clients = false;
00577 ++block_stacking_updates;
00578 }
00579 else
00580 if( --block_stacking_updates == 0 )
00581 updateStackingOrder( blocked_propagating_new_clients );
00582 }
00583
00584
00585 ClientList Workspace::ensureStackingOrder( const ClientList& list ) const
00586 {
00587
00588 if( list.count() < 2 )
00589 return list;
00590
00591 ClientList result = list;
00592 for( ClientList::ConstIterator it = stacking_order.begin();
00593 it != stacking_order.end();
00594 ++it )
00595 if( result.remove( *it ) != 0 )
00596 result.append( *it );
00597 return result;
00598 }
00599
00600
00601
00602 bool Workspace::keepTransientAbove( const Client* mainwindow, const Client* transient )
00603 {
00604
00605
00606
00607
00608 if( mainwindow->isTopMenu() && transient->groupTransient())
00609 return false;
00610
00611
00612
00613
00614 if( transient->isDialog() && !transient->isModal() && transient->groupTransient())
00615 return false;
00616 return true;
00617
00618
00619
00620
00621 if( mainwindow->isDock() && !mainwindow->keepBelow()
00622 && !mainwindow->isActive() && !transient->isActive())
00623 return false;
00624 return true;
00625 }
00626
00627
00628
00629
00630
00631 void Client::restackWindow( Window , int detail, NET::RequestSource src, Time timestamp, bool send_event )
00632 {
00633 switch ( detail )
00634 {
00635 case Above:
00636 case TopIf:
00637 workspace()->raiseClientRequest( this, src, timestamp );
00638 break;
00639 case Below:
00640 case BottomIf:
00641 workspace()->lowerClientRequest( this, src, timestamp );
00642 break;
00643 case Opposite:
00644 default:
00645 break;
00646 }
00647 if( send_event )
00648 sendSyntheticConfigureNotify();
00649 }
00650
00651 void Client::setKeepAbove( bool b )
00652 {
00653 b = rules()->checkKeepAbove( b );
00654 if( b )
00655 setKeepBelow( false );
00656 if ( b == keepAbove()
00657 || ( b && keepBelow()))
00658 {
00659 if( bool( info->state() & NET::KeepAbove ) != keepAbove())
00660 info->setState( keepAbove() ? NET::KeepAbove : 0, NET::KeepAbove );
00661 return;
00662 }
00663 keep_above = b;
00664 info->setState( keepAbove() ? NET::KeepAbove : 0, NET::KeepAbove );
00665 if( decoration != NULL )
00666 decoration->emitKeepAboveChanged( keepAbove());
00667 workspace()->updateClientLayer( this );
00668 updateWindowRules();
00669 }
00670
00671 void Client::setKeepBelow( bool b )
00672 {
00673 b = rules()->checkKeepBelow( b );
00674 if( b )
00675 setKeepAbove( false );
00676 if ( b == keepBelow()
00677 || ( b && keepAbove()))
00678 {
00679 if( bool( info->state() & NET::KeepBelow ) != keepBelow())
00680 info->setState( keepBelow() ? NET::KeepBelow : 0, NET::KeepBelow );
00681 return;
00682 }
00683 keep_below = b;
00684 info->setState( keepBelow() ? NET::KeepBelow : 0, NET::KeepBelow );
00685 if( decoration != NULL )
00686 decoration->emitKeepBelowChanged( keepBelow());
00687 workspace()->updateClientLayer( this );
00688 updateWindowRules();
00689 }
00690
00691 Layer Client::layer() const
00692 {
00693 if( in_layer == UnknownLayer )
00694 const_cast< Client* >( this )->in_layer = belongsToLayer();
00695 return in_layer;
00696 }
00697
00698 Layer Client::belongsToLayer() const
00699 {
00700 if( isDesktop())
00701 return DesktopLayer;
00702 if( isSplash())
00703 return NormalLayer;
00704 if( isDock() && keepBelow())
00705
00706
00707
00708 return NormalLayer;
00709 if( keepBelow())
00710 return BelowLayer;
00711 if( isDock() && !keepBelow())
00712 return DockLayer;
00713 if( isTopMenu())
00714 return DockLayer;
00715
00716
00717 bool raise_special_active_windows = ( workspace()->topClientOnDesktop( desktop(), true ) == this );
00718 if( keepAbove())
00719 return AboveLayer;
00720 if( isFullScreen() && workspace()->activeClient() != NULL
00721 && ( workspace()->activeClient() == this || this->hasTransient( workspace()->activeClient(), true ))
00722 && raise_special_active_windows )
00723 return ActiveLayer;
00724 return NormalLayer;
00725 }
00726
00727 }
This file is part of the documentation for kwin Library Version 3.3.0.