kwin/placement.cpp

807 lines
26 KiB
C++
Raw Normal View History

/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
Copyright (C) 1997 to 2002 Cristian Tibirna <tibirna@kde.org>
Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
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/>.
*********************************************************************/
#include "placement.h"
#include <QRect>
#include <assert.h>
#include <QTextStream>
#ifndef KCMRULES
#include "workspace.h"
#include "client.h"
#include "options.h"
#include "rules.h"
#endif
namespace KWin
{
#ifndef KCMRULES
Placement::Placement(Workspace* w)
2011-01-30 14:34:42 +00:00
{
m_WorkspacePtr = w;
2011-01-30 14:34:42 +00:00
reinitCascading(0);
}
/*!
Places the client \a c according to the workspace's layout policy
*/
2011-01-30 14:34:42 +00:00
void Placement::place(Client* c, QRect& area)
{
Policy policy = c->rules()->checkPlacement(Default);
if (policy != Default) {
place(c, area, policy);
return;
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
if (c->isUtility())
placeUtility(c, area, options->placement);
else if (c->isDialog())
placeDialog(c, area, options->placement);
else if (c->isSplash())
placeOnMainWindow(c, area); // on mainwindow, if any, otherwise centered
else
place(c, area, options->placement);
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void Placement::place(Client* c, QRect& area, Policy policy, Policy nextPlacement)
{
if (policy == Unknown)
policy = Default;
2011-01-30 14:34:42 +00:00
if (policy == Default)
policy = options->placement;
2011-01-30 14:34:42 +00:00
if (policy == NoPlacement)
return;
else if (policy == Random)
placeAtRandom(c, area, nextPlacement);
else if (policy == Cascade)
placeCascaded(c, area, nextPlacement);
else if (policy == Centered)
placeCentered(c, area, nextPlacement);
else if (policy == ZeroCornered)
placeZeroCornered(c, area, nextPlacement);
else if (policy == UnderMouse)
placeUnderMouse(c, area, nextPlacement);
else if (policy == OnMainWindow)
placeOnMainWindow(c, area, nextPlacement);
2011-01-30 14:34:42 +00:00
else if (policy == Maximizing)
placeMaximizing(c, area, nextPlacement);
else
placeSmart(c, area, nextPlacement);
2011-01-30 14:34:42 +00:00
}
/*!
Place the client \a c according to a simply "random" placement algorithm.
*/
2011-01-30 14:34:42 +00:00
void Placement::placeAtRandom(Client* c, const QRect& area, Policy /*next*/)
{
const int step = 24;
static int px = step;
static int py = 2 * step;
2011-01-30 14:34:42 +00:00
int tx, ty;
2011-01-30 14:34:42 +00:00
const QRect maxRect = checkArea(c, area);
if (px < maxRect.x())
px = maxRect.x();
if (py < maxRect.y())
py = maxRect.y();
px += step;
2011-01-30 14:34:42 +00:00
py += 2 * step;
2011-01-30 14:34:42 +00:00
if (px > maxRect.width() / 2)
px = maxRect.x() + step;
2011-01-30 14:34:42 +00:00
if (py > maxRect.height() / 2)
py = maxRect.y() + step;
tx = px;
ty = py;
2011-01-30 14:34:42 +00:00
if (tx + c->width() > maxRect.right()) {
tx = maxRect.right() - c->width();
if (tx < 0)
tx = 0;
px = maxRect.x();
2011-01-30 14:34:42 +00:00
}
if (ty + c->height() > maxRect.bottom()) {
ty = maxRect.bottom() - c->height();
if (ty < 0)
ty = 0;
py = maxRect.y();
}
2011-01-30 14:34:42 +00:00
c->move(tx, ty);
}
/*!
Place the client \a c according to a really smart placement algorithm :-)
*/
2011-01-30 14:34:42 +00:00
void Placement::placeSmart(Client* c, const QRect& area, Policy /*next*/)
{
/*
* 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;
int desktop = c->desktop() == 0 || c->isOnAllDesktops() ? m_WorkspacePtr->currentDesktop() : c->desktop();
int cxl, cxr, cyt, cyb; //temp coords
int xl, xr, yt, yb; //temp coords
int basket; //temp holder
// get the maximum allowed windows space
2011-01-30 14:34:42 +00:00
const QRect maxRect = checkArea(c, area);
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
2011-01-30 14:34:42 +00:00
do {
//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
2011-01-30 14:34:42 +00:00
else if (x + cw > maxRect.right())
overlap = w_wrong;
2011-01-30 14:34:42 +00:00
else {
overlap = none; //initialize
cxl = x; cxr = x + cw;
cyt = y; cyb = y + ch;
ClientList::ConstIterator l;
2011-01-30 14:34:42 +00:00
for (l = m_WorkspacePtr->stackingOrder().constBegin(); l != m_WorkspacePtr->stackingOrder().constEnd() ; ++l) {
if ((*l)->isOnDesktop(desktop) &&
(*l)->isShown(false) && (*l) != c) {
xl = (*l)->x(); yt = (*l)->y();
xr = xl + (*l)->width(); yb = yt + (*l)->height();
//if windows overlap, calc the overall overlapping
2011-01-30 14:34:42 +00:00
if ((cxl < xr) && (cxr > xl) &&
(cyt < yb) && (cyb > yt)) {
xl = qMax(cxl, xl); xr = qMin(cxr, xr);
yt = qMax(cyt, yt); yb = qMin(cyb, yb);
2011-01-30 14:34:42 +00:00
if ((*l)->keepAbove())
overlap += 16 * (xr - xl) * (yb - yt);
2011-01-30 14:34:42 +00:00
else if ((*l)->keepBelow() && !(*l)->isDock()) // ignore KeepBelow windows
overlap += 0; // for placement (see Client::belongsToLayer() for Dock)
else
overlap += (xr - xl) * (yb - yt);
}
}
}
2011-01-30 14:34:42 +00:00
}
//CT first time we get no overlap we stop.
2011-01-30 14:34:42 +00:00
if (overlap == none) {
x_optimal = x;
y_optimal = y;
break;
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
if (first_pass) {
first_pass = false;
min_overlap = overlap;
2011-01-30 14:34:42 +00:00
}
//CT save the best position and the minimum overlap up to now
2011-01-30 14:34:42 +00:00
else if (overlap >= none && overlap < min_overlap) {
min_overlap = overlap;
x_optimal = x;
y_optimal = y;
2011-01-30 14:34:42 +00:00
}
// really need to loop? test if there's any overlap
2011-01-30 14:34:42 +00:00
if (overlap > none) {
possible = maxRect.right();
if (possible - cw > x) possible -= cw;
// compare to the position of each client on the same desk
ClientList::ConstIterator l;
2011-01-30 14:34:42 +00:00
for (l = m_WorkspacePtr->stackingOrder().constBegin(); l != m_WorkspacePtr->stackingOrder().constEnd() ; ++l) {
if ((*l)->isOnDesktop(desktop) &&
2011-01-30 14:34:42 +00:00
(*l)->isShown(false) && (*l) != c) {
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
2011-01-30 14:34:42 +00:00
if ((y < yb) && (yt < ch + y)) {
2011-01-30 14:34:42 +00:00
if ((xr > x) && (possible > xr)) possible = xr;
basket = xl - cw;
2011-01-30 14:34:42 +00:00
if ((basket > x) && (possible > basket)) possible = basket;
}
}
}
2011-01-30 14:34:42 +00:00
x = possible;
}
// ... else ==> not enough x dimension (overlap was wrong on horizontal)
2011-01-30 14:34:42 +00:00
else if (overlap == w_wrong) {
x = maxRect.left();
possible = maxRect.bottom();
if (possible - ch > y) possible -= ch;
//test the position of each window on the desk
ClientList::ConstIterator l;
2011-01-30 14:34:42 +00:00
for (l = m_WorkspacePtr->stackingOrder().constBegin(); l != m_WorkspacePtr->stackingOrder().constEnd() ; ++l) {
if ((*l)->isOnDesktop(desktop) &&
(*l) != c && c->isShown(false)) {
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
2011-01-30 14:34:42 +00:00
if ((yb > y) && (possible > yb)) possible = yb;
basket = yt - ch;
2011-01-30 14:34:42 +00:00
if ((basket > y) && (possible > basket)) possible = basket;
}
}
2011-01-30 14:34:42 +00:00
y = possible;
}
2011-01-30 14:34:42 +00:00
} while ((overlap != none) && (overlap != h_wrong) && (y < maxRect.bottom()));
2011-01-30 14:34:42 +00:00
if (ch >= maxRect.height())
y_optimal = maxRect.top();
// place the window
c->move(x_optimal, y_optimal);
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void Placement::reinitCascading(int desktop)
{
// desktop == 0 - reinit all
if (desktop == 0) {
cci.clear();
2011-01-30 14:34:42 +00:00
for (int i = 0; i < m_WorkspacePtr->numberOfDesktops(); i++) {
DesktopCascadingInfo inf;
2011-01-30 14:34:42 +00:00
inf.pos = QPoint(-1, -1);
inf.col = 0;
inf.row = 0;
cci.append(inf);
}
2011-01-30 14:34:42 +00:00
} else {
cci[desktop - 1].pos = QPoint(-1, -1);
cci[desktop - 1].col = cci[desktop - 1].row = 0;
}
2011-01-30 14:34:42 +00:00
}
/*!
Place windows in a cascading order, remembering positions for each desktop
*/
2011-01-30 14:34:42 +00:00
void Placement::placeCascaded(Client* c, QRect& area, Policy nextPlacement)
{
/* 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;
const int dn = c->desktop() == 0 || c->isOnAllDesktops() ? (m_WorkspacePtr->currentDesktop() - 1) : (c->desktop() - 1);
// get the maximum allowed windows space and desk's origin
2011-01-30 14:34:42 +00:00
QRect maxRect = checkArea(c, area);
// 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();
2011-01-30 14:34:42 +00:00
if (nextPlacement == Unknown)
nextPlacement = Smart;
2011-01-30 14:34:42 +00:00
//initialize if needed
if (cci[dn].pos.x() < 0 || cci[dn].pos.x() < X || cci[dn].pos.y() < Y) {
cci[dn].pos = QPoint(X, Y);
cci[dn].col = cci[dn].row = 0;
2011-01-30 14:34:42 +00:00
}
xp = cci[dn].pos.x();
yp = cci[dn].pos.y();
//here to touch in case people vote for resize on placement
if ((yp + ch) > H) yp = Y;
2011-01-30 14:34:42 +00:00
if ((xp + cw) > W) {
if (!yp) {
place(c, area, nextPlacement);
return;
} else xp = X;
}
2011-01-30 14:34:42 +00:00
//if this isn't the first window
if (cci[dn].pos.x() != X && cci[dn].pos.y() != Y) {
/* 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));
*/
2011-01-30 14:34:42 +00:00
if (xp != X && yp == Y) {
++(cci[dn].col);
xp = delta_x * cci[dn].col;
2011-01-30 14:34:42 +00:00
}
if (yp != Y && xp == X) {
++(cci[dn].row);
yp = delta_y * cci[dn].row;
2011-01-30 14:34:42 +00:00
}
// last resort: if still doesn't fit, smart place it
2011-01-30 14:34:42 +00:00
if (((xp + cw) > W - X) || ((yp + ch) > H - Y)) {
place(c, area, nextPlacement);
return;
}
2011-01-30 14:34:42 +00:00
}
// place the window
c->move(QPoint(xp, yp));
// new position
cci[dn].pos = QPoint(xp + delta_x, yp + delta_y);
2011-01-30 14:34:42 +00:00
}
/*!
Place windows centered, on top of all others
*/
2011-01-30 14:34:42 +00:00
void Placement::placeCentered(Client* c, const QRect& area, Policy /*next*/)
{
// get the maximum allowed windows space and desk's origin
2011-01-30 14:34:42 +00:00
const QRect maxRect = checkArea(c, area);
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));
2011-01-30 14:34:42 +00:00
}
/*!
Place windows in the (0,0) corner, on top of all others
*/
2011-01-30 14:34:42 +00:00
void Placement::placeZeroCornered(Client* c, const QRect& area, Policy /*next*/)
{
// get the maximum allowed windows space and desk's origin
2011-01-30 14:34:42 +00:00
const QRect maxRect = checkArea(c, area);
// place the window
c->move(QPoint(maxRect.left(), maxRect.top()));
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void Placement::placeUtility(Client* c, QRect& area, Policy /*next*/)
{
// 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
2011-01-30 14:34:42 +00:00
place(c, area, Default);
}
2011-01-30 14:34:42 +00:00
void Placement::placeDialog(Client* c, QRect& area, Policy nextPlacement)
{
placeOnMainWindow(c, area, nextPlacement);
}
2011-01-30 14:34:42 +00:00
void Placement::placeUnderMouse(Client* c, QRect& area, Policy /*next*/)
{
area = checkArea(c, area);
QRect geom = c->geometry();
2011-01-30 14:34:42 +00:00
geom.moveCenter(cursorPos());
c->move(geom.topLeft());
c->keepInArea(area); // make sure it's kept inside workarea
}
2011-01-30 14:34:42 +00:00
void Placement::placeOnMainWindow(Client* c, QRect& area, Policy nextPlacement)
{
if (nextPlacement == Unknown)
nextPlacement = Centered;
2011-01-30 14:34:42 +00:00
if (nextPlacement == Maximizing) // maximize if needed
placeMaximizing(c, area, NoPlacement);
area = checkArea(c, area);
ClientList mainwindows = c->mainClients();
Client* place_on = NULL;
Client* place_on2 = NULL;
int mains_count = 0;
2011-01-30 14:34:42 +00:00
for (ClientList::ConstIterator it = mainwindows.constBegin();
it != mainwindows.constEnd();
++it) {
if (mainwindows.count() > 1 && (*it)->isSpecialWindow())
continue; // don't consider toolbars etc when placing
++mains_count;
place_on2 = *it;
2011-01-30 14:34:42 +00:00
if ((*it)->isOnCurrentDesktop()) {
if (place_on == NULL)
place_on = *it;
2011-01-30 14:34:42 +00:00
else {
// two or more on current desktop -> center
// That's the default at least. However, with maximizing placement
// policy as the default, the dialog should be either maximized or
// made as large as its maximum size and then placed centered.
// So the nextPlacement argument allows chaining. In this case, nextPlacement
// is Maximizing and it will call placeCentered().
place(c, area, Centered);
return;
}
}
2011-01-30 14:34:42 +00:00
}
if (place_on == NULL) {
// 'mains_count' is used because it doesn't include ignored mainwindows
if (mains_count != 1) {
place(c, area, Centered);
return;
}
2011-01-30 14:34:42 +00:00
place_on = place_on2; // use the only window filtered together with 'mains_count'
}
if (place_on->isDesktop()) {
place(c, area, Centered);
return;
2011-01-30 14:34:42 +00:00
}
QRect geom = c->geometry();
2011-01-30 14:34:42 +00:00
geom.moveCenter(place_on->geometry().center());
c->move(geom.topLeft());
// get area again, because the mainwindow may be on different xinerama screen
2011-01-30 14:34:42 +00:00
area = checkArea(c, QRect());
c->keepInArea(area); // make sure it's kept inside workarea
}
2011-01-30 14:34:42 +00:00
void Placement::placeMaximizing(Client* c, QRect& area, Policy nextPlacement)
{
if (nextPlacement == Unknown)
nextPlacement = Smart;
2011-01-30 14:34:42 +00:00
if (c->isMaximizable() && c->maxSize().width() >= area.width() && c->maxSize().height() >= area.height()) {
if (m_WorkspacePtr->clientArea(MaximizeArea, c) == area)
c->maximize(Client::MaximizeFull);
else { // if the geometry doesn't match default maximize area (xinerama case?),
// it's probably better to use the given area
c->setGeometry(area);
}
2011-01-30 14:34:42 +00:00
} else {
c->resizeWithChecks(c->maxSize().boundedTo(area.size()));
place(c, area, nextPlacement);
}
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +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;
2011-01-30 14:34:42 +00:00
}
#endif
2011-01-30 14:34:42 +00:00
Placement::Policy Placement::policyFromString(const QString& policy, bool no_special)
{
if (policy == "NoPlacement")
return NoPlacement;
2011-01-30 14:34:42 +00:00
else if (policy == "Default" && !no_special)
return Default;
2011-01-30 14:34:42 +00:00
else if (policy == "Random")
return Random;
2011-01-30 14:34:42 +00:00
else if (policy == "Cascade")
return Cascade;
2011-01-30 14:34:42 +00:00
else if (policy == "Centered")
return Centered;
2011-01-30 14:34:42 +00:00
else if (policy == "ZeroCornered")
return ZeroCornered;
2011-01-30 14:34:42 +00:00
else if (policy == "UnderMouse" && !no_special)
return UnderMouse;
2011-01-30 14:34:42 +00:00
else if (policy == "OnMainWindow" && !no_special)
return OnMainWindow;
2011-01-30 14:34:42 +00:00
else if (policy == "Maximizing")
return Maximizing;
else
return Smart;
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
const char* Placement::policyToString(Policy policy)
{
const char* const policies[] = {
"NoPlacement", "Default", "XXX should never see", "Random", "Smart", "Cascade", "Centered",
"ZeroCornered", "UnderMouse", "OnMainWindow", "Maximizing"
};
assert(policy < int(sizeof(policies) / sizeof(policies[ 0 ])));
return policies[ policy ];
2011-01-30 14:34:42 +00:00
}
#ifndef KCMRULES
// ********************
// Workspace
// ********************
/*!
Moves active window left until in bumps into another window or workarea edge.
*/
void Workspace::slotWindowPackLeft()
2011-01-30 14:34:42 +00:00
{
if (active_client && active_client->isMovable())
active_client->move(packPositionLeft(active_client, active_client->geometry().left(), true),
active_client->y());
}
void Workspace::slotWindowPackRight()
2011-01-30 14:34:42 +00:00
{
if (active_client && active_client->isMovable())
active_client->move(
packPositionRight(active_client, active_client->geometry().right(), true)
- active_client->width() + 1, active_client->y());
2011-01-30 14:34:42 +00:00
}
void Workspace::slotWindowPackUp()
2011-01-30 14:34:42 +00:00
{
if (active_client && active_client->isMovable())
active_client->move(active_client->x(),
packPositionUp(active_client, active_client->geometry().top(), true));
}
void Workspace::slotWindowPackDown()
2011-01-30 14:34:42 +00:00
{
if (active_client && active_client->isMovable())
active_client->move(active_client->x(),
packPositionDown(active_client, active_client->geometry().bottom(), true) - active_client->height() + 1);
}
void Workspace::slotWindowGrowHorizontal()
2011-01-30 14:34:42 +00:00
{
if (active_client)
active_client->growHorizontal();
2011-01-30 14:34:42 +00:00
}
void Client::growHorizontal()
2011-01-30 14:34:42 +00:00
{
if (!isResizable() || isShade())
return;
QRect geom = geometry();
2011-01-30 14:34:42 +00:00
geom.setRight(workspace()->packPositionRight(this, geom.right(), true));
QSize adjsize = adjustedSize(geom.size(), SizemodeFixedW);
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);
// check that it hasn't grown outside of the area, due to size increments
// TODO this may be wrong?
2011-01-30 14:34:42 +00:00
if (workspace()->clientArea(MovementArea,
QPoint((x() + newright) / 2, geometry().center().y()), desktop()).right() >= newright)
geom.setRight(newright);
}
2011-01-30 14:34:42 +00:00
geom.setSize(adjustedSize(geom.size(), SizemodeFixedW));
setGeometry(geom);
}
void Workspace::slotWindowShrinkHorizontal()
2011-01-30 14:34:42 +00:00
{
if (active_client)
active_client->shrinkHorizontal();
2011-01-30 14:34:42 +00:00
}
void Client::shrinkHorizontal()
2011-01-30 14:34:42 +00:00
{
if (!isResizable() || isShade())
return;
QRect geom = geometry();
2011-01-30 14:34:42 +00:00
geom.setRight(workspace()->packPositionLeft(this, geom.right(), false));
if (geom.width() <= 1)
return;
2011-01-30 14:34:42 +00:00
geom.setSize(adjustedSize(geom.size(), SizemodeFixedW));
if (geom.width() > 20)
setGeometry(geom);
}
void Workspace::slotWindowGrowVertical()
2011-01-30 14:34:42 +00:00
{
if (active_client)
active_client->growVertical();
2011-01-30 14:34:42 +00:00
}
void Client::growVertical()
2011-01-30 14:34:42 +00:00
{
if (!isResizable() || isShade())
return;
QRect geom = geometry();
2011-01-30 14:34:42 +00:00
geom.setBottom(workspace()->packPositionDown(this, geom.bottom(), true));
QSize adjsize = adjustedSize(geom.size(), SizemodeFixedH);
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);
// check that it hasn't grown outside of the area, due to size increments
2011-01-30 14:34:42 +00:00
if (workspace()->clientArea(MovementArea,
QPoint(geometry().center().x(), (y() + newbottom) / 2), desktop()).bottom() >= newbottom)
geom.setBottom(newbottom);
}
2011-01-30 14:34:42 +00:00
geom.setSize(adjustedSize(geom.size(), SizemodeFixedH));
setGeometry(geom);
}
void Workspace::slotWindowShrinkVertical()
2011-01-30 14:34:42 +00:00
{
if (active_client)
active_client->shrinkVertical();
2011-01-30 14:34:42 +00:00
}
void Client::shrinkVertical()
2011-01-30 14:34:42 +00:00
{
if (!isResizable() || isShade())
return;
QRect geom = geometry();
2011-01-30 14:34:42 +00:00
geom.setBottom(workspace()->packPositionUp(this, geom.bottom(), false));
if (geom.height() <= 1)
return;
2011-01-30 14:34:42 +00:00
geom.setSize(adjustedSize(geom.size(), SizemodeFixedH));
if (geom.height() > 20)
setGeometry(geom);
}
void Workspace::slotWindowQuickTileLeft()
2011-01-30 14:34:42 +00:00
{
if (!active_client)
return;
2011-01-30 14:34:42 +00:00
active_client->setQuickTileMode(QuickTileLeft, true);
}
void Workspace::slotWindowQuickTileRight()
2011-01-30 14:34:42 +00:00
{
if (!active_client)
return;
2011-01-30 14:34:42 +00:00
active_client->setQuickTileMode(QuickTileRight, true);
}
2011-01-30 14:34:42 +00:00
int Workspace::packPositionLeft(const Client* cl, int oldx, bool left_edge) const
{
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)
return oldx;
2011-01-30 14:34:42 +00:00
for (ClientList::ConstIterator it = clients.constBegin();
it != clients.constEnd();
++it) {
if (!(*it)->isShown(false) || !(*it)->isOnDesktop(active_client->desktop()))
continue;
int x = left_edge ? (*it)->geometry().right() + 1 : (*it)->geometry().left() - 1;
2011-01-30 14:34:42 +00:00
if (x > newx && x < oldx
&& !(cl->geometry().top() > (*it)->geometry().bottom() // they overlap in Y direction
|| cl->geometry().bottom() < (*it)->geometry().top()))
newx = x;
}
2011-01-30 14:34:42 +00:00
return newx;
}
2011-01-30 14:34:42 +00:00
int Workspace::packPositionRight(const Client* cl, int oldx, bool right_edge) const
{
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)
return oldx;
2011-01-30 14:34:42 +00:00
for (ClientList::ConstIterator it = clients.constBegin();
it != clients.constEnd();
++it) {
if (!(*it)->isShown(false) || !(*it)->isOnDesktop(cl->desktop()))
continue;
int x = right_edge ? (*it)->geometry().left() - 1 : (*it)->geometry().right() + 1;
2011-01-30 14:34:42 +00:00
if (x < newx && x > oldx
&& !(cl->geometry().top() > (*it)->geometry().bottom()
|| cl->geometry().bottom() < (*it)->geometry().top()))
newx = x;
}
2011-01-30 14:34:42 +00:00
return newx;
}
2011-01-30 14:34:42 +00:00
int Workspace::packPositionUp(const Client* cl, int oldy, bool top_edge) const
{
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)
return oldy;
2011-01-30 14:34:42 +00:00
for (ClientList::ConstIterator it = clients.constBegin();
it != clients.constEnd();
++it) {
if (!(*it)->isShown(false) || !(*it)->isOnDesktop(cl->desktop()))
continue;
int y = top_edge ? (*it)->geometry().bottom() + 1 : (*it)->geometry().top() - 1;
2011-01-30 14:34:42 +00:00
if (y > newy && y < oldy
&& !(cl->geometry().left() > (*it)->geometry().right() // they overlap in X direction
|| cl->geometry().right() < (*it)->geometry().left()))
newy = y;
}
2011-01-30 14:34:42 +00:00
return newy;
}
2011-01-30 14:34:42 +00:00
int Workspace::packPositionDown(const Client* cl, int oldy, bool bottom_edge) const
{
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)
return oldy;
2011-01-30 14:34:42 +00:00
for (ClientList::ConstIterator it = clients.constBegin();
it != clients.constEnd();
++it) {
if (!(*it)->isShown(false) || !(*it)->isOnDesktop(cl->desktop()))
continue;
int y = bottom_edge ? (*it)->geometry().top() - 1 : (*it)->geometry().bottom() + 1;
2011-01-30 14:34:42 +00:00
if (y < newy && y > oldy
&& !(cl->geometry().left() > (*it)->geometry().right()
|| cl->geometry().right() < (*it)->geometry().left()))
newy = y;
}
2011-01-30 14:34:42 +00:00
return newy;
}
/*!
Asks the internal positioning object to place a client
*/
void Workspace::place(Client* c, QRect& area)
2011-01-30 14:34:42 +00:00
{
initPositioning->place(c, area);
}
void Workspace::placeSmart(Client* c, const QRect& area)
2011-01-30 14:34:42 +00:00
{
initPositioning->placeSmart(c, area);
}
#endif
} // namespace