2007-11-27 19:40:25 +00:00
|
|
|
/********************************************************************
|
2007-04-29 17:35:43 +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>
|
|
|
|
|
2007-11-27 19:40:25 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
// This file contains things relevant to handling incoming events.
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include "client.h"
|
|
|
|
|
|
|
|
#include <kstartupinfo.h>
|
|
|
|
#include <kglobal.h>
|
|
|
|
#include <X11/extensions/shape.h>
|
|
|
|
|
|
|
|
#include "notifications.h"
|
|
|
|
#include <QX11Info>
|
|
|
|
#include "rules.h"
|
|
|
|
#include "group.h"
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
/**
|
|
|
|
* Manages the clients. This means handling the very first maprequest:
|
|
|
|
* reparenting, initial geometry, initial state, placement, etc.
|
|
|
|
* Returns false if KWin is not going to manage this window.
|
2007-04-29 17:35:43 +00:00
|
|
|
*/
|
|
|
|
bool Client::manage( Window w, bool isMapped )
|
|
|
|
{
|
2008-12-18 15:01:25 +00:00
|
|
|
StackingUpdatesBlocker stacking_blocker( workspace() );
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
grabXServer();
|
|
|
|
|
|
|
|
XWindowAttributes attr;
|
2008-12-18 15:01:25 +00:00
|
|
|
if( !XGetWindowAttributes( display(), w, &attr ))
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
ungrabXServer();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
// From this place on, manage() must not return false
|
2007-04-29 17:35:43 +00:00
|
|
|
block_geometry_updates = 1;
|
2008-12-18 15:01:25 +00:00
|
|
|
pending_geometry_update = PendingGeometryForced; // Force update when finishing with geometry changes
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
embedClient( w, attr );
|
2008-12-18 15:01:25 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
vis = attr.visual;
|
|
|
|
bit_depth = attr.depth;
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
// SELI TODO: Order all these things in some sane manner
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
bool init_minimize = false;
|
2008-12-18 15:01:25 +00:00
|
|
|
XWMHints* hints = XGetWMHints( display(), w );
|
|
|
|
if( hints && ( hints->flags & StateHint ) && hints->initial_state == IconicState )
|
2007-04-29 17:35:43 +00:00
|
|
|
init_minimize = true;
|
2008-12-18 15:01:25 +00:00
|
|
|
if( hints )
|
|
|
|
XFree( hints );
|
2007-04-29 17:35:43 +00:00
|
|
|
if( isMapped )
|
2008-12-18 15:01:25 +00:00
|
|
|
init_minimize = false; // If it's already mapped, ignore hint
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
unsigned long properties[2];
|
|
|
|
properties[WinInfo::PROTOCOLS] =
|
2007-04-29 17:35:43 +00:00
|
|
|
NET::WMDesktop |
|
|
|
|
NET::WMState |
|
|
|
|
NET::WMWindowType |
|
|
|
|
NET::WMStrut |
|
|
|
|
NET::WMName |
|
|
|
|
NET::WMIconGeometry |
|
|
|
|
NET::WMIcon |
|
|
|
|
NET::WMPid |
|
|
|
|
NET::WMIconName |
|
|
|
|
0;
|
2008-12-18 15:01:25 +00:00
|
|
|
properties[WinInfo::PROTOCOLS2] =
|
2007-04-29 17:35:43 +00:00
|
|
|
NET::WM2UserTime |
|
|
|
|
NET::WM2StartupId |
|
|
|
|
NET::WM2ExtendedStrut |
|
|
|
|
NET::WM2Opacity |
|
2008-11-17 08:03:39 +00:00
|
|
|
NET::WM2FullscreenMonitors |
|
2009-11-25 23:32:35 +00:00
|
|
|
NET::WM2FrameOverlap |
|
2007-04-29 17:35:43 +00:00
|
|
|
0;
|
|
|
|
|
|
|
|
info = new WinInfo( this, display(), client, rootWindow(), properties, 2 );
|
|
|
|
|
|
|
|
cmap = attr.colormap;
|
|
|
|
|
|
|
|
getResourceClass();
|
|
|
|
getWindowRole();
|
|
|
|
getWmClientLeader();
|
|
|
|
getWmClientMachine();
|
2007-06-25 08:51:44 +00:00
|
|
|
getSyncCounter();
|
2008-12-18 15:01:25 +00:00
|
|
|
// First only read the caption text, so that setupWindowRules() can use it for matching,
|
2007-04-29 17:35:43 +00:00
|
|
|
// and only then really set the caption using setCaption(), which checks for duplicates etc.
|
|
|
|
// and also relies on rules already existing
|
|
|
|
cap_normal = readName();
|
|
|
|
setupWindowRules( false );
|
2008-12-18 15:01:25 +00:00
|
|
|
ignore_focus_stealing = options->checkIgnoreFocusStealing( this ); // TODO: Change to rules
|
2007-04-29 17:35:43 +00:00
|
|
|
setCaption( cap_normal, true );
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
if( Extensions::shapeAvailable() )
|
2007-04-29 17:35:43 +00:00
|
|
|
XShapeSelectInput( display(), window(), ShapeNotifyMask );
|
2008-12-18 15:01:25 +00:00
|
|
|
detectShape( window() );
|
2007-04-29 17:35:43 +00:00
|
|
|
detectNoBorder();
|
|
|
|
fetchIconicName();
|
2008-12-18 15:01:25 +00:00
|
|
|
getWMHints(); // Needs to be done before readTransient() because of reading the group
|
|
|
|
modal = ( info->state() & NET::Modal ) != 0; // Needs to be valid before handling groups
|
2007-04-29 17:35:43 +00:00
|
|
|
readTransient();
|
|
|
|
getIcons();
|
|
|
|
getWindowProtocols();
|
2008-12-18 15:01:25 +00:00
|
|
|
getWmNormalHints(); // Get xSizeHint
|
2007-04-29 17:35:43 +00:00
|
|
|
getMotifHints();
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
// TODO: Try to obey all state information from info->state()
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
original_skip_taskbar = skip_taskbar = ( info->state() & NET::SkipTaskbar ) != 0;
|
|
|
|
skip_pager = ( info->state() & NET::SkipPager ) != 0;
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-08-12 11:02:58 +00:00
|
|
|
setupCompositing();
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
KStartupInfoId asn_id;
|
|
|
|
KStartupInfoData asn_data;
|
|
|
|
bool asn_valid = workspace()->checkStartupNotification( window(), asn_id, asn_data );
|
|
|
|
|
|
|
|
workspace()->updateClientLayer( this );
|
|
|
|
|
|
|
|
SessionInfo* session = workspace()->takeSessionInfo( this );
|
2008-03-23 00:12:11 +00:00
|
|
|
if( session )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2008-03-23 00:12:11 +00:00
|
|
|
init_minimize = session->minimized;
|
|
|
|
noborder = session->noBorder;
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setShortcut( rules()->checkShortcut( session ? session->shortcut : QString(), true ));
|
|
|
|
|
|
|
|
init_minimize = rules()->checkMinimize( init_minimize, !isMapped );
|
2008-03-23 00:12:11 +00:00
|
|
|
noborder = rules()->checkNoBorder( noborder, !isMapped );
|
2008-12-18 15:01:25 +00:00
|
|
|
|
|
|
|
// Initial desktop placement
|
|
|
|
if( session )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
desk = session->desktop;
|
|
|
|
if( session->onAllDesktops )
|
|
|
|
desk = NET::OnAllDesktops;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-12-18 15:01:25 +00:00
|
|
|
// If this window is transient, ensure that it is opened on the
|
2007-04-29 17:35:43 +00:00
|
|
|
// same window as its parent. this is necessary when an application
|
|
|
|
// starts up on a different desktop than is currently displayed
|
2008-12-18 15:01:25 +00:00
|
|
|
if( isTransient() )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
ClientList mainclients = mainClients();
|
|
|
|
bool on_current = false;
|
2010-08-19 12:07:44 +00:00
|
|
|
bool on_all = false;
|
2007-04-29 17:35:43 +00:00
|
|
|
Client* maincl = NULL;
|
2008-12-18 15:01:25 +00:00
|
|
|
// This is slightly duplicated from Placement::placeOnMainWindow()
|
2008-11-11 23:09:11 +00:00
|
|
|
for( ClientList::ConstIterator it = mainclients.constBegin();
|
2008-12-18 15:01:25 +00:00
|
|
|
it != mainclients.constEnd();
|
|
|
|
++it )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2008-12-18 15:01:25 +00:00
|
|
|
if( mainclients.count() > 1 && (*it)->isSpecialWindow() )
|
|
|
|
continue; // Don't consider toolbars etc when placing
|
2007-04-29 17:35:43 +00:00
|
|
|
maincl = *it;
|
2008-12-18 15:01:25 +00:00
|
|
|
if( (*it)->isOnCurrentDesktop() )
|
2007-04-29 17:35:43 +00:00
|
|
|
on_current = true;
|
2010-08-19 12:07:44 +00:00
|
|
|
if( (*it)->isOnAllDesktops() )
|
|
|
|
on_all = true;
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2010-08-19 12:07:44 +00:00
|
|
|
if( on_all )
|
|
|
|
desk = NET::OnAllDesktops;
|
|
|
|
else if( on_current )
|
2007-04-29 17:35:43 +00:00
|
|
|
desk = workspace()->currentDesktop();
|
|
|
|
else if( maincl != NULL )
|
|
|
|
desk = maincl->desktop();
|
|
|
|
}
|
2008-12-18 15:01:25 +00:00
|
|
|
if( info->desktop() )
|
|
|
|
desk = info->desktop(); // Window had the initial desktop property, force it
|
2007-04-29 17:35:43 +00:00
|
|
|
if( desktop() == 0 && asn_valid && asn_data.desktop() != 0 )
|
|
|
|
desk = asn_data.desktop();
|
|
|
|
}
|
2008-12-18 15:01:25 +00:00
|
|
|
if( desk == 0 ) // Assume window wants to be visible on the current desktop
|
2007-04-29 17:35:43 +00:00
|
|
|
desk = workspace()->currentDesktop();
|
|
|
|
desk = rules()->checkDesktop( desk, !isMapped );
|
2008-12-18 15:01:25 +00:00
|
|
|
if( desk != NET::OnAllDesktops ) // Do range check
|
2007-04-29 17:35:43 +00:00
|
|
|
desk = qMax( 1, qMin( workspace()->numberOfDesktops(), desk ));
|
|
|
|
info->setDesktop( desk );
|
2008-12-18 15:01:25 +00:00
|
|
|
workspace()->updateOnAllDesktopsOfTransients( this ); // SELI TODO
|
|
|
|
//onAllDesktopsChange(); // Decoration doesn't exist here yet
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
QRect geom( attr.x, attr.y, attr.width, attr.height );
|
|
|
|
bool placementDone = false;
|
|
|
|
|
|
|
|
if ( session )
|
|
|
|
geom = session->geometry;
|
|
|
|
|
|
|
|
QRect area;
|
|
|
|
bool partial_keep_in_area = isMapped || session;
|
|
|
|
if( isMapped || session )
|
2008-12-18 15:01:25 +00:00
|
|
|
area = workspace()->clientArea( FullArea, geom.center(), desktop() );
|
2007-04-29 17:35:43 +00:00
|
|
|
else if( options->xineramaPlacementEnabled )
|
2007-05-07 12:27:19 +00:00
|
|
|
{
|
|
|
|
int screen = options->xineramaPlacementScreen;
|
2008-12-18 15:01:25 +00:00
|
|
|
if( screen == -1 ) // Active screen
|
2007-05-07 14:27:39 +00:00
|
|
|
screen = asn_data.xinerama() == -1 ? workspace()->activeScreen() : asn_data.xinerama();
|
2007-05-07 12:27:19 +00:00
|
|
|
area = workspace()->clientArea( PlacementArea, workspace()->screenGeometry( screen ).center(), desktop());
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
else
|
2008-12-18 15:01:25 +00:00
|
|
|
area = workspace()->clientArea( PlacementArea, cursorPos(), desktop() );
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
if( int type = checkFullScreenHack( geom ))
|
|
|
|
{
|
|
|
|
fullscreen_mode = FullScreenHack;
|
|
|
|
if( rules()->checkStrictGeometry( false ))
|
|
|
|
{
|
2008-12-18 15:01:25 +00:00
|
|
|
geom = type == 2 // 1 = It's xinerama-aware fullscreen hack, 2 = It's full area
|
|
|
|
? workspace()->clientArea( FullArea, geom.center(), desktop() )
|
|
|
|
: workspace()->clientArea( ScreenArea, geom.center(), desktop() );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
else
|
2008-12-18 15:01:25 +00:00
|
|
|
geom = workspace()->clientArea( FullScreenArea, geom.center(), desktop() );
|
2007-04-29 17:35:43 +00:00
|
|
|
placementDone = true;
|
|
|
|
}
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
if( isDesktop() )
|
|
|
|
// KWin doesn't manage desktop windows
|
2008-05-02 16:39:49 +00:00
|
|
|
placementDone = true;
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
bool usePosition = false;
|
|
|
|
if ( isMapped || session || placementDone )
|
2008-12-18 15:01:25 +00:00
|
|
|
placementDone = true; // Use geometry
|
|
|
|
else if( isTransient() && !isUtility() && !isDialog() && !isSplash() )
|
2007-04-29 17:35:43 +00:00
|
|
|
usePosition = true;
|
2008-12-18 15:01:25 +00:00
|
|
|
else if( isTransient() && !hasNETSupport() )
|
2007-04-29 17:35:43 +00:00
|
|
|
usePosition = true;
|
2008-12-18 15:01:25 +00:00
|
|
|
else if( isDialog() && hasNETSupport() )
|
|
|
|
{ // If the dialog is actually non-NETWM transient window, don't try to apply placement to it,
|
|
|
|
// it breaks with too many things (xmms, display)
|
2007-04-29 17:35:43 +00:00
|
|
|
if( mainClients().count() >= 1 )
|
|
|
|
{
|
|
|
|
#if 1
|
2007-07-19 16:38:46 +00:00
|
|
|
// #78082 - Ok, it seems there are after all some cases when an application has a good
|
2007-04-29 17:35:43 +00:00
|
|
|
// reason to specify a position for its dialog. Too bad other WMs have never bothered
|
|
|
|
// with placement for dialogs, so apps always specify positions for their dialogs,
|
|
|
|
// including such silly positions like always centered on the screen or under mouse.
|
2007-07-19 16:38:46 +00:00
|
|
|
// Using ignoring requested position in window-specific settings helps, and now
|
|
|
|
// there's also _NET_WM_FULL_PLACEMENT.
|
2007-04-29 17:35:43 +00:00
|
|
|
usePosition = true;
|
|
|
|
#else
|
2008-12-18 15:01:25 +00:00
|
|
|
; // Force using placement policy
|
2007-04-29 17:35:43 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
usePosition = true;
|
|
|
|
}
|
2008-12-18 15:01:25 +00:00
|
|
|
else if( isSplash() )
|
|
|
|
; // Force using placement policy
|
2007-04-29 17:35:43 +00:00
|
|
|
else
|
|
|
|
usePosition = true;
|
|
|
|
if( !rules()->checkIgnoreGeometry( !usePosition ))
|
|
|
|
{
|
2008-12-18 15:01:25 +00:00
|
|
|
bool ignorePPosition = options->ignorePositionClasses.contains(
|
|
|
|
QString::fromLatin1( resourceClass() ));
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
if((( xSizeHint.flags & PPosition ) && !ignorePPosition ) ||
|
|
|
|
( xSizeHint.flags & USPosition ))
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
placementDone = true;
|
2008-12-18 15:01:25 +00:00
|
|
|
// Disobey xinerama placement option for now (#70943)
|
|
|
|
area = workspace()->clientArea( PlacementArea, geom.center(), desktop() );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-18 15:01:25 +00:00
|
|
|
//if( true ) // Size is always obeyed for now, only with constraints applied
|
|
|
|
// if(( xSizeHint.flags & USSize ) || ( xSizeHint.flags & PSize ))
|
|
|
|
// {
|
|
|
|
// // Keep in mind that we now actually have a size :-)
|
|
|
|
// }
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
if( xSizeHint.flags & PMaxSize )
|
2007-04-29 17:35:43 +00:00
|
|
|
geom.setSize( geom.size().boundedTo(
|
2008-12-18 15:01:25 +00:00
|
|
|
rules()->checkMaxSize( QSize( xSizeHint.max_width, xSizeHint.max_height ))));
|
|
|
|
if( xSizeHint.flags & PMinSize )
|
2007-04-29 17:35:43 +00:00
|
|
|
geom.setSize( geom.size().expandedTo(
|
2008-12-18 15:01:25 +00:00
|
|
|
rules()->checkMinSize( QSize( xSizeHint.min_width, xSizeHint.min_height ))));
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
if( isMovable() && ( geom.x() > area.right() || geom.y() > area.bottom() ))
|
|
|
|
placementDone = false; // Weird, do not trust.
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
if( placementDone )
|
|
|
|
move( geom.x(), geom.y() ); // Before gravitating
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2009-11-15 03:24:04 +00:00
|
|
|
// Create client group if the window will have a decoration
|
2009-11-16 13:31:02 +00:00
|
|
|
bool dontKeepInArea = false;
|
2009-11-15 03:24:04 +00:00
|
|
|
if( !noBorder() )
|
|
|
|
{
|
|
|
|
client_group = NULL;
|
|
|
|
// Automatically add to previous groups on session restore
|
|
|
|
if( session && session->clientGroupClient && session->clientGroupClient != this )
|
|
|
|
session->clientGroupClient->clientGroup()->add( this, -1, true );
|
|
|
|
else if( isMapped )
|
|
|
|
// If the window is already mapped (Restarted KWin) add any windows that already have the
|
|
|
|
// same geometry to the same client group. (May incorrectly handle maximized windows)
|
|
|
|
foreach( ClientGroup* group, workspace()->clientGroups )
|
2009-12-14 12:03:32 +00:00
|
|
|
if( geom == QRect( group->visible()->pos(), group->visible()->clientSize() ) &&
|
|
|
|
desk == group->visible()->desktop() &&
|
|
|
|
group->visible()->maximizeMode() != MaximizeFull )
|
2009-11-15 03:24:04 +00:00
|
|
|
{
|
|
|
|
group->add( this, -1, true );
|
|
|
|
break;
|
|
|
|
}
|
2009-11-16 13:31:02 +00:00
|
|
|
if( !client_group && !isMapped && !session )
|
2009-11-16 10:09:03 +00:00
|
|
|
{ // Attempt to automatically group similar windows
|
|
|
|
const Client* similar = workspace()->findSimilarClient( this );
|
|
|
|
if( similar && similar->clientGroup() && !similar->noBorder() )
|
|
|
|
{
|
2010-06-20 12:16:28 +00:00
|
|
|
geom = QRect( similar->pos() + similar->clientPos(), similar->clientSize() );
|
|
|
|
updateDecoration( false );
|
2009-11-17 10:41:32 +00:00
|
|
|
similar->clientGroup()->add( this, -1,
|
|
|
|
rules()->checkAutogroupInForeground( options->autogroupInForeground ));
|
2009-11-16 13:31:02 +00:00
|
|
|
// Don't move entire group
|
|
|
|
geom = QRect( similar->pos() + similar->clientPos(), similar->clientSize() );
|
|
|
|
placementDone = true;
|
|
|
|
dontKeepInArea = true;
|
2009-11-16 10:09:03 +00:00
|
|
|
}
|
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
if( !client_group )
|
|
|
|
client_group = new ClientGroup( this );
|
|
|
|
}
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
updateDecoration( false ); // Also gravitates
|
|
|
|
// TODO: Is CentralGravity right here, when resizing is done after gravitating?
|
|
|
|
plainResize( rules()->checkSize( sizeForClientSize( geom.size() ), !isMapped ));
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
QPoint forced_pos = rules()->checkPosition( invalidPoint, !isMapped );
|
|
|
|
if( forced_pos != invalidPoint )
|
|
|
|
{
|
|
|
|
move( forced_pos );
|
|
|
|
placementDone = true;
|
2008-12-18 15:01:25 +00:00
|
|
|
// Don't keep inside workarea if the window has specially configured position
|
2007-04-29 17:35:43 +00:00
|
|
|
partial_keep_in_area = true;
|
2008-12-18 15:01:25 +00:00
|
|
|
area = workspace()->clientArea( FullArea, geom.center(), desktop() );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2008-12-18 15:01:25 +00:00
|
|
|
if( !placementDone )
|
|
|
|
{ // Placement needs to be after setting size
|
2007-04-29 17:35:43 +00:00
|
|
|
workspace()->place( this, area );
|
|
|
|
placementDone = true;
|
|
|
|
}
|
|
|
|
|
2009-11-16 13:31:02 +00:00
|
|
|
if(( !isSpecialWindow() || isToolbar() ) && isMovable() && !dontKeepInArea )
|
2007-04-29 17:35:43 +00:00
|
|
|
keepInArea( area, partial_keep_in_area );
|
|
|
|
|
2007-12-17 16:30:36 +00:00
|
|
|
updateShape();
|
2008-12-18 15:01:25 +00:00
|
|
|
|
|
|
|
// CT: Extra check for stupid jdk 1.3.1. But should make sense in general
|
2007-04-29 17:35:43 +00:00
|
|
|
// if client has initial state set to Iconic and is transient with a parent
|
|
|
|
// window that is not Iconic, set init_state to Normal
|
2008-12-18 15:01:25 +00:00
|
|
|
if( init_minimize && isTransient() )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
ClientList mainclients = mainClients();
|
2008-11-11 23:09:11 +00:00
|
|
|
for( ClientList::ConstIterator it = mainclients.constBegin();
|
2008-12-18 15:01:25 +00:00
|
|
|
it != mainclients.constEnd();
|
|
|
|
++it )
|
2007-04-29 17:35:43 +00:00
|
|
|
if( (*it)->isShown( true ))
|
2008-12-18 15:01:25 +00:00
|
|
|
init_minimize = false; // SELI TODO: Even e.g. for NET::Utility?
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2008-12-18 15:01:25 +00:00
|
|
|
// If a dialog is shown for minimized window, minimize it too
|
2008-03-18 14:56:57 +00:00
|
|
|
if( !init_minimize && isTransient() && mainClients().count() > 0 )
|
|
|
|
{
|
|
|
|
bool visible_parent = false;
|
2008-12-18 15:01:25 +00:00
|
|
|
// Use allMainClients(), to include also main clients of group transients
|
2008-04-18 15:50:12 +00:00
|
|
|
// that have been optimized out in Client::checkGroupTransients()
|
|
|
|
ClientList mainclients = allMainClients();
|
2008-11-11 23:09:11 +00:00
|
|
|
for( ClientList::ConstIterator it = mainclients.constBegin();
|
2008-12-18 15:01:25 +00:00
|
|
|
it != mainclients.constEnd();
|
|
|
|
++it )
|
2008-03-18 14:56:57 +00:00
|
|
|
if( (*it)->isShown( true ))
|
|
|
|
visible_parent = true;
|
|
|
|
if( !visible_parent )
|
|
|
|
{
|
|
|
|
init_minimize = true;
|
|
|
|
demandAttention();
|
|
|
|
}
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
if( init_minimize )
|
2008-12-18 15:01:25 +00:00
|
|
|
minimize( true ); // No animation
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2009-08-15 17:33:47 +00:00
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
// SELI TODO: This seems to be mainly for kstart and ksystraycmd
|
2007-04-29 17:35:43 +00:00
|
|
|
// probably should be replaced by something better
|
|
|
|
bool doNotShow = false;
|
2008-12-18 15:01:25 +00:00
|
|
|
if ( workspace()->isNotManaged( caption() ))
|
2007-04-29 17:35:43 +00:00
|
|
|
doNotShow = true;
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
// Other settings from the previous session
|
|
|
|
if( session )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2008-12-18 15:01:25 +00:00
|
|
|
// Session restored windows are not considered to be new windows WRT rules,
|
|
|
|
// I.e. obey only forcing rules
|
2007-04-29 17:35:43 +00:00
|
|
|
setKeepAbove( session->keepAbove );
|
|
|
|
setKeepBelow( session->keepBelow );
|
|
|
|
setSkipTaskbar( session->skipTaskbar, true );
|
|
|
|
setSkipPager( session->skipPager );
|
2010-05-03 20:04:44 +00:00
|
|
|
setSkipSwitcher( session->skipSwitcher );
|
2007-04-29 17:35:43 +00:00
|
|
|
setShade( session->shaded ? ShadeNormal : ShadeNone );
|
2009-08-15 17:33:47 +00:00
|
|
|
setOpacity( session->opacity );
|
2007-04-29 17:35:43 +00:00
|
|
|
if( session->maximized != MaximizeRestore )
|
|
|
|
{
|
2008-12-18 15:01:25 +00:00
|
|
|
maximize( MaximizeMode( session->maximized ));
|
2007-04-29 17:35:43 +00:00
|
|
|
geom_restore = session->restore;
|
|
|
|
}
|
|
|
|
if( session->fullscreen == FullScreenHack )
|
2008-12-18 15:01:25 +00:00
|
|
|
; // Nothing, this should be already set again above
|
2007-04-29 17:35:43 +00:00
|
|
|
else if( session->fullscreen != FullScreenNone )
|
|
|
|
{
|
|
|
|
setFullScreen( true, false );
|
|
|
|
geom_fs_restore = session->fsrestore;
|
|
|
|
}
|
|
|
|
}
|
2008-12-18 15:01:25 +00:00
|
|
|
else
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2008-12-18 15:01:25 +00:00
|
|
|
geom_restore = geometry(); // Remember restore geometry
|
|
|
|
if( isMaximizable() && ( width() >= area.width() || height() >= area.height() ))
|
|
|
|
{ // Window is too large for the screen, maximize in the
|
|
|
|
// directions necessary
|
|
|
|
if( width() >= area.width() && height() >= area.height() )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
maximize( Client::MaximizeFull );
|
2008-12-18 15:01:25 +00:00
|
|
|
geom_restore = QRect(); // Use placement when unmaximizing
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2008-12-18 15:01:25 +00:00
|
|
|
else if( width() >= area.width() )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
maximize( Client::MaximizeHorizontal );
|
2008-12-18 15:01:25 +00:00
|
|
|
geom_restore = QRect(); // Use placement when unmaximizing
|
|
|
|
geom_restore.setY( y() ); // But only for horizontal direction
|
|
|
|
geom_restore.setHeight( height() );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2008-12-18 15:01:25 +00:00
|
|
|
else if( height() >= area.height() )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
maximize( Client::MaximizeVertical );
|
2008-12-18 15:01:25 +00:00
|
|
|
geom_restore = QRect(); // Use placement when unmaximizing
|
|
|
|
geom_restore.setX( x() ); // But only for vertical direction
|
|
|
|
geom_restore.setWidth( width() );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-18 15:01:25 +00:00
|
|
|
|
|
|
|
// Window may want to be maximized
|
2007-04-29 17:35:43 +00:00
|
|
|
// done after checking that the window isn't larger than the workarea, so that
|
|
|
|
// the restore geometry from the checks above takes precedence, and window
|
|
|
|
// isn't restored larger than the workarea
|
2008-12-18 15:01:25 +00:00
|
|
|
MaximizeMode maxmode = static_cast<MaximizeMode>(
|
|
|
|
(( info->state() & NET::MaxVert ) ? MaximizeVertical : 0 ) |
|
|
|
|
(( info->state() & NET::MaxHoriz ) ? MaximizeHorizontal : 0 ));
|
2007-04-29 17:35:43 +00:00
|
|
|
MaximizeMode forced_maxmode = rules()->checkMaximize( maxmode, !isMapped );
|
2008-12-18 15:01:25 +00:00
|
|
|
|
|
|
|
// Either hints were set to maximize, or is forced to maximize,
|
2007-04-29 17:35:43 +00:00
|
|
|
// or is forced to non-maximize and hints were set to maximize
|
|
|
|
if( forced_maxmode != MaximizeRestore || maxmode != MaximizeRestore )
|
|
|
|
maximize( forced_maxmode );
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
// Read other initial states
|
2007-04-29 17:35:43 +00:00
|
|
|
setShade( rules()->checkShade( info->state() & NET::Shaded ? ShadeNormal : ShadeNone, !isMapped ));
|
|
|
|
setKeepAbove( rules()->checkKeepAbove( info->state() & NET::KeepAbove, !isMapped ));
|
|
|
|
setKeepBelow( rules()->checkKeepBelow( info->state() & NET::KeepBelow, !isMapped ));
|
|
|
|
setSkipTaskbar( rules()->checkSkipTaskbar( info->state() & NET::SkipTaskbar, !isMapped ), true );
|
|
|
|
setSkipPager( rules()->checkSkipPager( info->state() & NET::SkipPager, !isMapped ));
|
2010-05-03 20:04:44 +00:00
|
|
|
setSkipSwitcher( rules()->checkSkipSwitcher( false, !isMapped ));
|
2007-04-29 17:35:43 +00:00
|
|
|
if( info->state() & NET::DemandsAttention )
|
|
|
|
demandAttention();
|
|
|
|
if( info->state() & NET::Modal )
|
|
|
|
setModal( true );
|
2008-12-18 15:01:25 +00:00
|
|
|
if( fullscreen_mode != FullScreenHack && isFullScreenable() )
|
2007-04-29 17:35:43 +00:00
|
|
|
setFullScreen( rules()->checkFullScreen( info->state() & NET::FullScreen, !isMapped ), false );
|
|
|
|
}
|
|
|
|
|
|
|
|
updateAllowedActions( true );
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
// Set initial user time directly
|
2007-04-29 17:35:43 +00:00
|
|
|
user_time = readUserTimeMapTimestamp( asn_valid ? &asn_id : NULL, asn_valid ? &asn_data : NULL, session );
|
2008-12-18 15:01:25 +00:00
|
|
|
group()->updateUserTime( user_time ); // And do what Client::updateUserTime() does
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
if( isTopMenu()) // They're shown in Workspace::addClient() if their mainwindow
|
|
|
|
hideClient( true ); // Is the active one
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
// This should avoid flicker, because real restacking is done
|
2007-04-29 17:35:43 +00:00
|
|
|
// only after manage() finishes because of blocking, but the window is shown sooner
|
2008-12-18 15:01:25 +00:00
|
|
|
XLowerWindow( display(), frameId() );
|
2007-04-29 17:35:43 +00:00
|
|
|
if( session && session->stackingOrder != -1 )
|
|
|
|
{
|
|
|
|
sm_stacking_order = session->stackingOrder;
|
|
|
|
workspace()->restoreSessionStackingOrder( this );
|
|
|
|
}
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
if( compositing() )
|
|
|
|
// Sending ConfigureNotify is done when setting mapping state below,
|
|
|
|
// Getting the first sync response means window is ready for compositing
|
|
|
|
sendSyncRequest();
|
2007-06-25 08:51:44 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
if( isShown( true ) && !doNotShow )
|
|
|
|
{
|
2008-12-18 15:01:25 +00:00
|
|
|
if( isDialog() )
|
2007-04-29 17:35:43 +00:00
|
|
|
Notify::raise( Notify::TransNew );
|
2008-12-18 15:01:25 +00:00
|
|
|
if( isNormalWindow() )
|
2007-04-29 17:35:43 +00:00
|
|
|
Notify::raise( Notify::New );
|
|
|
|
|
|
|
|
bool allow;
|
|
|
|
if( session )
|
2008-12-18 15:01:25 +00:00
|
|
|
allow = session->active &&
|
|
|
|
( !workspace()->wasUserInteraction() || workspace()->activeClient() == NULL ||
|
|
|
|
workspace()->activeClient()->isDesktop() );
|
2007-04-29 17:35:43 +00:00
|
|
|
else
|
|
|
|
allow = workspace()->allowClientActivation( this, userTime(), false );
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
// If session saving, force showing new windows (i.e. "save file?" dialogs etc.)
|
2007-04-29 17:35:43 +00:00
|
|
|
// also force if activation is allowed
|
2008-12-18 15:01:25 +00:00
|
|
|
if( !isOnCurrentDesktop() && !isMapped && !session && ( allow || workspace()->sessionSaving() ))
|
|
|
|
workspace()->setCurrentDesktop( desktop() );
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
bool belongs_to_desktop = false;
|
2008-11-11 23:09:11 +00:00
|
|
|
for( ClientList::ConstIterator it = group()->members().constBegin();
|
2008-12-18 15:01:25 +00:00
|
|
|
it != group()->members().constEnd();
|
|
|
|
++it )
|
|
|
|
if( (*it)->isDesktop() )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
belongs_to_desktop = true;
|
|
|
|
break;
|
|
|
|
}
|
2008-12-18 15:01:25 +00:00
|
|
|
if( !belongs_to_desktop && workspace()->showingDesktop() )
|
2007-04-29 17:35:43 +00:00
|
|
|
workspace()->resetShowingDesktop( options->showDesktopIsMinimizeAll );
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
if( isOnCurrentDesktop() && !isMapped && !allow && ( !session || session->stackingOrder < 0 ))
|
2007-04-29 17:35:43 +00:00
|
|
|
workspace()->restackClientUnderActive( this );
|
|
|
|
|
|
|
|
updateVisibility();
|
|
|
|
|
|
|
|
if( !isMapped )
|
|
|
|
{
|
2008-12-18 15:01:25 +00:00
|
|
|
if( allow && isOnCurrentDesktop() )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2008-12-18 15:01:25 +00:00
|
|
|
if( !isSpecialWindow() )
|
2007-04-29 17:35:43 +00:00
|
|
|
if ( options->focusPolicyIsReasonable() && wantsTabFocus() )
|
|
|
|
workspace()->requestFocus( this );
|
|
|
|
}
|
2008-12-18 15:01:25 +00:00
|
|
|
else if( !session && !isSpecialWindow())
|
|
|
|
demandAttention();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( !doNotShow ) // if( !isShown( true ) && !doNotShow )
|
|
|
|
updateVisibility();
|
|
|
|
else // doNotShow
|
2008-12-18 15:01:25 +00:00
|
|
|
hideClient( true ); // SELI HACK !!!
|
2008-08-12 11:02:58 +00:00
|
|
|
assert( mapping_state != Withdrawn );
|
|
|
|
blockGeometryUpdates( false );
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
if( user_time == CurrentTime || user_time == -1U )
|
|
|
|
{ // No known user time, set something old
|
2007-04-29 17:35:43 +00:00
|
|
|
user_time = xTime() - 1000000;
|
2008-12-18 15:01:25 +00:00
|
|
|
if( user_time == CurrentTime || user_time == -1U ) // Let's be paranoid
|
2007-04-29 17:35:43 +00:00
|
|
|
user_time = xTime() - 1000000 + 10;
|
|
|
|
}
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
//sendSyntheticConfigureNotify(); // Done when setting mapping state
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
delete session;
|
2008-12-18 15:01:25 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
ungrabXServer();
|
2008-12-18 15:01:25 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
client_rules.discardTemporary();
|
2008-12-18 15:01:25 +00:00
|
|
|
applyWindowRules(); // Just in case
|
|
|
|
workspace()->discardUsedWindowRules( this, false ); // Remove ApplyNow rules
|
|
|
|
updateWindowRules(); // Was blocked while !isManaged()
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
// TODO: there's a small problem here - isManaged() depends on the mapping state,
|
|
|
|
// but this client is not yet in Workspace's client list at this point, will
|
|
|
|
// be only done in addClient()
|
2007-04-29 17:35:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
// Called only from manage()
|
|
|
|
void Client::embedClient( Window w, const XWindowAttributes& attr )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
assert( client == None );
|
|
|
|
assert( frameId() == None );
|
|
|
|
assert( wrapper == None );
|
|
|
|
client = w;
|
2008-12-18 15:01:25 +00:00
|
|
|
|
|
|
|
// We don't want the window to be destroyed when we are destroyed
|
2007-04-29 17:35:43 +00:00
|
|
|
XAddToSaveSet( display(), client );
|
|
|
|
XSelectInput( display(), client, NoEventMask );
|
|
|
|
XUnmapWindow( display(), client );
|
2008-12-18 15:01:25 +00:00
|
|
|
XWindowChanges wc; // Set the border width to 0
|
|
|
|
wc.border_width = 0; // TODO: Possibly save this, and also use it for initial configuring of the window
|
2007-04-29 17:35:43 +00:00
|
|
|
XConfigureWindow( display(), client, CWBorderWidth, &wc );
|
|
|
|
|
|
|
|
XSetWindowAttributes swa;
|
|
|
|
swa.colormap = attr.colormap;
|
|
|
|
swa.background_pixmap = None;
|
|
|
|
swa.border_pixel = 0;
|
|
|
|
|
|
|
|
Window frame = XCreateWindow( display(), rootWindow(), 0, 0, 1, 1, 0,
|
2008-12-18 15:01:25 +00:00
|
|
|
attr.depth, InputOutput, attr.visual, CWColormap | CWBackPixmap | CWBorderPixel, &swa );
|
2007-04-29 17:35:43 +00:00
|
|
|
setWindowHandles( client, frame );
|
|
|
|
wrapper = XCreateWindow( display(), frame, 0, 0, 1, 1, 0,
|
2008-12-18 15:01:25 +00:00
|
|
|
attr.depth, InputOutput, attr.visual, CWColormap | CWBackPixmap | CWBorderPixel, &swa );
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
XDefineCursor( display(), frame, QCursor( Qt::ArrowCursor ).handle() );
|
|
|
|
// Some apps are stupid and don't define their own cursor - set the arrow one for them
|
|
|
|
XDefineCursor( display(), wrapper, QCursor( Qt::ArrowCursor ).handle() );
|
2007-04-29 17:35:43 +00:00
|
|
|
XReparentWindow( display(), client, wrapper, 0, 0 );
|
|
|
|
XSelectInput( display(), frame,
|
2008-12-18 15:01:25 +00:00
|
|
|
KeyPressMask | KeyReleaseMask |
|
|
|
|
ButtonPressMask | ButtonReleaseMask |
|
|
|
|
KeymapStateMask |
|
|
|
|
ButtonMotionMask |
|
|
|
|
PointerMotionMask |
|
|
|
|
EnterWindowMask | LeaveWindowMask |
|
|
|
|
FocusChangeMask |
|
|
|
|
ExposureMask |
|
|
|
|
PropertyChangeMask |
|
|
|
|
StructureNotifyMask | SubstructureRedirectMask );
|
2007-04-29 17:35:43 +00:00
|
|
|
XSelectInput( display(), wrapper, ClientWinMask | SubstructureNotifyMask );
|
|
|
|
XSelectInput( display(), client,
|
2008-12-18 15:01:25 +00:00
|
|
|
FocusChangeMask |
|
|
|
|
PropertyChangeMask |
|
|
|
|
ColormapChangeMask |
|
|
|
|
EnterWindowMask | LeaveWindowMask |
|
|
|
|
KeyPressMask | KeyReleaseMask
|
|
|
|
);
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
updateMouseGrab();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|