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
|
|
|
|
|
|
|
#include "client.h"
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QDateTime>
|
2007-06-17 17:09:40 +00:00
|
|
|
#include <QProcess>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <kstandarddirs.h>
|
|
|
|
#include <QWhatsThis>
|
2007-04-30 15:48:34 +00:00
|
|
|
#include <kwindowsystem.h>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <kiconloader.h>
|
|
|
|
#include <stdlib.h>
|
2007-11-26 15:42:44 +00:00
|
|
|
#include <signal.h>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include "bridge.h"
|
|
|
|
#include "group.h"
|
|
|
|
#include "workspace.h"
|
|
|
|
#include "atoms.h"
|
|
|
|
#include "notifications.h"
|
|
|
|
#include "rules.h"
|
|
|
|
#include "scene.h"
|
|
|
|
#include "effects.h"
|
|
|
|
#include "deleted.h"
|
2009-04-22 17:29:56 +00:00
|
|
|
#include "paintredirector.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include <X11/extensions/shape.h>
|
|
|
|
#include <QX11Info>
|
|
|
|
|
2007-06-25 08:51:44 +00:00
|
|
|
#ifdef HAVE_XSYNC
|
|
|
|
#include <X11/extensions/sync.h>
|
|
|
|
#endif
|
|
|
|
|
2009-04-22 17:29:56 +00:00
|
|
|
#ifdef HAVE_XRENDER
|
|
|
|
#include <X11/extensions/Xrender.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
// Put all externs before the namespace statement to allow the linker
|
2007-04-29 17:35:43 +00:00
|
|
|
// to resolve them properly
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
// Creating a client:
|
|
|
|
// - only by calling Workspace::createClient()
|
|
|
|
// - it creates a new client and calls manage() for it
|
|
|
|
//
|
|
|
|
// Destroying a client:
|
|
|
|
// - destroyClient() - only when the window itself has been destroyed
|
|
|
|
// - releaseWindow() - the window is kept, only the client itself is destroyed
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \class Client client.h
|
|
|
|
* \brief The Client class encapsulates a window decoration frame.
|
|
|
|
*/
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
/**
|
|
|
|
* This ctor is "dumb" - it only initializes data. All the real initialization
|
|
|
|
* is done in manage().
|
2007-04-29 17:35:43 +00:00
|
|
|
*/
|
2008-12-18 13:50:57 +00:00
|
|
|
Client::Client( Workspace* ws )
|
|
|
|
: Toplevel( ws )
|
|
|
|
, client( None )
|
|
|
|
, wrapper( None )
|
|
|
|
, decoration( NULL )
|
|
|
|
, bridge( new Bridge( this ))
|
|
|
|
, move_faked_activity( false )
|
|
|
|
, move_resize_grab_window( None )
|
|
|
|
, move_resize_has_keyboard_grab( false )
|
|
|
|
, transient_for( NULL )
|
|
|
|
, transient_for_id( None )
|
|
|
|
, original_transient_for_id( None )
|
|
|
|
, autoRaiseTimer( NULL )
|
|
|
|
, shadeHoverTimer( NULL )
|
|
|
|
, delayedMoveResizeTimer( NULL )
|
|
|
|
, in_group( NULL )
|
|
|
|
, window_group( None )
|
|
|
|
, in_layer( UnknownLayer )
|
|
|
|
, ping_timer( NULL )
|
|
|
|
, process_killer( NULL )
|
|
|
|
, user_time( CurrentTime ) // Not known yet
|
|
|
|
, allowed_actions( 0 )
|
|
|
|
, block_geometry_updates( 0 )
|
|
|
|
, pending_geometry_update( PendingGeometryNone )
|
|
|
|
, shade_geometry_change( false )
|
2007-06-25 08:51:44 +00:00
|
|
|
#ifdef HAVE_XSYNC
|
2008-12-18 13:50:57 +00:00
|
|
|
, sync_counter( None )
|
|
|
|
, sync_alarm( None )
|
2007-06-25 08:51:44 +00:00
|
|
|
#endif
|
2008-12-18 13:50:57 +00:00
|
|
|
, sync_timeout( NULL )
|
|
|
|
, sync_resize_pending( false )
|
|
|
|
, border_left( 0 )
|
|
|
|
, border_right( 0 )
|
|
|
|
, border_top( 0 )
|
|
|
|
, border_bottom( 0 )
|
|
|
|
, sm_stacking_order( -1 )
|
|
|
|
, demandAttentionKNotifyTimer( NULL )
|
2009-04-22 17:29:56 +00:00
|
|
|
, paintRedirector( 0 )
|
2009-07-24 18:32:24 +00:00
|
|
|
, padding_left( 0 )
|
|
|
|
, padding_right( 0 )
|
|
|
|
, padding_top( 0 )
|
|
|
|
, padding_bottom( 0 )
|
2008-12-18 13:50:57 +00:00
|
|
|
{ // TODO: Do all as initialization
|
|
|
|
|
|
|
|
// Set the initial mapping state
|
2008-08-12 11:02:58 +00:00
|
|
|
mapping_state = Withdrawn;
|
2008-12-18 13:50:57 +00:00
|
|
|
desk = 0; // No desktop yet
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
mode = PositionCenter;
|
|
|
|
buttonDown = false;
|
|
|
|
moveResizeMode = false;
|
|
|
|
|
|
|
|
info = NULL;
|
|
|
|
|
|
|
|
shade_mode = ShadeNone;
|
|
|
|
active = false;
|
|
|
|
deleting = false;
|
|
|
|
keep_above = false;
|
|
|
|
keep_below = false;
|
|
|
|
motif_may_move = true;
|
|
|
|
motif_may_resize = true;
|
|
|
|
motif_may_close = true;
|
|
|
|
fullscreen_mode = FullScreenNone;
|
|
|
|
skip_taskbar = false;
|
|
|
|
original_skip_taskbar = false;
|
|
|
|
minimized = false;
|
|
|
|
hidden = false;
|
|
|
|
modal = false;
|
|
|
|
noborder = false;
|
2008-03-23 00:12:11 +00:00
|
|
|
app_noborder = false;
|
2007-04-29 17:35:43 +00:00
|
|
|
urgency = false;
|
|
|
|
ignore_focus_stealing = false;
|
|
|
|
demands_attention = false;
|
|
|
|
check_active_modal = false;
|
|
|
|
|
|
|
|
Pdeletewindow = 0;
|
|
|
|
Ptakefocus = 0;
|
|
|
|
Ptakeactivity = 0;
|
|
|
|
Pcontexthelp = 0;
|
|
|
|
Pping = 0;
|
|
|
|
input = false;
|
|
|
|
skip_pager = false;
|
|
|
|
|
|
|
|
max_mode = MaximizeRestore;
|
|
|
|
maxmode_restore = MaximizeRestore;
|
2008-12-18 13:50:57 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
cmap = None;
|
2008-12-18 13:50:57 +00:00
|
|
|
|
|
|
|
geom = QRect( 0, 0, 100, 100 ); // So that decorations don't start with size being (0,0)
|
2007-04-29 17:35:43 +00:00
|
|
|
client_size = QSize( 100, 100 );
|
2007-06-25 08:51:44 +00:00
|
|
|
#if defined(HAVE_XSYNC) || defined(HAVE_XDAMAGE)
|
|
|
|
ready_for_painting = false; // wait for first damage or sync reply
|
|
|
|
#endif
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
// SELI TODO: Initialize xsizehints??
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
/**
|
|
|
|
* "Dumb" destructor.
|
2007-04-29 17:35:43 +00:00
|
|
|
*/
|
|
|
|
Client::~Client()
|
|
|
|
{
|
2007-06-25 08:51:44 +00:00
|
|
|
#ifdef HAVE_XSYNC
|
|
|
|
if( sync_alarm != None )
|
|
|
|
XSyncDestroyAlarm( display(), sync_alarm );
|
|
|
|
#endif
|
2007-04-29 17:35:43 +00:00
|
|
|
assert(!moveResizeMode);
|
|
|
|
assert( client == None );
|
|
|
|
assert( wrapper == None );
|
2008-12-18 13:50:57 +00:00
|
|
|
//assert( frameId() == None );
|
2007-04-29 17:35:43 +00:00
|
|
|
assert( decoration == NULL );
|
|
|
|
assert( block_geometry_updates == 0 );
|
|
|
|
assert( !check_active_modal );
|
|
|
|
delete bridge;
|
|
|
|
}
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
// Use destroyClient() or releaseWindow(), Client instances cannot be deleted directly
|
2007-04-29 17:35:43 +00:00
|
|
|
void Client::deleteClient( Client* c, allowed_t )
|
|
|
|
{
|
|
|
|
delete c;
|
|
|
|
}
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
/**
|
|
|
|
* Releases the window. The client has done its job and the window is still existing.
|
2007-04-29 17:35:43 +00:00
|
|
|
*/
|
|
|
|
void Client::releaseWindow( bool on_shutdown )
|
|
|
|
{
|
|
|
|
assert( !deleting );
|
|
|
|
deleting = true;
|
|
|
|
Deleted* del = Deleted::create( this );
|
|
|
|
if( effects )
|
|
|
|
{
|
|
|
|
static_cast<EffectsHandlerImpl*>(effects)->windowClosed( effectWindow());
|
|
|
|
scene->windowClosed( this, del );
|
|
|
|
}
|
|
|
|
finishCompositing();
|
2008-12-18 13:50:57 +00:00
|
|
|
workspace()->discardUsedWindowRules( this, true ); // Remove ForceTemporarily rules
|
2007-04-29 17:35:43 +00:00
|
|
|
StackingUpdatesBlocker blocker( workspace());
|
|
|
|
if (moveResizeMode)
|
|
|
|
leaveMoveResize();
|
|
|
|
finishWindowRules();
|
|
|
|
++block_geometry_updates;
|
|
|
|
if( isOnCurrentDesktop() && isShown( true ))
|
2009-06-11 20:12:11 +00:00
|
|
|
addWorkspaceRepaint( visibleRect() );
|
2008-12-18 13:50:57 +00:00
|
|
|
// Grab X during the release to make removing of properties, setting to withdrawn state
|
2007-04-30 09:41:48 +00:00
|
|
|
// and repareting to root an atomic operation (http://lists.kde.org/?l=kde-devel&m=116448102901184&w=2)
|
|
|
|
grabXServer();
|
2008-08-12 11:02:58 +00:00
|
|
|
exportMappingState( WithdrawnState );
|
2008-12-18 13:50:57 +00:00
|
|
|
setModal( false ); // Otherwise its mainwindow wouldn't get focus
|
|
|
|
hidden = true; // So that it's not considered visible anymore (can't use hideClient(), it would set flags)
|
2007-04-29 17:35:43 +00:00
|
|
|
if( !on_shutdown )
|
|
|
|
workspace()->clientHidden( this );
|
2008-12-18 13:50:57 +00:00
|
|
|
XUnmapWindow( display(), frameId()); // Destroying decoration would cause ugly visual effect
|
2007-04-29 17:35:43 +00:00
|
|
|
destroyDecoration();
|
|
|
|
cleanGrouping();
|
|
|
|
if( !on_shutdown )
|
|
|
|
{
|
|
|
|
workspace()->removeClient( this, Allowed );
|
2008-12-18 13:50:57 +00:00
|
|
|
// Only when the window is being unmapped, not when closing down KWin (NETWM sections 5.5,5.7)
|
2007-04-29 17:35:43 +00:00
|
|
|
info->setDesktop( 0 );
|
|
|
|
desk = 0;
|
2008-12-18 13:50:57 +00:00
|
|
|
info->setState( 0, info->state()); // Reset all state flags
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
XDeleteProperty( display(), client, atoms->kde_net_wm_user_creation_time);
|
|
|
|
XDeleteProperty( display(), client, atoms->net_frame_extents );
|
|
|
|
XDeleteProperty( display(), client, atoms->kde_net_wm_frame_strut );
|
2007-07-19 16:24:51 +00:00
|
|
|
XReparentWindow( display(), client, rootWindow(), x(), y());
|
2007-04-29 17:35:43 +00:00
|
|
|
XRemoveFromSaveSet( display(), client );
|
|
|
|
XSelectInput( display(), client, NoEventMask );
|
|
|
|
if( on_shutdown )
|
2008-12-18 13:50:57 +00:00
|
|
|
// Map the window, so it can be found after another WM is started
|
2007-04-29 17:35:43 +00:00
|
|
|
XMapWindow( display(), client );
|
2008-12-18 13:50:57 +00:00
|
|
|
// TODO: Preserve minimized, shaded etc. state?
|
|
|
|
else // Make sure it's not mapped if the app unmapped it (#65279). The app
|
|
|
|
// may do map+unmap before we initially map the window by calling rawShow() from manage().
|
2007-04-29 17:35:43 +00:00
|
|
|
XUnmapWindow( display(), client );
|
|
|
|
client = None;
|
|
|
|
XDestroyWindow( display(), wrapper );
|
|
|
|
wrapper = None;
|
|
|
|
XDestroyWindow( display(), frameId());
|
2008-12-18 13:50:57 +00:00
|
|
|
//frame = None;
|
|
|
|
--block_geometry_updates; // Don't use GeometryUpdatesBlocker, it would now set the geometry
|
2007-04-29 17:35:43 +00:00
|
|
|
disownDataPassedToDeleted();
|
|
|
|
del->unrefWindow();
|
2007-04-30 09:50:38 +00:00
|
|
|
checkNonExistentClients();
|
2007-04-29 17:35:43 +00:00
|
|
|
deleteClient( this, Allowed );
|
2007-04-30 09:41:48 +00:00
|
|
|
ungrabXServer();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
/**
|
|
|
|
* Like releaseWindow(), but this one is called when the window has been already destroyed
|
|
|
|
* (E.g. The application closed it)
|
|
|
|
*/
|
2007-04-29 17:35:43 +00:00
|
|
|
void Client::destroyClient()
|
|
|
|
{
|
|
|
|
assert( !deleting );
|
|
|
|
deleting = true;
|
|
|
|
Deleted* del = Deleted::create( this );
|
|
|
|
if( effects )
|
|
|
|
{
|
|
|
|
static_cast<EffectsHandlerImpl*>(effects)->windowClosed( effectWindow());
|
|
|
|
scene->windowClosed( this, del );
|
|
|
|
}
|
|
|
|
finishCompositing();
|
2008-12-18 13:50:57 +00:00
|
|
|
workspace()->discardUsedWindowRules( this, true ); // Remove ForceTemporarily rules
|
2007-04-29 17:35:43 +00:00
|
|
|
StackingUpdatesBlocker blocker( workspace());
|
|
|
|
if (moveResizeMode)
|
|
|
|
leaveMoveResize();
|
|
|
|
finishWindowRules();
|
|
|
|
++block_geometry_updates;
|
|
|
|
if( isOnCurrentDesktop() && isShown( true ))
|
2009-06-11 20:12:11 +00:00
|
|
|
addWorkspaceRepaint( visibleRect() );
|
2007-04-29 17:35:43 +00:00
|
|
|
setModal( false );
|
2008-12-18 13:50:57 +00:00
|
|
|
hidden = true; // So that it's not considered visible anymore
|
2007-04-29 17:35:43 +00:00
|
|
|
workspace()->clientHidden( this );
|
|
|
|
destroyDecoration();
|
|
|
|
cleanGrouping();
|
|
|
|
workspace()->removeClient( this, Allowed );
|
|
|
|
client = None; // invalidate
|
|
|
|
XDestroyWindow( display(), wrapper );
|
|
|
|
wrapper = None;
|
|
|
|
XDestroyWindow( display(), frameId());
|
2008-12-18 13:50:57 +00:00
|
|
|
//frame = None;
|
|
|
|
--block_geometry_updates; // Don't use GeometryUpdatesBlocker, it would now set the geometry
|
2007-04-29 17:35:43 +00:00
|
|
|
disownDataPassedToDeleted();
|
|
|
|
del->unrefWindow();
|
2007-04-30 09:47:59 +00:00
|
|
|
checkNonExistentClients();
|
2007-04-30 09:50:38 +00:00
|
|
|
deleteClient( this, Allowed );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Client::updateDecoration( bool check_workspace_pos, bool force )
|
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
if( !force &&
|
|
|
|
(( decoration == NULL && noBorder() ) || ( decoration != NULL && !noBorder() )))
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
|
|
|
bool do_show = false;
|
|
|
|
QRect oldgeom = geometry();
|
|
|
|
blockGeometryUpdates( true );
|
|
|
|
if( force )
|
|
|
|
destroyDecoration();
|
2008-12-18 13:50:57 +00:00
|
|
|
if( !noBorder() )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
setMask( QRegion()); // Reset shape mask
|
2007-04-29 17:35:43 +00:00
|
|
|
decoration = workspace()->createDecoration( bridge );
|
2008-12-18 13:50:57 +00:00
|
|
|
// TODO: Check decoration's minimum size?
|
2007-04-29 17:35:43 +00:00
|
|
|
decoration->init();
|
|
|
|
decoration->widget()->installEventFilter( this );
|
|
|
|
XReparentWindow( display(), decoration->widget()->winId(), frameId(), 0, 0 );
|
|
|
|
decoration->widget()->lower();
|
|
|
|
decoration->borders( border_left, border_right, border_top, border_bottom );
|
2009-05-04 22:35:33 +00:00
|
|
|
padding_left = padding_right = padding_top = padding_bottom = 0;
|
|
|
|
if (KDecorationUnstable *deco2 = dynamic_cast<KDecorationUnstable*>(decoration))
|
|
|
|
deco2->padding( padding_left, padding_right, padding_top, padding_bottom );
|
|
|
|
XMoveWindow( display(), decoration->widget()->winId(), -padding_left, -padding_top );
|
2007-04-29 17:35:43 +00:00
|
|
|
move( calculateGravitation( false ));
|
|
|
|
plainResize( sizeForClientSize( clientSize()), ForceGeometrySet );
|
|
|
|
do_show = true;
|
2009-04-22 17:29:56 +00:00
|
|
|
paintRedirector = new PaintRedirector( decoration->widget());
|
|
|
|
connect( paintRedirector, SIGNAL( paintPending()), SLOT( repaintDecorationPending()));
|
|
|
|
resizeDecorationPixmaps();
|
2007-04-29 17:35:43 +00:00
|
|
|
if( compositing() )
|
|
|
|
discardWindowPixmap();
|
|
|
|
if( scene != NULL )
|
|
|
|
scene->windowGeometryShapeChanged( this );
|
|
|
|
if( effects != NULL )
|
|
|
|
static_cast<EffectsHandlerImpl*>(effects)->windowGeometryShapeChanged( effectWindow(), oldgeom );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
destroyDecoration();
|
|
|
|
if( check_workspace_pos )
|
|
|
|
checkWorkspacePosition();
|
|
|
|
blockGeometryUpdates( false );
|
|
|
|
if( do_show )
|
|
|
|
decoration->widget()->show();
|
|
|
|
updateFrameExtents();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::destroyDecoration()
|
|
|
|
{
|
|
|
|
QRect oldgeom = geometry();
|
|
|
|
if( decoration != NULL )
|
|
|
|
{
|
|
|
|
delete decoration;
|
|
|
|
decoration = NULL;
|
|
|
|
QPoint grav = calculateGravitation( true );
|
|
|
|
border_left = border_right = border_top = border_bottom = 0;
|
2008-12-18 13:50:57 +00:00
|
|
|
setMask( QRegion()); // Reset shape mask
|
2007-04-29 17:35:43 +00:00
|
|
|
plainResize( sizeForClientSize( clientSize()), ForceGeometrySet );
|
|
|
|
move( grav );
|
2009-04-22 17:29:56 +00:00
|
|
|
delete paintRedirector;
|
|
|
|
paintRedirector = NULL;
|
|
|
|
decorationPixmapLeft = decorationPixmapRight = decorationPixmapTop = decorationPixmapBottom = QPixmap();
|
2007-04-29 17:35:43 +00:00
|
|
|
if( compositing() )
|
|
|
|
discardWindowPixmap();
|
|
|
|
if( scene != NULL && !deleting )
|
|
|
|
scene->windowGeometryShapeChanged( this );
|
|
|
|
if( effects != NULL && !deleting )
|
|
|
|
static_cast<EffectsHandlerImpl*>(effects)->windowGeometryShapeChanged( effectWindow(), oldgeom );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-19 19:32:32 +00:00
|
|
|
bool Client::checkBorderSizes( bool also_resize )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
if( decoration == NULL )
|
2008-03-19 19:32:32 +00:00
|
|
|
return false;
|
2009-05-04 22:35:33 +00:00
|
|
|
|
|
|
|
int new_left = 0, new_right = 0, new_top = 0, new_bottom = 0;
|
|
|
|
if (KDecorationUnstable *deco2 = dynamic_cast<KDecorationUnstable*>(decoration))
|
|
|
|
deco2->padding( new_left, new_right, new_top, new_bottom );
|
|
|
|
if (padding_left != new_left || padding_top != new_top)
|
|
|
|
XMoveWindow( display(), decoration->widget()->winId(), -new_left, -new_top );
|
|
|
|
padding_left = new_left;
|
|
|
|
padding_right = new_right;
|
|
|
|
padding_top = new_top;
|
|
|
|
padding_bottom = new_bottom;
|
2007-04-29 17:35:43 +00:00
|
|
|
decoration->borders( new_left, new_right, new_top, new_bottom );
|
2008-12-18 13:50:57 +00:00
|
|
|
if( new_left == border_left && new_right == border_right &&
|
|
|
|
new_top == border_top && new_bottom == border_bottom )
|
2008-03-19 19:32:32 +00:00
|
|
|
return false;
|
|
|
|
if( !also_resize )
|
|
|
|
{
|
|
|
|
border_left = new_left;
|
|
|
|
border_right = new_right;
|
|
|
|
border_top = new_top;
|
|
|
|
border_bottom = new_bottom;
|
|
|
|
return true;
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
GeometryUpdatesBlocker blocker( this );
|
|
|
|
move( calculateGravitation( true ));
|
|
|
|
border_left = new_left;
|
|
|
|
border_right = new_right;
|
|
|
|
border_top = new_top;
|
|
|
|
border_bottom = new_bottom;
|
|
|
|
move( calculateGravitation( false ));
|
2008-12-18 13:50:57 +00:00
|
|
|
plainResize( sizeForClientSize( clientSize() ), ForceGeometrySet );
|
2007-04-29 17:35:43 +00:00
|
|
|
checkWorkspacePosition();
|
2008-03-19 19:32:32 +00:00
|
|
|
return true;
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2009-04-22 17:29:56 +00:00
|
|
|
void Client::triggerDecorationRepaint()
|
2008-03-21 12:57:41 +00:00
|
|
|
{
|
|
|
|
if( decoration != NULL )
|
|
|
|
decoration->widget()->update();
|
|
|
|
}
|
|
|
|
|
2009-05-04 22:35:33 +00:00
|
|
|
void Client::layoutDecorationRects(QRect &left, QRect &top, QRect &right, QRect &bottom, Client::CoordinateMode mode) const
|
|
|
|
{
|
|
|
|
QRect r = decoration->widget()->rect();
|
|
|
|
if (mode == WindowRelative)
|
|
|
|
r.translate(-padding_left, -padding_top);
|
|
|
|
|
|
|
|
top = QRect(r.x(), r.y(), r.width(), padding_top + border_top);
|
|
|
|
bottom = QRect(r.x(), r.y() + r.height() - padding_bottom - border_bottom,
|
|
|
|
r.width(), padding_bottom + border_bottom);
|
|
|
|
left = QRect(r.x(), r.y() + top.height(),
|
|
|
|
padding_left + border_left, r.height() - top.height() - bottom.height());
|
|
|
|
right = QRect(r.x() + r.width() - padding_right - border_right, r.y() + top.height(),
|
|
|
|
padding_right + border_right, r.height() - top.height() - bottom.height());
|
|
|
|
}
|
|
|
|
|
2009-04-22 17:29:56 +00:00
|
|
|
void Client::repaintDecorationPending()
|
|
|
|
{
|
2009-05-04 22:35:33 +00:00
|
|
|
if ( compositing() )
|
|
|
|
{
|
|
|
|
// The scene will update the decoration pixmaps in the next painting pass
|
|
|
|
const QRegion r = paintRedirector->pendingRegion();
|
|
|
|
Workspace::self()->addRepaint( r.translated( x() - padding_left, y() - padding_top ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ensureDecorationPixmapsPainted();
|
2009-04-22 17:29:56 +00:00
|
|
|
}
|
|
|
|
|
2009-04-22 19:00:51 +00:00
|
|
|
bool Client::decorationPixmapRequiresRepaint()
|
|
|
|
{
|
|
|
|
if (!paintRedirector)
|
|
|
|
return false;
|
|
|
|
QRegion r = paintRedirector->pendingRegion();
|
|
|
|
return !r.isEmpty();
|
|
|
|
}
|
|
|
|
|
2009-04-22 17:29:56 +00:00
|
|
|
void Client::ensureDecorationPixmapsPainted()
|
|
|
|
{
|
|
|
|
if (!paintRedirector)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QRegion r = paintRedirector->pendingRegion();
|
|
|
|
if (r.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
QPixmap p = paintRedirector->performPendingPaint();
|
|
|
|
|
2009-05-04 22:35:33 +00:00
|
|
|
QRect lr, rr, tr, br;
|
|
|
|
layoutDecorationRects( lr, tr, rr, br, DecorationRelative );
|
2009-04-22 17:29:56 +00:00
|
|
|
|
|
|
|
repaintDecorationPixmap( decorationPixmapLeft, lr, p, r );
|
|
|
|
repaintDecorationPixmap( decorationPixmapRight, rr, p, r );
|
|
|
|
repaintDecorationPixmap( decorationPixmapTop, tr, p, r );
|
|
|
|
repaintDecorationPixmap( decorationPixmapBottom, br, p, r );
|
|
|
|
|
|
|
|
if (!compositing())
|
|
|
|
{
|
|
|
|
// Blit the pixmaps to the frame window
|
2009-05-04 22:35:33 +00:00
|
|
|
layoutDecorationRects( lr, tr, rr, br, WindowRelative );
|
2009-04-22 17:29:56 +00:00
|
|
|
#ifdef HAVE_XRENDER
|
|
|
|
if (Extensions::renderAvailable())
|
|
|
|
{
|
|
|
|
XRenderPictFormat* format = XRenderFindVisualFormat( display(), visual());
|
|
|
|
XRenderPictureAttributes pa;
|
|
|
|
pa.subwindow_mode = IncludeInferiors;
|
|
|
|
Picture pic = XRenderCreatePicture( display(), frameId(), format, CPSubwindowMode, &pa );
|
|
|
|
XRenderComposite( display(), PictOpSrc, decorationPixmapLeft.x11PictureHandle(), None, pic,
|
|
|
|
0, 0, 0, 0, lr.x(), lr.y(), lr.width(), lr.height() );
|
|
|
|
XRenderComposite( display(), PictOpSrc, decorationPixmapRight.x11PictureHandle(), None, pic,
|
|
|
|
0, 0, 0, 0, rr.x(), rr.y(), rr.width(), rr.height() );
|
|
|
|
XRenderComposite( display(), PictOpSrc, decorationPixmapTop.x11PictureHandle(), None, pic,
|
|
|
|
0, 0, 0, 0, tr.x(), tr.y(), tr.width(), tr.height() );
|
|
|
|
XRenderComposite( display(), PictOpSrc, decorationPixmapBottom.x11PictureHandle(), None, pic,
|
|
|
|
0, 0, 0, 0, br.x(), br.y(), br.width(), br.height() );
|
|
|
|
XRenderFreePicture( display(), pic ); // TODO don't recreate pictures all the time?
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
XGCValues values;
|
|
|
|
values.subwindow_mode = IncludeInferiors;
|
|
|
|
GC gc = XCreateGC( display(), rootWindow(), GCSubwindowMode, &values );
|
|
|
|
XCopyArea( display(), decorationPixmapLeft.handle(), frameId(), gc, 0, 0,
|
|
|
|
lr.width(), lr.height(), lr.x(), lr.y() );
|
|
|
|
XCopyArea( display(), decorationPixmapRight.handle(), frameId(), gc, 0, 0,
|
|
|
|
rr.width(), rr.height(), rr.x(), rr.y() );
|
|
|
|
XCopyArea( display(), decorationPixmapTop.handle(), frameId(), gc, 0, 0,
|
|
|
|
tr.width(), tr.height(), tr.x(), tr.y() );
|
|
|
|
XCopyArea( display(), decorationPixmapBottom.handle(), frameId(), gc, 0, 0,
|
|
|
|
br.width(), br.height(), br.x(), br.y() );
|
|
|
|
XFreeGC( display(), gc );
|
|
|
|
}
|
|
|
|
}
|
2009-05-18 16:42:23 +00:00
|
|
|
else
|
|
|
|
XSync( display(), false );
|
2009-04-22 17:29:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Client::repaintDecorationPixmap( QPixmap& pix, const QRect& r, const QPixmap& src, QRegion reg )
|
|
|
|
{
|
|
|
|
if( !r.isValid())
|
|
|
|
return;
|
|
|
|
QRect b = reg.boundingRect();
|
|
|
|
reg &= r;
|
|
|
|
if( reg.isEmpty())
|
|
|
|
return;
|
|
|
|
QPainter pt( &pix );
|
|
|
|
pt.translate( -r.topLeft() );
|
|
|
|
pt.setCompositionMode( QPainter::CompositionMode_Source );
|
|
|
|
pt.setClipRegion( reg );
|
|
|
|
pt.drawPixmap( b.topLeft(), src );
|
|
|
|
pt.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::resizeDecorationPixmaps()
|
|
|
|
{
|
2009-05-04 22:35:33 +00:00
|
|
|
QRect lr, rr, tr, br;
|
|
|
|
layoutDecorationRects( lr, tr, rr, br, DecorationRelative );
|
|
|
|
|
|
|
|
decorationPixmapTop = QPixmap( tr.size() );
|
|
|
|
decorationPixmapBottom = QPixmap( br.size() );
|
|
|
|
decorationPixmapLeft = QPixmap( lr.size() );
|
|
|
|
decorationPixmapRight = QPixmap( rr.size() );
|
2009-04-22 17:29:56 +00:00
|
|
|
#ifdef HAVE_XRENDER
|
|
|
|
if ( Extensions::renderAvailable() ) {
|
|
|
|
// Make sure the pixmaps are created with alpha channels
|
|
|
|
decorationPixmapLeft.fill( Qt::transparent );
|
|
|
|
decorationPixmapRight.fill( Qt::transparent );
|
|
|
|
decorationPixmapTop.fill( Qt::transparent );
|
|
|
|
decorationPixmapBottom.fill( Qt::transparent );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
triggerDecorationRepaint();
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
void Client::detectNoBorder()
|
|
|
|
{
|
|
|
|
if( shape())
|
|
|
|
{
|
|
|
|
noborder = true;
|
2008-03-23 00:12:11 +00:00
|
|
|
app_noborder = true;
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch( windowType())
|
|
|
|
{
|
|
|
|
case NET::Desktop :
|
|
|
|
case NET::Dock :
|
|
|
|
case NET::TopMenu :
|
|
|
|
case NET::Splash :
|
|
|
|
noborder = true;
|
2008-03-23 00:12:11 +00:00
|
|
|
app_noborder = true;
|
2008-12-18 13:50:57 +00:00
|
|
|
break;
|
2007-04-29 17:35:43 +00:00
|
|
|
case NET::Unknown :
|
|
|
|
case NET::Normal :
|
|
|
|
case NET::Toolbar :
|
|
|
|
case NET::Menu :
|
|
|
|
case NET::Dialog :
|
|
|
|
case NET::Utility :
|
|
|
|
noborder = false;
|
2008-12-18 13:50:57 +00:00
|
|
|
break;
|
2007-04-29 17:35:43 +00:00
|
|
|
default:
|
2008-09-17 11:44:51 +00:00
|
|
|
abort();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
// NET::Override is some strange beast without clear definition, usually
|
|
|
|
// just meaning "noborder", so let's treat it only as such flag, and ignore it as
|
|
|
|
// a window type otherwise (SUPPORTED_WINDOW_TYPES_MASK doesn't include it)
|
2007-12-07 15:53:43 +00:00
|
|
|
if( info->windowType( SUPPORTED_MANAGED_WINDOW_TYPES_MASK | NET::OverrideMask ) == NET::Override )
|
2008-03-23 00:12:11 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
noborder = true;
|
2008-03-23 00:12:11 +00:00
|
|
|
app_noborder = true;
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Client::updateFrameExtents()
|
|
|
|
{
|
|
|
|
NETStrut strut;
|
|
|
|
strut.left = border_left;
|
|
|
|
strut.right = border_right;
|
|
|
|
strut.top = border_top;
|
|
|
|
strut.bottom = border_bottom;
|
|
|
|
info->setFrameExtents( strut );
|
|
|
|
}
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
/**
|
|
|
|
* Resizes the decoration, and makes sure the decoration widget gets resize event
|
|
|
|
* even if the size hasn't changed. This is needed to make sure the decoration
|
|
|
|
* re-layouts (e.g. when options()->moveResizeMaximizedWindows() changes,
|
|
|
|
* the decoration may turn on/off some borders, but the actual size
|
|
|
|
* of the decoration stays the same).
|
|
|
|
*/
|
2007-04-29 17:35:43 +00:00
|
|
|
void Client::resizeDecoration( const QSize& s )
|
|
|
|
{
|
|
|
|
if( decoration == NULL )
|
|
|
|
return;
|
2009-05-04 22:35:33 +00:00
|
|
|
QSize newSize = s + QSize(padding_left + padding_right, padding_top + padding_bottom);
|
|
|
|
QSize oldSize = decoration->widget()->size();
|
|
|
|
decoration->resize( newSize );
|
|
|
|
if( oldSize == newSize )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2009-05-04 22:35:33 +00:00
|
|
|
QResizeEvent e( newSize, oldSize );
|
2007-04-29 17:35:43 +00:00
|
|
|
QApplication::sendEvent( decoration->widget(), &e );
|
|
|
|
}
|
2009-05-04 22:35:33 +00:00
|
|
|
else // oldSize != newSize
|
2009-04-22 17:29:56 +00:00
|
|
|
{
|
|
|
|
resizeDecorationPixmaps();
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Client::noBorder() const
|
|
|
|
{
|
2008-03-23 00:12:11 +00:00
|
|
|
return noborder || isFullScreen();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Client::userCanSetNoBorder() const
|
|
|
|
{
|
2008-03-23 00:12:11 +00:00
|
|
|
return !isFullScreen() && !isShade();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:12:11 +00:00
|
|
|
void Client::setNoBorder( bool set )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
if( !userCanSetNoBorder() )
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
|
|
|
set = rules()->checkNoBorder( set );
|
2008-03-23 00:12:11 +00:00
|
|
|
if( noborder == set )
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2008-03-23 00:12:11 +00:00
|
|
|
noborder = set;
|
2007-04-29 17:35:43 +00:00
|
|
|
updateDecoration( true, false );
|
|
|
|
updateWindowRules();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::updateShape()
|
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
if( shape() )
|
|
|
|
{ // Workaround for #19644 - Shaped windows shouldn't have decoration
|
|
|
|
if( !app_noborder )
|
|
|
|
{ // Only when shape is detected for the first time, still let the user to override
|
2008-03-23 00:12:11 +00:00
|
|
|
app_noborder = true;
|
|
|
|
noborder = true;
|
|
|
|
updateDecoration( true );
|
|
|
|
}
|
2007-04-29 21:19:29 +00:00
|
|
|
}
|
2008-12-18 13:50:57 +00:00
|
|
|
if( shape() && noBorder() )
|
2008-03-23 00:12:11 +00:00
|
|
|
XShapeCombineShape( display(), frameId(), ShapeBounding,
|
|
|
|
clientPos().x(), clientPos().y(), window(), ShapeBounding, ShapeSet );
|
2008-12-18 13:50:57 +00:00
|
|
|
|
2008-03-23 00:12:11 +00:00
|
|
|
// Decoration mask (i.e. 'else' here) setting is done in setMask()
|
|
|
|
// when the decoration calls it or when the decoration is created/destroyed
|
2007-07-04 09:51:10 +00:00
|
|
|
updateInputShape();
|
|
|
|
if( compositing())
|
2008-09-30 16:45:24 +00:00
|
|
|
{
|
|
|
|
addRepaintFull();
|
2009-06-11 20:12:11 +00:00
|
|
|
addWorkspaceRepaint( visibleRect() ); // In case shape change removes part of this window
|
2008-09-30 16:45:24 +00:00
|
|
|
}
|
2007-07-04 09:51:10 +00:00
|
|
|
if( scene != NULL )
|
|
|
|
scene->windowGeometryShapeChanged( this );
|
|
|
|
if( effects != NULL )
|
|
|
|
static_cast<EffectsHandlerImpl*>(effects)->windowGeometryShapeChanged( effectWindow(), geometry());
|
|
|
|
}
|
2007-04-29 21:39:58 +00:00
|
|
|
|
2008-03-23 00:12:11 +00:00
|
|
|
static Window shape_helper_window = None;
|
|
|
|
|
2007-07-04 09:51:10 +00:00
|
|
|
void Client::updateInputShape()
|
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
if( hiddenPreview() ) // Sets it to none, don't change
|
2007-07-04 09:51:10 +00:00
|
|
|
return;
|
2007-05-30 14:22:09 +00:00
|
|
|
if( Extensions::shapeInputAvailable())
|
2007-04-29 21:59:40 +00:00
|
|
|
{ // There appears to be no way to find out if a window has input
|
|
|
|
// shape set or not, so always propagate the input shape
|
|
|
|
// (it's the same like the bounding shape by default).
|
|
|
|
// Also, build the shape using a helper window, not directly
|
|
|
|
// in the frame window, because the sequence set-shape-to-frame,
|
|
|
|
// remove-shape-of-client, add-input-shape-of-client has the problem
|
|
|
|
// that after the second step there's a hole in the input shape
|
|
|
|
// until the real shape of the client is added and that can make
|
|
|
|
// the window lose focus (which is a problem with mouse focus policies)
|
2008-12-18 13:50:57 +00:00
|
|
|
// TODO: It seems there is, after all - XShapeGetRectangles() - but maybe this is better
|
2008-03-23 00:12:11 +00:00
|
|
|
if( shape_helper_window == None )
|
|
|
|
shape_helper_window = XCreateSimpleWindow( display(), rootWindow(),
|
2007-04-29 21:59:40 +00:00
|
|
|
0, 0, 1, 1, 0, 0, 0 );
|
2008-03-23 00:12:11 +00:00
|
|
|
XResizeWindow( display(), shape_helper_window, width(), height());
|
|
|
|
XShapeCombineShape( display(), shape_helper_window, ShapeInput, 0, 0,
|
2008-12-18 13:50:57 +00:00
|
|
|
frameId(), ShapeBounding, ShapeSet );
|
2008-03-23 00:12:11 +00:00
|
|
|
XShapeCombineShape( display(), shape_helper_window, ShapeInput,
|
2008-12-18 13:50:57 +00:00
|
|
|
clientPos().x(), clientPos().y(), window(), ShapeBounding, ShapeSubtract );
|
2008-03-23 00:12:11 +00:00
|
|
|
XShapeCombineShape( display(), shape_helper_window, ShapeInput,
|
2008-12-18 13:50:57 +00:00
|
|
|
clientPos().x(), clientPos().y(), window(), ShapeInput, ShapeUnion );
|
2007-04-29 21:59:40 +00:00
|
|
|
XShapeCombineShape( display(), frameId(), ShapeInput, 0, 0,
|
2008-12-18 13:50:57 +00:00
|
|
|
shape_helper_window, ShapeInput, ShapeSet );
|
2007-04-29 21:19:29 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Client::setMask( const QRegion& reg, int mode )
|
|
|
|
{
|
2009-05-04 22:35:33 +00:00
|
|
|
QRegion r = reg.translated( -padding_left, -padding_right ) & QRect( 0, 0, width(), height() );
|
|
|
|
if( _mask == r )
|
2008-03-23 00:12:11 +00:00
|
|
|
return;
|
2009-05-04 22:35:33 +00:00
|
|
|
_mask = r;
|
2008-03-23 00:12:11 +00:00
|
|
|
Window shape_window = frameId();
|
2008-12-18 13:50:57 +00:00
|
|
|
if( shape() )
|
|
|
|
{ // The same way of applying a shape without strange intermediate states like above
|
2008-03-23 00:12:11 +00:00
|
|
|
if( shape_helper_window == None )
|
|
|
|
shape_helper_window = XCreateSimpleWindow( display(), rootWindow(),
|
|
|
|
0, 0, 1, 1, 0, 0, 0 );
|
|
|
|
shape_window = shape_helper_window;
|
|
|
|
}
|
2009-05-04 22:35:33 +00:00
|
|
|
if( _mask.isEmpty() )
|
2008-12-18 13:50:57 +00:00
|
|
|
XShapeCombineMask( display(), shape_window, ShapeBounding, 0, 0, None, ShapeSet );
|
2007-04-29 17:35:43 +00:00
|
|
|
else if( mode == X::Unsorted )
|
2009-05-04 22:35:33 +00:00
|
|
|
XShapeCombineRegion( display(), shape_window, ShapeBounding, 0, 0, _mask.handle(), ShapeSet );
|
2007-04-29 17:35:43 +00:00
|
|
|
else
|
|
|
|
{
|
2009-05-04 22:35:33 +00:00
|
|
|
QVector< QRect > rects = _mask.rects();
|
2008-12-18 13:50:57 +00:00
|
|
|
XRectangle* xrects = new XRectangle[rects.count()];
|
|
|
|
for( int i = 0; i < rects.count(); ++i )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
xrects[i].x = rects[i].x();
|
|
|
|
xrects[i].y = rects[i].y();
|
|
|
|
xrects[i].width = rects[i].width();
|
|
|
|
xrects[i].height = rects[i].height();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2008-03-23 00:12:11 +00:00
|
|
|
XShapeCombineRectangles( display(), shape_window, ShapeBounding, 0, 0,
|
2007-04-29 17:35:43 +00:00
|
|
|
xrects, rects.count(), ShapeSet, mode );
|
|
|
|
delete[] xrects;
|
|
|
|
}
|
2008-12-18 13:50:57 +00:00
|
|
|
if( shape() )
|
|
|
|
{ // The rest of the applyign using a temporary window
|
2008-03-23 00:12:11 +00:00
|
|
|
XRectangle rec = { 0, 0, clientSize().width(), clientSize().height() };
|
|
|
|
XShapeCombineRectangles( display(), shape_helper_window, ShapeBounding,
|
2008-12-18 13:50:57 +00:00
|
|
|
clientPos().x(), clientPos().y(), &rec, 1, ShapeSubtract, Unsorted );
|
2008-03-23 00:12:11 +00:00
|
|
|
XShapeCombineShape( display(), shape_helper_window, ShapeBounding,
|
2008-12-18 13:50:57 +00:00
|
|
|
clientPos().x(), clientPos().y(), window(), ShapeBounding, ShapeUnion );
|
2008-03-23 00:12:11 +00:00
|
|
|
XShapeCombineShape( display(), frameId(), ShapeBounding, 0, 0,
|
2008-12-18 13:50:57 +00:00
|
|
|
shape_helper_window, ShapeBounding, ShapeSet );
|
2008-03-23 00:12:11 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
if( scene != NULL )
|
|
|
|
scene->windowGeometryShapeChanged( this );
|
|
|
|
if( effects != NULL )
|
2008-12-18 13:50:57 +00:00
|
|
|
static_cast<EffectsHandlerImpl*>( effects )->windowGeometryShapeChanged( effectWindow(), geometry() );
|
2007-05-02 12:50:37 +00:00
|
|
|
updateShape();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QRegion Client::mask() const
|
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
if( _mask.isEmpty() )
|
|
|
|
return QRegion( 0, 0, width(), height() );
|
2007-04-29 17:35:43 +00:00
|
|
|
return _mask;
|
|
|
|
}
|
2008-12-18 13:50:57 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
void Client::hideClient( bool hide )
|
|
|
|
{
|
|
|
|
if( hidden == hide )
|
|
|
|
return;
|
|
|
|
hidden = hide;
|
|
|
|
updateVisibility();
|
|
|
|
}
|
2008-12-18 13:50:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether the window is minimizable or not
|
2007-04-29 17:35:43 +00:00
|
|
|
*/
|
|
|
|
bool Client::isMinimizable() const
|
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
if( isSpecialWindow() )
|
2007-04-29 17:35:43 +00:00
|
|
|
return false;
|
2008-12-18 13:50:57 +00:00
|
|
|
if( isTransient() )
|
|
|
|
{ // #66868 - Let other xmms windows be minimized when the mainwindow is minimized
|
2007-04-29 17:35:43 +00:00
|
|
|
bool shown_mainwindow = false;
|
|
|
|
ClientList mainclients = mainClients();
|
2008-11-11 23:09:11 +00:00
|
|
|
for( ClientList::ConstIterator it = mainclients.constBegin();
|
2008-12-18 13:50:57 +00:00
|
|
|
it != mainclients.constEnd();
|
|
|
|
++it )
|
2007-04-29 17:35:43 +00:00
|
|
|
if( (*it)->isShown( true ))
|
|
|
|
shown_mainwindow = true;
|
|
|
|
if( !shown_mainwindow )
|
|
|
|
return true;
|
|
|
|
}
|
2009-01-09 14:07:03 +00:00
|
|
|
#if 0
|
2008-12-18 13:50:57 +00:00
|
|
|
// This is here because kicker's taskbar doesn't provide separate entries
|
2007-04-29 17:35:43 +00:00
|
|
|
// for windows with an explicitly given parent
|
2008-12-18 13:50:57 +00:00
|
|
|
// TODO: perhaps this should be redone
|
2009-01-09 14:07:03 +00:00
|
|
|
// Disabled for now, since at least modal dialogs should be minimizable
|
|
|
|
// (resulting in the mainwindow being minimized too).
|
2007-04-29 17:35:43 +00:00
|
|
|
if( transientFor() != NULL )
|
|
|
|
return false;
|
2009-01-09 14:07:03 +00:00
|
|
|
#endif
|
2008-12-18 13:50:57 +00:00
|
|
|
if( !wantsTabFocus() ) // SELI, TODO: - NET::Utility? why wantsTabFocus() - skiptaskbar? ?
|
2007-04-29 17:35:43 +00:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
/**
|
|
|
|
* Minimizes this client plus its transients
|
2007-04-29 17:35:43 +00:00
|
|
|
*/
|
|
|
|
void Client::minimize( bool avoid_animation )
|
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
if( !isMinimizable() || isMinimized() )
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
Notify::raise( Notify::Minimize );
|
|
|
|
|
|
|
|
minimized = true;
|
|
|
|
|
|
|
|
updateVisibility();
|
|
|
|
updateAllowedActions();
|
|
|
|
workspace()->updateMinimizedOfTransients( this );
|
|
|
|
updateWindowRules();
|
|
|
|
workspace()->updateFocusChains( this, Workspace::FocusChainMakeLast );
|
2008-12-18 13:50:57 +00:00
|
|
|
if( effects && !avoid_animation ) // TODO: Shouldn't it tell effects at least about the change?
|
2007-04-29 17:35:43 +00:00
|
|
|
static_cast<EffectsHandlerImpl*>(effects)->windowMinimized( effectWindow());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::unminimize( bool avoid_animation )
|
|
|
|
{
|
|
|
|
if( !isMinimized())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Notify::raise( Notify::UnMinimize );
|
|
|
|
minimized = false;
|
|
|
|
updateVisibility();
|
|
|
|
updateAllowedActions();
|
|
|
|
workspace()->updateMinimizedOfTransients( this );
|
|
|
|
updateWindowRules();
|
|
|
|
if( effects && !avoid_animation )
|
2008-12-18 13:50:57 +00:00
|
|
|
static_cast<EffectsHandlerImpl*>( effects )->windowUnminimized( effectWindow() );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QRect Client::iconGeometry() const
|
|
|
|
{
|
|
|
|
NETRect r = info->iconGeometry();
|
|
|
|
QRect geom( r.pos.x, r.pos.y, r.size.width, r.size.height );
|
|
|
|
if( geom.isValid() )
|
|
|
|
return geom;
|
|
|
|
else
|
2008-12-18 13:50:57 +00:00
|
|
|
{ // Check all mainwindows of this window (recursively)
|
2007-04-29 17:35:43 +00:00
|
|
|
foreach( Client* mainwin, mainClients() )
|
|
|
|
{
|
|
|
|
geom = mainwin->iconGeometry();
|
|
|
|
if( geom.isValid() )
|
|
|
|
return geom;
|
|
|
|
}
|
|
|
|
// No mainwindow (or their parents) with icon geometry was found
|
|
|
|
return QRect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Client::isShadeable() const
|
|
|
|
{
|
|
|
|
return !isSpecialWindow() && !noBorder();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::setShade( ShadeMode mode )
|
|
|
|
{
|
|
|
|
if( !isShadeable())
|
|
|
|
return;
|
|
|
|
mode = rules()->checkShade( mode );
|
|
|
|
if( shade_mode == mode )
|
|
|
|
return;
|
|
|
|
bool was_shade = isShade();
|
|
|
|
ShadeMode was_shade_mode = shade_mode;
|
|
|
|
shade_mode = mode;
|
|
|
|
if( was_shade == isShade())
|
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
if( decoration != NULL ) // Decoration may want to update after e.g. hover-shade changes
|
2007-04-29 17:35:43 +00:00
|
|
|
decoration->shadeChange();
|
2008-12-18 13:50:57 +00:00
|
|
|
return; // No real change in shaded state
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( shade_mode == ShadeNormal )
|
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
if( isShown( true ) && isOnCurrentDesktop() )
|
|
|
|
Notify::raise( Notify::ShadeUp );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
else if( shade_mode == ShadeNone )
|
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
if( isShown( true ) && isOnCurrentDesktop() )
|
|
|
|
Notify::raise( Notify::ShadeDown );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assert( decoration != NULL ); // noborder windows can't be shaded
|
|
|
|
GeometryUpdatesBlocker blocker( this );
|
2008-12-18 13:50:57 +00:00
|
|
|
// Decorations may turn off some borders when shaded
|
2007-04-29 17:35:43 +00:00
|
|
|
decoration->borders( border_left, border_right, border_top, border_bottom );
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
// TODO: All this unmapping, resizing etc. feels too much duplicated from elsewhere
|
2007-04-29 17:35:43 +00:00
|
|
|
if ( isShade())
|
|
|
|
{ // shade_mode == ShadeNormal
|
2009-06-11 20:12:11 +00:00
|
|
|
addWorkspaceRepaint( visibleRect() );
|
2008-12-18 13:50:57 +00:00
|
|
|
// Shade
|
2007-04-29 17:35:43 +00:00
|
|
|
shade_geometry_change = true;
|
2008-12-18 13:50:57 +00:00
|
|
|
QSize s( sizeForClientSize( QSize( clientSize() )));
|
2007-04-29 17:35:43 +00:00
|
|
|
s.setHeight( border_top + border_bottom );
|
2008-12-18 13:50:57 +00:00
|
|
|
XSelectInput( display(), wrapper, ClientWinMask ); // Avoid getting UnmapNotify
|
2007-04-29 17:35:43 +00:00
|
|
|
XUnmapWindow( display(), wrapper );
|
|
|
|
XUnmapWindow( display(), client );
|
|
|
|
XSelectInput( display(), wrapper, ClientWinMask | SubstructureNotifyMask );
|
|
|
|
plainResize( s );
|
|
|
|
shade_geometry_change = false;
|
|
|
|
if( isActive())
|
|
|
|
{
|
|
|
|
if( was_shade_mode == ShadeHover )
|
|
|
|
workspace()->activateNextClient( this );
|
|
|
|
else
|
|
|
|
workspace()->focusToNull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
shade_geometry_change = true;
|
2008-12-18 13:50:57 +00:00
|
|
|
QSize s( sizeForClientSize( clientSize() ));
|
2007-04-29 17:35:43 +00:00
|
|
|
shade_geometry_change = false;
|
|
|
|
plainResize( s );
|
|
|
|
if( shade_mode == ShadeHover || shade_mode == ShadeActivated )
|
|
|
|
setActive( true );
|
2008-12-18 13:50:57 +00:00
|
|
|
XMapWindow( display(), wrapperId() );
|
|
|
|
XMapWindow( display(), window() );
|
2007-04-29 17:35:43 +00:00
|
|
|
if ( isActive() )
|
|
|
|
workspace()->requestFocus( this );
|
|
|
|
}
|
|
|
|
checkMaximizeGeometry();
|
|
|
|
info->setState( isShade() ? NET::Shaded : 0, NET::Shaded );
|
|
|
|
info->setState( isShown( false ) ? 0 : NET::Hidden, NET::Hidden );
|
|
|
|
discardWindowPixmap();
|
|
|
|
updateVisibility();
|
|
|
|
updateAllowedActions();
|
|
|
|
workspace()->updateMinimizedOfTransients( this );
|
|
|
|
decoration->shadeChange();
|
|
|
|
updateWindowRules();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::shadeHover()
|
|
|
|
{
|
|
|
|
setShade( ShadeHover );
|
2008-12-15 08:27:17 +00:00
|
|
|
cancelShadeHoverTimer();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2008-12-15 08:27:17 +00:00
|
|
|
void Client::shadeUnhover()
|
|
|
|
{
|
|
|
|
setShade( ShadeNormal );
|
|
|
|
cancelShadeHoverTimer();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::cancelShadeHoverTimer()
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
delete shadeHoverTimer;
|
|
|
|
shadeHoverTimer = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::toggleShade()
|
2008-12-18 13:50:57 +00:00
|
|
|
{ // If the mode is ShadeHover or ShadeActive, cancel shade too
|
2007-04-29 17:35:43 +00:00
|
|
|
setShade( shade_mode == ShadeNone ? ShadeNormal : ShadeNone );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::updateVisibility()
|
|
|
|
{
|
|
|
|
if( deleting )
|
|
|
|
return;
|
|
|
|
if( hidden )
|
|
|
|
{
|
|
|
|
info->setState( NET::Hidden, NET::Hidden );
|
2008-12-18 13:50:57 +00:00
|
|
|
setSkipTaskbar( true, false ); // Also hide from taskbar
|
2008-08-12 11:02:58 +00:00
|
|
|
if( compositing() && options->hiddenPreviews == HiddenPreviewsAlways )
|
|
|
|
internalKeep( Allowed );
|
|
|
|
else
|
|
|
|
internalHide( Allowed );
|
|
|
|
return;
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2008-12-18 13:50:57 +00:00
|
|
|
setSkipTaskbar( original_skip_taskbar, false ); // Reset from 'hidden'
|
2007-04-29 17:35:43 +00:00
|
|
|
if( minimized )
|
|
|
|
{
|
|
|
|
info->setState( NET::Hidden, NET::Hidden );
|
2008-08-12 11:02:58 +00:00
|
|
|
if( compositing() && options->hiddenPreviews == HiddenPreviewsAlways )
|
|
|
|
internalKeep( Allowed );
|
|
|
|
else
|
|
|
|
internalHide( Allowed );
|
|
|
|
return;
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2008-08-12 11:02:58 +00:00
|
|
|
info->setState( 0, NET::Hidden );
|
2007-04-29 17:35:43 +00:00
|
|
|
if( !isOnCurrentDesktop())
|
|
|
|
{
|
2008-08-12 11:02:58 +00:00
|
|
|
if( compositing() && options->hiddenPreviews != HiddenPreviewsNever )
|
|
|
|
internalKeep( Allowed );
|
2007-04-29 17:35:43 +00:00
|
|
|
else
|
2008-08-12 11:02:58 +00:00
|
|
|
internalHide( Allowed );
|
|
|
|
return;
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2008-08-12 11:02:58 +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 13:50:57 +00:00
|
|
|
it != group()->members().constEnd();
|
|
|
|
++it )
|
|
|
|
if( (*it)->isDesktop() )
|
2008-08-12 11:02:58 +00:00
|
|
|
{
|
|
|
|
belongs_to_desktop = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if( !belongs_to_desktop && workspace()->showingDesktop())
|
|
|
|
workspace()->resetShowingDesktop( true );
|
|
|
|
internalShow( Allowed );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
/**
|
|
|
|
* Sets the client window's mapping state. Possible values are
|
|
|
|
* WithdrawnState, IconicState, NormalState.
|
2007-04-29 17:35:43 +00:00
|
|
|
*/
|
2008-12-18 13:50:57 +00:00
|
|
|
void Client::exportMappingState( int s )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
assert( client != None );
|
|
|
|
assert( !deleting || s == WithdrawnState );
|
2008-08-12 11:02:58 +00:00
|
|
|
if( s == WithdrawnState )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
XDeleteProperty( display(), window(), atoms->wm_state );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
assert( s == NormalState || s == IconicState );
|
|
|
|
|
|
|
|
unsigned long data[2];
|
|
|
|
data[0] = (unsigned long) s;
|
|
|
|
data[1] = (unsigned long) None;
|
|
|
|
XChangeProperty(display(), window(), atoms->wm_state, atoms->wm_state, 32,
|
2008-12-18 13:50:57 +00:00
|
|
|
PropModeReplace, (unsigned char*)( data ), 2);
|
2008-08-12 11:02:58 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-08-12 11:02:58 +00:00
|
|
|
void Client::internalShow( allowed_t )
|
|
|
|
{
|
|
|
|
if( mapping_state == Mapped )
|
|
|
|
return;
|
|
|
|
MappingState old = mapping_state;
|
|
|
|
mapping_state = Mapped;
|
|
|
|
if( old == Unmapped || old == Withdrawn )
|
|
|
|
map( Allowed );
|
|
|
|
if( old == Kept )
|
|
|
|
updateHiddenPreview();
|
2008-08-24 13:32:57 +00:00
|
|
|
workspace()->checkUnredirect();
|
2008-08-12 11:02:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Client::internalHide( allowed_t )
|
|
|
|
{
|
|
|
|
if( mapping_state == Unmapped )
|
|
|
|
return;
|
|
|
|
MappingState old = mapping_state;
|
|
|
|
mapping_state = Unmapped;
|
|
|
|
if( old == Mapped || old == Kept )
|
|
|
|
unmap( Allowed );
|
|
|
|
if( old == Kept )
|
|
|
|
updateHiddenPreview();
|
2009-06-11 20:12:11 +00:00
|
|
|
addWorkspaceRepaint( visibleRect() );
|
2008-08-12 11:02:58 +00:00
|
|
|
workspace()->clientHidden( this );
|
2008-08-24 13:32:57 +00:00
|
|
|
workspace()->checkUnredirect();
|
2008-08-12 11:02:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Client::internalKeep( allowed_t )
|
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
assert( compositing() );
|
2008-08-12 11:02:58 +00:00
|
|
|
if( mapping_state == Kept )
|
|
|
|
return;
|
|
|
|
MappingState old = mapping_state;
|
|
|
|
mapping_state = Kept;
|
|
|
|
if( old == Unmapped || old == Withdrawn )
|
|
|
|
map( Allowed );
|
|
|
|
updateHiddenPreview();
|
2009-06-11 20:12:11 +00:00
|
|
|
addWorkspaceRepaint( visibleRect() );
|
2008-08-12 11:02:58 +00:00
|
|
|
workspace()->clientHidden( this );
|
2008-08-24 13:32:57 +00:00
|
|
|
workspace()->checkUnredirect();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
/**
|
|
|
|
* Maps (shows) the client. Note that it is mapping state of the frame,
|
|
|
|
* not necessarily the client window itself (i.e. a shaded window is here
|
|
|
|
* considered mapped, even though it is in IconicState).
|
2007-04-29 17:35:43 +00:00
|
|
|
*/
|
2008-08-12 11:02:58 +00:00
|
|
|
void Client::map( allowed_t )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2008-08-12 11:02:58 +00:00
|
|
|
// XComposite invalidates backing pixmaps on unmap (minimize, different
|
|
|
|
// virtual desktop, etc.). We kept the last known good pixmap around
|
|
|
|
// for use in effects, but now we want to have access to the new pixmap
|
|
|
|
if( compositing() )
|
|
|
|
discardWindowPixmap();
|
2007-04-29 17:35:43 +00:00
|
|
|
if( decoration != NULL )
|
2008-12-18 13:50:57 +00:00
|
|
|
decoration->widget()->show(); // Not really necessary, but let it know the state
|
2007-04-29 17:35:43 +00:00
|
|
|
XMapWindow( display(), frameId());
|
|
|
|
if( !isShade())
|
|
|
|
{
|
|
|
|
XMapWindow( display(), wrapper );
|
|
|
|
XMapWindow( display(), client );
|
2008-08-12 11:02:58 +00:00
|
|
|
exportMappingState( NormalState );
|
2007-07-04 09:51:10 +00:00
|
|
|
}
|
|
|
|
else
|
2008-08-12 11:02:58 +00:00
|
|
|
exportMappingState( IconicState );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
/**
|
|
|
|
* Unmaps the client. Again, this is about the frame.
|
|
|
|
*/
|
2008-08-12 11:02:58 +00:00
|
|
|
void Client::unmap( allowed_t )
|
|
|
|
{
|
|
|
|
// Here it may look like a race condition, as some other client might try to unmap
|
|
|
|
// the window between these two XSelectInput() calls. However, they're supposed to
|
|
|
|
// use XWithdrawWindow(), which also sends a synthetic event to the root window,
|
|
|
|
// which won't be missed, so this shouldn't be a problem. The chance the real UnmapNotify
|
|
|
|
// will be missed is also very minimal, so I don't think it's needed to grab the server
|
|
|
|
// here.
|
2008-12-18 13:50:57 +00:00
|
|
|
XSelectInput( display(), wrapper, ClientWinMask ); // Avoid getting UnmapNotify
|
|
|
|
XUnmapWindow( display(), frameId() );
|
2008-08-12 11:02:58 +00:00
|
|
|
XUnmapWindow( display(), wrapper );
|
|
|
|
XUnmapWindow( display(), client );
|
|
|
|
XSelectInput( display(), wrapper, ClientWinMask | SubstructureNotifyMask );
|
|
|
|
if( decoration != NULL )
|
2008-12-18 13:50:57 +00:00
|
|
|
decoration->widget()->hide(); // Not really necessary, but let it know the state
|
2008-08-12 11:02:58 +00:00
|
|
|
exportMappingState( IconicState );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
/**
|
|
|
|
* XComposite doesn't keep window pixmaps of unmapped windows, which means
|
|
|
|
* there wouldn't be any previews of windows that are minimized or on another
|
|
|
|
* virtual desktop. Therefore rawHide() actually keeps such windows mapped.
|
|
|
|
* However special care needs to be taken so that such windows don't interfere.
|
|
|
|
* Therefore they're put very low in the stacking order and they have input shape
|
|
|
|
* set to none, which hopefully is enough. If there's no input shape available,
|
|
|
|
* then it's hoped that there will be some other desktop above it *shrug*.
|
|
|
|
* Using normal shape would be better, but that'd affect other things, e.g. painting
|
|
|
|
* of the actual preview.
|
|
|
|
*/
|
2008-08-12 11:02:58 +00:00
|
|
|
void Client::updateHiddenPreview()
|
2007-07-04 09:51:10 +00:00
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
if( hiddenPreview() )
|
2008-08-12 11:02:58 +00:00
|
|
|
{
|
2007-07-04 09:51:10 +00:00
|
|
|
workspace()->forceRestacking();
|
2008-12-18 13:50:57 +00:00
|
|
|
if( Extensions::shapeInputAvailable() )
|
2007-07-04 09:51:10 +00:00
|
|
|
XShapeCombineRectangles( display(), frameId(), ShapeInput, 0, 0, NULL, 0, ShapeSet, Unsorted );
|
|
|
|
}
|
2008-08-12 11:02:58 +00:00
|
|
|
else
|
|
|
|
{
|
2007-07-04 09:51:10 +00:00
|
|
|
workspace()->forceRestacking();
|
|
|
|
updateInputShape();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
void Client::sendClientMessage( Window w, Atom a, Atom protocol, long data1, long data2, long data3 )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
XEvent ev;
|
|
|
|
long mask;
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
memset( &ev, 0, sizeof( ev ));
|
2007-04-29 17:35:43 +00:00
|
|
|
ev.xclient.type = ClientMessage;
|
|
|
|
ev.xclient.window = w;
|
|
|
|
ev.xclient.message_type = a;
|
|
|
|
ev.xclient.format = 32;
|
|
|
|
ev.xclient.data.l[0] = protocol;
|
|
|
|
ev.xclient.data.l[1] = xTime();
|
|
|
|
ev.xclient.data.l[2] = data1;
|
|
|
|
ev.xclient.data.l[3] = data2;
|
|
|
|
ev.xclient.data.l[4] = data3;
|
|
|
|
mask = 0L;
|
2008-12-18 13:50:57 +00:00
|
|
|
if( w == rootWindow() )
|
|
|
|
mask = SubstructureRedirectMask; // Magic!
|
|
|
|
XSendEvent( display(), w, False, mask, &ev );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
/**
|
|
|
|
* Returns whether the window may be closed (have a close button)
|
2007-04-29 17:35:43 +00:00
|
|
|
*/
|
|
|
|
bool Client::isCloseable() const
|
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
return rules()->checkCloseable( motif_may_close && !isSpecialWindow() );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
/**
|
|
|
|
* Closes the window by either sending a delete_window message or using XKill.
|
2007-04-29 17:35:43 +00:00
|
|
|
*/
|
|
|
|
void Client::closeWindow()
|
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
if( !isCloseable() )
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2008-12-18 13:50:57 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
// Update user time, because the window may create a confirming dialog.
|
2008-12-18 13:50:57 +00:00
|
|
|
updateUserTime();
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
if ( Pdeletewindow )
|
|
|
|
{
|
|
|
|
Notify::raise( Notify::Close );
|
|
|
|
sendClientMessage( window(), atoms->wm_protocols, atoms->wm_delete_window);
|
|
|
|
pingWindow();
|
|
|
|
}
|
2008-12-18 13:50:57 +00:00
|
|
|
else // Client will not react on wm_delete_window. We have not choice
|
|
|
|
// but destroy his connection to the XServer.
|
2007-04-29 17:35:43 +00:00
|
|
|
killWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
/**
|
|
|
|
* Kills the window via XKill
|
2007-04-29 17:35:43 +00:00
|
|
|
*/
|
|
|
|
void Client::killWindow()
|
|
|
|
{
|
2007-08-03 06:59:24 +00:00
|
|
|
kDebug( 1212 ) << "Client::killWindow():" << caption();
|
2008-12-18 13:50:57 +00:00
|
|
|
|
|
|
|
// Not sure if we need an Notify::Kill or not.. until then, use
|
2007-04-29 17:35:43 +00:00
|
|
|
// Notify::Close
|
|
|
|
Notify::raise( Notify::Close );
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
if( isDialog() )
|
2007-04-29 17:35:43 +00:00
|
|
|
Notify::raise( Notify::TransDelete );
|
2008-12-18 13:50:57 +00:00
|
|
|
if( isNormalWindow() )
|
2007-04-29 17:35:43 +00:00
|
|
|
Notify::raise( Notify::Delete );
|
|
|
|
killProcess( false );
|
2008-12-18 13:50:57 +00:00
|
|
|
XKillClient(display(), window() ); // Always kill this client at the server
|
2007-04-29 17:35:43 +00:00
|
|
|
destroyClient();
|
|
|
|
}
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
/**
|
|
|
|
* Send a ping to the window using _NET_WM_PING if possible if it
|
|
|
|
* doesn't respond within a reasonable time, it will be killed.
|
|
|
|
*/
|
2007-04-29 17:35:43 +00:00
|
|
|
void Client::pingWindow()
|
|
|
|
{
|
|
|
|
if( !Pping )
|
2008-12-18 13:50:57 +00:00
|
|
|
return; // Can't ping :(
|
2007-04-29 17:35:43 +00:00
|
|
|
if( options->killPingTimeout == 0 )
|
2008-12-18 13:50:57 +00:00
|
|
|
return; // Turned off
|
2007-04-29 17:35:43 +00:00
|
|
|
if( ping_timer != NULL )
|
2008-12-18 13:50:57 +00:00
|
|
|
return; // Pinging already
|
2007-04-29 17:35:43 +00:00
|
|
|
ping_timer = new QTimer( this );
|
2008-12-18 13:50:57 +00:00
|
|
|
connect( ping_timer, SIGNAL( timeout() ), SLOT( pingTimeout() ));
|
2007-04-29 17:35:43 +00:00
|
|
|
ping_timer->setSingleShot( true );
|
|
|
|
ping_timer->start( options->killPingTimeout );
|
|
|
|
ping_timestamp = xTime();
|
|
|
|
workspace()->sendPingToWindow( window(), ping_timestamp );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::gotPing( Time timestamp )
|
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
// Just plain compare is not good enough because of 64bit and truncating and whatnot
|
2007-04-30 12:38:30 +00:00
|
|
|
if( NET::timestampCompare( timestamp, ping_timestamp ) != 0 )
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
|
|
|
delete ping_timer;
|
|
|
|
ping_timer = NULL;
|
|
|
|
if( process_killer != NULL )
|
|
|
|
{
|
|
|
|
process_killer->kill();
|
2008-12-18 13:50:57 +00:00
|
|
|
// Recycle when the process manager has noticed that the process exited
|
2008-06-11 13:51:20 +00:00
|
|
|
// a delete process_killer here sometimes causes a hang in waitForFinished
|
2008-12-18 13:50:57 +00:00
|
|
|
connect(process_killer, SIGNAL( finished(int, QProcess::ExitStatus) ),
|
|
|
|
process_killer, SLOT( deleteLater() ));
|
2007-04-29 17:35:43 +00:00
|
|
|
process_killer = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::pingTimeout()
|
|
|
|
{
|
2007-08-03 06:59:24 +00:00
|
|
|
kDebug( 1212 ) << "Ping timeout:" << caption();
|
2008-03-07 19:54:11 +00:00
|
|
|
ping_timer->deleteLater();
|
2007-04-29 17:35:43 +00:00
|
|
|
ping_timer = NULL;
|
|
|
|
killProcess( true, ping_timestamp );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::killProcess( bool ask, Time timestamp )
|
|
|
|
{
|
|
|
|
if( process_killer != NULL )
|
|
|
|
return;
|
|
|
|
Q_ASSERT( !ask || timestamp != CurrentTime );
|
|
|
|
QByteArray machine = wmClientMachine( true );
|
|
|
|
pid_t pid = info->pid();
|
2008-12-18 13:50:57 +00:00
|
|
|
if( pid <= 0 || machine.isEmpty()) // Needed properties missing
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2007-08-03 06:59:24 +00:00
|
|
|
kDebug( 1212 ) << "Kill process:" << pid << "(" << machine << ")";
|
2007-04-29 17:35:43 +00:00
|
|
|
if( !ask )
|
|
|
|
{
|
|
|
|
if( machine != "localhost" )
|
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
QStringList lst;
|
|
|
|
lst << machine << "kill" << QString::number( pid );
|
|
|
|
QProcess::startDetached( "xon",lst );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
::kill( pid, SIGTERM );
|
|
|
|
}
|
|
|
|
else
|
2007-07-19 16:38:46 +00:00
|
|
|
{
|
2007-11-26 15:42:44 +00:00
|
|
|
process_killer = new QProcess( this );
|
2008-12-18 13:50:57 +00:00
|
|
|
connect( process_killer, SIGNAL( error(QProcess::ProcessError) ), SLOT( processKillerExited() ));
|
|
|
|
connect( process_killer, SIGNAL( finished(int, QProcess::ExitStatus) ), SLOT( processKillerExited() ));
|
2007-11-26 15:42:44 +00:00
|
|
|
process_killer->start( KStandardDirs::findExe( "kwin_killer_helper" ),
|
2008-12-18 13:50:57 +00:00
|
|
|
QStringList() << "--pid" << QByteArray().setNum( unsigned( pid )) << "--hostname" << machine
|
2008-04-29 09:13:00 +00:00
|
|
|
<< "--windowname" << caption()
|
2007-04-29 17:35:43 +00:00
|
|
|
<< "--applicationname" << resourceClass()
|
|
|
|
<< "--wid" << QString::number( window() )
|
2007-11-26 15:42:44 +00:00
|
|
|
<< "--timestamp" << QString::number( timestamp ));
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::processKillerExited()
|
|
|
|
{
|
2007-08-03 06:59:24 +00:00
|
|
|
kDebug( 1212 ) << "Killer exited";
|
2007-04-29 17:35:43 +00:00
|
|
|
delete process_killer;
|
|
|
|
process_killer = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::setSkipTaskbar( bool b, bool from_outside )
|
|
|
|
{
|
|
|
|
int was_wants_tab_focus = wantsTabFocus();
|
|
|
|
if( from_outside )
|
|
|
|
{
|
|
|
|
b = rules()->checkSkipTaskbar( b );
|
|
|
|
original_skip_taskbar = b;
|
|
|
|
}
|
2008-12-18 13:50:57 +00:00
|
|
|
if( b == skipTaskbar() )
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
|
|
|
skip_taskbar = b;
|
2008-12-18 13:50:57 +00:00
|
|
|
info->setState( b ? NET::SkipTaskbar : 0, NET::SkipTaskbar );
|
2007-04-29 17:35:43 +00:00
|
|
|
updateWindowRules();
|
|
|
|
if( was_wants_tab_focus != wantsTabFocus())
|
|
|
|
workspace()->updateFocusChains( this,
|
|
|
|
isActive() ? Workspace::FocusChainMakeFirst : Workspace::FocusChainUpdate );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::setSkipPager( bool b )
|
|
|
|
{
|
|
|
|
b = rules()->checkSkipPager( b );
|
2008-12-18 13:50:57 +00:00
|
|
|
if( b == skipPager() )
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
|
|
|
skip_pager = b;
|
2008-12-18 13:50:57 +00:00
|
|
|
info->setState( b ? NET::SkipPager : 0, NET::SkipPager );
|
2007-04-29 17:35:43 +00:00
|
|
|
updateWindowRules();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::setModal( bool m )
|
|
|
|
{ // Qt-3.2 can have even modal normal windows :(
|
|
|
|
if( modal == m )
|
|
|
|
return;
|
|
|
|
modal = m;
|
|
|
|
if( !modal )
|
|
|
|
return;
|
2008-12-18 13:50:57 +00:00
|
|
|
// Changing modality for a mapped window is weird (?)
|
2007-04-29 17:35:43 +00:00
|
|
|
// _NET_WM_STATE_MODAL should possibly rather be _NET_WM_WINDOW_TYPE_MODAL_DIALOG
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::setDesktop( int desktop )
|
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
if( desktop != NET::OnAllDesktops ) // Do range check
|
2007-04-29 17:35:43 +00:00
|
|
|
desktop = qMax( 1, qMin( workspace()->numberOfDesktops(), desktop ));
|
2008-11-25 03:23:59 +00:00
|
|
|
desktop = qMin( workspace()->numberOfDesktops(), rules()->checkDesktop( desktop ));
|
2007-04-29 17:35:43 +00:00
|
|
|
if( desk == desktop )
|
|
|
|
return;
|
|
|
|
int was_desk = desk;
|
|
|
|
desk = desktop;
|
|
|
|
info->setDesktop( desktop );
|
|
|
|
if(( was_desk == NET::OnAllDesktops ) != ( desktop == NET::OnAllDesktops ))
|
|
|
|
{ // onAllDesktops changed
|
2008-12-18 13:50:57 +00:00
|
|
|
if( isShown( true ))
|
2007-04-29 17:35:43 +00:00
|
|
|
Notify::raise( isOnAllDesktops() ? Notify::OnAllDesktops : Notify::NotOnAllDesktops );
|
|
|
|
workspace()->updateOnAllDesktopsOfTransients( this );
|
|
|
|
}
|
|
|
|
if( decoration != NULL )
|
|
|
|
decoration->desktopChange();
|
|
|
|
workspace()->updateFocusChains( this, Workspace::FocusChainMakeFirst );
|
|
|
|
updateVisibility();
|
|
|
|
updateWindowRules();
|
|
|
|
}
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
/**
|
|
|
|
* Returns the virtual desktop within the workspace() the client window
|
|
|
|
* is located in, 0 if it isn't located on any special desktop (not mapped yet),
|
|
|
|
* or NET::OnAllDesktops. Do not use desktop() directly, use
|
|
|
|
* isOnDesktop() instead.
|
2007-04-29 17:35:43 +00:00
|
|
|
*/
|
|
|
|
int Client::desktop() const
|
|
|
|
{
|
|
|
|
return desk;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::setOnAllDesktops( bool b )
|
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
if(( b && isOnAllDesktops() ) ||
|
|
|
|
( !b && !isOnAllDesktops() ))
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
|
|
|
if( b )
|
|
|
|
setDesktop( NET::OnAllDesktops );
|
|
|
|
else
|
|
|
|
setDesktop( workspace()->currentDesktop());
|
|
|
|
}
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
/**
|
|
|
|
* Performs activation and/or raising of the window
|
|
|
|
*/
|
2007-04-29 17:35:43 +00:00
|
|
|
void Client::takeActivity( int flags, bool handled, allowed_t )
|
|
|
|
{
|
|
|
|
if( !handled || !Ptakeactivity )
|
|
|
|
{
|
|
|
|
if( flags & ActivityFocus )
|
|
|
|
takeFocus( Allowed );
|
|
|
|
if( flags & ActivityRaise )
|
|
|
|
workspace()->raiseClient( this );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
static Time previous_activity_timestamp;
|
|
|
|
static Client* previous_client;
|
2008-12-18 13:50:57 +00:00
|
|
|
|
|
|
|
//if( previous_activity_timestamp == xTime() && previous_client != this )
|
|
|
|
// {
|
|
|
|
// kDebug( 1212 ) << "Repeated use of the same X timestamp for activity";
|
|
|
|
// kDebug( 1212 ) << kBacktrace();
|
|
|
|
// }
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
previous_activity_timestamp = xTime();
|
|
|
|
previous_client = this;
|
|
|
|
#endif
|
2008-12-18 13:50:57 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
workspace()->sendTakeActivity( this, xTime(), flags );
|
|
|
|
}
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
/**
|
|
|
|
* Performs the actual focusing of the window using XSetInputFocus and WM_TAKE_FOCUS
|
|
|
|
*/
|
2007-04-29 17:35:43 +00:00
|
|
|
void Client::takeFocus( allowed_t )
|
|
|
|
{
|
|
|
|
#ifndef NDEBUG
|
|
|
|
static Time previous_focus_timestamp;
|
|
|
|
static Client* previous_client;
|
2008-12-18 13:50:57 +00:00
|
|
|
|
|
|
|
//if( previous_focus_timestamp == xTime() && previous_client != this )
|
|
|
|
// {
|
|
|
|
// kDebug( 1212 ) << "Repeated use of the same X timestamp for focus";
|
|
|
|
// kDebug( 1212 ) << kBacktrace();
|
|
|
|
// }
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
previous_focus_timestamp = xTime();
|
|
|
|
previous_client = this;
|
|
|
|
#endif
|
2008-12-18 13:50:57 +00:00
|
|
|
if( rules()->checkAcceptFocus( input ))
|
2007-04-29 17:35:43 +00:00
|
|
|
XSetInputFocus( display(), window(), RevertToPointerRoot, xTime() );
|
2008-12-18 13:50:57 +00:00
|
|
|
if( Ptakefocus )
|
|
|
|
sendClientMessage( window(), atoms->wm_protocols, atoms->wm_take_focus );
|
2007-04-29 17:35:43 +00:00
|
|
|
workspace()->setShouldGetFocus( this );
|
|
|
|
}
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
/**
|
|
|
|
* Returns whether the window provides context help or not. If it does,
|
|
|
|
* you should show a help menu item or a help button like '?' and call
|
|
|
|
* contextHelp() if this is invoked.
|
|
|
|
*
|
|
|
|
* \sa contextHelp()
|
2007-04-29 17:35:43 +00:00
|
|
|
*/
|
|
|
|
bool Client::providesContextHelp() const
|
|
|
|
{
|
|
|
|
return Pcontexthelp;
|
|
|
|
}
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
/**
|
|
|
|
* Invokes context help on the window. Only works if the window
|
|
|
|
* actually provides context help.
|
|
|
|
*
|
|
|
|
* \sa providesContextHelp()
|
2007-04-29 17:35:43 +00:00
|
|
|
*/
|
|
|
|
void Client::showContextHelp()
|
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
if( Pcontexthelp )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
sendClientMessage( window(), atoms->wm_protocols, atoms->net_wm_context_help );
|
|
|
|
QWhatsThis::enterWhatsThisMode(); // SELI TODO: ?
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
/**
|
|
|
|
* Fetches the window's caption (WM_NAME property). It will be
|
|
|
|
* stored in the client's caption().
|
2007-04-29 17:35:43 +00:00
|
|
|
*/
|
|
|
|
void Client::fetchName()
|
|
|
|
{
|
|
|
|
setCaption( readName());
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Client::readName() const
|
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
if( info->name() && info->name()[0] != '\0' )
|
2007-04-29 17:35:43 +00:00
|
|
|
return QString::fromUtf8( info->name() );
|
2008-12-18 13:50:57 +00:00
|
|
|
else
|
2007-04-30 15:48:34 +00:00
|
|
|
return KWindowSystem::readNameProperty( window(), XA_WM_NAME );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2008-12-18 13:50:57 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
KWIN_COMPARE_PREDICATE( FetchNameInternalPredicate, Client, const Client*, (!cl->isSpecialWindow() || cl->isToolbar()) && cl != value && cl->caption() == value->caption());
|
|
|
|
|
2008-12-19 10:32:54 +00:00
|
|
|
// The list is taken from http://www.unicode.org/reports/tr9/ (#154840)
|
2008-08-13 16:33:54 +00:00
|
|
|
QChar LRM(0x200E);
|
|
|
|
QChar RLM(0x200F);
|
|
|
|
QChar LRE(0x202A);
|
|
|
|
QChar RLE(0x202B);
|
|
|
|
QChar LRO(0x202D);
|
|
|
|
QChar RLO(0x202E);
|
|
|
|
QChar PDF(0x202C);
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
void Client::setCaption( const QString& _s, bool force )
|
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
QString s = _s;
|
|
|
|
if( s != cap_normal || force )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
bool reset_name = force;
|
2008-12-18 13:50:57 +00:00
|
|
|
for( int i = 0; i < s.length(); ++i )
|
|
|
|
if( !s[i].isPrint() )
|
|
|
|
s[i] = QChar( ' ' );
|
2007-04-29 17:35:43 +00:00
|
|
|
cap_normal = s;
|
2008-12-18 13:50:57 +00:00
|
|
|
bool was_suffix = ( !cap_suffix.isEmpty() );
|
2007-04-29 17:35:43 +00:00
|
|
|
QString machine_suffix;
|
|
|
|
if( wmClientMachine( false ) != "localhost" && !isLocalMachine( wmClientMachine( false )))
|
2008-12-19 10:32:54 +00:00
|
|
|
machine_suffix = QString( " <@" ) + wmClientMachine( true ) + '>' + LRM;
|
2007-04-29 17:35:43 +00:00
|
|
|
QString shortcut_suffix = !shortcut().isEmpty() ? ( " {" + shortcut().toString() + '}' ) : QString();
|
|
|
|
cap_suffix = machine_suffix + shortcut_suffix;
|
2008-12-18 13:50:57 +00:00
|
|
|
if(( !isSpecialWindow() || isToolbar() ) && workspace()->findClient( FetchNameInternalPredicate( this )))
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
int i = 2;
|
2008-12-18 13:50:57 +00:00
|
|
|
do
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2008-08-13 16:33:54 +00:00
|
|
|
cap_suffix = machine_suffix + " <" + QString::number(i) + '>' + LRM + shortcut_suffix;
|
2007-04-29 17:35:43 +00:00
|
|
|
i++;
|
|
|
|
} while ( workspace()->findClient( FetchNameInternalPredicate( this )));
|
|
|
|
info->setVisibleName( caption().toUtf8() );
|
|
|
|
reset_name = false;
|
|
|
|
}
|
2008-12-18 13:50:57 +00:00
|
|
|
if(( was_suffix && cap_suffix.isEmpty() ) || reset_name )
|
|
|
|
{ // If it was new window, it may have old value still set, if the window is reused
|
|
|
|
info->setVisibleName( "" );
|
|
|
|
info->setVisibleIconName( "" );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2008-12-18 13:50:57 +00:00
|
|
|
else if( !cap_suffix.isEmpty() && !cap_iconic.isEmpty())
|
|
|
|
// Keep the same suffix in iconic name if it's set
|
2007-04-29 17:35:43 +00:00
|
|
|
info->setVisibleIconName( ( cap_iconic + cap_suffix ).toUtf8() );
|
|
|
|
|
|
|
|
if( isManaged() && decoration != NULL )
|
2008-12-18 13:50:57 +00:00
|
|
|
decoration->captionChange();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::updateCaption()
|
|
|
|
{
|
|
|
|
setCaption( cap_normal, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::fetchIconicName()
|
|
|
|
{
|
|
|
|
QString s;
|
2008-12-18 13:50:57 +00:00
|
|
|
if( info->iconName() && info->iconName()[0] != '\0' )
|
2007-04-29 17:35:43 +00:00
|
|
|
s = QString::fromUtf8( info->iconName() );
|
2008-12-18 13:50:57 +00:00
|
|
|
else
|
2007-04-30 15:48:34 +00:00
|
|
|
s = KWindowSystem::readNameProperty( window(), XA_WM_ICON_NAME );
|
2008-12-18 13:50:57 +00:00
|
|
|
if( s != cap_iconic )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
bool was_set = !cap_iconic.isEmpty();
|
2007-04-29 17:35:43 +00:00
|
|
|
cap_iconic = s;
|
|
|
|
if( !cap_suffix.isEmpty())
|
2008-12-18 13:50:57 +00:00
|
|
|
{
|
|
|
|
if( !cap_iconic.isEmpty()) // Keep the same suffix in iconic name if it's set
|
|
|
|
info->setVisibleIconName( ( s + cap_suffix ).toUtf8() );
|
|
|
|
else if( was_set )
|
|
|
|
info->setVisibleIconName( "" );
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
/**
|
|
|
|
* \reimp
|
2007-04-29 17:35:43 +00:00
|
|
|
*/
|
|
|
|
QString Client::caption( bool full ) const
|
|
|
|
{
|
|
|
|
return full ? cap_normal + cap_suffix : cap_normal;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::getWMHints()
|
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
XWMHints* hints = XGetWMHints( display(), window() );
|
2007-04-29 17:35:43 +00:00
|
|
|
input = true;
|
|
|
|
window_group = None;
|
|
|
|
urgency = false;
|
2008-12-18 13:50:57 +00:00
|
|
|
if( hints )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
if( hints->flags & InputHint )
|
|
|
|
input = hints->input;
|
|
|
|
if( hints->flags & WindowGroupHint )
|
|
|
|
window_group = hints->window_group;
|
2008-12-18 13:50:57 +00:00
|
|
|
urgency = !!( hints->flags & UrgencyHint ); // Need boolean, it's a uint bitfield
|
2007-04-29 17:35:43 +00:00
|
|
|
XFree( (char*)hints );
|
|
|
|
}
|
|
|
|
checkGroup();
|
|
|
|
updateUrgency();
|
2008-12-18 13:50:57 +00:00
|
|
|
updateAllowedActions(); // Group affects isMinimizable()
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Client::getMotifHints()
|
|
|
|
{
|
|
|
|
bool mnoborder, mresize, mmove, mminimize, mmaximize, mclose;
|
|
|
|
Motif::readFlags( client, mnoborder, mresize, mmove, mminimize, mmaximize, mclose );
|
2008-03-22 14:34:22 +00:00
|
|
|
if( mnoborder )
|
2008-03-23 00:12:11 +00:00
|
|
|
{
|
2008-03-22 14:34:22 +00:00
|
|
|
noborder = true;
|
2008-03-23 00:12:11 +00:00
|
|
|
app_noborder = true;
|
|
|
|
}
|
2008-12-18 13:50:57 +00:00
|
|
|
if( !hasNETSupport() )
|
|
|
|
{ // NETWM apps should set type and size constraints
|
|
|
|
motif_may_resize = mresize; // This should be set using minsize==maxsize, but oh well
|
2007-04-29 17:35:43 +00:00
|
|
|
motif_may_move = mmove;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
motif_may_resize = motif_may_move = true;
|
2008-12-18 13:50:57 +00:00
|
|
|
|
|
|
|
// mminimize; - Ignore, bogus - E.g. shading or sending to another desktop is "minimizing" too
|
|
|
|
// mmaximize; - Ignore, bogus - Maximizing is basically just resizing
|
|
|
|
motif_may_close = mclose; // Motif apps like to crash when they set this hint and WM closes them anyway
|
|
|
|
if( isManaged() )
|
|
|
|
updateDecoration( true ); // Check if noborder state has changed
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Client::readIcons( Window win, QPixmap* icon, QPixmap* miniicon )
|
2008-12-18 13:50:57 +00:00
|
|
|
{
|
|
|
|
// Get the icons, allow scaling
|
2007-04-29 17:35:43 +00:00
|
|
|
if( icon != NULL )
|
2007-04-30 15:48:34 +00:00
|
|
|
*icon = KWindowSystem::icon( win, 32, 32, true, KWindowSystem::NETWM | KWindowSystem::WMHints );
|
2007-04-29 17:35:43 +00:00
|
|
|
if( miniicon != NULL )
|
2008-12-08 03:49:44 +00:00
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
if( icon == NULL || !icon->isNull() )
|
2007-04-30 15:48:34 +00:00
|
|
|
*miniicon = KWindowSystem::icon( win, 16, 16, true, KWindowSystem::NETWM | KWindowSystem::WMHints );
|
2007-04-29 17:35:43 +00:00
|
|
|
else
|
|
|
|
*miniicon = QPixmap();
|
2008-12-08 03:49:44 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Client::getIcons()
|
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
// First read icons from the window itself
|
2007-04-29 17:35:43 +00:00
|
|
|
readIcons( window(), &icon_pix, &miniicon_pix );
|
2008-12-18 13:50:57 +00:00
|
|
|
if( icon_pix.isNull() )
|
|
|
|
{ // Then try window group
|
2007-04-29 17:35:43 +00:00
|
|
|
icon_pix = group()->icon();
|
|
|
|
miniicon_pix = group()->miniIcon();
|
|
|
|
}
|
2008-12-18 13:50:57 +00:00
|
|
|
if( icon_pix.isNull() && isTransient() )
|
|
|
|
{ // Then mainclients
|
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 13:50:57 +00:00
|
|
|
it != mainclients.constEnd() && icon_pix.isNull();
|
|
|
|
++it )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
icon_pix = (*it)->icon();
|
|
|
|
miniicon_pix = (*it)->miniIcon();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( icon_pix.isNull())
|
2008-12-18 13:50:57 +00:00
|
|
|
{ // And if nothing else, load icon from classhint or xapp icon
|
2007-04-30 15:48:34 +00:00
|
|
|
icon_pix = KWindowSystem::icon( window(), 32, 32, true, KWindowSystem::ClassHint | KWindowSystem::XApp );
|
|
|
|
miniicon_pix = KWindowSystem::icon( window(), 16, 16, true, KWindowSystem::ClassHint | KWindowSystem::XApp );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
if( isManaged() && decoration != NULL )
|
|
|
|
decoration->iconChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::getWindowProtocols()
|
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
Atom* p;
|
2007-04-29 17:35:43 +00:00
|
|
|
int i,n;
|
|
|
|
|
|
|
|
Pdeletewindow = 0;
|
|
|
|
Ptakefocus = 0;
|
|
|
|
Ptakeactivity = 0;
|
|
|
|
Pcontexthelp = 0;
|
|
|
|
Pping = 0;
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
if( XGetWMProtocols( display(), window(), &p, &n ))
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
for( i = 0; i < n; i++ )
|
|
|
|
{
|
|
|
|
if( p[i] == atoms->wm_delete_window )
|
2007-04-29 17:35:43 +00:00
|
|
|
Pdeletewindow = 1;
|
2008-12-18 13:50:57 +00:00
|
|
|
else if( p[i] == atoms->wm_take_focus )
|
2007-04-29 17:35:43 +00:00
|
|
|
Ptakefocus = 1;
|
2008-12-18 13:50:57 +00:00
|
|
|
else if( p[i] == atoms->net_wm_take_activity )
|
2007-04-29 17:35:43 +00:00
|
|
|
Ptakeactivity = 1;
|
2008-12-18 13:50:57 +00:00
|
|
|
else if( p[i] == atoms->net_wm_context_help )
|
2007-04-29 17:35:43 +00:00
|
|
|
Pcontexthelp = 1;
|
2008-12-18 13:50:57 +00:00
|
|
|
else if( p[i] == atoms->net_wm_ping )
|
2007-04-29 17:35:43 +00:00
|
|
|
Pping = 1;
|
2008-12-18 13:50:57 +00:00
|
|
|
}
|
|
|
|
if( n > 0 )
|
|
|
|
XFree( p );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-25 08:51:44 +00:00
|
|
|
void Client::getSyncCounter()
|
|
|
|
{
|
|
|
|
#ifdef HAVE_XSYNC
|
2008-12-18 13:50:57 +00:00
|
|
|
if( !Extensions::syncAvailable() )
|
2007-06-25 08:51:44 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
Atom retType;
|
|
|
|
unsigned long nItemRet;
|
|
|
|
unsigned long byteRet;
|
|
|
|
int formatRet;
|
|
|
|
unsigned char* propRet;
|
|
|
|
int ret = XGetWindowProperty( display(), window(), atoms->net_wm_sync_request_counter,
|
|
|
|
0, 1, false, XA_CARDINAL, &retType, &formatRet, &nItemRet, &byteRet, &propRet );
|
2008-12-18 13:50:57 +00:00
|
|
|
|
2007-06-25 08:51:44 +00:00
|
|
|
if( ret == Success && formatRet == 32 )
|
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
sync_counter = *(long*)( propRet );
|
2007-06-25 08:51:44 +00:00
|
|
|
XSyncIntToValue( &sync_counter_value, 0 );
|
2008-12-18 13:50:57 +00:00
|
|
|
XSyncValue zero;
|
|
|
|
XSyncIntToValue( &zero, 0 );
|
|
|
|
XSyncSetCounter( display(), sync_counter, zero );
|
2007-06-25 08:51:44 +00:00
|
|
|
if( sync_alarm == None )
|
|
|
|
{
|
|
|
|
XSyncAlarmAttributes attrs;
|
|
|
|
attrs.trigger.counter = sync_counter;
|
|
|
|
attrs.trigger.value_type = XSyncRelative;
|
|
|
|
attrs.trigger.test_type = XSyncPositiveTransition;
|
|
|
|
XSyncIntToValue( &attrs.trigger.wait_value, 1 );
|
|
|
|
XSyncIntToValue( &attrs.delta, 1 );
|
|
|
|
sync_alarm = XSyncCreateAlarm( display(),
|
|
|
|
XSyncCACounter | XSyncCAValueType | XSyncCATestType | XSyncCADelta | XSyncCAValue,
|
2008-12-18 13:50:57 +00:00
|
|
|
&attrs );
|
2007-06-25 08:51:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
/**
|
|
|
|
* Send the client a _NET_SYNC_REQUEST
|
|
|
|
*/
|
2007-06-25 08:51:44 +00:00
|
|
|
void Client::sendSyncRequest()
|
|
|
|
{
|
|
|
|
#ifdef HAVE_XSYNC
|
|
|
|
if( sync_counter == None )
|
|
|
|
return;
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
// We increment before the notify so that after the notify
|
2007-06-25 08:51:44 +00:00
|
|
|
// syncCounterSerial will equal the value we are expecting
|
|
|
|
// in the acknowledgement
|
|
|
|
int overflow;
|
|
|
|
XSyncValue one;
|
|
|
|
XSyncIntToValue( &one, 1 );
|
2008-12-18 13:50:57 +00:00
|
|
|
#undef XSyncValueAdd // It causes a warning :-/
|
2007-06-25 08:51:44 +00:00
|
|
|
XSyncValueAdd( &sync_counter_value, sync_counter_value, one, &overflow );
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
// Send the message to client
|
2007-06-25 08:51:44 +00:00
|
|
|
XEvent ev;
|
|
|
|
ev.xclient.type = ClientMessage;
|
|
|
|
ev.xclient.window = window();
|
|
|
|
ev.xclient.format = 32;
|
|
|
|
ev.xclient.message_type = atoms->wm_protocols;
|
2008-12-18 13:50:57 +00:00
|
|
|
ev.xclient.data.l[0] = atoms->net_wm_sync_request;
|
|
|
|
ev.xclient.data.l[1] = xTime();
|
|
|
|
ev.xclient.data.l[2] = XSyncValueLow32( sync_counter_value );
|
|
|
|
ev.xclient.data.l[3] = XSyncValueHigh32( sync_counter_value );
|
|
|
|
ev.xclient.data.l[4] = 0;
|
2007-06-25 08:51:44 +00:00
|
|
|
XSendEvent( display(), window(), False, NoEventMask, &ev );
|
2008-12-18 13:50:57 +00:00
|
|
|
XSync( display(), false );
|
2007-06-25 08:51:44 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
bool Client::wantsTabFocus() const
|
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
return ( isNormalWindow() || isDialog() ) && wantsInput();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Client::wantsInput() const
|
|
|
|
{
|
|
|
|
return rules()->checkAcceptFocus( input || Ptakefocus );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Client::isSpecialWindow() const
|
2008-12-18 13:50:57 +00:00
|
|
|
{ // TODO
|
|
|
|
return isDesktop() || isDock() || isSplash() || isTopMenu() || isToolbar();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
/**
|
|
|
|
* Sets an appropriate cursor shape for the logical mouse position \a m
|
2007-04-29 17:35:43 +00:00
|
|
|
*/
|
2007-05-22 15:46:42 +00:00
|
|
|
void Client::updateCursor()
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2007-05-22 15:46:42 +00:00
|
|
|
Position m = mode;
|
2008-12-18 13:50:57 +00:00
|
|
|
if( !isResizable() || isShade() )
|
2007-04-29 17:35:43 +00:00
|
|
|
m = PositionCenter;
|
2007-05-22 15:46:42 +00:00
|
|
|
QCursor c;
|
|
|
|
switch( m )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
case PositionTopLeft:
|
|
|
|
case PositionBottomRight:
|
2007-05-22 15:46:42 +00:00
|
|
|
c = Qt::SizeFDiagCursor;
|
2007-04-29 17:35:43 +00:00
|
|
|
break;
|
|
|
|
case PositionBottomLeft:
|
|
|
|
case PositionTopRight:
|
2007-05-22 15:46:42 +00:00
|
|
|
c = Qt::SizeBDiagCursor;
|
2007-04-29 17:35:43 +00:00
|
|
|
break;
|
|
|
|
case PositionTop:
|
|
|
|
case PositionBottom:
|
2007-05-22 15:46:42 +00:00
|
|
|
c = Qt::SizeVerCursor;
|
2007-04-29 17:35:43 +00:00
|
|
|
break;
|
|
|
|
case PositionLeft:
|
|
|
|
case PositionRight:
|
2007-05-22 15:46:42 +00:00
|
|
|
c = Qt::SizeHorCursor;
|
2007-04-29 17:35:43 +00:00
|
|
|
break;
|
|
|
|
default:
|
2007-05-22 15:46:42 +00:00
|
|
|
if( moveResizeMode )
|
|
|
|
c = Qt::SizeAllCursor;
|
2007-04-29 17:35:43 +00:00
|
|
|
else
|
2007-05-22 15:46:42 +00:00
|
|
|
c = Qt::ArrowCursor;
|
2007-04-29 17:35:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if( c.handle() == cursor.handle())
|
|
|
|
return;
|
|
|
|
cursor = c;
|
|
|
|
if( decoration != NULL )
|
|
|
|
decoration->widget()->setCursor( cursor );
|
2008-12-18 13:50:57 +00:00
|
|
|
XDefineCursor( display(), frameId(), cursor.handle() );
|
2007-05-22 15:46:42 +00:00
|
|
|
if( moveResizeMode ) // XDefineCursor doesn't change cursor if there's pointer grab active
|
|
|
|
XChangeActivePointerGrab( display(),
|
|
|
|
ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | LeaveWindowMask,
|
|
|
|
cursor.handle(), xTime());
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Client::Position Client::mousePosition( const QPoint& p ) const
|
|
|
|
{
|
|
|
|
if( decoration != NULL )
|
|
|
|
return decoration->mousePosition( p );
|
|
|
|
return PositionCenter;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::updateAllowedActions( bool force )
|
|
|
|
{
|
|
|
|
if( !isManaged() && !force )
|
|
|
|
return;
|
|
|
|
unsigned long old_allowed_actions = allowed_actions;
|
|
|
|
allowed_actions = 0;
|
2008-12-18 13:50:57 +00:00
|
|
|
if( isMovable() )
|
2007-04-29 17:35:43 +00:00
|
|
|
allowed_actions |= NET::ActionMove;
|
2008-12-18 13:50:57 +00:00
|
|
|
if( isResizable() )
|
2007-04-29 17:35:43 +00:00
|
|
|
allowed_actions |= NET::ActionResize;
|
2008-12-18 13:50:57 +00:00
|
|
|
if( isMinimizable() )
|
2007-04-29 17:35:43 +00:00
|
|
|
allowed_actions |= NET::ActionMinimize;
|
2008-12-18 13:50:57 +00:00
|
|
|
if( isShadeable() )
|
2007-04-29 17:35:43 +00:00
|
|
|
allowed_actions |= NET::ActionShade;
|
2008-12-18 13:50:57 +00:00
|
|
|
// Sticky state not supported
|
|
|
|
if( isMaximizable() )
|
2007-04-29 17:35:43 +00:00
|
|
|
allowed_actions |= NET::ActionMax;
|
2008-12-18 13:50:57 +00:00
|
|
|
if( userCanSetFullScreen() )
|
2007-04-29 17:35:43 +00:00
|
|
|
allowed_actions |= NET::ActionFullScreen;
|
2008-12-18 13:50:57 +00:00
|
|
|
allowed_actions |= NET::ActionChangeDesktop; // Always (Pagers shouldn't show Docks etc.)
|
|
|
|
if( isCloseable() )
|
2007-04-29 17:35:43 +00:00
|
|
|
allowed_actions |= NET::ActionClose;
|
|
|
|
if( old_allowed_actions == allowed_actions )
|
|
|
|
return;
|
2008-12-18 13:50:57 +00:00
|
|
|
// TODO: This could be delayed and compressed - It's only for pagers etc. anyway
|
2007-04-29 17:35:43 +00:00
|
|
|
info->setAllowedActions( allowed_actions );
|
2008-12-18 13:50:57 +00:00
|
|
|
// TODO: This should also tell the decoration, so that it can update the buttons
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Client::autoRaise()
|
|
|
|
{
|
|
|
|
workspace()->raiseClient( this );
|
|
|
|
cancelAutoRaise();
|
|
|
|
}
|
2008-12-18 13:50:57 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
void Client::cancelAutoRaise()
|
|
|
|
{
|
|
|
|
delete autoRaiseTimer;
|
|
|
|
autoRaiseTimer = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::debug( kdbgstream& stream ) const
|
|
|
|
{
|
2008-12-18 13:50:57 +00:00
|
|
|
stream << "\'ID:" << window() << ";WMCLASS:" << resourceClass() << ":"
|
|
|
|
<< resourceName() << ";Caption:" << caption() << "\'";
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2008-12-18 13:50:57 +00:00
|
|
|
QPixmap* kwin_get_menu_pix_hack()
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
static QPixmap p;
|
2008-12-18 13:50:57 +00:00
|
|
|
if( p.isNull() )
|
2007-04-29 17:35:43 +00:00
|
|
|
p = SmallIcon( "bx2" );
|
|
|
|
return &p;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#include "client.moc"
|