2007-11-27 19:40:25 +00:00
|
|
|
/********************************************************************
|
2007-04-29 17:35:43 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
|
2010-08-11 11:55:26 +00:00
|
|
|
Copyright (C) 2010 Sebastian Sauer <sebsauer@kdab.com>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2007-11-27 19:40:25 +00: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 17:35:43 +00:00
|
|
|
|
|
|
|
#include "zoom.h"
|
2012-09-09 16:01:07 +00:00
|
|
|
// KConfigSkeleton
|
|
|
|
#include "zoomconfig.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2013-08-14 19:13:12 +00:00
|
|
|
#include <QAction>
|
2013-02-26 08:00:51 +00:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QStyle>
|
2018-06-05 10:52:57 +00:00
|
|
|
#include <QVector2D>
|
|
|
|
#include <QDBusConnection>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <kstandardaction.h>
|
2014-03-17 15:24:10 +00:00
|
|
|
#include <KConfigGroup>
|
|
|
|
#include <KGlobalAccel>
|
|
|
|
#include <KLocalizedString>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-08-11 11:55:26 +00:00
|
|
|
#include <kwinglutils.h>
|
2013-01-29 09:10:07 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2010-08-11 11:55:26 +00:00
|
|
|
#include <kwinxrenderutils.h>
|
2013-01-29 09:10:07 +00:00
|
|
|
#include <xcb/render.h>
|
|
|
|
#endif
|
2010-08-11 11:55:26 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
ZoomEffect::ZoomEffect()
|
2011-02-25 19:25:21 +00:00
|
|
|
: Effect()
|
2011-01-30 14:34:42 +00:00
|
|
|
, zoom(1)
|
|
|
|
, target_zoom(1)
|
|
|
|
, polling(false)
|
|
|
|
, zoomFactor(1.25)
|
|
|
|
, mouseTracking(MouseTrackingProportional)
|
|
|
|
, enableFocusTracking(false)
|
|
|
|
, followFocus(true)
|
|
|
|
, mousePointer(MousePointerScale)
|
|
|
|
, focusDelay(350) // in milliseconds
|
|
|
|
, imageWidth(0)
|
|
|
|
, imageHeight(0)
|
|
|
|
, isMouseHidden(false)
|
|
|
|
, xMove(0)
|
|
|
|
, yMove(0)
|
|
|
|
, moveFactor(20.0)
|
|
|
|
{
|
2016-12-02 19:27:43 +00:00
|
|
|
initConfig<ZoomConfig>();
|
2013-08-14 19:13:12 +00:00
|
|
|
QAction* a = 0;
|
2013-12-10 10:45:33 +00:00
|
|
|
a = KStandardAction::zoomIn(this, SLOT(zoomIn()), this);
|
2013-08-14 19:13:12 +00:00
|
|
|
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Equal);
|
|
|
|
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Equal);
|
2013-07-10 10:26:50 +00:00
|
|
|
effects->registerGlobalShortcut(Qt::META + Qt::Key_Equal, a);
|
2013-07-15 10:05:59 +00:00
|
|
|
effects->registerAxisShortcut(Qt::ControlModifier | Qt::MetaModifier, PointerAxisDown, a);
|
2013-08-14 19:13:12 +00:00
|
|
|
|
2013-12-10 10:45:33 +00:00
|
|
|
a = KStandardAction::zoomOut(this, SLOT(zoomOut()), this);
|
2013-08-14 19:13:12 +00:00
|
|
|
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Minus);
|
|
|
|
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Minus);
|
2013-07-10 10:26:50 +00:00
|
|
|
effects->registerGlobalShortcut(Qt::META + Qt::Key_Minus, a);
|
2013-07-15 10:05:59 +00:00
|
|
|
effects->registerAxisShortcut(Qt::ControlModifier | Qt::MetaModifier, PointerAxisUp, a);
|
2013-08-14 19:13:12 +00:00
|
|
|
|
2013-12-10 10:45:33 +00:00
|
|
|
a = KStandardAction::actualSize(this, SLOT(actualSize()), this);
|
2013-08-14 19:13:12 +00:00
|
|
|
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_0);
|
|
|
|
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_0);
|
2013-07-10 10:26:50 +00:00
|
|
|
effects->registerGlobalShortcut(Qt::META + Qt::Key_0, a);
|
2013-08-14 19:13:12 +00:00
|
|
|
|
2013-12-10 10:45:33 +00:00
|
|
|
a = new QAction(this);
|
|
|
|
a->setObjectName(QStringLiteral("MoveZoomLeft"));
|
2013-01-09 09:31:48 +00:00
|
|
|
a->setText(i18n("Move Zoomed Area to Left"));
|
2018-03-20 18:58:26 +00:00
|
|
|
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>());
|
|
|
|
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>());
|
|
|
|
effects->registerGlobalShortcut(QKeySequence(), a);
|
2019-01-01 20:48:53 +00:00
|
|
|
connect(a, &QAction::triggered, this, &ZoomEffect::moveZoomLeft);
|
2010-08-11 11:55:26 +00:00
|
|
|
|
2013-12-10 10:45:33 +00:00
|
|
|
a = new QAction(this);
|
|
|
|
a->setObjectName(QStringLiteral("MoveZoomRight"));
|
2013-01-09 09:31:48 +00:00
|
|
|
a->setText(i18n("Move Zoomed Area to Right"));
|
2018-03-20 18:58:26 +00:00
|
|
|
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>());
|
|
|
|
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>());
|
|
|
|
effects->registerGlobalShortcut(QKeySequence(), a);
|
2019-01-01 20:48:53 +00:00
|
|
|
connect(a, &QAction::triggered, this, &ZoomEffect::moveZoomRight);
|
2010-08-11 11:55:26 +00:00
|
|
|
|
2013-12-10 10:45:33 +00:00
|
|
|
a = new QAction(this);
|
|
|
|
a->setObjectName(QStringLiteral("MoveZoomUp"));
|
2013-01-09 09:31:48 +00:00
|
|
|
a->setText(i18n("Move Zoomed Area Upwards"));
|
2018-03-20 18:58:26 +00:00
|
|
|
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>());
|
|
|
|
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>());
|
|
|
|
effects->registerGlobalShortcut(QKeySequence(), a);
|
2019-01-01 20:48:53 +00:00
|
|
|
connect(a, &QAction::triggered, this, &ZoomEffect::moveZoomUp);
|
2010-08-11 11:55:26 +00:00
|
|
|
|
2013-12-10 10:45:33 +00:00
|
|
|
a = new QAction(this);
|
|
|
|
a->setObjectName(QStringLiteral("MoveZoomDown"));
|
2013-01-09 09:31:48 +00:00
|
|
|
a->setText(i18n("Move Zoomed Area Downwards"));
|
2018-03-20 18:58:26 +00:00
|
|
|
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>());
|
|
|
|
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>());
|
|
|
|
effects->registerGlobalShortcut(QKeySequence(), a);
|
2019-01-01 20:48:53 +00:00
|
|
|
connect(a, &QAction::triggered, this, &ZoomEffect::moveZoomDown);
|
2010-08-11 11:55:26 +00:00
|
|
|
|
2013-01-09 09:31:48 +00:00
|
|
|
// TODO: these two actions don't belong into the effect. They need to be moved into KWin core
|
2013-12-10 10:45:33 +00:00
|
|
|
a = new QAction(this);
|
|
|
|
a->setObjectName(QStringLiteral("MoveMouseToFocus"));
|
2011-01-30 14:34:42 +00:00
|
|
|
a->setText(i18n("Move Mouse to Focus"));
|
2013-08-14 19:13:12 +00:00
|
|
|
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_F5);
|
|
|
|
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_F5);
|
2013-07-10 10:26:50 +00:00
|
|
|
effects->registerGlobalShortcut(Qt::META + Qt::Key_F5, a);
|
2019-01-01 20:48:53 +00:00
|
|
|
connect(a, &QAction::triggered, this, &ZoomEffect::moveMouseToFocus);
|
2010-08-11 11:55:26 +00:00
|
|
|
|
2013-12-10 10:45:33 +00:00
|
|
|
a = new QAction(this);
|
|
|
|
a->setObjectName(QStringLiteral("MoveMouseToCenter"));
|
2011-01-30 14:34:42 +00:00
|
|
|
a->setText(i18n("Move Mouse to Center"));
|
2013-08-14 19:13:12 +00:00
|
|
|
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_F6);
|
|
|
|
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_F6);
|
2013-07-10 10:26:50 +00:00
|
|
|
effects->registerGlobalShortcut(Qt::META + Qt::Key_F6, a);
|
2019-01-01 20:48:53 +00:00
|
|
|
connect(a, &QAction::triggered, this, &ZoomEffect::moveMouseToCenter);
|
2011-01-30 14:34:42 +00:00
|
|
|
|
|
|
|
timeline.setDuration(350);
|
|
|
|
timeline.setFrameRange(0, 100);
|
2019-01-01 20:48:53 +00:00
|
|
|
connect(&timeline, &QTimeLine::frameChanged, this, &ZoomEffect::timelineFrameChanged);
|
|
|
|
connect(effects, &EffectsHandler::mouseChanged, this, &ZoomEffect::slotMouseChanged);
|
2010-08-11 11:55:26 +00:00
|
|
|
|
2013-01-10 22:31:25 +00:00
|
|
|
source_zoom = -1; // used to trigger initialZoom reading
|
2011-01-30 14:34:42 +00:00
|
|
|
reconfigure(ReconfigureAll);
|
|
|
|
}
|
2010-08-11 11:55:26 +00:00
|
|
|
|
|
|
|
ZoomEffect::~ZoomEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-08-11 11:55:26 +00:00
|
|
|
// switch off and free resources
|
|
|
|
showCursor();
|
2012-04-13 10:05:23 +00:00
|
|
|
// Save the zoom value.
|
2016-11-11 10:10:05 +00:00
|
|
|
ZoomConfig::setInitialZoom(target_zoom);
|
|
|
|
ZoomConfig::self()->save();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-08-11 11:55:26 +00:00
|
|
|
|
|
|
|
void ZoomEffect::showCursor()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (isMouseHidden) {
|
2015-02-07 14:41:45 +00:00
|
|
|
disconnect(effects, &EffectsHandler::cursorShapeChanged, this, &ZoomEffect::recreateTexture);
|
2010-08-11 11:55:26 +00:00
|
|
|
// show the previously hidden mouse-pointer again and free the loaded texture/picture.
|
2016-10-20 08:25:37 +00:00
|
|
|
effects->showCursor();
|
2013-02-21 18:38:03 +00:00
|
|
|
texture.reset();
|
2013-02-21 17:21:46 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2013-02-21 18:38:03 +00:00
|
|
|
xrenderPicture.reset();
|
2013-02-21 17:21:46 +00:00
|
|
|
#endif
|
2010-08-11 11:55:26 +00:00
|
|
|
isMouseHidden = false;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-08-11 11:55:26 +00:00
|
|
|
|
|
|
|
void ZoomEffect::hideCursor()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-11-22 18:26:48 +00:00
|
|
|
if (mouseTracking == MouseTrackingProportional && mousePointer == MousePointerKeep)
|
|
|
|
return; // don't replace the actual cursor by a static image for no reason.
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!isMouseHidden) {
|
|
|
|
// try to load the cursor-theme into a OpenGL texture and if successful then hide the mouse-pointer
|
2010-08-11 11:55:26 +00:00
|
|
|
recreateTexture();
|
2013-02-21 17:21:46 +00:00
|
|
|
bool shouldHide = false;
|
|
|
|
if (effects->isOpenGLCompositing()) {
|
2013-02-21 18:38:03 +00:00
|
|
|
shouldHide = !texture.isNull();
|
2013-02-21 17:21:46 +00:00
|
|
|
} else if (effects->compositingType() == XRenderCompositing) {
|
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2013-02-21 18:38:03 +00:00
|
|
|
shouldHide = !xrenderPicture.isNull();
|
2013-02-21 17:21:46 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if (shouldHide) {
|
2016-10-20 08:25:37 +00:00
|
|
|
effects->hideCursor();
|
2015-02-07 14:41:45 +00:00
|
|
|
connect(effects, &EffectsHandler::cursorShapeChanged, this, &ZoomEffect::recreateTexture);
|
2010-08-11 11:55:26 +00:00
|
|
|
isMouseHidden = true;
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-08-11 11:55:26 +00:00
|
|
|
|
|
|
|
void ZoomEffect::recreateTexture()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
Better handling for making the compositing OpenGL context current
With QtQuick2 it's possible that the scene graph rendering context either
lives in an own thread or uses the main GUI thread. In the latter case
it's the same thread as our compositing OpenGL context lives in. This
means our basic assumption that between two rendering passes the context
stays current does not hold.
The code already ensured that before we start a rendering pass the
context is made current, but there are many more possible cases. If we
use OpenGL in areas not triggered by the rendering loop but in response
to other events the context needs to be made current. This includes the
loading and unloading of effects (some effects use OpenGL in the static
effect check, in the ctor and dtor), background loading of texture data,
lazy loading after first usage invoked by shortcut, etc. etc.
To properly handle these cases new methods are added to EffectsHandler
to make the compositing OpenGL context current. These calls delegate down
into the scene. On non-OpenGL scenes they are noop, but on OpenGL they go
into the backend and make the context current. In addition they ensure
that Qt doesn't think that it's QOpenGLContext is current by calling
doneCurrent() on the QOpenGLContext::currentContext(). This unfortunately
causes an additional call to makeCurrent with a null context, but there
is no other way to tell Qt - it doesn't notice when a different context
is made current with low level API calls. In the multi-threaded
architecture this doesn't matter as ::currentContext() returns null.
A short evaluation showed that a transition to QOpenGLContext doesn't
seem feasible. Qt only supports either GLX or EGL while KWin supports
both and when entering the transition phase for Wayland, it would become
extremely tricky if our native platform is X11, but we want a Wayland
EGL context. A future solution might be to have a "KWin-QPA plugin" which
uses either xcb or Wayland and hides everything from Qt.
The API documentation is extended to describe when the effects-framework
ensures that an OpenGL context is current. The effects are changed to
make the context current in cases where it's not guaranteed. This has
been done by looking for creation or deletion of GLTextures and Shaders.
If there are other OpenGL usages outside the rendering loop, ctor/dtor
this needs to be changed, too.
2013-11-22 14:05:36 +00:00
|
|
|
effects->makeOpenGLContextCurrent();
|
2016-10-17 14:12:21 +00:00
|
|
|
const auto cursor = effects->cursorImage();
|
|
|
|
if (!cursor.image().isNull()) {
|
|
|
|
imageWidth = cursor.image().width();
|
|
|
|
imageHeight = cursor.image().height();
|
|
|
|
cursorHotSpot = cursor.hotSpot();
|
2018-10-04 17:20:55 +00:00
|
|
|
if (effects->isOpenGLCompositing()) {
|
2016-10-17 14:12:21 +00:00
|
|
|
texture.reset(new GLTexture(cursor.image()));
|
2018-10-04 17:20:55 +00:00
|
|
|
texture->setWrapMode(GL_CLAMP_TO_EDGE);
|
|
|
|
}
|
2010-08-11 11:55:26 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2011-01-30 14:34:42 +00:00
|
|
|
if (effects->compositingType() == XRenderCompositing)
|
2016-10-17 14:12:21 +00:00
|
|
|
xrenderPicture.reset(new XRenderPicture(cursor.image()));
|
2010-08-11 11:55:26 +00:00
|
|
|
#endif
|
|
|
|
}
|
2011-06-30 19:06:17 +00:00
|
|
|
else {
|
2015-06-12 01:05:17 +00:00
|
|
|
qCDebug(KWINEFFECTS) << "Falling back to proportional mouse tracking!";
|
2011-06-30 19:06:17 +00:00
|
|
|
mouseTracking = MouseTrackingProportional;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-08-11 11:55:26 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void ZoomEffect::reconfigure(ReconfigureFlags)
|
|
|
|
{
|
2014-03-25 15:29:03 +00:00
|
|
|
ZoomConfig::self()->read();
|
2010-08-11 11:55:26 +00:00
|
|
|
// On zoom-in and zoom-out change the zoom by the defined zoom-factor.
|
2012-09-30 11:50:49 +00:00
|
|
|
zoomFactor = qMax(0.1, ZoomConfig::zoomFactor());
|
2010-08-11 11:55:26 +00:00
|
|
|
// Visibility of the mouse-pointer.
|
2012-09-09 16:01:07 +00:00
|
|
|
mousePointer = MousePointerType(ZoomConfig::mousePointer());
|
2010-08-11 11:55:26 +00:00
|
|
|
// Track moving of the mouse.
|
2012-09-09 16:01:07 +00:00
|
|
|
mouseTracking = MouseTrackingType(ZoomConfig::mouseTracking());
|
2010-08-11 11:55:26 +00:00
|
|
|
// Enable tracking of the focused location.
|
2012-09-09 16:01:07 +00:00
|
|
|
bool _enableFocusTracking = ZoomConfig::enableFocusTracking();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (enableFocusTracking != _enableFocusTracking) {
|
2010-08-11 11:55:26 +00:00
|
|
|
enableFocusTracking = _enableFocusTracking;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (QDBusConnection::sessionBus().isConnected()) {
|
|
|
|
if (enableFocusTracking)
|
2013-07-23 05:02:52 +00:00
|
|
|
QDBusConnection::sessionBus().connect(QStringLiteral("org.kde.kaccessibleapp"),
|
|
|
|
QStringLiteral("/Adaptor"),
|
|
|
|
QStringLiteral("org.kde.kaccessibleapp.Adaptor"),
|
|
|
|
QStringLiteral("focusChanged"),
|
|
|
|
this, SLOT(focusChanged(int,int,int,int,int,int)));
|
2010-08-11 11:55:26 +00:00
|
|
|
else
|
2013-07-23 05:02:52 +00:00
|
|
|
QDBusConnection::sessionBus().disconnect(QStringLiteral("org.kde.kaccessibleapp"),
|
|
|
|
QStringLiteral("/Adaptor"),
|
|
|
|
QStringLiteral("org.kde.kaccessibleapp.Adaptor"),
|
|
|
|
QStringLiteral("focusChanged"),
|
|
|
|
this, SLOT(focusChanged(int,int,int,int,int,int)));
|
2010-08-11 11:55:26 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-08-11 11:55:26 +00:00
|
|
|
// When the focus changes, move the zoom area to the focused location.
|
2012-09-09 16:01:07 +00:00
|
|
|
followFocus = ZoomConfig::enableFollowFocus();
|
2010-08-11 11:55:26 +00:00
|
|
|
// The time in milliseconds to wait before a focus-event takes away a mouse-move.
|
2012-09-09 16:01:07 +00:00
|
|
|
focusDelay = qMax(uint(0), ZoomConfig::focusDelay());
|
2010-08-11 11:55:26 +00:00
|
|
|
// The factor the zoom-area will be moved on touching an edge on push-mode or using the navigation KAction's.
|
2012-09-09 16:01:07 +00:00
|
|
|
moveFactor = qMax(0.1, ZoomConfig::moveFactor());
|
2013-01-10 22:31:25 +00:00
|
|
|
if (source_zoom < 0) {
|
|
|
|
// Load the saved zoom value.
|
|
|
|
source_zoom = 1.0;
|
|
|
|
target_zoom = ZoomConfig::initialZoom();
|
|
|
|
if (target_zoom > 1.0)
|
|
|
|
zoomIn(target_zoom);
|
|
|
|
} else {
|
|
|
|
source_zoom = 1.0;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void ZoomEffect::prePaintScreen(ScreenPrePaintData& data, int time)
|
|
|
|
{
|
|
|
|
if (zoom != target_zoom) {
|
2013-01-10 22:31:25 +00:00
|
|
|
const float zoomDist = qAbs(target_zoom - source_zoom);
|
2011-01-30 14:34:42 +00:00
|
|
|
if (target_zoom > zoom)
|
2013-01-10 22:31:25 +00:00
|
|
|
zoom = qMin(zoom + ((zoomDist * time) / animationTime(150*zoomFactor)), target_zoom);
|
2007-04-29 17:35:43 +00:00
|
|
|
else
|
2013-01-10 22:31:25 +00:00
|
|
|
zoom = qMax(zoom - ((zoomDist * time) / animationTime(150*zoomFactor)), target_zoom);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-08-11 11:55:26 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (zoom == 1.0) {
|
2010-08-11 11:55:26 +00:00
|
|
|
showCursor();
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2010-08-11 11:55:26 +00:00
|
|
|
hideCursor();
|
2007-07-07 14:01:32 +00:00
|
|
|
data.mask |= PAINT_SCREEN_TRANSFORMED;
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->prePaintScreen(data, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZoomEffect::paintScreen(int mask, QRegion region, ScreenPaintData& data)
|
|
|
|
{
|
|
|
|
if (zoom != 1.0) {
|
2012-05-28 10:00:31 +00:00
|
|
|
data *= QVector2D(zoom, zoom);
|
2014-02-24 15:13:30 +00:00
|
|
|
const QSize screenSize = effects->virtualScreenSize();
|
2010-08-11 11:55:26 +00:00
|
|
|
|
|
|
|
// mouse-tracking allows navigation of the zoom-area using the mouse.
|
2011-01-30 14:34:42 +00:00
|
|
|
switch(mouseTracking) {
|
|
|
|
case MouseTrackingProportional:
|
2012-05-28 12:45:46 +00:00
|
|
|
data.setXTranslation(- int(cursorPoint.x() * (zoom - 1.0)));
|
|
|
|
data.setYTranslation(- int(cursorPoint.y() * (zoom - 1.0)));
|
2011-01-30 14:34:42 +00:00
|
|
|
prevPoint = cursorPoint;
|
|
|
|
break;
|
|
|
|
case MouseTrackingCentred:
|
|
|
|
prevPoint = cursorPoint;
|
2012-03-11 17:45:17 +00:00
|
|
|
// fall through
|
|
|
|
case MouseTrackingDisabled:
|
2014-02-24 15:13:30 +00:00
|
|
|
data.setXTranslation(qMin(0, qMax(int(screenSize.width() - screenSize.width() * zoom), int(screenSize.width() / 2 - prevPoint.x() * zoom))));
|
|
|
|
data.setYTranslation(qMin(0, qMax(int(screenSize.height() - screenSize.height() * zoom), int(screenSize.height() / 2 - prevPoint.y() * zoom))));
|
2011-01-30 14:34:42 +00:00
|
|
|
break;
|
2013-01-12 01:59:22 +00:00
|
|
|
case MouseTrackingPush: {
|
2011-01-30 14:34:42 +00:00
|
|
|
// touching an edge of the screen moves the zoom-area in that direction.
|
|
|
|
int x = cursorPoint.x() * zoom - prevPoint.x() * (zoom - 1.0);
|
|
|
|
int y = cursorPoint.y() * zoom - prevPoint.y() * (zoom - 1.0);
|
2013-01-12 01:59:22 +00:00
|
|
|
int threshold = 4;
|
2011-01-30 14:34:42 +00:00
|
|
|
xMove = yMove = 0;
|
|
|
|
if (x < threshold)
|
2013-01-12 01:59:22 +00:00
|
|
|
xMove = (x - threshold) / zoom;
|
2014-02-24 15:13:30 +00:00
|
|
|
else if (x + threshold > screenSize.width())
|
|
|
|
xMove = (x + threshold - screenSize.width()) / zoom;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (y < threshold)
|
2013-01-12 01:59:22 +00:00
|
|
|
yMove = (y - threshold) / zoom;
|
2014-02-24 15:13:30 +00:00
|
|
|
else if (y + threshold > screenSize.height())
|
|
|
|
yMove = (y + threshold - screenSize.height()) / zoom;
|
2013-01-12 01:59:22 +00:00
|
|
|
if (xMove)
|
2014-02-24 15:13:30 +00:00
|
|
|
prevPoint.setX(qMax(0, qMin(screenSize.width(), prevPoint.x() + xMove)));
|
2013-01-12 01:59:22 +00:00
|
|
|
if (yMove)
|
2014-02-24 15:13:30 +00:00
|
|
|
prevPoint.setY(qMax(0, qMin(screenSize.height(), prevPoint.y() + yMove)));
|
2013-01-12 01:59:22 +00:00
|
|
|
data.setXTranslation(- int(prevPoint.x() * (zoom - 1.0)));
|
|
|
|
data.setYTranslation(- int(prevPoint.y() * (zoom - 1.0)));
|
|
|
|
break;
|
2010-08-11 11:55:26 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-08-11 11:55:26 +00:00
|
|
|
|
|
|
|
// use the focusPoint if focus tracking is enabled
|
2011-01-30 14:34:42 +00:00
|
|
|
if (enableFocusTracking && followFocus) {
|
2010-08-11 11:55:26 +00:00
|
|
|
bool acceptFocus = true;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (mouseTracking != MouseTrackingDisabled && focusDelay > 0) {
|
2010-08-11 11:55:26 +00:00
|
|
|
// Wait some time for the mouse before doing the switch. This serves as threshold
|
|
|
|
// to prevent the focus from jumping around to much while working with the mouse.
|
|
|
|
const int msecs = lastMouseEvent.msecsTo(lastFocusEvent);
|
|
|
|
acceptFocus = msecs > focusDelay;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (acceptFocus) {
|
2012-05-28 12:45:46 +00:00
|
|
|
data.setXTranslation(- int(focusPoint.x() * (zoom - 1.0)));
|
|
|
|
data.setYTranslation(- int(focusPoint.y() * (zoom - 1.0)));
|
2010-08-11 11:55:26 +00:00
|
|
|
prevPoint = focusPoint;
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-08-11 11:55:26 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->paintScreen(mask, region, data);
|
2010-08-11 11:55:26 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (zoom != 1.0 && mousePointer != MousePointerHide) {
|
2011-01-01 09:39:02 +00:00
|
|
|
// Draw the mouse-texture at the position matching to zoomed-in image of the desktop. Hiding the
|
2010-08-11 11:55:26 +00:00
|
|
|
// previous mouse-cursor and drawing our own fake mouse-cursor is needed to be able to scale the
|
2011-01-01 09:39:02 +00:00
|
|
|
// mouse-cursor up and to re-position those mouse-cursor to match to the chosen zoom-level.
|
2011-06-30 19:06:17 +00:00
|
|
|
int w = imageWidth;
|
|
|
|
int h = imageHeight;
|
|
|
|
if (mousePointer == MousePointerScale) {
|
|
|
|
w *= zoom;
|
|
|
|
h *= zoom;
|
|
|
|
}
|
2014-02-03 20:02:10 +00:00
|
|
|
const QPoint p = effects->cursorPos() - cursorHotSpot;
|
2012-05-28 12:45:46 +00:00
|
|
|
QRect rect(p.x() * zoom + data.xTranslation(), p.y() * zoom + data.yTranslation(), w, h);
|
2011-06-30 19:06:17 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (texture) {
|
2010-08-11 11:55:26 +00:00
|
|
|
texture->bind();
|
2011-01-30 14:34:42 +00:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
2015-02-07 21:11:20 +00:00
|
|
|
auto s = ShaderManager::instance()->pushShader(ShaderTrait::MapTexture);
|
2015-11-27 11:26:16 +00:00
|
|
|
QMatrix4x4 mvp = data.projectionMatrix();
|
2015-02-07 21:11:20 +00:00
|
|
|
mvp.translate(rect.x(), rect.y());
|
|
|
|
s->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
|
2010-08-11 11:55:26 +00:00
|
|
|
texture->render(region, rect);
|
2015-02-07 21:11:20 +00:00
|
|
|
ShaderManager::instance()->popShader();
|
2010-08-11 11:55:26 +00:00
|
|
|
texture->unbind();
|
2010-12-08 17:45:23 +00:00
|
|
|
glDisable(GL_BLEND);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-08-11 11:55:26 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2011-01-30 14:34:42 +00:00
|
|
|
if (xrenderPicture) {
|
2013-01-29 09:10:07 +00:00
|
|
|
#define DOUBLE_TO_FIXED(d) ((xcb_render_fixed_t) ((d) * 65536))
|
2014-09-27 18:30:49 +00:00
|
|
|
static const xcb_render_transform_t xrenderIdentity = {
|
2013-01-29 09:10:07 +00:00
|
|
|
DOUBLE_TO_FIXED(1), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0),
|
|
|
|
DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(1), DOUBLE_TO_FIXED(0),
|
|
|
|
DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(1)
|
|
|
|
};
|
2011-06-30 19:06:17 +00:00
|
|
|
if (mousePointer == MousePointerScale) {
|
2014-04-16 13:58:06 +00:00
|
|
|
xcb_render_set_picture_filter(xcbConnection(), *xrenderPicture, 4, const_cast<char*>("good"), 0, NULL);
|
2013-01-29 09:10:07 +00:00
|
|
|
const xcb_render_transform_t xform = {
|
|
|
|
DOUBLE_TO_FIXED(1.0 / zoom), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0),
|
|
|
|
DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(1.0 / zoom), DOUBLE_TO_FIXED(0),
|
|
|
|
DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(1)
|
|
|
|
};
|
2014-04-16 13:58:06 +00:00
|
|
|
xcb_render_set_picture_transform(xcbConnection(), *xrenderPicture, xform);
|
2011-06-30 19:06:17 +00:00
|
|
|
}
|
2014-04-16 13:58:06 +00:00
|
|
|
xcb_render_composite(xcbConnection(), XCB_RENDER_PICT_OP_OVER, *xrenderPicture, XCB_RENDER_PICTURE_NONE,
|
2013-01-29 09:10:07 +00:00
|
|
|
effects->xrenderBufferPicture(), 0, 0, 0, 0, rect.x(), rect.y(), rect.width(), rect.height());
|
2011-06-30 19:06:17 +00:00
|
|
|
if (mousePointer == MousePointerScale)
|
2014-04-16 13:58:06 +00:00
|
|
|
xcb_render_set_picture_transform(xcbConnection(), *xrenderPicture, xrenderIdentity);
|
2013-01-29 09:10:07 +00:00
|
|
|
#undef DOUBLE_TO_FIXED
|
2010-08-11 11:55:26 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
#endif
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void ZoomEffect::postPaintScreen()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (zoom != target_zoom)
|
2007-04-29 17:35:43 +00:00
|
|
|
effects->addRepaintFull();
|
|
|
|
effects->postPaintScreen();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2012-04-13 10:05:23 +00:00
|
|
|
void ZoomEffect::zoomIn(double to)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2013-01-10 22:31:25 +00:00
|
|
|
source_zoom = zoom;
|
2012-04-13 10:05:23 +00:00
|
|
|
if (to < 0.0)
|
|
|
|
target_zoom *= zoomFactor;
|
|
|
|
else
|
|
|
|
target_zoom = to;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!polling) {
|
2009-02-01 15:16:52 +00:00
|
|
|
polling = true;
|
|
|
|
effects->startMousePolling();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2013-10-10 04:50:47 +00:00
|
|
|
cursorPoint = effects->cursorPos();
|
2012-03-11 17:45:17 +00:00
|
|
|
if (mouseTracking == MouseTrackingDisabled)
|
2013-10-10 04:50:47 +00:00
|
|
|
prevPoint = cursorPoint;
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->addRepaintFull();
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void ZoomEffect::zoomOut()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2013-01-10 22:31:25 +00:00
|
|
|
source_zoom = zoom;
|
2010-08-11 11:55:26 +00:00
|
|
|
target_zoom /= zoomFactor;
|
2014-02-03 20:03:26 +00:00
|
|
|
if ((zoomFactor > 1 && target_zoom < 1.01) || (zoomFactor < 1 && target_zoom > 0.99)) {
|
2009-04-27 20:20:05 +00:00
|
|
|
target_zoom = 1;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (polling) {
|
2009-04-27 20:20:05 +00:00
|
|
|
polling = false;
|
|
|
|
effects->stopMousePolling();
|
2009-02-01 15:16:52 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2012-03-11 17:45:17 +00:00
|
|
|
if (mouseTracking == MouseTrackingDisabled)
|
2013-02-21 18:38:03 +00:00
|
|
|
prevPoint = effects->cursorPos();
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->addRepaintFull();
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void ZoomEffect::actualSize()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2013-01-10 22:31:25 +00:00
|
|
|
source_zoom = zoom;
|
2007-04-29 17:35:43 +00:00
|
|
|
target_zoom = 1;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (polling) {
|
2009-04-27 20:20:05 +00:00
|
|
|
polling = false;
|
|
|
|
effects->stopMousePolling();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->addRepaintFull();
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-08-11 11:55:26 +00:00
|
|
|
void ZoomEffect::timelineFrameChanged(int /* frame */)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2014-02-24 15:13:30 +00:00
|
|
|
const QSize screenSize = effects->virtualScreenSize();
|
|
|
|
prevPoint.setX(qMax(0, qMin(screenSize.width(), prevPoint.x() + xMove)));
|
|
|
|
prevPoint.setY(qMax(0, qMin(screenSize.height(), prevPoint.y() + yMove)));
|
2010-08-11 11:55:26 +00:00
|
|
|
cursorPoint = prevPoint;
|
|
|
|
effects->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-08-11 11:55:26 +00:00
|
|
|
|
|
|
|
void ZoomEffect::moveZoom(int x, int y)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (timeline.state() == QTimeLine::Running)
|
2010-08-11 11:55:26 +00:00
|
|
|
timeline.stop();
|
|
|
|
|
2014-02-24 15:13:30 +00:00
|
|
|
const QSize screenSize = effects->virtualScreenSize();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (x < 0)
|
2014-02-24 15:13:30 +00:00
|
|
|
xMove = - qMax(1.0, screenSize.width() / zoom / moveFactor);
|
2011-01-30 14:34:42 +00:00
|
|
|
else if (x > 0)
|
2014-02-24 15:13:30 +00:00
|
|
|
xMove = qMax(1.0, screenSize.width() / zoom / moveFactor);
|
2010-08-11 11:55:26 +00:00
|
|
|
else
|
|
|
|
xMove = 0;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (y < 0)
|
2014-02-24 15:13:30 +00:00
|
|
|
yMove = - qMax(1.0, screenSize.height() / zoom / moveFactor);
|
2011-01-30 14:34:42 +00:00
|
|
|
else if (y > 0)
|
2014-02-24 15:13:30 +00:00
|
|
|
yMove = qMax(1.0, screenSize.height() / zoom / moveFactor);
|
2010-08-11 11:55:26 +00:00
|
|
|
else
|
|
|
|
yMove = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2010-08-11 11:55:26 +00:00
|
|
|
timeline.start();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-08-11 11:55:26 +00:00
|
|
|
|
|
|
|
void ZoomEffect::moveZoomLeft()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-08-11 11:55:26 +00:00
|
|
|
moveZoom(-1, 0);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-08-11 11:55:26 +00:00
|
|
|
|
|
|
|
void ZoomEffect::moveZoomRight()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-08-11 11:55:26 +00:00
|
|
|
moveZoom(1, 0);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-08-11 11:55:26 +00:00
|
|
|
|
|
|
|
void ZoomEffect::moveZoomUp()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-08-11 11:55:26 +00:00
|
|
|
moveZoom(0, -1);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-08-11 11:55:26 +00:00
|
|
|
|
|
|
|
void ZoomEffect::moveZoomDown()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-08-11 11:55:26 +00:00
|
|
|
moveZoom(0, 1);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-08-11 11:55:26 +00:00
|
|
|
|
|
|
|
void ZoomEffect::moveMouseToFocus()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-08-11 11:55:26 +00:00
|
|
|
QCursor::setPos(focusPoint.x(), focusPoint.y());
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-08-11 11:55:26 +00:00
|
|
|
|
|
|
|
void ZoomEffect::moveMouseToCenter()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2014-02-24 15:13:30 +00:00
|
|
|
const QRect r = effects->virtualScreenGeometry();
|
2010-08-11 11:55:26 +00:00
|
|
|
QCursor::setPos(r.x() + r.width() / 2, r.y() + r.height() / 2);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-08-11 11:55:26 +00:00
|
|
|
|
2011-03-12 13:37:30 +00:00
|
|
|
void ZoomEffect::slotMouseChanged(const QPoint& pos, const QPoint& old, Qt::MouseButtons,
|
2011-01-30 14:34:42 +00:00
|
|
|
Qt::MouseButtons, Qt::KeyboardModifiers, Qt::KeyboardModifiers)
|
|
|
|
{
|
|
|
|
if (zoom == 1.0)
|
2010-10-16 09:36:11 +00:00
|
|
|
return;
|
2010-08-11 11:55:26 +00:00
|
|
|
cursorPoint = pos;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (pos != old) {
|
2010-08-11 11:55:26 +00:00
|
|
|
lastMouseEvent = QTime::currentTime();
|
2007-04-29 17:35:43 +00:00
|
|
|
effects->addRepaintFull();
|
2010-08-11 11:55:26 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-08-11 11:55:26 +00:00
|
|
|
|
|
|
|
void ZoomEffect::focusChanged(int px, int py, int rx, int ry, int rwidth, int rheight)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (zoom == 1.0)
|
2010-10-16 09:36:11 +00:00
|
|
|
return;
|
2014-02-24 15:13:30 +00:00
|
|
|
const QSize screenSize = effects->virtualScreenSize();
|
|
|
|
focusPoint = (px >= 0 && py >= 0) ? QPoint(px, py) : QPoint(rx + qMax(0, (qMin(screenSize.width(), rwidth) / 2) - 60), ry + qMax(0, (qMin(screenSize.height(), rheight) / 2) - 60));
|
2011-01-30 14:34:42 +00:00
|
|
|
if (enableFocusTracking) {
|
2010-08-11 11:55:26 +00:00
|
|
|
lastFocusEvent = QTime::currentTime();
|
|
|
|
effects->addRepaintFull();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-08-27 09:21:31 +00:00
|
|
|
bool ZoomEffect::isActive() const
|
|
|
|
{
|
|
|
|
return zoom != 1.0 || zoom != target_zoom;
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
} // namespace
|
|
|
|
|