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 #include "group.h"
00031 #include <QTextStream>
00032 #include "workspace.h"
00033 #include "client.h"
00034 #include "effects.h"
00035
00036 #include <assert.h>
00037 #include <kstartupinfo.h>
00038 #include <QX11Info>
00039
00040
00041
00042
00043
00044
00045
00046
00047 namespace KWin
00048 {
00049
00050
00051
00052
00053
00054
00055
00056
00057 #ifdef NDEBUG
00058 #undef ENABLE_TRANSIENCY_CHECK
00059 #endif
00060
00061 #ifdef ENABLE_TRANSIENCY_CHECK
00062 static bool transiencyCheckNonExistent = false;
00063
00064 bool performTransiencyCheck()
00065 {
00066 bool ret = true;
00067 ClientList clients = Workspace::self()->clients;
00068 for( ClientList::ConstIterator it1 = clients.constBegin();
00069 it1 != clients.constEnd();
00070 ++it1 )
00071 {
00072 if( (*it1)->deleting )
00073 continue;
00074 if( (*it1)->in_group == NULL )
00075 {
00076 kDebug(1212) << "TC: " << *it1 << " in not in a group" << endl;
00077 ret = false;
00078 }
00079 else if( !(*it1)->in_group->members().contains( *it1 ))
00080 {
00081 kDebug(1212) << "TC: " << *it1 << " has a group " << (*it1)->in_group << " but group does not contain it" << endl;
00082 ret = false;
00083 }
00084 if( !(*it1)->isTransient())
00085 {
00086 if( !(*it1)->mainClients().isEmpty())
00087 {
00088 kDebug(1212) << "TC: " << *it1 << " is not transient, has main clients:" << (*it1)->mainClients() << endl;
00089 ret = false;
00090 }
00091 }
00092 else
00093 {
00094 ClientList mains = (*it1)->mainClients();
00095 for( ClientList::ConstIterator it2 = mains.constBegin();
00096 it2 != mains.constEnd();
00097 ++it2 )
00098 {
00099 if( transiencyCheckNonExistent
00100 && !Workspace::self()->clients.contains( *it2 )
00101 && !Workspace::self()->desktops.contains( *it2 ))
00102 {
00103 kDebug(1212) << "TC:" << *it1 << " has non-existent main client ";
00104 kDebug(1212) << "TC2:" << *it2;
00105 ret = false;
00106 continue;
00107 }
00108 if( !(*it2)->transients_list.contains( *it1 ))
00109 {
00110 kdDebug(1212) << "TC:" << *it1 << " has main client " << *it2 << " but main client does not have it as a transient" << endl;
00111 ret = false;
00112 }
00113 }
00114 }
00115 ClientList trans = (*it1)->transients_list;
00116 for( ClientList::ConstIterator it2 = trans.constBegin();
00117 it2 != trans.constEnd();
00118 ++it2 )
00119 {
00120 if( transiencyCheckNonExistent
00121 && !Workspace::self()->clients.contains( *it2 )
00122 && !Workspace::self()->desktops.contains( *it2 ))
00123 {
00124 kDebug(1212) << "TC:" << *it1 << " has non-existent transient ";
00125 kDebug(1212) << "TC2:" << *it2;
00126 ret = false;
00127 continue;
00128 }
00129 if( !(*it2)->mainClients().contains( *it1 ))
00130 {
00131 kdDebug(1212) << "TC:" << *it1 << " has transient " << *it2 << " but transient does not have it as a main client" << endl;
00132 ret = false;
00133 }
00134 }
00135 }
00136 GroupList groups = Workspace::self()->groups;
00137 for( GroupList::ConstIterator it1 = groups.constBegin();
00138 it1 != groups.constEnd();
00139 ++it1 )
00140 {
00141 ClientList members = (*it1)->members();
00142 for( ClientList::ConstIterator it2 = members.constBegin();
00143 it2 != members.constEnd();
00144 ++it2 )
00145 {
00146 if( (*it2)->in_group != *it1 )
00147 {
00148 kDebug(1212) << "TC: Group " << *it1 << " contains client " << *it2 << " but client is not in that group" << endl;
00149 ret = false;
00150 }
00151 }
00152 }
00153 return ret;
00154 }
00155
00156 static QString transiencyCheckStartBt;
00157 static const Client* transiencyCheckClient;
00158 static int transiencyCheck = 0;
00159
00160 static void startTransiencyCheck( const QString& bt, const Client* c, bool ne )
00161 {
00162 if( ++transiencyCheck == 1 )
00163 {
00164 transiencyCheckStartBt = bt;
00165 transiencyCheckClient = c;
00166 }
00167 if( ne )
00168 transiencyCheckNonExistent = true;
00169 }
00170 static void checkTransiency()
00171 {
00172 if( --transiencyCheck == 0 )
00173 {
00174 if( !performTransiencyCheck())
00175 {
00176 kDebug(1212) << "BT:" << transiencyCheckStartBt << endl;
00177 kDebug(1212) << "CLIENT:" << transiencyCheckClient << endl;
00178 abort();
00179 }
00180 transiencyCheckNonExistent = false;
00181 }
00182 }
00183 class TransiencyChecker
00184 {
00185 public:
00186 TransiencyChecker( const QString& bt, const Client*c ) { startTransiencyCheck( bt, c, false ); }
00187 ~TransiencyChecker() { checkTransiency(); }
00188 };
00189
00190 void checkNonExistentClients()
00191 {
00192 startTransiencyCheck( kdBacktrace(), NULL, true );
00193 checkTransiency();
00194 }
00195
00196 #define TRANSIENCY_CHECK( c ) TransiencyChecker transiency_checker( kdBacktrace(), c )
00197
00198 #else
00199
00200 #define TRANSIENCY_CHECK( c )
00201
00202 void checkNonExistentClients()
00203 {
00204 }
00205
00206 #endif
00207
00208
00209
00210
00211
00212 Group::Group( Window leader_P, Workspace* workspace_P )
00213 : leader_client( NULL ),
00214 leader_wid( leader_P ),
00215 _workspace( workspace_P ),
00216 leader_info( NULL ),
00217 user_time( -1U ),
00218 refcount( 0 )
00219 {
00220 if( leader_P != None )
00221 {
00222 leader_client = workspace_P->findClient( WindowMatchPredicate( leader_P ));
00223 unsigned long properties[ 2 ] = { 0, NET::WM2StartupId };
00224 leader_info = new NETWinInfo2( display(), leader_P, rootWindow(),
00225 properties, 2 );
00226 }
00227 effect_group = new EffectWindowGroupImpl( this );
00228 workspace()->addGroup( this, Allowed );
00229 }
00230
00231 Group::~Group()
00232 {
00233 delete leader_info;
00234 delete effect_group;
00235 }
00236
00237 QPixmap Group::icon() const
00238 {
00239 if( leader_client != NULL )
00240 return leader_client->icon();
00241 else if( leader_wid != None )
00242 {
00243 QPixmap ic;
00244 Client::readIcons( leader_wid, &ic, NULL );
00245 return ic;
00246 }
00247 return QPixmap();
00248 }
00249
00250 QPixmap Group::miniIcon() const
00251 {
00252 if( leader_client != NULL )
00253 return leader_client->miniIcon();
00254 else if( leader_wid != None )
00255 {
00256 QPixmap ic;
00257 Client::readIcons( leader_wid, NULL, &ic );
00258 return ic;
00259 }
00260 return QPixmap();
00261 }
00262
00263 void Group::addMember( Client* member_P )
00264 {
00265 TRANSIENCY_CHECK( member_P );
00266 _members.append( member_P );
00267
00268
00269 }
00270
00271 void Group::removeMember( Client* member_P )
00272 {
00273 TRANSIENCY_CHECK( member_P );
00274
00275
00276 Q_ASSERT( _members.contains( member_P ));
00277 _members.removeAll( member_P );
00278
00279
00280
00281
00282 if( refcount == 0 && _members.isEmpty())
00283 {
00284 workspace()->removeGroup( this, Allowed );
00285 delete this;
00286 }
00287 }
00288
00289 void Group::ref()
00290 {
00291 ++refcount;
00292 }
00293
00294 void Group::deref()
00295 {
00296 if( --refcount == 0 && _members.isEmpty())
00297 {
00298 workspace()->removeGroup( this, Allowed );
00299 delete this;
00300 }
00301 }
00302
00303 void Group::gotLeader( Client* leader_P )
00304 {
00305 assert( leader_P->window() == leader_wid );
00306 leader_client = leader_P;
00307 }
00308
00309 void Group::lostLeader()
00310 {
00311 assert( !_members.contains( leader_client ));
00312 leader_client = NULL;
00313 if( _members.isEmpty())
00314 {
00315 workspace()->removeGroup( this, Allowed );
00316 delete this;
00317 }
00318 }
00319
00320 void Group::getIcons()
00321 {
00322
00323 }
00324
00325
00326
00327
00328
00329 Group* Workspace::findGroup( Window leader ) const
00330 {
00331 assert( leader != None );
00332 for( GroupList::ConstIterator it = groups.constBegin();
00333 it != groups.constEnd();
00334 ++it )
00335 if( (*it)->leader() == leader )
00336 return *it;
00337 return NULL;
00338 }
00339
00340
00341
00342 Group* Workspace::findClientLeaderGroup( const Client* c ) const
00343 {
00344 TRANSIENCY_CHECK( c );
00345 Group* ret = NULL;
00346 for( ClientList::ConstIterator it = clients.constBegin();
00347 it != clients.constEnd();
00348 ++it )
00349 {
00350 if( *it == c )
00351 continue;
00352 if( (*it)->wmClientLeader() == c->wmClientLeader())
00353 {
00354 if( ret == NULL || ret == (*it)->group())
00355 ret = (*it)->group();
00356 else
00357 {
00358
00359
00360
00361
00362 ClientList old_group = (*it)->group()->members();
00363
00364 for( int pos = 0;
00365 pos < old_group.count();
00366 ++pos )
00367 {
00368 Client* tmp = old_group[ pos ];
00369 if( tmp != c )
00370 tmp->changeClientLeaderGroup( ret );
00371 }
00372 }
00373 }
00374 }
00375 return ret;
00376 }
00377
00378 void Workspace::updateMinimizedOfTransients( Client* c )
00379 {
00380
00381 if ( c->isMinimized() || c->isShade() )
00382 {
00383 for( ClientList::ConstIterator it = c->transients().constBegin();
00384 it != c->transients().constEnd();
00385 ++it )
00386 {
00387 if( !(*it)->isMinimized()
00388 && !(*it)->isTopMenu() )
00389 {
00390 (*it)->minimize();
00391 updateMinimizedOfTransients( (*it) );
00392 }
00393 }
00394 if( c->isModal())
00395 {
00396 foreach( Client* c2, c->mainClients())
00397 c2->minimize();
00398 }
00399 }
00400 else
00401 {
00402 for( ClientList::ConstIterator it = c->transients().constBegin();
00403 it != c->transients().constEnd();
00404 ++it )
00405 {
00406 if( (*it)->isMinimized()
00407 && !(*it)->isTopMenu())
00408 {
00409 (*it)->unminimize();
00410 updateMinimizedOfTransients( (*it) );
00411 }
00412 }
00413 if( c->isModal())
00414 {
00415 foreach( Client* c2, c->mainClients())
00416 c2->unminimize();
00417 }
00418 }
00419 }
00420
00421
00425 void Workspace::updateOnAllDesktopsOfTransients( Client* c )
00426 {
00427 for( ClientList::ConstIterator it = c->transients().constBegin();
00428 it != c->transients().constEnd();
00429 ++it)
00430 {
00431 if( (*it)->isOnAllDesktops() != c->isOnAllDesktops())
00432 (*it)->setOnAllDesktops( c->isOnAllDesktops());
00433 }
00434 }
00435
00436
00437 void Workspace::checkTransients( Window w )
00438 {
00439 TRANSIENCY_CHECK( NULL );
00440 for( ClientList::ConstIterator it = clients.constBegin();
00441 it != clients.constEnd();
00442 ++it )
00443 (*it)->checkTransient( w );
00444 }
00445
00446
00447
00448
00449
00450
00451
00452
00453 bool Toplevel::resourceMatch( const Toplevel* c1, const Toplevel* c2 )
00454 {
00455
00456 if( qstrncmp( c1->resourceClass(), "xv", 2 ) == 0 && c1->resourceName() == "xv" )
00457 return qstrncmp( c2->resourceClass(), "xv", 2 ) == 0 && c2->resourceName() == "xv";
00458
00459 if( c1->resourceName() == "mozilla" )
00460 return c2->resourceName() == "mozilla";
00461 return c1->resourceClass() == c2->resourceClass();
00462 }
00463
00464
00465
00466
00467
00468
00469 bool Client::belongToSameApplication( const Client* c1, const Client* c2, bool active_hack )
00470 {
00471 bool same_app = false;
00472
00473
00474 if( c1 == c2 )
00475 same_app = true;
00476 else if( c1->isTransient() && c2->hasTransient( c1, true ))
00477 same_app = true;
00478 else if( c2->isTransient() && c1->hasTransient( c2, true ))
00479 same_app = true;
00480 else if( c1->group() == c2->group())
00481 same_app = true;
00482 else if( c1->wmClientLeader() == c2->wmClientLeader()
00483 && c1->wmClientLeader() != c1->window()
00484 && c2->wmClientLeader() != c2->window())
00485 same_app = true;
00486
00487
00488 else if( c1->pid() != c2->pid()
00489 || c1->wmClientMachine( false ) != c2->wmClientMachine( false ))
00490 ;
00491 else if( c1->wmClientLeader() != c2->wmClientLeader()
00492 && c1->wmClientLeader() != c1->window()
00493 && c2->wmClientLeader() != c2->window())
00494 ;
00495 else if( !resourceMatch( c1, c2 ))
00496 ;
00497 else if( !sameAppWindowRoleMatch( c1, c2, active_hack ))
00498 ;
00499 else if( c1->pid() == 0 || c2->pid() == 0 )
00500 ;
00501
00502 else
00503 same_app = true;
00504
00505 return same_app;
00506 }
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518 bool Client::sameAppWindowRoleMatch( const Client* c1, const Client* c2, bool active_hack )
00519 {
00520 if( c1->isTransient())
00521 {
00522 while( c1->transientFor() != NULL )
00523 c1 = c1->transientFor();
00524 if( c1->groupTransient())
00525 return c1->group() == c2->group();
00526 #if 0
00527
00528
00529
00530 || c1->group()->leaderClient() == c1 || c2->group()->leaderClient() == c2;
00531 #endif
00532 }
00533 if( c2->isTransient())
00534 {
00535 while( c2->transientFor() != NULL )
00536 c2 = c2->transientFor();
00537 if( c2->groupTransient())
00538 return c1->group() == c2->group();
00539 #if 0
00540 || c1->group()->leaderClient() == c1 || c2->group()->leaderClient() == c2;
00541 #endif
00542 }
00543 int pos1 = c1->windowRole().indexOf( '#' );
00544 int pos2 = c2->windowRole().indexOf( '#' );
00545 if(( pos1 >= 0 && pos2 >= 0 )
00546 ||
00547
00548
00549 ( c1->resourceName() == "mozilla" && c2->resourceName() == "mozilla" ))
00550 {
00551 if( !active_hack )
00552 return c1 == c2;
00553 if( !c1->isActive() && !c2->isActive())
00554 return c1 == c2;
00555 else
00556 return true;
00557 }
00558 return true;
00559 }
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607 void Client::readTransient()
00608 {
00609 TRANSIENCY_CHECK( this );
00610 Window new_transient_for_id;
00611 if( XGetTransientForHint( display(), window(), &new_transient_for_id ))
00612 {
00613 original_transient_for_id = new_transient_for_id;
00614 new_transient_for_id = verifyTransientFor( new_transient_for_id, true );
00615 }
00616 else
00617 {
00618 original_transient_for_id = None;
00619 new_transient_for_id = verifyTransientFor( None, false );
00620 }
00621 setTransient( new_transient_for_id );
00622 }
00623
00624 void Client::setTransient( Window new_transient_for_id )
00625 {
00626 TRANSIENCY_CHECK( this );
00627 if( new_transient_for_id != transient_for_id )
00628 {
00629 removeFromMainClients();
00630 transient_for = NULL;
00631 transient_for_id = new_transient_for_id;
00632 if( transient_for_id != None && !groupTransient())
00633 {
00634 transient_for = workspace()->findClient( WindowMatchPredicate( transient_for_id ));
00635 assert( transient_for != NULL );
00636 transient_for->addTransient( this );
00637 }
00638 checkGroup( NULL, true );
00639 if( isTopMenu())
00640 workspace()->updateCurrentTopMenu();
00641 workspace()->updateClientLayer( this );
00642 }
00643 }
00644
00645 void Client::removeFromMainClients()
00646 {
00647 TRANSIENCY_CHECK( this );
00648 if( transientFor() != NULL )
00649 transientFor()->removeTransient( this );
00650 if( groupTransient())
00651 {
00652 for( ClientList::ConstIterator it = group()->members().constBegin();
00653 it != group()->members().constEnd();
00654 ++it )
00655 (*it)->removeTransient( this );
00656 }
00657 }
00658
00659
00660
00661
00662
00663 void Client::cleanGrouping()
00664 {
00665 TRANSIENCY_CHECK( this );
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677 removeFromMainClients();
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688 for( ClientList::ConstIterator it = transients_list.constBegin();
00689 it != transients_list.constEnd();
00690 )
00691 {
00692 if( (*it)->transientFor() == this )
00693 {
00694 removeTransient( *it );
00695 it = transients_list.constBegin();
00696 }
00697 else
00698 ++it;
00699 }
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715 ClientList group_members = group()->members();
00716 group()->removeMember( this );
00717 in_group = NULL;
00718 for( ClientList::ConstIterator it = group_members.constBegin();
00719 it != group_members.constEnd();
00720 ++it )
00721 (*it)->removeTransient( this );
00722
00723
00724
00725
00726
00727 }
00728
00729
00730
00731
00732
00733 void Client::checkGroupTransients()
00734 {
00735 TRANSIENCY_CHECK( this );
00736 for( ClientList::ConstIterator it1 = group()->members().constBegin();
00737 it1 != group()->members().constEnd();
00738 ++it1 )
00739 {
00740 if( !(*it1)->groupTransient())
00741 continue;
00742 for( ClientList::ConstIterator it2 = group()->members().constBegin();
00743 it2 != group()->members().constEnd();
00744 ++it2 )
00745 {
00746 if( *it1 == *it2 )
00747 continue;
00748 for( Client* cl = (*it2)->transientFor();
00749 cl != NULL;
00750 cl = cl->transientFor())
00751 {
00752 if( cl == *it1 )
00753 {
00754 (*it2)->transients_list.removeAll( *it1 );
00755 continue;
00756 }
00757 }
00758
00759
00760
00761
00762 if( (*it2)->groupTransient() && (*it1)->hasTransient( *it2, true ) && (*it2)->hasTransient( *it1, true ))
00763 (*it2)->transients_list.removeAll( *it1 );
00764
00765
00766
00767
00768
00769 for( ClientList::ConstIterator it3 = group()->members().constBegin();
00770 it3 != group()->members().constEnd();
00771 ++it3 )
00772 {
00773 if( *it1 == *it2 || *it2 == *it3 || *it1 == *it3 )
00774 continue;
00775 if( (*it2)->hasTransient( *it1, false ) && (*it3)->hasTransient( *it1, false ))
00776 {
00777 if( (*it2)->hasTransient( *it3, true ))
00778 (*it2)->transients_list.removeAll( *it1 );
00779 if( (*it3)->hasTransient( *it2, true ))
00780 (*it3)->transients_list.removeAll( *it1 );
00781 }
00782 }
00783 }
00784 }
00785 }
00786
00790 Window Client::verifyTransientFor( Window new_transient_for, bool defined )
00791 {
00792 Window new_property_value = new_transient_for;
00793
00794
00795 if( isSplash() && new_transient_for == None )
00796 new_transient_for = rootWindow();
00797 if( new_transient_for == None )
00798 {
00799 if( defined )
00800 new_property_value = new_transient_for = rootWindow();
00801 else
00802 return None;
00803 }
00804 if( new_transient_for == window())
00805 {
00806 kWarning( 1216 ) << "Client " << this << " has WM_TRANSIENT_FOR poiting to itself." ;
00807 new_property_value = new_transient_for = rootWindow();
00808 }
00809
00810
00811
00812 WId before_search = new_transient_for;
00813 while( new_transient_for != None
00814 && new_transient_for != rootWindow()
00815 && !workspace()->findClient( WindowMatchPredicate( new_transient_for )))
00816 {
00817 Window root_return, parent_return;
00818 Window* wins = NULL;
00819 unsigned int nwins;
00820 int r = XQueryTree(display(), new_transient_for, &root_return, &parent_return, &wins, &nwins);
00821 if ( wins )
00822 XFree((void *) wins);
00823 if ( r == 0)
00824 break;
00825 new_transient_for = parent_return;
00826 }
00827 if( Client* new_transient_for_client = workspace()->findClient( WindowMatchPredicate( new_transient_for )))
00828 {
00829 if( new_transient_for != before_search )
00830 {
00831 kDebug( 1212 ) << "Client " << this << " has WM_TRANSIENT_FOR poiting to non-toplevel window "
00832 << before_search << ", child of " << new_transient_for_client << ", adjusting." << endl;
00833 new_property_value = new_transient_for;
00834 }
00835 }
00836 else
00837 new_transient_for = before_search;
00838
00839
00840
00841 int count = 20;
00842 Window loop_pos = new_transient_for;
00843 while( loop_pos != None && loop_pos != rootWindow())
00844 {
00845 Client* pos = workspace()->findClient( WindowMatchPredicate( loop_pos ));
00846 if( pos == NULL )
00847 break;
00848 loop_pos = pos->transient_for_id;
00849 if( --count == 0 || pos == this )
00850 {
00851 kWarning( 1216 ) << "Client " << this << " caused WM_TRANSIENT_FOR loop." ;
00852 new_transient_for = rootWindow();
00853 }
00854 }
00855 if( new_transient_for != rootWindow()
00856 && workspace()->findClient( WindowMatchPredicate( new_transient_for )) == NULL )
00857 {
00858 new_transient_for = rootWindow();
00859 }
00860 if( new_property_value != original_transient_for_id )
00861 XSetTransientForHint( display(), window(), new_property_value );
00862 return new_transient_for;
00863 }
00864
00865 void Client::addTransient( Client* cl )
00866 {
00867 TRANSIENCY_CHECK( this );
00868 assert( !transients_list.contains( cl ));
00869
00870 assert( cl != this );
00871 transients_list.append( cl );
00872 if( workspace()->mostRecentlyActivatedClient() == this && cl->isModal())
00873 check_active_modal = true;
00874
00875
00876
00877
00878
00879
00880 }
00881
00882 void Client::removeTransient( Client* cl )
00883 {
00884 TRANSIENCY_CHECK( this );
00885
00886
00887 transients_list.removeAll( cl );
00888
00889
00890 if( cl->transientFor() == this )
00891 {
00892 cl->transient_for_id = None;
00893 cl->transient_for = NULL;
00894
00895 cl->setTransient( None );
00896 }
00897 }
00898
00899
00900 void Client::checkTransient( Window w )
00901 {
00902 TRANSIENCY_CHECK( this );
00903 if( original_transient_for_id != w )
00904 return;
00905 w = verifyTransientFor( w, true );
00906 setTransient( w );
00907 }
00908
00909
00910
00911 bool Client::hasTransient( const Client* cl, bool indirect ) const
00912 {
00913
00914 ConstClientList set;
00915 return hasTransientInternal( cl, indirect, set );
00916 }
00917
00918 bool Client::hasTransientInternal( const Client* cl, bool indirect, ConstClientList& set ) const
00919 {
00920 if( cl->transientFor() != NULL )
00921 {
00922 if( cl->transientFor() == this )
00923 return true;
00924 if( !indirect )
00925 return false;
00926 if( set.contains( cl ))
00927 return false;
00928 set.append( cl );
00929 return hasTransientInternal( cl->transientFor(), indirect, set );
00930 }
00931 if( !cl->isTransient())
00932 return false;
00933 if( group() != cl->group())
00934 return false;
00935
00936 if( transients().contains( const_cast< Client* >( cl )))
00937 return true;
00938 if( !indirect )
00939 return false;
00940 if( set.contains( this ))
00941 return false;
00942 set.append( this );
00943 for( ClientList::ConstIterator it = transients().constBegin();
00944 it != transients().constEnd();
00945 ++it )
00946 if( (*it)->hasTransientInternal( cl, indirect, set ))
00947 return true;
00948 return false;
00949 }
00950
00951 ClientList Client::mainClients() const
00952 {
00953 if( !isTransient())
00954 return ClientList();
00955 if( transientFor() != NULL )
00956 return ClientList() << const_cast< Client* >( transientFor());
00957 ClientList result;
00958 for( ClientList::ConstIterator it = group()->members().constBegin();
00959 it != group()->members().constEnd();
00960 ++it )
00961 if((*it)->hasTransient( this, false ))
00962 result.append( *it );
00963 return result;
00964 }
00965
00966 ClientList Client::allMainClients() const
00967 {
00968 ClientList result = mainClients();
00969 foreach( const Client* cl, result )
00970 result += cl->allMainClients();
00971 return result;
00972 }
00973
00974 Client* Client::findModal( bool allow_itself )
00975 {
00976 for( ClientList::ConstIterator it = transients().constBegin();
00977 it != transients().constEnd();
00978 ++it )
00979 if( Client* ret = (*it)->findModal( true ))
00980 return ret;
00981 if( isModal() && allow_itself )
00982 return this;
00983 return NULL;
00984 }
00985
00986
00987
00988
00989 void Client::checkGroup( Group* set_group, bool force )
00990 {
00991 TRANSIENCY_CHECK( this );
00992 Group* old_group = in_group;
00993 if( old_group != NULL )
00994 old_group->ref();
00995 if( set_group != NULL )
00996 {
00997 if( set_group != in_group )
00998 {
00999 if( in_group != NULL )
01000 in_group->removeMember( this );
01001 in_group = set_group;
01002 in_group->addMember( this );
01003 }
01004 }
01005 else if( window_group != None )
01006 {
01007 Group* new_group = workspace()->findGroup( window_group );
01008 if( transientFor() != NULL && transientFor()->group() != new_group )
01009 {
01010
01011 new_group = transientFor()->group();
01012 }
01013 if( new_group == NULL )
01014 new_group = new Group( window_group, workspace());
01015 if( new_group != in_group )
01016 {
01017 if( in_group != NULL )
01018 in_group->removeMember( this );
01019 in_group = new_group;
01020 in_group->addMember( this );
01021 }
01022 }
01023 else
01024 {
01025 if( transientFor() != NULL )
01026 {
01027
01028 Group* new_group = transientFor()->group();
01029 if( new_group != in_group )
01030 {
01031 if( in_group != NULL )
01032 in_group->removeMember( this );
01033 in_group = transientFor()->group();
01034 in_group->addMember( this );
01035 }
01036 }
01037 else if( groupTransient())
01038 {
01039
01040 Group* new_group = workspace()->findClientLeaderGroup( this );
01041 if( new_group == NULL )
01042 new_group = new Group( None, workspace());
01043 if( new_group != in_group )
01044 {
01045 if( in_group != NULL )
01046 in_group->removeMember( this );
01047 in_group = new_group;
01048 in_group->addMember( this );
01049 }
01050 }
01051 else
01052 {
01053
01054
01055 Group* new_group = workspace()->findClientLeaderGroup( this );
01056 if( in_group != NULL && in_group != new_group )
01057 {
01058 in_group->removeMember( this );
01059 in_group = NULL;
01060 }
01061 if( new_group == NULL )
01062 new_group = new Group( None, workspace() );
01063 if( in_group != new_group )
01064 {
01065 in_group = new_group;
01066 in_group->addMember( this );
01067 }
01068 }
01069 }
01070 if( in_group != old_group || force )
01071 {
01072 for( ClientList::Iterator it = transients_list.begin();
01073 it != transients_list.end();
01074 )
01075 {
01076 if( (*it)->groupTransient() && (*it)->group() != group())
01077 it = transients_list.erase( it );
01078 else
01079 ++it;
01080 }
01081 if( groupTransient())
01082 {
01083
01084 if( old_group != NULL )
01085 {
01086 for( ClientList::ConstIterator it = old_group->members().constBegin();
01087 it != old_group->members().constEnd();
01088 ++it )
01089 (*it)->removeTransient( this );
01090 }
01091
01092 for( ClientList::ConstIterator it = group()->members().constBegin();
01093 it != group()->members().constEnd();
01094 ++it )
01095 {
01096 if( *it == this )
01097 break;
01098 (*it)->addTransient( this );
01099 }
01100 }
01101
01102
01103 for( ClientList::ConstIterator it = group()->members().constBegin();
01104 it != group()->members().constEnd();
01105 ++it )
01106 {
01107 if( !(*it)->isSplash())
01108 continue;
01109 if( !(*it)->groupTransient())
01110 continue;
01111 if( *it == this || hasTransient( *it, true ))
01112 continue;
01113 addTransient( *it );
01114 }
01115 }
01116 if( old_group != NULL )
01117 old_group->deref();
01118 checkGroupTransients();
01119 checkActiveModal();
01120 workspace()->updateClientLayer( this );
01121 }
01122
01123
01124 void Client::changeClientLeaderGroup( Group* gr )
01125 {
01126
01127 if( transientFor() != NULL )
01128 return;
01129
01130 if( window_group )
01131 return;
01132 checkGroup( gr );
01133 }
01134
01135 bool Client::check_active_modal = false;
01136
01137 void Client::checkActiveModal()
01138 {
01139
01140
01141
01142 Client* check_modal = workspace()->mostRecentlyActivatedClient();
01143 if( check_modal != NULL && check_modal->check_active_modal )
01144 {
01145 Client* new_modal = check_modal->findModal();
01146 if( new_modal != NULL && new_modal != check_modal )
01147 {
01148 if( !new_modal->isManaged())
01149 return;
01150 workspace()->activateClient( new_modal );
01151 }
01152 check_modal->check_active_modal = false;
01153 }
01154 }
01155
01156 }