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) 2003 Lubos Lunak <l.lunak@kde.org>
|
2009-02-17 18:50:00 +03:00
|
|
|
Copyright (C) 2009 Lucas Murray <lmurray@undefinedfire.com>
|
2007-04-29 21:35:43 +04:00
|
|
|
|
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
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
This file contains things relevant to geometry, i.e. workspace size,
|
|
|
|
window positions and window sizes.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "client.h"
|
2011-08-21 23:50:23 +04:00
|
|
|
#include "composite.h"
|
2013-02-19 20:30:59 +04:00
|
|
|
#include "cursor.h"
|
2013-04-26 12:41:24 +04:00
|
|
|
#include "netinfo.h"
|
2007-04-29 21:35:43 +04:00
|
|
|
#include "workspace.h"
|
|
|
|
|
|
|
|
#include "placement.h"
|
|
|
|
#include "geometrytip.h"
|
|
|
|
#include "rules.h"
|
2013-04-03 14:19:27 +04:00
|
|
|
#include "screens.h"
|
2007-04-29 21:35:43 +04:00
|
|
|
#include "effects.h"
|
2013-01-21 12:04:06 +04:00
|
|
|
#ifdef KWIN_BUILD_SCREENEDGES
|
|
|
|
#include "screenedge.h"
|
|
|
|
#endif
|
2013-09-06 17:32:55 +04:00
|
|
|
#include <QApplication>
|
2013-09-02 15:14:39 +04:00
|
|
|
#include <QDebug>
|
2013-02-26 12:00:51 +04:00
|
|
|
#include <QDesktopWidget>
|
2010-01-03 20:26:27 +03:00
|
|
|
#include <QVarLengthArray>
|
2008-11-15 06:04:44 +03:00
|
|
|
|
2011-04-28 13:16:27 +04:00
|
|
|
#include "outline.h"
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2013-07-18 18:22:34 +04:00
|
|
|
static inline int sign(int v) {
|
|
|
|
return (v > 0) - (v < 0);
|
|
|
|
}
|
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
//********************************************
|
|
|
|
// Workspace
|
|
|
|
//********************************************
|
|
|
|
|
2011-05-08 22:39:27 +04:00
|
|
|
extern int screen_number;
|
|
|
|
extern bool is_multihead;
|
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
/*!
|
|
|
|
Resizes the workspace after an XRANDR screen size change
|
|
|
|
*/
|
|
|
|
void Workspace::desktopResized()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2012-03-27 21:14:53 +04:00
|
|
|
QRect geom;
|
2013-04-03 14:19:27 +04:00
|
|
|
for (int i = 0; i < screens()->count(); i++) {
|
2012-08-11 23:32:27 +04:00
|
|
|
//do NOT use - QApplication::desktop()->screenGeometry(i) there could be a virtual geometry
|
|
|
|
// see bug #302783
|
|
|
|
geom |= QApplication::desktop()->screen(i)->geometry();
|
2012-03-27 21:14:53 +04:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
NETSize desktop_geometry;
|
|
|
|
desktop_geometry.width = geom.width();
|
|
|
|
desktop_geometry.height = geom.height();
|
2013-04-29 14:17:42 +04:00
|
|
|
rootInfo()->setDesktopGeometry(-1, desktop_geometry);
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
updateClientArea();
|
2011-09-30 15:22:39 +04:00
|
|
|
saveOldScreenSizes(); // after updateClientArea(), so that one still uses the previous one
|
2013-01-21 12:04:06 +04:00
|
|
|
|
|
|
|
// TODO: emit a signal instead and remove the deep function calls into edges and effects
|
2011-07-07 20:29:11 +04:00
|
|
|
#ifdef KWIN_BUILD_SCREENEDGES
|
2013-01-25 13:15:00 +04:00
|
|
|
ScreenEdges::self()->recreateEdges();
|
2011-07-07 20:29:11 +04:00
|
|
|
#endif
|
2013-01-21 12:04:06 +04:00
|
|
|
|
2011-11-26 19:15:46 +04:00
|
|
|
if (effects) {
|
|
|
|
static_cast<EffectsHandlerImpl*>(effects)->desktopResized(geom.size());
|
|
|
|
}
|
2013-03-20 10:10:34 +04:00
|
|
|
|
|
|
|
//Update the shape of the overlay window to fix redrawing of unredirected windows. bug#305781
|
|
|
|
m_compositor->checkUnredirect(true);
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-09-30 15:22:39 +04:00
|
|
|
void Workspace::saveOldScreenSizes()
|
|
|
|
{
|
2011-09-30 16:50:18 +04:00
|
|
|
olddisplaysize = QSize( displayWidth(), displayHeight());
|
2011-09-30 15:22:39 +04:00
|
|
|
oldscreensizes.clear();
|
|
|
|
for( int i = 0;
|
2013-04-03 14:19:27 +04:00
|
|
|
i < screens()->count();
|
2011-09-30 15:22:39 +04:00
|
|
|
++i )
|
2013-04-03 14:19:27 +04:00
|
|
|
oldscreensizes.append( screens()->geometry( i ));
|
2011-09-30 15:22:39 +04:00
|
|
|
}
|
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
/*!
|
|
|
|
Updates the current client areas according to the current clients.
|
|
|
|
|
|
|
|
If the area changes or force is true, the new areas are propagated to the world.
|
|
|
|
|
|
|
|
The client area is the area that is available for clients (that
|
|
|
|
which is not taken by windows like panels, the top-of-screen menu
|
|
|
|
etc).
|
|
|
|
|
|
|
|
\sa clientArea()
|
|
|
|
*/
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
void Workspace::updateClientArea(bool force)
|
|
|
|
{
|
2013-04-03 14:19:27 +04:00
|
|
|
const Screens *s = Screens::self();
|
|
|
|
int nscreens = s->count();
|
2012-11-16 11:23:47 +04:00
|
|
|
const int numberOfDesktops = VirtualDesktopManager::self()->count();
|
2013-09-02 15:14:39 +04:00
|
|
|
qDebug() << "screens: " << nscreens << "desktops: " << numberOfDesktops;
|
2012-11-16 11:23:47 +04:00
|
|
|
QVector< QRect > new_wareas(numberOfDesktops + 1);
|
|
|
|
QVector< StrutRects > new_rmoveareas(numberOfDesktops + 1);
|
|
|
|
QVector< QVector< QRect > > new_sareas(numberOfDesktops + 1);
|
2011-01-30 17:34:42 +03:00
|
|
|
QVector< QRect > screens(nscreens);
|
2012-03-27 21:14:53 +04:00
|
|
|
QRect desktopArea;
|
2013-04-03 14:19:27 +04:00
|
|
|
for (int i = 0; i < nscreens; i++) {
|
|
|
|
desktopArea |= s->geometry(i);
|
2012-03-27 21:14:53 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
for (int iS = 0;
|
2007-04-29 21:35:43 +04:00
|
|
|
iS < nscreens;
|
2011-01-30 17:34:42 +03:00
|
|
|
iS ++) {
|
2013-04-03 14:19:27 +04:00
|
|
|
screens [iS] = s->geometry(iS);
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
for (int i = 1;
|
2012-11-16 11:23:47 +04:00
|
|
|
i <= numberOfDesktops;
|
2011-01-30 17:34:42 +03:00
|
|
|
++i) {
|
2008-07-29 17:44:08 +04:00
|
|
|
new_wareas[ i ] = desktopArea;
|
2011-01-30 17:34:42 +03:00
|
|
|
new_sareas[ i ].resize(nscreens);
|
|
|
|
for (int iS = 0;
|
|
|
|
iS < nscreens;
|
|
|
|
iS ++)
|
2008-07-29 17:44:08 +04:00
|
|
|
new_sareas[ i ][ iS ] = screens[ iS ];
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
for (ClientList::ConstIterator it = clients.constBegin(); it != clients.constEnd(); ++it) {
|
|
|
|
if (!(*it)->hasStrut())
|
2008-07-29 17:44:08 +04:00
|
|
|
continue;
|
2011-01-30 17:34:42 +03:00
|
|
|
QRect r = (*it)->adjustedClientArea(desktopArea, desktopArea);
|
2009-02-17 18:50:00 +03:00
|
|
|
StrutRects strutRegion = (*it)->strutRects();
|
2009-02-15 19:37:42 +03:00
|
|
|
|
|
|
|
// Ignore offscreen xinerama struts. These interfere with the larger monitors on the setup
|
|
|
|
// and should be ignored so that applications that use the work area to work out where
|
|
|
|
// windows can go can use the entire visible area of the larger monitors.
|
|
|
|
// This goes against the EWMH description of the work area but it is a toss up between
|
|
|
|
// having unusable sections of the screen (Which can be quite large with newer monitors)
|
|
|
|
// or having some content appear offscreen (Relatively rare compared to other).
|
|
|
|
bool hasOffscreenXineramaStrut = (*it)->hasOffscreenXineramaStrut();
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
if ((*it)->isOnAllDesktops()) {
|
|
|
|
for (int i = 1;
|
2012-11-16 11:23:47 +04:00
|
|
|
i <= numberOfDesktops;
|
2011-01-30 17:34:42 +03:00
|
|
|
++i) {
|
|
|
|
if (!hasOffscreenXineramaStrut)
|
|
|
|
new_wareas[ i ] = new_wareas[ i ].intersected(r);
|
2009-02-17 18:50:00 +03:00
|
|
|
new_rmoveareas[ i ] += strutRegion;
|
2011-01-30 17:34:42 +03:00
|
|
|
for (int iS = 0;
|
|
|
|
iS < nscreens;
|
|
|
|
iS ++) {
|
2008-07-29 17:44:08 +04:00
|
|
|
new_sareas[ i ][ iS ] = new_sareas[ i ][ iS ].intersected(
|
2011-01-30 17:34:42 +03:00
|
|
|
(*it)->adjustedClientArea(desktopArea, screens[ iS ]));
|
2008-07-29 17:44:08 +04:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
} else {
|
|
|
|
if (!hasOffscreenXineramaStrut)
|
|
|
|
new_wareas[(*it)->desktop()] = new_wareas[(*it)->desktop()].intersected(r);
|
|
|
|
new_rmoveareas[(*it)->desktop()] += strutRegion;
|
|
|
|
for (int iS = 0;
|
|
|
|
iS < nscreens;
|
|
|
|
iS ++) {
|
2013-11-01 15:29:05 +04:00
|
|
|
// qDebug() << "adjusting new_sarea: " << screens[ iS ];
|
2011-01-30 17:34:42 +03:00
|
|
|
new_sareas[(*it)->desktop()][ iS ]
|
|
|
|
= new_sareas[(*it)->desktop()][ iS ].intersected(
|
|
|
|
(*it)->adjustedClientArea(desktopArea, screens[ iS ]));
|
2008-07-29 17:44:08 +04:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
#if 0
|
2011-01-30 17:34:42 +03:00
|
|
|
for (int i = 1;
|
2007-04-29 21:35:43 +04:00
|
|
|
i <= numberOfDesktops();
|
2011-01-30 17:34:42 +03:00
|
|
|
++i) {
|
|
|
|
for (int iS = 0;
|
|
|
|
iS < nscreens;
|
|
|
|
iS ++)
|
2013-09-02 15:14:39 +04:00
|
|
|
qDebug() << "new_sarea: " << new_sareas[ i ][ iS ];
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
bool changed = force;
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
if (screenarea.isEmpty())
|
2007-04-29 21:35:43 +04:00
|
|
|
changed = true;
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
for (int i = 1;
|
2012-11-16 11:23:47 +04:00
|
|
|
!changed && i <= numberOfDesktops;
|
2011-01-30 17:34:42 +03:00
|
|
|
++i) {
|
|
|
|
if (workarea[ i ] != new_wareas[ i ])
|
2008-07-29 17:44:08 +04:00
|
|
|
changed = true;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (restrictedmovearea[ i ] != new_rmoveareas[ i ])
|
2009-02-17 18:50:00 +03:00
|
|
|
changed = true;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (screenarea[ i ].size() != new_sareas[ i ].size())
|
2008-07-29 17:44:08 +04:00
|
|
|
changed = true;
|
2011-01-30 17:34:42 +03:00
|
|
|
for (int iS = 0;
|
|
|
|
!changed && iS < nscreens;
|
|
|
|
iS ++)
|
2008-07-29 17:44:08 +04:00
|
|
|
if (new_sareas[ i ][ iS ] != screenarea [ i ][ iS ])
|
2008-07-29 17:36:55 +04:00
|
|
|
changed = true;
|
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 (changed) {
|
2007-04-29 21:35:43 +04:00
|
|
|
workarea = new_wareas;
|
2009-02-17 18:50:00 +03:00
|
|
|
oldrestrictedmovearea = restrictedmovearea;
|
|
|
|
restrictedmovearea = new_rmoveareas;
|
2007-04-29 21:35:43 +04:00
|
|
|
screenarea = new_sareas;
|
|
|
|
NETRect r;
|
2012-11-16 11:23:47 +04:00
|
|
|
for (int i = 1; i <= numberOfDesktops; i++) {
|
2007-04-29 21:35:43 +04:00
|
|
|
r.pos.x = workarea[ i ].x();
|
|
|
|
r.pos.y = workarea[ i ].y();
|
|
|
|
r.size.width = workarea[ i ].width();
|
|
|
|
r.size.height = workarea[ i ].height();
|
2013-04-29 14:17:42 +04:00
|
|
|
rootInfo()->setWorkArea(i, r);
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
for (ClientList::ConstIterator it = clients.constBegin();
|
|
|
|
it != clients.constEnd();
|
|
|
|
++it)
|
2007-04-29 21:35:43 +04:00
|
|
|
(*it)->checkWorkspacePosition();
|
2011-01-30 17:34:42 +03:00
|
|
|
for (ClientList::ConstIterator it = desktops.constBegin();
|
|
|
|
it != desktops.constEnd();
|
|
|
|
++it)
|
2007-04-29 21:35:43 +04:00
|
|
|
(*it)->checkWorkspacePosition();
|
2011-09-29 19:52:19 +04:00
|
|
|
|
2011-09-30 15:22:39 +04:00
|
|
|
oldrestrictedmovearea.clear(); // reset, no longer valid or needed
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
|
2013-09-02 15:14:39 +04:00
|
|
|
qDebug() << "Done.";
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
void Workspace::updateClientArea()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
updateClientArea(false);
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
returns the area available for clients. This is the desktop
|
|
|
|
geometry minus windows on the dock. Placement algorithms should
|
|
|
|
refer to this rather than geometry().
|
|
|
|
|
|
|
|
\sa geometry()
|
|
|
|
*/
|
2011-05-08 22:39:27 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
QRect Workspace::clientArea(clientAreaOption opt, int screen, int desktop) const
|
|
|
|
{
|
|
|
|
if (desktop == NETWinInfo::OnAllDesktops || desktop == 0)
|
2012-11-16 11:23:47 +04:00
|
|
|
desktop = VirtualDesktopManager::self()->current();
|
2011-01-30 17:34:42 +03:00
|
|
|
if (screen == -1)
|
2013-04-03 14:19:27 +04:00
|
|
|
screen = screens()->current();
|
2011-01-30 17:34:42 +03:00
|
|
|
|
2011-05-08 22:39:27 +04:00
|
|
|
QRect sarea, warea;
|
|
|
|
|
|
|
|
if (is_multihead) {
|
|
|
|
sarea = (!screenarea.isEmpty()
|
2011-01-30 17:34:42 +03:00
|
|
|
&& screen < screenarea[ desktop ].size()) // screens may be missing during KWin initialization or screen config changes
|
2011-05-08 22:39:27 +04:00
|
|
|
? screenarea[ desktop ][ screen_number ]
|
2013-04-03 14:19:27 +04:00
|
|
|
: screens()->geometry(screen_number);
|
2011-05-08 22:39:27 +04:00
|
|
|
warea = workarea[ desktop ].isNull()
|
2013-04-03 14:19:27 +04:00
|
|
|
? screens()->geometry(screen_number)
|
2011-05-08 22:39:27 +04:00
|
|
|
: workarea[ desktop ];
|
|
|
|
} else {
|
|
|
|
sarea = (!screenarea.isEmpty()
|
|
|
|
&& screen < screenarea[ desktop ].size()) // screens may be missing during KWin initialization or screen config changes
|
|
|
|
? screenarea[ desktop ][ screen ]
|
2013-04-03 14:19:27 +04:00
|
|
|
: screens()->geometry(screen);
|
2011-05-08 22:39:27 +04:00
|
|
|
warea = workarea[ desktop ].isNull()
|
2012-03-27 21:14:53 +04:00
|
|
|
? QRect(0, 0, displayWidth(), displayHeight())
|
2011-05-08 22:39:27 +04:00
|
|
|
: workarea[ desktop ];
|
|
|
|
}
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
switch(opt) {
|
|
|
|
case MaximizeArea:
|
2012-01-22 14:04:55 +04:00
|
|
|
case PlacementArea:
|
2011-01-30 17:34:42 +03:00
|
|
|
return sarea;
|
|
|
|
case MaximizeFullArea:
|
|
|
|
case FullScreenArea:
|
|
|
|
case MovementArea:
|
2012-01-22 14:04:55 +04:00
|
|
|
case ScreenArea:
|
2011-05-08 22:39:27 +04:00
|
|
|
if (is_multihead)
|
2013-04-03 14:19:27 +04:00
|
|
|
return screens()->geometry(screen_number);
|
2011-01-30 17:34:42 +03:00
|
|
|
else
|
2013-04-03 14:19:27 +04:00
|
|
|
return screens()->geometry(screen);
|
2011-01-30 17:34:42 +03:00
|
|
|
case WorkArea:
|
2011-05-08 22:39:27 +04:00
|
|
|
if (is_multihead)
|
|
|
|
return sarea;
|
|
|
|
else
|
|
|
|
return warea;
|
2011-01-30 17:34:42 +03:00
|
|
|
case FullArea:
|
2012-03-27 21:14:53 +04:00
|
|
|
return QRect(0, 0, displayWidth(), displayHeight());
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
abort();
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-05-08 22:39:27 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
QRect Workspace::clientArea(clientAreaOption opt, const QPoint& p, int desktop) const
|
|
|
|
{
|
2013-04-03 14:19:27 +04:00
|
|
|
return clientArea(opt, screens()->number(p), desktop);
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-05-07 16:18:19 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
QRect Workspace::clientArea(clientAreaOption opt, const Client* c) const
|
|
|
|
{
|
|
|
|
return clientArea(opt, c->geometry().center(), c->desktop());
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
QRegion Workspace::restrictedMoveArea(int desktop, StrutAreas areas) const
|
|
|
|
{
|
|
|
|
if (desktop == NETWinInfo::OnAllDesktops || desktop == 0)
|
2012-11-16 11:23:47 +04:00
|
|
|
desktop = VirtualDesktopManager::self()->current();
|
2009-02-17 18:50:00 +03:00
|
|
|
QRegion region;
|
2011-01-30 17:34:42 +03:00
|
|
|
foreach (const StrutRect & rect, restrictedmovearea[desktop])
|
|
|
|
if (areas & rect.area())
|
|
|
|
region += rect;
|
2009-02-17 18:50:00 +03:00
|
|
|
return region;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2009-02-17 18:50:00 +03:00
|
|
|
|
2011-09-30 15:22:39 +04:00
|
|
|
bool Workspace::inUpdateClientArea() const
|
|
|
|
{
|
|
|
|
return !oldrestrictedmovearea.isEmpty();
|
|
|
|
}
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
QRegion Workspace::previousRestrictedMoveArea(int desktop, StrutAreas areas) const
|
|
|
|
{
|
|
|
|
if (desktop == NETWinInfo::OnAllDesktops || desktop == 0)
|
2012-11-16 11:23:47 +04:00
|
|
|
desktop = VirtualDesktopManager::self()->current();
|
2009-02-17 18:50:00 +03:00
|
|
|
QRegion region;
|
2011-01-30 17:34:42 +03:00
|
|
|
foreach (const StrutRect & rect, oldrestrictedmovearea.at(desktop))
|
|
|
|
if (areas & rect.area())
|
|
|
|
region += rect;
|
2009-02-17 18:50:00 +03:00
|
|
|
return region;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-05-07 16:18:19 +04:00
|
|
|
|
2011-09-30 15:22:39 +04:00
|
|
|
QVector< QRect > Workspace::previousScreenSizes() const
|
2011-09-29 19:52:19 +04:00
|
|
|
{
|
2011-09-30 15:22:39 +04:00
|
|
|
return oldscreensizes;
|
2011-09-29 19:52:19 +04:00
|
|
|
}
|
|
|
|
|
2011-09-30 16:50:18 +04:00
|
|
|
int Workspace::oldDisplayWidth() const
|
|
|
|
{
|
|
|
|
return olddisplaysize.width();
|
|
|
|
}
|
|
|
|
|
|
|
|
int Workspace::oldDisplayHeight() const
|
|
|
|
{
|
|
|
|
return olddisplaysize.height();
|
|
|
|
}
|
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
/*!
|
|
|
|
Client \a c is moved around to position \a pos. This gives the
|
|
|
|
workspace the opportunity to interveniate and to implement
|
|
|
|
snap-to-windows functionality.
|
2009-10-05 08:06:20 +04:00
|
|
|
|
|
|
|
The parameter \a snapAdjust is a multiplier used to calculate the
|
|
|
|
effective snap zones. When 1.0, it means that the snap zones will be
|
|
|
|
used without change.
|
2007-04-29 21:35:43 +04:00
|
|
|
*/
|
2011-01-30 17:34:42 +03:00
|
|
|
QPoint Workspace::adjustClientPosition(Client* c, QPoint pos, bool unrestricted, double snapAdjust)
|
|
|
|
{
|
2013-04-10 16:57:18 +04:00
|
|
|
QSize borderSnapZone(options->borderSnapZone(), options->borderSnapZone());
|
|
|
|
QRect maxRect;
|
2013-08-16 23:21:21 +04:00
|
|
|
int guideMaximized = MaximizeRestore;
|
2013-04-10 16:57:18 +04:00
|
|
|
if (c->maximizeMode() != MaximizeRestore) {
|
2013-08-28 01:46:55 +04:00
|
|
|
maxRect = clientArea(MaximizeArea, pos + c->rect().center(), c->desktop());
|
2013-04-10 16:57:18 +04:00
|
|
|
QRect geo = c->geometry();
|
|
|
|
if (c->maximizeMode() & MaximizeHorizontal && (geo.x() == maxRect.left() || geo.right() == maxRect.right())) {
|
2013-08-16 23:21:21 +04:00
|
|
|
guideMaximized |= MaximizeHorizontal;
|
2013-04-10 16:57:18 +04:00
|
|
|
borderSnapZone.setWidth(qMax(borderSnapZone.width() + 2, maxRect.width() / 16));
|
|
|
|
}
|
|
|
|
if (c->maximizeMode() & MaximizeVertical && (geo.y() == maxRect.top() || geo.bottom() == maxRect.bottom())) {
|
2013-08-16 23:21:21 +04:00
|
|
|
guideMaximized |= MaximizeVertical;
|
2013-04-10 16:57:18 +04:00
|
|
|
borderSnapZone.setHeight(qMax(borderSnapZone.height() + 2, maxRect.height() / 16));
|
|
|
|
}
|
|
|
|
}
|
2013-02-17 04:56:01 +04:00
|
|
|
|
2013-04-10 16:57:18 +04:00
|
|
|
if (options->windowSnapZone() || !borderSnapZone.isNull() || options->centerSnapZone()) {
|
2013-02-17 04:56:01 +04:00
|
|
|
|
2012-02-20 13:25:13 +04:00
|
|
|
const bool sOWO = options->isSnapOnlyWhenOverlapping();
|
2013-08-15 13:54:46 +04:00
|
|
|
const int screen = screens()->number(pos + c->rect().center());
|
2013-04-10 16:57:18 +04:00
|
|
|
if (maxRect.isNull())
|
2013-08-15 13:54:46 +04:00
|
|
|
maxRect = clientArea(MovementArea, screen, c->desktop());
|
2007-04-29 21:35:43 +04:00
|
|
|
const int xmin = maxRect.left();
|
2011-01-30 17:34:42 +03:00
|
|
|
const int xmax = maxRect.right() + 1; //desk size
|
2007-04-29 21:35:43 +04:00
|
|
|
const int ymin = maxRect.top();
|
2011-01-30 17:34:42 +03:00
|
|
|
const int ymax = maxRect.bottom() + 1;
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
const int cx(pos.x());
|
|
|
|
const int cy(pos.y());
|
|
|
|
const int cw(c->width());
|
|
|
|
const int ch(c->height());
|
2011-01-30 17:34:42 +03:00
|
|
|
const int rx(cx + cw);
|
|
|
|
const int ry(cy + ch); //these don't change
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
int nx(cx), ny(cy); //buffers
|
|
|
|
int deltaX(xmax);
|
|
|
|
int deltaY(ymax); //minimum distance to other clients
|
|
|
|
|
|
|
|
int lx, ly, lrx, lry; //coords and size for the comparison client, l
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
// border snap
|
2013-04-10 16:57:18 +04:00
|
|
|
const int snapX = borderSnapZone.width() * snapAdjust; //snap trigger
|
|
|
|
const int snapY = borderSnapZone.height() * snapAdjust;
|
|
|
|
if (snapX || snapY) {
|
2013-08-15 13:54:46 +04:00
|
|
|
QRect geo = c->geometry();
|
2013-02-17 04:56:01 +04:00
|
|
|
const QPoint cp = c->clientPos();
|
2013-08-15 13:54:46 +04:00
|
|
|
const QSize cs = geo.size() - c->clientSize();
|
2013-02-17 04:56:01 +04:00
|
|
|
int padding[4] = { cp.x(), cs.width() - cp.x(), cp.y(), cs.height() - cp.y() };
|
|
|
|
|
2013-08-15 13:54:46 +04:00
|
|
|
// snap to titlebar / snap to window borders on inner screen edges
|
2013-02-17 04:56:01 +04:00
|
|
|
Position titlePos = c->titlebarPosition();
|
2013-08-15 13:54:46 +04:00
|
|
|
if (padding[0] && (titlePos == PositionLeft || (c->maximizeMode() & MaximizeHorizontal) ||
|
|
|
|
screens()->intersecting(geo.translated(maxRect.x() - (padding[0] + geo.x()), 0)) > 1))
|
2013-02-17 04:56:01 +04:00
|
|
|
padding[0] = 0;
|
2013-08-15 13:54:46 +04:00
|
|
|
if (padding[1] && (titlePos == PositionRight || (c->maximizeMode() & MaximizeHorizontal) ||
|
|
|
|
screens()->intersecting(geo.translated(maxRect.right() + padding[1] - geo.right(), 0)) > 1))
|
2013-02-17 04:56:01 +04:00
|
|
|
padding[1] = 0;
|
2013-08-15 13:54:46 +04:00
|
|
|
if (padding[2] && (titlePos == PositionTop || (c->maximizeMode() & MaximizeVertical) ||
|
|
|
|
screens()->intersecting(geo.translated(0, maxRect.y() - (padding[2] + geo.y()))) > 1))
|
2013-02-17 04:56:01 +04:00
|
|
|
padding[2] = 0;
|
2013-08-15 13:54:46 +04:00
|
|
|
if (padding[3] && (titlePos == PositionBottom || (c->maximizeMode() & MaximizeVertical) ||
|
|
|
|
screens()->intersecting(geo.translated(0, maxRect.bottom() + padding[3] - geo.bottom())) > 1))
|
2013-02-17 04:56:01 +04:00
|
|
|
padding[3] = 0;
|
2013-04-10 16:57:18 +04:00
|
|
|
if ((sOWO ? (cx < xmin) : true) && (qAbs(xmin - cx) < snapX)) {
|
2013-06-19 23:28:21 +04:00
|
|
|
deltaX = xmin - cx;
|
2013-02-17 04:56:01 +04:00
|
|
|
nx = xmin - padding[0];
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2013-04-10 16:57:18 +04:00
|
|
|
if ((sOWO ? (rx > xmax) : true) && (qAbs(rx - xmax) < snapX) && (qAbs(xmax - rx) < deltaX)) {
|
2013-06-19 23:28:21 +04:00
|
|
|
deltaX = rx - xmax;
|
2013-02-17 04:56:01 +04:00
|
|
|
nx = xmax - cw + padding[1];
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2013-04-10 16:57:18 +04:00
|
|
|
if ((sOWO ? (cy < ymin) : true) && (qAbs(ymin - cy) < snapY)) {
|
2013-06-19 23:28:21 +04:00
|
|
|
deltaY = ymin - cy;
|
2013-02-17 04:56:01 +04:00
|
|
|
ny = ymin - padding[2];
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2013-04-10 16:57:18 +04:00
|
|
|
if ((sOWO ? (ry > ymax) : true) && (qAbs(ry - ymax) < snapY) && (qAbs(ymax - ry) < deltaY)) {
|
2013-06-19 23:28:21 +04:00
|
|
|
deltaY = ry - ymax;
|
2013-02-17 04:56:01 +04:00
|
|
|
ny = ymax - ch + padding[3];
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
// windows snap
|
2013-04-10 16:57:18 +04:00
|
|
|
int snap = options->windowSnapZone() * snapAdjust;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (snap) {
|
2007-04-29 21:35:43 +04:00
|
|
|
QList<Client *>::ConstIterator l;
|
2011-01-30 17:34:42 +03:00
|
|
|
for (l = clients.constBegin(); l != clients.constEnd(); ++l) {
|
2013-06-19 23:17:31 +04:00
|
|
|
if ((*l) == c)
|
|
|
|
continue;
|
|
|
|
if ((*l)->isMinimized())
|
|
|
|
continue; // is minimized
|
|
|
|
if ((*l)->tabGroup() && (*l) != (*l)->tabGroup()->current())
|
|
|
|
continue; // is not active tab
|
|
|
|
if (!((*l)->isOnDesktop(c->desktop()) || c->isOnDesktop((*l)->desktop())))
|
|
|
|
continue; // wrong virtual desktop
|
|
|
|
if (!(*l)->isOnCurrentActivity())
|
|
|
|
continue; // wrong activity
|
|
|
|
if ((*l)->isDesktop() || (*l)->isSplash())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
lx = (*l)->x();
|
|
|
|
ly = (*l)->y();
|
|
|
|
lrx = lx + (*l)->width();
|
|
|
|
lry = ly + (*l)->height();
|
|
|
|
|
2013-08-16 23:21:21 +04:00
|
|
|
if (!(guideMaximized & MaximizeHorizontal) &&
|
|
|
|
(((cy <= lry) && (cy >= ly)) || ((ry >= ly) && (ry <= lry)) || ((cy <= ly) && (ry >= lry)))) {
|
2013-06-19 23:17:31 +04:00
|
|
|
if ((sOWO ? (cx < lrx) : true) && (qAbs(lrx - cx) < snap) && (qAbs(lrx - cx) < deltaX)) {
|
|
|
|
deltaX = qAbs(lrx - cx);
|
|
|
|
nx = lrx;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2013-06-19 23:17:31 +04:00
|
|
|
if ((sOWO ? (rx > lx) : true) && (qAbs(rx - lx) < snap) && (qAbs(rx - lx) < deltaX)) {
|
|
|
|
deltaX = qAbs(rx - lx);
|
|
|
|
nx = lx - cw;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2013-06-19 23:17:31 +04:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2013-08-16 23:21:21 +04:00
|
|
|
if (!(guideMaximized & MaximizeVertical) &&
|
|
|
|
(((cx <= lrx) && (cx >= lx)) || ((rx >= lx) && (rx <= lrx)) || ((cx <= lx) && (rx >= lrx)))) {
|
2013-06-19 23:17:31 +04:00
|
|
|
if ((sOWO ? (cy < lry) : true) && (qAbs(lry - cy) < snap) && (qAbs(lry - cy) < deltaY)) {
|
|
|
|
deltaY = qAbs(lry - cy);
|
|
|
|
ny = lry;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2013-06-19 23:17:31 +04:00
|
|
|
//if ( (qAbs( ry-ly ) < snap) && (qAbs( ry - ly ) < deltaY ))
|
|
|
|
if ((sOWO ? (ry > ly) : true) && (qAbs(ry - ly) < snap) && (qAbs(ry - ly) < deltaY)) {
|
|
|
|
deltaY = qAbs(ry - ly);
|
|
|
|
ny = ly - ch;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2013-06-19 23:17:31 +04:00
|
|
|
}
|
2008-07-25 14:19:28 +04:00
|
|
|
|
2013-06-19 23:17:31 +04:00
|
|
|
// Corner snapping
|
2013-08-16 23:21:21 +04:00
|
|
|
if (!(guideMaximized & MaximizeVertical) && (nx == lrx || nx + cw == lx)) {
|
2013-06-19 23:17:31 +04:00
|
|
|
if ((sOWO ? (ry > lry) : true) && (qAbs(lry - ry) < snap) && (qAbs(lry - ry) < deltaY)) {
|
|
|
|
deltaY = qAbs(lry - ry);
|
|
|
|
ny = lry - ch;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2013-06-19 23:17:31 +04:00
|
|
|
if ((sOWO ? (cy < ly) : true) && (qAbs(cy - ly) < snap) && (qAbs(cy - ly) < deltaY)) {
|
|
|
|
deltaY = qAbs(cy - ly);
|
|
|
|
ny = ly;
|
|
|
|
}
|
|
|
|
}
|
2013-08-16 23:21:21 +04:00
|
|
|
if (!(guideMaximized & MaximizeHorizontal) && (ny == lry || ny + ch == ly)) {
|
2013-06-19 23:17:31 +04:00
|
|
|
if ((sOWO ? (rx > lrx) : true) && (qAbs(lrx - rx) < snap) && (qAbs(lrx - rx) < deltaX)) {
|
|
|
|
deltaX = qAbs(lrx - rx);
|
|
|
|
nx = lrx - cw;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2013-06-19 23:17:31 +04:00
|
|
|
if ((sOWO ? (cx < lx) : true) && (qAbs(cx - lx) < snap) && (qAbs(cx - lx) < deltaX)) {
|
|
|
|
deltaX = qAbs(cx - lx);
|
|
|
|
nx = lx;
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2008-07-09 19:18:47 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
// center snap
|
2012-02-20 13:25:13 +04:00
|
|
|
snap = options->centerSnapZone() * snapAdjust; //snap trigger
|
2011-01-30 17:34:42 +03:00
|
|
|
if (snap) {
|
|
|
|
int diffX = qAbs((xmin + xmax) / 2 - (cx + cw / 2));
|
|
|
|
int diffY = qAbs((ymin + ymax) / 2 - (cy + ch / 2));
|
|
|
|
if (diffX < snap && diffY < snap && diffX < deltaX && diffY < deltaY) {
|
|
|
|
// Snap to center of screen
|
|
|
|
nx = (xmin + xmax) / 2 - cw / 2;
|
|
|
|
ny = (ymin + ymax) / 2 - ch / 2;
|
2013-04-10 16:57:18 +04:00
|
|
|
} else if (options->borderSnapZone()) {
|
2011-01-30 17:34:42 +03:00
|
|
|
// Enhance border snap
|
|
|
|
if ((nx == xmin || nx == xmax - cw) && diffY < snap && diffY < deltaY) {
|
|
|
|
// Snap to vertical center on screen edge
|
|
|
|
ny = (ymin + ymax) / 2 - ch / 2;
|
|
|
|
} else if (((unrestricted ? ny == ymin : ny <= ymin) || ny == ymax - ch) &&
|
|
|
|
diffX < snap && diffX < deltaX) {
|
|
|
|
// Snap to horizontal center on screen edge
|
|
|
|
nx = (xmin + xmax) / 2 - cw / 2;
|
2008-07-09 19:18:47 +04:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2008-07-09 19:18:47 +04:00
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
pos = QPoint(nx, ny);
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
return pos;
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
QRect Workspace::adjustClientSize(Client* c, QRect moveResizeGeom, int mode)
|
|
|
|
{
|
|
|
|
//adapted from adjustClientPosition on 29May2004
|
|
|
|
//this function is called when resizing a window and will modify
|
|
|
|
//the new dimensions to snap to other windows/borders if appropriate
|
2012-02-20 13:25:13 +04:00
|
|
|
if (options->windowSnapZone() || options->borderSnapZone()) { // || options->centerSnapZone )
|
|
|
|
const bool sOWO = options->isSnapOnlyWhenOverlapping();
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
const QRect maxRect = clientArea(MovementArea, c->rect().center(), c->desktop());
|
|
|
|
const int xmin = maxRect.left();
|
|
|
|
const int xmax = maxRect.right(); //desk size
|
|
|
|
const int ymin = maxRect.top();
|
|
|
|
const int ymax = maxRect.bottom();
|
|
|
|
|
|
|
|
const int cx(moveResizeGeom.left());
|
|
|
|
const int cy(moveResizeGeom.top());
|
|
|
|
const int rx(moveResizeGeom.right());
|
|
|
|
const int ry(moveResizeGeom.bottom());
|
|
|
|
|
|
|
|
int newcx(cx), newcy(cy); //buffers
|
|
|
|
int newrx(rx), newry(ry);
|
|
|
|
int deltaX(xmax);
|
|
|
|
int deltaY(ymax); //minimum distance to other clients
|
|
|
|
|
|
|
|
int lx, ly, lrx, lry; //coords and size for the comparison client, l
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
// border snap
|
2012-02-20 13:25:13 +04:00
|
|
|
int snap = options->borderSnapZone(); //snap trigger
|
2011-01-30 17:34:42 +03:00
|
|
|
if (snap) {
|
2007-04-29 21:35:43 +04:00
|
|
|
deltaX = int(snap);
|
|
|
|
deltaY = int(snap);
|
|
|
|
|
|
|
|
#define SNAP_BORDER_TOP \
|
2011-01-30 17:34:42 +03:00
|
|
|
if ((sOWO?(newcy<ymin):true) && (qAbs(ymin-newcy)<deltaY)) \
|
|
|
|
{ \
|
|
|
|
deltaY = qAbs(ymin-newcy); \
|
|
|
|
newcy = ymin; \
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
#define SNAP_BORDER_BOTTOM \
|
2011-01-30 17:34:42 +03:00
|
|
|
if ((sOWO?(newry>ymax):true) && (qAbs(ymax-newry)<deltaY)) \
|
|
|
|
{ \
|
|
|
|
deltaY = qAbs(ymax-newcy); \
|
|
|
|
newry = ymax; \
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
#define SNAP_BORDER_LEFT \
|
2011-01-30 17:34:42 +03:00
|
|
|
if ((sOWO?(newcx<xmin):true) && (qAbs(xmin-newcx)<deltaX)) \
|
|
|
|
{ \
|
|
|
|
deltaX = qAbs(xmin-newcx); \
|
|
|
|
newcx = xmin; \
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
#define SNAP_BORDER_RIGHT \
|
2011-01-30 17:34:42 +03:00
|
|
|
if ((sOWO?(newrx>xmax):true) && (qAbs(xmax-newrx)<deltaX)) \
|
|
|
|
{ \
|
|
|
|
deltaX = qAbs(xmax-newrx); \
|
|
|
|
newrx = xmax; \
|
|
|
|
}
|
|
|
|
switch(mode) {
|
|
|
|
case PositionBottomRight:
|
|
|
|
SNAP_BORDER_BOTTOM
|
|
|
|
SNAP_BORDER_RIGHT
|
|
|
|
break;
|
|
|
|
case PositionRight:
|
|
|
|
SNAP_BORDER_RIGHT
|
|
|
|
break;
|
|
|
|
case PositionBottom:
|
|
|
|
SNAP_BORDER_BOTTOM
|
|
|
|
break;
|
|
|
|
case PositionTopLeft:
|
|
|
|
SNAP_BORDER_TOP
|
|
|
|
SNAP_BORDER_LEFT
|
|
|
|
break;
|
|
|
|
case PositionLeft:
|
|
|
|
SNAP_BORDER_LEFT
|
|
|
|
break;
|
|
|
|
case PositionTop:
|
|
|
|
SNAP_BORDER_TOP
|
|
|
|
break;
|
|
|
|
case PositionTopRight:
|
|
|
|
SNAP_BORDER_TOP
|
|
|
|
SNAP_BORDER_RIGHT
|
|
|
|
break;
|
|
|
|
case PositionBottomLeft:
|
|
|
|
SNAP_BORDER_BOTTOM
|
|
|
|
SNAP_BORDER_LEFT
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
break;
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
// windows snap
|
2012-02-20 13:25:13 +04:00
|
|
|
snap = options->windowSnapZone();
|
2011-01-30 17:34:42 +03:00
|
|
|
if (snap) {
|
2007-04-29 21:35:43 +04:00
|
|
|
deltaX = int(snap);
|
|
|
|
deltaY = int(snap);
|
|
|
|
QList<Client *>::ConstIterator l;
|
2011-01-30 17:34:42 +03:00
|
|
|
for (l = clients.constBegin(); l != clients.constEnd(); ++l) {
|
2012-11-16 11:23:47 +04:00
|
|
|
if ((*l)->isOnDesktop(VirtualDesktopManager::self()->current()) &&
|
2011-01-30 17:34:42 +03:00
|
|
|
!(*l)->isMinimized()
|
|
|
|
&& (*l) != c) {
|
|
|
|
lx = (*l)->x() - 1;
|
|
|
|
ly = (*l)->y() - 1;
|
|
|
|
lrx = (*l)->x() + (*l)->width();
|
|
|
|
lry = (*l)->y() + (*l)->height();
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
#define WITHIN_HEIGHT ((( newcy <= lry ) && ( newcy >= ly )) || \
|
2011-01-30 17:34:42 +03:00
|
|
|
(( newry >= ly ) && ( newry <= lry )) || \
|
|
|
|
(( newcy <= ly ) && ( newry >= lry )) )
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
#define WITHIN_WIDTH ( (( cx <= lrx ) && ( cx >= lx )) || \
|
2011-01-30 17:34:42 +03:00
|
|
|
(( rx >= lx ) && ( rx <= lrx )) || \
|
|
|
|
(( cx <= lx ) && ( rx >= lrx )) )
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
#define SNAP_WINDOW_TOP if ( (sOWO?(newcy<lry):true) \
|
2011-01-30 17:34:42 +03:00
|
|
|
&& WITHIN_WIDTH \
|
|
|
|
&& (qAbs( lry - newcy ) < deltaY) ) { \
|
|
|
|
deltaY = qAbs( lry - newcy ); \
|
|
|
|
newcy=lry; \
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
#define SNAP_WINDOW_BOTTOM if ( (sOWO?(newry>ly):true) \
|
2011-01-30 17:34:42 +03:00
|
|
|
&& WITHIN_WIDTH \
|
|
|
|
&& (qAbs( ly - newry ) < deltaY) ) { \
|
|
|
|
deltaY = qAbs( ly - newry ); \
|
|
|
|
newry=ly; \
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
#define SNAP_WINDOW_LEFT if ( (sOWO?(newcx<lrx):true) \
|
2011-01-30 17:34:42 +03:00
|
|
|
&& WITHIN_HEIGHT \
|
|
|
|
&& (qAbs( lrx - newcx ) < deltaX)) { \
|
|
|
|
deltaX = qAbs( lrx - newcx ); \
|
|
|
|
newcx=lrx; \
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
#define SNAP_WINDOW_RIGHT if ( (sOWO?(newrx>lx):true) \
|
2011-01-30 17:34:42 +03:00
|
|
|
&& WITHIN_HEIGHT \
|
|
|
|
&& (qAbs( lx - newrx ) < deltaX)) \
|
|
|
|
{ \
|
|
|
|
deltaX = qAbs( lx - newrx ); \
|
|
|
|
newrx=lx; \
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2008-07-25 14:19:28 +04:00
|
|
|
#define SNAP_WINDOW_C_TOP if ( (sOWO?(newcy<ly):true) \
|
2011-01-30 17:34:42 +03:00
|
|
|
&& (newcx == lrx || newrx == lx) \
|
|
|
|
&& qAbs(ly-newcy) < deltaY ) { \
|
|
|
|
deltaY = qAbs( ly - newcy + 1 ); \
|
|
|
|
newcy = ly + 1; \
|
|
|
|
}
|
2008-07-25 14:19:28 +04:00
|
|
|
|
|
|
|
#define SNAP_WINDOW_C_BOTTOM if ( (sOWO?(newry>lry):true) \
|
2011-01-30 17:34:42 +03:00
|
|
|
&& (newcx == lrx || newrx == lx) \
|
|
|
|
&& qAbs(lry-newry) < deltaY ) { \
|
|
|
|
deltaY = qAbs( lry - newry - 1 ); \
|
|
|
|
newry = lry - 1; \
|
|
|
|
}
|
2008-07-25 14:19:28 +04:00
|
|
|
|
|
|
|
#define SNAP_WINDOW_C_LEFT if ( (sOWO?(newcx<lx):true) \
|
2011-01-30 17:34:42 +03:00
|
|
|
&& (newcy == lry || newry == ly) \
|
|
|
|
&& qAbs(lx-newcx) < deltaX ) { \
|
|
|
|
deltaX = qAbs( lx - newcx + 1 ); \
|
|
|
|
newcx = lx + 1; \
|
|
|
|
}
|
2008-07-25 14:19:28 +04:00
|
|
|
|
|
|
|
#define SNAP_WINDOW_C_RIGHT if ( (sOWO?(newrx>lrx):true) \
|
2011-01-30 17:34:42 +03:00
|
|
|
&& (newcy == lry || newry == ly) \
|
|
|
|
&& qAbs(lrx-newrx) < deltaX ) { \
|
|
|
|
deltaX = qAbs( lrx - newrx - 1 ); \
|
|
|
|
newrx = lrx - 1; \
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(mode) {
|
|
|
|
case PositionBottomRight:
|
2007-04-29 21:35:43 +04:00
|
|
|
SNAP_WINDOW_BOTTOM
|
|
|
|
SNAP_WINDOW_RIGHT
|
2008-07-25 14:19:28 +04:00
|
|
|
SNAP_WINDOW_C_BOTTOM
|
|
|
|
SNAP_WINDOW_C_RIGHT
|
2007-04-29 21:35:43 +04:00
|
|
|
break;
|
2011-01-30 17:34:42 +03:00
|
|
|
case PositionRight:
|
2007-04-29 21:35:43 +04:00
|
|
|
SNAP_WINDOW_RIGHT
|
2008-07-25 14:19:28 +04:00
|
|
|
SNAP_WINDOW_C_RIGHT
|
2007-04-29 21:35:43 +04:00
|
|
|
break;
|
2011-01-30 17:34:42 +03:00
|
|
|
case PositionBottom:
|
2007-04-29 21:35:43 +04:00
|
|
|
SNAP_WINDOW_BOTTOM
|
2008-07-25 14:19:28 +04:00
|
|
|
SNAP_WINDOW_C_BOTTOM
|
2007-04-29 21:35:43 +04:00
|
|
|
break;
|
2011-01-30 17:34:42 +03:00
|
|
|
case PositionTopLeft:
|
2007-04-29 21:35:43 +04:00
|
|
|
SNAP_WINDOW_TOP
|
|
|
|
SNAP_WINDOW_LEFT
|
2008-07-25 14:19:28 +04:00
|
|
|
SNAP_WINDOW_C_TOP
|
|
|
|
SNAP_WINDOW_C_LEFT
|
2007-04-29 21:35:43 +04:00
|
|
|
break;
|
2011-01-30 17:34:42 +03:00
|
|
|
case PositionLeft:
|
2007-04-29 21:35:43 +04:00
|
|
|
SNAP_WINDOW_LEFT
|
2008-07-25 14:19:28 +04:00
|
|
|
SNAP_WINDOW_C_LEFT
|
2007-04-29 21:35:43 +04:00
|
|
|
break;
|
2011-01-30 17:34:42 +03:00
|
|
|
case PositionTop:
|
2007-04-29 21:35:43 +04:00
|
|
|
SNAP_WINDOW_TOP
|
2008-07-25 14:19:28 +04:00
|
|
|
SNAP_WINDOW_C_TOP
|
2007-04-29 21:35:43 +04:00
|
|
|
break;
|
2011-01-30 17:34:42 +03:00
|
|
|
case PositionTopRight:
|
2007-04-29 21:35:43 +04:00
|
|
|
SNAP_WINDOW_TOP
|
|
|
|
SNAP_WINDOW_RIGHT
|
2008-07-25 14:19:28 +04:00
|
|
|
SNAP_WINDOW_C_TOP
|
|
|
|
SNAP_WINDOW_C_RIGHT
|
2007-04-29 21:35:43 +04:00
|
|
|
break;
|
2011-01-30 17:34:42 +03:00
|
|
|
case PositionBottomLeft:
|
2007-04-29 21:35:43 +04:00
|
|
|
SNAP_WINDOW_BOTTOM
|
|
|
|
SNAP_WINDOW_LEFT
|
2008-07-25 14:19:28 +04:00
|
|
|
SNAP_WINDOW_C_BOTTOM
|
|
|
|
SNAP_WINDOW_C_LEFT
|
2007-04-29 21:35:43 +04:00
|
|
|
break;
|
2011-01-30 17:34:42 +03:00
|
|
|
default:
|
2008-09-17 15:44:51 +04:00
|
|
|
abort();
|
2007-04-29 21:35:43 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2008-07-09 19:18:47 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
// center snap
|
2008-07-09 19:18:47 +04:00
|
|
|
//snap = options->centerSnapZone;
|
|
|
|
//if (snap)
|
|
|
|
// {
|
|
|
|
// // Don't resize snap to center as it interferes too much
|
|
|
|
// // There are two ways of implementing this if wanted:
|
|
|
|
// // 1) Snap only to the same points that the move snap does, and
|
|
|
|
// // 2) Snap to the horizontal and vertical center lines of the screen
|
|
|
|
// }
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
moveResizeGeom = QRect(QPoint(newcx, newcy), QPoint(newrx, newry));
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
return moveResizeGeom;
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Marks the client as being moved around by the user.
|
|
|
|
*/
|
2011-01-30 17:34:42 +03:00
|
|
|
void Workspace::setClientIsMoving(Client *c)
|
|
|
|
{
|
2007-04-29 21:35:43 +04:00
|
|
|
Q_ASSERT(!c || !movingClient); // Catch attempts to move a second
|
|
|
|
// window while still moving the first one.
|
|
|
|
movingClient = c;
|
|
|
|
if (movingClient)
|
|
|
|
++block_focus;
|
|
|
|
else
|
|
|
|
--block_focus;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2009-02-12 13:01:40 +03:00
|
|
|
// When kwin crashes, windows will not be gravitated back to their original position
|
|
|
|
// and will remain offset by the size of the decoration. So when restarting, fix this
|
|
|
|
// (the property with the size of the frame remains on the window after the crash).
|
2012-03-26 19:30:34 +04:00
|
|
|
void Workspace::fixPositionAfterCrash(xcb_window_t w, const xcb_get_geometry_reply_t *geometry)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
NETWinInfo i(display(), w, rootWindow(), NET::WMFrameExtents);
|
2009-02-12 13:01:40 +03:00
|
|
|
NETStrut frame = i.frameExtents();
|
2012-03-26 19:30:34 +04:00
|
|
|
|
|
|
|
if (frame.left != 0 || frame.top != 0) {
|
2012-11-26 14:04:30 +04:00
|
|
|
// left and top needed due to narrowing conversations restrictions in C++11
|
|
|
|
const uint32_t left = frame.left;
|
|
|
|
const uint32_t top = frame.top;
|
|
|
|
const uint32_t values[] = { geometry->x - left, geometry->y - top };
|
2012-03-26 19:30:34 +04:00
|
|
|
xcb_configure_window(connection(), w, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, values);
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2009-02-12 13:01:40 +03:00
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
//********************************************
|
|
|
|
// Client
|
|
|
|
//********************************************
|
|
|
|
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
void Client::keepInArea(QRect area, bool partial)
|
|
|
|
{
|
|
|
|
if (partial) {
|
2007-04-29 21:35:43 +04:00
|
|
|
// increase the area so that can have only 100 pixels in the area
|
2011-01-30 17:34:42 +03:00
|
|
|
area.setLeft(qMin(area.left() - width() + 100, area.left()));
|
|
|
|
area.setTop(qMin(area.top() - height() + 100, area.top()));
|
|
|
|
area.setRight(qMax(area.right() + width() - 100, area.right()));
|
|
|
|
area.setBottom(qMax(area.bottom() + height() - 100, area.bottom()));
|
|
|
|
}
|
|
|
|
if (!partial) {
|
|
|
|
// resize to fit into area
|
|
|
|
if (area.width() < width() || area.height() < height())
|
|
|
|
resizeWithChecks(qMin(area.width(), width()), qMin(area.height(), height()));
|
|
|
|
}
|
2013-09-12 00:50:32 +04:00
|
|
|
int tx = x(), ty = y();
|
2013-03-20 23:19:35 +04:00
|
|
|
if (geometry().right() > area.right() && width() <= area.width())
|
2013-09-12 00:50:32 +04:00
|
|
|
tx = area.right() - width() + 1;
|
2013-03-20 23:19:35 +04:00
|
|
|
if (geometry().bottom() > area.bottom() && height() <= area.height())
|
2013-09-12 00:50:32 +04:00
|
|
|
ty = area.bottom() - height() + 1;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (!area.contains(geometry().topLeft())) {
|
|
|
|
if (tx < area.x())
|
2007-04-29 21:35:43 +04:00
|
|
|
tx = area.x();
|
2011-01-30 17:34:42 +03:00
|
|
|
if (ty < area.y())
|
2007-04-29 21:35:43 +04:00
|
|
|
ty = area.y();
|
|
|
|
}
|
2013-09-12 00:50:32 +04:00
|
|
|
if (tx != x() || ty != y())
|
|
|
|
move(tx, ty);
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Returns \a area with the client's strut taken into account.
|
|
|
|
|
|
|
|
Used from Workspace in updateClientArea.
|
|
|
|
*/
|
|
|
|
// TODO move to Workspace?
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
QRect Client::adjustedClientArea(const QRect &desktopArea, const QRect& area) const
|
|
|
|
{
|
2007-04-29 21:35:43 +04:00
|
|
|
QRect r = area;
|
|
|
|
NETExtendedStrut str = strut();
|
|
|
|
QRect stareaL = QRect(
|
2011-01-30 17:34:42 +03:00
|
|
|
0,
|
|
|
|
str . left_start,
|
|
|
|
str . left_width,
|
|
|
|
str . left_end - str . left_start + 1);
|
|
|
|
QRect stareaR = QRect(
|
|
|
|
desktopArea . right() - str . right_width + 1,
|
|
|
|
str . right_start,
|
|
|
|
str . right_width,
|
|
|
|
str . right_end - str . right_start + 1);
|
|
|
|
QRect stareaT = QRect(
|
|
|
|
str . top_start,
|
|
|
|
0,
|
|
|
|
str . top_end - str . top_start + 1,
|
|
|
|
str . top_width);
|
|
|
|
QRect stareaB = QRect(
|
|
|
|
str . bottom_start,
|
|
|
|
desktopArea . bottom() - str . bottom_width + 1,
|
|
|
|
str . bottom_end - str . bottom_start + 1,
|
|
|
|
str . bottom_width);
|
|
|
|
|
|
|
|
QRect screenarea = workspace()->clientArea(ScreenArea, this);
|
2007-04-29 21:35:43 +04:00
|
|
|
// HACK: workarea handling is not xinerama aware, so if this strut
|
|
|
|
// reserves place at a xinerama edge that's inside the virtual screen,
|
|
|
|
// ignore the strut for workspace setting.
|
2012-03-27 21:14:53 +04:00
|
|
|
if (area == QRect(0, 0, displayWidth(), displayHeight())) {
|
2011-01-30 17:34:42 +03:00
|
|
|
if (stareaL.left() < screenarea.left())
|
2007-04-29 21:35:43 +04:00
|
|
|
stareaL = QRect();
|
2011-01-30 17:34:42 +03:00
|
|
|
if (stareaR.right() > screenarea.right())
|
2007-04-29 21:35:43 +04:00
|
|
|
stareaR = QRect();
|
2011-01-30 17:34:42 +03:00
|
|
|
if (stareaT.top() < screenarea.top())
|
2007-04-29 21:35:43 +04:00
|
|
|
stareaT = QRect();
|
2011-01-30 17:34:42 +03:00
|
|
|
if (stareaB.bottom() < screenarea.bottom())
|
2007-04-29 21:35:43 +04:00
|
|
|
stareaB = QRect();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
// Handle struts at xinerama edges that are inside the virtual screen.
|
|
|
|
// They're given in virtual screen coordinates, make them affect only
|
|
|
|
// their xinerama screen.
|
2011-01-30 17:34:42 +03:00
|
|
|
stareaL.setLeft(qMax(stareaL.left(), screenarea.left()));
|
|
|
|
stareaR.setRight(qMin(stareaR.right(), screenarea.right()));
|
|
|
|
stareaT.setTop(qMax(stareaT.top(), screenarea.top()));
|
|
|
|
stareaB.setBottom(qMin(stareaB.bottom(), screenarea.bottom()));
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
if (stareaL . intersects(area)) {
|
2013-11-01 15:29:05 +04:00
|
|
|
// qDebug() << "Moving left of: " << r << " to " << stareaL.right() + 1;
|
2011-01-30 17:34:42 +03:00
|
|
|
r . setLeft(stareaL . right() + 1);
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
if (stareaR . intersects(area)) {
|
2013-11-01 15:29:05 +04:00
|
|
|
// qDebug() << "Moving right of: " << r << " to " << stareaR.left() - 1;
|
2011-01-30 17:34:42 +03:00
|
|
|
r . setRight(stareaR . left() - 1);
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
if (stareaT . intersects(area)) {
|
2013-11-01 15:29:05 +04:00
|
|
|
// qDebug() << "Moving top of: " << r << " to " << stareaT.bottom() + 1;
|
2011-01-30 17:34:42 +03:00
|
|
|
r . setTop(stareaT . bottom() + 1);
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
if (stareaB . intersects(area)) {
|
2013-11-01 15:29:05 +04:00
|
|
|
// qDebug() << "Moving bottom of: " << r << " to " << stareaB.top() - 1;
|
2011-01-30 17:34:42 +03:00
|
|
|
r . setBottom(stareaB . top() - 1);
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
return r;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
NETExtendedStrut Client::strut() const
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2007-04-29 21:35:43 +04:00
|
|
|
NETExtendedStrut ext = info->extendedStrut();
|
|
|
|
NETStrut str = info->strut();
|
2011-01-30 17:34:42 +03:00
|
|
|
if (ext.left_width == 0 && ext.right_width == 0 && ext.top_width == 0 && ext.bottom_width == 0
|
|
|
|
&& (str.left != 0 || str.right != 0 || str.top != 0 || str.bottom != 0)) {
|
2007-04-29 21:35:43 +04:00
|
|
|
// build extended from simple
|
2011-01-30 17:34:42 +03:00
|
|
|
if (str.left != 0) {
|
2007-04-29 21:35:43 +04:00
|
|
|
ext.left_width = str.left;
|
|
|
|
ext.left_start = 0;
|
|
|
|
ext.left_end = displayHeight();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
if (str.right != 0) {
|
2007-04-29 21:35:43 +04:00
|
|
|
ext.right_width = str.right;
|
|
|
|
ext.right_start = 0;
|
|
|
|
ext.right_end = displayHeight();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
if (str.top != 0) {
|
2007-04-29 21:35:43 +04:00
|
|
|
ext.top_width = str.top;
|
|
|
|
ext.top_start = 0;
|
|
|
|
ext.top_end = displayWidth();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
if (str.bottom != 0) {
|
2007-04-29 21:35:43 +04:00
|
|
|
ext.bottom_width = str.bottom;
|
|
|
|
ext.bottom_start = 0;
|
|
|
|
ext.bottom_end = displayWidth();
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
return ext;
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
StrutRect Client::strutRect(StrutArea area) const
|
|
|
|
{
|
|
|
|
assert(area != StrutAreaAll); // Not valid
|
2009-02-17 18:50:00 +03:00
|
|
|
NETExtendedStrut strutArea = strut();
|
2011-01-30 17:34:42 +03:00
|
|
|
switch(area) {
|
|
|
|
case StrutAreaTop:
|
|
|
|
if (strutArea.top_width != 0)
|
|
|
|
return StrutRect(QRect(
|
|
|
|
strutArea.top_start, 0,
|
|
|
|
strutArea.top_end - strutArea.top_start, strutArea.top_width
|
|
|
|
), StrutAreaTop);
|
|
|
|
break;
|
|
|
|
case StrutAreaRight:
|
|
|
|
if (strutArea.right_width != 0)
|
|
|
|
return StrutRect(QRect(
|
|
|
|
displayWidth() - strutArea.right_width, strutArea.right_start,
|
|
|
|
strutArea.right_width, strutArea.right_end - strutArea.right_start
|
|
|
|
), StrutAreaRight);
|
|
|
|
break;
|
|
|
|
case StrutAreaBottom:
|
|
|
|
if (strutArea.bottom_width != 0)
|
|
|
|
return StrutRect(QRect(
|
|
|
|
strutArea.bottom_start, displayHeight() - strutArea.bottom_width,
|
|
|
|
strutArea.bottom_end - strutArea.bottom_start, strutArea.bottom_width
|
|
|
|
), StrutAreaBottom);
|
|
|
|
break;
|
|
|
|
case StrutAreaLeft:
|
|
|
|
if (strutArea.left_width != 0)
|
|
|
|
return StrutRect(QRect(
|
|
|
|
0, strutArea.left_start,
|
|
|
|
strutArea.left_width, strutArea.left_end - strutArea.left_start
|
|
|
|
), StrutAreaLeft);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort(); // Not valid
|
2009-02-17 18:50:00 +03:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
return StrutRect(); // Null rect
|
|
|
|
}
|
2009-02-17 18:50:00 +03:00
|
|
|
|
|
|
|
StrutRects Client::strutRects() const
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2009-02-17 18:50:00 +03:00
|
|
|
StrutRects region;
|
2011-01-30 17:34:42 +03:00
|
|
|
region += strutRect(StrutAreaTop);
|
|
|
|
region += strutRect(StrutAreaRight);
|
|
|
|
region += strutRect(StrutAreaBottom);
|
|
|
|
region += strutRect(StrutAreaLeft);
|
2009-02-17 18:50:00 +03:00
|
|
|
return region;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2009-02-17 18:50:00 +03:00
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
bool Client::hasStrut() const
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2007-04-29 21:35:43 +04:00
|
|
|
NETExtendedStrut ext = strut();
|
2011-01-30 17:34:42 +03:00
|
|
|
if (ext.left_width == 0 && ext.right_width == 0 && ext.top_width == 0 && ext.bottom_width == 0)
|
2007-04-29 21:35:43 +04:00
|
|
|
return false;
|
|
|
|
return true;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2009-02-15 19:37:42 +03:00
|
|
|
bool Client::hasOffscreenXineramaStrut() const
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2009-02-17 18:50:00 +03:00
|
|
|
// Get strut as a QRegion
|
|
|
|
QRegion region;
|
2011-01-30 17:34:42 +03:00
|
|
|
region += strutRect(StrutAreaTop);
|
|
|
|
region += strutRect(StrutAreaRight);
|
|
|
|
region += strutRect(StrutAreaBottom);
|
|
|
|
region += strutRect(StrutAreaLeft);
|
2009-02-15 19:37:42 +03:00
|
|
|
|
|
|
|
// Remove all visible areas so that only the invisible remain
|
2013-04-03 14:19:27 +04:00
|
|
|
for (int i = 0; i < screens()->count(); i ++)
|
|
|
|
region -= screens()->geometry(i);
|
2009-02-15 19:37:42 +03:00
|
|
|
|
|
|
|
// If there's anything left then we have an offscreen strut
|
2009-02-17 18:50:00 +03:00
|
|
|
return !region.isEmpty();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-09-29 19:52:19 +04:00
|
|
|
void Client::checkWorkspacePosition(QRect oldGeometry, int oldDesktop)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2011-09-29 19:52:19 +04:00
|
|
|
if( !oldGeometry.isValid())
|
|
|
|
oldGeometry = geometry();
|
|
|
|
if( oldDesktop == -2 )
|
|
|
|
oldDesktop = desktop();
|
2011-01-30 17:34:42 +03:00
|
|
|
if (isDesktop())
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (isFullScreen()) {
|
|
|
|
QRect area = workspace()->clientArea(FullScreenArea, this);
|
|
|
|
if (geometry() != area)
|
|
|
|
setGeometry(area);
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
if (isDock())
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
|
|
|
|
2011-07-10 04:24:54 +04:00
|
|
|
if (maximizeMode() != MaximizeRestore) {
|
2011-01-30 17:34:42 +03:00
|
|
|
// TODO update geom_restore?
|
|
|
|
changeMaximize(false, false, true); // adjust size
|
2011-09-29 19:39:04 +04:00
|
|
|
const QRect screenArea = workspace()->clientArea(ScreenArea, this);
|
2011-07-29 00:19:10 +04:00
|
|
|
QRect geom = geometry();
|
2011-09-29 17:17:59 +04:00
|
|
|
checkOffscreenPosition(&geom, screenArea);
|
2011-07-29 00:19:10 +04:00
|
|
|
setGeometry(geom);
|
2011-07-10 04:24:54 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (quick_tile_mode != QuickTileNone) {
|
|
|
|
setGeometry(electricBorderMaximizeGeometry(geometry().center(), desktop()));
|
|
|
|
return;
|
|
|
|
}
|
2007-05-07 17:13:48 +04:00
|
|
|
|
2013-03-23 03:42:45 +04:00
|
|
|
// this can be true only if this window was mapped before KWin
|
|
|
|
// was started - in such case, don't adjust position to workarea,
|
|
|
|
// because the window already had its position, and if a window
|
|
|
|
// with a strut altering the workarea would be managed in initialization
|
|
|
|
// after this one, this window would be moved
|
|
|
|
if (workspace()->initializing())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If the window was touching an edge before but not now move it so it is again.
|
|
|
|
// Old and new maximums have different starting values so windows on the screen
|
|
|
|
// edge will move when a new strut is placed on the edge.
|
|
|
|
QRect oldScreenArea;
|
|
|
|
QRect oldGeomTall;
|
|
|
|
QRect oldGeomWide;
|
|
|
|
if( workspace()->inUpdateClientArea()) {
|
|
|
|
// we need to find the screen area as it was before the change
|
|
|
|
oldScreenArea = QRect( 0, 0, workspace()->oldDisplayWidth(), workspace()->oldDisplayHeight());
|
|
|
|
oldGeomTall = QRect(oldGeometry.x(), 0, oldGeometry.width(), workspace()->oldDisplayHeight()); // Full screen height
|
|
|
|
oldGeomWide = QRect(0, oldGeometry.y(), workspace()->oldDisplayWidth(), oldGeometry.height()); // Full screen width
|
|
|
|
int distance = INT_MAX;
|
|
|
|
foreach(const QRect &r, workspace()->previousScreenSizes()) {
|
|
|
|
int d = r.contains( oldGeometry.center()) ? 0 : ( r.center() - oldGeometry.center()).manhattanLength();
|
|
|
|
if( d < distance ) {
|
|
|
|
distance = d;
|
|
|
|
oldScreenArea = r;
|
2011-09-30 15:22:39 +04:00
|
|
|
}
|
2011-09-30 16:50:18 +04:00
|
|
|
}
|
2013-03-23 03:42:45 +04:00
|
|
|
} else {
|
|
|
|
oldScreenArea = workspace()->clientArea(ScreenArea, oldGeometry.center(), oldDesktop);
|
|
|
|
oldGeomTall = QRect(oldGeometry.x(), 0, oldGeometry.width(), displayHeight()); // Full screen height
|
|
|
|
oldGeomWide = QRect(0, oldGeometry.y(), displayWidth(), oldGeometry.height()); // Full screen width
|
|
|
|
}
|
|
|
|
int oldTopMax = oldScreenArea.y();
|
|
|
|
int oldRightMax = oldScreenArea.x() + oldScreenArea.width();
|
|
|
|
int oldBottomMax = oldScreenArea.y() + oldScreenArea.height();
|
|
|
|
int oldLeftMax = oldScreenArea.x();
|
|
|
|
const QRect screenArea = workspace()->clientArea(ScreenArea, this);
|
|
|
|
int topMax = screenArea.y();
|
|
|
|
int rightMax = screenArea.x() + screenArea.width();
|
|
|
|
int bottomMax = screenArea.y() + screenArea.height();
|
|
|
|
int leftMax = screenArea.x();
|
|
|
|
QRect newGeom = geom_restore; // geometry();
|
|
|
|
const QRect newGeomTall = QRect(newGeom.x(), 0, newGeom.width(), displayHeight()); // Full screen height
|
|
|
|
const QRect newGeomWide = QRect(0, newGeom.y(), displayWidth(), newGeom.height()); // Full screen width
|
|
|
|
// Get the max strut point for each side where the window is (E.g. Highest point for
|
|
|
|
// the bottom struts bounded by the window's left and right sides).
|
|
|
|
if( workspace()->inUpdateClientArea()) {
|
|
|
|
// These 4 compute old bounds when the restricted areas themselves changed (Workspace::updateClientArea())
|
|
|
|
foreach (const QRect & r, workspace()->previousRestrictedMoveArea(oldDesktop, StrutAreaTop).rects()) {
|
|
|
|
QRect rect = r & oldGeomTall;
|
|
|
|
if (!rect.isEmpty())
|
|
|
|
oldTopMax = qMax(oldTopMax, rect.y() + rect.height());
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2013-03-23 03:42:45 +04:00
|
|
|
foreach (const QRect & r, workspace()->previousRestrictedMoveArea(oldDesktop, StrutAreaRight).rects()) {
|
|
|
|
QRect rect = r & oldGeomWide;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (!rect.isEmpty())
|
2013-03-23 03:42:45 +04:00
|
|
|
oldRightMax = qMin(oldRightMax, rect.x());
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2013-03-23 03:42:45 +04:00
|
|
|
foreach (const QRect & r, workspace()->previousRestrictedMoveArea(oldDesktop, StrutAreaBottom).rects()) {
|
|
|
|
QRect rect = r & oldGeomTall;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (!rect.isEmpty())
|
2013-03-23 03:42:45 +04:00
|
|
|
oldBottomMax = qMin(oldBottomMax, rect.y());
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2013-03-23 03:42:45 +04:00
|
|
|
foreach (const QRect & r, workspace()->previousRestrictedMoveArea(oldDesktop, StrutAreaLeft).rects()) {
|
|
|
|
QRect rect = r & oldGeomWide;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (!rect.isEmpty())
|
2013-03-23 03:42:45 +04:00
|
|
|
oldLeftMax = qMax(oldLeftMax, rect.x() + rect.width());
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2013-03-23 03:42:45 +04:00
|
|
|
} else {
|
|
|
|
// These 4 compute old bounds when e.g. active desktop or screen changes
|
|
|
|
foreach (const QRect & r, workspace()->restrictedMoveArea(oldDesktop, StrutAreaTop).rects()) {
|
|
|
|
QRect rect = r & oldGeomTall;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (!rect.isEmpty())
|
2013-03-23 03:42:45 +04:00
|
|
|
oldTopMax = qMax(oldTopMax, rect.y() + rect.height());
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2013-03-23 03:42:45 +04:00
|
|
|
foreach (const QRect & r, workspace()->restrictedMoveArea(oldDesktop, StrutAreaRight).rects()) {
|
|
|
|
QRect rect = r & oldGeomWide;
|
|
|
|
if (!rect.isEmpty())
|
|
|
|
oldRightMax = qMin(oldRightMax, rect.x());
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2013-03-23 03:42:45 +04:00
|
|
|
foreach (const QRect & r, workspace()->restrictedMoveArea(oldDesktop, StrutAreaBottom).rects()) {
|
|
|
|
QRect rect = r & oldGeomTall;
|
|
|
|
if (!rect.isEmpty())
|
|
|
|
oldBottomMax = qMin(oldBottomMax, rect.y());
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2013-03-23 03:42:45 +04:00
|
|
|
foreach (const QRect & r, workspace()->restrictedMoveArea(oldDesktop, StrutAreaLeft).rects()) {
|
|
|
|
QRect rect = r & oldGeomWide;
|
|
|
|
if (!rect.isEmpty())
|
|
|
|
oldLeftMax = qMax(oldLeftMax, rect.x() + rect.width());
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2013-03-23 03:42:45 +04:00
|
|
|
}
|
|
|
|
// These 4 compute new bounds
|
|
|
|
foreach (const QRect & r, workspace()->restrictedMoveArea(desktop(), StrutAreaTop).rects()) {
|
|
|
|
QRect rect = r & newGeomTall;
|
|
|
|
if (!rect.isEmpty())
|
|
|
|
topMax = qMax(topMax, rect.y() + rect.height());
|
|
|
|
}
|
|
|
|
foreach (const QRect & r, workspace()->restrictedMoveArea(desktop(), StrutAreaRight).rects()) {
|
|
|
|
QRect rect = r & newGeomWide;
|
|
|
|
if (!rect.isEmpty())
|
|
|
|
rightMax = qMin(rightMax, rect.x());
|
|
|
|
}
|
|
|
|
foreach (const QRect & r, workspace()->restrictedMoveArea(desktop(), StrutAreaBottom).rects()) {
|
|
|
|
QRect rect = r & newGeomTall;
|
|
|
|
if (!rect.isEmpty())
|
|
|
|
bottomMax = qMin(bottomMax, rect.y());
|
|
|
|
}
|
|
|
|
foreach (const QRect & r, workspace()->restrictedMoveArea(desktop(), StrutAreaLeft).rects()) {
|
|
|
|
QRect rect = r & newGeomWide;
|
|
|
|
if (!rect.isEmpty())
|
|
|
|
leftMax = qMax(leftMax, rect.x() + rect.width());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the sides were inside or touching but are no longer
|
|
|
|
if ((oldGeometry.y() >= oldTopMax && newGeom.y() < topMax)
|
|
|
|
|| (oldGeometry.y() == oldTopMax && newGeom.y() != topMax)) {
|
|
|
|
// Top was inside or touching before but isn't anymore
|
|
|
|
newGeom.moveTop(qMax(topMax, screenArea.y()));
|
|
|
|
}
|
|
|
|
if ((oldGeometry.y() + oldGeometry.height() <= oldBottomMax && newGeom.y() + newGeom.height() > bottomMax)
|
|
|
|
|| (oldGeometry.y() + oldGeometry.height() == oldBottomMax && newGeom.y() + newGeom.height() != bottomMax)) {
|
|
|
|
// Bottom was inside or touching before but isn't anymore
|
|
|
|
newGeom.moveBottom(qMin(bottomMax - 1, screenArea.bottom()));
|
|
|
|
// If the other side was inside make sure it still is afterwards (shrink appropriately)
|
|
|
|
if (oldGeometry.y() >= oldTopMax && newGeom.y() < topMax)
|
|
|
|
newGeom.setTop(qMax(topMax, screenArea.y()));
|
|
|
|
}
|
|
|
|
if ((oldGeometry.x() >= oldLeftMax && newGeom.x() < leftMax)
|
|
|
|
|| (oldGeometry.x() == oldLeftMax && newGeom.x() != leftMax)) {
|
|
|
|
// Left was inside or touching before but isn't anymore
|
|
|
|
newGeom.moveLeft(qMax(leftMax, screenArea.x()));
|
|
|
|
}
|
|
|
|
if ((oldGeometry.x() + oldGeometry.width() <= oldRightMax && newGeom.x() + newGeom.width() > rightMax)
|
|
|
|
|| (oldGeometry.x() + oldGeometry.width() == oldRightMax && newGeom.x() + newGeom.width() != rightMax)) {
|
|
|
|
// Right was inside or touching before but isn't anymore
|
|
|
|
newGeom.moveRight(qMin(rightMax - 1, screenArea.right()));
|
|
|
|
// If the other side was inside make sure it still is afterwards (shrink appropriately)
|
|
|
|
if (oldGeometry.x() >= oldLeftMax && newGeom.x() < leftMax)
|
2013-03-23 04:07:12 +04:00
|
|
|
newGeom.setLeft(qMax(leftMax, screenArea.x()));
|
2013-03-23 03:42:45 +04:00
|
|
|
}
|
2009-02-17 18:50:00 +03:00
|
|
|
|
2013-03-23 03:42:45 +04:00
|
|
|
checkOffscreenPosition(&newGeom, screenArea);
|
|
|
|
// Obey size hints. TODO: We really should make sure it stays in the right place
|
|
|
|
newGeom.setSize(adjustedSize(newGeom.size()));
|
2009-02-17 18:50:00 +03:00
|
|
|
|
2013-03-23 03:42:45 +04:00
|
|
|
if (newGeom != geometry())
|
|
|
|
setGeometry(newGeom);
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-09-29 17:17:59 +04:00
|
|
|
void Client::checkOffscreenPosition(QRect* geom, const QRect& screenArea)
|
2011-07-29 00:18:41 +04:00
|
|
|
{
|
2011-09-29 17:17:59 +04:00
|
|
|
if (geom->x() > screenArea.right()) {
|
2011-07-29 00:18:41 +04:00
|
|
|
int screenWidth = screenArea.width();
|
2011-09-29 17:17:59 +04:00
|
|
|
geom->moveLeft(screenWidth - (screenWidth / 4));
|
2011-07-29 00:18:41 +04:00
|
|
|
}
|
2011-09-29 17:17:59 +04:00
|
|
|
if (geom->y() > screenArea.bottom()) {
|
2011-07-29 00:18:41 +04:00
|
|
|
int screenHeight = screenArea.height();
|
2011-09-29 17:17:59 +04:00
|
|
|
geom->moveBottom(screenHeight - (screenHeight / 4));
|
2011-07-29 00:18:41 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
/*!
|
|
|
|
Adjust the frame size \a frame according to he window's size hints.
|
|
|
|
*/
|
2011-01-30 17:34:42 +03:00
|
|
|
QSize Client::adjustedSize(const QSize& frame, Sizemode mode) const
|
|
|
|
{
|
2007-04-29 21:35:43 +04:00
|
|
|
// first, get the window size for the given frame size s
|
2011-01-30 17:34:42 +03:00
|
|
|
QSize wsize(frame.width() - (border_left + border_right),
|
|
|
|
frame.height() - (border_top + border_bottom));
|
|
|
|
if (wsize.isEmpty())
|
|
|
|
wsize = QSize(1, 1);
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
return sizeForClientSize(wsize, mode, false);
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
// this helper returns proper size even if the window is shaded
|
|
|
|
// see also the comment in Client::setGeometry()
|
|
|
|
QSize Client::adjustedSize() const
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
return sizeForClientSize(clientSize());
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Calculate the appropriate frame size for the given client size \a
|
|
|
|
wsize.
|
|
|
|
|
|
|
|
\a wsize is adapted according to the window's size hints (minimum,
|
|
|
|
maximum and incremental size changes).
|
|
|
|
|
|
|
|
*/
|
2011-01-30 17:34:42 +03:00
|
|
|
QSize Client::sizeForClientSize(const QSize& wsize, Sizemode mode, bool noframe) const
|
|
|
|
{
|
2007-04-29 21:35:43 +04:00
|
|
|
int w = wsize.width();
|
|
|
|
int h = wsize.height();
|
2011-01-30 17:34:42 +03:00
|
|
|
if (w < 1 || h < 1) {
|
2013-09-02 15:14:39 +04:00
|
|
|
qWarning() << "sizeForClientSize() with empty size!" ;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
if (w < 1) w = 1;
|
|
|
|
if (h < 1) h = 1;
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
// basesize, minsize, maxsize, paspect and resizeinc have all values defined,
|
|
|
|
// even if they're not set in flags - see getWmNormalHints()
|
2012-01-12 10:42:55 +04:00
|
|
|
QSize min_size = tabGroup() ? tabGroup()->minSize() : minSize();
|
|
|
|
QSize max_size = tabGroup() ? tabGroup()->maxSize() : maxSize();
|
2011-01-30 17:34:42 +03:00
|
|
|
if (decoration != NULL) {
|
2007-04-29 21:35:43 +04:00
|
|
|
QSize decominsize = decoration->minimumSize();
|
2011-01-30 17:34:42 +03:00
|
|
|
QSize border_size(border_left + border_right, border_top + border_bottom);
|
|
|
|
if (border_size.width() > decominsize.width()) // just in case
|
|
|
|
decominsize.setWidth(border_size.width());
|
|
|
|
if (border_size.height() > decominsize.height())
|
|
|
|
decominsize.setHeight(border_size.height());
|
|
|
|
if (decominsize.width() > min_size.width())
|
|
|
|
min_size.setWidth(decominsize.width());
|
|
|
|
if (decominsize.height() > min_size.height())
|
|
|
|
min_size.setHeight(decominsize.height());
|
|
|
|
}
|
|
|
|
w = qMin(max_size.width(), w);
|
|
|
|
h = qMin(max_size.height(), h);
|
|
|
|
w = qMax(min_size.width(), w);
|
|
|
|
h = qMax(min_size.height(), h);
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
int w1 = w;
|
|
|
|
int h1 = h;
|
|
|
|
int width_inc = xSizeHint.width_inc;
|
|
|
|
int height_inc = xSizeHint.height_inc;
|
|
|
|
int basew_inc = xSizeHint.min_width; // see getWmNormalHints()
|
|
|
|
int baseh_inc = xSizeHint.min_height;
|
2011-01-30 17:34:42 +03:00
|
|
|
w = int((w - basew_inc) / width_inc) * width_inc + basew_inc;
|
|
|
|
h = int((h - baseh_inc) / height_inc) * height_inc + baseh_inc;
|
2007-04-29 21:35:43 +04:00
|
|
|
// code for aspect ratios based on code from FVWM
|
|
|
|
/*
|
|
|
|
* The math looks like this:
|
|
|
|
*
|
|
|
|
* minAspectX dwidth maxAspectX
|
|
|
|
* ---------- <= ------- <= ----------
|
|
|
|
* minAspectY dheight maxAspectY
|
|
|
|
*
|
|
|
|
* If that is multiplied out, then the width and height are
|
|
|
|
* invalid in the following situations:
|
|
|
|
*
|
|
|
|
* minAspectX * dheight > minAspectY * dwidth
|
|
|
|
* maxAspectX * dheight < maxAspectY * dwidth
|
|
|
|
*
|
|
|
|
*/
|
2011-01-30 17:34:42 +03:00
|
|
|
if (xSizeHint.flags & PAspect) {
|
2007-04-29 21:35:43 +04:00
|
|
|
double min_aspect_w = xSizeHint.min_aspect.x; // use doubles, because the values can be MAX_INT
|
|
|
|
double min_aspect_h = xSizeHint.min_aspect.y; // and multiplying would go wrong otherwise
|
|
|
|
double max_aspect_w = xSizeHint.max_aspect.x;
|
|
|
|
double max_aspect_h = xSizeHint.max_aspect.y;
|
|
|
|
// According to ICCCM 4.1.2.3 PMinSize should be a fallback for PBaseSize for size increments,
|
|
|
|
// but not for aspect ratio. Since this code comes from FVWM, handles both at the same time,
|
|
|
|
// and I have no idea how it works, let's hope nobody relies on that.
|
|
|
|
w -= xSizeHint.base_width;
|
|
|
|
h -= xSizeHint.base_height;
|
|
|
|
int max_width = max_size.width() - xSizeHint.base_width;
|
|
|
|
int min_width = min_size.width() - xSizeHint.base_width;
|
|
|
|
int max_height = max_size.height() - xSizeHint.base_height;
|
|
|
|
int min_height = min_size.height() - xSizeHint.base_height;
|
|
|
|
#define ASPECT_CHECK_GROW_W \
|
2011-01-30 17:34:42 +03:00
|
|
|
if ( min_aspect_w * h > min_aspect_h * w ) \
|
|
|
|
{ \
|
|
|
|
int delta = int( min_aspect_w * h / min_aspect_h - w ) / width_inc * width_inc; \
|
|
|
|
if ( w + delta <= max_width ) \
|
|
|
|
w += delta; \
|
|
|
|
}
|
|
|
|
#define ASPECT_CHECK_SHRINK_H_GROW_W \
|
|
|
|
if ( min_aspect_w * h > min_aspect_h * w ) \
|
|
|
|
{ \
|
|
|
|
int delta = int( h - w * min_aspect_h / min_aspect_w ) / height_inc * height_inc; \
|
|
|
|
if ( h - delta >= min_height ) \
|
|
|
|
h -= delta; \
|
|
|
|
else \
|
|
|
|
{ \
|
2007-04-29 21:35:43 +04:00
|
|
|
int delta = int( min_aspect_w * h / min_aspect_h - w ) / width_inc * width_inc; \
|
2011-01-30 17:34:42 +03:00
|
|
|
if ( w + delta <= max_width ) \
|
2007-04-29 21:35:43 +04:00
|
|
|
w += delta; \
|
2011-01-30 17:34:42 +03:00
|
|
|
} \
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
#define ASPECT_CHECK_GROW_H \
|
2011-01-30 17:34:42 +03:00
|
|
|
if ( max_aspect_w * h < max_aspect_h * w ) \
|
|
|
|
{ \
|
|
|
|
int delta = int( w * max_aspect_h / max_aspect_w - h ) / height_inc * height_inc; \
|
|
|
|
if ( h + delta <= max_height ) \
|
|
|
|
h += delta; \
|
|
|
|
}
|
|
|
|
#define ASPECT_CHECK_SHRINK_W_GROW_H \
|
|
|
|
if ( max_aspect_w * h < max_aspect_h * w ) \
|
|
|
|
{ \
|
|
|
|
int delta = int( w - max_aspect_w * h / max_aspect_h ) / width_inc * width_inc; \
|
|
|
|
if ( w - delta >= min_width ) \
|
|
|
|
w -= delta; \
|
|
|
|
else \
|
|
|
|
{ \
|
2007-04-29 21:35:43 +04:00
|
|
|
int delta = int( w * max_aspect_h / max_aspect_w - h ) / height_inc * height_inc; \
|
2011-01-30 17:34:42 +03:00
|
|
|
if ( h + delta <= max_height ) \
|
2007-04-29 21:35:43 +04:00
|
|
|
h += delta; \
|
2011-01-30 17:34:42 +03:00
|
|
|
} \
|
|
|
|
}
|
|
|
|
switch(mode) {
|
|
|
|
case SizemodeAny:
|
2007-04-29 21:35:43 +04:00
|
|
|
#if 0 // make SizemodeAny equal to SizemodeFixedW - prefer keeping fixed width,
|
2011-01-30 17:34:42 +03:00
|
|
|
// so that changing aspect ratio to a different value and back keeps the same size (#87298)
|
|
|
|
{
|
2007-04-29 21:35:43 +04:00
|
|
|
ASPECT_CHECK_SHRINK_H_GROW_W
|
|
|
|
ASPECT_CHECK_SHRINK_W_GROW_H
|
|
|
|
ASPECT_CHECK_GROW_H
|
|
|
|
ASPECT_CHECK_GROW_W
|
|
|
|
break;
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
#endif
|
|
|
|
case SizemodeFixedW: {
|
|
|
|
// the checks are order so that attempts to modify height are first
|
|
|
|
ASPECT_CHECK_GROW_H
|
|
|
|
ASPECT_CHECK_SHRINK_H_GROW_W
|
|
|
|
ASPECT_CHECK_SHRINK_W_GROW_H
|
|
|
|
ASPECT_CHECK_GROW_W
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SizemodeFixedH: {
|
|
|
|
ASPECT_CHECK_GROW_W
|
|
|
|
ASPECT_CHECK_SHRINK_W_GROW_H
|
|
|
|
ASPECT_CHECK_SHRINK_H_GROW_W
|
|
|
|
ASPECT_CHECK_GROW_H
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SizemodeMax: {
|
|
|
|
// first checks that try to shrink
|
|
|
|
ASPECT_CHECK_SHRINK_H_GROW_W
|
|
|
|
ASPECT_CHECK_SHRINK_W_GROW_H
|
|
|
|
ASPECT_CHECK_GROW_W
|
|
|
|
ASPECT_CHECK_GROW_H
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
#undef ASPECT_CHECK_SHRINK_H_GROW_W
|
|
|
|
#undef ASPECT_CHECK_SHRINK_W_GROW_H
|
|
|
|
#undef ASPECT_CHECK_GROW_W
|
|
|
|
#undef ASPECT_CHECK_GROW_H
|
|
|
|
w += xSizeHint.base_width;
|
|
|
|
h += xSizeHint.base_height;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2012-03-18 03:56:30 +04:00
|
|
|
if (!rules()->checkStrictGeometry(!isFullScreen())) {
|
2011-01-30 17:34:42 +03:00
|
|
|
// disobey increments and aspect by explicit rule
|
|
|
|
w = w1;
|
|
|
|
h = h1;
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
if (!noframe) {
|
2007-04-29 21:35:43 +04:00
|
|
|
w += border_left + border_right;
|
|
|
|
h += border_top + border_bottom;
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
return rules()->checkSize(QSize(w, h));
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Gets the client's normal WM hints and reconfigures itself respectively.
|
|
|
|
*/
|
|
|
|
void Client::getWmNormalHints()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2007-04-29 21:35:43 +04:00
|
|
|
long msize;
|
2013-02-01 22:42:42 +04:00
|
|
|
const bool hadFixedAspect = xSizeHint.flags & PAspect;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (XGetWMNormalHints(display(), window(), &xSizeHint, &msize) == 0)
|
2007-04-29 21:35:43 +04:00
|
|
|
xSizeHint.flags = 0;
|
|
|
|
// set defined values for the fields, even if they're not in flags
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
if (!(xSizeHint.flags & PMinSize))
|
2007-04-29 21:35:43 +04:00
|
|
|
xSizeHint.min_width = xSizeHint.min_height = 0;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (xSizeHint.flags & PBaseSize) {
|
2007-04-29 21:35:43 +04:00
|
|
|
// PBaseSize is a fallback for PMinSize according to ICCCM 4.1.2.3
|
|
|
|
// The other way around PMinSize is not a complete fallback for PBaseSize,
|
|
|
|
// so that's not handled here.
|
2011-01-30 17:34:42 +03:00
|
|
|
if (!(xSizeHint.flags & PMinSize)) {
|
2007-04-29 21:35:43 +04:00
|
|
|
xSizeHint.min_width = xSizeHint.base_width;
|
|
|
|
xSizeHint.min_height = xSizeHint.base_height;
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
} else
|
2007-04-29 21:35:43 +04:00
|
|
|
xSizeHint.base_width = xSizeHint.base_height = 0;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (!(xSizeHint.flags & PMaxSize))
|
2007-04-29 21:35:43 +04:00
|
|
|
xSizeHint.max_width = xSizeHint.max_height = INT_MAX;
|
2011-01-30 17:34:42 +03:00
|
|
|
else {
|
|
|
|
xSizeHint.max_width = qMax(xSizeHint.max_width, 1);
|
|
|
|
xSizeHint.max_height = qMax(xSizeHint.max_height, 1);
|
|
|
|
}
|
|
|
|
if (xSizeHint.flags & PResizeInc) {
|
|
|
|
xSizeHint.width_inc = qMax(xSizeHint.width_inc, 1);
|
|
|
|
xSizeHint.height_inc = qMax(xSizeHint.height_inc, 1);
|
|
|
|
} else {
|
2007-04-29 21:35:43 +04:00
|
|
|
xSizeHint.width_inc = 1;
|
|
|
|
xSizeHint.height_inc = 1;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
if (xSizeHint.flags & PAspect) {
|
|
|
|
// no dividing by zero
|
|
|
|
xSizeHint.min_aspect.y = qMax(xSizeHint.min_aspect.y, 1);
|
|
|
|
xSizeHint.max_aspect.y = qMax(xSizeHint.max_aspect.y, 1);
|
2013-02-01 22:42:42 +04:00
|
|
|
if (!hadFixedAspect)
|
|
|
|
maximize(max_mode); // align to eventual new contraints
|
2011-01-30 17:34:42 +03:00
|
|
|
} else {
|
2007-04-29 21:35:43 +04:00
|
|
|
xSizeHint.min_aspect.x = 1;
|
|
|
|
xSizeHint.min_aspect.y = INT_MAX;
|
|
|
|
xSizeHint.max_aspect.x = INT_MAX;
|
|
|
|
xSizeHint.max_aspect.y = 1;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
if (!(xSizeHint.flags & PWinGravity))
|
2007-04-29 21:35:43 +04:00
|
|
|
xSizeHint.win_gravity = NorthWestGravity;
|
2009-11-15 18:48:59 +03:00
|
|
|
|
|
|
|
// Update min/max size of this group
|
2012-01-12 10:42:55 +04:00
|
|
|
if (tabGroup())
|
|
|
|
tabGroup()->updateMinMaxSize();
|
2009-11-15 18:48:59 +03:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
if (isManaged()) {
|
|
|
|
// update to match restrictions
|
2007-04-29 21:35:43 +04:00
|
|
|
QSize new_size = adjustedSize();
|
2011-01-30 17:34:42 +03:00
|
|
|
if (new_size != size() && !isFullScreen()) {
|
2013-09-12 00:50:32 +04:00
|
|
|
QRect origClientGeometry(pos() + clientPos(), clientSize());
|
2011-01-30 17:34:42 +03:00
|
|
|
resizeWithChecks(new_size);
|
|
|
|
if ((!isSpecialWindow() || isToolbar()) && !isFullScreen()) {
|
2007-04-29 21:35:43 +04:00
|
|
|
// try to keep the window in its xinerama screen if possible,
|
|
|
|
// if that fails at least keep it visible somewhere
|
2011-01-30 17:34:42 +03:00
|
|
|
QRect area = workspace()->clientArea(MovementArea, this);
|
2013-09-12 00:50:32 +04:00
|
|
|
if (area.contains(origClientGeometry))
|
2011-01-30 17:34:42 +03:00
|
|
|
keepInArea(area);
|
|
|
|
area = workspace()->clientArea(WorkArea, this);
|
2013-09-12 00:50:32 +04:00
|
|
|
if (area.contains(origClientGeometry))
|
2011-01-30 17:34:42 +03:00
|
|
|
keepInArea(area);
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
updateAllowedActions(); // affects isResizeable()
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
QSize Client::minSize() const
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
return rules()->checkMinSize(QSize(xSizeHint.min_width, xSizeHint.min_height));
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
QSize Client::maxSize() const
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
return rules()->checkMaxSize(QSize(xSizeHint.max_width, xSizeHint.max_height));
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-11-03 02:05:03 +04:00
|
|
|
QSize Client::basicUnit() const
|
|
|
|
{
|
|
|
|
return QSize(xSizeHint.width_inc, xSizeHint.height_inc);
|
|
|
|
}
|
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
/*!
|
|
|
|
Auxiliary function to inform the client about the current window
|
|
|
|
configuration.
|
|
|
|
|
|
|
|
*/
|
|
|
|
void Client::sendSyntheticConfigureNotify()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2007-04-29 21:35:43 +04:00
|
|
|
XConfigureEvent c;
|
|
|
|
c.type = ConfigureNotify;
|
|
|
|
c.send_event = True;
|
|
|
|
c.event = window();
|
|
|
|
c.window = window();
|
|
|
|
c.x = x() + clientPos().x();
|
|
|
|
c.y = y() + clientPos().y();
|
|
|
|
c.width = clientSize().width();
|
|
|
|
c.height = clientSize().height();
|
|
|
|
c.border_width = 0;
|
|
|
|
c.above = None;
|
|
|
|
c.override_redirect = 0;
|
2011-01-30 17:34:42 +03:00
|
|
|
XSendEvent(display(), c.event, true, StructureNotifyMask, (XEvent*)&c);
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
const QPoint Client::calculateGravitation(bool invert, int gravity) const
|
|
|
|
{
|
2007-04-29 21:35:43 +04:00
|
|
|
int dx, dy;
|
|
|
|
dx = dy = 0;
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
if (gravity == 0) // default (nonsense) value for the argument
|
2007-04-29 21:35:43 +04:00
|
|
|
gravity = xSizeHint.win_gravity;
|
|
|
|
|
|
|
|
// dx, dy specify how the client window moves to make space for the frame
|
2011-01-30 17:34:42 +03:00
|
|
|
switch(gravity) {
|
|
|
|
case NorthWestGravity: // move down right
|
|
|
|
default:
|
|
|
|
dx = border_left;
|
|
|
|
dy = border_top;
|
|
|
|
break;
|
|
|
|
case NorthGravity: // move right
|
|
|
|
dx = 0;
|
|
|
|
dy = border_top;
|
|
|
|
break;
|
|
|
|
case NorthEastGravity: // move down left
|
|
|
|
dx = -border_right;
|
|
|
|
dy = border_top;
|
|
|
|
break;
|
|
|
|
case WestGravity: // move right
|
|
|
|
dx = border_left;
|
|
|
|
dy = 0;
|
|
|
|
break;
|
|
|
|
case CenterGravity:
|
|
|
|
break; // will be handled specially
|
|
|
|
case StaticGravity: // don't move
|
|
|
|
dx = 0;
|
|
|
|
dy = 0;
|
|
|
|
break;
|
|
|
|
case EastGravity: // move left
|
|
|
|
dx = -border_right;
|
|
|
|
dy = 0;
|
|
|
|
break;
|
|
|
|
case SouthWestGravity: // move up right
|
|
|
|
dx = border_left ;
|
|
|
|
dy = -border_bottom;
|
|
|
|
break;
|
|
|
|
case SouthGravity: // move up
|
|
|
|
dx = 0;
|
|
|
|
dy = -border_bottom;
|
|
|
|
break;
|
|
|
|
case SouthEastGravity: // move up left
|
|
|
|
dx = -border_right;
|
|
|
|
dy = -border_bottom;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (gravity != CenterGravity) {
|
|
|
|
// translate from client movement to frame movement
|
2007-04-29 21:35:43 +04:00
|
|
|
dx -= border_left;
|
|
|
|
dy -= border_top;
|
2011-01-30 17:34:42 +03:00
|
|
|
} else {
|
|
|
|
// center of the frame will be at the same position client center without frame would be
|
|
|
|
dx = - (border_left + border_right) / 2;
|
|
|
|
dy = - (border_top + border_bottom) / 2;
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
if (!invert)
|
|
|
|
return QPoint(x() + dx, y() + dy);
|
|
|
|
else
|
|
|
|
return QPoint(x() - dx, y() - dy);
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
void Client::configureRequest(int value_mask, int rx, int ry, int rw, int rh, int gravity, bool from_tool)
|
|
|
|
{
|
2011-03-08 23:33:40 +03:00
|
|
|
// "maximized" is a user setting -> we do not allow the client to resize itself
|
|
|
|
// away from this & against the users explicit wish
|
2013-09-02 15:14:39 +04:00
|
|
|
qDebug() << this << bool(value_mask & (CWX|CWWidth|CWY|CWHeight)) <<
|
2011-06-13 21:33:20 +04:00
|
|
|
bool(maximizeMode() & MaximizeVertical) <<
|
|
|
|
bool(maximizeMode() & MaximizeHorizontal);
|
2013-06-23 02:01:05 +04:00
|
|
|
|
|
|
|
// we want to (partially) ignore the request when the window is somehow maximized or quicktiled
|
|
|
|
bool ignore = !app_noborder && (quick_tile_mode != QuickTileNone || maximizeMode() != MaximizeRestore);
|
|
|
|
// however, the user shall be able to force obedience despite and also disobedience in general
|
|
|
|
ignore = rules()->checkIgnoreGeometry(ignore);
|
|
|
|
if (!ignore) { // either we're not max'd / q'tiled or the user allowed the client to break that - so break it.
|
|
|
|
quick_tile_mode = QuickTileNone;
|
|
|
|
max_mode = MaximizeRestore;
|
|
|
|
} else if (!app_noborder && quick_tile_mode == QuickTileNone &&
|
|
|
|
(maximizeMode() == MaximizeVertical || maximizeMode() == MaximizeHorizontal)) {
|
|
|
|
// ignoring can be, because either we do, or the user does explicitly not want it.
|
|
|
|
// for partially maximized windows we want to allow configures in the other dimension.
|
|
|
|
// so we've to ask the user again - to know whether we just ignored for the partial maximization.
|
|
|
|
// the problem here is, that the user can explicitly permit configure requests - even for maximized windows!
|
|
|
|
// we cannot distinguish that from passing "false" for partially maximized windows.
|
|
|
|
ignore = rules()->checkIgnoreGeometry(false);
|
|
|
|
if (!ignore) { // the user is not interested, so we fix up dimensions
|
|
|
|
if (maximizeMode() == MaximizeVertical)
|
|
|
|
value_mask &= ~(CWY|CWHeight);
|
|
|
|
if (maximizeMode() == MaximizeHorizontal)
|
|
|
|
value_mask &= ~(CWX|CWWidth);
|
|
|
|
if (!(value_mask & (CWX|CWWidth|CWY|CWHeight))) {
|
|
|
|
ignore = true; // the modification turned the request void
|
|
|
|
}
|
|
|
|
}
|
2012-02-17 22:44:30 +04:00
|
|
|
}
|
2013-06-23 02:01:05 +04:00
|
|
|
|
|
|
|
if (ignore) {
|
2013-09-02 15:14:39 +04:00
|
|
|
qDebug() << "DENIED";
|
2013-06-23 02:01:05 +04:00
|
|
|
return; // nothing to (left) to do for use - bugs #158974, #252314, #321491
|
2011-06-13 21:33:20 +04:00
|
|
|
}
|
2013-06-23 02:01:05 +04:00
|
|
|
|
2013-09-02 15:14:39 +04:00
|
|
|
qDebug() << "PERMITTED" << this << bool(value_mask & (CWX|CWWidth|CWY|CWHeight));
|
2010-12-20 21:18:27 +03:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
if (gravity == 0) // default (nonsense) value for the argument
|
2007-04-29 21:35:43 +04:00
|
|
|
gravity = xSizeHint.win_gravity;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (value_mask & (CWX | CWY)) {
|
|
|
|
QPoint new_pos = calculateGravitation(true, gravity); // undo gravitation
|
|
|
|
if (value_mask & CWX)
|
|
|
|
new_pos.setX(rx);
|
|
|
|
if (value_mask & CWY)
|
|
|
|
new_pos.setY(ry);
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
// clever(?) workaround for applications like xv that want to set
|
|
|
|
// the location to the current location but miscalculate the
|
|
|
|
// frame size due to kwin being a double-reparenting window
|
|
|
|
// manager
|
2011-01-30 17:34:42 +03:00
|
|
|
if (new_pos.x() == x() + clientPos().x() && new_pos.y() == y() + clientPos().y()
|
|
|
|
&& gravity == NorthWestGravity && !from_tool) {
|
|
|
|
new_pos.setX(x());
|
|
|
|
new_pos.setY(y());
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
int nw = clientSize().width();
|
|
|
|
int nh = clientSize().height();
|
2011-01-30 17:34:42 +03:00
|
|
|
if (value_mask & CWWidth)
|
2007-04-29 21:35:43 +04:00
|
|
|
nw = rw;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (value_mask & CWHeight)
|
2007-04-29 21:35:43 +04:00
|
|
|
nh = rh;
|
2011-01-30 17:34:42 +03:00
|
|
|
QSize ns = sizeForClientSize(QSize(nw, nh)); // enforces size if needed
|
|
|
|
new_pos = rules()->checkPosition(new_pos);
|
2013-04-03 14:19:27 +04:00
|
|
|
int newScreen = screens()->number(QRect(new_pos, ns).center());
|
2012-10-20 01:37:37 +04:00
|
|
|
if (newScreen != rules()->checkScreen(newScreen))
|
|
|
|
return; // not allowed by rule
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2013-09-12 00:50:32 +04:00
|
|
|
QRect origClientGeometry(pos() + clientPos(), clientSize());
|
2011-01-30 17:34:42 +03:00
|
|
|
GeometryUpdatesBlocker blocker(this);
|
|
|
|
move(new_pos);
|
|
|
|
plainResize(ns);
|
|
|
|
setGeometry(QRect(calculateGravitation(false, gravity), size()));
|
|
|
|
updateFullScreenHack(QRect(new_pos, QSize(nw, nh)));
|
|
|
|
QRect area = workspace()->clientArea(WorkArea, this);
|
|
|
|
if (!from_tool && (!isSpecialWindow() || isToolbar()) && !isFullScreen()
|
2013-09-12 00:50:32 +04:00
|
|
|
&& area.contains(origClientGeometry))
|
2011-01-30 17:34:42 +03:00
|
|
|
keepInArea(area);
|
2010-12-21 17:34:45 +03:00
|
|
|
|
|
|
|
// this is part of the kicker-xinerama-hack... it should be
|
|
|
|
// safe to remove when kicker gets proper ExtendedStrut support;
|
|
|
|
// see Workspace::updateClientArea() and
|
|
|
|
// Client::adjustedClientArea()
|
2011-01-30 17:34:42 +03:00
|
|
|
if (hasStrut())
|
|
|
|
workspace() -> updateClientArea();
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
if (value_mask & (CWWidth | CWHeight)
|
|
|
|
&& !(value_mask & (CWX | CWY))) { // pure resize
|
2007-04-29 21:35:43 +04:00
|
|
|
int nw = clientSize().width();
|
|
|
|
int nh = clientSize().height();
|
2011-01-30 17:34:42 +03:00
|
|
|
if (value_mask & CWWidth)
|
2007-04-29 21:35:43 +04:00
|
|
|
nw = rw;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (value_mask & CWHeight)
|
2007-04-29 21:35:43 +04:00
|
|
|
nh = rh;
|
2011-01-30 17:34:42 +03:00
|
|
|
QSize ns = sizeForClientSize(QSize(nw, nh));
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
if (ns != size()) { // don't restore if some app sets its own size again
|
2013-09-12 00:50:32 +04:00
|
|
|
QRect origClientGeometry(pos() + clientPos(), clientSize());
|
2011-01-30 17:34:42 +03:00
|
|
|
GeometryUpdatesBlocker blocker(this);
|
2007-04-29 21:35:43 +04:00
|
|
|
int save_gravity = xSizeHint.win_gravity;
|
|
|
|
xSizeHint.win_gravity = gravity;
|
2011-01-30 17:34:42 +03:00
|
|
|
resizeWithChecks(ns);
|
2007-04-29 21:35:43 +04:00
|
|
|
xSizeHint.win_gravity = save_gravity;
|
2011-01-30 17:34:42 +03:00
|
|
|
updateFullScreenHack(QRect(calculateGravitation(true, xSizeHint.win_gravity), QSize(nw, nh)));
|
|
|
|
if (!from_tool && (!isSpecialWindow() || isToolbar()) && !isFullScreen()) {
|
2007-04-29 21:35:43 +04:00
|
|
|
// try to keep the window in its xinerama screen if possible,
|
|
|
|
// if that fails at least keep it visible somewhere
|
2011-01-30 17:34:42 +03:00
|
|
|
QRect area = workspace()->clientArea(MovementArea, this);
|
2013-09-12 00:50:32 +04:00
|
|
|
if (area.contains(origClientGeometry))
|
2011-01-30 17:34:42 +03:00
|
|
|
keepInArea(area);
|
|
|
|
area = workspace()->clientArea(WorkArea, this);
|
2013-09-12 00:50:32 +04:00
|
|
|
if (area.contains(origClientGeometry))
|
2011-01-30 17:34:42 +03:00
|
|
|
keepInArea(area);
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2012-04-11 20:18:50 +04:00
|
|
|
geom_restore = geometry();
|
2007-04-29 21:35:43 +04:00
|
|
|
// No need to send synthetic configure notify event here, either it's sent together
|
|
|
|
// with geometry change, or there's no need to send it.
|
|
|
|
// Handling of the real ConfigureRequest event forces sending it, as there it's necessary.
|
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 Client::resizeWithChecks(int w, int h, ForceGeometry_t force)
|
|
|
|
{
|
|
|
|
assert(!shade_geometry_change);
|
|
|
|
if (isShade()) {
|
|
|
|
if (h == border_top + border_bottom) {
|
2013-09-02 15:14:39 +04:00
|
|
|
qWarning() << "Shaded geometry passed for size:" ;
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
int newx = x();
|
|
|
|
int newy = y();
|
2011-01-30 17:34:42 +03:00
|
|
|
QRect area = workspace()->clientArea(WorkArea, this);
|
2007-04-29 21:35:43 +04:00
|
|
|
// don't allow growing larger than workarea
|
2011-01-30 17:34:42 +03:00
|
|
|
if (w > area.width())
|
2007-04-29 21:35:43 +04:00
|
|
|
w = area.width();
|
2011-01-30 17:34:42 +03:00
|
|
|
if (h > area.height())
|
2007-04-29 21:35:43 +04:00
|
|
|
h = area.height();
|
2011-01-30 17:34:42 +03:00
|
|
|
QSize tmp = adjustedSize(QSize(w, h)); // checks size constraints, including min/max size
|
2007-04-29 21:35:43 +04:00
|
|
|
w = tmp.width();
|
|
|
|
h = tmp.height();
|
2011-01-30 17:34:42 +03:00
|
|
|
switch(xSizeHint.win_gravity) {
|
|
|
|
case NorthWestGravity: // top left corner doesn't move
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case NorthGravity: // middle of top border doesn't move
|
|
|
|
newx = (newx + width() / 2) - (w / 2);
|
|
|
|
break;
|
|
|
|
case NorthEastGravity: // top right corner doesn't move
|
|
|
|
newx = newx + width() - w;
|
|
|
|
break;
|
|
|
|
case WestGravity: // middle of left border doesn't move
|
|
|
|
newy = (newy + height() / 2) - (h / 2);
|
|
|
|
break;
|
|
|
|
case CenterGravity: // middle point doesn't move
|
|
|
|
newx = (newx + width() / 2) - (w / 2);
|
|
|
|
newy = (newy + height() / 2) - (h / 2);
|
|
|
|
break;
|
|
|
|
case StaticGravity: // top left corner of _client_ window doesn't move
|
|
|
|
// since decoration doesn't change, equal to NorthWestGravity
|
|
|
|
break;
|
|
|
|
case EastGravity: // // middle of right border doesn't move
|
|
|
|
newx = newx + width() - w;
|
|
|
|
newy = (newy + height() / 2) - (h / 2);
|
|
|
|
break;
|
|
|
|
case SouthWestGravity: // bottom left corner doesn't move
|
|
|
|
newy = newy + height() - h;
|
|
|
|
break;
|
|
|
|
case SouthGravity: // middle of bottom border doesn't move
|
|
|
|
newx = (newx + width() / 2) - (w / 2);
|
|
|
|
newy = newy + height() - h;
|
|
|
|
break;
|
|
|
|
case SouthEastGravity: // bottom right corner doesn't move
|
|
|
|
newx = newx + width() - w;
|
|
|
|
newy = newy + height() - h;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
setGeometry(newx, newy, w, h, force);
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
// _NET_MOVERESIZE_WINDOW
|
2011-01-30 17:34:42 +03:00
|
|
|
void Client::NETMoveResizeWindow(int flags, int x, int y, int width, int height)
|
|
|
|
{
|
2007-04-29 21:35:43 +04:00
|
|
|
int gravity = flags & 0xff;
|
|
|
|
int value_mask = 0;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (flags & (1 << 8))
|
2007-04-29 21:35:43 +04:00
|
|
|
value_mask |= CWX;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (flags & (1 << 9))
|
2007-04-29 21:35:43 +04:00
|
|
|
value_mask |= CWY;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (flags & (1 << 10))
|
2007-04-29 21:35:43 +04:00
|
|
|
value_mask |= CWWidth;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (flags & (1 << 11))
|
2007-04-29 21:35:43 +04:00
|
|
|
value_mask |= CWHeight;
|
2011-01-30 17:34:42 +03:00
|
|
|
configureRequest(value_mask, x, y, width, height, gravity, true);
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Returns whether the window is moveable or has a fixed
|
|
|
|
position.
|
|
|
|
*/
|
|
|
|
bool Client::isMovable() const
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (!motif_may_move || isFullScreen())
|
2007-04-29 21:35:43 +04:00
|
|
|
return false;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (isSpecialWindow() && !isSplash() && !isToolbar()) // allow moving of splashscreens :)
|
2007-04-29 21:35:43 +04:00
|
|
|
return false;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (rules()->checkPosition(invalidPoint) != invalidPoint) // forced position
|
2007-04-29 21:35:43 +04:00
|
|
|
return false;
|
|
|
|
return true;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2008-07-25 14:31:47 +04:00
|
|
|
/*!
|
|
|
|
Returns whether the window is moveable across Xinerama screens
|
|
|
|
*/
|
|
|
|
bool Client::isMovableAcrossScreens() const
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (!motif_may_move)
|
2008-07-25 14:31:47 +04:00
|
|
|
return false;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (isSpecialWindow() && !isSplash() && !isToolbar()) // allow moving of splashscreens :)
|
2008-07-25 14:31:47 +04:00
|
|
|
return false;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (rules()->checkPosition(invalidPoint) != invalidPoint) // forced position
|
2008-07-25 14:31:47 +04:00
|
|
|
return false;
|
|
|
|
return true;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2008-07-25 14:31:47 +04:00
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
/*!
|
|
|
|
Returns whether the window is resizable or has a fixed size.
|
|
|
|
*/
|
|
|
|
bool Client::isResizable() const
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (!motif_may_resize || isFullScreen())
|
2007-04-29 21:35:43 +04:00
|
|
|
return false;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (isSpecialWindow() || isSplash() || isToolbar())
|
2007-04-29 21:35:43 +04:00
|
|
|
return false;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (rules()->checkSize(QSize()).isValid()) // forced size
|
2007-04-29 21:35:43 +04:00
|
|
|
return false;
|
2013-06-08 22:16:35 +04:00
|
|
|
if ((mode == PositionTop || mode == PositionTopLeft || mode == PositionTopRight ||
|
|
|
|
mode == PositionLeft || mode == PositionBottomLeft) && rules()->checkPosition(invalidPoint) != invalidPoint)
|
|
|
|
return false;
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2012-01-12 10:42:55 +04:00
|
|
|
QSize min = tabGroup() ? tabGroup()->minSize() : minSize();
|
|
|
|
QSize max = tabGroup() ? tabGroup()->maxSize() : maxSize();
|
2007-04-29 21:35:43 +04:00
|
|
|
return min.width() < max.width() || min.height() < max.height();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
Returns whether the window is maximizable or not
|
|
|
|
*/
|
|
|
|
bool Client::isMaximizable() const
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2007-04-29 21:35:43 +04:00
|
|
|
{
|
2011-01-30 17:34:42 +03:00
|
|
|
// isMovable() and isResizable() may be false for maximized windows
|
|
|
|
// with moving/resizing maximized windows disabled
|
|
|
|
TemporaryAssign< MaximizeMode > tmp(max_mode, MaximizeRestore);
|
2013-02-05 00:21:18 +04:00
|
|
|
if (!isResizable() || isToolbar()) // SELI isToolbar() ?
|
2007-04-29 21:35:43 +04:00
|
|
|
return false;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2011-12-10 23:29:01 +04:00
|
|
|
if (rules()->checkMaximize(MaximizeRestore) == MaximizeRestore && rules()->checkMaximize(MaximizeFull) != MaximizeRestore)
|
|
|
|
return true;
|
|
|
|
return false;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Reimplemented to inform the client about the new window position.
|
|
|
|
*/
|
2011-12-22 22:38:52 +04:00
|
|
|
void Client::setGeometry(int x, int y, int w, int h, ForceGeometry_t force)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2007-04-29 21:35:43 +04:00
|
|
|
// this code is also duplicated in Client::plainResize()
|
|
|
|
// Ok, the shading geometry stuff. Generally, code doesn't care about shaded geometry,
|
|
|
|
// simply because there are too many places dealing with geometry. Those places
|
|
|
|
// ignore shaded state and use normal geometry, which they usually should get
|
|
|
|
// from adjustedSize(). Such geometry comes here, and if the window is shaded,
|
|
|
|
// the geometry is used only for client_size, since that one is not used when
|
|
|
|
// shading. Then the frame geometry is adjusted for the shaded geometry.
|
|
|
|
// This gets more complicated in the case the code does only something like
|
|
|
|
// setGeometry( geometry()) - geometry() will return the shaded frame geometry.
|
|
|
|
// Such code is wrong and should be changed to handle the case when the window is shaded,
|
2010-09-21 18:31:40 +04:00
|
|
|
// for example using Client::clientSize()
|
2011-01-30 17:34:42 +03:00
|
|
|
|
|
|
|
if (shade_geometry_change)
|
2007-04-29 21:35:43 +04:00
|
|
|
; // nothing
|
2011-01-30 17:34:42 +03:00
|
|
|
else if (isShade()) {
|
|
|
|
if (h == border_top + border_bottom) {
|
2013-09-02 15:14:39 +04:00
|
|
|
qDebug() << "Shaded geometry passed for size:";
|
2011-01-30 17:34:42 +03:00
|
|
|
} else {
|
|
|
|
client_size = QSize(w - border_left - border_right, h - border_top - border_bottom);
|
2007-04-29 21:35:43 +04:00
|
|
|
h = border_top + border_bottom;
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
} else {
|
|
|
|
client_size = QSize(w - border_left - border_right, h - border_top - border_bottom);
|
|
|
|
}
|
|
|
|
QRect g(x, y, w, h);
|
|
|
|
if (block_geometry_updates == 0 && g != rules()->checkGeometry(g)) {
|
2013-09-02 15:14:39 +04:00
|
|
|
qDebug() << "forced geometry fail:" << g << ":" << rules()->checkGeometry(g);
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
if (force == NormalGeometrySet && geom == g && pending_geometry_update == PendingGeometryNone)
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
2007-11-28 17:33:35 +03:00
|
|
|
geom = g;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (block_geometry_updates != 0) {
|
|
|
|
if (pending_geometry_update == PendingGeometryForced)
|
2007-06-19 19:40:09 +04:00
|
|
|
{} // maximum, nothing needed
|
2011-01-30 17:34:42 +03:00
|
|
|
else if (force == ForceGeometrySet)
|
2007-06-19 19:40:09 +04:00
|
|
|
pending_geometry_update = PendingGeometryForced;
|
|
|
|
else
|
|
|
|
pending_geometry_update = PendingGeometryNormal;
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
bool resized = (geom_before_block.size() != geom.size() || pending_geometry_update == PendingGeometryForced);
|
|
|
|
if (resized) {
|
|
|
|
resizeDecoration(QSize(w, h));
|
2013-09-10 10:37:49 +04:00
|
|
|
m_frame.setGeometry(x, y, w, h);
|
2011-01-30 17:34:42 +03:00
|
|
|
if (!isShade()) {
|
2007-04-29 21:35:43 +04:00
|
|
|
QSize cs = clientSize();
|
2013-09-09 12:42:01 +04:00
|
|
|
m_wrapper.setGeometry(QRect(clientPos(), cs));
|
2013-07-31 12:11:39 +04:00
|
|
|
if (!isResize() || syncRequest.counter == XCB_NONE)
|
2013-09-10 09:45:17 +04:00
|
|
|
m_client.setGeometry(0, 0, cs.width(), cs.height());
|
2012-12-30 01:27:31 +04:00
|
|
|
// SELI - won't this be too expensive?
|
|
|
|
// THOMAS - yes, but gtk+ clients will not resize without ...
|
|
|
|
sendSyntheticConfigureNotify();
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
updateShape();
|
2011-11-09 23:39:13 +04:00
|
|
|
} else {
|
2012-12-30 01:27:31 +04:00
|
|
|
if (moveResizeMode) {
|
|
|
|
if (compositing()) // Defer the X update until we leave this mode
|
|
|
|
needsXWindowMove = true;
|
|
|
|
else
|
2013-09-10 10:37:49 +04:00
|
|
|
m_frame.move(x, y); // sendSyntheticConfigureNotify() on finish shall be sufficient
|
2012-11-08 03:54:05 +04:00
|
|
|
} else {
|
2013-09-10 10:37:49 +04:00
|
|
|
m_frame.move(x, y);
|
2012-12-30 01:27:31 +04:00
|
|
|
sendSyntheticConfigureNotify();
|
2012-11-08 03:54:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unconditionally move the input window: it won't affect rendering
|
2013-02-04 14:20:15 +04:00
|
|
|
m_decoInputExtent.move(QPoint(x, y) + inputPos());
|
2011-11-09 23:39:13 +04:00
|
|
|
}
|
2012-02-05 21:50:23 +04:00
|
|
|
updateWindowRules(Rules::Position|Rules::Size);
|
2011-01-30 17:34:42 +03:00
|
|
|
|
|
|
|
// keep track of old maximize mode
|
2010-01-22 05:50:33 +03:00
|
|
|
// to detect changes
|
2013-04-03 14:19:27 +04:00
|
|
|
screens()->setCurrent(this);
|
2008-08-23 13:20:42 +04:00
|
|
|
workspace()->updateStackingOrder();
|
2011-01-30 17:34:42 +03:00
|
|
|
|
2010-01-22 05:50:33 +03:00
|
|
|
// need to regenerate decoration pixmaps when either
|
|
|
|
// - size is changed
|
|
|
|
// - maximize mode is changed to MaximizeRestore, when size unchanged
|
|
|
|
// which can happen when untabbing maximized windows
|
2011-01-30 17:34:42 +03:00
|
|
|
if (resized) {
|
2007-04-29 21:35:43 +04:00
|
|
|
discardWindowPixmap();
|
2011-06-20 00:07:19 +04:00
|
|
|
emit geometryShapeChanged(this, geom_before_block);
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2012-03-10 14:34:56 +04:00
|
|
|
const QRect deco_rect = visibleRect();
|
2012-02-07 20:01:41 +04:00
|
|
|
addLayerRepaint(deco_rect_before_block);
|
|
|
|
addLayerRepaint(deco_rect);
|
2007-04-29 21:35:43 +04:00
|
|
|
geom_before_block = geom;
|
2009-05-05 03:19:42 +04:00
|
|
|
deco_rect_before_block = deco_rect;
|
2009-11-15 06:24:04 +03:00
|
|
|
|
|
|
|
// Update states of all other windows in this group
|
2012-01-12 10:42:55 +04:00
|
|
|
if (tabGroup())
|
2012-03-16 03:15:13 +04:00
|
|
|
tabGroup()->updateStates(this, TabGroup::Geometry);
|
2011-01-30 17:34:42 +03:00
|
|
|
|
2011-12-22 22:38:52 +04:00
|
|
|
// TODO: this signal is emitted too often
|
|
|
|
emit geometryChanged();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
|
2011-12-22 22:38:52 +04:00
|
|
|
void Client::plainResize(int w, int h, ForceGeometry_t force)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2007-04-29 21:35:43 +04:00
|
|
|
// this code is also duplicated in Client::setGeometry(), and it's also commented there
|
2011-01-30 17:34:42 +03:00
|
|
|
if (shade_geometry_change)
|
2007-04-29 21:35:43 +04:00
|
|
|
; // nothing
|
2011-01-30 17:34:42 +03:00
|
|
|
else if (isShade()) {
|
|
|
|
if (h == border_top + border_bottom) {
|
2013-09-02 15:14:39 +04:00
|
|
|
qDebug() << "Shaded geometry passed for size:";
|
2011-01-30 17:34:42 +03:00
|
|
|
} else {
|
|
|
|
client_size = QSize(w - border_left - border_right, h - border_top - border_bottom);
|
2007-04-29 21:35:43 +04:00
|
|
|
h = border_top + border_bottom;
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
} else {
|
|
|
|
client_size = QSize(w - border_left - border_right, h - border_top - border_bottom);
|
|
|
|
}
|
|
|
|
QSize s(w, h);
|
|
|
|
if (block_geometry_updates == 0 && s != rules()->checkSize(s)) {
|
2013-09-02 15:14:39 +04:00
|
|
|
qDebug() << "forced size fail:" << s << ":" << rules()->checkSize(s);
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-06-19 19:40:09 +04:00
|
|
|
// resuming geometry updates is handled only in setGeometry()
|
2011-01-30 17:34:42 +03:00
|
|
|
assert(pending_geometry_update == PendingGeometryNone || block_geometry_updates > 0);
|
|
|
|
if (force == NormalGeometrySet && geom.size() == s)
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
2011-01-30 17:34:42 +03:00
|
|
|
geom.setSize(s);
|
|
|
|
if (block_geometry_updates != 0) {
|
|
|
|
if (pending_geometry_update == PendingGeometryForced)
|
2007-06-19 19:40:09 +04:00
|
|
|
{} // maximum, nothing needed
|
2011-01-30 17:34:42 +03:00
|
|
|
else if (force == ForceGeometrySet)
|
2007-06-19 19:40:09 +04:00
|
|
|
pending_geometry_update = PendingGeometryForced;
|
|
|
|
else
|
|
|
|
pending_geometry_update = PendingGeometryNormal;
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
resizeDecoration(s);
|
2013-09-10 10:37:49 +04:00
|
|
|
m_frame.resize(w, h);
|
2007-11-28 17:33:35 +03:00
|
|
|
// resizeDecoration( s );
|
2011-01-30 17:34:42 +03:00
|
|
|
if (!isShade()) {
|
2007-04-29 21:35:43 +04:00
|
|
|
QSize cs = clientSize();
|
2013-09-09 12:42:01 +04:00
|
|
|
m_wrapper.setGeometry(QRect(clientPos(), cs));
|
2013-09-10 09:45:17 +04:00
|
|
|
m_client.setGeometry(0, 0, cs.width(), cs.height());
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-30 01:19:29 +04:00
|
|
|
updateShape();
|
2011-01-30 17:34:42 +03:00
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
sendSyntheticConfigureNotify();
|
2012-02-05 21:50:23 +04:00
|
|
|
updateWindowRules(Rules::Position|Rules::Size);
|
2013-04-03 14:19:27 +04:00
|
|
|
screens()->setCurrent(this);
|
2008-08-23 13:20:42 +04:00
|
|
|
workspace()->updateStackingOrder();
|
2007-04-29 21:35:43 +04:00
|
|
|
discardWindowPixmap();
|
2011-06-20 00:07:19 +04:00
|
|
|
emit geometryShapeChanged(this, geom_before_block);
|
2012-03-10 14:34:56 +04:00
|
|
|
const QRect deco_rect = visibleRect();
|
2012-02-07 20:01:41 +04:00
|
|
|
addLayerRepaint(deco_rect_before_block);
|
|
|
|
addLayerRepaint(deco_rect);
|
2007-04-29 21:35:43 +04:00
|
|
|
geom_before_block = geom;
|
2009-05-05 03:19:42 +04:00
|
|
|
deco_rect_before_block = deco_rect;
|
2009-11-15 06:24:04 +03:00
|
|
|
|
|
|
|
// Update states of all other windows in this group
|
2012-01-12 10:42:55 +04:00
|
|
|
if (tabGroup())
|
2012-03-16 03:15:13 +04:00
|
|
|
tabGroup()->updateStates(this, TabGroup::Geometry);
|
2011-12-22 22:38:52 +04:00
|
|
|
// TODO: this signal is emitted too often
|
|
|
|
emit geometryChanged();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Reimplemented to inform the client about the new window position.
|
|
|
|
*/
|
2011-01-30 17:34:42 +03:00
|
|
|
void Client::move(int x, int y, ForceGeometry_t force)
|
|
|
|
{
|
2007-06-19 19:40:09 +04:00
|
|
|
// resuming geometry updates is handled only in setGeometry()
|
2011-01-30 17:34:42 +03:00
|
|
|
assert(pending_geometry_update == PendingGeometryNone || block_geometry_updates > 0);
|
|
|
|
QPoint p(x, y);
|
|
|
|
if (block_geometry_updates == 0 && p != rules()->checkPosition(p)) {
|
2013-09-02 15:14:39 +04:00
|
|
|
qDebug() << "forced position fail:" << p << ":" << rules()->checkPosition(p);
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
if (force == NormalGeometrySet && geom.topLeft() == p)
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
2011-01-30 17:34:42 +03:00
|
|
|
geom.moveTopLeft(p);
|
|
|
|
if (block_geometry_updates != 0) {
|
|
|
|
if (pending_geometry_update == PendingGeometryForced)
|
2007-06-19 19:40:09 +04:00
|
|
|
{} // maximum, nothing needed
|
2011-01-30 17:34:42 +03:00
|
|
|
else if (force == ForceGeometrySet)
|
2007-06-19 19:40:09 +04:00
|
|
|
pending_geometry_update = PendingGeometryForced;
|
|
|
|
else
|
|
|
|
pending_geometry_update = PendingGeometryNormal;
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2013-09-10 10:37:49 +04:00
|
|
|
m_frame.move(x, y);
|
2007-04-29 21:35:43 +04:00
|
|
|
sendSyntheticConfigureNotify();
|
2012-02-05 21:50:23 +04:00
|
|
|
updateWindowRules(Rules::Position);
|
2013-04-03 14:19:27 +04:00
|
|
|
screens()->setCurrent(this);
|
2008-08-23 13:20:42 +04:00
|
|
|
workspace()->updateStackingOrder();
|
2012-08-28 21:31:17 +04:00
|
|
|
if (Compositor::isCreated()) {
|
2012-08-23 15:42:59 +04:00
|
|
|
// TODO: move out of geometry.cpp, is this really needed here?
|
2012-08-28 21:31:17 +04:00
|
|
|
Compositor::self()->checkUnredirect();
|
2011-08-21 23:50:23 +04:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
// client itself is not damaged
|
2012-03-10 14:34:56 +04:00
|
|
|
const QRect deco_rect = visibleRect();
|
2012-02-07 20:01:41 +04:00
|
|
|
addLayerRepaint(deco_rect_before_block);
|
|
|
|
addLayerRepaint(deco_rect); // trigger repaint of window's new location
|
2007-04-29 21:35:43 +04:00
|
|
|
geom_before_block = geom;
|
2009-05-05 03:19:42 +04:00
|
|
|
deco_rect_before_block = deco_rect;
|
2009-11-15 06:24:04 +03:00
|
|
|
|
|
|
|
// Update states of all other windows in this group
|
2012-01-12 10:42:55 +04:00
|
|
|
if (tabGroup())
|
2012-03-16 03:15:13 +04:00
|
|
|
tabGroup()->updateStates(this, TabGroup::Geometry);
|
2013-03-26 10:45:08 +04:00
|
|
|
emit geometryChanged();
|
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 Client::blockGeometryUpdates(bool block)
|
|
|
|
{
|
|
|
|
if (block) {
|
|
|
|
if (block_geometry_updates == 0)
|
2007-06-19 19:40:09 +04:00
|
|
|
pending_geometry_update = PendingGeometryNone;
|
2007-04-29 21:35:43 +04:00
|
|
|
++block_geometry_updates;
|
2011-01-30 17:34:42 +03:00
|
|
|
} else {
|
|
|
|
if (--block_geometry_updates == 0) {
|
|
|
|
if (pending_geometry_update != PendingGeometryNone) {
|
|
|
|
if (isShade())
|
|
|
|
setGeometry(QRect(pos(), adjustedSize()), NormalGeometrySet);
|
2007-04-29 21:35:43 +04:00
|
|
|
else
|
2011-01-30 17:34:42 +03:00
|
|
|
setGeometry(geometry(), NormalGeometrySet);
|
2007-06-19 19:40:09 +04:00
|
|
|
pending_geometry_update = PendingGeometryNone;
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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 Client::maximize(MaximizeMode m)
|
|
|
|
{
|
|
|
|
setMaximize(m & MaximizeVertical, m & MaximizeHorizontal);
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Sets the maximization according to \a vertically and \a horizontally
|
|
|
|
*/
|
2011-01-30 17:34:42 +03:00
|
|
|
void Client::setMaximize(bool vertically, bool horizontally)
|
|
|
|
{
|
2009-09-13 21:09:44 +04:00
|
|
|
// changeMaximize() flips the state, so change from set->flip
|
2013-06-26 21:29:52 +04:00
|
|
|
MaximizeMode oldMode = maximizeMode();
|
2007-04-29 21:35:43 +04:00
|
|
|
changeMaximize(
|
|
|
|
max_mode & MaximizeVertical ? !vertically : vertically,
|
|
|
|
max_mode & MaximizeHorizontal ? !horizontally : horizontally,
|
2011-01-30 17:34:42 +03:00
|
|
|
false);
|
2013-06-26 21:29:52 +04:00
|
|
|
if (oldMode != maximizeMode()) {
|
|
|
|
emit clientMaximizedStateChanged(this, max_mode);
|
|
|
|
emit clientMaximizedStateChanged(this, vertically, horizontally);
|
|
|
|
}
|
2009-11-15 06:24:04 +03:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2012-03-16 03:15:13 +04:00
|
|
|
// Update states of all other windows in this group
|
|
|
|
class TabSynchronizer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TabSynchronizer(Client *client, TabGroup::States syncStates) :
|
|
|
|
m_client(client) , m_states(syncStates)
|
|
|
|
{
|
|
|
|
if (client->tabGroup())
|
|
|
|
client->tabGroup()->blockStateUpdates(true);
|
|
|
|
}
|
|
|
|
~TabSynchronizer()
|
|
|
|
{
|
|
|
|
syncNow();
|
|
|
|
}
|
|
|
|
void syncNow()
|
|
|
|
{
|
|
|
|
if (m_client && m_client->tabGroup()) {
|
|
|
|
m_client->tabGroup()->blockStateUpdates(false);
|
|
|
|
m_client->tabGroup()->updateStates(m_client, m_states);
|
|
|
|
}
|
|
|
|
m_client = 0;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
Client *m_client;
|
|
|
|
TabGroup::States m_states;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-09-09 01:05:50 +04:00
|
|
|
static bool changeMaximizeRecursion = false;
|
2011-01-30 17:34:42 +03:00
|
|
|
void Client::changeMaximize(bool vertical, bool horizontal, bool adjust)
|
|
|
|
{
|
2011-12-10 23:29:01 +04:00
|
|
|
if (changeMaximizeRecursion)
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
2012-03-07 17:46:17 +04:00
|
|
|
|
|
|
|
// sic! codeblock for TemporaryAssign
|
2011-12-10 23:29:01 +04:00
|
|
|
{
|
|
|
|
// isMovable() and isResizable() may be false for maximized windows
|
|
|
|
// with moving/resizing maximized windows disabled
|
|
|
|
TemporaryAssign< MaximizeMode > tmp(max_mode, MaximizeRestore);
|
2013-02-05 00:21:18 +04:00
|
|
|
if (!isResizable() || isToolbar()) // SELI isToolbar() ?
|
2011-12-10 23:29:01 +04:00
|
|
|
return;
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2013-02-01 02:58:53 +04:00
|
|
|
QRect clientArea;
|
|
|
|
if (isElectricBorderMaximizing())
|
|
|
|
clientArea = workspace()->clientArea(MaximizeArea, cursorPos(), desktop());
|
|
|
|
else
|
|
|
|
clientArea = workspace()->clientArea(MaximizeArea, this);
|
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
MaximizeMode old_mode = max_mode;
|
|
|
|
// 'adjust == true' means to update the size only, e.g. after changing workspace size
|
2011-01-30 17:34:42 +03:00
|
|
|
if (!adjust) {
|
|
|
|
if (vertical)
|
|
|
|
max_mode = MaximizeMode(max_mode ^ MaximizeVertical);
|
|
|
|
if (horizontal)
|
|
|
|
max_mode = MaximizeMode(max_mode ^ MaximizeHorizontal);
|
|
|
|
}
|
2008-07-25 14:16:09 +04:00
|
|
|
|
2013-02-01 02:58:53 +04:00
|
|
|
// if the client insist on a fix aspect ratio, we check whether the maximizing will get us
|
|
|
|
// out of screen bounds and take that as a "full maximization with aspect check" then
|
|
|
|
if ((xSizeHint.flags & PAspect) && // fixed aspect
|
|
|
|
(max_mode == MaximizeVertical || max_mode == MaximizeHorizontal) && // ondimensional maximization
|
|
|
|
rules()->checkStrictGeometry(true)) { // obey aspect
|
|
|
|
if (max_mode == MaximizeVertical || (old_mode & MaximizeVertical)) {
|
|
|
|
const double fx = xSizeHint.min_aspect.x; // use doubles, because the values can be MAX_INT
|
|
|
|
const double fy = xSizeHint.max_aspect.y; // use doubles, because the values can be MAX_INT
|
|
|
|
if (fx*clientArea.height()/fy > clientArea.width()) // too big
|
|
|
|
max_mode = old_mode & MaximizeHorizontal ? MaximizeRestore : MaximizeFull;
|
|
|
|
} else { // max_mode == MaximizeHorizontal
|
|
|
|
const double fx = xSizeHint.max_aspect.x;
|
|
|
|
const double fy = xSizeHint.min_aspect.y;
|
|
|
|
if (fy*clientArea.width()/fx > clientArea.height()) // too big
|
|
|
|
max_mode = old_mode & MaximizeVertical ? MaximizeRestore : MaximizeFull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
max_mode = rules()->checkMaximize(max_mode);
|
|
|
|
if (!adjust && max_mode == old_mode)
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
GeometryUpdatesBlocker blocker(this);
|
2012-03-16 03:15:13 +04:00
|
|
|
// QT synchronizing required because we eventually change from QT to Maximized
|
|
|
|
TabSynchronizer syncer(this, TabGroup::Maximized|TabGroup::QuickTile);
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2008-01-17 18:44:21 +03:00
|
|
|
// maximing one way and unmaximizing the other way shouldn't happen,
|
|
|
|
// so restore first and then maximize the other way
|
2011-01-30 17:34:42 +03:00
|
|
|
if ((old_mode == MaximizeVertical && max_mode == MaximizeHorizontal)
|
|
|
|
|| (old_mode == MaximizeHorizontal && max_mode == MaximizeVertical)) {
|
|
|
|
changeMaximize(false, false, false); // restore
|
|
|
|
}
|
2008-07-25 14:16:09 +04:00
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
// save sizes for restoring, if maximalizing
|
2012-03-12 06:05:35 +04:00
|
|
|
QSize sz;
|
|
|
|
if (isShade())
|
|
|
|
sz = sizeForClientSize(clientSize());
|
|
|
|
else
|
|
|
|
sz = size();
|
2012-04-11 20:18:50 +04:00
|
|
|
|
|
|
|
if (quick_tile_mode == QuickTileNone) {
|
|
|
|
if (!adjust && !(old_mode & MaximizeVertical)) {
|
|
|
|
geom_restore.setTop(y());
|
|
|
|
geom_restore.setHeight(sz.height());
|
|
|
|
}
|
|
|
|
if (!adjust && !(old_mode & MaximizeHorizontal)) {
|
|
|
|
geom_restore.setLeft(x());
|
|
|
|
geom_restore.setWidth(sz.width());
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
|
2012-03-07 17:46:17 +04:00
|
|
|
if (options->borderlessMaximizedWindows()) {
|
|
|
|
// triggers a maximize change.
|
2012-04-11 20:18:50 +04:00
|
|
|
// The next setNoBorder interation will exit since there's no change but the first recursion pullutes the restore geometry
|
2012-03-07 17:46:17 +04:00
|
|
|
changeMaximizeRecursion = true;
|
|
|
|
setNoBorder(app_noborder || max_mode == MaximizeFull);
|
|
|
|
changeMaximizeRecursion = false;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
|
2013-02-17 04:56:01 +04:00
|
|
|
const ForceGeometry_t geom_mode = decoration && checkBorderSizes(false) ? ForceGeometrySet : NormalGeometrySet;
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2009-10-14 13:33:00 +04:00
|
|
|
// Conditional quick tiling exit points
|
2011-01-30 17:34:42 +03:00
|
|
|
if (quick_tile_mode != QuickTileNone) {
|
|
|
|
if (old_mode == MaximizeFull &&
|
|
|
|
!clientArea.contains(geom_restore.center())) {
|
|
|
|
// Not restoring on the same screen
|
2009-10-14 13:33:00 +04:00
|
|
|
// TODO: The following doesn't work for some reason
|
|
|
|
//quick_tile_mode = QuickTileNone; // And exit quick tile mode manually
|
2011-01-30 17:34:42 +03:00
|
|
|
} else if ((old_mode == MaximizeVertical && max_mode == MaximizeRestore) ||
|
|
|
|
(old_mode == MaximizeFull && max_mode == MaximizeHorizontal)) {
|
|
|
|
// Modifying geometry of a tiled window
|
2009-10-14 13:33:00 +04:00
|
|
|
quick_tile_mode = QuickTileNone; // Exit quick tile mode without restoring geometry
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2009-10-14 13:33:00 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
switch(max_mode) {
|
|
|
|
|
|
|
|
case MaximizeVertical: {
|
|
|
|
if (old_mode & MaximizeHorizontal) { // actually restoring from MaximizeFull
|
|
|
|
if (geom_restore.width() == 0 || !clientArea.contains(geom_restore.center())) {
|
|
|
|
// needs placement
|
|
|
|
plainResize(adjustedSize(QSize(width() * 2 / 3, clientArea.height()), SizemodeFixedH), geom_mode);
|
2012-11-22 16:33:23 +04:00
|
|
|
Placement::self()->placeSmart(this, clientArea);
|
2011-01-30 17:34:42 +03:00
|
|
|
} else {
|
|
|
|
setGeometry(QRect(QPoint(geom_restore.x(), clientArea.top()),
|
|
|
|
adjustedSize(QSize(geom_restore.width(), clientArea.height()), SizemodeFixedH)), geom_mode);
|
|
|
|
}
|
|
|
|
} else {
|
2013-02-05 00:21:18 +04:00
|
|
|
QRect r(x(), clientArea.top(), width(), clientArea.height());
|
|
|
|
r.setTopLeft(rules()->checkPosition(r.topLeft()));
|
|
|
|
r.setSize(adjustedSize(r.size(), SizemodeFixedH));
|
|
|
|
setGeometry(r, geom_mode);
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
info->setState(NET::MaxVert, NET::Max);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MaximizeHorizontal: {
|
|
|
|
if (old_mode & MaximizeVertical) { // actually restoring from MaximizeFull
|
|
|
|
if (geom_restore.height() == 0 || !clientArea.contains(geom_restore.center())) {
|
|
|
|
// needs placement
|
|
|
|
plainResize(adjustedSize(QSize(clientArea.width(), height() * 2 / 3), SizemodeFixedW), geom_mode);
|
2012-11-22 16:33:23 +04:00
|
|
|
Placement::self()->placeSmart(this, clientArea);
|
2011-01-30 17:34:42 +03:00
|
|
|
} else {
|
|
|
|
setGeometry(QRect(QPoint(clientArea.left(), geom_restore.y()),
|
|
|
|
adjustedSize(QSize(clientArea.width(), geom_restore.height()), SizemodeFixedW)), geom_mode);
|
|
|
|
}
|
|
|
|
} else {
|
2013-02-05 00:21:18 +04:00
|
|
|
QRect r(clientArea.left(), y(), clientArea.width(), height());
|
|
|
|
r.setTopLeft(rules()->checkPosition(r.topLeft()));
|
|
|
|
r.setSize(adjustedSize(r.size(), SizemodeFixedW));
|
|
|
|
setGeometry(r, geom_mode);
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
info->setState(NET::MaxHoriz, NET::Max);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MaximizeRestore: {
|
|
|
|
QRect restore = geometry();
|
|
|
|
// when only partially maximized, geom_restore may not have the other dimension remembered
|
|
|
|
if (old_mode & MaximizeVertical) {
|
|
|
|
restore.setTop(geom_restore.top());
|
|
|
|
restore.setBottom(geom_restore.bottom());
|
|
|
|
}
|
|
|
|
if (old_mode & MaximizeHorizontal) {
|
|
|
|
restore.setLeft(geom_restore.left());
|
|
|
|
restore.setRight(geom_restore.right());
|
|
|
|
}
|
|
|
|
if (!restore.isValid()) {
|
|
|
|
QSize s = QSize(clientArea.width() * 2 / 3, clientArea.height() * 2 / 3);
|
|
|
|
if (geom_restore.width() > 0)
|
|
|
|
s.setWidth(geom_restore.width());
|
|
|
|
if (geom_restore.height() > 0)
|
|
|
|
s.setHeight(geom_restore.height());
|
|
|
|
plainResize(adjustedSize(s));
|
2012-11-22 16:33:23 +04:00
|
|
|
Placement::self()->placeSmart(this, clientArea);
|
2011-01-30 17:34:42 +03:00
|
|
|
restore = geometry();
|
|
|
|
if (geom_restore.width() > 0)
|
|
|
|
restore.moveLeft(geom_restore.x());
|
|
|
|
if (geom_restore.height() > 0)
|
|
|
|
restore.moveTop(geom_restore.y());
|
2012-04-24 22:17:09 +04:00
|
|
|
geom_restore = restore; // relevant for mouse pos calculation, bug #298646
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2013-02-01 02:58:53 +04:00
|
|
|
if (xSizeHint.flags & PAspect) {
|
|
|
|
restore.setSize(adjustedSize(restore.size(), SizemodeAny));
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
setGeometry(restore, geom_mode);
|
|
|
|
if (!clientArea.contains(geom_restore.center())) // Not restoring to the same screen
|
2012-11-22 16:33:23 +04:00
|
|
|
Placement::self()->place(this, clientArea);
|
2011-01-30 17:34:42 +03:00
|
|
|
info->setState(0, NET::Max);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MaximizeFull: {
|
2013-02-05 00:21:18 +04:00
|
|
|
QRect r(clientArea);
|
|
|
|
r.setTopLeft(rules()->checkPosition(r.topLeft()));
|
|
|
|
r.setSize(adjustedSize(r.size(), SizemodeMax));
|
2011-08-10 00:43:43 +04:00
|
|
|
if (r.size() != clientArea.size()) { // to avoid off-by-one errors...
|
2012-04-23 14:13:31 +04:00
|
|
|
if (isElectricBorderMaximizing() && r.width() < clientArea.width())
|
2013-02-26 11:45:44 +04:00
|
|
|
r.moveLeft(Cursor::pos().x() - r.width()/2);
|
2011-08-10 00:43:43 +04:00
|
|
|
else
|
|
|
|
r.moveCenter(clientArea.center());
|
2013-02-05 00:21:18 +04:00
|
|
|
r.moveTopLeft(rules()->checkPosition(r.topLeft()));
|
2011-08-10 00:43:43 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
setGeometry(r, geom_mode);
|
2013-03-15 00:54:40 +04:00
|
|
|
if (options->electricBorderMaximize() && r.top() == clientArea.top())
|
|
|
|
quick_tile_mode = QuickTileMaximize;
|
|
|
|
else
|
|
|
|
quick_tile_mode = QuickTileNone;
|
2011-01-30 17:34:42 +03:00
|
|
|
info->setState(NET::Max, NET::Max);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2012-03-16 03:15:13 +04:00
|
|
|
syncer.syncNow(); // important because of window rule updates!
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
updateAllowedActions();
|
2012-02-05 21:50:23 +04:00
|
|
|
updateWindowRules(Rules::MaximizeVert|Rules::MaximizeHoriz|Rules::Position|Rules::Size);
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
bool Client::isFullScreenable(bool fullscreen_hack) const
|
|
|
|
{
|
|
|
|
if (!rules()->checkFullScreen(true))
|
2007-04-29 21:35:43 +04:00
|
|
|
return false;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (fullscreen_hack)
|
2007-04-29 21:35:43 +04:00
|
|
|
return isNormalWindow();
|
2013-09-10 23:19:58 +04:00
|
|
|
if (rules()->checkStrictGeometry(true)) { // allow rule to ignore geometry constraints
|
2011-01-30 17:34:42 +03:00
|
|
|
QRect fsarea = workspace()->clientArea(FullScreenArea, this);
|
|
|
|
if (sizeForClientSize(fsarea.size(), SizemodeAny, true) != fsarea.size())
|
2013-09-10 23:19:58 +04:00
|
|
|
return false; // the app wouldn't fit exactly fullscreen geometry due to its strict geometry requirements
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
// don't check size constrains - some apps request fullscreen despite requesting fixed size
|
|
|
|
return !isSpecialWindow(); // also better disallow only weird types to go fullscreen
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
bool Client::userCanSetFullScreen() const
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (fullscreen_mode == FullScreenHack)
|
2007-04-29 21:35:43 +04:00
|
|
|
return false;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (!isFullScreenable(false))
|
2007-04-29 21:35:43 +04:00
|
|
|
return false;
|
2013-09-10 23:19:58 +04:00
|
|
|
return isNormalWindow() || isDialog();
|
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 Client::setFullScreen(bool set, bool user)
|
|
|
|
{
|
|
|
|
if (!isFullScreen() && !set)
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (fullscreen_mode == FullScreenHack)
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (user && !userCanSetFullScreen())
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
2011-01-30 17:34:42 +03:00
|
|
|
set = rules()->checkFullScreen(set);
|
|
|
|
setShade(ShadeNone);
|
2007-04-29 21:35:43 +04:00
|
|
|
bool was_fs = isFullScreen();
|
2012-05-18 21:06:21 +04:00
|
|
|
if (was_fs)
|
2013-02-26 11:45:44 +04:00
|
|
|
workspace()->updateFocusMousePosition(Cursor::pos());
|
2012-05-18 21:06:21 +04:00
|
|
|
else
|
2007-04-29 21:35:43 +04:00
|
|
|
geom_fs_restore = geometry();
|
|
|
|
fullscreen_mode = set ? FullScreenNormal : FullScreenNone;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (was_fs == isFullScreen())
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (set)
|
|
|
|
workspace()->raiseClient(this);
|
|
|
|
StackingUpdatesBlocker blocker1(workspace());
|
|
|
|
GeometryUpdatesBlocker blocker2(this);
|
|
|
|
workspace()->updateClientLayer(this); // active fullscreens get different layer
|
|
|
|
info->setState(isFullScreen() ? NET::FullScreen : 0, NET::FullScreen);
|
|
|
|
updateDecoration(false, false);
|
2012-03-18 03:56:30 +04:00
|
|
|
if (isFullScreen()) {
|
2011-01-30 17:34:42 +03:00
|
|
|
if (info->fullscreenMonitors().isSet())
|
|
|
|
setGeometry(fullscreenMonitorsArea(info->fullscreenMonitors()));
|
2008-11-17 11:03:39 +03:00
|
|
|
else
|
2011-01-30 17:34:42 +03:00
|
|
|
setGeometry(workspace()->clientArea(FullScreenArea, this));
|
2012-03-18 03:56:30 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
else {
|
2011-07-29 01:49:08 +04:00
|
|
|
if (!geom_fs_restore.isNull()) {
|
2011-09-29 20:14:31 +04:00
|
|
|
int currentScreen = screen();
|
2011-01-30 17:34:42 +03:00
|
|
|
setGeometry(QRect(geom_fs_restore.topLeft(), adjustedSize(geom_fs_restore.size())));
|
2011-09-29 20:14:31 +04:00
|
|
|
if( currentScreen != screen())
|
|
|
|
workspace()->sendClientToScreen( this, currentScreen );
|
2007-04-29 21:35:43 +04:00
|
|
|
// TODO isShaded() ?
|
2011-07-29 01:49:08 +04:00
|
|
|
} else {
|
2011-01-30 17:34:42 +03:00
|
|
|
// does this ever happen?
|
|
|
|
setGeometry(workspace()->clientArea(MaximizeArea, this));
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2012-02-05 21:50:23 +04:00
|
|
|
updateWindowRules(Rules::Fullscreen|Rules::Position|Rules::Size);
|
2011-01-30 17:34:42 +03:00
|
|
|
|
2011-12-22 18:34:55 +04:00
|
|
|
if (was_fs != isFullScreen()) {
|
2012-01-21 13:51:22 +04:00
|
|
|
emit clientFullScreenSet(this, set, user);
|
2011-12-22 18:34:55 +04:00
|
|
|
emit fullScreenChanged();
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2008-11-17 11:03:39 +03:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
void Client::updateFullscreenMonitors(NETFullscreenMonitors topology)
|
|
|
|
{
|
2013-04-03 14:19:27 +04:00
|
|
|
int nscreens = screens()->count();
|
2008-11-17 11:03:39 +03:00
|
|
|
|
2013-11-01 15:29:05 +04:00
|
|
|
// qDebug() << "incoming request with top: " << topology.top << " bottom: " << topology.bottom
|
2008-11-17 11:03:39 +03:00
|
|
|
// << " left: " << topology.left << " right: " << topology.right
|
|
|
|
// << ", we have: " << nscreens << " screens.";
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
if (topology.top >= nscreens ||
|
|
|
|
topology.bottom >= nscreens ||
|
|
|
|
topology.left >= nscreens ||
|
|
|
|
topology.right >= nscreens) {
|
2013-09-02 15:14:39 +04:00
|
|
|
qWarning() << "fullscreenMonitors update failed. request higher than number of screens.";
|
2011-01-30 17:34:42 +03:00
|
|
|
return;
|
2008-11-17 11:03:39 +03:00
|
|
|
}
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
info->setFullscreenMonitors(topology);
|
|
|
|
if (isFullScreen())
|
|
|
|
setGeometry(fullscreenMonitorsArea(topology));
|
|
|
|
}
|
|
|
|
|
2008-11-17 11:03:39 +03:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Calculates the bounding rectangle defined by the 4 monitor indices indicating the
|
|
|
|
top, bottom, left, and right edges of the window when the fullscreen state is enabled.
|
|
|
|
*/
|
|
|
|
QRect Client::fullscreenMonitorsArea(NETFullscreenMonitors requestedTopology) const
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2008-11-17 11:03:39 +03:00
|
|
|
QRect top, bottom, left, right, total;
|
|
|
|
|
2013-04-03 14:19:27 +04:00
|
|
|
top = screens()->geometry(requestedTopology.top);
|
|
|
|
bottom = screens()->geometry(requestedTopology.bottom);
|
|
|
|
left = screens()->geometry(requestedTopology.left);
|
|
|
|
right = screens()->geometry(requestedTopology.right);
|
2011-01-30 17:34:42 +03:00
|
|
|
total = top.united(bottom.united(left.united(right)));
|
2008-11-17 11:03:39 +03:00
|
|
|
|
2013-11-01 15:29:05 +04:00
|
|
|
// qDebug() << "top: " << top << " bottom: " << bottom
|
2008-11-17 11:03:39 +03:00
|
|
|
// << " left: " << left << " right: " << right;
|
2013-11-01 15:29:05 +04:00
|
|
|
// qDebug() << "returning rect: " << total;
|
2008-11-17 11:03:39 +03:00
|
|
|
return total;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2008-11-17 11:03:39 +03:00
|
|
|
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
int Client::checkFullScreenHack(const QRect& geom) const
|
|
|
|
{
|
2012-02-20 13:25:13 +04:00
|
|
|
if (!options->isLegacyFullscreenSupport())
|
2009-09-09 00:19:20 +04:00
|
|
|
return 0;
|
2007-04-29 21:35:43 +04:00
|
|
|
// if it's noborder window, and has size of one screen or the whole desktop geometry, it's fullscreen hack
|
2011-01-30 17:34:42 +03:00
|
|
|
if (noBorder() && app_noborder && isFullScreenable(true)) {
|
|
|
|
if (geom.size() == workspace()->clientArea(FullArea, geom.center(), desktop()).size())
|
2007-04-29 21:35:43 +04:00
|
|
|
return 2; // full area fullscreen hack
|
2011-01-30 17:34:42 +03:00
|
|
|
if (geom.size() == workspace()->clientArea(ScreenArea, geom.center(), desktop()).size())
|
2007-04-29 21:35:43 +04:00
|
|
|
return 1; // xinerama-aware fullscreen hack
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
void Client::updateFullScreenHack(const QRect& geom)
|
|
|
|
{
|
|
|
|
int type = checkFullScreenHack(geom);
|
|
|
|
if (fullscreen_mode == FullScreenNone && type != 0) {
|
2007-04-29 21:35:43 +04:00
|
|
|
fullscreen_mode = FullScreenHack;
|
2011-01-30 17:34:42 +03:00
|
|
|
updateDecoration(false, false);
|
2007-04-29 21:35:43 +04:00
|
|
|
QRect geom;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (rules()->checkStrictGeometry(false)) {
|
2007-04-29 21:35:43 +04:00
|
|
|
geom = type == 2 // 1 - it's xinerama-aware fullscreen hack, 2 - it's full area
|
2011-01-30 17:34:42 +03:00
|
|
|
? workspace()->clientArea(FullArea, geom.center(), desktop())
|
|
|
|
: workspace()->clientArea(ScreenArea, geom.center(), desktop());
|
|
|
|
} else
|
|
|
|
geom = workspace()->clientArea(FullScreenArea, geom.center(), desktop());
|
|
|
|
setGeometry(geom);
|
2011-12-22 18:34:55 +04:00
|
|
|
emit fullScreenChanged();
|
2011-01-30 17:34:42 +03:00
|
|
|
} else if (fullscreen_mode == FullScreenHack && type == 0) {
|
2007-04-29 21:35:43 +04:00
|
|
|
fullscreen_mode = FullScreenNone;
|
2011-01-30 17:34:42 +03:00
|
|
|
updateDecoration(false, false);
|
2007-04-29 21:35:43 +04:00
|
|
|
// whoever called this must setup correct geometry
|
2011-12-22 18:34:55 +04:00
|
|
|
emit fullScreenChanged();
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
StackingUpdatesBlocker blocker(workspace());
|
|
|
|
workspace()->updateClientLayer(this); // active fullscreens get different layer
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
static GeometryTip* geometryTip = 0;
|
|
|
|
|
|
|
|
void Client::positionGeometryTip()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
assert(isMove() || isResize());
|
2007-04-29 21:35:43 +04:00
|
|
|
// Position and Size display
|
2011-01-30 17:34:42 +03:00
|
|
|
if (effects && static_cast<EffectsHandlerImpl*>(effects)->provides(Effect::GeometryTip))
|
2010-11-10 22:21:56 +03:00
|
|
|
return; // some effect paints this for us
|
2011-01-30 17:34:42 +03:00
|
|
|
if (options->showGeometryTip()) {
|
|
|
|
if (!geometryTip) {
|
2013-05-02 17:22:03 +04:00
|
|
|
geometryTip = new GeometryTip(&xSizeHint);
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
QRect wgeom(moveResizeGeom); // position of the frame, size of the window itself
|
|
|
|
wgeom.setWidth(wgeom.width() - (width() - clientSize().width()));
|
|
|
|
wgeom.setHeight(wgeom.height() - (height() - clientSize().height()));
|
|
|
|
if (isShade())
|
|
|
|
wgeom.setHeight(0);
|
|
|
|
geometryTip->setGeometry(wgeom);
|
|
|
|
if (!geometryTip->isVisible())
|
2007-04-29 21:35:43 +04:00
|
|
|
geometryTip->show();
|
2008-06-20 20:21:03 +04:00
|
|
|
geometryTip->raise();
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2012-06-13 21:38:27 +04:00
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
bool Client::startMoveResize()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
assert(!moveResizeMode);
|
|
|
|
assert(QWidget::keyboardGrabber() == NULL);
|
|
|
|
assert(QWidget::mouseGrabber() == NULL);
|
2007-05-22 19:46:42 +04:00
|
|
|
stopDelayedMoveResize();
|
2011-01-30 17:34:42 +03:00
|
|
|
if (QApplication::activePopupWidget() != NULL)
|
2007-04-29 21:35:43 +04:00
|
|
|
return false; // popups have grab
|
|
|
|
bool has_grab = false;
|
|
|
|
// This reportedly improves smoothness of the moveresize operation,
|
|
|
|
// something with Enter/LeaveNotify events, looks like XFree performance problem or something *shrug*
|
|
|
|
// (http://lists.kde.org/?t=107302193400001&r=1&w=2)
|
2011-01-30 17:34:42 +03:00
|
|
|
QRect r = workspace()->clientArea(FullArea, this);
|
2013-05-02 21:04:43 +04:00
|
|
|
m_moveResizeGrabWindow.create(r, XCB_WINDOW_CLASS_INPUT_ONLY, 0, NULL, rootWindow());
|
|
|
|
m_moveResizeGrabWindow.map();
|
|
|
|
m_moveResizeGrabWindow.raise();
|
|
|
|
const xcb_grab_pointer_cookie_t cookie = xcb_grab_pointer_unchecked(connection(), false, m_moveResizeGrabWindow,
|
|
|
|
XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION |
|
|
|
|
XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW,
|
|
|
|
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, m_moveResizeGrabWindow, Cursor::x11Cursor(m_cursor), xTime());
|
|
|
|
ScopedCPointer<xcb_grab_pointer_reply_t> pointerGrab(xcb_grab_pointer_reply(connection(), cookie, NULL));
|
|
|
|
if (!pointerGrab.isNull() && pointerGrab->status == XCB_GRAB_STATUS_SUCCESS) {
|
2007-04-29 21:35:43 +04:00
|
|
|
has_grab = true;
|
2013-05-02 21:04:43 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
if (grabXKeyboard(frameId()))
|
2007-04-29 21:35:43 +04:00
|
|
|
has_grab = move_resize_has_keyboard_grab = true;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (!has_grab) { // at least one grab is necessary in order to be able to finish move/resize
|
2013-05-02 21:04:43 +04:00
|
|
|
m_moveResizeGrabWindow.reset();
|
2007-04-29 21:35:43 +04:00
|
|
|
return false;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2011-03-08 00:31:44 +03:00
|
|
|
|
2012-03-20 01:45:50 +04:00
|
|
|
moveResizeMode = true;
|
|
|
|
workspace()->setClientIsMoving(this);
|
|
|
|
|
2013-03-15 00:54:40 +04:00
|
|
|
if (mode != PositionCenter) { // means "isResize()" but moveResizeMode = true is set below
|
|
|
|
if (maximizeMode() == MaximizeFull) { // partial is cond. reset in finishMoveResize
|
|
|
|
geom_restore = geometry(); // "restore" to current geometry
|
|
|
|
setMaximize(false, false);
|
2012-11-01 23:54:26 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2011-03-08 00:31:44 +03:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
if (quick_tile_mode != QuickTileNone && mode != PositionCenter) { // Cannot use isResize() yet
|
|
|
|
// Exit quick tile mode when the user attempts to resize a tiled window
|
2009-10-14 13:33:00 +04:00
|
|
|
quick_tile_mode = QuickTileNone; // Do so without restoring original geometry
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2009-09-13 21:09:44 +04:00
|
|
|
|
2011-12-09 23:44:06 +04:00
|
|
|
s_haveResizeEffect = effects && static_cast<EffectsHandlerImpl*>(effects)->provides(Effect::Resize);
|
2012-06-25 23:54:00 +04:00
|
|
|
moveResizeStartScreen = screen();
|
2007-04-29 21:35:43 +04:00
|
|
|
initialMoveResizeGeom = moveResizeGeom = geometry();
|
|
|
|
checkUnrestrictedMoveResize();
|
2011-03-13 14:41:30 +03:00
|
|
|
emit clientStartUserMovedResized(this);
|
2011-07-07 20:29:11 +04:00
|
|
|
#ifdef KWIN_BUILD_SCREENEDGES
|
2013-01-25 13:15:00 +04:00
|
|
|
if (ScreenEdges::self()->isDesktopSwitchingMovingClients())
|
|
|
|
ScreenEdges::self()->reserveDesktopSwitching(true, Qt::Vertical|Qt::Horizontal);
|
2011-07-07 20:29:11 +04:00
|
|
|
#endif
|
2011-01-30 17:34:42 +03:00
|
|
|
return true;
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
void Client::finishMoveResize(bool cancel)
|
|
|
|
{
|
2012-05-09 23:33:23 +04:00
|
|
|
const bool wasResize = isResize(); // store across leaveMoveResize
|
|
|
|
leaveMoveResize();
|
|
|
|
|
2012-07-13 11:53:21 +04:00
|
|
|
if (cancel)
|
|
|
|
setGeometry(initialMoveResizeGeom);
|
|
|
|
else {
|
|
|
|
if (wasResize) {
|
|
|
|
const bool restoreH = maximizeMode() == MaximizeHorizontal &&
|
|
|
|
moveResizeGeom.width() != initialMoveResizeGeom.width();
|
|
|
|
const bool restoreV = maximizeMode() == MaximizeVertical &&
|
|
|
|
moveResizeGeom.height() != initialMoveResizeGeom.height();
|
2013-04-14 11:44:36 +04:00
|
|
|
if (restoreH || restoreV) {
|
|
|
|
changeMaximize(restoreV, restoreH, false);
|
|
|
|
}
|
2012-05-09 23:33:23 +04:00
|
|
|
}
|
2012-07-13 11:53:21 +04:00
|
|
|
setGeometry(moveResizeGeom);
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2013-04-15 22:33:01 +04:00
|
|
|
checkScreen(); // needs to be done because clientFinishUserMovedResized has not yet re-activated online alignment
|
|
|
|
if (screen() != moveResizeStartScreen) {
|
|
|
|
workspace()->sendClientToScreen(this, screen()); // checks rule validity
|
2012-08-24 20:48:50 +04:00
|
|
|
if (maximizeMode() != MaximizeRestore)
|
|
|
|
checkWorkspacePosition();
|
|
|
|
}
|
2010-04-25 20:43:14 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
if (isElectricBorderMaximizing()) {
|
2011-03-08 00:31:44 +03:00
|
|
|
setQuickTileMode(electricMode);
|
2009-09-17 12:11:01 +04:00
|
|
|
electricMaximizing = false;
|
2013-04-25 10:14:34 +04:00
|
|
|
outline()->hide();
|
2013-04-25 11:40:13 +04:00
|
|
|
elevate(false);
|
2012-04-11 20:18:50 +04:00
|
|
|
} else if (!cancel) {
|
2012-05-09 23:33:23 +04:00
|
|
|
if (!(maximizeMode() & MaximizeHorizontal)) {
|
|
|
|
geom_restore.setX(geometry().x());
|
|
|
|
geom_restore.setWidth(geometry().width());
|
|
|
|
}
|
|
|
|
if (!(maximizeMode() & MaximizeVertical)) {
|
|
|
|
geom_restore.setY(geometry().y());
|
|
|
|
geom_restore.setHeight(geometry().height());
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
// FRAME update();
|
2010-04-25 20:43:14 +04:00
|
|
|
|
2011-03-13 14:41:30 +03:00
|
|
|
emit clientFinishUserMovedResized(this);
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
void Client::leaveMoveResize()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2012-11-08 03:54:05 +04:00
|
|
|
if (needsXWindowMove) {
|
|
|
|
// Do the deferred move
|
2013-09-10 10:37:49 +04:00
|
|
|
m_frame.move(geom.topLeft());
|
2012-11-08 03:54:05 +04:00
|
|
|
needsXWindowMove = false;
|
|
|
|
}
|
2012-12-30 01:27:31 +04:00
|
|
|
if (!isResize())
|
|
|
|
sendSyntheticConfigureNotify(); // tell the client about it's new final position
|
2011-01-30 17:34:42 +03:00
|
|
|
if (geometryTip) {
|
2007-04-29 21:35:43 +04:00
|
|
|
geometryTip->hide();
|
|
|
|
delete geometryTip;
|
|
|
|
geometryTip = NULL;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
if (move_resize_has_keyboard_grab)
|
2007-04-29 21:35:43 +04:00
|
|
|
ungrabXKeyboard();
|
|
|
|
move_resize_has_keyboard_grab = false;
|
2013-09-10 13:34:34 +04:00
|
|
|
xcb_ungrab_pointer(connection(), xTime());
|
2013-05-02 21:04:43 +04:00
|
|
|
m_moveResizeGrabWindow.reset();
|
2007-04-29 21:35:43 +04:00
|
|
|
workspace()->setClientIsMoving(0);
|
|
|
|
moveResizeMode = false;
|
2013-07-31 12:11:39 +04:00
|
|
|
if (syncRequest.counter == XCB_NONE) // don't forget to sanitize since the timeout will no more fire
|
2012-10-28 16:53:08 +04:00
|
|
|
syncRequest.isPending = false;
|
2011-08-13 18:39:58 +04:00
|
|
|
delete syncRequest.timeout;
|
|
|
|
syncRequest.timeout = NULL;
|
2011-07-07 20:29:11 +04:00
|
|
|
#ifdef KWIN_BUILD_SCREENEDGES
|
2013-01-25 13:15:00 +04:00
|
|
|
if (ScreenEdges::self()->isDesktopSwitchingMovingClients())
|
|
|
|
ScreenEdges::self()->reserveDesktopSwitching(false, Qt::Vertical|Qt::Horizontal);
|
2011-07-07 20:29:11 +04:00
|
|
|
#endif
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
// This function checks if it actually makes sense to perform a restricted move/resize.
|
|
|
|
// If e.g. the titlebar is already outside of the workarea, there's no point in performing
|
|
|
|
// a restricted move resize, because then e.g. resize would also move the window (#74555).
|
|
|
|
// NOTE: Most of it is duplicated from handleMoveResize().
|
|
|
|
void Client::checkUnrestrictedMoveResize()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (unrestrictedMoveResize)
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
2011-01-30 17:34:42 +03:00
|
|
|
QRect desktopArea = workspace()->clientArea(WorkArea, moveResizeGeom.center(), desktop());
|
2007-04-29 21:35:43 +04:00
|
|
|
int left_marge, right_marge, top_marge, bottom_marge, titlebar_marge;
|
2008-07-25 14:16:09 +04:00
|
|
|
// restricted move/resize - keep at least part of the titlebar always visible
|
2007-04-29 21:35:43 +04:00
|
|
|
// how much must remain visible when moved away in that direction
|
2011-01-30 17:34:42 +03:00
|
|
|
left_marge = qMin(100 + border_right, moveResizeGeom.width());
|
|
|
|
right_marge = qMin(100 + border_left, moveResizeGeom.width());
|
2007-04-29 21:35:43 +04:00
|
|
|
// width/height change with opaque resizing, use the initial ones
|
|
|
|
titlebar_marge = initialMoveResizeGeom.height();
|
|
|
|
top_marge = border_bottom;
|
|
|
|
bottom_marge = border_top;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (isResize()) {
|
|
|
|
if (moveResizeGeom.bottom() < desktopArea.top() + top_marge)
|
2007-04-29 21:35:43 +04:00
|
|
|
unrestrictedMoveResize = true;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (moveResizeGeom.top() > desktopArea.bottom() - bottom_marge)
|
2007-04-29 21:35:43 +04:00
|
|
|
unrestrictedMoveResize = true;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (moveResizeGeom.right() < desktopArea.left() + left_marge)
|
2007-04-29 21:35:43 +04:00
|
|
|
unrestrictedMoveResize = true;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (moveResizeGeom.left() > desktopArea.right() - right_marge)
|
2007-04-29 21:35:43 +04:00
|
|
|
unrestrictedMoveResize = true;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (!unrestrictedMoveResize && moveResizeGeom.top() < desktopArea.top()) // titlebar mustn't go out
|
2007-04-29 21:35:43 +04:00
|
|
|
unrestrictedMoveResize = true;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
if (isMove()) {
|
2012-04-17 03:24:28 +04:00
|
|
|
if (moveResizeGeom.bottom() < desktopArea.top() + titlebar_marge - 1)
|
2007-04-29 21:35:43 +04:00
|
|
|
unrestrictedMoveResize = true;
|
|
|
|
// no need to check top_marge, titlebar_marge already handles it
|
2012-04-17 03:24:28 +04:00
|
|
|
if (moveResizeGeom.top() > desktopArea.bottom() - bottom_marge + 1) // titlebar mustn't go out
|
2007-04-29 21:35:43 +04:00
|
|
|
unrestrictedMoveResize = true;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (moveResizeGeom.right() < desktopArea.left() + left_marge)
|
2007-04-29 21:35:43 +04:00
|
|
|
unrestrictedMoveResize = true;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (moveResizeGeom.left() > desktopArea.right() - right_marge)
|
2007-04-29 21:35:43 +04:00
|
|
|
unrestrictedMoveResize = true;
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2007-05-22 19:46:42 +04:00
|
|
|
// When the user pressed mouse on the titlebar, don't activate move immediatelly,
|
|
|
|
// since it may be just a click. Activate instead after a delay. Move used to be
|
|
|
|
// activated only after moving by several pixels, but that looks bad.
|
|
|
|
void Client::startDelayedMoveResize()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2007-05-22 19:46:42 +04:00
|
|
|
delete delayedMoveResizeTimer;
|
2011-01-30 17:34:42 +03:00
|
|
|
delayedMoveResizeTimer = new QTimer(this);
|
|
|
|
connect(delayedMoveResizeTimer, SIGNAL(timeout()), this, SLOT(delayedMoveResize()));
|
|
|
|
delayedMoveResizeTimer->setSingleShot(true);
|
|
|
|
delayedMoveResizeTimer->start(QApplication::startDragTime());
|
|
|
|
}
|
2007-05-22 19:46:42 +04:00
|
|
|
|
|
|
|
void Client::stopDelayedMoveResize()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2007-05-22 19:46:42 +04:00
|
|
|
delete delayedMoveResizeTimer;
|
|
|
|
delayedMoveResizeTimer = NULL;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-05-22 19:46:42 +04:00
|
|
|
|
|
|
|
void Client::delayedMoveResize()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
assert(buttonDown);
|
|
|
|
if (!startMoveResize())
|
2007-05-22 19:46:42 +04:00
|
|
|
buttonDown = false;
|
|
|
|
updateCursor();
|
|
|
|
stopDelayedMoveResize();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-05-22 19:46:42 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
void Client::handleMoveResize(int x, int y, int x_root, int y_root)
|
|
|
|
{
|
2011-08-13 18:39:58 +04:00
|
|
|
if (syncRequest.isPending && isResize())
|
|
|
|
return; // we're still waiting for the client or the timeout
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
if ((mode == PositionCenter && !isMovableAcrossScreens())
|
|
|
|
|| (mode != PositionCenter && (isShade() || !isResizable())))
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
if (!moveResizeMode) {
|
|
|
|
QPoint p(QPoint(x - padding_left, y - padding_top) - moveOffset);
|
2013-09-04 18:33:51 +04:00
|
|
|
if (p.manhattanLength() >= QApplication::startDragDistance()) {
|
2011-01-30 17:34:42 +03:00
|
|
|
if (!startMoveResize()) {
|
2007-04-29 21:35:43 +04:00
|
|
|
buttonDown = false;
|
2007-05-22 19:46:42 +04:00
|
|
|
updateCursor();
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
updateCursor();
|
|
|
|
} else
|
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
|
|
|
|
|
|
|
// ShadeHover or ShadeActive, ShadeNormal was already avoided above
|
2011-01-30 17:34:42 +03:00
|
|
|
if (mode != PositionCenter && shade_mode != ShadeNone)
|
|
|
|
setShade(ShadeNone);
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
QPoint globalPos(x_root, y_root);
|
2007-04-29 21:35:43 +04:00
|
|
|
// these two points limit the geometry rectangle, i.e. if bottomleft resizing is done,
|
|
|
|
// the bottomleft corner should be at is at (topleft.x(), bottomright().y())
|
|
|
|
QPoint topleft = globalPos - moveOffset;
|
|
|
|
QPoint bottomright = globalPos + invertedMoveOffset;
|
|
|
|
QRect previousMoveResizeGeom = moveResizeGeom;
|
|
|
|
|
|
|
|
// TODO move whole group when moving its leader or when the leader is not mapped?
|
|
|
|
|
2009-02-17 18:50:00 +03:00
|
|
|
// When doing a restricted move we must always keep 100px of the titlebar
|
|
|
|
// visible to allow the user to be able to move it again.
|
|
|
|
int frameLeft, frameRight, frameTop, frameBottom;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (decoration)
|
|
|
|
decoration->borders(frameLeft, frameRight, frameTop, frameBottom);
|
2009-02-17 18:50:00 +03:00
|
|
|
else
|
|
|
|
frameTop = 10;
|
2011-01-30 17:34:42 +03:00
|
|
|
int titlebarArea = qMin(frameTop * 100, moveResizeGeom.width() * moveResizeGeom.height());
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
bool update = false;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (isResize()) {
|
2007-04-29 21:35:43 +04:00
|
|
|
// first resize (without checking constrains), then snap, then check bounds, then check constrains
|
|
|
|
QRect orig = initialMoveResizeGeom;
|
|
|
|
Sizemode sizemode = SizemodeAny;
|
2011-01-30 17:34:42 +03:00
|
|
|
switch(mode) {
|
|
|
|
case PositionTopLeft:
|
|
|
|
moveResizeGeom = QRect(topleft, orig.bottomRight()) ;
|
|
|
|
break;
|
|
|
|
case PositionBottomRight:
|
|
|
|
moveResizeGeom = QRect(orig.topLeft(), bottomright) ;
|
|
|
|
break;
|
|
|
|
case PositionBottomLeft:
|
|
|
|
moveResizeGeom = QRect(QPoint(topleft.x(), orig.y()), QPoint(orig.right(), bottomright.y())) ;
|
|
|
|
break;
|
|
|
|
case PositionTopRight:
|
|
|
|
moveResizeGeom = QRect(QPoint(orig.x(), topleft.y()), QPoint(bottomright.x(), orig.bottom())) ;
|
|
|
|
break;
|
|
|
|
case PositionTop:
|
|
|
|
moveResizeGeom = QRect(QPoint(orig.left(), topleft.y()), orig.bottomRight()) ;
|
|
|
|
sizemode = SizemodeFixedH; // try not to affect height
|
|
|
|
break;
|
|
|
|
case PositionBottom:
|
|
|
|
moveResizeGeom = QRect(orig.topLeft(), QPoint(orig.right(), bottomright.y())) ;
|
|
|
|
sizemode = SizemodeFixedH;
|
|
|
|
break;
|
|
|
|
case PositionLeft:
|
|
|
|
moveResizeGeom = QRect(QPoint(topleft.x(), orig.top()), orig.bottomRight()) ;
|
|
|
|
sizemode = SizemodeFixedW;
|
|
|
|
break;
|
|
|
|
case PositionRight:
|
|
|
|
moveResizeGeom = QRect(orig.topLeft(), QPoint(bottomright.x(), orig.bottom())) ;
|
|
|
|
sizemode = SizemodeFixedW;
|
|
|
|
break;
|
|
|
|
case PositionCenter:
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
break;
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
// adjust new size to snap to other windows/borders
|
2011-01-30 17:34:42 +03:00
|
|
|
moveResizeGeom = workspace()->adjustClientSize(this, moveResizeGeom, mode);
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
if (!unrestrictedMoveResize) {
|
2009-03-18 05:34:07 +03:00
|
|
|
// Make sure the titlebar isn't behind a restricted area. We don't need to restrict
|
|
|
|
// the other directions. If not visible enough, move the window to the closest valid
|
|
|
|
// point. We bruteforce this by slowly moving the window back to its previous position.
|
2011-01-30 17:34:42 +03:00
|
|
|
for (;;) {
|
|
|
|
QRegion titlebarRegion(moveResizeGeom.left(), moveResizeGeom.top(),
|
|
|
|
moveResizeGeom.width(), frameTop);
|
|
|
|
titlebarRegion &= workspace()->clientArea(FullArea, -1, 0); // On the screen
|
|
|
|
titlebarRegion -= workspace()->restrictedMoveArea(desktop()); // Strut areas
|
2009-03-18 05:34:07 +03:00
|
|
|
// Now we have a region of all the visible areas of the titlebar
|
|
|
|
// Count the visible pixels and check to see if it's enough
|
|
|
|
int visiblePixels = 0;
|
2011-01-30 17:34:42 +03:00
|
|
|
foreach (const QRect & rect, titlebarRegion.rects())
|
|
|
|
if (rect.height() >= frameTop) // Only the full height regions, prevents long slim areas
|
|
|
|
visiblePixels += rect.width() * rect.height();
|
|
|
|
if (visiblePixels >= titlebarArea)
|
2009-03-18 05:34:07 +03:00
|
|
|
break; // We have reached a valid position
|
|
|
|
|
|
|
|
// Not visible enough, move the window to the closest valid point. We bruteforce
|
|
|
|
// this by slowly moving the window back to its previous position.
|
2011-01-30 17:34:42 +03:00
|
|
|
if (previousMoveResizeGeom.y() != moveResizeGeom.y()) {
|
|
|
|
if (previousMoveResizeGeom.y() > moveResizeGeom.y())
|
|
|
|
moveResizeGeom.setTop(moveResizeGeom.y() + 1);
|
2009-03-18 05:34:07 +03:00
|
|
|
else
|
2011-01-30 17:34:42 +03:00
|
|
|
moveResizeGeom.setTop(moveResizeGeom.y() - 1);
|
|
|
|
} else { // Our heights match but we still don't have a valid area, maybe
|
|
|
|
// we are trying to resize in from the side?
|
2009-03-18 05:34:07 +03:00
|
|
|
bool breakLoop = false;
|
2011-01-30 17:34:42 +03:00
|
|
|
switch(mode) {
|
2013-07-18 17:59:37 +04:00
|
|
|
case PositionBottomLeft:
|
2011-01-30 17:34:42 +03:00
|
|
|
case PositionTopLeft:
|
|
|
|
case PositionLeft:
|
|
|
|
if (previousMoveResizeGeom.x() >= moveResizeGeom.x()) {
|
|
|
|
breakLoop = true;
|
2009-02-17 18:50:00 +03:00
|
|
|
break;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
moveResizeGeom.setLeft(moveResizeGeom.x() - 1);
|
|
|
|
break;
|
2013-07-18 17:59:37 +04:00
|
|
|
case PositionBottomRight:
|
2011-01-30 17:34:42 +03:00
|
|
|
case PositionTopRight:
|
|
|
|
case PositionRight:
|
|
|
|
if (previousMoveResizeGeom.right() <= moveResizeGeom.right()) {
|
2009-03-18 05:34:07 +03:00
|
|
|
breakLoop = true;
|
2011-01-30 17:34:42 +03:00
|
|
|
break;
|
2009-03-18 05:34:07 +03:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
moveResizeGeom.setRight(moveResizeGeom.x() + moveResizeGeom.width());
|
2009-02-17 18:50:00 +03:00
|
|
|
break;
|
2011-01-30 17:34:42 +03:00
|
|
|
default:
|
|
|
|
breakLoop = true;
|
2009-02-17 18:50:00 +03:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
if (breakLoop)
|
|
|
|
break;
|
2009-02-17 18:50:00 +03:00
|
|
|
}
|
2009-06-26 13:06:48 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2009-06-26 13:06:48 +04:00
|
|
|
// Always obey size hints, even when in "unrestricted" mode
|
2011-01-30 17:34:42 +03:00
|
|
|
QSize size = adjustedSize(moveResizeGeom.size(), sizemode);
|
2009-06-26 13:06:48 +04:00
|
|
|
// the new topleft and bottomright corners (after checking size constrains), if they'll be needed
|
2011-01-30 17:34:42 +03:00
|
|
|
topleft = QPoint(moveResizeGeom.right() - size.width() + 1, moveResizeGeom.bottom() - size.height() + 1);
|
|
|
|
bottomright = QPoint(moveResizeGeom.left() + size.width() - 1, moveResizeGeom.top() + size.height() - 1);
|
2009-06-26 13:06:48 +04:00
|
|
|
orig = moveResizeGeom;
|
2011-01-30 17:34:42 +03:00
|
|
|
switch(mode) {
|
|
|
|
// these 4 corners ones are copied from above
|
|
|
|
case PositionTopLeft:
|
|
|
|
moveResizeGeom = QRect(topleft, orig.bottomRight()) ;
|
|
|
|
break;
|
|
|
|
case PositionBottomRight:
|
|
|
|
moveResizeGeom = QRect(orig.topLeft(), bottomright) ;
|
|
|
|
break;
|
|
|
|
case PositionBottomLeft:
|
|
|
|
moveResizeGeom = QRect(QPoint(topleft.x(), orig.y()), QPoint(orig.right(), bottomright.y())) ;
|
|
|
|
break;
|
|
|
|
case PositionTopRight:
|
|
|
|
moveResizeGeom = QRect(QPoint(orig.x(), topleft.y()), QPoint(bottomright.x(), orig.bottom())) ;
|
|
|
|
break;
|
2009-06-26 13:06:48 +04:00
|
|
|
// The side ones can't be copied exactly - if aspect ratios are specified, both dimensions may change.
|
|
|
|
// Therefore grow to the right/bottom if needed.
|
|
|
|
// TODO it should probably obey gravity rather than always using right/bottom ?
|
2011-01-30 17:34:42 +03:00
|
|
|
case PositionTop:
|
|
|
|
moveResizeGeom = QRect(QPoint(orig.left(), topleft.y()), QPoint(bottomright.x(), orig.bottom())) ;
|
|
|
|
break;
|
|
|
|
case PositionBottom:
|
|
|
|
moveResizeGeom = QRect(orig.topLeft(), QPoint(bottomright.x(), bottomright.y())) ;
|
|
|
|
break;
|
|
|
|
case PositionLeft:
|
|
|
|
moveResizeGeom = QRect(QPoint(topleft.x(), orig.top()), QPoint(orig.right(), bottomright.y()));
|
|
|
|
break;
|
|
|
|
case PositionRight:
|
|
|
|
moveResizeGeom = QRect(orig.topLeft(), QPoint(bottomright.x(), bottomright.y())) ;
|
|
|
|
break;
|
|
|
|
case PositionCenter:
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
break;
|
|
|
|
}
|
2009-06-26 13:06:48 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
if (moveResizeGeom.size() != previousMoveResizeGeom.size())
|
2007-04-29 21:35:43 +04:00
|
|
|
update = true;
|
2011-01-30 17:34:42 +03:00
|
|
|
} else if (isMove()) {
|
|
|
|
assert(mode == PositionCenter);
|
|
|
|
if (!isMovable()) { // isMovableAcrossScreens() must have been true to get here
|
|
|
|
// Special moving of maximized windows on Xinerama screens
|
2013-04-03 14:19:27 +04:00
|
|
|
int screen = screens()->number(globalPos);
|
2011-08-10 00:43:43 +04:00
|
|
|
if (isFullScreen())
|
|
|
|
moveResizeGeom = workspace()->clientArea(FullScreenArea, screen, 0);
|
|
|
|
else {
|
|
|
|
moveResizeGeom = workspace()->clientArea(MaximizeArea, screen, 0);
|
|
|
|
QSize adjSize = adjustedSize(moveResizeGeom.size(), SizemodeMax);
|
|
|
|
if (adjSize != moveResizeGeom.size()) {
|
|
|
|
QRect r(moveResizeGeom);
|
|
|
|
moveResizeGeom.setSize(adjSize);
|
|
|
|
moveResizeGeom.moveCenter(r.center());
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
} else {
|
2008-07-25 14:31:47 +04:00
|
|
|
// first move, then snap, then check bounds
|
2011-01-30 17:34:42 +03:00
|
|
|
moveResizeGeom.moveTopLeft(topleft);
|
|
|
|
moveResizeGeom.moveTopLeft(workspace()->adjustClientPosition(this, moveResizeGeom.topLeft(),
|
|
|
|
unrestrictedMoveResize));
|
2009-02-17 18:50:00 +03:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
if (!unrestrictedMoveResize) {
|
2009-03-18 05:34:07 +03:00
|
|
|
// Make sure the titlebar isn't behind a restricted area.
|
2012-06-13 21:38:27 +04:00
|
|
|
const QRegion fullArea = workspace()->clientArea(FullArea, this); // On the screen
|
|
|
|
const QRegion strut = workspace()->restrictedMoveArea(desktop()); // Strut areas
|
2011-01-30 17:34:42 +03:00
|
|
|
for (;;) {
|
|
|
|
QRegion titlebarRegion(moveResizeGeom.left(), moveResizeGeom.top(),
|
|
|
|
moveResizeGeom.width(), frameTop);
|
2012-03-12 02:12:04 +04:00
|
|
|
titlebarRegion &= fullArea;
|
2012-06-13 21:38:27 +04:00
|
|
|
titlebarRegion -= strut; // Strut areas
|
2009-03-18 05:34:07 +03:00
|
|
|
// Now we have a region of all the visible areas of the titlebar
|
|
|
|
// Count the visible pixels and check to see if it's enough
|
|
|
|
int visiblePixels = 0;
|
2011-01-30 17:34:42 +03:00
|
|
|
foreach (const QRect & rect, titlebarRegion.rects())
|
2012-03-12 02:12:04 +04:00
|
|
|
if (rect.height() >= frameTop) // Only the full height regions, prevents long slim areas
|
|
|
|
visiblePixels += rect.width() * rect.height();
|
2011-01-30 17:34:42 +03:00
|
|
|
if (visiblePixels >= titlebarArea)
|
2009-03-18 05:34:07 +03:00
|
|
|
break; // We have reached a valid position
|
|
|
|
|
2012-06-13 21:38:27 +04:00
|
|
|
// (esp.) if there're more screens with different struts (panels) it the titlebar
|
|
|
|
// will be movable outside the movearea (covering one of the panels) until it
|
|
|
|
// crosses the panel "too much" (not enough visiblePixels) and then stucks because
|
|
|
|
// it's usually only pushed by 1px to either direction
|
|
|
|
// so we first check whether we intersect suc strut and move the window below it
|
|
|
|
// immediately (it's still possible to hit the visiblePixels >= titlebarArea break
|
|
|
|
// by moving the window slightly downwards, but it won't stuck)
|
|
|
|
// see bug #274466
|
|
|
|
// and bug #301805 for why we can't just match the titlearea against the screen
|
2013-04-03 14:19:27 +04:00
|
|
|
if (screens()->count() > 1) { // optimization
|
2012-06-13 21:38:27 +04:00
|
|
|
// TODO: could be useful on partial screen struts (half-width panels etc.)
|
|
|
|
int newTitleTop = -1;
|
|
|
|
foreach (const QRect &r, strut.rects()) {
|
|
|
|
if (r.top() == 0 && r.width() > r.height() && // "top panel"
|
|
|
|
r.intersects(moveResizeGeom) && moveResizeGeom.top() < r.bottom()) {
|
|
|
|
newTitleTop = r.bottom();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (newTitleTop > -1) {
|
|
|
|
moveResizeGeom.moveTop(newTitleTop); // invalid position, possibly on screen change
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-18 18:22:34 +04:00
|
|
|
int dx = sign(previousMoveResizeGeom.x() - moveResizeGeom.x()),
|
|
|
|
dy = sign(previousMoveResizeGeom.y() - moveResizeGeom.y());
|
|
|
|
if (visiblePixels && dx) // means there's no full width cap -> favor horizontally
|
|
|
|
dy = 0;
|
|
|
|
else if (dy)
|
|
|
|
dx = 0;
|
|
|
|
|
|
|
|
// Move it back
|
|
|
|
moveResizeGeom.translate(dx, dy);
|
|
|
|
|
2012-06-13 21:38:27 +04:00
|
|
|
if (moveResizeGeom == previousMoveResizeGeom) {
|
2009-03-18 05:34:07 +03:00
|
|
|
break; // Prevent lockup
|
2012-06-13 21:38:27 +04:00
|
|
|
}
|
2009-02-17 18:50:00 +03:00
|
|
|
}
|
2008-07-25 14:31:47 +04:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
if (moveResizeGeom.topLeft() != previousMoveResizeGeom.topLeft())
|
|
|
|
update = true;
|
|
|
|
} else
|
2008-09-17 15:44:51 +04:00
|
|
|
abort();
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-08-13 18:39:58 +04:00
|
|
|
if (!update)
|
|
|
|
return;
|
2007-06-25 12:51:44 +04:00
|
|
|
|
2012-10-28 16:53:08 +04:00
|
|
|
if (isResize() && !s_haveResizeEffect) {
|
2011-08-13 18:39:58 +04:00
|
|
|
if (!syncRequest.timeout) {
|
|
|
|
syncRequest.timeout = new QTimer(this);
|
|
|
|
connect(syncRequest.timeout, SIGNAL(timeout()), SLOT(performMoveResize()));
|
|
|
|
syncRequest.timeout->setSingleShot(true);
|
|
|
|
}
|
2013-07-31 12:11:39 +04:00
|
|
|
if (syncRequest.counter != XCB_NONE) {
|
2012-10-28 16:53:08 +04:00
|
|
|
syncRequest.timeout->start(250);
|
|
|
|
sendSyncRequest();
|
|
|
|
} else { // for clients not supporting the XSYNC protocol, we
|
|
|
|
syncRequest.isPending = true; // limit the resizes to 30Hz to take pointless load from X11
|
2012-12-30 01:27:31 +04:00
|
|
|
syncRequest.timeout->start(33); // and the client, the mouse is still moved at full speed
|
2012-10-28 16:53:08 +04:00
|
|
|
} // and no human can control faster resizes anyway
|
2013-09-10 09:45:17 +04:00
|
|
|
m_client.setGeometry(0, 0, moveResizeGeom.width() - (border_left + border_right), moveResizeGeom.height() - (border_top + border_bottom));
|
2011-08-13 18:39:58 +04:00
|
|
|
} else
|
2007-06-25 12:51:44 +04:00
|
|
|
performMoveResize();
|
2010-04-25 20:43:14 +04:00
|
|
|
|
2011-07-07 20:29:11 +04:00
|
|
|
#ifdef KWIN_BUILD_SCREENEDGES
|
2013-01-25 13:15:00 +04:00
|
|
|
if (isMove()) {
|
|
|
|
ScreenEdges::self()->check(globalPos, QDateTime::fromMSecsSinceEpoch(xTime()));
|
2007-06-25 12:51:44 +04:00
|
|
|
}
|
2013-01-25 13:15:00 +04:00
|
|
|
#endif
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-06-25 12:51:44 +04:00
|
|
|
|
|
|
|
void Client::performMoveResize()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2012-07-13 11:53:21 +04:00
|
|
|
if (isMove() || (isResize() && !s_haveResizeEffect)) {
|
|
|
|
setGeometry(moveResizeGeom);
|
2011-12-09 23:44:06 +04:00
|
|
|
}
|
2013-07-31 12:11:39 +04:00
|
|
|
if (syncRequest.counter == XCB_NONE) // client w/o XSYNC support. allow the next resize event
|
2012-10-28 16:53:08 +04:00
|
|
|
syncRequest.isPending = false; // NEVER do this for clients with a valid counter
|
|
|
|
// (leads to sync request races in some clients)
|
|
|
|
if (isResize())
|
2011-08-13 18:39:58 +04:00
|
|
|
addRepaintFull();
|
2011-05-21 23:15:06 +04:00
|
|
|
positionGeometryTip();
|
2011-03-13 14:41:30 +03:00
|
|
|
emit clientStepUserMovedResized(this, moveResizeGeom);
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-03-08 00:31:44 +03:00
|
|
|
void Client::setElectricBorderMode(QuickTileMode mode)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2011-03-08 00:31:44 +03:00
|
|
|
if (mode != QuickTileMaximize) {
|
|
|
|
// sanitize the mode, ie. simplify "invalid" combinations
|
|
|
|
if ((mode & QuickTileHorizontal) == QuickTileHorizontal)
|
|
|
|
mode &= ~QuickTileHorizontal;
|
|
|
|
if ((mode & QuickTileVertical) == QuickTileVertical)
|
|
|
|
mode &= ~QuickTileVertical;
|
|
|
|
}
|
2009-09-09 00:01:08 +04:00
|
|
|
electricMode = mode;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2009-09-09 00:01:08 +04:00
|
|
|
|
2013-02-17 04:56:01 +04:00
|
|
|
Client::QuickTileMode Client::electricBorderMode() const
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2009-09-09 00:01:08 +04:00
|
|
|
return electricMode;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2009-09-09 00:01:08 +04:00
|
|
|
|
|
|
|
bool Client::isElectricBorderMaximizing() const
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2009-09-09 00:01:08 +04:00
|
|
|
return electricMaximizing;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2009-09-09 00:01:08 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
void Client::setElectricBorderMaximizing(bool maximizing)
|
|
|
|
{
|
2009-09-09 00:01:08 +04:00
|
|
|
electricMaximizing = maximizing;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (maximizing)
|
2013-04-25 10:14:34 +04:00
|
|
|
outline()->show(electricBorderMaximizeGeometry(cursorPos(), desktop()));
|
2009-09-09 00:01:08 +04:00
|
|
|
else
|
2013-04-25 10:14:34 +04:00
|
|
|
outline()->hide();
|
2013-04-25 11:40:13 +04:00
|
|
|
elevate(maximizing);
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2009-09-09 00:01:08 +04:00
|
|
|
|
2011-03-08 00:31:44 +03:00
|
|
|
QRect Client::electricBorderMaximizeGeometry(QPoint pos, int desktop)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2011-03-08 00:31:44 +03:00
|
|
|
if (electricMode == QuickTileMaximize) {
|
2011-01-30 17:34:42 +03:00
|
|
|
if (maximizeMode() == MaximizeFull)
|
2011-03-08 00:31:44 +03:00
|
|
|
return geometryRestore();
|
2011-01-30 17:34:42 +03:00
|
|
|
else
|
2011-03-08 00:31:44 +03:00
|
|
|
return workspace()->clientArea(MaximizeArea, pos, desktop);
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2011-03-08 00:31:44 +03:00
|
|
|
|
|
|
|
QRect ret = workspace()->clientArea(MaximizeArea, pos, desktop);
|
|
|
|
if (electricMode & QuickTileLeft)
|
2011-08-11 01:54:28 +04:00
|
|
|
ret.setRight(ret.left()+ret.width()/2 - 1);
|
2011-03-08 00:31:44 +03:00
|
|
|
else if (electricMode & QuickTileRight)
|
2011-08-11 01:54:28 +04:00
|
|
|
ret.setLeft(ret.right()-(ret.width()-ret.width()/2) + 1);
|
2011-03-08 00:31:44 +03:00
|
|
|
if (electricMode & QuickTileTop)
|
2011-08-11 01:54:28 +04:00
|
|
|
ret.setBottom(ret.top()+ret.height()/2 - 1);
|
2011-03-08 00:31:44 +03:00
|
|
|
else if (electricMode & QuickTileBottom)
|
2011-08-11 01:54:28 +04:00
|
|
|
ret.setTop(ret.bottom()-(ret.height()-ret.height()/2) + 1);
|
2011-03-08 00:31:44 +03:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
return ret;
|
|
|
|
}
|
2009-09-09 00:01:08 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
void Client::setQuickTileMode(QuickTileMode mode, bool keyboard)
|
|
|
|
{
|
2009-09-13 21:09:44 +04:00
|
|
|
// Only allow quick tile on a regular or maximized window
|
2011-01-30 17:34:42 +03:00
|
|
|
if (!isResizable() && maximizeMode() != MaximizeFull)
|
|
|
|
return;
|
2009-09-13 21:09:44 +04:00
|
|
|
|
2011-03-08 00:31:44 +03:00
|
|
|
if (mode == QuickTileMaximize)
|
|
|
|
{
|
2012-03-16 03:15:13 +04:00
|
|
|
TabSynchronizer syncer(this, TabGroup::QuickTile|TabGroup::Geometry|TabGroup::Maximized);
|
2011-03-08 00:31:44 +03:00
|
|
|
quick_tile_mode = QuickTileNone;
|
|
|
|
if (maximizeMode() == MaximizeFull)
|
|
|
|
setMaximize(false, false);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setMaximize(true, true);
|
2013-03-15 00:54:40 +04:00
|
|
|
QRect clientArea = workspace()->clientArea(MaximizeArea, this);
|
|
|
|
if (geometry().top() != clientArea.top()) {
|
|
|
|
QRect r(geometry());
|
|
|
|
r.moveTop(clientArea.top());
|
|
|
|
setGeometry(r);
|
|
|
|
}
|
2011-03-08 00:31:44 +03:00
|
|
|
quick_tile_mode = QuickTileMaximize;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// sanitize the mode, ie. simplify "invalid" combinations
|
|
|
|
if ((mode & QuickTileHorizontal) == QuickTileHorizontal)
|
|
|
|
mode &= ~QuickTileHorizontal;
|
|
|
|
if ((mode & QuickTileVertical) == QuickTileVertical)
|
|
|
|
mode &= ~QuickTileVertical;
|
|
|
|
|
|
|
|
setElectricBorderMode(mode); // used by ::electricBorderMaximizeGeometry(.)
|
|
|
|
|
2009-09-13 21:09:44 +04:00
|
|
|
// restore from maximized so that it is possible to tile maximized windows with one hit or by dragging
|
2011-01-30 17:34:42 +03:00
|
|
|
if (maximizeMode() == MaximizeFull) {
|
2012-03-16 03:15:13 +04:00
|
|
|
|
|
|
|
TabSynchronizer syncer(this, TabGroup::QuickTile|TabGroup::Geometry|TabGroup::Maximized);
|
|
|
|
|
2009-09-13 21:09:44 +04:00
|
|
|
setMaximize(false, false);
|
2010-01-09 12:49:52 +03:00
|
|
|
|
2013-02-17 04:56:01 +04:00
|
|
|
if (mode != QuickTileNone) {
|
|
|
|
quick_tile_mode = mode;
|
|
|
|
// decorations may turn off some borders when tiled
|
|
|
|
const ForceGeometry_t geom_mode = decoration && checkBorderSizes(false) ? ForceGeometrySet : NormalGeometrySet;
|
|
|
|
quick_tile_mode = QuickTileNone; // Temporary, so the maximize code doesn't get all confused
|
|
|
|
setGeometry(electricBorderMaximizeGeometry(keyboard ? geometry().center() : cursorPos(), desktop()), geom_mode);
|
|
|
|
}
|
2010-01-09 12:49:52 +03:00
|
|
|
// Store the mode change
|
|
|
|
quick_tile_mode = mode;
|
|
|
|
|
|
|
|
return;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2009-09-13 21:09:44 +04:00
|
|
|
|
|
|
|
// First, check if the requested tile negates the tile we're in now: move right when left or left when right
|
|
|
|
// is the same as explicitly untiling this window, so allow it.
|
2011-03-08 00:31:44 +03:00
|
|
|
if (mode == QuickTileNone || ((quick_tile_mode & QuickTileHorizontal) && (mode & QuickTileHorizontal))) {
|
2012-03-16 03:15:13 +04:00
|
|
|
TabSynchronizer syncer(this, TabGroup::QuickTile|TabGroup::Geometry);
|
|
|
|
|
|
|
|
quick_tile_mode = QuickTileNone;
|
2009-09-13 21:09:44 +04:00
|
|
|
// Untiling, so just restore geometry, and we're done.
|
2012-04-24 22:17:09 +04:00
|
|
|
if (!geom_restore.isValid()) // invalid if we started maximized and wait for placement
|
|
|
|
geom_restore = geometry();
|
2013-02-17 04:56:01 +04:00
|
|
|
// decorations may turn off some borders when tiled
|
|
|
|
const ForceGeometry_t geom_mode = decoration && checkBorderSizes(false) ? ForceGeometrySet : NormalGeometrySet;
|
|
|
|
setGeometry(geom_restore, geom_mode);
|
2011-07-10 04:24:54 +04:00
|
|
|
checkWorkspacePosition(); // Just in case it's a different screen
|
2009-09-13 21:09:44 +04:00
|
|
|
return;
|
2011-01-30 17:34:42 +03:00
|
|
|
} else {
|
2012-03-16 03:15:13 +04:00
|
|
|
TabSynchronizer syncer(this, TabGroup::QuickTile|TabGroup::Geometry);
|
|
|
|
|
2009-12-23 04:36:44 +03:00
|
|
|
QPoint whichScreen = keyboard ? geometry().center() : cursorPos();
|
2009-09-13 21:09:44 +04:00
|
|
|
|
2009-12-23 04:36:44 +03:00
|
|
|
// If trying to tile to the side that the window is already tiled to move the window to the next
|
2012-04-11 20:18:50 +04:00
|
|
|
// screen if it exists, otherwise ignore the request to prevent corrupting geom_restore.
|
2011-01-30 17:34:42 +03:00
|
|
|
if (quick_tile_mode == mode) {
|
2013-04-03 14:19:27 +04:00
|
|
|
const int numScreens = screens()->count();
|
2009-12-23 04:36:44 +03:00
|
|
|
const int curScreen = screen();
|
|
|
|
int nextScreen = curScreen;
|
2010-01-03 20:26:27 +03:00
|
|
|
QVarLengthArray<QRect> screens(numScreens);
|
2011-01-30 17:34:42 +03:00
|
|
|
for (int i = 0; i < numScreens; ++i) // Cache
|
2013-04-03 14:19:27 +04:00
|
|
|
screens[i] = Screens::self()->geometry(i);
|
2011-01-30 17:34:42 +03:00
|
|
|
for (int i = 0; i < numScreens; ++i) {
|
|
|
|
if (i == curScreen)
|
2009-12-23 04:36:44 +03:00
|
|
|
continue;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (((mode == QuickTileLeft &&
|
|
|
|
screens[i].center().x() < screens[nextScreen].center().x()) ||
|
|
|
|
(mode == QuickTileRight &&
|
|
|
|
screens[i].center().x() > screens[nextScreen].center().x())) &&
|
|
|
|
// Must be in horizontal line
|
|
|
|
(screens[i].bottom() > screens[nextScreen].top() ||
|
|
|
|
screens[i].top() < screens[nextScreen].bottom()))
|
2009-12-23 04:36:44 +03:00
|
|
|
nextScreen = i;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
if (nextScreen == curScreen)
|
2009-12-23 04:36:44 +03:00
|
|
|
return; // No other screens
|
|
|
|
|
|
|
|
// Move to other screen
|
2012-04-11 20:18:50 +04:00
|
|
|
geom_restore.translate(
|
2009-12-23 04:36:44 +03:00
|
|
|
screens[nextScreen].x() - screens[curScreen].x(),
|
2011-01-30 17:34:42 +03:00
|
|
|
screens[nextScreen].y() - screens[curScreen].y());
|
2009-12-23 04:36:44 +03:00
|
|
|
whichScreen = screens[nextScreen].center();
|
|
|
|
|
|
|
|
// Swap sides
|
2011-01-30 17:34:42 +03:00
|
|
|
if (mode == QuickTileLeft)
|
2009-12-23 04:36:44 +03:00
|
|
|
mode = QuickTileRight;
|
|
|
|
else
|
|
|
|
mode = QuickTileLeft;
|
2012-03-16 03:15:13 +04:00
|
|
|
} else {
|
2009-12-23 04:36:44 +03:00
|
|
|
// Not coming out of an existing tile, not shifting monitors, we're setting a brand new tile.
|
|
|
|
// Store geometry first, so we can go out of this tile later.
|
2012-04-11 20:18:50 +04:00
|
|
|
geom_restore = geometry();
|
2012-03-16 03:15:13 +04:00
|
|
|
}
|
2009-09-13 21:09:44 +04:00
|
|
|
|
2013-02-17 04:56:01 +04:00
|
|
|
if (mode != QuickTileNone) {
|
|
|
|
quick_tile_mode = mode;
|
|
|
|
// decorations may turn off some borders when tiled
|
|
|
|
const ForceGeometry_t geom_mode = decoration && checkBorderSizes(false) ? ForceGeometrySet : NormalGeometrySet;
|
|
|
|
// Temporary, so the maximize code doesn't get all confused
|
|
|
|
quick_tile_mode = QuickTileNone;
|
|
|
|
setGeometry(electricBorderMaximizeGeometry(whichScreen, desktop()), geom_mode);
|
|
|
|
}
|
2012-03-16 03:15:13 +04:00
|
|
|
|
2009-09-13 21:09:44 +04:00
|
|
|
// Store the mode change
|
|
|
|
quick_tile_mode = mode;
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2009-09-13 21:09:44 +04:00
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
} // namespace
|