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.
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
// SELI zmenit doc
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
This file contains things relevant to stacking order and layers.
|
|
|
|
|
|
|
|
Design:
|
|
|
|
|
|
|
|
Normal unconstrained stacking order, as requested by the user (by clicking
|
|
|
|
on windows to raise them, etc.), is in Workspace::unconstrained_stacking_order.
|
|
|
|
That list shouldn't be used at all, except for building
|
|
|
|
Workspace::stacking_order. The building is done
|
|
|
|
in Workspace::constrainedStackingOrder(). Only Workspace::stackingOrder() should
|
|
|
|
be used to get the stacking order, because it also checks the stacking order
|
|
|
|
is up to date.
|
|
|
|
All clients are also stored in Workspace::clients (except for isDesktop() clients,
|
|
|
|
as those are very special, and are stored in Workspace::desktops), in the order
|
|
|
|
the clients were created.
|
|
|
|
|
|
|
|
Every window has one layer assigned in which it is. There are 6 layers,
|
2005-12-16 14:08:20 +00:00
|
|
|
from bottom : DesktopLayer, BelowLayer, NormalLayer, DockLayer, AboveLayer
|
2003-09-16 19:28:03 +00:00
|
|
|
and ActiveLayer (see also NETWM sect.7.10.). The layer a window is in depends
|
|
|
|
on the window type, and on other things like whether the window is active.
|
|
|
|
|
|
|
|
NET::Splash clients belong to the Normal layer. NET::TopMenu clients
|
|
|
|
belong to Dock layer. Clients that are both NET::Dock and NET::KeepBelow
|
|
|
|
are in the Normal layer in order to keep the 'allow window to cover
|
|
|
|
the panel' Kicker setting to work as intended (this may look like a slight
|
|
|
|
spec violation, but a) I have no better idea, b) the spec allows adjusting
|
|
|
|
the stacking order if the WM thinks it's a good idea . We put all
|
|
|
|
NET::KeepAbove above all Docks too, even though the spec suggests putting
|
|
|
|
them in the same layer.
|
|
|
|
|
|
|
|
Most transients are in the same layer as their mainwindow,
|
|
|
|
see Workspace::constrainedStackingOrder(), they may also be in higher layers, but
|
|
|
|
they should never be below their mainwindow.
|
|
|
|
|
|
|
|
When some client attribute changes (above/below flag, transiency...),
|
|
|
|
Workspace::updateClientLayer() should be called in order to make
|
|
|
|
sure it's moved to the appropriate layer ClientList if needed.
|
|
|
|
|
|
|
|
Currently the things that affect client in which layer a client
|
|
|
|
belongs: KeepAbove/Keep Below flags, window type, fullscreen
|
|
|
|
state and whether the client is active, mainclient (transiency).
|
|
|
|
|
|
|
|
Make sure updateStackingOrder() is called in order to make
|
|
|
|
Workspace::stackingOrder() up to date and propagated to the world.
|
|
|
|
Using Workspace::blockStackingUpdates() (or the StackingUpdatesBlocker
|
|
|
|
helper class) it's possible to temporarily disable updates
|
|
|
|
and the stacking order will be updated once after it's allowed again.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
2004-05-28 13:51:11 +00:00
|
|
|
#include <kdebug.h>
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
#include "utils.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "workspace.h"
|
|
|
|
#include "tabbox.h"
|
|
|
|
#include "group.h"
|
2004-05-28 13:51:11 +00:00
|
|
|
#include "rules.h"
|
2005-07-28 14:59:42 +00:00
|
|
|
#include <QX11Info>
|
2004-04-16 10:23:42 +00:00
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
namespace KWinInternal
|
|
|
|
{
|
|
|
|
|
|
|
|
//*******************************
|
|
|
|
// Workspace
|
|
|
|
//*******************************
|
|
|
|
|
|
|
|
void Workspace::updateClientLayer( Client* c )
|
|
|
|
{
|
|
|
|
if( c == NULL )
|
|
|
|
return;
|
|
|
|
if( c->layer() == c->belongsToLayer())
|
|
|
|
return;
|
|
|
|
StackingUpdatesBlocker blocker( this );
|
|
|
|
c->invalidateLayer(); // invalidate, will be updated when doing restacking
|
|
|
|
for( ClientList::ConstIterator it = c->transients().begin();
|
|
|
|
it != c->transients().end();
|
|
|
|
++it )
|
|
|
|
updateClientLayer( *it );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::updateStackingOrder( bool propagate_new_clients )
|
|
|
|
{
|
2007-01-08 15:01:49 +00:00
|
|
|
if( block_stacking_updates > 0 )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2007-01-08 15:01:49 +00:00
|
|
|
if( propagate_new_clients )
|
|
|
|
blocked_propagating_new_clients = true;
|
2003-09-16 19:28:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
ClientList new_stacking_order = constrainedStackingOrder();
|
|
|
|
bool changed = ( new_stacking_order != stacking_order );
|
|
|
|
stacking_order = new_stacking_order;
|
|
|
|
#if 0
|
2006-02-06 14:47:18 +00:00
|
|
|
kDebug() << "stacking:" << changed << endl;
|
2003-09-16 19:28:03 +00:00
|
|
|
if( changed || propagate_new_clients )
|
|
|
|
{
|
|
|
|
for( ClientList::ConstIterator it = stacking_order.begin();
|
|
|
|
it != stacking_order.end();
|
|
|
|
++it )
|
2006-02-06 14:47:18 +00:00
|
|
|
kDebug() << (void*)(*it) << *it << ":" << (*it)->layer() << endl;
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if( changed || propagate_new_clients )
|
2007-01-08 15:02:12 +00:00
|
|
|
{
|
2003-09-16 19:28:03 +00:00
|
|
|
propagateClients( propagate_new_clients );
|
2007-01-08 15:02:12 +00:00
|
|
|
if( active_client )
|
|
|
|
active_client->updateMouseGrab();
|
|
|
|
}
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Propagates the managed clients to the world.
|
|
|
|
Called ONLY from updateStackingOrder().
|
|
|
|
*/
|
|
|
|
void Workspace::propagateClients( bool propagate_new_clients )
|
|
|
|
{
|
|
|
|
Window *cl; // MW we should not assume WId and Window to be compatible
|
|
|
|
// when passig pointers around.
|
|
|
|
|
|
|
|
// restack the windows according to the stacking order
|
2003-11-12 09:47:13 +00:00
|
|
|
Window* new_stack = new Window[ stacking_order.count() + 2 ];
|
|
|
|
int pos = 0;
|
2003-09-16 19:28:03 +00:00
|
|
|
// Stack all windows under the support window. The support window is
|
|
|
|
// not used for anything (besides the NETWM property), and it's not shown,
|
|
|
|
// but it was lowered after kwin startup. Stacking all clients below
|
|
|
|
// it ensures that no client will be ever shown above override-redirect
|
|
|
|
// windows (e.g. popups).
|
2003-11-12 09:47:13 +00:00
|
|
|
new_stack[ pos++ ] = supportWindow->winId();
|
2003-12-16 12:25:42 +00:00
|
|
|
int topmenu_space_pos = 1; // not 0, that's supportWindow !!!
|
2005-07-28 14:59:42 +00:00
|
|
|
for ( int i = stacking_order.size() - 1; i >= 0; i-- )
|
2003-11-12 09:47:13 +00:00
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
new_stack[ pos++ ] = stacking_order.at( i )->frameId();
|
|
|
|
if( stacking_order.at( i )->belongsToLayer() >= DockLayer )
|
2003-11-12 09:47:13 +00:00
|
|
|
topmenu_space_pos = pos;
|
|
|
|
}
|
|
|
|
if( topmenu_space != NULL )
|
2004-07-27 08:48:38 +00:00
|
|
|
{ // make sure the topmenu space is below all topmenus, fullscreens, etc.
|
2003-11-12 09:47:13 +00:00
|
|
|
for( int i = pos;
|
|
|
|
i > topmenu_space_pos;
|
|
|
|
--i )
|
|
|
|
new_stack[ i ] = new_stack[ i - 1 ];
|
|
|
|
new_stack[ topmenu_space_pos ] = topmenu_space->winId();
|
|
|
|
++pos;
|
|
|
|
}
|
2003-09-16 19:28:03 +00:00
|
|
|
// TODO isn't it too inefficient to restart always all clients?
|
|
|
|
// TODO don't restack not visible windows?
|
2003-12-16 12:25:42 +00:00
|
|
|
assert( new_stack[ 0 ] = supportWindow->winId());
|
2006-07-04 19:36:19 +00:00
|
|
|
XRestackWindows(display(), new_stack, pos);
|
2003-09-16 19:28:03 +00:00
|
|
|
delete [] new_stack;
|
|
|
|
|
|
|
|
if ( propagate_new_clients )
|
|
|
|
{
|
|
|
|
cl = new Window[ desktops.count() + clients.count()];
|
2003-11-12 09:47:13 +00:00
|
|
|
pos = 0;
|
2003-09-16 19:28:03 +00:00
|
|
|
// TODO this is still not completely in the map order
|
|
|
|
for ( ClientList::ConstIterator it = desktops.begin(); it != desktops.end(); ++it )
|
2003-11-12 09:47:13 +00:00
|
|
|
cl[pos++] = (*it)->window();
|
2003-09-16 19:28:03 +00:00
|
|
|
for ( ClientList::ConstIterator it = clients.begin(); it != clients.end(); ++it )
|
2003-11-12 09:47:13 +00:00
|
|
|
cl[pos++] = (*it)->window();
|
|
|
|
rootInfo->setClientList( cl, pos );
|
2003-09-16 19:28:03 +00:00
|
|
|
delete [] cl;
|
|
|
|
}
|
|
|
|
|
|
|
|
cl = new Window[ stacking_order.count()];
|
2003-11-12 09:47:13 +00:00
|
|
|
pos = 0;
|
2003-09-16 19:28:03 +00:00
|
|
|
for ( ClientList::ConstIterator it = stacking_order.begin(); it != stacking_order.end(); ++it)
|
2003-11-12 09:47:13 +00:00
|
|
|
cl[pos++] = (*it)->window();
|
|
|
|
rootInfo->setClientListStacking( cl, pos );
|
2003-09-16 19:28:03 +00:00
|
|
|
delete [] cl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Returns topmost visible client. Windows on the dock, the desktop
|
|
|
|
or of any other special kind are excluded. Also if the window
|
|
|
|
doesn't accept focus it's excluded.
|
|
|
|
*/
|
|
|
|
// TODO misleading name for this method
|
2007-01-08 15:02:12 +00:00
|
|
|
Client* Workspace::topClientOnDesktop( int desktop, bool unconstrained, bool only_normal ) const
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2003-11-20 09:05:32 +00:00
|
|
|
// TODO Q_ASSERT( block_stacking_updates == 0 );
|
2005-07-28 14:59:42 +00:00
|
|
|
ClientList list;
|
2004-01-19 14:42:52 +00:00
|
|
|
if( !unconstrained )
|
2007-01-08 15:02:12 +00:00
|
|
|
list = stacking_order;
|
2004-01-19 14:42:52 +00:00
|
|
|
else
|
2007-01-08 15:02:12 +00:00
|
|
|
list = unconstrained_stacking_order;
|
|
|
|
for( int i = list.size() - 1;
|
|
|
|
i >= 0;
|
|
|
|
--i )
|
2004-01-19 14:42:52 +00:00
|
|
|
{
|
2007-01-08 15:02:12 +00:00
|
|
|
if( list.at( i )->isOnDesktop( desktop ) && list.at( i )->isShown( false ))
|
|
|
|
{
|
|
|
|
if( !only_normal )
|
|
|
|
return list.at( i );
|
|
|
|
if( list.at( i )->wantsTabFocus() && !list.at( i )->isSpecialWindow())
|
|
|
|
return list.at( i );
|
|
|
|
}
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Client* Workspace::findDesktop( bool topmost, int desktop ) const
|
|
|
|
{
|
2003-09-25 10:47:36 +00:00
|
|
|
// TODO Q_ASSERT( block_stacking_updates == 0 );
|
2003-09-16 19:28:03 +00:00
|
|
|
if( topmost )
|
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
for ( int i = stacking_order.size() - 1; i>=0; i-- )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
if ( stacking_order.at( i )->isOnDesktop( desktop ) && stacking_order.at( i )->isDesktop()
|
|
|
|
&& stacking_order.at( i )->isShown( true ))
|
|
|
|
return stacking_order.at( i );
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else // bottom-most
|
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
foreach ( Client* c, stacking_order )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
if ( c->isOnDesktop( desktop ) && c->isDesktop()
|
|
|
|
&& c->isShown( true ))
|
|
|
|
return c;
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::raiseOrLowerClient( Client *c)
|
|
|
|
{
|
|
|
|
if (!c) return;
|
|
|
|
Client* topmost = NULL;
|
2003-11-20 09:05:32 +00:00
|
|
|
// TODO Q_ASSERT( block_stacking_updates == 0 );
|
2003-09-16 19:28:03 +00:00
|
|
|
if ( most_recently_raised && stacking_order.contains( most_recently_raised ) &&
|
2003-10-10 13:00:01 +00:00
|
|
|
most_recently_raised->isShown( true ) && c->isOnCurrentDesktop())
|
2003-09-16 19:28:03 +00:00
|
|
|
topmost = most_recently_raised;
|
|
|
|
else
|
|
|
|
topmost = topClientOnDesktop( c->isOnAllDesktops() ? currentDesktop() : c->desktop());
|
|
|
|
|
|
|
|
if( c == topmost)
|
|
|
|
lowerClient(c);
|
|
|
|
else
|
|
|
|
raiseClient(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Workspace::lowerClient( Client* c )
|
|
|
|
{
|
|
|
|
if ( !c )
|
|
|
|
return;
|
2004-04-23 14:51:30 +00:00
|
|
|
if( c->isTopMenu())
|
|
|
|
return;
|
2003-09-16 19:28:03 +00:00
|
|
|
|
2004-02-10 14:46:03 +00:00
|
|
|
c->cancelAutoRaise();
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
StackingUpdatesBlocker blocker( this );
|
|
|
|
|
2006-03-06 14:30:06 +00:00
|
|
|
unconstrained_stacking_order.removeAll( c );
|
2003-09-16 19:28:03 +00:00
|
|
|
unconstrained_stacking_order.prepend( c );
|
|
|
|
if( c->isTransient())
|
|
|
|
{
|
|
|
|
// lower also mainclients, in their reversed stacking order
|
|
|
|
ClientList mainclients = ensureStackingOrder( c->mainClients());
|
2005-07-28 14:59:42 +00:00
|
|
|
for( int i = mainclients.size() - 1;
|
|
|
|
i >= 0;
|
|
|
|
--i )
|
|
|
|
lowerClient( mainclients[ i ] );
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( c == most_recently_raised )
|
|
|
|
most_recently_raised = 0;
|
|
|
|
}
|
|
|
|
|
2003-09-30 12:49:23 +00:00
|
|
|
void Workspace::lowerClientWithinApplication( Client* c )
|
|
|
|
{
|
|
|
|
if ( !c )
|
|
|
|
return;
|
2004-04-23 14:51:30 +00:00
|
|
|
if( c->isTopMenu())
|
|
|
|
return;
|
2003-09-30 12:49:23 +00:00
|
|
|
|
2004-02-10 14:46:03 +00:00
|
|
|
c->cancelAutoRaise();
|
|
|
|
|
2003-09-30 12:49:23 +00:00
|
|
|
StackingUpdatesBlocker blocker( this );
|
|
|
|
|
2006-03-06 14:30:06 +00:00
|
|
|
unconstrained_stacking_order.removeAll( c );
|
2003-09-30 12:49:23 +00:00
|
|
|
bool lowered = false;
|
|
|
|
// first try to put it below the bottom-most window of the application
|
|
|
|
for( ClientList::Iterator it = unconstrained_stacking_order.begin();
|
|
|
|
it != unconstrained_stacking_order.end();
|
|
|
|
++it )
|
|
|
|
if( Client::belongToSameApplication( *it, c ))
|
|
|
|
{
|
|
|
|
unconstrained_stacking_order.insert( it, c );
|
|
|
|
lowered = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if( !lowered )
|
|
|
|
unconstrained_stacking_order.prepend( c );
|
|
|
|
// ignore mainwindows
|
|
|
|
}
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
void Workspace::raiseClient( Client* c )
|
|
|
|
{
|
|
|
|
if ( !c )
|
|
|
|
return;
|
2004-04-23 14:51:30 +00:00
|
|
|
if( c->isTopMenu())
|
|
|
|
return;
|
2003-09-16 19:28:03 +00:00
|
|
|
|
2004-02-10 14:46:03 +00:00
|
|
|
c->cancelAutoRaise();
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
StackingUpdatesBlocker blocker( this );
|
|
|
|
|
|
|
|
if( c->isTransient())
|
|
|
|
{
|
|
|
|
ClientList mainclients = ensureStackingOrder( c->mainClients());
|
|
|
|
for( ClientList::ConstIterator it = mainclients.begin();
|
|
|
|
it != mainclients.end();
|
|
|
|
++it )
|
|
|
|
raiseClient( *it );
|
|
|
|
}
|
|
|
|
|
2006-03-06 14:30:06 +00:00
|
|
|
unconstrained_stacking_order.removeAll( c );
|
2003-09-16 19:28:03 +00:00
|
|
|
unconstrained_stacking_order.append( c );
|
|
|
|
|
|
|
|
if( !c->isSpecialWindow())
|
2004-04-16 10:23:42 +00:00
|
|
|
{
|
2003-09-16 19:28:03 +00:00
|
|
|
most_recently_raised = c;
|
2004-04-22 12:30:57 +00:00
|
|
|
pending_take_activity = NULL;
|
2004-04-16 10:23:42 +00:00
|
|
|
}
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
2003-09-30 12:49:23 +00:00
|
|
|
void Workspace::raiseClientWithinApplication( Client* c )
|
|
|
|
{
|
|
|
|
if ( !c )
|
|
|
|
return;
|
2004-04-23 14:51:30 +00:00
|
|
|
if( c->isTopMenu())
|
|
|
|
return;
|
2003-09-30 12:49:23 +00:00
|
|
|
|
2004-02-10 14:46:03 +00:00
|
|
|
c->cancelAutoRaise();
|
|
|
|
|
2003-09-30 12:49:23 +00:00
|
|
|
StackingUpdatesBlocker blocker( this );
|
|
|
|
// ignore mainwindows
|
|
|
|
|
|
|
|
// first try to put it above the top-most window of the application
|
2005-07-28 14:59:42 +00:00
|
|
|
for ( int i = unconstrained_stacking_order.size() - 1; i>= 0 ; i-- )
|
2003-12-02 17:54:42 +00:00
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
if( unconstrained_stacking_order.at( i ) == c ) // don't lower it just because it asked to be raised
|
2004-03-02 17:28:37 +00:00
|
|
|
return;
|
2005-07-28 14:59:42 +00:00
|
|
|
if( Client::belongToSameApplication( unconstrained_stacking_order.at( i ), c ))
|
2003-09-30 12:49:23 +00:00
|
|
|
{
|
2006-03-06 14:30:06 +00:00
|
|
|
unconstrained_stacking_order.removeAll( c );
|
2005-07-28 14:59:42 +00:00
|
|
|
unconstrained_stacking_order.insert( ++i, c ); // insert after the found one
|
2004-03-02 17:28:37 +00:00
|
|
|
return;
|
2003-09-30 12:49:23 +00:00
|
|
|
}
|
2003-12-02 17:54:42 +00:00
|
|
|
}
|
2003-09-30 12:49:23 +00:00
|
|
|
}
|
|
|
|
|
2004-04-16 09:43:53 +00:00
|
|
|
void Workspace::raiseClientRequest( Client* c, NET::RequestSource src, Time timestamp )
|
2003-09-30 12:49:23 +00:00
|
|
|
{
|
2004-04-16 09:43:53 +00:00
|
|
|
if( src == NET::FromTool || allowFullClientRaising( c, timestamp ))
|
2003-09-30 12:49:23 +00:00
|
|
|
raiseClient( c );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
raiseClientWithinApplication( c );
|
|
|
|
c->demandAttention();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-16 09:43:53 +00:00
|
|
|
void Workspace::lowerClientRequest( Client* c, NET::RequestSource src, Time /*timestamp*/ )
|
2003-09-30 12:49:23 +00:00
|
|
|
{
|
|
|
|
// If the client has support for all this focus stealing prevention stuff,
|
|
|
|
// do only lowering within the application, as that's the more logical
|
|
|
|
// variant of lowering when application requests it.
|
|
|
|
// No demanding of attention here of course.
|
2004-04-16 09:43:53 +00:00
|
|
|
if( src == NET::FromTool || !c->hasUserTimeSupport())
|
2003-09-30 12:49:23 +00:00
|
|
|
lowerClient( c );
|
2004-04-16 09:43:53 +00:00
|
|
|
else
|
|
|
|
lowerClientWithinApplication( c );
|
2003-09-30 12:49:23 +00:00
|
|
|
}
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
void Workspace::restackClientUnderActive( Client* c )
|
|
|
|
{
|
2004-04-23 14:51:30 +00:00
|
|
|
if( c->isTopMenu())
|
|
|
|
return;
|
2003-09-16 19:28:03 +00:00
|
|
|
if( !active_client || active_client == c )
|
|
|
|
{
|
|
|
|
raiseClient( c );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert( unconstrained_stacking_order.contains( active_client ));
|
2007-01-08 15:02:12 +00:00
|
|
|
if( Client::belongToSameApplication( active_client, c ))
|
|
|
|
{ // put it below the active window if it's the same app
|
|
|
|
unconstrained_stacking_order.removeAll( c );
|
|
|
|
unconstrained_stacking_order.insert( unconstrained_stacking_order.find( active_client ), c );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // put in the stacking order below _all_ windows belonging to the active application
|
|
|
|
for( ClientList::Iterator it = unconstrained_stacking_order.begin();
|
|
|
|
it != unconstrained_stacking_order.end();
|
|
|
|
++it )
|
|
|
|
{ // TODO ignore topmenus?
|
|
|
|
if( Client::belongToSameApplication( active_client, *it ))
|
2003-12-11 09:48:37 +00:00
|
|
|
{
|
2007-01-08 15:02:12 +00:00
|
|
|
if( *it != c )
|
|
|
|
{
|
|
|
|
unconstrained_stacking_order.removeAll( c );
|
|
|
|
unconstrained_stacking_order.insert( it, c );
|
|
|
|
}
|
|
|
|
break;
|
2003-12-11 09:48:37 +00:00
|
|
|
}
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
}
|
2003-11-19 10:42:23 +00:00
|
|
|
assert( unconstrained_stacking_order.contains( c ));
|
2006-02-27 10:13:31 +00:00
|
|
|
for( int desktop = 1;
|
|
|
|
desktop <= numberOfDesktops();
|
|
|
|
++desktop )
|
|
|
|
{ // do for every virtual desktop to handle the case of onalldesktop windows
|
|
|
|
if( c->wantsTabFocus() && c->isOnDesktop( desktop ) && focus_chain[ desktop ].contains( active_client ))
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2007-01-08 15:02:12 +00:00
|
|
|
if( Client::belongToSameApplication( active_client, c ))
|
|
|
|
{ // put it after the active window if it's the same app
|
|
|
|
focus_chain[ desktop ].removeAll( c );
|
|
|
|
focus_chain[ desktop ].insert( focus_chain[ desktop ].find( active_client ), c );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // put it in focus_chain[currentDesktop()] after all windows belonging to the active applicationa
|
|
|
|
focus_chain[ desktop ].removeAll( c );
|
|
|
|
for( int i = focus_chain[ desktop ].size() - 1;
|
|
|
|
i >= 0;
|
|
|
|
--i )
|
2006-02-27 10:13:31 +00:00
|
|
|
{
|
2007-01-08 15:02:12 +00:00
|
|
|
if( Client::belongToSameApplication( active_client, focus_chain[ desktop ].at( i )))
|
|
|
|
{
|
|
|
|
focus_chain[ desktop ].insert( i, c );
|
|
|
|
break;
|
|
|
|
}
|
2006-02-27 10:13:31 +00:00
|
|
|
}
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
}
|
2006-04-11 14:14:38 +00:00
|
|
|
}
|
|
|
|
// the same for global_focus_chain
|
|
|
|
if( c->wantsTabFocus() && global_focus_chain.contains( active_client ))
|
|
|
|
{
|
2007-01-08 15:02:12 +00:00
|
|
|
if( Client::belongToSameApplication( active_client, c ))
|
2006-11-07 17:07:24 +00:00
|
|
|
{
|
2007-01-08 15:02:12 +00:00
|
|
|
global_focus_chain.removeAll( c );
|
|
|
|
global_focus_chain.insert( global_focus_chain.find( active_client ), c );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
global_focus_chain.removeAll( c );
|
|
|
|
for ( int i = global_focus_chain.size() - 1;
|
|
|
|
i >= 0;
|
|
|
|
--i )
|
2006-04-11 14:14:38 +00:00
|
|
|
{
|
2007-01-08 15:02:12 +00:00
|
|
|
if( Client::belongToSameApplication( active_client, global_focus_chain.at( i ) ))
|
|
|
|
{
|
|
|
|
global_focus_chain.insert( i, c );
|
|
|
|
break;
|
|
|
|
}
|
2006-04-11 14:14:38 +00:00
|
|
|
}
|
|
|
|
}
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
updateStackingOrder();
|
|
|
|
}
|
|
|
|
|
2006-04-20 14:57:10 +00:00
|
|
|
void Workspace::restoreSessionStackingOrder( Client* c )
|
|
|
|
{
|
|
|
|
if( c->sessionStackingOrder() < 0 )
|
|
|
|
return;
|
|
|
|
StackingUpdatesBlocker blocker( this );
|
2006-04-29 14:38:17 +00:00
|
|
|
unconstrained_stacking_order.removeAll( c );
|
2006-04-20 14:57:10 +00:00
|
|
|
ClientList::Iterator best_pos = unconstrained_stacking_order.end();
|
|
|
|
for( ClientList::Iterator it = unconstrained_stacking_order.begin(); // from bottom
|
|
|
|
it != unconstrained_stacking_order.end();
|
|
|
|
++it )
|
|
|
|
{
|
|
|
|
if( (*it)->sessionStackingOrder() > c->sessionStackingOrder() )
|
|
|
|
{
|
|
|
|
unconstrained_stacking_order.insert( it, c );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unconstrained_stacking_order.append( c );
|
|
|
|
}
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
void Workspace::circulateDesktopApplications()
|
|
|
|
{
|
|
|
|
if ( desktops.count() > 1 )
|
|
|
|
{
|
|
|
|
bool change_active = activeClient()->isDesktop();
|
|
|
|
raiseClient( findDesktop( false, currentDesktop()));
|
|
|
|
if( change_active ) // if the previously topmost Desktop was active, activate this new one
|
|
|
|
activateClient( findDesktop( true, currentDesktop()));
|
|
|
|
}
|
|
|
|
// if there's no active client, make desktop the active one
|
|
|
|
if( desktops.count() > 0 && activeClient() == NULL && should_get_focus.count() == 0 )
|
|
|
|
activateClient( findDesktop( true, currentDesktop()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Returns a stacking order based upon \a list that fulfills certain contained.
|
|
|
|
*/
|
|
|
|
ClientList Workspace::constrainedStackingOrder()
|
|
|
|
{
|
|
|
|
ClientList layer[ NumLayers ];
|
|
|
|
|
|
|
|
#if 0
|
2006-02-06 14:47:18 +00:00
|
|
|
kDebug() << "stacking1:" << endl;
|
2003-09-16 19:28:03 +00:00
|
|
|
#endif
|
|
|
|
// build the order from layers
|
2005-01-28 16:35:34 +00:00
|
|
|
QMap< Group*, Layer > minimum_layer;
|
2003-09-16 19:28:03 +00:00
|
|
|
for( ClientList::ConstIterator it = unconstrained_stacking_order.begin();
|
|
|
|
it != unconstrained_stacking_order.end();
|
|
|
|
++it )
|
|
|
|
{
|
2005-01-28 16:35:34 +00:00
|
|
|
Layer l = (*it)->layer();
|
|
|
|
// If a window is raised above some other window in the same window group
|
2005-03-09 15:04:32 +00:00
|
|
|
// which is in the ActiveLayer (i.e. it's fulscreened), make sure it stays
|
|
|
|
// above that window (see #95731).
|
|
|
|
if( minimum_layer.contains( (*it)->group())
|
|
|
|
&& minimum_layer[ (*it)->group() ] == ActiveLayer
|
|
|
|
&& ( l == NormalLayer || l == AboveLayer ))
|
2005-01-28 16:35:34 +00:00
|
|
|
{
|
|
|
|
l = minimum_layer[ (*it)->group() ];
|
|
|
|
}
|
|
|
|
minimum_layer[ (*it)->group() ] = l;
|
|
|
|
layer[ l ].append( *it );
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
ClientList stacking;
|
|
|
|
for( Layer lay = FirstLayer;
|
|
|
|
lay < NumLayers;
|
|
|
|
++lay )
|
|
|
|
stacking += layer[ lay ];
|
|
|
|
#if 0
|
2006-02-06 14:47:18 +00:00
|
|
|
kDebug() << "stacking2:" << endl;
|
2003-09-16 19:28:03 +00:00
|
|
|
for( ClientList::ConstIterator it = stacking.begin();
|
|
|
|
it != stacking.end();
|
|
|
|
++it )
|
2006-02-06 14:47:18 +00:00
|
|
|
kDebug() << (void*)(*it) << *it << ":" << (*it)->layer() << endl;
|
2003-09-16 19:28:03 +00:00
|
|
|
#endif
|
|
|
|
// now keep transients above their mainwindows
|
|
|
|
// TODO this could(?) use some optimization
|
2005-07-28 14:59:42 +00:00
|
|
|
for( int i = stacking.size() - 1;
|
|
|
|
i >= 0;
|
2003-09-16 19:28:03 +00:00
|
|
|
)
|
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
if( !stacking[ i ]->isTransient())
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
--i;
|
2003-09-16 19:28:03 +00:00
|
|
|
continue;
|
|
|
|
}
|
2005-07-28 14:59:42 +00:00
|
|
|
int i2 = -1;
|
|
|
|
if( stacking[ i ]->groupTransient())
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
if( stacking[ i ]->group()->members().count() > 0 )
|
2003-09-16 19:28:03 +00:00
|
|
|
{ // find topmost client this one is transient for
|
2005-07-28 14:59:42 +00:00
|
|
|
for( i2 = stacking.size() - 1;
|
|
|
|
i2 >= 0;
|
|
|
|
--i2 )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
if( stacking[ i2 ] == stacking[ i ] )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
i2 = -1; // don't reorder
|
2003-09-16 19:28:03 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-07-28 14:59:42 +00:00
|
|
|
if( stacking[ i2 ]->hasTransient( stacking[ i ], true )
|
|
|
|
&& keepTransientAbove( stacking[ i2 ], stacking[ i ] ))
|
2003-09-16 19:28:03 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-07-28 14:59:42 +00:00
|
|
|
} // else i2 remains pointing at -1
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
for( i2 = stacking.size() - 1;
|
|
|
|
i2 >= 0;
|
|
|
|
--i2 )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
if( stacking[ i2 ] == stacking[ i ] )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
i2 = -1; // don't reorder
|
2003-09-16 19:28:03 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-07-28 14:59:42 +00:00
|
|
|
if( stacking[ i2 ] == stacking[ i ]->transientFor()
|
|
|
|
&& keepTransientAbove( stacking[ i2 ], stacking[ i ] ))
|
2003-09-16 19:28:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-02-06 14:47:18 +00:00
|
|
|
// kDebug() << "STACK:" << stacking[ i ] << ":" << ( i2 == -1 ? ((Client*)0) : stacking[ i2 ] ) << endl;
|
2005-07-28 14:59:42 +00:00
|
|
|
if( i2 == -1 )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
--i;
|
2003-09-16 19:28:03 +00:00
|
|
|
continue;
|
|
|
|
}
|
2005-07-28 14:59:42 +00:00
|
|
|
Client* current = stacking[ i ];
|
|
|
|
stacking.removeAt( i );
|
|
|
|
--i;
|
2003-11-13 15:34:04 +00:00
|
|
|
if( !current->transients().isEmpty()) // this one now can be possibly above its transients,
|
2005-07-28 14:59:42 +00:00
|
|
|
i = i2; // so go again higher in the stack order and possibly move those transients again
|
|
|
|
++i2; // insert after the mainwindow, it's ok if it2 is now stacking.end()
|
|
|
|
stacking.insert( i2, current );
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
#if 0
|
2006-02-06 14:47:18 +00:00
|
|
|
kDebug() << "stacking3:" << endl;
|
2003-09-16 19:28:03 +00:00
|
|
|
for( ClientList::ConstIterator it = stacking.begin();
|
|
|
|
it != stacking.end();
|
|
|
|
++it )
|
2006-02-06 14:47:18 +00:00
|
|
|
kDebug() << (void*)(*it) << *it << ":" << (*it)->layer() << endl;
|
|
|
|
kDebug() << "\n\n" << endl;
|
2003-09-16 19:28:03 +00:00
|
|
|
#endif
|
|
|
|
return stacking;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::blockStackingUpdates( bool block )
|
|
|
|
{
|
|
|
|
if( block )
|
|
|
|
{
|
|
|
|
if( block_stacking_updates == 0 )
|
|
|
|
blocked_propagating_new_clients = false;
|
|
|
|
++block_stacking_updates;
|
|
|
|
}
|
|
|
|
else // !block
|
|
|
|
if( --block_stacking_updates == 0 )
|
|
|
|
updateStackingOrder( blocked_propagating_new_clients );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure list is in stacking order
|
|
|
|
ClientList Workspace::ensureStackingOrder( const ClientList& list ) const
|
|
|
|
{
|
2003-11-20 09:05:32 +00:00
|
|
|
// TODO Q_ASSERT( block_stacking_updates == 0 );
|
2003-09-16 19:28:03 +00:00
|
|
|
if( list.count() < 2 )
|
|
|
|
return list;
|
|
|
|
// TODO is this worth optimizing?
|
|
|
|
ClientList result = list;
|
|
|
|
for( ClientList::ConstIterator it = stacking_order.begin();
|
|
|
|
it != stacking_order.end();
|
|
|
|
++it )
|
2006-03-06 14:30:06 +00:00
|
|
|
if( result.removeAll( *it ) != 0 )
|
2003-09-16 19:28:03 +00:00
|
|
|
result.append( *it );
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-09-25 12:17:35 +00:00
|
|
|
// check whether a transient should be actually kept above its mainwindow
|
|
|
|
// there may be some special cases where this rule shouldn't be enfored
|
|
|
|
bool Workspace::keepTransientAbove( const Client* mainwindow, const Client* transient )
|
|
|
|
{
|
2003-11-27 14:05:42 +00:00
|
|
|
// When topmenu's mainwindow becomes active, topmenu is raised and shown.
|
|
|
|
// They also belong to the Dock layer. This makes them to be very high.
|
|
|
|
// Therefore don't keep group transients above them, otherwise this would move
|
|
|
|
// group transients way too high.
|
|
|
|
if( mainwindow->isTopMenu() && transient->groupTransient())
|
|
|
|
return false;
|
2004-11-24 14:51:10 +00:00
|
|
|
// #93832 - don't keep splashscreens above dialogs
|
|
|
|
if( transient->isSplash() && mainwindow->isDialog())
|
|
|
|
return false;
|
2004-07-16 11:19:47 +00:00
|
|
|
// This is rather a hack for #76026. Don't keep non-modal dialogs above
|
|
|
|
// the mainwindow, but only if they're group transient (since only such dialogs
|
|
|
|
// have taskbar entry in Kicker). A proper way of doing this (both kwin and kicker)
|
|
|
|
// needs to be found.
|
|
|
|
if( transient->isDialog() && !transient->isModal() && transient->groupTransient())
|
|
|
|
return false;
|
2003-09-25 12:17:35 +00:00
|
|
|
// #63223 - don't keep transients above docks, because the dock is kept high,
|
|
|
|
// and e.g. dialogs for them would be too high too
|
2004-11-30 14:26:09 +00:00
|
|
|
if( mainwindow->isDock())
|
2003-09-25 12:17:35 +00:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
//*******************************
|
|
|
|
// Client
|
|
|
|
//*******************************
|
|
|
|
|
2004-04-16 09:43:53 +00:00
|
|
|
void Client::restackWindow( Window /*above TODO */, int detail, NET::RequestSource src, Time timestamp, bool send_event )
|
2003-09-30 12:49:23 +00:00
|
|
|
{
|
|
|
|
switch ( detail )
|
|
|
|
{
|
|
|
|
case Above:
|
|
|
|
case TopIf:
|
2004-04-16 09:43:53 +00:00
|
|
|
workspace()->raiseClientRequest( this, src, timestamp );
|
|
|
|
break;
|
2003-09-30 12:49:23 +00:00
|
|
|
case Below:
|
|
|
|
case BottomIf:
|
2004-04-16 09:43:53 +00:00
|
|
|
workspace()->lowerClientRequest( this, src, timestamp );
|
|
|
|
break;
|
2003-09-30 12:49:23 +00:00
|
|
|
case Opposite:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if( send_event )
|
|
|
|
sendSyntheticConfigureNotify();
|
|
|
|
}
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
void Client::setKeepAbove( bool b )
|
|
|
|
{
|
2004-05-28 13:51:11 +00:00
|
|
|
b = rules()->checkKeepAbove( b );
|
2005-01-12 12:30:34 +00:00
|
|
|
if( b && !rules()->checkKeepBelow( false ))
|
2004-05-28 13:51:11 +00:00
|
|
|
setKeepBelow( false );
|
2005-01-12 12:30:34 +00:00
|
|
|
if ( b == keepAbove())
|
2004-05-28 13:51:11 +00:00
|
|
|
{ // force hint change if different
|
|
|
|
if( bool( info->state() & NET::KeepAbove ) != keepAbove())
|
|
|
|
info->setState( keepAbove() ? NET::KeepAbove : 0, NET::KeepAbove );
|
2003-09-16 19:28:03 +00:00
|
|
|
return;
|
2004-05-28 13:51:11 +00:00
|
|
|
}
|
2003-09-16 19:28:03 +00:00
|
|
|
keep_above = b;
|
2004-05-28 13:51:11 +00:00
|
|
|
info->setState( keepAbove() ? NET::KeepAbove : 0, NET::KeepAbove );
|
2004-07-22 11:19:08 +00:00
|
|
|
if( decoration != NULL )
|
|
|
|
decoration->emitKeepAboveChanged( keepAbove());
|
2003-09-16 19:28:03 +00:00
|
|
|
workspace()->updateClientLayer( this );
|
2004-06-11 15:12:29 +00:00
|
|
|
updateWindowRules();
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Client::setKeepBelow( bool b )
|
|
|
|
{
|
2004-05-28 13:51:11 +00:00
|
|
|
b = rules()->checkKeepBelow( b );
|
2005-01-12 12:30:34 +00:00
|
|
|
if( b && !rules()->checkKeepAbove( false ))
|
2004-05-28 13:51:11 +00:00
|
|
|
setKeepAbove( false );
|
2005-01-12 12:30:34 +00:00
|
|
|
if ( b == keepBelow())
|
2004-05-28 13:51:11 +00:00
|
|
|
{ // force hint change if different
|
|
|
|
if( bool( info->state() & NET::KeepBelow ) != keepBelow())
|
|
|
|
info->setState( keepBelow() ? NET::KeepBelow : 0, NET::KeepBelow );
|
2003-09-16 19:28:03 +00:00
|
|
|
return;
|
2004-05-28 13:51:11 +00:00
|
|
|
}
|
2003-09-16 19:28:03 +00:00
|
|
|
keep_below = b;
|
2004-05-28 13:51:11 +00:00
|
|
|
info->setState( keepBelow() ? NET::KeepBelow : 0, NET::KeepBelow );
|
2004-07-22 11:19:08 +00:00
|
|
|
if( decoration != NULL )
|
|
|
|
decoration->emitKeepBelowChanged( keepBelow());
|
2003-09-16 19:28:03 +00:00
|
|
|
workspace()->updateClientLayer( this );
|
2004-06-11 15:12:29 +00:00
|
|
|
updateWindowRules();
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Layer Client::layer() const
|
|
|
|
{
|
|
|
|
if( in_layer == UnknownLayer )
|
|
|
|
const_cast< Client* >( this )->in_layer = belongsToLayer();
|
|
|
|
return in_layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
Layer Client::belongsToLayer() const
|
|
|
|
{
|
|
|
|
if( isDesktop())
|
|
|
|
return DesktopLayer;
|
|
|
|
if( isSplash()) // no damn annoying splashscreens
|
|
|
|
return NormalLayer; // getting in the way of everything else
|
|
|
|
if( isDock() && keepBelow())
|
|
|
|
// slight hack for the 'allow window to cover panel' Kicker setting
|
|
|
|
// don't move keepbelow docks below normal window, but only to the same
|
|
|
|
// layer, so that both may be raised to cover the other
|
|
|
|
return NormalLayer;
|
|
|
|
if( keepBelow())
|
|
|
|
return BelowLayer;
|
|
|
|
if( isDock() && !keepBelow())
|
|
|
|
return DockLayer;
|
|
|
|
if( isTopMenu())
|
|
|
|
return DockLayer;
|
2004-10-06 14:02:30 +00:00
|
|
|
// only raise fullscreen above docks if it's the topmost window in unconstrained stacking order,
|
|
|
|
// i.e. the window set to be topmost by the user (also includes transients of the fullscreen window)
|
|
|
|
const Client* ac = workspace()->mostRecentlyActivatedClient(); // instead of activeClient() - avoids flicker
|
2005-03-10 16:29:00 +00:00
|
|
|
const Client* top = workspace()->topClientOnDesktop( desktop(), true );
|
2005-03-14 18:23:13 +00:00
|
|
|
if( isFullScreen() && ac != NULL && top != NULL
|
2005-06-29 09:52:27 +00:00
|
|
|
&& ( ac == this || this->group() == ac->group())
|
|
|
|
&& ( top == this || this->group() == top->group()))
|
2003-09-16 19:28:03 +00:00
|
|
|
return ActiveLayer;
|
2004-10-29 12:59:29 +00:00
|
|
|
if( keepAbove())
|
|
|
|
return AboveLayer;
|
2003-09-16 19:28:03 +00:00
|
|
|
return NormalLayer;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|