2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2009-06-25 14:41:45 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2009 Martin Gräßlin <mgraesslin@kde.org>
|
2009-06-25 14:41:45 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2009-06-25 14:41:45 +00:00
|
|
|
|
|
|
|
#include "resize.h"
|
2012-09-09 12:40:41 +00:00
|
|
|
// KConfigSkeleton
|
|
|
|
#include "resizeconfig.h"
|
2009-06-25 14:41:45 +00:00
|
|
|
|
2010-12-08 17:39:36 +00:00
|
|
|
#include <kwinglutils.h>
|
2009-06-25 14:41:45 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2013-04-11 19:36:03 +00:00
|
|
|
#include "kwinxrenderutils.h"
|
2009-06-25 14:41:45 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <KColorScheme>
|
|
|
|
|
2018-06-05 10:52:57 +00:00
|
|
|
#include <QVector2D>
|
2013-06-24 06:13:29 +00:00
|
|
|
#include <QPainter>
|
2012-05-28 10:00:31 +00:00
|
|
|
|
2009-06-25 14:41:45 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
ResizeEffect::ResizeEffect()
|
2013-07-03 15:14:25 +00:00
|
|
|
: AnimationEffect()
|
|
|
|
, m_active(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
|
|
|
, m_resizeWindow(nullptr)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2016-12-02 19:27:43 +00:00
|
|
|
initConfig<ResizeConfig>();
|
2011-01-30 14:34:42 +00:00
|
|
|
reconfigure(ReconfigureAll);
|
2019-01-01 20:48:53 +00:00
|
|
|
connect(effects, &EffectsHandler::windowStartUserMovedResized, this, &ResizeEffect::slotWindowStartUserMovedResized);
|
|
|
|
connect(effects, &EffectsHandler::windowStepUserMovedResized, this, &ResizeEffect::slotWindowStepUserMovedResized);
|
|
|
|
connect(effects, &EffectsHandler::windowFinishUserMovedResized, this, &ResizeEffect::slotWindowFinishUserMovedResized);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-06-25 14:41:45 +00:00
|
|
|
|
|
|
|
ResizeEffect::~ResizeEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2009-06-25 14:41:45 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void ResizeEffect::prePaintScreen(ScreenPrePaintData& data, int time)
|
|
|
|
{
|
|
|
|
if (m_active) {
|
2009-06-25 14:41:45 +00:00
|
|
|
data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
|
|
|
|
}
|
2013-07-03 15:14:25 +00:00
|
|
|
AnimationEffect::prePaintScreen(data, time);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-06-25 14:41:45 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void ResizeEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
|
|
|
|
{
|
|
|
|
if (m_active && w == m_resizeWindow)
|
2010-04-25 18:40:04 +00:00
|
|
|
data.mask |= PAINT_WINDOW_TRANSFORMED;
|
2013-07-03 15:14:25 +00:00
|
|
|
AnimationEffect::prePaintWindow(w, data, time);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 18:40:04 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void ResizeEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
|
|
|
|
{
|
|
|
|
if (m_active && w == m_resizeWindow) {
|
|
|
|
if (m_features & TextureScale) {
|
2012-05-28 12:45:46 +00:00
|
|
|
data += (m_currentGeometry.topLeft() - m_originalGeometry.topLeft());
|
2012-08-23 14:50:33 +00:00
|
|
|
data *= QVector2D(float(m_currentGeometry.width())/m_originalGeometry.width(),
|
|
|
|
float(m_currentGeometry.height())/m_originalGeometry.height());
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
effects->paintWindow(w, mask, region, data);
|
2010-04-25 18:40:04 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_features & Outline) {
|
|
|
|
QRegion intersection = m_originalGeometry.intersected(m_currentGeometry);
|
|
|
|
QRegion paintRegion = QRegion(m_originalGeometry).united(m_currentGeometry).subtracted(intersection);
|
2010-04-25 18:40:04 +00:00
|
|
|
float alpha = 0.8f;
|
2011-01-30 14:34:42 +00:00
|
|
|
QColor color = KColorScheme(QPalette::Normal, KColorScheme::Selection).background().color();
|
2009-06-25 14:41:45 +00:00
|
|
|
|
2012-09-20 09:33:32 +00:00
|
|
|
if (effects->isOpenGLCompositing()) {
|
2010-12-11 14:58:52 +00:00
|
|
|
GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer();
|
|
|
|
vbo->reset();
|
|
|
|
vbo->setUseColor(true);
|
2015-11-30 13:40:37 +00:00
|
|
|
ShaderBinder binder(ShaderTrait::UniformColor);
|
|
|
|
binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, data.screenProjectionMatrix());
|
2011-01-30 14:34:42 +00:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
2010-12-08 17:39:36 +00:00
|
|
|
color.setAlphaF(alpha);
|
2010-12-11 14:58:52 +00:00
|
|
|
vbo->setColor(color);
|
2010-12-08 17:39:36 +00:00
|
|
|
QVector<float> verts;
|
2019-07-09 20:08:47 +00:00
|
|
|
verts.reserve(paintRegion.rectCount() * 12);
|
|
|
|
for (const QRect &r : paintRegion) {
|
2010-12-08 17:39:36 +00:00
|
|
|
verts << r.x() + r.width() << r.y();
|
|
|
|
verts << r.x() << r.y();
|
|
|
|
verts << r.x() << r.y() + r.height();
|
|
|
|
verts << r.x() << r.y() + r.height();
|
|
|
|
verts << r.x() + r.width() << r.y() + r.height();
|
|
|
|
verts << r.x() + r.width() << r.y();
|
2009-06-25 14:41:45 +00:00
|
|
|
}
|
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
|
|
|
vbo->setData(verts.count() / 2, 2, verts.data(), nullptr);
|
2010-12-11 14:58:52 +00:00
|
|
|
vbo->render(GL_TRIANGLES);
|
2010-12-08 17:39:36 +00:00
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
2009-06-25 14:41:45 +00:00
|
|
|
|
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2011-01-30 14:34:42 +00:00
|
|
|
if (effects->compositingType() == XRenderCompositing) {
|
2013-01-29 08:28:53 +00:00
|
|
|
QVector<xcb_rectangle_t> rects;
|
2019-07-09 20:08:47 +00:00
|
|
|
for (const QRect &r : paintRegion) {
|
2013-01-29 08:28:53 +00:00
|
|
|
xcb_rectangle_t rect = {int16_t(r.x()), int16_t(r.y()), uint16_t(r.width()), uint16_t(r.height())};
|
|
|
|
rects << rect;
|
|
|
|
}
|
2014-04-16 13:58:06 +00:00
|
|
|
xcb_render_fill_rectangles(xcbConnection(), XCB_RENDER_PICT_OP_OVER,
|
2013-04-11 19:36:03 +00:00
|
|
|
effects->xrenderBufferPicture(), preMultiply(color, alpha),
|
|
|
|
rects.count(), rects.constData());
|
2010-04-25 18:40:04 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
#endif
|
2013-06-24 06:13:29 +00:00
|
|
|
if (effects->compositingType() == QPainterCompositing) {
|
|
|
|
QPainter *painter = effects->scenePainter();
|
|
|
|
painter->save();
|
|
|
|
color.setAlphaF(alpha);
|
2019-07-09 20:08:47 +00:00
|
|
|
for (const QRect &r : paintRegion) {
|
2013-06-24 06:13:29 +00:00
|
|
|
painter->fillRect(r, color);
|
|
|
|
}
|
|
|
|
painter->restore();
|
|
|
|
}
|
2009-06-25 14:41:45 +00:00
|
|
|
}
|
2013-07-03 15:14:25 +00:00
|
|
|
} else {
|
|
|
|
AnimationEffect::paintWindow(w, mask, region, data);
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 18:40:04 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void ResizeEffect::reconfigure(ReconfigureFlags)
|
|
|
|
{
|
2010-04-25 18:40:04 +00:00
|
|
|
m_features = 0;
|
2014-03-25 15:29:03 +00:00
|
|
|
ResizeConfig::self()->read();
|
2012-09-09 12:40:41 +00:00
|
|
|
if (ResizeConfig::textureScale())
|
2010-04-25 18:40:04 +00:00
|
|
|
m_features |= TextureScale;
|
2012-09-09 12:40:41 +00:00
|
|
|
if (ResizeConfig::outline())
|
2010-04-25 18:40:04 +00:00
|
|
|
m_features |= Outline;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-06-25 14:41:45 +00:00
|
|
|
|
2011-03-13 11:41:30 +00:00
|
|
|
void ResizeEffect::slotWindowStartUserMovedResized(EffectWindow *w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-03-13 11:41:30 +00:00
|
|
|
if (w->isUserResize() && !w->isUserMove()) {
|
2009-06-25 14:41:45 +00:00
|
|
|
m_active = true;
|
|
|
|
m_resizeWindow = w;
|
2010-04-25 18:40:04 +00:00
|
|
|
m_originalGeometry = w->geometry();
|
2009-10-30 14:22:33 +00:00
|
|
|
m_currentGeometry = w->geometry();
|
2009-06-25 14:41:45 +00:00
|
|
|
w->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2011-03-13 11:41:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResizeEffect::slotWindowFinishUserMovedResized(EffectWindow *w)
|
|
|
|
{
|
|
|
|
if (m_active && w == m_resizeWindow) {
|
2009-06-25 14:41:45 +00:00
|
|
|
m_active = 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
|
|
|
m_resizeWindow = nullptr;
|
2013-07-03 15:14:25 +00:00
|
|
|
if (m_features & TextureScale)
|
|
|
|
animate(w, CrossFadePrevious, 0, 150, FPx2(1.0));
|
2009-06-25 14:41:45 +00:00
|
|
|
effects->addRepaintFull();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-06-25 14:41:45 +00:00
|
|
|
|
2011-03-13 11:41:30 +00:00
|
|
|
void ResizeEffect::slotWindowStepUserMovedResized(EffectWindow *w, const QRect &geometry)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-03-13 11:41:30 +00:00
|
|
|
if (m_active && w == m_resizeWindow) {
|
2009-10-30 14:22:33 +00:00
|
|
|
m_currentGeometry = geometry;
|
|
|
|
effects->addRepaintFull();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-10-30 14:22:33 +00:00
|
|
|
|
2009-06-25 14:41:45 +00:00
|
|
|
} // namespace
|