2007-11-27 22:40:25 +03:00
|
|
|
/********************************************************************
|
2007-04-29 21:35:43 +04: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) 1997 to 2002 Cristian Tibirna <tibirna@kde.org>
|
|
|
|
Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
|
2007-11-27 22:40:25 +03: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 21:35:43 +04:00
|
|
|
|
|
|
|
#include "placement.h"
|
|
|
|
|
|
|
|
#include <QRect>
|
|
|
|
#include <assert.h>
|
|
|
|
|
2007-10-06 02:21:25 +04:00
|
|
|
#include <QTextStream>
|
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
#ifndef KCMRULES
|
|
|
|
#include "workspace.h"
|
|
|
|
#include "client.h"
|
2014-03-19 17:45:27 +04:00
|
|
|
#include "cursor.h"
|
2007-04-29 21:35:43 +04:00
|
|
|
#include "options.h"
|
|
|
|
#include "rules.h"
|
2013-09-16 18:26:21 +04:00
|
|
|
#include "screens.h"
|
2007-04-29 21:35:43 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifndef KCMRULES
|
|
|
|
|
2013-04-05 11:41:25 +04:00
|
|
|
KWIN_SINGLETON_FACTORY(Placement)
|
2012-11-22 16:06:42 +04:00
|
|
|
|
2013-04-05 11:41:25 +04:00
|
|
|
Placement::Placement(QObject*)
|
2012-11-22 16:06:42 +04:00
|
|
|
{
|
2011-01-30 17:34:42 +03:00
|
|
|
reinitCascading(0);
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2012-11-22 16:06:42 +04:00
|
|
|
Placement::~Placement()
|
|
|
|
{
|
|
|
|
s_self = NULL;
|
|
|
|
}
|
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
/*!
|
|
|
|
Places the client \a c according to the workspace's layout policy
|
|
|
|
*/
|
2015-05-27 14:22:50 +03:00
|
|
|
void Placement::place(AbstractClient* c, QRect& area)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
Policy policy = c->rules()->checkPlacement(Default);
|
|
|
|
if (policy != Default) {
|
|
|
|
place(c, area, policy);
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
if (c->isUtility())
|
2012-02-20 13:25:13 +04:00
|
|
|
placeUtility(c, area, options->placement());
|
2011-01-30 17:34:42 +03:00
|
|
|
else if (c->isDialog())
|
2012-02-20 13:25:13 +04:00
|
|
|
placeDialog(c, area, options->placement());
|
2011-01-30 17:34:42 +03:00
|
|
|
else if (c->isSplash())
|
|
|
|
placeOnMainWindow(c, area); // on mainwindow, if any, otherwise centered
|
2015-01-02 14:11:54 +03:00
|
|
|
else if (c->isOnScreenDisplay() || c->isNotification())
|
|
|
|
placeOnScreenDisplay(c, area);
|
2015-09-11 14:31:41 +03:00
|
|
|
else if (c->isTransient() && c->hasTransientPlacementHint())
|
|
|
|
placeTransient(c);
|
2007-04-29 21:35:43 +04:00
|
|
|
else
|
2012-02-20 13:25:13 +04:00
|
|
|
place(c, area, options->placement());
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2015-05-27 14:22:50 +03:00
|
|
|
void Placement::place(AbstractClient* c, QRect& area, Policy policy, Policy nextPlacement)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (policy == Unknown)
|
2007-04-29 21:35:43 +04:00
|
|
|
policy = Default;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (policy == Default)
|
2012-02-20 13:25:13 +04:00
|
|
|
policy = options->placement();
|
2011-01-30 17:34:42 +03:00
|
|
|
if (policy == NoPlacement)
|
2007-04-29 21:35:43 +04:00
|
|
|
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 17:34:42 +03:00
|
|
|
else if (policy == Maximizing)
|
2007-04-29 21:35:43 +04:00
|
|
|
placeMaximizing(c, area, nextPlacement);
|
|
|
|
else
|
|
|
|
placeSmart(c, area, nextPlacement);
|
2013-08-15 13:53:02 +04:00
|
|
|
|
|
|
|
if (options->borderSnapZone()) {
|
|
|
|
// snap to titlebar / snap to window borders on inner screen edges
|
|
|
|
const QRect geo(c->geometry());
|
|
|
|
QPoint corner = geo.topLeft();
|
|
|
|
const QPoint cp = c->clientPos();
|
|
|
|
const QSize cs = geo.size() - c->clientSize();
|
2014-12-02 13:12:20 +03:00
|
|
|
Client::Position titlePos = c->titlebarPosition();
|
2013-08-15 13:53:02 +04:00
|
|
|
|
|
|
|
const QRect fullRect = workspace()->clientArea(FullArea, c);
|
2014-12-02 15:49:08 +03:00
|
|
|
if (!(c->maximizeMode() & MaximizeHorizontal)) {
|
2014-12-02 13:12:20 +03:00
|
|
|
if (titlePos != Client::PositionRight && geo.right() == fullRect.right())
|
2013-08-15 13:53:02 +04:00
|
|
|
corner.rx() += cs.width() - cp.x();
|
2014-12-02 13:12:20 +03:00
|
|
|
if (titlePos != Client::PositionLeft && geo.x() == fullRect.x())
|
2013-08-15 13:53:02 +04:00
|
|
|
corner.rx() -= cp.x();
|
|
|
|
}
|
2014-12-02 15:49:08 +03:00
|
|
|
if (!(c->maximizeMode() & MaximizeVertical)) {
|
2014-12-02 13:12:20 +03:00
|
|
|
if (titlePos != Client::PositionBottom && geo.bottom() == fullRect.bottom())
|
2013-08-15 13:53:02 +04:00
|
|
|
corner.ry() += cs.height() - cp.y();
|
2014-12-02 13:12:20 +03:00
|
|
|
if (titlePos != Client::PositionTop && geo.y() == fullRect.y())
|
2013-08-15 13:53:02 +04:00
|
|
|
corner.ry() -= cp.y();
|
|
|
|
}
|
|
|
|
c->move(corner);
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Place the client \a c according to a simply "random" placement algorithm.
|
|
|
|
*/
|
2015-05-27 11:34:15 +03:00
|
|
|
void Placement::placeAtRandom(AbstractClient* c, const QRect& area, Policy /*next*/)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2007-04-29 21:35:43 +04:00
|
|
|
const int step = 24;
|
|
|
|
static int px = step;
|
|
|
|
static int py = 2 * step;
|
2011-01-30 17:34:42 +03:00
|
|
|
int tx, ty;
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
const QRect maxRect = checkArea(c, area);
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
if (px < maxRect.x())
|
|
|
|
px = maxRect.x();
|
|
|
|
if (py < maxRect.y())
|
|
|
|
py = maxRect.y();
|
|
|
|
|
|
|
|
px += step;
|
2011-01-30 17:34:42 +03:00
|
|
|
py += 2 * step;
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
if (px > maxRect.width() / 2)
|
2007-04-29 21:35:43 +04:00
|
|
|
px = maxRect.x() + step;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (py > maxRect.height() / 2)
|
2007-04-29 21:35:43 +04:00
|
|
|
py = maxRect.y() + step;
|
|
|
|
tx = px;
|
|
|
|
ty = py;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (tx + c->width() > maxRect.right()) {
|
2007-04-29 21:35:43 +04:00
|
|
|
tx = maxRect.right() - c->width();
|
|
|
|
if (tx < 0)
|
|
|
|
tx = 0;
|
|
|
|
px = maxRect.x();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
if (ty + c->height() > maxRect.bottom()) {
|
2007-04-29 21:35:43 +04:00
|
|
|
ty = maxRect.bottom() - c->height();
|
|
|
|
if (ty < 0)
|
|
|
|
ty = 0;
|
|
|
|
py = maxRect.y();
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
c->move(tx, ty);
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2013-01-22 23:09:42 +04:00
|
|
|
// TODO: one day, there'll be C++11 ...
|
2015-03-12 12:44:34 +03:00
|
|
|
static inline bool isIrrelevant(const AbstractClient *client, const AbstractClient *regarding, int desktop)
|
2013-01-22 23:09:42 +04:00
|
|
|
{
|
|
|
|
if (!client)
|
|
|
|
return true;
|
|
|
|
if (client == regarding)
|
|
|
|
return true;
|
|
|
|
if (!client->isCurrentTab())
|
|
|
|
return true;
|
|
|
|
if (!client->isShown(false))
|
|
|
|
return true;
|
|
|
|
if (!client->isOnDesktop(desktop))
|
|
|
|
return true;
|
|
|
|
if (!client->isOnCurrentActivity())
|
|
|
|
return true;
|
2013-06-25 17:35:13 +04:00
|
|
|
if (client->isDesktop())
|
|
|
|
return true;
|
2013-01-22 23:09:42 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
/*!
|
|
|
|
Place the client \a c according to a really smart placement algorithm :-)
|
|
|
|
*/
|
2015-05-27 11:32:42 +03:00
|
|
|
void Placement::placeSmart(AbstractClient* c, const QRect& area, Policy /*next*/)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2007-04-29 21:35:43 +04: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;
|
2012-11-16 11:23:47 +04:00
|
|
|
int desktop = c->desktop() == 0 || c->isOnAllDesktops() ? VirtualDesktopManager::self()->current() : c->desktop();
|
2007-04-29 21:35:43 +04: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
|
2011-01-30 17:34:42 +03:00
|
|
|
const QRect maxRect = checkArea(c, area);
|
2007-04-29 21:35:43 +04: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
|
2011-01-30 17:34:42 +03:00
|
|
|
do {
|
2007-04-29 21:35:43 +04: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
|
2011-01-30 17:34:42 +03:00
|
|
|
else if (x + cw > maxRect.right())
|
2007-04-29 21:35:43 +04:00
|
|
|
overlap = w_wrong;
|
2011-01-30 17:34:42 +03:00
|
|
|
else {
|
2007-04-29 21:35:43 +04:00
|
|
|
overlap = none; //initialize
|
|
|
|
|
|
|
|
cxl = x; cxr = x + cw;
|
|
|
|
cyt = y; cyb = y + ch;
|
2012-04-08 12:07:35 +04:00
|
|
|
ToplevelList::ConstIterator l;
|
2013-05-08 15:55:20 +04:00
|
|
|
for (l = workspace()->stackingOrder().constBegin(); l != workspace()->stackingOrder().constEnd() ; ++l) {
|
2015-05-27 11:32:42 +03:00
|
|
|
AbstractClient *client = qobject_cast<AbstractClient*>(*l);
|
2013-01-22 23:09:42 +04:00
|
|
|
if (isIrrelevant(client, c, desktop)) {
|
2012-04-08 12:07:35 +04:00
|
|
|
continue;
|
|
|
|
}
|
2013-01-22 23:09:42 +04:00
|
|
|
xl = client->x(); yt = client->y();
|
|
|
|
xr = xl + client->width(); yb = yt + client->height();
|
|
|
|
|
|
|
|
//if windows overlap, calc the overall overlapping
|
|
|
|
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);
|
|
|
|
if (client->keepAbove())
|
|
|
|
overlap += 16 * (xr - xl) * (yb - yt);
|
|
|
|
else if (client->keepBelow() && !client->isDock()) // ignore KeepBelow windows
|
|
|
|
overlap += 0; // for placement (see Client::belongsToLayer() for Dock)
|
|
|
|
else
|
|
|
|
overlap += (xr - xl) * (yb - yt);
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
//CT first time we get no overlap we stop.
|
2011-01-30 17:34:42 +03:00
|
|
|
if (overlap == none) {
|
2007-04-29 21:35:43 +04:00
|
|
|
x_optimal = x;
|
|
|
|
y_optimal = y;
|
|
|
|
break;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
if (first_pass) {
|
2007-04-29 21:35:43 +04:00
|
|
|
first_pass = false;
|
|
|
|
min_overlap = overlap;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
//CT save the best position and the minimum overlap up to now
|
2011-01-30 17:34:42 +03:00
|
|
|
else if (overlap >= none && overlap < min_overlap) {
|
2007-04-29 21:35:43 +04:00
|
|
|
min_overlap = overlap;
|
|
|
|
x_optimal = x;
|
|
|
|
y_optimal = y;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
// really need to loop? test if there's any overlap
|
2011-01-30 17:34:42 +03:00
|
|
|
if (overlap > none) {
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
possible = maxRect.right();
|
|
|
|
if (possible - cw > x) possible -= cw;
|
|
|
|
|
|
|
|
// compare to the position of each client on the same desk
|
2012-04-08 12:07:35 +04:00
|
|
|
ToplevelList::ConstIterator l;
|
2013-05-08 15:55:20 +04:00
|
|
|
for (l = workspace()->stackingOrder().constBegin(); l != workspace()->stackingOrder().constEnd() ; ++l) {
|
2015-05-27 11:32:42 +03:00
|
|
|
AbstractClient *client = qobject_cast<AbstractClient*>(*l);
|
2013-01-22 23:09:42 +04:00
|
|
|
if (isIrrelevant(client, c, desktop)) {
|
2012-04-08 12:07:35 +04:00
|
|
|
continue;
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2013-01-22 23:09:42 +04:00
|
|
|
xl = client->x(); yt = client->y();
|
|
|
|
xr = xl + client->width(); yb = yt + client->height();
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2013-01-22 23:09:42 +04:00
|
|
|
// if not enough room above or under the current tested client
|
|
|
|
// determine the first non-overlapped x position
|
|
|
|
if ((y < yb) && (yt < ch + y)) {
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2013-01-22 23:09:42 +04:00
|
|
|
if ((xr > x) && (possible > xr)) possible = xr;
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2013-01-22 23:09:42 +04:00
|
|
|
basket = xl - cw;
|
|
|
|
if ((basket > x) && (possible > basket)) possible = basket;
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
x = possible;
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
// ... else ==> not enough x dimension (overlap was wrong on horizontal)
|
2011-01-30 17:34:42 +03:00
|
|
|
else if (overlap == w_wrong) {
|
2007-04-29 21:35:43 +04:00
|
|
|
x = maxRect.left();
|
|
|
|
possible = maxRect.bottom();
|
|
|
|
|
|
|
|
if (possible - ch > y) possible -= ch;
|
|
|
|
|
|
|
|
//test the position of each window on the desk
|
2012-04-08 12:07:35 +04:00
|
|
|
ToplevelList::ConstIterator l;
|
2013-05-08 15:55:20 +04:00
|
|
|
for (l = workspace()->stackingOrder().constBegin(); l != workspace()->stackingOrder().constEnd() ; ++l) {
|
2015-05-27 11:32:42 +03:00
|
|
|
AbstractClient *client = qobject_cast<AbstractClient*>(*l);
|
2013-01-22 23:09:42 +04:00
|
|
|
if (isIrrelevant(client, c, desktop)) {
|
2012-04-08 12:07:35 +04:00
|
|
|
continue;
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2013-01-22 23:09:42 +04:00
|
|
|
xl = client->x(); yt = client->y();
|
|
|
|
xr = xl + client->width(); yb = yt + client->height();
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2013-01-22 23:09:42 +04:00
|
|
|
// 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;
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2013-01-22 23:09:42 +04:00
|
|
|
basket = yt - ch;
|
|
|
|
if ((basket > y) && (possible > basket)) possible = basket;
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
y = possible;
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
} while ((overlap != none) && (overlap != h_wrong) && (y < maxRect.bottom()));
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
if (ch >= maxRect.height())
|
|
|
|
y_optimal = maxRect.top();
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
// place the window
|
|
|
|
c->move(x_optimal, y_optimal);
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
void Placement::reinitCascading(int desktop)
|
|
|
|
{
|
|
|
|
// desktop == 0 - reinit all
|
|
|
|
if (desktop == 0) {
|
2007-04-29 21:35:43 +04:00
|
|
|
cci.clear();
|
2012-11-16 11:23:47 +04:00
|
|
|
for (uint i = 0; i < VirtualDesktopManager::self()->count(); ++i) {
|
2007-04-29 21:35:43 +04:00
|
|
|
DesktopCascadingInfo inf;
|
2011-01-30 17:34:42 +03:00
|
|
|
inf.pos = QPoint(-1, -1);
|
2007-04-29 21:35:43 +04:00
|
|
|
inf.col = 0;
|
|
|
|
inf.row = 0;
|
|
|
|
cci.append(inf);
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
} else {
|
2007-04-29 21:35:43 +04:00
|
|
|
cci[desktop - 1].pos = QPoint(-1, -1);
|
|
|
|
cci[desktop - 1].col = cci[desktop - 1].row = 0;
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2015-03-06 11:31:14 +03:00
|
|
|
QPoint Workspace::cascadeOffset(const AbstractClient *c) const
|
2012-08-25 20:20:34 +04:00
|
|
|
{
|
|
|
|
QRect area = clientArea(PlacementArea, c->geometry().center(), c->desktop());
|
|
|
|
return QPoint(area.width()/48, area.height()/48);
|
|
|
|
}
|
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
/*!
|
|
|
|
Place windows in a cascading order, remembering positions for each desktop
|
|
|
|
*/
|
2015-05-27 14:22:50 +03:00
|
|
|
void Placement::placeCascaded(AbstractClient* c, QRect& area, Policy nextPlacement)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2007-04-29 21:35:43 +04: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"
|
2013-05-08 15:55:20 +04:00
|
|
|
const QPoint delta = workspace()->cascadeOffset(c);
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2012-11-16 11:23:47 +04:00
|
|
|
const int dn = c->desktop() == 0 || c->isOnAllDesktops() ? (VirtualDesktopManager::self()->current() - 1) : (c->desktop() - 1);
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
// get the maximum allowed windows space and desk's origin
|
2011-01-30 17:34:42 +03:00
|
|
|
QRect maxRect = checkArea(c, area);
|
2007-04-29 21:35:43 +04: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();
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
if (nextPlacement == Unknown)
|
2007-04-29 21:35:43 +04:00
|
|
|
nextPlacement = Smart;
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
//initialize if needed
|
|
|
|
if (cci[dn].pos.x() < 0 || cci[dn].pos.x() < X || cci[dn].pos.y() < Y) {
|
2007-04-29 21:35:43 +04:00
|
|
|
cci[dn].pos = QPoint(X, Y);
|
|
|
|
cci[dn].col = cci[dn].row = 0;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04: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 17:34:42 +03:00
|
|
|
if ((xp + cw) > W) {
|
|
|
|
if (!yp) {
|
|
|
|
place(c, area, nextPlacement);
|
|
|
|
return;
|
|
|
|
} else xp = X;
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
//if this isn't the first window
|
|
|
|
if (cci[dn].pos.x() != X && cci[dn].pos.y() != Y) {
|
2007-04-29 21:35:43 +04: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
|
|
|
|
*
|
2012-08-25 20:20:34 +04:00
|
|
|
* if (xp != X && yp == Y) xp = delta.x() * (++(cci[dn].col));
|
|
|
|
* if (yp != Y && xp == X) yp = delta.y() * (++(cci[dn].row));
|
2007-04-29 21:35:43 +04:00
|
|
|
*/
|
2011-01-30 17:34:42 +03:00
|
|
|
if (xp != X && yp == Y) {
|
2007-04-29 21:35:43 +04:00
|
|
|
++(cci[dn].col);
|
2012-08-25 20:20:34 +04:00
|
|
|
xp = delta.x() * cci[dn].col;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
if (yp != Y && xp == X) {
|
2007-04-29 21:35:43 +04:00
|
|
|
++(cci[dn].row);
|
2012-08-25 20:20:34 +04:00
|
|
|
yp = delta.y() * cci[dn].row;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
// last resort: if still doesn't fit, smart place it
|
2011-01-30 17:34:42 +03:00
|
|
|
if (((xp + cw) > W - X) || ((yp + ch) > H - Y)) {
|
|
|
|
place(c, area, nextPlacement);
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
// place the window
|
|
|
|
c->move(QPoint(xp, yp));
|
|
|
|
|
|
|
|
// new position
|
2012-08-25 20:20:34 +04:00
|
|
|
cci[dn].pos = QPoint(xp + delta.x(), yp + delta.y());
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Place windows centered, on top of all others
|
|
|
|
*/
|
2015-05-27 11:28:23 +03:00
|
|
|
void Placement::placeCentered(AbstractClient* c, const QRect& area, Policy /*next*/)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
// get the maximum allowed windows space and desk's origin
|
2011-01-30 17:34:42 +03:00
|
|
|
const QRect maxRect = checkArea(c, area);
|
2007-04-29 21:35:43 +04: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));
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Place windows in the (0,0) corner, on top of all others
|
|
|
|
*/
|
2015-05-27 11:25:04 +03:00
|
|
|
void Placement::placeZeroCornered(AbstractClient* c, const QRect& area, Policy /*next*/)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2007-04-29 21:35:43 +04:00
|
|
|
// get the maximum allowed windows space and desk's origin
|
2013-08-15 13:53:02 +04:00
|
|
|
c->move(checkArea(c, area).topLeft());
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2015-05-27 14:22:50 +03:00
|
|
|
void Placement::placeUtility(AbstractClient* c, QRect& area, Policy /*next*/)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2007-04-29 21:35:43 +04: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
|
2011-01-30 17:34:42 +03:00
|
|
|
place(c, area, Default);
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2015-05-27 11:36:59 +03:00
|
|
|
void Placement::placeOnScreenDisplay(AbstractClient* c, QRect& area)
|
2014-02-12 13:50:13 +04:00
|
|
|
{
|
|
|
|
// place at lower 1/3 of the screen
|
|
|
|
const int x = area.left() + (area.width() - c->width()) / 2;
|
|
|
|
const int y = area.top() + 2 * (area.height() - c->height()) / 3;
|
|
|
|
|
|
|
|
c->move(QPoint(x, y));
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2015-09-11 14:31:41 +03:00
|
|
|
void Placement::placeTransient(AbstractClient *c)
|
|
|
|
{
|
|
|
|
// TODO: apply sanity checks?
|
|
|
|
c->move(c->transientFor()->pos() + c->transientPlacementHint());
|
|
|
|
}
|
|
|
|
|
2015-05-27 14:22:50 +03:00
|
|
|
void Placement::placeDialog(AbstractClient* c, QRect& area, Policy nextPlacement)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
placeOnMainWindow(c, area, nextPlacement);
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2015-05-27 12:53:51 +03:00
|
|
|
void Placement::placeUnderMouse(AbstractClient* c, QRect& area, Policy /*next*/)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
area = checkArea(c, area);
|
2007-04-29 21:35:43 +04:00
|
|
|
QRect geom = c->geometry();
|
2014-03-19 17:45:27 +04:00
|
|
|
geom.moveCenter(Cursor::pos());
|
2011-01-30 17:34:42 +03:00
|
|
|
c->move(geom.topLeft());
|
|
|
|
c->keepInArea(area); // make sure it's kept inside workarea
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2015-05-27 14:22:50 +03:00
|
|
|
void Placement::placeOnMainWindow(AbstractClient* c, QRect& area, Policy nextPlacement)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (nextPlacement == Unknown)
|
2007-04-29 21:35:43 +04:00
|
|
|
nextPlacement = Centered;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (nextPlacement == Maximizing) // maximize if needed
|
|
|
|
placeMaximizing(c, area, NoPlacement);
|
|
|
|
area = checkArea(c, area);
|
2015-09-11 16:55:23 +03:00
|
|
|
auto mainwindows = c->mainClients();
|
2015-05-27 14:22:50 +03:00
|
|
|
AbstractClient* place_on = nullptr;
|
|
|
|
AbstractClient* place_on2 = nullptr;
|
2007-04-29 21:35:43 +04:00
|
|
|
int mains_count = 0;
|
2015-09-11 16:55:23 +03:00
|
|
|
for (auto it = mainwindows.constBegin();
|
2011-01-30 17:34:42 +03:00
|
|
|
it != mainwindows.constEnd();
|
|
|
|
++it) {
|
|
|
|
if (mainwindows.count() > 1 && (*it)->isSpecialWindow())
|
2007-04-29 21:35:43 +04:00
|
|
|
continue; // don't consider toolbars etc when placing
|
|
|
|
++mains_count;
|
|
|
|
place_on2 = *it;
|
2011-01-30 17:34:42 +03:00
|
|
|
if ((*it)->isOnCurrentDesktop()) {
|
|
|
|
if (place_on == NULL)
|
2007-04-29 21:35:43 +04:00
|
|
|
place_on = *it;
|
2011-01-30 17:34:42 +03: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);
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
if (place_on == NULL) {
|
|
|
|
// 'mains_count' is used because it doesn't include ignored mainwindows
|
|
|
|
if (mains_count != 1) {
|
|
|
|
place(c, area, Centered);
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
place_on = place_on2; // use the only window filtered together with 'mains_count'
|
|
|
|
}
|
|
|
|
if (place_on->isDesktop()) {
|
|
|
|
place(c, area, Centered);
|
2007-05-07 16:37:12 +04:00
|
|
|
return;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
QRect geom = c->geometry();
|
2011-01-30 17:34:42 +03:00
|
|
|
geom.moveCenter(place_on->geometry().center());
|
|
|
|
c->move(geom.topLeft());
|
2007-04-29 21:35:43 +04:00
|
|
|
// get area again, because the mainwindow may be on different xinerama screen
|
2011-01-30 17:34:42 +03:00
|
|
|
area = checkArea(c, QRect());
|
|
|
|
c->keepInArea(area); // make sure it's kept inside workarea
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2015-05-27 14:22:50 +03:00
|
|
|
void Placement::placeMaximizing(AbstractClient* c, QRect& area, Policy nextPlacement)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (nextPlacement == Unknown)
|
2007-04-29 21:35:43 +04:00
|
|
|
nextPlacement = Smart;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (c->isMaximizable() && c->maxSize().width() >= area.width() && c->maxSize().height() >= area.height()) {
|
2013-05-08 15:55:20 +04:00
|
|
|
if (workspace()->clientArea(MaximizeArea, c) == area)
|
2014-12-02 15:49:08 +03:00
|
|
|
c->maximize(MaximizeFull);
|
2011-01-30 17:34:42 +03:00
|
|
|
else { // if the geometry doesn't match default maximize area (xinerama case?),
|
|
|
|
// it's probably better to use the given area
|
2015-05-27 14:22:50 +03:00
|
|
|
if (Client *client = qobject_cast<Client*>(c)) {
|
|
|
|
client->setGeometry(area);
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
} else {
|
|
|
|
c->resizeWithChecks(c->maxSize().boundedTo(area.size()));
|
|
|
|
place(c, area, nextPlacement);
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2012-11-22 14:07:33 +04:00
|
|
|
void Placement::cascadeDesktop()
|
|
|
|
{
|
|
|
|
// TODO XINERAMA this probably is not right for xinerama
|
|
|
|
Workspace *ws = Workspace::self();
|
2012-11-16 11:23:47 +04:00
|
|
|
const int desktop = VirtualDesktopManager::self()->current();
|
2012-11-22 14:07:33 +04:00
|
|
|
reinitCascading(desktop);
|
|
|
|
// TODO: make area const once placeFoo methods are fixed to take a const QRect&
|
|
|
|
QRect area = ws->clientArea(PlacementArea, QPoint(0, 0), desktop);
|
|
|
|
foreach (Toplevel *toplevel, ws->stackingOrder()) {
|
|
|
|
Client *client = qobject_cast<Client*>(toplevel);
|
|
|
|
if (!client ||
|
|
|
|
(!client->isOnCurrentDesktop()) ||
|
|
|
|
(client->isMinimized()) ||
|
|
|
|
(client->isOnAllDesktops()) ||
|
|
|
|
(!client->isMovable()))
|
|
|
|
continue;
|
|
|
|
placeCascaded(client, area);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Placement::unclutterDesktop()
|
|
|
|
{
|
|
|
|
const ClientList &clients = Workspace::self()->clientList();
|
|
|
|
for (int i = clients.size() - 1; i >= 0; i--) {
|
|
|
|
Client *client = clients.at(i);
|
|
|
|
if ((!client->isOnCurrentDesktop()) ||
|
|
|
|
(client->isMinimized()) ||
|
|
|
|
(client->isOnAllDesktops()) ||
|
|
|
|
(!client->isMovable()))
|
|
|
|
continue;
|
|
|
|
placeSmart(client, QRect());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-27 11:22:43 +03:00
|
|
|
QRect Placement::checkArea(const AbstractClient* c, const QRect& area)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (area.isNull())
|
2013-05-08 15:55:20 +04:00
|
|
|
return workspace()->clientArea(PlacementArea, c->geometry().center(), c->desktop());
|
2007-04-29 21:35:43 +04:00
|
|
|
return area;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
Placement::Policy Placement::policyFromString(const QString& policy, bool no_special)
|
|
|
|
{
|
2013-07-23 09:02:52 +04:00
|
|
|
if (policy == QStringLiteral("NoPlacement"))
|
2007-04-29 21:35:43 +04:00
|
|
|
return NoPlacement;
|
2013-07-23 09:02:52 +04:00
|
|
|
else if (policy == QStringLiteral("Default") && !no_special)
|
2007-04-29 21:35:43 +04:00
|
|
|
return Default;
|
2013-07-23 09:02:52 +04:00
|
|
|
else if (policy == QStringLiteral("Random"))
|
2007-04-29 21:35:43 +04:00
|
|
|
return Random;
|
2013-07-23 09:02:52 +04:00
|
|
|
else if (policy == QStringLiteral("Cascade"))
|
2007-04-29 21:35:43 +04:00
|
|
|
return Cascade;
|
2013-07-23 09:02:52 +04:00
|
|
|
else if (policy == QStringLiteral("Centered"))
|
2007-04-29 21:35:43 +04:00
|
|
|
return Centered;
|
2013-07-23 09:02:52 +04:00
|
|
|
else if (policy == QStringLiteral("ZeroCornered"))
|
2007-04-29 21:35:43 +04:00
|
|
|
return ZeroCornered;
|
2013-07-23 09:02:52 +04:00
|
|
|
else if (policy == QStringLiteral("UnderMouse"))
|
2007-04-29 21:35:43 +04:00
|
|
|
return UnderMouse;
|
2013-07-23 09:02:52 +04:00
|
|
|
else if (policy == QStringLiteral("OnMainWindow") && !no_special)
|
2007-04-29 21:35:43 +04:00
|
|
|
return OnMainWindow;
|
2013-07-23 09:02:52 +04:00
|
|
|
else if (policy == QStringLiteral("Maximizing"))
|
2007-04-29 21:35:43 +04:00
|
|
|
return Maximizing;
|
|
|
|
else
|
|
|
|
return Smart;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03: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 ])));
|
2007-04-29 21:35:43 +04:00
|
|
|
return policies[ policy ];
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef KCMRULES
|
|
|
|
|
|
|
|
// ********************
|
|
|
|
// Workspace
|
|
|
|
// ********************
|
|
|
|
|
2013-04-15 22:43:50 +04:00
|
|
|
void Client::packTo(int left, int top)
|
|
|
|
{
|
2015-01-29 02:14:47 +03:00
|
|
|
workspace()->updateFocusMousePosition(Cursor::pos()); // may cause leave event;
|
2015-01-29 02:14:47 +03:00
|
|
|
|
2013-04-15 22:43:50 +04:00
|
|
|
const int oldScreen = screen();
|
|
|
|
move(left, top);
|
|
|
|
if (screen() != oldScreen) {
|
|
|
|
workspace()->sendClientToScreen(this, screen()); // checks rule validity
|
|
|
|
if (maximizeMode() != MaximizeRestore)
|
|
|
|
checkWorkspacePosition();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
/*!
|
|
|
|
Moves active window left until in bumps into another window or workarea edge.
|
|
|
|
*/
|
|
|
|
void Workspace::slotWindowPackLeft()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (active_client && active_client->isMovable())
|
2013-04-15 22:43:50 +04:00
|
|
|
active_client->packTo(packPositionLeft(active_client, active_client->geometry().left(), true),
|
|
|
|
active_client->y());
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
void Workspace::slotWindowPackRight()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (active_client && active_client->isMovable())
|
2013-04-15 22:43:50 +04:00
|
|
|
active_client->packTo(packPositionRight(active_client, active_client->geometry().right(), true)
|
|
|
|
- active_client->width() + 1, active_client->y());
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
void Workspace::slotWindowPackUp()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (active_client && active_client->isMovable())
|
2013-04-15 22:43:50 +04:00
|
|
|
active_client->packTo(active_client->x(),
|
|
|
|
packPositionUp(active_client, active_client->geometry().top(), true));
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
void Workspace::slotWindowPackDown()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (active_client && active_client->isMovable())
|
2013-04-15 22:43:50 +04:00
|
|
|
active_client->packTo(active_client->x(),
|
|
|
|
packPositionDown(active_client, active_client->geometry().bottom(), true) - active_client->height() + 1);
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
void Workspace::slotWindowGrowHorizontal()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (active_client)
|
2007-04-29 21:35:43 +04:00
|
|
|
active_client->growHorizontal();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
void Client::growHorizontal()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (!isResizable() || isShade())
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
|
|
|
QRect geom = geometry();
|
2011-01-30 17:34:42 +03:00
|
|
|
geom.setRight(workspace()->packPositionRight(this, geom.right(), true));
|
|
|
|
QSize adjsize = adjustedSize(geom.size(), SizemodeFixedW);
|
2015-01-21 18:05:29 +03:00
|
|
|
if (geometry().size() == adjsize && geom.size() != adjsize && m_geometryHints.resizeIncrements().width() > 1) { // take care of size increments
|
|
|
|
int newright = workspace()->packPositionRight(this, geom.right() + m_geometryHints.resizeIncrements().width() - 1, true);
|
2007-04-29 21:35:43 +04:00
|
|
|
// check that it hasn't grown outside of the area, due to size increments
|
|
|
|
// TODO this may be wrong?
|
2011-01-30 17:34:42 +03:00
|
|
|
if (workspace()->clientArea(MovementArea,
|
|
|
|
QPoint((x() + newright) / 2, geometry().center().y()), desktop()).right() >= newright)
|
|
|
|
geom.setRight(newright);
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
geom.setSize(adjustedSize(geom.size(), SizemodeFixedW));
|
2015-01-29 02:14:47 +03:00
|
|
|
geom.setSize(adjustedSize(geom.size(), SizemodeFixedH));
|
2015-01-29 02:14:47 +03:00
|
|
|
workspace()->updateFocusMousePosition(Cursor::pos()); // may cause leave event;
|
2011-01-30 17:34:42 +03:00
|
|
|
setGeometry(geom);
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
void Workspace::slotWindowShrinkHorizontal()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (active_client)
|
2007-04-29 21:35:43 +04:00
|
|
|
active_client->shrinkHorizontal();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
void Client::shrinkHorizontal()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (!isResizable() || isShade())
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
|
|
|
QRect geom = geometry();
|
2011-01-30 17:34:42 +03:00
|
|
|
geom.setRight(workspace()->packPositionLeft(this, geom.right(), false));
|
|
|
|
if (geom.width() <= 1)
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
2011-01-30 17:34:42 +03:00
|
|
|
geom.setSize(adjustedSize(geom.size(), SizemodeFixedW));
|
2015-01-29 02:14:47 +03:00
|
|
|
if (geom.width() > 20) {
|
2015-01-29 02:14:47 +03:00
|
|
|
workspace()->updateFocusMousePosition(Cursor::pos()); // may cause leave event;
|
2011-01-30 17:34:42 +03:00
|
|
|
setGeometry(geom);
|
2015-01-29 02:14:47 +03:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
void Workspace::slotWindowGrowVertical()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (active_client)
|
2007-04-29 21:35:43 +04:00
|
|
|
active_client->growVertical();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
void Client::growVertical()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (!isResizable() || isShade())
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
|
|
|
QRect geom = geometry();
|
2011-01-30 17:34:42 +03:00
|
|
|
geom.setBottom(workspace()->packPositionDown(this, geom.bottom(), true));
|
|
|
|
QSize adjsize = adjustedSize(geom.size(), SizemodeFixedH);
|
2015-01-21 18:05:29 +03:00
|
|
|
if (geometry().size() == adjsize && geom.size() != adjsize && m_geometryHints.resizeIncrements().height() > 1) { // take care of size increments
|
|
|
|
int newbottom = workspace()->packPositionDown(this, geom.bottom() + m_geometryHints.resizeIncrements().height() - 1, true);
|
2007-04-29 21:35:43 +04:00
|
|
|
// check that it hasn't grown outside of the area, due to size increments
|
2011-01-30 17:34:42 +03:00
|
|
|
if (workspace()->clientArea(MovementArea,
|
|
|
|
QPoint(geometry().center().x(), (y() + newbottom) / 2), desktop()).bottom() >= newbottom)
|
|
|
|
geom.setBottom(newbottom);
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
geom.setSize(adjustedSize(geom.size(), SizemodeFixedH));
|
2015-01-29 02:14:47 +03:00
|
|
|
workspace()->updateFocusMousePosition(Cursor::pos()); // may cause leave event;
|
2011-01-30 17:34:42 +03:00
|
|
|
setGeometry(geom);
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
|
|
|
|
void Workspace::slotWindowShrinkVertical()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (active_client)
|
2007-04-29 21:35:43 +04:00
|
|
|
active_client->shrinkVertical();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
void Client::shrinkVertical()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (!isResizable() || isShade())
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
|
|
|
QRect geom = geometry();
|
2011-01-30 17:34:42 +03:00
|
|
|
geom.setBottom(workspace()->packPositionUp(this, geom.bottom(), false));
|
|
|
|
if (geom.height() <= 1)
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
2011-01-30 17:34:42 +03:00
|
|
|
geom.setSize(adjustedSize(geom.size(), SizemodeFixedH));
|
2015-01-29 02:14:47 +03:00
|
|
|
if (geom.height() > 20) {
|
2015-01-29 02:14:47 +03:00
|
|
|
workspace()->updateFocusMousePosition(Cursor::pos()); // may cause leave event;
|
2011-01-30 17:34:42 +03:00
|
|
|
setGeometry(geom);
|
2015-01-29 02:14:47 +03:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2009-09-13 21:09:44 +04:00
|
|
|
|
|
|
|
void Workspace::slotWindowQuickTileLeft()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (!active_client)
|
|
|
|
return;
|
2009-09-13 21:09:44 +04:00
|
|
|
|
2014-12-02 12:52:16 +03:00
|
|
|
active_client->setQuickTileMode(Client::QuickTileLeft, true);
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2009-09-13 21:09:44 +04:00
|
|
|
|
|
|
|
void Workspace::slotWindowQuickTileRight()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (!active_client)
|
|
|
|
return;
|
2009-09-13 21:09:44 +04:00
|
|
|
|
2014-12-02 12:52:16 +03:00
|
|
|
active_client->setQuickTileMode(Client::QuickTileRight, true);
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2009-09-13 21:09:44 +04:00
|
|
|
|
2015-03-31 12:09:57 +03:00
|
|
|
void Workspace::slotWindowQuickTileTop()
|
|
|
|
{
|
|
|
|
if (!active_client)
|
|
|
|
return;
|
|
|
|
|
|
|
|
active_client->setQuickTileMode(Client::QuickTileTop, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::slotWindowQuickTileBottom()
|
|
|
|
{
|
|
|
|
if (!active_client)
|
|
|
|
return;
|
|
|
|
|
|
|
|
active_client->setQuickTileMode(Client::QuickTileBottom, true);
|
|
|
|
}
|
|
|
|
|
2011-02-07 21:19:51 +03:00
|
|
|
void Workspace::slotWindowQuickTileTopLeft()
|
|
|
|
{
|
|
|
|
if (!active_client) {
|
|
|
|
return;
|
|
|
|
}
|
2014-12-02 12:52:16 +03:00
|
|
|
active_client->setQuickTileMode(Client::QuickTileTop|Client::QuickTileLeft, true);
|
2011-02-07 21:19:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::slotWindowQuickTileTopRight()
|
|
|
|
{
|
|
|
|
if (!active_client) {
|
|
|
|
return;
|
|
|
|
}
|
2014-12-02 12:52:16 +03:00
|
|
|
active_client->setQuickTileMode(Client::QuickTileTop|Client::QuickTileRight, true);
|
2011-02-07 21:19:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::slotWindowQuickTileBottomLeft()
|
|
|
|
{
|
|
|
|
if (!active_client) {
|
|
|
|
return;
|
|
|
|
}
|
2014-12-02 12:52:16 +03:00
|
|
|
active_client->setQuickTileMode(Client::QuickTileBottom|Client::QuickTileLeft, true);
|
2011-02-07 21:19:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::slotWindowQuickTileBottomRight()
|
|
|
|
{
|
|
|
|
if (!active_client) {
|
|
|
|
return;
|
|
|
|
}
|
2014-12-02 12:52:16 +03:00
|
|
|
active_client->setQuickTileMode(Client::QuickTileBottom|Client::QuickTileRight, true);
|
2011-02-07 21:19:51 +03:00
|
|
|
}
|
|
|
|
|
2015-03-12 12:55:14 +03:00
|
|
|
int Workspace::packPositionLeft(const AbstractClient* cl, int oldx, bool left_edge) const
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2013-07-19 18:28:05 +04:00
|
|
|
int newx = clientArea(MaximizeArea, cl).left();
|
2011-01-30 17:34:42 +03:00
|
|
|
if (oldx <= newx) // try another Xinerama screen
|
2013-07-19 18:28:05 +04:00
|
|
|
newx = clientArea(MaximizeArea,
|
2011-01-30 17:34:42 +03:00
|
|
|
QPoint(cl->geometry().left() - 1, cl->geometry().center().y()), cl->desktop()).left();
|
2014-12-02 13:12:20 +03:00
|
|
|
if (cl->titlebarPosition() != Client::PositionLeft) {
|
2013-09-16 18:26:21 +04:00
|
|
|
QRect geo = cl->geometry();
|
|
|
|
int rgt = newx - cl->clientPos().x();
|
|
|
|
geo.moveRight(rgt);
|
|
|
|
if (screens()->intersecting(geo) < 2)
|
|
|
|
newx = rgt;
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
if (oldx <= newx)
|
2007-04-29 21:35:43 +04:00
|
|
|
return oldx;
|
2015-02-04 00:59:07 +03:00
|
|
|
const int desktop = cl->desktop() == 0 || cl->isOnAllDesktops() ? VirtualDesktopManager::self()->current() : cl->desktop();
|
2013-07-19 18:28:05 +04:00
|
|
|
for (ClientList::ConstIterator it = clients.constBegin(), end = clients.constEnd(); it != end; ++it) {
|
2015-02-04 00:59:07 +03:00
|
|
|
if (isIrrelevant(*it, cl, desktop))
|
2007-04-29 21:35:43 +04:00
|
|
|
continue;
|
|
|
|
int x = left_edge ? (*it)->geometry().right() + 1 : (*it)->geometry().left() - 1;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (x > newx && x < oldx
|
|
|
|
&& !(cl->geometry().top() > (*it)->geometry().bottom() // they overlap in Y direction
|
|
|
|
|| cl->geometry().bottom() < (*it)->geometry().top()))
|
2007-04-29 21:35:43 +04:00
|
|
|
newx = x;
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
return newx;
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2015-03-12 12:55:14 +03:00
|
|
|
int Workspace::packPositionRight(const AbstractClient* cl, int oldx, bool right_edge) const
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2013-07-19 18:28:05 +04:00
|
|
|
int newx = clientArea(MaximizeArea, cl).right();
|
2011-01-30 17:34:42 +03:00
|
|
|
if (oldx >= newx) // try another Xinerama screen
|
2013-07-19 18:28:05 +04:00
|
|
|
newx = clientArea(MaximizeArea,
|
2011-01-30 17:34:42 +03:00
|
|
|
QPoint(cl->geometry().right() + 1, cl->geometry().center().y()), cl->desktop()).right();
|
2014-12-02 13:12:20 +03:00
|
|
|
if (cl->titlebarPosition() != Client::PositionRight) {
|
2013-09-16 18:26:21 +04:00
|
|
|
QRect geo = cl->geometry();
|
|
|
|
int rgt = newx + cl->width() - (cl->clientSize().width() + cl->clientPos().x());
|
|
|
|
geo.moveRight(rgt);
|
|
|
|
if (screens()->intersecting(geo) < 2)
|
|
|
|
newx = rgt;
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
if (oldx >= newx)
|
2007-04-29 21:35:43 +04:00
|
|
|
return oldx;
|
2015-02-04 00:59:07 +03:00
|
|
|
const int desktop = cl->desktop() == 0 || cl->isOnAllDesktops() ? VirtualDesktopManager::self()->current() : cl->desktop();
|
2013-07-19 18:28:05 +04:00
|
|
|
for (ClientList::ConstIterator it = clients.constBegin(), end = clients.constEnd(); it != end; ++it) {
|
2015-02-04 00:59:07 +03:00
|
|
|
if (isIrrelevant(*it, cl, desktop))
|
2007-04-29 21:35:43 +04:00
|
|
|
continue;
|
|
|
|
int x = right_edge ? (*it)->geometry().left() - 1 : (*it)->geometry().right() + 1;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (x < newx && x > oldx
|
|
|
|
&& !(cl->geometry().top() > (*it)->geometry().bottom()
|
|
|
|
|| cl->geometry().bottom() < (*it)->geometry().top()))
|
2007-04-29 21:35:43 +04:00
|
|
|
newx = x;
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
return newx;
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2015-03-12 12:55:14 +03:00
|
|
|
int Workspace::packPositionUp(const AbstractClient* cl, int oldy, bool top_edge) const
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2013-07-19 18:28:05 +04:00
|
|
|
int newy = clientArea(MaximizeArea, cl).top();
|
2011-01-30 17:34:42 +03:00
|
|
|
if (oldy <= newy) // try another Xinerama screen
|
2013-07-19 18:28:05 +04:00
|
|
|
newy = clientArea(MaximizeArea,
|
2011-01-30 17:34:42 +03:00
|
|
|
QPoint(cl->geometry().center().x(), cl->geometry().top() - 1), cl->desktop()).top();
|
2014-12-02 13:12:20 +03:00
|
|
|
if (cl->titlebarPosition() != Client::PositionTop) {
|
2013-09-16 18:26:21 +04:00
|
|
|
QRect geo = cl->geometry();
|
|
|
|
int top = newy - cl->clientPos().y();
|
|
|
|
geo.moveTop(top);
|
|
|
|
if (screens()->intersecting(geo) < 2)
|
|
|
|
newy = top;
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
if (oldy <= newy)
|
2007-04-29 21:35:43 +04:00
|
|
|
return oldy;
|
2015-02-04 00:59:07 +03:00
|
|
|
const int desktop = cl->desktop() == 0 || cl->isOnAllDesktops() ? VirtualDesktopManager::self()->current() : cl->desktop();
|
2013-07-19 18:28:05 +04:00
|
|
|
for (ClientList::ConstIterator it = clients.constBegin(), end = clients.constEnd(); it != end; ++it) {
|
2015-02-04 00:59:07 +03:00
|
|
|
if (isIrrelevant(*it, cl, desktop))
|
2007-04-29 21:35:43 +04:00
|
|
|
continue;
|
|
|
|
int y = top_edge ? (*it)->geometry().bottom() + 1 : (*it)->geometry().top() - 1;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (y > newy && y < oldy
|
|
|
|
&& !(cl->geometry().left() > (*it)->geometry().right() // they overlap in X direction
|
|
|
|
|| cl->geometry().right() < (*it)->geometry().left()))
|
2007-04-29 21:35:43 +04:00
|
|
|
newy = y;
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
return newy;
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2015-03-12 12:55:14 +03:00
|
|
|
int Workspace::packPositionDown(const AbstractClient* cl, int oldy, bool bottom_edge) const
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2013-07-19 18:28:05 +04:00
|
|
|
int newy = clientArea(MaximizeArea, cl).bottom();
|
2011-01-30 17:34:42 +03:00
|
|
|
if (oldy >= newy) // try another Xinerama screen
|
2013-07-19 18:28:05 +04:00
|
|
|
newy = clientArea(MaximizeArea,
|
2011-01-30 17:34:42 +03:00
|
|
|
QPoint(cl->geometry().center().x(), cl->geometry().bottom() + 1), cl->desktop()).bottom();
|
2014-12-02 13:12:20 +03:00
|
|
|
if (cl->titlebarPosition() != Client::PositionBottom) {
|
2013-09-16 18:26:21 +04:00
|
|
|
QRect geo = cl->geometry();
|
|
|
|
int btm = newy + cl->height() - (cl->clientSize().height() + cl->clientPos().y());
|
|
|
|
geo.moveBottom(btm);
|
|
|
|
if (screens()->intersecting(geo) < 2)
|
|
|
|
newy = btm;
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
if (oldy >= newy)
|
2007-04-29 21:35:43 +04:00
|
|
|
return oldy;
|
2015-02-04 00:59:07 +03:00
|
|
|
const int desktop = cl->desktop() == 0 || cl->isOnAllDesktops() ? VirtualDesktopManager::self()->current() : cl->desktop();
|
2013-07-19 18:28:05 +04:00
|
|
|
for (ClientList::ConstIterator it = clients.constBegin(), end = clients.constEnd(); it != end; ++it) {
|
2015-02-04 00:59:07 +03:00
|
|
|
if (isIrrelevant(*it, cl, desktop))
|
2007-04-29 21:35:43 +04:00
|
|
|
continue;
|
|
|
|
int y = bottom_edge ? (*it)->geometry().top() - 1 : (*it)->geometry().bottom() + 1;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (y < newy && y > oldy
|
|
|
|
&& !(cl->geometry().left() > (*it)->geometry().right()
|
|
|
|
|| cl->geometry().right() < (*it)->geometry().left()))
|
2007-04-29 21:35:43 +04:00
|
|
|
newy = y;
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
return newy;
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} // namespace
|