2003-09-16 19:28:03 +00:00
|
|
|
/*****************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
|
|
|
|
Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
|
|
|
|
You can Freely distribute this program under the GNU General Public
|
|
|
|
License. See the file "COPYING" for the exact licensing terms.
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
This file contains things relevant to window grouping.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
//#define QT_CLEAN_NAMESPACE
|
|
|
|
|
|
|
|
#include "group.h"
|
|
|
|
|
|
|
|
#include "workspace.h"
|
|
|
|
#include "client.h"
|
2004-02-25 09:51:47 +00:00
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
#include <assert.h>
|
2004-02-25 09:51:47 +00:00
|
|
|
#include <kstartupinfo.h>
|
2005-07-28 14:59:42 +00:00
|
|
|
#include <QX11Info>
|
2004-02-25 09:51:47 +00:00
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
|
2003-12-10 11:28:31 +00:00
|
|
|
/*
|
|
|
|
TODO
|
|
|
|
Rename as many uses of 'transient' as possible (hasTransient->hasSubwindow,etc.),
|
|
|
|
or I'll get it backwards in half of the cases again.
|
|
|
|
*/
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
namespace KWinInternal
|
|
|
|
{
|
|
|
|
|
2006-12-13 18:48:58 +00:00
|
|
|
/*
|
|
|
|
Consistency checks for window relations. Since transients are determinated
|
|
|
|
using Client::transiency_list and main windows are determined using Client::transientFor()
|
|
|
|
or the group for group transients, these have to match both ways.
|
|
|
|
*/
|
|
|
|
//#define ENABLE_TRANSIENCY_CHECK
|
|
|
|
|
|
|
|
#ifdef NDEBUG
|
|
|
|
#undef ENABLE_TRANSIENCY_CHECK
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENABLE_TRANSIENCY_CHECK
|
2006-12-14 16:32:55 +00:00
|
|
|
static bool transiencyCheckNonExistent = false;
|
|
|
|
|
2006-12-13 18:48:58 +00:00
|
|
|
bool performTransiencyCheck()
|
|
|
|
{
|
|
|
|
bool ret = true;
|
|
|
|
ClientList clients = Workspace::self()->clients;
|
|
|
|
for( ClientList::ConstIterator it1 = clients.begin();
|
|
|
|
it1 != clients.end();
|
|
|
|
++it1 )
|
|
|
|
{
|
|
|
|
if( (*it1)->deleting )
|
|
|
|
continue;
|
2007-01-04 17:16:16 +00:00
|
|
|
if( (*it1)->in_group == NULL )
|
|
|
|
{
|
|
|
|
kdDebug() << "TC: " << *it1 << " in not in a group" << endl;
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
else if( !(*it1)->in_group->members().contains( *it1 ))
|
|
|
|
{
|
|
|
|
kdDebug() << "TC: " << *it1 << " has a group " << (*it1)->in_group << " but group does not contain it" << endl;
|
|
|
|
ret = false;
|
|
|
|
}
|
2006-12-13 18:48:58 +00:00
|
|
|
if( !(*it1)->isTransient())
|
|
|
|
{
|
|
|
|
if( !(*it1)->mainClients().isEmpty())
|
|
|
|
{
|
|
|
|
kdDebug() << "TC: " << *it1 << " is not transient, has main clients:" << (*it1)->mainClients() << endl;
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ClientList mains = (*it1)->mainClients();
|
|
|
|
for( ClientList::ConstIterator it2 = mains.begin();
|
|
|
|
it2 != mains.end();
|
|
|
|
++it2 )
|
|
|
|
{
|
2006-12-14 16:32:55 +00:00
|
|
|
if( transiencyCheckNonExistent
|
|
|
|
&& !Workspace::self()->clients.contains( *it2 )
|
2006-12-14 15:35:36 +00:00
|
|
|
&& !Workspace::self()->desktops.contains( *it2 ))
|
|
|
|
{
|
|
|
|
kDebug() << "TC:" << *it1 << " has non-existent main client " << endl;
|
|
|
|
kDebug() << "TC2:" << *it2 << endl; // this may crash
|
|
|
|
ret = false;
|
|
|
|
continue;
|
|
|
|
}
|
2006-12-13 18:48:58 +00:00
|
|
|
if( !(*it2)->transients_list.contains( *it1 ))
|
|
|
|
{
|
|
|
|
kdDebug() << "TC:" << *it1 << " has main client " << *it2 << " but main client does not have it as a transient" << endl;
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ClientList trans = (*it1)->transients_list;
|
|
|
|
for( ClientList::ConstIterator it2 = trans.begin();
|
|
|
|
it2 != trans.end();
|
|
|
|
++it2 )
|
|
|
|
{
|
2006-12-14 16:32:55 +00:00
|
|
|
if( transiencyCheckNonExistent
|
|
|
|
&& !Workspace::self()->clients.contains( *it2 )
|
2006-12-14 15:35:36 +00:00
|
|
|
&& !Workspace::self()->desktops.contains( *it2 ))
|
|
|
|
{
|
|
|
|
kDebug() << "TC:" << *it1 << " has non-existent transient " << endl;
|
|
|
|
kDebug() << "TC2:" << *it2 << endl; // this may crash
|
|
|
|
ret = false;
|
|
|
|
continue;
|
|
|
|
}
|
2006-12-13 18:48:58 +00:00
|
|
|
if( !(*it2)->mainClients().contains( *it1 ))
|
|
|
|
{
|
|
|
|
kdDebug() << "TC:" << *it1 << " has transient " << *it2 << " but transient does not have it as a main client" << endl;
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-01-04 17:16:16 +00:00
|
|
|
GroupList groups = Workspace::self()->groups;
|
|
|
|
for( GroupList::ConstIterator it1 = groups.begin();
|
|
|
|
it1 != groups.end();
|
|
|
|
++it1 )
|
|
|
|
{
|
|
|
|
ClientList members = (*it1)->members();
|
|
|
|
for( ClientList::ConstIterator it2 = members.begin();
|
|
|
|
it2 != members.end();
|
|
|
|
++it2 )
|
|
|
|
{
|
|
|
|
if( (*it2)->in_group != *it1 )
|
|
|
|
{
|
|
|
|
kdDebug() << "TC: Group " << *it1 << " contains client " << *it2 << " but client is not in that group" << endl;
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-12-13 18:48:58 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static QString transiencyCheckStartBt;
|
|
|
|
static const Client* transiencyCheckClient;
|
|
|
|
static int transiencyCheck = 0;
|
2006-12-14 16:32:55 +00:00
|
|
|
|
|
|
|
static void startTransiencyCheck( const QString& bt, const Client* c, bool ne )
|
2006-12-13 18:48:58 +00:00
|
|
|
{
|
|
|
|
if( ++transiencyCheck == 1 )
|
|
|
|
{
|
|
|
|
transiencyCheckStartBt = bt;
|
|
|
|
transiencyCheckClient = c;
|
|
|
|
}
|
2006-12-14 16:32:55 +00:00
|
|
|
if( ne )
|
|
|
|
transiencyCheckNonExistent = true;
|
2006-12-13 18:48:58 +00:00
|
|
|
}
|
|
|
|
static void checkTransiency()
|
|
|
|
{
|
|
|
|
if( --transiencyCheck == 0 )
|
|
|
|
{
|
|
|
|
if( !performTransiencyCheck())
|
|
|
|
{
|
|
|
|
kdDebug() << "BT:" << transiencyCheckStartBt << endl;
|
|
|
|
kdDebug() << "CLIENT:" << transiencyCheckClient << endl;
|
|
|
|
assert( false );
|
|
|
|
}
|
2006-12-14 16:32:55 +00:00
|
|
|
transiencyCheckNonExistent = false;
|
2006-12-13 18:48:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
class TransiencyChecker
|
|
|
|
{
|
|
|
|
public:
|
2006-12-14 16:32:55 +00:00
|
|
|
TransiencyChecker( const QString& bt, const Client*c ) { startTransiencyCheck( bt, c, false ); }
|
2006-12-13 18:48:58 +00:00
|
|
|
~TransiencyChecker() { checkTransiency(); }
|
|
|
|
};
|
|
|
|
|
2006-12-14 16:32:55 +00:00
|
|
|
void checkNonExistentClients()
|
|
|
|
{
|
|
|
|
startTransiencyCheck( kdBacktrace(), NULL, true );
|
|
|
|
checkTransiency();
|
|
|
|
}
|
|
|
|
|
2006-12-13 18:48:58 +00:00
|
|
|
#define TRANSIENCY_CHECK( c ) TransiencyChecker transiency_checker( kdBacktrace(), c )
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define TRANSIENCY_CHECK( c )
|
|
|
|
|
2006-12-14 16:32:55 +00:00
|
|
|
void checkNonExistentClients()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-12-13 18:48:58 +00:00
|
|
|
#endif
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
//********************************************
|
|
|
|
// Group
|
|
|
|
//********************************************
|
|
|
|
|
|
|
|
Group::Group( Window leader_P, Workspace* workspace_P )
|
2004-02-25 09:51:47 +00:00
|
|
|
: leader_client( NULL ),
|
2003-09-16 19:28:03 +00:00
|
|
|
leader_wid( leader_P ),
|
2004-02-25 09:51:47 +00:00
|
|
|
_workspace( workspace_P ),
|
|
|
|
leader_info( NULL ),
|
2006-12-15 13:01:19 +00:00
|
|
|
user_time( -1U ),
|
|
|
|
refcount( 0 )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2004-02-25 09:51:47 +00:00
|
|
|
if( leader_P != None )
|
|
|
|
{
|
|
|
|
leader_client = workspace_P->findClient( WindowMatchPredicate( leader_P ));
|
|
|
|
unsigned long properties[ 2 ] = { 0, NET::WM2StartupId };
|
2006-08-10 17:00:14 +00:00
|
|
|
leader_info = new NETWinInfo( display(), leader_P, workspace()->rootWin(),
|
2004-02-25 09:51:47 +00:00
|
|
|
properties, 2 );
|
|
|
|
}
|
2003-09-16 19:28:03 +00:00
|
|
|
workspace()->addGroup( this, Allowed );
|
|
|
|
}
|
|
|
|
|
2004-02-25 09:51:47 +00:00
|
|
|
Group::~Group()
|
|
|
|
{
|
|
|
|
delete leader_info;
|
|
|
|
}
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
QPixmap Group::icon() const
|
|
|
|
{
|
|
|
|
if( leader_client != NULL )
|
|
|
|
return leader_client->icon();
|
2004-02-05 18:16:53 +00:00
|
|
|
else if( leader_wid != None )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
QPixmap ic;
|
|
|
|
Client::readIcons( leader_wid, &ic, NULL );
|
|
|
|
return ic;
|
|
|
|
}
|
2004-02-05 18:16:53 +00:00
|
|
|
return QPixmap();
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPixmap Group::miniIcon() const
|
|
|
|
{
|
|
|
|
if( leader_client != NULL )
|
|
|
|
return leader_client->miniIcon();
|
2004-02-05 18:16:53 +00:00
|
|
|
else if( leader_wid != None )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
QPixmap ic;
|
|
|
|
Client::readIcons( leader_wid, NULL, &ic );
|
|
|
|
return ic;
|
|
|
|
}
|
2004-02-05 18:16:53 +00:00
|
|
|
return QPixmap();
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Group::addMember( Client* member_P )
|
|
|
|
{
|
2006-12-13 18:48:58 +00:00
|
|
|
TRANSIENCY_CHECK( member_P );
|
2003-09-16 19:28:03 +00:00
|
|
|
_members.append( member_P );
|
2006-02-06 14:47:18 +00:00
|
|
|
// kDebug() << "GROUPADD:" << this << ":" << member_P << endl;
|
|
|
|
// kDebug() << kBacktrace() << endl;
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Group::removeMember( Client* member_P )
|
|
|
|
{
|
2006-12-13 18:48:58 +00:00
|
|
|
TRANSIENCY_CHECK( member_P );
|
2006-02-06 14:47:18 +00:00
|
|
|
// kDebug() << "GROUPREMOVE:" << this << ":" << member_P << endl;
|
|
|
|
// kDebug() << kBacktrace() << endl;
|
2003-09-16 19:28:03 +00:00
|
|
|
Q_ASSERT( _members.contains( member_P ));
|
2006-04-11 17:12:05 +00:00
|
|
|
_members.removeAll( member_P );
|
2006-12-15 13:01:19 +00:00
|
|
|
// there are cases when automatic deleting of groups must be delayed,
|
|
|
|
// e.g. when removing a member and doing some operation on the possibly
|
|
|
|
// other members of the group (which would be however deleted already
|
|
|
|
// if there were no other members)
|
|
|
|
if( refcount == 0 && _members.isEmpty())
|
|
|
|
{
|
|
|
|
workspace()->removeGroup( this, Allowed );
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Group::ref()
|
|
|
|
{
|
|
|
|
++refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Group::deref()
|
|
|
|
{
|
|
|
|
if( --refcount == 0 && _members.isEmpty())
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
workspace()->removeGroup( this, Allowed );
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Group::gotLeader( Client* leader_P )
|
|
|
|
{
|
|
|
|
assert( leader_P->window() == leader_wid );
|
|
|
|
leader_client = leader_P;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Group::lostLeader()
|
|
|
|
{
|
|
|
|
assert( !_members.contains( leader_client ));
|
|
|
|
leader_client = NULL;
|
|
|
|
if( _members.isEmpty())
|
|
|
|
{
|
|
|
|
workspace()->removeGroup( this, Allowed );
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-25 09:51:47 +00:00
|
|
|
void Group::getIcons()
|
|
|
|
{
|
|
|
|
// TODO - also needs adding the flag to NETWinInfo
|
|
|
|
}
|
2003-09-16 19:28:03 +00:00
|
|
|
|
|
|
|
//***************************************
|
|
|
|
// Workspace
|
|
|
|
//***************************************
|
|
|
|
|
2004-02-05 18:16:53 +00:00
|
|
|
Group* Workspace::findGroup( Window leader ) const
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
assert( leader != None );
|
|
|
|
for( GroupList::ConstIterator it = groups.begin();
|
|
|
|
it != groups.end();
|
|
|
|
++it )
|
|
|
|
if( (*it)->leader() == leader )
|
|
|
|
return *it;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-02-05 18:16:53 +00:00
|
|
|
// Client is group transient, but has no group set. Try to find
|
|
|
|
// group with windows with the same client leader.
|
|
|
|
Group* Workspace::findClientLeaderGroup( const Client* c ) const
|
|
|
|
{
|
2006-12-13 18:48:58 +00:00
|
|
|
TRANSIENCY_CHECK( c );
|
2004-04-29 09:43:01 +00:00
|
|
|
Group* ret = NULL;
|
2004-02-05 18:16:53 +00:00
|
|
|
for( ClientList::ConstIterator it = clients.begin();
|
|
|
|
it != clients.end();
|
|
|
|
++it )
|
|
|
|
{
|
|
|
|
if( *it == c )
|
|
|
|
continue;
|
|
|
|
if( (*it)->wmClientLeader() == c->wmClientLeader())
|
2004-04-29 09:43:01 +00:00
|
|
|
{
|
|
|
|
if( ret == NULL || ret == (*it)->group())
|
|
|
|
ret = (*it)->group();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// There are already two groups with the same client leader.
|
|
|
|
// This most probably means the app uses group transients without
|
|
|
|
// setting group for its windows. Merging the two groups is a bad
|
|
|
|
// hack, but there's no really good solution for this case.
|
2006-12-13 18:29:43 +00:00
|
|
|
ClientList old_group = (*it)->group()->members();
|
2004-04-29 09:43:01 +00:00
|
|
|
// old_group autodeletes when being empty
|
2006-12-13 18:29:43 +00:00
|
|
|
for( int pos = 0;
|
|
|
|
pos < old_group.count();
|
|
|
|
++pos )
|
2004-04-29 09:43:01 +00:00
|
|
|
{
|
2006-12-13 18:29:43 +00:00
|
|
|
Client* tmp = old_group[ pos ];
|
|
|
|
if( tmp != c )
|
|
|
|
tmp->changeClientLeaderGroup( ret );
|
2004-04-29 09:43:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-02-05 18:16:53 +00:00
|
|
|
}
|
2004-04-29 09:43:01 +00:00
|
|
|
return ret;
|
2004-02-05 18:16:53 +00:00
|
|
|
}
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
void Workspace::updateMinimizedOfTransients( Client* c )
|
|
|
|
{
|
|
|
|
// if mainwindow is minimized or shaded, minimize transients too
|
|
|
|
if ( c->isMinimized() || c->isShade() )
|
|
|
|
{
|
|
|
|
for( ClientList::ConstIterator it = c->transients().begin();
|
|
|
|
it != c->transients().end();
|
|
|
|
++it )
|
|
|
|
{
|
|
|
|
if( !(*it)->isMinimized()
|
|
|
|
&& !(*it)->isTopMenu() ) // topmenus are not minimized, they're hidden
|
|
|
|
{
|
2004-03-01 18:00:07 +00:00
|
|
|
(*it)->minimize( true ); // avoid animation
|
2003-09-16 19:28:03 +00:00
|
|
|
updateMinimizedOfTransients( (*it) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // else unmiminize the transients
|
|
|
|
for( ClientList::ConstIterator it = c->transients().begin();
|
|
|
|
it != c->transients().end();
|
|
|
|
++it )
|
|
|
|
{
|
|
|
|
if( (*it)->isMinimized()
|
|
|
|
&& !(*it)->isTopMenu())
|
|
|
|
{
|
2004-03-01 18:00:07 +00:00
|
|
|
(*it)->unminimize( true ); // avoid animation
|
2003-09-16 19:28:03 +00:00
|
|
|
updateMinimizedOfTransients( (*it) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Sets the client \a c's transient windows' on_all_desktops property to \a on_all_desktops.
|
|
|
|
*/
|
|
|
|
void Workspace::updateOnAllDesktopsOfTransients( Client* c )
|
|
|
|
{
|
|
|
|
for( ClientList::ConstIterator it = c->transients().begin();
|
|
|
|
it != c->transients().end();
|
|
|
|
++it)
|
|
|
|
{
|
|
|
|
if( (*it)->isOnAllDesktops() != c->isOnAllDesktops())
|
|
|
|
(*it)->setOnAllDesktops( c->isOnAllDesktops());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// A new window has been mapped. Check if it's not a mainwindow for some already existing transient window.
|
|
|
|
void Workspace::checkTransients( Window w )
|
|
|
|
{
|
2006-12-13 18:48:58 +00:00
|
|
|
TRANSIENCY_CHECK( NULL );
|
2003-09-16 19:28:03 +00:00
|
|
|
for( ClientList::ConstIterator it = clients.begin();
|
|
|
|
it != clients.end();
|
|
|
|
++it )
|
|
|
|
(*it)->checkTransient( w );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//****************************************
|
|
|
|
// Client
|
|
|
|
//****************************************
|
|
|
|
|
|
|
|
// hacks for broken apps here
|
2004-02-23 12:47:28 +00:00
|
|
|
// all resource classes are forced to be lowercase
|
2003-09-16 19:28:03 +00:00
|
|
|
bool Client::resourceMatch( const Client* c1, const Client* c2 )
|
|
|
|
{
|
|
|
|
// xv has "xv" as resource name, and different strings starting with "XV" as resource class
|
2004-02-23 12:47:28 +00:00
|
|
|
if( qstrncmp( c1->resourceClass(), "xv", 2 ) == 0 && c1->resourceName() == "xv" )
|
|
|
|
return qstrncmp( c2->resourceClass(), "xv", 2 ) == 0 && c2->resourceName() == "xv";
|
2003-09-16 19:28:03 +00:00
|
|
|
// Mozilla has "Mozilla" as resource name, and different strings as resource class
|
2004-02-23 12:47:28 +00:00
|
|
|
if( c1->resourceName() == "mozilla" )
|
|
|
|
return c2->resourceName() == "mozilla";
|
2003-09-16 19:28:03 +00:00
|
|
|
return c1->resourceClass() == c2->resourceClass();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Client::belongToSameApplication( const Client* c1, const Client* c2, bool active_hack )
|
|
|
|
{
|
|
|
|
bool same_app = false;
|
2006-08-02 16:27:34 +00:00
|
|
|
|
|
|
|
// tests that definitely mean they belong together
|
2003-11-19 10:44:36 +00:00
|
|
|
if( c1 == c2 )
|
|
|
|
same_app = true;
|
|
|
|
else if( c1->isTransient() && c2->hasTransient( c1, true ))
|
2003-09-16 19:28:03 +00:00
|
|
|
same_app = true; // c1 has c2 as mainwindow
|
|
|
|
else if( c2->isTransient() && c1->hasTransient( c2, true ))
|
|
|
|
same_app = true; // c2 has c1 as mainwindow
|
2006-08-02 16:27:34 +00:00
|
|
|
else if( c1->group() == c2->group())
|
|
|
|
same_app = true; // same group
|
|
|
|
else if( c1->wmClientLeader() == c2->wmClientLeader()
|
|
|
|
&& c1->wmClientLeader() != c1->window() // if WM_CLIENT_LEADER is not set, it returns window(),
|
|
|
|
&& c2->wmClientLeader() != c2->window()) // don't use in this test then
|
|
|
|
same_app = true; // same client leader
|
|
|
|
|
|
|
|
// tests that mean they most probably don't belong together
|
2003-09-16 19:28:03 +00:00
|
|
|
else if( c1->pid() != c2->pid()
|
2004-05-28 13:54:20 +00:00
|
|
|
|| c1->wmClientMachine( false ) != c2->wmClientMachine( false ))
|
2003-09-16 19:28:03 +00:00
|
|
|
; // different processes
|
2003-10-24 09:00:40 +00:00
|
|
|
else if( c1->wmClientLeader() != c2->wmClientLeader()
|
|
|
|
&& c1->wmClientLeader() != c1->window() // if WM_CLIENT_LEADER is not set, it returns window(),
|
|
|
|
&& c2->wmClientLeader() != c2->window()) // don't use in this test then
|
2003-09-16 19:28:03 +00:00
|
|
|
; // different client leader
|
|
|
|
else if( !resourceMatch( c1, c2 ))
|
|
|
|
; // different apps
|
|
|
|
else if( !sameAppWindowRoleMatch( c1, c2, active_hack ))
|
|
|
|
; // "different" apps
|
2003-11-13 17:19:49 +00:00
|
|
|
else if( c1->pid() == 0 || c2->pid() == 0 )
|
|
|
|
; // old apps that don't have _NET_WM_PID, consider them different
|
2003-12-02 18:11:24 +00:00
|
|
|
// if they weren't found to match above
|
2003-11-13 18:27:31 +00:00
|
|
|
else
|
2003-09-16 19:28:03 +00:00
|
|
|
same_app = true; // looks like it's the same app
|
2006-08-02 16:27:34 +00:00
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
return same_app;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Non-transient windows with window role containing '#' are always
|
|
|
|
// considered belonging to different applications (unless
|
|
|
|
// the window role is exactly the same). KMainWindow sets
|
|
|
|
// window role this way by default, and different KMainWindow
|
|
|
|
// usually "are" different application from user's point of view.
|
|
|
|
// This help with no-focus-stealing for e.g. konqy reusing.
|
|
|
|
// On the other hand, if one of the windows is active, they are
|
|
|
|
// considered belonging to the same application. This is for
|
|
|
|
// the cases when opening new mainwindow directly from the application,
|
|
|
|
// e.g. 'Open New Window' in konqy ( active_hack == true ).
|
|
|
|
bool Client::sameAppWindowRoleMatch( const Client* c1, const Client* c2, bool active_hack )
|
|
|
|
{
|
|
|
|
if( c1->isTransient())
|
|
|
|
{
|
|
|
|
while( c1->transientFor() != NULL )
|
|
|
|
c1 = c1->transientFor();
|
|
|
|
if( c1->groupTransient())
|
2004-02-05 18:16:53 +00:00
|
|
|
return c1->group() == c2->group();
|
|
|
|
#if 0
|
2003-09-16 19:28:03 +00:00
|
|
|
// if a group transient is in its own group, it didn't possibly have a group,
|
|
|
|
// and therefore should be considered belonging to the same app like
|
|
|
|
// all other windows from the same app
|
|
|
|
|| c1->group()->leaderClient() == c1 || c2->group()->leaderClient() == c2;
|
2004-02-05 18:16:53 +00:00
|
|
|
#endif
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
if( c2->isTransient())
|
|
|
|
{
|
|
|
|
while( c2->transientFor() != NULL )
|
|
|
|
c2 = c2->transientFor();
|
|
|
|
if( c2->groupTransient())
|
2004-02-05 18:16:53 +00:00
|
|
|
return c1->group() == c2->group();
|
|
|
|
#if 0
|
2003-09-16 19:28:03 +00:00
|
|
|
|| c1->group()->leaderClient() == c1 || c2->group()->leaderClient() == c2;
|
2004-02-05 18:16:53 +00:00
|
|
|
#endif
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2006-04-09 20:16:13 +00:00
|
|
|
int pos1 = c1->windowRole().indexOf( '#' );
|
|
|
|
int pos2 = c2->windowRole().indexOf( '#' );
|
2003-09-16 19:28:03 +00:00
|
|
|
if(( pos1 >= 0 && pos2 >= 0 )
|
|
|
|
||
|
|
|
|
// hacks here
|
|
|
|
// Mozilla has resourceName() and resourceClass() swapped
|
2004-02-23 12:47:28 +00:00
|
|
|
c1->resourceName() == "mozilla" && c2->resourceName() == "mozilla" )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
if( !active_hack ) // without the active hack for focus stealing prevention,
|
|
|
|
return c1 == c2; // different mainwindows are always different apps
|
|
|
|
if( !c1->isActive() && !c2->isActive())
|
|
|
|
return c1 == c2;
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Transiency stuff: ICCCM 4.1.2.6, NETWM 7.3
|
|
|
|
|
|
|
|
WM_TRANSIENT_FOR is basically means "this is my mainwindow".
|
|
|
|
For NET::Unknown windows, transient windows are considered to be NET::Dialog
|
|
|
|
windows, for compatibility with non-NETWM clients. KWin may adjust the value
|
|
|
|
of this property in some cases (window pointing to itself or creating a loop,
|
|
|
|
keeping NET::Splash windows above other windows from the same app, etc.).
|
|
|
|
|
|
|
|
Client::transient_for_id is the value of the WM_TRANSIENT_FOR property, after
|
|
|
|
possibly being adjusted by KWin. Client::transient_for points to the Client
|
|
|
|
this Client is transient for, or is NULL. If Client::transient_for_id is
|
|
|
|
poiting to the root window, the window is considered to be transient
|
|
|
|
for the whole window group, as suggested in NETWM 7.3.
|
|
|
|
|
|
|
|
In the case of group transient window, Client::transient_for is NULL,
|
|
|
|
and Client::groupTransient() returns true. Such window is treated as
|
2003-12-10 11:27:20 +00:00
|
|
|
if it were transient for every window in its window group that has been
|
|
|
|
mapped _before_ it (or, to be exact, was added to the same group before it).
|
|
|
|
Otherwise two group transients can create loops, which can lead very very
|
|
|
|
nasty things (bug #67914 and all its dupes).
|
2003-09-16 19:28:03 +00:00
|
|
|
|
|
|
|
Client::original_transient_for_id is the value of the property, which
|
|
|
|
may be different if Client::transient_for_id if e.g. forcing NET::Splash
|
|
|
|
to be kept on top of its window group, or when the mainwindow is not mapped
|
|
|
|
yet, in which case the window is temporarily made group transient,
|
|
|
|
and when the mainwindow is mapped, transiency is re-evaluated.
|
|
|
|
|
|
|
|
This can get a bit complicated with with e.g. two Konqueror windows created
|
|
|
|
by the same process. They should ideally appear like two independent applications
|
|
|
|
to the user. This should be accomplished by all windows in the same process
|
|
|
|
having the same window group (needs to be changed in Qt at the moment), and
|
|
|
|
using non-group transients poiting to their relevant mainwindow for toolwindows
|
|
|
|
etc. KWin should handle both group and non-group transient dialogs well.
|
|
|
|
|
|
|
|
In other words:
|
|
|
|
- non-transient windows : isTransient() == false
|
|
|
|
- normal transients : transientFor() != NULL
|
|
|
|
- group transients : groupTransient() == true
|
|
|
|
|
|
|
|
- list of mainwindows : mainClients() (call once and loop over the result)
|
|
|
|
- list of transients : transients()
|
|
|
|
- every window in the group : group()->members()
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Client::readTransient()
|
|
|
|
{
|
2006-12-13 18:48:58 +00:00
|
|
|
TRANSIENCY_CHECK( this );
|
2003-09-16 19:28:03 +00:00
|
|
|
Window new_transient_for_id;
|
2006-08-10 17:00:14 +00:00
|
|
|
if( XGetTransientForHint( display(), window(), &new_transient_for_id ))
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
original_transient_for_id = new_transient_for_id;
|
|
|
|
new_transient_for_id = verifyTransientFor( new_transient_for_id, true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
original_transient_for_id = None;
|
|
|
|
new_transient_for_id = verifyTransientFor( None, false );
|
|
|
|
}
|
|
|
|
setTransient( new_transient_for_id );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::setTransient( Window new_transient_for_id )
|
|
|
|
{
|
2006-12-13 18:48:58 +00:00
|
|
|
TRANSIENCY_CHECK( this );
|
2003-09-16 19:28:03 +00:00
|
|
|
if( new_transient_for_id != transient_for_id )
|
|
|
|
{
|
|
|
|
removeFromMainClients();
|
|
|
|
transient_for = NULL;
|
|
|
|
transient_for_id = new_transient_for_id;
|
2004-02-05 18:16:53 +00:00
|
|
|
if( transient_for_id != None && !groupTransient())
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2004-02-05 18:16:53 +00:00
|
|
|
transient_for = workspace()->findClient( WindowMatchPredicate( transient_for_id ));
|
|
|
|
assert( transient_for != NULL ); // verifyTransient() had to check this
|
|
|
|
transient_for->addTransient( this );
|
2004-05-28 11:33:36 +00:00
|
|
|
} // checkGroup() will check 'check_active_modal'
|
2004-04-29 14:13:08 +00:00
|
|
|
checkGroup( NULL, true ); // force, because transiency has changed
|
2004-07-27 13:13:52 +00:00
|
|
|
if( isTopMenu())
|
|
|
|
workspace()->updateCurrentTopMenu();
|
2003-09-16 19:28:03 +00:00
|
|
|
workspace()->updateClientLayer( this );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::removeFromMainClients()
|
|
|
|
{
|
2006-12-13 18:48:58 +00:00
|
|
|
TRANSIENCY_CHECK( this );
|
2003-09-16 19:28:03 +00:00
|
|
|
if( transientFor() != NULL )
|
|
|
|
transientFor()->removeTransient( this );
|
|
|
|
if( groupTransient())
|
|
|
|
{
|
|
|
|
for( ClientList::ConstIterator it = group()->members().begin();
|
|
|
|
it != group()->members().end();
|
|
|
|
++it )
|
|
|
|
(*it)->removeTransient( this );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-19 14:53:39 +00:00
|
|
|
// *sigh* this transiency handling is madness :(
|
|
|
|
// This one is called when destroying/releasing a window.
|
|
|
|
// It makes sure this client is removed from all grouping
|
|
|
|
// related lists.
|
|
|
|
void Client::cleanGrouping()
|
|
|
|
{
|
2006-12-13 18:48:58 +00:00
|
|
|
TRANSIENCY_CHECK( this );
|
2006-02-06 14:47:18 +00:00
|
|
|
// kDebug() << "CLEANGROUPING:" << this << endl;
|
2003-09-19 14:53:39 +00:00
|
|
|
// for( ClientList::ConstIterator it = group()->members().begin();
|
|
|
|
// it != group()->members().end();
|
|
|
|
// ++it )
|
2006-02-06 14:47:18 +00:00
|
|
|
// kDebug() << "CL:" << *it << endl;
|
2003-09-19 14:53:39 +00:00
|
|
|
// ClientList mains;
|
|
|
|
// mains = mainClients();
|
|
|
|
// for( ClientList::ConstIterator it = mains.begin();
|
|
|
|
// it != mains.end();
|
|
|
|
// ++it )
|
2006-02-06 14:47:18 +00:00
|
|
|
// kDebug() << "MN:" << *it << endl;
|
2003-09-19 14:53:39 +00:00
|
|
|
removeFromMainClients();
|
2006-02-06 14:47:18 +00:00
|
|
|
// kDebug() << "CLEANGROUPING2:" << this << endl;
|
2003-09-19 14:53:39 +00:00
|
|
|
// for( ClientList::ConstIterator it = group()->members().begin();
|
|
|
|
// it != group()->members().end();
|
|
|
|
// ++it )
|
2006-02-06 14:47:18 +00:00
|
|
|
// kDebug() << "CL2:" << *it << endl;
|
2003-09-19 14:53:39 +00:00
|
|
|
// mains = mainClients();
|
|
|
|
// for( ClientList::ConstIterator it = mains.begin();
|
|
|
|
// it != mains.end();
|
|
|
|
// ++it )
|
2006-02-06 14:47:18 +00:00
|
|
|
// kDebug() << "MN2:" << *it << endl;
|
2003-09-19 14:53:39 +00:00
|
|
|
for( ClientList::ConstIterator it = transients_list.begin();
|
|
|
|
it != transients_list.end();
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if( (*it)->transientFor() == this )
|
|
|
|
{
|
|
|
|
ClientList::ConstIterator it2 = it++;
|
|
|
|
removeTransient( *it2 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
++it;
|
|
|
|
}
|
2006-02-06 14:47:18 +00:00
|
|
|
// kDebug() << "CLEANGROUPING3:" << this << endl;
|
2003-09-19 14:53:39 +00:00
|
|
|
// for( ClientList::ConstIterator it = group()->members().begin();
|
|
|
|
// it != group()->members().end();
|
|
|
|
// ++it )
|
2006-02-06 14:47:18 +00:00
|
|
|
// kDebug() << "CL3:" << *it << endl;
|
2003-09-19 14:53:39 +00:00
|
|
|
// mains = mainClients();
|
|
|
|
// for( ClientList::ConstIterator it = mains.begin();
|
|
|
|
// it != mains.end();
|
|
|
|
// ++it )
|
2006-02-06 14:47:18 +00:00
|
|
|
// kDebug() << "MN3:" << *it << endl;
|
2003-09-19 14:53:39 +00:00
|
|
|
// HACK
|
|
|
|
// removeFromMainClients() did remove 'this' from transient
|
|
|
|
// lists of all group members, but then made windows that
|
|
|
|
// were transient for 'this' group transient, which again
|
|
|
|
// added 'this' to those transient lists :(
|
|
|
|
ClientList group_members = group()->members();
|
|
|
|
group()->removeMember( this );
|
|
|
|
in_group = NULL;
|
|
|
|
for( ClientList::ConstIterator it = group_members.begin();
|
|
|
|
it != group_members.end();
|
|
|
|
++it )
|
|
|
|
(*it)->removeTransient( this );
|
2006-02-06 14:47:18 +00:00
|
|
|
// kDebug() << "CLEANGROUPING4:" << this << endl;
|
2003-09-19 14:53:39 +00:00
|
|
|
// for( ClientList::ConstIterator it = group_members.begin();
|
|
|
|
// it != group_members.end();
|
|
|
|
// ++it )
|
2006-02-06 14:47:18 +00:00
|
|
|
// kDebug() << "CL4:" << *it << endl;
|
2003-09-19 14:53:39 +00:00
|
|
|
}
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
// Make sure that no group transient is considered transient
|
2003-11-21 14:05:20 +00:00
|
|
|
// for a window that is (directly or indirectly) transient for it
|
|
|
|
// (including another group transients).
|
|
|
|
// Non-group transients not causing loops are checked in verifyTransientFor().
|
2003-09-16 19:28:03 +00:00
|
|
|
void Client::checkGroupTransients()
|
|
|
|
{
|
2006-12-13 18:48:58 +00:00
|
|
|
TRANSIENCY_CHECK( this );
|
2003-09-16 19:28:03 +00:00
|
|
|
for( ClientList::ConstIterator it1 = group()->members().begin();
|
|
|
|
it1 != group()->members().end();
|
|
|
|
++it1 )
|
|
|
|
{
|
2003-11-19 12:10:48 +00:00
|
|
|
if( !(*it1)->groupTransient()) // check all group transients in the group
|
|
|
|
continue; // TODO optimize to check only the changed ones?
|
|
|
|
for( ClientList::ConstIterator it2 = group()->members().begin();
|
|
|
|
it2 != group()->members().end();
|
|
|
|
++it2 ) // group transients can be transient only for others in the group,
|
|
|
|
{ // so don't make them transient for the ones that are transient for it
|
|
|
|
if( *it1 == *it2 )
|
2003-09-16 19:28:03 +00:00
|
|
|
continue;
|
2003-11-19 12:10:48 +00:00
|
|
|
for( Client* cl = (*it2)->transientFor();
|
|
|
|
cl != NULL;
|
|
|
|
cl = cl->transientFor())
|
|
|
|
{
|
|
|
|
if( cl == *it1 )
|
2003-11-21 14:05:20 +00:00
|
|
|
{ // don't use removeTransient(), that would modify *it2 too
|
2006-04-11 17:12:05 +00:00
|
|
|
(*it2)->transients_list.removeAll( *it1 );
|
2003-11-19 12:10:48 +00:00
|
|
|
continue;
|
|
|
|
}
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2003-11-21 14:05:20 +00:00
|
|
|
// if *it1 and *it2 are both group transients, and are transient for each other,
|
|
|
|
// make only *it2 transient for *it1 (i.e. subwindow), as *it2 came later,
|
|
|
|
// and should be therefore on top of *it1
|
2003-11-27 14:37:55 +00:00
|
|
|
// TODO This could possibly be optimized, it also requires hasTransient() to check for loops.
|
2003-11-21 14:05:20 +00:00
|
|
|
if( (*it2)->groupTransient() && (*it1)->hasTransient( *it2, true ) && (*it2)->hasTransient( *it1, true ))
|
2006-04-11 17:12:05 +00:00
|
|
|
(*it2)->transients_list.removeAll( *it1 );
|
2005-02-28 13:43:00 +00:00
|
|
|
// if there are already windows W1 and W2, W2 being transient for W1, and group transient W3
|
|
|
|
// is added, make it transient only for W2, not for W1, because it's already indirectly
|
|
|
|
// transient for it - the indirect transiency actually shouldn't break anything,
|
|
|
|
// but it can lead to exponentially expensive operations (#95231)
|
|
|
|
// TODO this is pretty slow as well
|
|
|
|
for( ClientList::ConstIterator it3 = group()->members().begin();
|
|
|
|
it3 != group()->members().end();
|
|
|
|
++it3 )
|
|
|
|
{
|
|
|
|
if( *it1 == *it2 || *it2 == *it3 || *it1 == *it3 )
|
|
|
|
continue;
|
|
|
|
if( (*it2)->hasTransient( *it1, false ) && (*it3)->hasTransient( *it1, false ))
|
|
|
|
{
|
|
|
|
if( (*it2)->hasTransient( *it3, true ))
|
2006-04-11 17:12:05 +00:00
|
|
|
(*it3)->transients_list.removeAll( *it1 );
|
2005-02-28 13:43:00 +00:00
|
|
|
if( (*it3)->hasTransient( *it2, true ))
|
2006-04-11 17:12:05 +00:00
|
|
|
(*it2)->transients_list.removeAll( *it1 );
|
2005-02-28 13:43:00 +00:00
|
|
|
}
|
|
|
|
}
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Check that the window is not transient for itself, and similar nonsense.
|
|
|
|
*/
|
|
|
|
Window Client::verifyTransientFor( Window new_transient_for, bool defined )
|
|
|
|
{
|
|
|
|
Window new_property_value = new_transient_for;
|
|
|
|
// make sure splashscreens are shown above all their app's windows, even though
|
|
|
|
// they're in Normal layer
|
|
|
|
if( isSplash() && new_transient_for == None )
|
|
|
|
new_transient_for = workspace()->rootWin();
|
|
|
|
if( new_transient_for == None )
|
|
|
|
if( defined ) // sometimes WM_TRANSIENT_FOR is set to None, instead of root window
|
|
|
|
new_property_value = new_transient_for = workspace()->rootWin();
|
|
|
|
else
|
|
|
|
return None;
|
|
|
|
if( new_transient_for == window()) // pointing to self
|
|
|
|
{ // also fix the property itself
|
2006-02-06 14:47:18 +00:00
|
|
|
kWarning( 1216 ) << "Client " << this << " has WM_TRANSIENT_FOR poiting to itself." << endl;
|
2003-09-16 19:28:03 +00:00
|
|
|
new_property_value = new_transient_for = workspace()->rootWin();
|
|
|
|
}
|
|
|
|
// The transient_for window may be embedded in another application,
|
|
|
|
// so kwin cannot see it. Try to find the managed client for the
|
|
|
|
// window and fix the transient_for property if possible.
|
|
|
|
WId before_search = new_transient_for;
|
|
|
|
while( new_transient_for != None
|
|
|
|
&& new_transient_for != workspace()->rootWin()
|
|
|
|
&& !workspace()->findClient( WindowMatchPredicate( new_transient_for )))
|
|
|
|
{
|
|
|
|
Window root_return, parent_return;
|
|
|
|
Window* wins = NULL;
|
|
|
|
unsigned int nwins;
|
2006-08-10 17:00:14 +00:00
|
|
|
int r = XQueryTree(display(), new_transient_for, &root_return, &parent_return, &wins, &nwins);
|
2003-09-16 19:28:03 +00:00
|
|
|
if ( wins )
|
|
|
|
XFree((void *) wins);
|
|
|
|
if ( r == 0)
|
|
|
|
break;
|
|
|
|
new_transient_for = parent_return;
|
|
|
|
}
|
2003-09-29 11:20:12 +00:00
|
|
|
if( Client* new_transient_for_client = workspace()->findClient( WindowMatchPredicate( new_transient_for )))
|
|
|
|
{
|
|
|
|
if( new_transient_for != before_search )
|
|
|
|
{
|
2006-02-06 14:47:18 +00:00
|
|
|
kDebug( 1212 ) << "Client " << this << " has WM_TRANSIENT_FOR poiting to non-toplevel window "
|
2003-09-29 11:20:12 +00:00
|
|
|
<< before_search << ", child of " << new_transient_for_client << ", adjusting." << endl;
|
|
|
|
new_property_value = new_transient_for; // also fix the property
|
|
|
|
}
|
|
|
|
}
|
2003-09-16 19:28:03 +00:00
|
|
|
else
|
2003-09-29 11:20:12 +00:00
|
|
|
new_transient_for = before_search; // nice try
|
2003-09-16 19:28:03 +00:00
|
|
|
// loop detection
|
|
|
|
// group transients cannot cause loops, because they're considered transient only for non-transient
|
|
|
|
// windows in the group
|
|
|
|
int count = 20;
|
|
|
|
Window loop_pos = new_transient_for;
|
|
|
|
while( loop_pos != None && loop_pos != workspace()->rootWin())
|
|
|
|
{
|
|
|
|
Client* pos = workspace()->findClient( WindowMatchPredicate( loop_pos ));
|
|
|
|
if( pos == NULL )
|
|
|
|
break;
|
|
|
|
loop_pos = pos->transient_for_id;
|
|
|
|
if( --count == 0 )
|
|
|
|
{
|
2006-02-06 14:47:18 +00:00
|
|
|
kWarning( 1216 ) << "Client " << this << " caused WM_TRANSIENT_FOR loop." << endl;
|
2003-09-16 19:28:03 +00:00
|
|
|
new_transient_for = workspace()->rootWin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( new_transient_for != workspace()->rootWin()
|
|
|
|
&& workspace()->findClient( WindowMatchPredicate( new_transient_for )) == NULL )
|
|
|
|
{ // it's transient for a specific window, but that window is not mapped
|
|
|
|
new_transient_for = workspace()->rootWin();
|
|
|
|
}
|
|
|
|
if( new_property_value != original_transient_for_id )
|
2006-08-10 17:00:14 +00:00
|
|
|
XSetTransientForHint( display(), window(), new_property_value );
|
2003-09-16 19:28:03 +00:00
|
|
|
return new_transient_for;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::addTransient( Client* cl )
|
|
|
|
{
|
2006-12-13 18:48:58 +00:00
|
|
|
TRANSIENCY_CHECK( this );
|
2003-09-16 19:28:03 +00:00
|
|
|
assert( !transients_list.contains( cl ));
|
2003-11-19 12:10:48 +00:00
|
|
|
// assert( !cl->hasTransient( this, true )); will be fixed in checkGroupTransients()
|
2003-09-24 16:56:49 +00:00
|
|
|
assert( cl != this );
|
2003-09-16 19:28:03 +00:00
|
|
|
transients_list.append( cl );
|
2004-05-28 11:33:36 +00:00
|
|
|
if( workspace()->mostRecentlyActivatedClient() == this && cl->isModal())
|
|
|
|
check_active_modal = true;
|
2006-02-06 14:47:18 +00:00
|
|
|
// kDebug() << "ADDTRANS:" << this << ":" << cl << endl;
|
|
|
|
// kDebug() << kBacktrace() << endl;
|
2003-11-21 14:05:20 +00:00
|
|
|
// for( ClientList::ConstIterator it = transients_list.begin();
|
|
|
|
// it != transients_list.end();
|
|
|
|
// ++it )
|
2006-02-06 14:47:18 +00:00
|
|
|
// kDebug() << "AT:" << (*it) << endl;
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Client::removeTransient( Client* cl )
|
|
|
|
{
|
2006-12-13 18:48:58 +00:00
|
|
|
TRANSIENCY_CHECK( this );
|
2006-02-06 14:47:18 +00:00
|
|
|
// kDebug() << "REMOVETRANS:" << this << ":" << cl << endl;
|
|
|
|
// kDebug() << kBacktrace() << endl;
|
2006-04-11 17:12:05 +00:00
|
|
|
transients_list.removeAll( cl );
|
2003-09-19 14:53:39 +00:00
|
|
|
// cl is transient for this, but this is going away
|
|
|
|
// make cl group transient
|
2003-09-16 19:28:03 +00:00
|
|
|
if( cl->transientFor() == this )
|
|
|
|
{
|
|
|
|
cl->transient_for_id = None;
|
|
|
|
cl->transient_for = NULL; // SELI
|
2003-09-19 14:53:39 +00:00
|
|
|
// SELI cl->setTransient( workspace()->rootWin());
|
|
|
|
cl->setTransient( None );
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// A new window has been mapped. Check if it's not a mainwindow for this already existing window.
|
|
|
|
void Client::checkTransient( Window w )
|
|
|
|
{
|
2006-12-13 18:48:58 +00:00
|
|
|
TRANSIENCY_CHECK( this );
|
2003-09-16 19:28:03 +00:00
|
|
|
if( original_transient_for_id != w )
|
|
|
|
return;
|
2003-09-24 16:56:49 +00:00
|
|
|
w = verifyTransientFor( w, true );
|
2003-09-16 19:28:03 +00:00
|
|
|
setTransient( w );
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns true if cl is the transient_for window for this client,
|
|
|
|
// or recursively the transient_for window
|
|
|
|
bool Client::hasTransient( const Client* cl, bool indirect ) const
|
|
|
|
{
|
2003-11-27 14:37:55 +00:00
|
|
|
// checkGroupTransients() uses this to break loops, so hasTransient() must detect them
|
|
|
|
ConstClientList set;
|
|
|
|
return hasTransientInternal( cl, indirect, set );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Client::hasTransientInternal( const Client* cl, bool indirect, ConstClientList& set ) const
|
|
|
|
{
|
2003-09-16 19:28:03 +00:00
|
|
|
if( cl->transientFor() != NULL )
|
|
|
|
{
|
|
|
|
if( cl->transientFor() == this )
|
|
|
|
return true;
|
|
|
|
if( !indirect )
|
|
|
|
return false;
|
2005-03-23 14:52:54 +00:00
|
|
|
if( set.contains( cl ))
|
|
|
|
return false;
|
|
|
|
set.append( cl );
|
2003-11-27 14:37:55 +00:00
|
|
|
return hasTransientInternal( cl->transientFor(), indirect, set );
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
if( !cl->isTransient())
|
|
|
|
return false;
|
|
|
|
if( group() != cl->group())
|
|
|
|
return false;
|
|
|
|
// cl is group transient, search from top
|
|
|
|
if( transients().contains( const_cast< Client* >( cl )))
|
|
|
|
return true;
|
|
|
|
if( !indirect )
|
|
|
|
return false;
|
2005-03-23 14:52:54 +00:00
|
|
|
if( set.contains( this ))
|
|
|
|
return false;
|
|
|
|
set.append( this );
|
2003-09-16 19:28:03 +00:00
|
|
|
for( ClientList::ConstIterator it = transients().begin();
|
|
|
|
it != transients().end();
|
|
|
|
++it )
|
2003-11-27 14:37:55 +00:00
|
|
|
if( (*it)->hasTransientInternal( cl, indirect, set ))
|
2003-09-16 19:28:03 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClientList Client::mainClients() const
|
|
|
|
{
|
|
|
|
if( !isTransient())
|
|
|
|
return ClientList();
|
|
|
|
if( transientFor() != NULL )
|
|
|
|
return ClientList() << const_cast< Client* >( transientFor());
|
|
|
|
ClientList result;
|
|
|
|
for( ClientList::ConstIterator it = group()->members().begin();
|
|
|
|
it != group()->members().end();
|
|
|
|
++it )
|
2003-12-11 09:09:38 +00:00
|
|
|
if((*it)->hasTransient( this, false ))
|
2003-09-16 19:28:03 +00:00
|
|
|
result.append( *it );
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Client* Client::findModal()
|
|
|
|
{
|
|
|
|
for( ClientList::ConstIterator it = transients().begin();
|
|
|
|
it != transients().end();
|
|
|
|
++it )
|
|
|
|
if( Client* ret = (*it)->findModal())
|
|
|
|
return ret;
|
|
|
|
if( isModal())
|
|
|
|
return this;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Client::window_group only holds the contents of the hint,
|
|
|
|
// but it should be used only to find the group, not for anything else
|
2004-04-29 09:43:01 +00:00
|
|
|
// Argument is only when some specific group needs to be set.
|
2004-04-29 14:13:08 +00:00
|
|
|
void Client::checkGroup( Group* set_group, bool force )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2006-12-13 18:48:58 +00:00
|
|
|
TRANSIENCY_CHECK( this );
|
2003-11-12 09:02:37 +00:00
|
|
|
Group* old_group = in_group;
|
2006-12-15 13:01:19 +00:00
|
|
|
if( old_group != NULL )
|
|
|
|
old_group->ref(); // turn off automatic deleting
|
2004-04-29 09:43:01 +00:00
|
|
|
if( set_group != NULL )
|
|
|
|
{
|
|
|
|
if( set_group != in_group )
|
|
|
|
{
|
|
|
|
if( in_group != NULL )
|
|
|
|
in_group->removeMember( this );
|
|
|
|
in_group = set_group;
|
|
|
|
in_group->addMember( this );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( window_group != None )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
Group* new_group = workspace()->findGroup( window_group );
|
|
|
|
if( transientFor() != NULL && transientFor()->group() != new_group )
|
2003-09-19 14:53:39 +00:00
|
|
|
{ // move the window to the right group (e.g. a dialog provided
|
|
|
|
// by different app, but transient for this one, so make it part of that group)
|
2003-09-16 19:28:03 +00:00
|
|
|
new_group = transientFor()->group();
|
|
|
|
}
|
|
|
|
if( new_group == NULL ) // doesn't exist yet
|
|
|
|
new_group = new Group( window_group, workspace());
|
|
|
|
if( new_group != in_group )
|
|
|
|
{
|
|
|
|
if( in_group != NULL )
|
|
|
|
in_group->removeMember( this );
|
|
|
|
in_group = new_group;
|
|
|
|
in_group->addMember( this );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( transientFor() != NULL )
|
|
|
|
{ // doesn't have window group set, but is transient for something
|
|
|
|
// so make it part of that group
|
|
|
|
Group* new_group = transientFor()->group();
|
|
|
|
if( new_group != in_group )
|
|
|
|
{
|
|
|
|
if( in_group != NULL )
|
|
|
|
in_group->removeMember( this );
|
|
|
|
in_group = transientFor()->group();
|
|
|
|
in_group->addMember( this );
|
|
|
|
}
|
|
|
|
}
|
2004-02-05 18:16:53 +00:00
|
|
|
else if( groupTransient())
|
|
|
|
{ // group transient which actually doesn't have a group :(
|
|
|
|
// try creating group with other windows with the same client leader
|
|
|
|
Group* new_group = workspace()->findClientLeaderGroup( this );
|
|
|
|
if( new_group == NULL )
|
|
|
|
new_group = new Group( None, workspace());
|
|
|
|
if( new_group != in_group )
|
|
|
|
{
|
|
|
|
if( in_group != NULL )
|
|
|
|
in_group->removeMember( this );
|
|
|
|
in_group = new_group;
|
|
|
|
in_group->addMember( this );
|
|
|
|
}
|
|
|
|
}
|
2006-12-13 18:29:43 +00:00
|
|
|
else // Not transient without a group, put it in its client leader group.
|
|
|
|
{ // This might be stupid if grouping was used for e.g. taskbar grouping
|
|
|
|
// or minimizing together the whole group, but as long as its used
|
|
|
|
// only for dialogs it's better to keep windows from one app in one group.
|
|
|
|
Group* new_group = workspace()->findClientLeaderGroup( this );
|
|
|
|
if( in_group != NULL && in_group != new_group )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
in_group->removeMember( this );
|
|
|
|
in_group = NULL;
|
|
|
|
}
|
2007-01-04 17:03:04 +00:00
|
|
|
if( new_group == NULL )
|
|
|
|
new_group = new Group( None, workspace() );
|
|
|
|
if( in_group != new_group )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2007-01-04 17:03:04 +00:00
|
|
|
in_group = new_group;
|
2003-09-16 19:28:03 +00:00
|
|
|
in_group->addMember( this );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-04-29 14:13:08 +00:00
|
|
|
if( in_group != old_group || force )
|
2003-11-10 18:08:59 +00:00
|
|
|
{
|
2003-11-12 09:02:37 +00:00
|
|
|
for( ClientList::Iterator it = transients_list.begin();
|
|
|
|
it != transients_list.end();
|
|
|
|
)
|
2003-12-10 11:28:31 +00:00
|
|
|
{ // group transients in the old group are no longer transient for it
|
2003-11-12 09:02:37 +00:00
|
|
|
if( (*it)->groupTransient() && (*it)->group() != group())
|
2006-04-11 17:12:05 +00:00
|
|
|
it = transients_list.erase( it );
|
2003-11-12 09:02:37 +00:00
|
|
|
else
|
|
|
|
++it;
|
|
|
|
}
|
2003-12-10 11:28:31 +00:00
|
|
|
if( groupTransient())
|
|
|
|
{
|
2006-12-13 18:53:55 +00:00
|
|
|
// no longer transient for ones in the old group
|
2006-12-15 13:01:19 +00:00
|
|
|
if( old_group != NULL )
|
2006-12-13 18:53:55 +00:00
|
|
|
{
|
2003-12-10 11:28:31 +00:00
|
|
|
for( ClientList::ConstIterator it = old_group->members().begin();
|
|
|
|
it != old_group->members().end();
|
|
|
|
++it )
|
|
|
|
(*it)->removeTransient( this );
|
|
|
|
}
|
2006-12-13 18:53:55 +00:00
|
|
|
// and make transient for all in the new group
|
2003-12-10 11:28:31 +00:00
|
|
|
for( ClientList::ConstIterator it = group()->members().begin();
|
|
|
|
it != group()->members().end();
|
|
|
|
++it )
|
2006-12-13 18:53:55 +00:00
|
|
|
{
|
|
|
|
if( *it == this )
|
|
|
|
break; // this means the window is only transient for windows mapped before it
|
2003-12-10 11:28:31 +00:00
|
|
|
(*it)->addTransient( this );
|
2006-12-13 18:53:55 +00:00
|
|
|
}
|
2003-12-10 11:28:31 +00:00
|
|
|
}
|
2004-05-26 08:47:37 +00:00
|
|
|
// group transient splashscreens should be transient even for windows
|
|
|
|
// in group mapped later
|
2003-11-10 18:08:59 +00:00
|
|
|
for( ClientList::ConstIterator it = group()->members().begin();
|
|
|
|
it != group()->members().end();
|
|
|
|
++it )
|
|
|
|
{
|
2004-05-26 08:47:37 +00:00
|
|
|
if( !(*it)->isSplash())
|
2003-11-10 18:08:59 +00:00
|
|
|
continue;
|
2004-05-26 08:47:37 +00:00
|
|
|
if( !(*it)->groupTransient())
|
|
|
|
continue;
|
|
|
|
if( *it == this || hasTransient( *it, true )) // TODO indirect?
|
2003-11-24 14:24:04 +00:00
|
|
|
continue;
|
2003-11-21 14:05:20 +00:00
|
|
|
addTransient( *it );
|
2003-11-10 18:08:59 +00:00
|
|
|
}
|
|
|
|
}
|
2006-12-15 13:01:19 +00:00
|
|
|
if( old_group != NULL )
|
|
|
|
old_group->deref(); // can be now deleted if empty
|
2004-04-29 09:43:01 +00:00
|
|
|
checkGroupTransients();
|
2004-08-04 12:19:50 +00:00
|
|
|
checkActiveModal();
|
|
|
|
workspace()->updateClientLayer( this );
|
|
|
|
}
|
|
|
|
|
2006-12-13 18:29:43 +00:00
|
|
|
// used by Workspace::findClientLeaderGroup()
|
|
|
|
void Client::changeClientLeaderGroup( Group* gr )
|
|
|
|
{
|
|
|
|
// transientFor() != NULL are in the group of their mainwindow, so keep them there
|
|
|
|
if( transientFor() != NULL )
|
|
|
|
return;
|
|
|
|
// also don't change the group for window which have group set
|
|
|
|
if( window_group )
|
|
|
|
return;
|
|
|
|
checkGroup( gr ); // change group
|
|
|
|
}
|
|
|
|
|
2004-08-04 12:19:50 +00:00
|
|
|
bool Client::check_active_modal = false;
|
|
|
|
|
|
|
|
void Client::checkActiveModal()
|
|
|
|
{
|
|
|
|
// if the active window got new modal transient, activate it.
|
2004-05-28 11:33:36 +00:00
|
|
|
// cannot be done in AddTransient(), because there may temporarily
|
|
|
|
// exist loops, breaking findModal
|
|
|
|
Client* check_modal = workspace()->mostRecentlyActivatedClient();
|
|
|
|
if( check_modal != NULL && check_modal->check_active_modal )
|
|
|
|
{
|
|
|
|
Client* new_modal = check_modal->findModal();
|
|
|
|
if( new_modal != NULL && new_modal != check_modal )
|
2004-08-04 12:19:50 +00:00
|
|
|
{
|
|
|
|
if( !new_modal->isManaged())
|
|
|
|
return; // postpone check until end of manage()
|
2004-05-28 11:33:36 +00:00
|
|
|
workspace()->activateClient( new_modal );
|
2004-08-04 12:19:50 +00:00
|
|
|
}
|
2004-05-28 11:33:36 +00:00
|
|
|
check_modal->check_active_modal = false;
|
|
|
|
}
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|