2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2010-11-10 19:21:56 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2010 Thomas Lübking <thomas.luebking@web.de>
|
2010-11-10 19:21:56 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2010-11-10 19:21:56 +00:00
|
|
|
|
|
|
|
#include "windowgeometry.h"
|
2012-09-19 08:17:17 +00:00
|
|
|
// KConfigSkeleton
|
|
|
|
#include "windowgeometryconfig.h"
|
|
|
|
|
2013-08-14 19:13:12 +00:00
|
|
|
#include <QAction>
|
2013-09-05 08:48:30 +00:00
|
|
|
#include <QLocale>
|
2010-11-10 19:21:56 +00:00
|
|
|
#include <QStringBuilder>
|
|
|
|
#include <kwinconfig.h>
|
|
|
|
#include <kconfiggroup.h>
|
2014-03-17 15:24:10 +00:00
|
|
|
#include <KGlobalAccel>
|
|
|
|
#include <KLocalizedString>
|
2010-11-10 19:21:56 +00:00
|
|
|
|
|
|
|
using namespace KWin;
|
|
|
|
|
|
|
|
WindowGeometry::WindowGeometry()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2016-12-02 19:27:43 +00:00
|
|
|
initConfig<WindowGeometryConfiguration>();
|
2010-11-10 19:21:56 +00:00
|
|
|
iAmActivated = true;
|
|
|
|
iAmActive = false;
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
myResizeWindow = nullptr;
|
2011-03-03 03:37:17 +00:00
|
|
|
#define myResizeString "Window geometry display, %1 and %2 are the new size," \
|
|
|
|
" %3 and %4 are pixel increments - avoid reformatting or suffixes like 'px'", \
|
|
|
|
"Width: %1 (%3)\nHeight: %2 (%4)"
|
|
|
|
#define myCoordString_0 "Window geometry display, %1 and %2 are the cartesian x and y coordinates" \
|
|
|
|
" - avoid reformatting or suffixes like 'px'", \
|
|
|
|
"X: %1\nY: %2"
|
|
|
|
#define myCoordString_1 "Window geometry display, %1 and %2 are the cartesian x and y coordinates," \
|
|
|
|
" %3 and %4 are the resp. increments - avoid reformatting or suffixes like 'px'", \
|
|
|
|
"X: %1 (%3)\nY: %2 (%4)"
|
2011-01-30 14:34:42 +00:00
|
|
|
reconfigure(ReconfigureAll);
|
2013-12-10 10:45:33 +00:00
|
|
|
QAction* a = new QAction(this);
|
|
|
|
a->setObjectName(QStringLiteral("WindowGeometry"));
|
2011-01-30 14:34:42 +00:00
|
|
|
a->setText(i18n("Toggle window geometry display (effect only)"));
|
2013-08-14 19:13:12 +00:00
|
|
|
|
|
|
|
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::CTRL + Qt::SHIFT + Qt::Key_F11);
|
|
|
|
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::CTRL + Qt::SHIFT + Qt::Key_F11);
|
2013-07-10 10:26:50 +00:00
|
|
|
effects->registerGlobalShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_F11, a);
|
2013-08-14 19:13:12 +00:00
|
|
|
|
2019-01-01 20:48:53 +00:00
|
|
|
connect(a, &QAction::triggered, this, &WindowGeometry::toggle);
|
2013-08-14 19:13:12 +00:00
|
|
|
|
2019-01-01 20:48:53 +00:00
|
|
|
connect(effects, &EffectsHandler::windowStartUserMovedResized, this, &WindowGeometry::slotWindowStartUserMovedResized);
|
|
|
|
connect(effects, &EffectsHandler::windowFinishUserMovedResized, this, &WindowGeometry::slotWindowFinishUserMovedResized);
|
|
|
|
connect(effects, &EffectsHandler::windowStepUserMovedResized, this, &WindowGeometry::slotWindowStepUserMovedResized);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-11-10 19:21:56 +00:00
|
|
|
|
|
|
|
WindowGeometry::~WindowGeometry()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < 3; ++i)
|
2010-11-10 19:21:56 +00:00
|
|
|
delete myMeasure[i];
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-11-10 19:21:56 +00:00
|
|
|
|
2017-11-14 19:12:57 +00:00
|
|
|
void WindowGeometry::createFrames()
|
|
|
|
{
|
|
|
|
if (myMeasure[0]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QFont fnt; fnt.setBold(true); fnt.setPointSize(12);
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
myMeasure[i] = effects->effectFrame(EffectFrameUnstyled, false);
|
|
|
|
myMeasure[i]->setFont(fnt);
|
|
|
|
}
|
|
|
|
myMeasure[0]->setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
|
|
|
myMeasure[1]->setAlignment(Qt::AlignCenter);
|
|
|
|
myMeasure[2]->setAlignment(Qt::AlignRight | Qt::AlignBottom);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void WindowGeometry::reconfigure(ReconfigureFlags)
|
|
|
|
{
|
2014-03-25 15:29:03 +00:00
|
|
|
WindowGeometryConfiguration::self()->read();
|
2012-09-19 08:17:17 +00:00
|
|
|
iHandleMoves = WindowGeometryConfiguration::move();
|
|
|
|
iHandleResizes = WindowGeometryConfiguration::resize();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-11-10 19:21:56 +00:00
|
|
|
|
2019-10-29 22:04:15 +00:00
|
|
|
void WindowGeometry::paintScreen(int mask, const QRegion ®ion, ScreenPaintData &data)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
effects->paintScreen(mask, region, data);
|
|
|
|
if (iAmActivated && iAmActive) {
|
|
|
|
for (int i = 0; i < 3; ++i)
|
2010-11-10 19:21:56 +00:00
|
|
|
myMeasure[i]->render(infiniteRegion(), 1.0, .66);
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-11-10 19:21:56 +00:00
|
|
|
|
|
|
|
void WindowGeometry::toggle()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-11-10 19:21:56 +00:00
|
|
|
iAmActivated = !iAmActivated;
|
2017-11-14 19:12:57 +00:00
|
|
|
createFrames();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-11-10 19:21:56 +00:00
|
|
|
|
2011-03-13 11:41:30 +00:00
|
|
|
void WindowGeometry::slotWindowStartUserMovedResized(EffectWindow *w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-03-13 11:41:30 +00:00
|
|
|
if (!iAmActivated)
|
|
|
|
return;
|
|
|
|
if (w->isUserResize() && !iHandleResizes)
|
|
|
|
return;
|
|
|
|
if (w->isUserMove() && !iHandleMoves)
|
2010-11-10 19:21:56 +00:00
|
|
|
return;
|
|
|
|
|
2017-11-14 19:12:57 +00:00
|
|
|
createFrames();
|
2011-03-13 11:41:30 +00:00
|
|
|
iAmActive = true;
|
|
|
|
myResizeWindow = w;
|
|
|
|
myOriginalGeometry = w->geometry();
|
|
|
|
myCurrentGeometry = w->geometry();
|
2011-11-05 15:17:26 +00:00
|
|
|
slotWindowStepUserMovedResized(w, w->geometry());
|
2011-03-13 11:41:30 +00:00
|
|
|
}
|
2010-11-10 19:21:56 +00:00
|
|
|
|
2011-03-13 11:41:30 +00:00
|
|
|
void WindowGeometry::slotWindowFinishUserMovedResized(EffectWindow *w)
|
|
|
|
{
|
|
|
|
if (iAmActive && w == myResizeWindow) {
|
2010-11-10 19:21:56 +00:00
|
|
|
iAmActive = false;
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
myResizeWindow = nullptr;
|
2013-01-30 16:26:19 +00:00
|
|
|
w->addRepaintFull();
|
|
|
|
if (myExtraDirtyArea.isValid())
|
|
|
|
w->addLayerRepaint(myExtraDirtyArea);
|
|
|
|
myExtraDirtyArea = QRect();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-11-10 19:21:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline QString number(int n)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2013-09-05 08:48:30 +00:00
|
|
|
QLocale locale;
|
2011-05-13 15:37:07 +00:00
|
|
|
QString sign;
|
|
|
|
if (n >= 0) {
|
2013-09-05 08:48:30 +00:00
|
|
|
sign = locale.positiveSign();
|
2013-07-23 05:02:52 +00:00
|
|
|
if (sign.isEmpty()) sign = QStringLiteral("+");
|
2011-05-13 15:37:07 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
n = -n;
|
2013-09-05 08:48:30 +00:00
|
|
|
sign = locale.negativeSign();
|
2013-07-23 05:02:52 +00:00
|
|
|
if (sign.isEmpty()) sign = QStringLiteral("-");
|
2011-05-13 15:37:07 +00:00
|
|
|
}
|
|
|
|
return sign + QString::number(n);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
|
2010-11-10 19:21:56 +00:00
|
|
|
|
2011-03-13 11:41:30 +00:00
|
|
|
void WindowGeometry::slotWindowStepUserMovedResized(EffectWindow *w, const QRect &geometry)
|
2010-11-10 19:21:56 +00:00
|
|
|
{
|
2011-01-30 14:34:42 +00:00
|
|
|
if (iAmActivated && iAmActive && w == myResizeWindow) {
|
2013-01-30 16:26:19 +00:00
|
|
|
if (myExtraDirtyArea.isValid())
|
2013-08-03 16:52:56 +00:00
|
|
|
effects->addRepaint(myExtraDirtyArea);
|
2013-01-30 16:26:19 +00:00
|
|
|
|
|
|
|
myExtraDirtyArea = QRect();
|
|
|
|
|
2010-11-10 19:21:56 +00:00
|
|
|
myCurrentGeometry = geometry;
|
2013-09-20 22:42:21 +00:00
|
|
|
QPoint center = geometry.center();
|
2010-11-10 19:21:56 +00:00
|
|
|
const QRect &r = geometry;
|
|
|
|
const QRect &r2 = myOriginalGeometry;
|
2019-09-12 19:19:34 +00:00
|
|
|
const QRect screen = effects->clientArea(ScreenArea, w);
|
2013-09-20 22:42:21 +00:00
|
|
|
QRect expandedGeometry = w->expandedGeometry();
|
|
|
|
expandedGeometry = geometry.adjusted(expandedGeometry.x() - w->x(),
|
|
|
|
expandedGeometry.y() - w->y(),
|
|
|
|
expandedGeometry.right() - w->geometry().right(),
|
|
|
|
expandedGeometry.bottom() - w->geometry().bottom());
|
2010-11-10 19:21:56 +00:00
|
|
|
|
|
|
|
// sufficient for moves, resizes calculated otherwise
|
|
|
|
int dx = r.x() - r2.x();
|
|
|
|
int dy = r.y() - r2.y();
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2010-11-10 19:21:56 +00:00
|
|
|
// upper left ----------------------
|
2011-01-30 14:34:42 +00:00
|
|
|
if (w->isUserResize())
|
2011-03-03 03:37:17 +00:00
|
|
|
myMeasure[0]->setText( i18nc(myCoordString_1, r.x(), r.y(), number(dx), number(dy) ) );
|
2010-11-10 19:21:56 +00:00
|
|
|
else
|
2011-03-03 03:37:17 +00:00
|
|
|
myMeasure[0]->setText( i18nc(myCoordString_0, r.x(), r.y() ) );
|
2013-09-20 22:42:21 +00:00
|
|
|
QPoint pos = expandedGeometry.topLeft();
|
|
|
|
pos = QPoint(qMax(pos.x(), screen.x()), qMax(pos.y(), screen.y()));
|
|
|
|
myMeasure[0]->setPosition(pos + QPoint(6,6)); // "6" is magic number because the unstyled effectframe has 5px padding
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2010-11-10 19:21:56 +00:00
|
|
|
// center ----------------------
|
2011-01-30 14:34:42 +00:00
|
|
|
if (w->isUserResize()) {
|
2010-11-10 19:21:56 +00:00
|
|
|
// calc width for center element, otherwise the current dx/dx remains right
|
|
|
|
dx = r.width() - r2.width();
|
|
|
|
dy = r.height() - r2.height();
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2011-11-02 22:05:03 +00:00
|
|
|
const QSize baseInc = w->basicUnit();
|
2011-11-13 17:38:03 +00:00
|
|
|
if (baseInc != QSize(1,1)) {
|
|
|
|
Q_ASSERT(baseInc.width() && baseInc.height());
|
|
|
|
const QSize csz = w->contentsRect().size();
|
|
|
|
myMeasure[1]->setText( i18nc(myResizeString, csz.width()/baseInc.width(), csz.height()/baseInc.height(), number(dx/baseInc.width()), number(dy/baseInc.height()) ) );
|
|
|
|
} else
|
|
|
|
myMeasure[1]->setText( i18nc(myResizeString, r.width(), r.height(), number(dx), number(dy) ) );
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2011-01-01 09:39:02 +00:00
|
|
|
// calc width for bottomright element, superfluous otherwise
|
2010-11-10 19:21:56 +00:00
|
|
|
dx = r.right() - r2.right();
|
|
|
|
dy = r.bottom() - r2.bottom();
|
2011-01-30 14:34:42 +00:00
|
|
|
} else
|
2011-03-03 03:37:17 +00:00
|
|
|
myMeasure[1]->setText( i18nc(myCoordString_0, number(dx), number(dy) ) );
|
2013-09-20 22:42:21 +00:00
|
|
|
const int cdx = myMeasure[1]->geometry().width() / 2 + 3; // "3" = 6/2 is magic number because
|
|
|
|
const int cdy = myMeasure[1]->geometry().height() / 2 + 3; // the unstyled effectframe has 5px padding
|
|
|
|
center = QPoint(qMax(center.x(), screen.x() + cdx),
|
|
|
|
qMax(center.y(), screen.y() + cdy));
|
|
|
|
center = QPoint(qMin(center.x(), screen.right() - cdx),
|
|
|
|
qMin(center.y(), screen.bottom() - cdy));
|
|
|
|
myMeasure[1]->setPosition(center);
|
2010-11-10 19:21:56 +00:00
|
|
|
|
|
|
|
// lower right ----------------------
|
2011-01-30 14:34:42 +00:00
|
|
|
if (w->isUserResize())
|
2011-03-03 03:37:17 +00:00
|
|
|
myMeasure[2]->setText( i18nc(myCoordString_1, r.right(), r.bottom(), number(dx), number(dy) ) );
|
2010-11-10 19:21:56 +00:00
|
|
|
else
|
2011-03-03 03:37:17 +00:00
|
|
|
myMeasure[2]->setText( i18nc(myCoordString_0, r.right(), r.bottom() ) );
|
2013-09-20 22:42:21 +00:00
|
|
|
pos = expandedGeometry.bottomRight();
|
|
|
|
pos = QPoint(qMin(pos.x(), screen.right()), qMin(pos.y(), screen.bottom()));
|
|
|
|
myMeasure[2]->setPosition(pos - QPoint(6,6)); // "6" is magic number because the unstyled effectframe has 5px padding
|
2013-01-30 16:26:19 +00:00
|
|
|
|
|
|
|
myExtraDirtyArea |= myMeasure[0]->geometry();
|
|
|
|
myExtraDirtyArea |= myMeasure[1]->geometry();
|
|
|
|
myExtraDirtyArea |= myMeasure[2]->geometry();
|
|
|
|
myExtraDirtyArea.adjust(-6,-6,6,6);
|
2010-11-10 19:21:56 +00:00
|
|
|
|
2013-01-30 16:26:19 +00:00
|
|
|
if (myExtraDirtyArea.isValid())
|
2013-08-03 16:52:56 +00:00
|
|
|
effects->addRepaint(myExtraDirtyArea);
|
2010-11-10 19:21:56 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-11-10 19:21:56 +00:00
|
|
|
|
2011-08-27 09:21:31 +00:00
|
|
|
bool WindowGeometry::isActive() const
|
|
|
|
{
|
|
|
|
return iAmActive;
|
|
|
|
}
|