2002-06-29 06:31:33 +00:00
|
|
|
/*****************************************************************
|
2003-09-16 19:28:03 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2002-06-29 06:31:33 +00:00
|
|
|
|
|
|
|
Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
|
|
|
|
Copyright (C) 1997 to 2002 Cristian Tibirna <tibirna@kde.org>
|
2003-09-16 19:28:03 +00:00
|
|
|
Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
|
|
|
|
You can Freely distribute this program under the GNU General Public
|
|
|
|
License. See the file "COPYING" for the exact licensing terms.
|
2002-06-29 06:31:33 +00:00
|
|
|
******************************************************************/
|
|
|
|
|
2004-06-21 16:25:24 +00:00
|
|
|
#include "placement.h"
|
|
|
|
|
2004-05-31 14:14:10 +00:00
|
|
|
#include <qrect.h>
|
2004-06-21 16:25:24 +00:00
|
|
|
#include <assert.h>
|
2004-05-31 14:14:10 +00:00
|
|
|
|
2004-06-21 16:25:24 +00:00
|
|
|
#ifndef KCMRULES
|
2002-06-29 06:31:33 +00:00
|
|
|
#include "workspace.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "options.h"
|
2004-05-31 14:14:10 +00:00
|
|
|
#include "rules.h"
|
2004-06-21 16:25:24 +00:00
|
|
|
#endif
|
2002-06-29 06:31:33 +00:00
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
namespace KWinInternal
|
2002-06-29 06:31:33 +00:00
|
|
|
{
|
|
|
|
|
2004-06-21 16:25:24 +00:00
|
|
|
#ifndef KCMRULES
|
|
|
|
|
2002-06-29 06:31:33 +00:00
|
|
|
Placement::Placement(Workspace* w)
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
m_WorkspacePtr = w;
|
2002-06-29 06:31:33 +00:00
|
|
|
|
|
|
|
//CT initialize the cascading info
|
2003-09-16 19:28:03 +00:00
|
|
|
for( int i = 0; i < m_WorkspacePtr->numberOfDesktops(); i++)
|
|
|
|
{
|
|
|
|
DesktopCascadingInfo inf;
|
|
|
|
inf.pos = QPoint(0,0);
|
|
|
|
inf.col = 0;
|
|
|
|
inf.row = 0;
|
|
|
|
cci.append(inf);
|
|
|
|
}
|
2002-06-29 06:31:33 +00:00
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2002-06-29 06:31:33 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Places the client \a c according to the workspace's layout policy
|
|
|
|
*/
|
2004-01-10 15:13:23 +00:00
|
|
|
void Placement::place(Client* c, QRect& area )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2004-05-31 14:14:10 +00:00
|
|
|
Policy policy = c->rules()->checkPlacement( Default );
|
|
|
|
if( policy != Default )
|
|
|
|
return place( c, policy, area );
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
if( c->isUtility())
|
2004-01-10 15:13:23 +00:00
|
|
|
placeUtility(c, area);
|
2003-09-16 19:28:03 +00:00
|
|
|
else if( c->isDialog())
|
2004-01-10 15:13:23 +00:00
|
|
|
placeDialog(c, area);
|
2003-09-16 19:28:03 +00:00
|
|
|
else if( c->isSplash())
|
2004-01-10 15:13:23 +00:00
|
|
|
placeOnMainWindow( c, area ); // on mainwindow, if any, otherwise centered
|
2003-09-16 19:28:03 +00:00
|
|
|
else
|
2004-05-31 14:14:10 +00:00
|
|
|
place(c, options->placement, area);
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
2004-05-31 14:14:10 +00:00
|
|
|
void Placement::place(Client* c, Policy policy, QRect& area )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2004-05-31 14:14:10 +00:00
|
|
|
if( policy == Default )
|
|
|
|
policy = options->placement;
|
|
|
|
if( policy == NoPlacement )
|
|
|
|
return;
|
|
|
|
else if (policy == Random)
|
|
|
|
placeAtRandom(c, area);
|
|
|
|
else if (policy == Cascade)
|
|
|
|
placeCascaded(c, area);
|
|
|
|
else if (policy == Centered)
|
|
|
|
placeCentered(c, area);
|
|
|
|
else if (policy == ZeroCornered)
|
|
|
|
placeZeroCornered(c, area);
|
|
|
|
else if (policy == UnderMouse)
|
|
|
|
placeUnderMouse(c, area);
|
|
|
|
else if (policy == OnMainWindow)
|
|
|
|
placeOnMainWindow(c, area);
|
|
|
|
else
|
|
|
|
placeSmart(c, area);
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2002-06-29 06:31:33 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Place the client \a c according to a simply "random" placement algorithm.
|
|
|
|
*/
|
2004-01-10 15:13:23 +00:00
|
|
|
void Placement::placeAtRandom(Client* c, const QRect& area )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2002-06-29 06:31:33 +00:00
|
|
|
const int step = 24;
|
|
|
|
static int px = step;
|
|
|
|
static int py = 2 * step;
|
|
|
|
int tx,ty;
|
|
|
|
|
2004-01-10 15:13:23 +00:00
|
|
|
const QRect maxRect = checkArea( c, area );
|
2002-06-29 06:31:33 +00:00
|
|
|
|
|
|
|
if (px < maxRect.x())
|
|
|
|
px = maxRect.x();
|
|
|
|
if (py < maxRect.y())
|
|
|
|
py = maxRect.y();
|
|
|
|
|
|
|
|
px += step;
|
|
|
|
py += 2*step;
|
|
|
|
|
|
|
|
if (px > maxRect.width()/2)
|
|
|
|
px = maxRect.x() + step;
|
|
|
|
if (py > maxRect.height()/2)
|
|
|
|
py = maxRect.y() + step;
|
|
|
|
tx = px;
|
|
|
|
ty = py;
|
2003-09-16 19:28:03 +00:00
|
|
|
if (tx + c->width() > maxRect.right())
|
|
|
|
{
|
2002-06-29 06:31:33 +00:00
|
|
|
tx = maxRect.right() - c->width();
|
|
|
|
if (tx < 0)
|
|
|
|
tx = 0;
|
|
|
|
px = maxRect.x();
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
if (ty + c->height() > maxRect.bottom())
|
|
|
|
{
|
2002-06-29 06:31:33 +00:00
|
|
|
ty = maxRect.bottom() - c->height();
|
|
|
|
if (ty < 0)
|
|
|
|
ty = 0;
|
|
|
|
py = maxRect.y();
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2002-06-29 06:31:33 +00:00
|
|
|
c->move(tx, ty);
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2002-06-29 06:31:33 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Place the client \a c according to a really smart placement algorithm :-)
|
|
|
|
*/
|
2004-01-10 15:13:23 +00:00
|
|
|
void Placement::placeSmart(Client* c, const QRect& area )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2002-06-29 06:31:33 +00:00
|
|
|
/*
|
|
|
|
* SmartPlacement by Cristian Tibirna (tibirna@kde.org)
|
|
|
|
* adapted for kwm (16-19jan98) and for kwin (16Nov1999) using (with
|
|
|
|
* permission) ideas from fvwm, authored by
|
|
|
|
* Anthony Martin (amartin@engr.csulb.edu).
|
|
|
|
* Xinerama supported added by Balaji Ramani (balaji@yablibli.com)
|
|
|
|
* with ideas from xfce.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const int none = 0, h_wrong = -1, w_wrong = -2; // overlap types
|
|
|
|
long int overlap, min_overlap = 0;
|
|
|
|
int x_optimal, y_optimal;
|
|
|
|
int possible;
|
2003-09-16 19:28:03 +00:00
|
|
|
int desktop = c->desktop() == 0 || c->isOnAllDesktops() ? m_WorkspacePtr->currentDesktop() : c->desktop();
|
2002-06-29 06:31:33 +00:00
|
|
|
|
|
|
|
int cxl, cxr, cyt, cyb; //temp coords
|
|
|
|
int xl, xr, yt, yb; //temp coords
|
|
|
|
int basket; //temp holder
|
|
|
|
|
|
|
|
// get the maximum allowed windows space
|
2004-01-10 15:13:23 +00:00
|
|
|
const QRect maxRect = checkArea( c, area );
|
2002-06-29 06:31:33 +00:00
|
|
|
int x = maxRect.left(), y = maxRect.top();
|
|
|
|
x_optimal = x; y_optimal = y;
|
|
|
|
|
|
|
|
//client gabarit
|
|
|
|
int ch = c->height() - 1;
|
|
|
|
int cw = c->width() - 1;
|
|
|
|
|
|
|
|
bool first_pass = true; //CT lame flag. Don't like it. What else would do?
|
|
|
|
|
|
|
|
//loop over possible positions
|
2003-09-16 19:28:03 +00:00
|
|
|
do
|
|
|
|
{
|
2002-06-29 06:31:33 +00:00
|
|
|
//test if enough room in x and y directions
|
|
|
|
if (y + ch > maxRect.bottom() && ch < maxRect.height())
|
|
|
|
overlap = h_wrong; // this throws the algorithm to an exit
|
|
|
|
else if(x + cw > maxRect.right())
|
|
|
|
overlap = w_wrong;
|
2003-09-16 19:28:03 +00:00
|
|
|
else
|
|
|
|
{
|
2002-06-29 06:31:33 +00:00
|
|
|
overlap = none; //initialize
|
|
|
|
|
|
|
|
cxl = x; cxr = x + cw;
|
|
|
|
cyt = y; cyb = y + ch;
|
|
|
|
ClientList::ConstIterator l;
|
2003-09-16 19:28:03 +00:00
|
|
|
for(l = m_WorkspacePtr->stackingOrder().begin(); l != m_WorkspacePtr->stackingOrder().end() ; ++l)
|
|
|
|
{
|
2002-06-29 06:31:33 +00:00
|
|
|
if((*l)->isOnDesktop(desktop) &&
|
2003-10-10 13:00:01 +00:00
|
|
|
(*l)->isShown( false ) && (*l) != c)
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2002-06-29 06:31:33 +00:00
|
|
|
|
|
|
|
xl = (*l)->x(); yt = (*l)->y();
|
|
|
|
xr = xl + (*l)->width(); yb = yt + (*l)->height();
|
|
|
|
|
|
|
|
//if windows overlap, calc the overall overlapping
|
|
|
|
if((cxl < xr) && (cxr > xl) &&
|
2003-09-16 19:28:03 +00:00
|
|
|
(cyt < yb) && (cyb > yt))
|
|
|
|
{
|
2002-06-29 06:31:33 +00:00
|
|
|
xl = QMAX(cxl, xl); xr = QMIN(cxr, xr);
|
|
|
|
yt = QMAX(cyt, yt); yb = QMIN(cyb, yb);
|
2003-09-16 19:28:03 +00:00
|
|
|
if((*l)->keepAbove())
|
2002-06-29 06:31:33 +00:00
|
|
|
overlap += 16 * (xr - xl) * (yb - yt);
|
2004-02-10 13:09:49 +00:00
|
|
|
else if((*l)->keepBelow() && !(*l)->isDock()) // ignore KeepBelow windows
|
|
|
|
overlap += 0; // for placement (see Client::belongsToLayer() for Dock)
|
2002-06-29 06:31:33 +00:00
|
|
|
else
|
|
|
|
overlap += (xr - xl) * (yb - yt);
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2002-06-29 06:31:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//CT first time we get no overlap we stop.
|
2003-09-16 19:28:03 +00:00
|
|
|
if (overlap == none)
|
|
|
|
{
|
2002-06-29 06:31:33 +00:00
|
|
|
x_optimal = x;
|
|
|
|
y_optimal = y;
|
|
|
|
break;
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2002-06-29 06:31:33 +00:00
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
if (first_pass)
|
|
|
|
{
|
2002-06-29 06:31:33 +00:00
|
|
|
first_pass = false;
|
|
|
|
min_overlap = overlap;
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2002-06-29 06:31:33 +00:00
|
|
|
//CT save the best position and the minimum overlap up to now
|
2003-09-16 19:28:03 +00:00
|
|
|
else if (overlap >= none && overlap < min_overlap)
|
|
|
|
{
|
2002-06-29 06:31:33 +00:00
|
|
|
min_overlap = overlap;
|
|
|
|
x_optimal = x;
|
|
|
|
y_optimal = y;
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2002-06-29 06:31:33 +00:00
|
|
|
|
|
|
|
// really need to loop? test if there's any overlap
|
2003-09-16 19:28:03 +00:00
|
|
|
if (overlap > none)
|
|
|
|
{
|
2002-06-29 06:31:33 +00:00
|
|
|
|
|
|
|
possible = maxRect.right();
|
|
|
|
if (possible - cw > x) possible -= cw;
|
|
|
|
|
|
|
|
// compare to the position of each client on the same desk
|
|
|
|
ClientList::ConstIterator l;
|
2003-09-16 19:28:03 +00:00
|
|
|
for(l = m_WorkspacePtr->stackingOrder().begin(); l != m_WorkspacePtr->stackingOrder().end() ; ++l)
|
|
|
|
{
|
2002-06-29 06:31:33 +00:00
|
|
|
|
|
|
|
if ((*l)->isOnDesktop(desktop) &&
|
2003-10-10 13:00:01 +00:00
|
|
|
(*l)->isShown( false ) && (*l) != c)
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2002-06-29 06:31:33 +00:00
|
|
|
|
|
|
|
xl = (*l)->x(); yt = (*l)->y();
|
|
|
|
xr = xl + (*l)->width(); yb = yt + (*l)->height();
|
|
|
|
|
|
|
|
// if not enough room above or under the current tested client
|
|
|
|
// determine the first non-overlapped x position
|
2003-09-16 19:28:03 +00:00
|
|
|
if((y < yb) && (yt < ch + y))
|
|
|
|
{
|
2002-06-29 06:31:33 +00:00
|
|
|
|
|
|
|
if((xr > x) && (possible > xr)) possible = xr;
|
|
|
|
|
|
|
|
basket = xl - cw;
|
|
|
|
if((basket > x) && (possible > basket)) possible = basket;
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2002-06-29 06:31:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
x = possible;
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2002-06-29 06:31:33 +00:00
|
|
|
|
|
|
|
// ... else ==> not enough x dimension (overlap was wrong on horizontal)
|
2003-09-16 19:28:03 +00:00
|
|
|
else if (overlap == w_wrong)
|
|
|
|
{
|
2002-06-29 06:31:33 +00:00
|
|
|
x = maxRect.left();
|
|
|
|
possible = maxRect.bottom();
|
|
|
|
|
|
|
|
if (possible - ch > y) possible -= ch;
|
|
|
|
|
|
|
|
//test the position of each window on the desk
|
|
|
|
ClientList::ConstIterator l;
|
2003-09-16 19:28:03 +00:00
|
|
|
for(l = m_WorkspacePtr->stackingOrder().begin(); l != m_WorkspacePtr->stackingOrder().end() ; ++l)
|
|
|
|
{
|
2002-06-29 06:31:33 +00:00
|
|
|
if((*l)->isOnDesktop(desktop) &&
|
2003-10-10 13:00:01 +00:00
|
|
|
(*l) != c && c->isShown( false ))
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2002-06-29 06:31:33 +00:00
|
|
|
|
|
|
|
xl = (*l)->x(); yt = (*l)->y();
|
|
|
|
xr = xl + (*l)->width(); yb = yt + (*l)->height();
|
|
|
|
|
|
|
|
// if not enough room to the left or right of the current tested client
|
|
|
|
// determine the first non-overlapped y position
|
|
|
|
if((yb > y) && (possible > yb)) possible = yb;
|
|
|
|
|
|
|
|
basket = yt - ch;
|
|
|
|
if((basket > y) && (possible > basket)) possible = basket;
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2002-06-29 06:31:33 +00:00
|
|
|
}
|
|
|
|
y = possible;
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2002-06-29 06:31:33 +00:00
|
|
|
}
|
|
|
|
while((overlap != none) && (overlap != h_wrong) && (y < maxRect.bottom()));
|
|
|
|
|
|
|
|
if(ch>= maxRect.height())
|
|
|
|
y_optimal=maxRect.top();
|
|
|
|
|
|
|
|
// place the window
|
|
|
|
c->move(x_optimal, y_optimal);
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2002-06-29 06:31:33 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Place windows in a cascading order, remembering positions for each desktop
|
|
|
|
*/
|
2004-01-10 15:13:23 +00:00
|
|
|
void Placement::placeCascaded (Client* c, const QRect& area, bool re_init)
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2002-06-29 06:31:33 +00:00
|
|
|
/* cascadePlacement by Cristian Tibirna (tibirna@kde.org) (30Jan98)
|
|
|
|
*/
|
|
|
|
// work coords
|
|
|
|
int xp, yp;
|
|
|
|
|
|
|
|
//CT how do I get from the 'Client' class the size that NW squarish "handle"
|
|
|
|
const int delta_x = 24;
|
|
|
|
const int delta_y = 24;
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
const int dn = c->desktop() == 0 || c->isOnAllDesktops() ? (m_WorkspacePtr->currentDesktop() - 1) : (c->desktop() - 1);
|
2002-06-29 06:31:33 +00:00
|
|
|
|
|
|
|
// get the maximum allowed windows space and desk's origin
|
2004-01-10 15:13:23 +00:00
|
|
|
QRect maxRect = checkArea( c, area );
|
2002-06-29 06:31:33 +00:00
|
|
|
|
|
|
|
// initialize often used vars: width and height of c; we gain speed
|
|
|
|
const int ch = c->height();
|
|
|
|
const int cw = c->width();
|
|
|
|
const int X = maxRect.left();
|
|
|
|
const int Y = maxRect.top();
|
|
|
|
const int H = maxRect.height();
|
|
|
|
const int W = maxRect.width();
|
|
|
|
|
|
|
|
//initialize if needed
|
2003-09-16 19:28:03 +00:00
|
|
|
if (re_init || cci[dn].pos.x() < X || cci[dn].pos.y() < Y )
|
|
|
|
{
|
|
|
|
cci[dn].pos = QPoint(X, Y);
|
|
|
|
cci[dn].col = cci[dn].row = 0;
|
|
|
|
}
|
2002-06-29 06:31:33 +00:00
|
|
|
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
xp = cci[dn].pos.x();
|
|
|
|
yp = cci[dn].pos.y();
|
2002-06-29 06:31:33 +00:00
|
|
|
|
|
|
|
//here to touch in case people vote for resize on placement
|
|
|
|
if ((yp + ch) > H) yp = Y;
|
|
|
|
|
|
|
|
if ((xp + cw) > W)
|
2003-09-16 19:28:03 +00:00
|
|
|
if (!yp)
|
|
|
|
{
|
2004-01-10 15:13:23 +00:00
|
|
|
placeSmart(c,area);
|
2003-09-16 19:28:03 +00:00
|
|
|
return;
|
2002-06-29 06:31:33 +00:00
|
|
|
}
|
2003-09-16 19:28:03 +00:00
|
|
|
else xp = X;
|
2002-06-29 06:31:33 +00:00
|
|
|
|
|
|
|
//if this isn't the first window
|
2003-09-16 19:28:03 +00:00
|
|
|
if (cci[dn].pos.x() != X && cci[dn].pos.y() != Y)
|
2002-06-29 06:31:33 +00:00
|
|
|
{
|
2003-09-16 19:28:03 +00:00
|
|
|
/* The following statements cause an internal compiler error with
|
|
|
|
* egcs-2.91.66 on SuSE Linux 6.3. The equivalent forms compile fine.
|
|
|
|
* 22-Dec-1999 CS
|
|
|
|
*
|
|
|
|
* if (xp != X && yp == Y) xp = delta_x * (++(cci[dn].col));
|
|
|
|
* if (yp != Y && xp == X) yp = delta_y * (++(cci[dn].row));
|
|
|
|
*/
|
|
|
|
if (xp != X && yp == Y)
|
|
|
|
{
|
|
|
|
++(cci[dn].col);
|
|
|
|
xp = delta_x * cci[dn].col;
|
|
|
|
}
|
2002-06-29 06:31:33 +00:00
|
|
|
if (yp != Y && xp == X)
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
++(cci[dn].row);
|
|
|
|
yp = delta_y * cci[dn].row;
|
|
|
|
}
|
2002-06-29 06:31:33 +00:00
|
|
|
|
|
|
|
// last resort: if still doesn't fit, smart place it
|
2003-09-16 19:28:03 +00:00
|
|
|
if (((xp + cw) > W - X) || ((yp + ch) > H - Y))
|
|
|
|
{
|
2004-01-10 15:13:23 +00:00
|
|
|
placeSmart(c,area);
|
2002-06-29 06:31:33 +00:00
|
|
|
return;
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2002-06-29 06:31:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// place the window
|
|
|
|
c->move(QPoint(xp, yp));
|
|
|
|
|
|
|
|
// new position
|
2003-09-16 19:28:03 +00:00
|
|
|
cci[dn].pos = QPoint(xp + delta_x, yp + delta_y);
|
|
|
|
}
|
2002-06-29 06:31:33 +00:00
|
|
|
|
|
|
|
/*!
|
2002-07-15 20:28:55 +00:00
|
|
|
Place windows centered, on top of all others
|
2002-06-29 06:31:33 +00:00
|
|
|
*/
|
2004-01-10 15:13:23 +00:00
|
|
|
void Placement::placeCentered (Client* c, const QRect& area )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2002-06-29 06:31:33 +00:00
|
|
|
|
|
|
|
// get the maximum allowed windows space and desk's origin
|
2004-01-10 15:13:23 +00:00
|
|
|
const QRect maxRect = checkArea( c, area );
|
2002-06-29 06:31:33 +00:00
|
|
|
|
|
|
|
const int xp = maxRect.left() + (maxRect.width() - c->width()) / 2;
|
|
|
|
const int yp = maxRect.top() + (maxRect.height() - c->height()) / 2;
|
|
|
|
|
|
|
|
// place the window
|
|
|
|
c->move(QPoint(xp, yp));
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2002-06-29 06:31:33 +00:00
|
|
|
|
2002-07-15 20:28:55 +00:00
|
|
|
/*!
|
|
|
|
Place windows in the (0,0) corner, on top of all others
|
|
|
|
*/
|
2004-01-10 15:13:23 +00:00
|
|
|
void Placement::placeZeroCornered(Client* c, const QRect& area )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2002-06-29 06:31:33 +00:00
|
|
|
// get the maximum allowed windows space and desk's origin
|
2004-01-10 15:13:23 +00:00
|
|
|
const QRect maxRect = checkArea( c, area );
|
2002-06-29 06:31:33 +00:00
|
|
|
|
|
|
|
// place the window
|
|
|
|
c->move(QPoint(maxRect.left(), maxRect.top()));
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
2004-01-10 15:13:23 +00:00
|
|
|
void Placement::placeUtility(Client* c, QRect& area )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
// TODO kwin should try to place utility windows next to their mainwindow,
|
|
|
|
// preferably at the right edge, and going down if there are more of them
|
|
|
|
// if there's not enough place outside the mainwindow, it should prefer
|
|
|
|
// top-right corner
|
|
|
|
// use the default placement for now
|
2004-05-31 14:14:10 +00:00
|
|
|
place( c, Default, area );
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-10 15:13:23 +00:00
|
|
|
void Placement::placeDialog(Client* c, QRect& area )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2004-01-10 15:13:23 +00:00
|
|
|
placeOnMainWindow( c, area );
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
2004-01-10 15:13:23 +00:00
|
|
|
void Placement::placeUnderMouse(Client* c, QRect& area )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2004-01-10 15:13:23 +00:00
|
|
|
area = checkArea( c, area );
|
2003-09-16 19:28:03 +00:00
|
|
|
QRect geom = c->geometry();
|
|
|
|
geom.moveCenter( QCursor::pos());
|
|
|
|
c->move( geom.topLeft());
|
2004-01-10 15:13:23 +00:00
|
|
|
c->keepInArea( area ); // make sure it's kept inside workarea
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
2004-01-10 15:13:23 +00:00
|
|
|
void Placement::placeOnMainWindow(Client* c, QRect& area )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2004-01-10 15:13:23 +00:00
|
|
|
area = checkArea( c, area );
|
2003-09-16 19:28:03 +00:00
|
|
|
ClientList mainwindows = c->mainClients();
|
|
|
|
Client* place_on = NULL;
|
2004-01-15 14:17:41 +00:00
|
|
|
Client* place_on2 = NULL;
|
2004-01-10 15:13:23 +00:00
|
|
|
int mains_count = 0;
|
2003-09-16 19:28:03 +00:00
|
|
|
for( ClientList::ConstIterator it = mainwindows.begin();
|
|
|
|
it != mainwindows.end();
|
|
|
|
++it )
|
|
|
|
{
|
|
|
|
if( (*it)->isSpecialWindow() && !(*it)->isOverride())
|
|
|
|
continue; // don't consider toolbars etc when placing
|
2004-01-10 15:13:23 +00:00
|
|
|
++mains_count;
|
2004-01-15 14:17:41 +00:00
|
|
|
place_on2 = *it;
|
2003-09-16 19:28:03 +00:00
|
|
|
if( (*it)->isOnCurrentDesktop())
|
|
|
|
{
|
|
|
|
if( place_on == NULL )
|
|
|
|
place_on = *it;
|
|
|
|
else
|
|
|
|
{ // two or more on current desktop -> center
|
2004-01-10 15:13:23 +00:00
|
|
|
placeCentered( c, area );
|
2003-09-16 19:28:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( place_on == NULL )
|
2004-01-10 15:13:23 +00:00
|
|
|
{ // 'mains_count' is used because it doesn't include ignored mainwindows
|
|
|
|
if( mains_count != 1 )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2004-01-10 15:13:23 +00:00
|
|
|
placeCentered( c, area );
|
2003-09-16 19:28:03 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-01-15 14:17:41 +00:00
|
|
|
place_on = place_on2; // use the only window filtered together with 'mains_count'
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
QRect geom = c->geometry();
|
|
|
|
geom.moveCenter( place_on->geometry().center());
|
|
|
|
c->move( geom.topLeft());
|
2004-01-10 15:13:23 +00:00
|
|
|
// get area again, because the mainwindow may be on different xinerama screen
|
|
|
|
area = checkArea( c, QRect());
|
2004-01-15 14:17:41 +00:00
|
|
|
c->keepInArea( area ); // make sure it's kept inside workarea
|
2004-01-10 15:13:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QRect Placement::checkArea( const Client* c, const QRect& area )
|
|
|
|
{
|
|
|
|
if( area.isNull())
|
|
|
|
return m_WorkspacePtr->clientArea( PlacementArea, c->geometry().center(), c->desktop());
|
|
|
|
return area;
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
2004-06-21 16:25:24 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2004-05-31 14:14:10 +00:00
|
|
|
Placement::Policy Placement::policyFromString( const QString& policy, bool no_special )
|
|
|
|
{
|
|
|
|
if( policy == "NoPlacement" )
|
|
|
|
return NoPlacement;
|
|
|
|
else if( policy == "Default" && !no_special )
|
|
|
|
return Default;
|
|
|
|
else if( policy == "Random" )
|
|
|
|
return Random;
|
|
|
|
else if( policy == "Cascade" )
|
|
|
|
return Cascade;
|
|
|
|
else if( policy == "Centered" )
|
|
|
|
return Centered;
|
|
|
|
else if( policy == "ZeroCornered" )
|
|
|
|
return ZeroCornered;
|
|
|
|
else if( policy == "UnderMouse" && !no_special)
|
|
|
|
return UnderMouse;
|
|
|
|
else if( policy == "OnMainWindow" && !no_special)
|
|
|
|
return OnMainWindow;
|
|
|
|
else
|
|
|
|
return Smart;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* Placement::policyToString( Policy policy )
|
|
|
|
{
|
|
|
|
const char* const policies[] =
|
|
|
|
{ "NoPlacement", "Default", "Random", "Smart", "Cascade", "Centered",
|
|
|
|
"ZeroCornered", "UnderMouse", "OnMainWindow" };
|
|
|
|
assert( policy < int( sizeof( policies ) / sizeof( policies[ 0 ] )));
|
|
|
|
return policies[ policy ];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-21 16:25:24 +00:00
|
|
|
#ifndef KCMRULES
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
// ********************
|
|
|
|
// Workspace
|
|
|
|
// ********************
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Moves active window left until in bumps into another window or workarea edge.
|
|
|
|
*/
|
|
|
|
void Workspace::slotWindowPackLeft()
|
|
|
|
{
|
2004-04-29 14:52:33 +00:00
|
|
|
if( active_client && active_client->isMovable())
|
2003-09-16 19:28:03 +00:00
|
|
|
active_client->move( packPositionLeft( active_client, active_client->geometry().left(), true ),
|
|
|
|
active_client->y());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::slotWindowPackRight()
|
|
|
|
{
|
2004-04-29 14:52:33 +00:00
|
|
|
if( active_client && active_client->isMovable())
|
2003-09-16 19:28:03 +00:00
|
|
|
active_client->move(
|
|
|
|
packPositionRight( active_client, active_client->geometry().right(), true )
|
|
|
|
- active_client->width() + 1, active_client->y());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::slotWindowPackUp()
|
|
|
|
{
|
2004-04-29 14:52:33 +00:00
|
|
|
if( active_client && active_client->isMovable())
|
2003-09-16 19:28:03 +00:00
|
|
|
active_client->move( active_client->x(),
|
|
|
|
packPositionUp( active_client, active_client->geometry().top(), true ));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::slotWindowPackDown()
|
|
|
|
{
|
2004-04-29 14:52:33 +00:00
|
|
|
if( active_client && active_client->isMovable())
|
2003-09-16 19:28:03 +00:00
|
|
|
active_client->move( active_client->x(),
|
|
|
|
packPositionDown( active_client, active_client->geometry().bottom(), true ) - active_client->height() + 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::slotWindowGrowHorizontal()
|
|
|
|
{
|
|
|
|
if( active_client )
|
|
|
|
active_client->growHorizontal();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::growHorizontal()
|
|
|
|
{
|
2004-04-29 14:52:33 +00:00
|
|
|
if( !isResizable())
|
|
|
|
return;
|
2003-09-16 19:28:03 +00:00
|
|
|
QRect geom = geometry();
|
|
|
|
geom.setRight( workspace()->packPositionRight( this, geom.right(), true ));
|
2003-11-24 14:26:11 +00:00
|
|
|
QSize adjsize = adjustedSize( geom.size(), SizemodeFixedW );
|
2003-09-16 19:28:03 +00:00
|
|
|
if( geometry().size() == adjsize && geom.size() != adjsize && xSizeHint.width_inc > 1 ) // take care of size increments
|
|
|
|
{
|
|
|
|
int newright = workspace()->packPositionRight( this, geom.right() + xSizeHint.width_inc - 1, true );
|
2003-10-10 12:58:38 +00:00
|
|
|
// check that it hasn't grown outside of the area, due to size increments
|
2003-10-10 13:09:54 +00:00
|
|
|
// TODO this may be wrong?
|
2003-10-10 12:58:38 +00:00
|
|
|
if( workspace()->clientArea( MovementArea,
|
|
|
|
QPoint(( x() + newright ) / 2, geometry().center().y()), desktop()).right() >= newright )
|
2003-09-16 19:28:03 +00:00
|
|
|
geom.setRight( newright );
|
|
|
|
}
|
2003-11-24 14:26:11 +00:00
|
|
|
geom.setSize( adjustedSize( geom.size(), SizemodeFixedW ));
|
2003-09-16 19:28:03 +00:00
|
|
|
setGeometry( geom );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::slotWindowShrinkHorizontal()
|
|
|
|
{
|
|
|
|
if( active_client )
|
|
|
|
active_client->shrinkHorizontal();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::shrinkHorizontal()
|
|
|
|
{
|
2004-04-29 14:52:33 +00:00
|
|
|
if( !isResizable())
|
|
|
|
return;
|
2003-09-16 19:28:03 +00:00
|
|
|
QRect geom = geometry();
|
|
|
|
geom.setRight( workspace()->packPositionLeft( this, geom.right(), false ));
|
|
|
|
if( geom.width() <= 1 )
|
|
|
|
return;
|
2003-11-24 14:26:11 +00:00
|
|
|
geom.setSize( adjustedSize( geom.size(), SizemodeFixedW ));
|
2003-09-16 19:28:03 +00:00
|
|
|
if( geom.width() > 20 )
|
|
|
|
setGeometry( geom );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::slotWindowGrowVertical()
|
|
|
|
{
|
|
|
|
if( active_client )
|
|
|
|
active_client->growVertical();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::growVertical()
|
|
|
|
{
|
2004-04-29 14:52:33 +00:00
|
|
|
if( !isResizable())
|
|
|
|
return;
|
2003-09-16 19:28:03 +00:00
|
|
|
QRect geom = geometry();
|
|
|
|
geom.setBottom( workspace()->packPositionDown( this, geom.bottom(), true ));
|
2003-11-24 14:26:11 +00:00
|
|
|
QSize adjsize = adjustedSize( geom.size(), SizemodeFixedH );
|
2003-09-16 19:28:03 +00:00
|
|
|
if( geometry().size() == adjsize && geom.size() != adjsize && xSizeHint.height_inc > 1 ) // take care of size increments
|
|
|
|
{
|
|
|
|
int newbottom = workspace()->packPositionDown( this, geom.bottom() + xSizeHint.height_inc - 1, true );
|
2003-10-10 12:58:38 +00:00
|
|
|
// check that it hasn't grown outside of the area, due to size increments
|
|
|
|
if( workspace()->clientArea( MovementArea,
|
|
|
|
QPoint( geometry().center().x(), ( y() + newbottom ) / 2 ), desktop()).bottom() >= newbottom )
|
2003-09-16 19:28:03 +00:00
|
|
|
geom.setBottom( newbottom );
|
|
|
|
}
|
2003-11-24 14:26:11 +00:00
|
|
|
geom.setSize( adjustedSize( geom.size(), SizemodeFixedH ));
|
2003-09-16 19:28:03 +00:00
|
|
|
setGeometry( geom );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Workspace::slotWindowShrinkVertical()
|
|
|
|
{
|
|
|
|
if( active_client )
|
|
|
|
active_client->shrinkVertical();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::shrinkVertical()
|
|
|
|
{
|
2004-04-29 14:52:33 +00:00
|
|
|
if( !isResizable())
|
|
|
|
return;
|
2003-09-16 19:28:03 +00:00
|
|
|
QRect geom = geometry();
|
|
|
|
geom.setBottom( workspace()->packPositionUp( this, geom.bottom(), false ));
|
|
|
|
if( geom.height() <= 1 )
|
|
|
|
return;
|
2003-11-24 14:26:11 +00:00
|
|
|
geom.setSize( adjustedSize( geom.size(), SizemodeFixedH ));
|
2003-09-16 19:28:03 +00:00
|
|
|
if( geom.height() > 20 )
|
|
|
|
setGeometry( geom );
|
|
|
|
}
|
|
|
|
|
|
|
|
int Workspace::packPositionLeft( const Client* cl, int oldx, bool left_edge ) const
|
|
|
|
{
|
2003-10-10 12:58:38 +00:00
|
|
|
int newx = clientArea( MovementArea, cl ).left();
|
|
|
|
if( oldx <= newx ) // try another Xinerama screen
|
|
|
|
newx = clientArea( MovementArea,
|
|
|
|
QPoint( cl->geometry().left() - 1, cl->geometry().center().y()), cl->desktop()).left();
|
|
|
|
if( oldx <= newx )
|
2003-09-16 19:28:03 +00:00
|
|
|
return oldx;
|
|
|
|
for( ClientList::ConstIterator it = clients.begin();
|
|
|
|
it != clients.end();
|
|
|
|
++it)
|
|
|
|
{
|
2003-10-10 13:00:01 +00:00
|
|
|
if( !(*it)->isShown( false ) || !(*it)->isOnDesktop( active_client->desktop()))
|
2003-09-16 19:28:03 +00:00
|
|
|
continue;
|
|
|
|
int x = left_edge ? (*it)->geometry().right() + 1 : (*it)->geometry().left() - 1;
|
|
|
|
if( x > newx && x < oldx
|
|
|
|
&& !( cl->geometry().top() > (*it)->geometry().bottom() // they overlap in Y direction
|
|
|
|
|| cl->geometry().bottom() < (*it)->geometry().top()))
|
|
|
|
newx = x;
|
|
|
|
}
|
|
|
|
return newx;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Workspace::packPositionRight( const Client* cl, int oldx, bool right_edge ) const
|
|
|
|
{
|
2003-10-10 12:58:38 +00:00
|
|
|
int newx = clientArea( MovementArea, cl ).right();
|
|
|
|
if( oldx >= newx ) // try another Xinerama screen
|
|
|
|
newx = clientArea( MovementArea,
|
|
|
|
QPoint( cl->geometry().right() + 1, cl->geometry().center().y()), cl->desktop()).right();
|
|
|
|
if( oldx >= newx )
|
2003-09-16 19:28:03 +00:00
|
|
|
return oldx;
|
|
|
|
for( ClientList::ConstIterator it = clients.begin();
|
|
|
|
it != clients.end();
|
|
|
|
++it)
|
|
|
|
{
|
2003-10-10 13:00:01 +00:00
|
|
|
if( !(*it)->isShown( false ) || !(*it)->isOnDesktop( cl->desktop()))
|
2003-09-16 19:28:03 +00:00
|
|
|
continue;
|
|
|
|
int x = right_edge ? (*it)->geometry().left() - 1 : (*it)->geometry().right() + 1;
|
|
|
|
if( x < newx && x > oldx
|
|
|
|
&& !( cl->geometry().top() > (*it)->geometry().bottom()
|
|
|
|
|| cl->geometry().bottom() < (*it)->geometry().top()))
|
|
|
|
newx = x;
|
|
|
|
}
|
|
|
|
return newx;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Workspace::packPositionUp( const Client* cl, int oldy, bool top_edge ) const
|
|
|
|
{
|
2003-10-10 12:58:38 +00:00
|
|
|
int newy = clientArea( MovementArea, cl ).top();
|
|
|
|
if( oldy <= newy ) // try another Xinerama screen
|
|
|
|
newy = clientArea( MovementArea,
|
|
|
|
QPoint( cl->geometry().center().x(), cl->geometry().top() - 1 ), cl->desktop()).top();
|
|
|
|
if( oldy <= newy )
|
2003-09-16 19:28:03 +00:00
|
|
|
return oldy;
|
|
|
|
for( ClientList::ConstIterator it = clients.begin();
|
|
|
|
it != clients.end();
|
|
|
|
++it)
|
|
|
|
{
|
2003-10-10 13:00:01 +00:00
|
|
|
if( !(*it)->isShown( false ) || !(*it)->isOnDesktop( cl->desktop()))
|
2003-09-16 19:28:03 +00:00
|
|
|
continue;
|
|
|
|
int y = top_edge ? (*it)->geometry().bottom() + 1 : (*it)->geometry().top() - 1;
|
|
|
|
if( y > newy && y < oldy
|
|
|
|
&& !( cl->geometry().left() > (*it)->geometry().right() // they overlap in X direction
|
|
|
|
|| cl->geometry().right() < (*it)->geometry().left()))
|
|
|
|
newy = y;
|
|
|
|
}
|
|
|
|
return newy;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Workspace::packPositionDown( const Client* cl, int oldy, bool bottom_edge ) const
|
|
|
|
{
|
2003-10-10 12:58:38 +00:00
|
|
|
int newy = clientArea( MovementArea, cl ).bottom();
|
|
|
|
if( oldy >= newy ) // try another Xinerama screen
|
|
|
|
newy = clientArea( MovementArea,
|
|
|
|
QPoint( cl->geometry().center().x(), cl->geometry().bottom() + 1 ), cl->desktop()).bottom();
|
|
|
|
if( oldy >= newy )
|
2003-09-16 19:28:03 +00:00
|
|
|
return oldy;
|
|
|
|
for( ClientList::ConstIterator it = clients.begin();
|
|
|
|
it != clients.end();
|
|
|
|
++it)
|
|
|
|
{
|
2003-10-10 13:00:01 +00:00
|
|
|
if( !(*it)->isShown( false ) || !(*it)->isOnDesktop( cl->desktop()))
|
2003-09-16 19:28:03 +00:00
|
|
|
continue;
|
|
|
|
int y = bottom_edge ? (*it)->geometry().top() - 1 : (*it)->geometry().bottom() + 1;
|
|
|
|
if( y < newy && y > oldy
|
|
|
|
&& !( cl->geometry().left() > (*it)->geometry().right()
|
|
|
|
|| cl->geometry().right() < (*it)->geometry().left()))
|
|
|
|
newy = y;
|
|
|
|
}
|
|
|
|
return newy;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Asks the internal positioning object to place a client
|
|
|
|
*/
|
2004-01-10 15:13:23 +00:00
|
|
|
void Workspace::place(Client* c, QRect& area)
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2004-01-10 15:13:23 +00:00
|
|
|
initPositioning->place( c, area );
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
2004-01-10 15:13:23 +00:00
|
|
|
void Workspace::placeSmart(Client* c, const QRect& area)
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2004-01-10 15:13:23 +00:00
|
|
|
initPositioning->placeSmart( c, area );
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
2004-06-21 16:25:24 +00:00
|
|
|
#endif
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
} // namespace
|