2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2006 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
SPDX-FileCopyrightText: 2010 Jorge Mata <matamax123@gmail.com>
|
|
|
|
SPDX-FileCopyrightText: 2018 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
2020-08-02 22:10:35 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include "trackmouse.h"
|
|
|
|
|
2012-09-12 17:24:20 +00:00
|
|
|
// KConfigSkeleton
|
|
|
|
#include "trackmouseconfig.h"
|
|
|
|
|
2013-08-14 19:13:12 +00:00
|
|
|
#include <QAction>
|
2013-06-21 12:57:37 +00:00
|
|
|
#include <QPainter>
|
2008-04-15 12:54:17 +00:00
|
|
|
#include <QTime>
|
2012-04-19 19:06:11 +00:00
|
|
|
#include <QMatrix4x4>
|
2008-04-15 12:54:17 +00:00
|
|
|
|
2007-12-17 14:14:53 +00:00
|
|
|
#include <kwinconfig.h>
|
2010-12-08 18:35:38 +00:00
|
|
|
#include <kwinglutils.h>
|
2013-02-12 11:34:51 +00:00
|
|
|
#include <kwinxrenderutils.h>
|
2007-05-13 17:47:20 +00:00
|
|
|
|
2014-03-17 15:24:10 +00:00
|
|
|
#include <KGlobalAccel>
|
|
|
|
#include <KLocalizedString>
|
2010-01-21 14:56:24 +00:00
|
|
|
|
2019-07-09 19:19:26 +00:00
|
|
|
#include <cmath>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
TrackMouseEffect::TrackMouseEffect()
|
[effects/trackmouse] Allow to use both modifiers and shortcut
Summary:
The Track Mouse effect can be toggled either by pressing modifier keys
and moving mouse or by pressing a shortcut. It's not possible to use
the latter and then the former without changing config.
But there is one caveat, in order to use shortcut, you have to uncheck
all modifier keys. This seems to be not very intuitive.
In addition to that, the KCM allows to change shortcut even if there is
some checked modifier.
As the title says, this change makes possible to use both modifier keys
and shortcut to activate this effect without changing config.
KCM:
{F6237308, layout=center, size=full}
BUG: 398124
FIXED-IN: 5.14.0
Reviewers: #kwin, #plasma, #vdg, davidedmundson
Reviewed By: #kwin, #plasma, #vdg, davidedmundson
Subscribers: broulik, abetts, ngraham, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D15272
2018-09-04 12:08:27 +00:00
|
|
|
: m_angle(0)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2016-12-02 19:27:43 +00:00
|
|
|
initConfig<TrackMouseConfig>();
|
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_texture[0] = m_texture[1] = nullptr;
|
2012-04-19 19:06:11 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
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_picture[0] = m_picture[1] = nullptr;
|
2012-04-19 19:06:11 +00:00
|
|
|
if ( effects->compositingType() == XRenderCompositing)
|
|
|
|
m_angleBase = 1.57079632679489661923; // Pi/2
|
|
|
|
#endif
|
2013-06-21 12:57:37 +00:00
|
|
|
if ( effects->isOpenGLCompositing() || effects->compositingType() == QPainterCompositing)
|
2012-04-19 19:06:11 +00:00
|
|
|
m_angleBase = 90.0;
|
|
|
|
m_mousePolling = false;
|
2013-08-14 19:13:12 +00:00
|
|
|
|
2013-12-10 10:45:33 +00:00
|
|
|
m_action = new QAction(this);
|
|
|
|
m_action->setObjectName(QStringLiteral("TrackMouse"));
|
2012-04-19 19:06:11 +00:00
|
|
|
m_action->setText(i18n("Track mouse"));
|
2013-08-14 19:13:12 +00:00
|
|
|
KGlobalAccel::self()->setDefaultShortcut(m_action, QList<QKeySequence>());
|
|
|
|
KGlobalAccel::self()->setShortcut(m_action, QList<QKeySequence>());
|
2013-07-10 10:26:50 +00:00
|
|
|
effects->registerGlobalShortcut(QKeySequence(), m_action);
|
2010-12-08 18:35:38 +00:00
|
|
|
|
2019-01-01 20:48:53 +00:00
|
|
|
connect(m_action, &QAction::triggered, this, &TrackMouseEffect::toggle);
|
2013-08-14 19:13:12 +00:00
|
|
|
|
2019-01-01 20:48:53 +00:00
|
|
|
connect(effects, &EffectsHandler::mouseChanged, this, &TrackMouseEffect::slotMouseChanged);
|
2011-01-30 14:34:42 +00:00
|
|
|
reconfigure(ReconfigureAll);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
TrackMouseEffect::~TrackMouseEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-04-19 19:06:11 +00:00
|
|
|
if (m_mousePolling)
|
2010-01-21 14:56:24 +00:00
|
|
|
effects->stopMousePolling();
|
2012-04-19 19:06:11 +00:00
|
|
|
for (int i = 0; i < 2; ++i) {
|
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
|
|
|
delete m_texture[i]; m_texture[i] = nullptr;
|
2012-04-19 19:06:11 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
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
|
|
|
delete m_picture[i]; m_picture[i] = nullptr;
|
2012-04-19 19:06:11 +00:00
|
|
|
#endif
|
|
|
|
}
|
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 TrackMouseEffect::reconfigure(ReconfigureFlags)
|
|
|
|
{
|
2019-09-19 15:16:14 +00:00
|
|
|
m_modifiers = Qt::KeyboardModifiers();
|
2014-03-25 15:29:03 +00:00
|
|
|
TrackMouseConfig::self()->read();
|
2012-09-12 17:24:20 +00:00
|
|
|
if (TrackMouseConfig::shift())
|
2012-04-19 19:06:11 +00:00
|
|
|
m_modifiers |= Qt::ShiftModifier;
|
2012-09-12 17:24:20 +00:00
|
|
|
if (TrackMouseConfig::alt())
|
2012-04-19 19:06:11 +00:00
|
|
|
m_modifiers |= Qt::AltModifier;
|
2012-09-12 17:24:20 +00:00
|
|
|
if (TrackMouseConfig::control())
|
2012-04-19 19:06:11 +00:00
|
|
|
m_modifiers |= Qt::ControlModifier;
|
2012-09-12 17:24:20 +00:00
|
|
|
if (TrackMouseConfig::meta())
|
2012-04-19 19:06:11 +00:00
|
|
|
m_modifiers |= Qt::MetaModifier;
|
|
|
|
|
|
|
|
if (m_modifiers) {
|
|
|
|
if (!m_mousePolling)
|
2010-01-22 05:01:05 +00:00
|
|
|
effects->startMousePolling();
|
2012-04-19 19:06:11 +00:00
|
|
|
m_mousePolling = true;
|
|
|
|
} else if (m_mousePolling) {
|
2010-01-21 14:56:24 +00:00
|
|
|
effects->stopMousePolling();
|
2012-04-19 19:06:11 +00:00
|
|
|
m_mousePolling = false;
|
2010-01-21 14:56:24 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-01-21 14:56:24 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void TrackMouseEffect::prePaintScreen(ScreenPrePaintData& data, int time)
|
|
|
|
{
|
[effects/trackmouse] Allow to use both modifiers and shortcut
Summary:
The Track Mouse effect can be toggled either by pressing modifier keys
and moving mouse or by pressing a shortcut. It's not possible to use
the latter and then the former without changing config.
But there is one caveat, in order to use shortcut, you have to uncheck
all modifier keys. This seems to be not very intuitive.
In addition to that, the KCM allows to change shortcut even if there is
some checked modifier.
As the title says, this change makes possible to use both modifier keys
and shortcut to activate this effect without changing config.
KCM:
{F6237308, layout=center, size=full}
BUG: 398124
FIXED-IN: 5.14.0
Reviewers: #kwin, #plasma, #vdg, davidedmundson
Reviewed By: #kwin, #plasma, #vdg, davidedmundson
Subscribers: broulik, abetts, ngraham, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D15272
2018-09-04 12:08:27 +00:00
|
|
|
QTime t = QTime::currentTime();
|
|
|
|
m_angle = ((t.second() % 4) * m_angleBase) + (t.msec() / 1000.0 * m_angleBase);
|
|
|
|
m_lastRect[0].moveCenter(cursorPos());
|
|
|
|
m_lastRect[1].moveCenter(cursorPos());
|
|
|
|
data.paint |= m_lastRect[0].adjusted(-1,-1,1,1);
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->prePaintScreen(data, time);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2019-10-29 22:04:15 +00:00
|
|
|
void TrackMouseEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintData& data)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
effects->paintScreen(mask, region, data); // paint normal screen
|
2012-04-19 19:06:11 +00:00
|
|
|
|
2012-09-20 09:33:32 +00:00
|
|
|
if ( effects->isOpenGLCompositing() && m_texture[0] && m_texture[1]) {
|
2015-11-27 11:12:44 +00:00
|
|
|
ShaderBinder binder(ShaderTrait::MapTexture);
|
2012-09-21 09:25:08 +00:00
|
|
|
GLShader *shader(binder.shader());
|
2014-02-25 10:02:32 +00:00
|
|
|
if (!shader) {
|
|
|
|
return;
|
2010-12-08 18:35:38 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
glEnable(GL_BLEND);
|
2012-04-19 19:06:11 +00:00
|
|
|
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
2015-11-27 11:12:44 +00:00
|
|
|
QMatrix4x4 matrix(data.projectionMatrix());
|
2012-04-19 19:06:11 +00:00
|
|
|
const QPointF p = m_lastRect[0].topLeft() + QPoint(m_lastRect[0].width()/2.0, m_lastRect[0].height()/2.0);
|
2014-07-10 11:35:36 +00:00
|
|
|
const float x = p.x()*data.xScale() + data.xTranslation();
|
|
|
|
const float y = p.y()*data.yScale() + data.yTranslation();
|
2012-04-19 19:06:11 +00:00
|
|
|
for (int i = 0; i < 2; ++i) {
|
2014-07-10 11:35:36 +00:00
|
|
|
matrix.translate(x, y, 0.0);
|
2012-04-19 19:06:11 +00:00
|
|
|
matrix.rotate(i ? -2*m_angle : m_angle, 0, 0, 1.0);
|
2014-07-10 11:35:36 +00:00
|
|
|
matrix.translate(-x, -y, 0.0);
|
2015-11-27 11:12:44 +00:00
|
|
|
QMatrix4x4 mvp(matrix);
|
|
|
|
mvp.translate(m_lastRect[i].x(), m_lastRect[i].y());
|
|
|
|
shader->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
|
2012-04-19 19:06:11 +00:00
|
|
|
m_texture[i]->bind();
|
|
|
|
m_texture[i]->render(region, m_lastRect[i]);
|
|
|
|
m_texture[i]->unbind();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-12-08 18:35:38 +00:00
|
|
|
glDisable(GL_BLEND);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2012-04-19 19:06:11 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2013-02-12 11:34:51 +00:00
|
|
|
if ( effects->compositingType() == XRenderCompositing && m_picture[0] && m_picture[1]) {
|
2012-04-19 19:06:11 +00:00
|
|
|
float sine = sin(m_angle);
|
|
|
|
const float cosine = cos(m_angle);
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
if (i) sine = -sine;
|
2013-02-12 11:34:51 +00:00
|
|
|
const float dx = m_size[i].width()/2.0;
|
|
|
|
const float dy = m_size[i].height()/2.0;
|
|
|
|
const xcb_render_picture_t picture = *m_picture[i];
|
|
|
|
#define DOUBLE_TO_FIXED(d) ((xcb_render_fixed_t) ((d) * 65536))
|
|
|
|
xcb_render_transform_t xform = {
|
|
|
|
DOUBLE_TO_FIXED( cosine ), DOUBLE_TO_FIXED( -sine ), DOUBLE_TO_FIXED( dx - cosine*dx + sine*dy ),
|
|
|
|
DOUBLE_TO_FIXED( sine ), DOUBLE_TO_FIXED( cosine ), DOUBLE_TO_FIXED( dy - sine*dx - cosine*dy ),
|
|
|
|
DOUBLE_TO_FIXED( 0.0 ), DOUBLE_TO_FIXED( 0.0 ), DOUBLE_TO_FIXED( 1.0 )
|
|
|
|
};
|
|
|
|
#undef DOUBLE_TO_FIXED
|
2014-04-16 13:58:06 +00:00
|
|
|
xcb_render_set_picture_transform(xcbConnection(), picture, xform);
|
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
|
|
|
xcb_render_set_picture_filter(xcbConnection(), picture, 8, "bilinear", 0, nullptr);
|
2013-02-12 11:34:51 +00:00
|
|
|
const QRect &rect = m_lastRect[i];
|
2014-04-16 13:58:06 +00:00
|
|
|
xcb_render_composite(xcbConnection(), XCB_RENDER_PICT_OP_OVER, picture, XCB_RENDER_PICTURE_NONE,
|
2013-02-12 11:34:51 +00:00
|
|
|
effects->xrenderBufferPicture(), 0, 0, 0, 0,
|
2014-07-10 11:35:36 +00:00
|
|
|
qRound((rect.x()+rect.width()/2.0)*data.xScale() - rect.width()/2.0 + data.xTranslation()),
|
|
|
|
qRound((rect.y()+rect.height()/2.0)*data.yScale() - rect.height()/2.0 + data.yTranslation()),
|
|
|
|
rect.width(), rect.height());
|
2012-04-19 19:06:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2013-06-21 12:57:37 +00:00
|
|
|
if (effects->compositingType() == QPainterCompositing && !m_image[0].isNull() && !m_image[1].isNull()) {
|
|
|
|
QPainter *painter = effects->scenePainter();
|
|
|
|
const QPointF p = m_lastRect[0].topLeft() + QPoint(m_lastRect[0].width()/2.0, m_lastRect[0].height()/2.0);
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
painter->save();
|
|
|
|
painter->translate(p.x(), p.y());
|
|
|
|
painter->rotate(i ? -2*m_angle : m_angle);
|
|
|
|
painter->translate(-p.x(), -p.y());
|
|
|
|
painter->drawImage(m_lastRect[i], m_image[i]);
|
|
|
|
painter->restore();
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void TrackMouseEffect::postPaintScreen()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
[effects/trackmouse] Allow to use both modifiers and shortcut
Summary:
The Track Mouse effect can be toggled either by pressing modifier keys
and moving mouse or by pressing a shortcut. It's not possible to use
the latter and then the former without changing config.
But there is one caveat, in order to use shortcut, you have to uncheck
all modifier keys. This seems to be not very intuitive.
In addition to that, the KCM allows to change shortcut even if there is
some checked modifier.
As the title says, this change makes possible to use both modifier keys
and shortcut to activate this effect without changing config.
KCM:
{F6237308, layout=center, size=full}
BUG: 398124
FIXED-IN: 5.14.0
Reviewers: #kwin, #plasma, #vdg, davidedmundson
Reviewed By: #kwin, #plasma, #vdg, davidedmundson
Subscribers: broulik, abetts, ngraham, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D15272
2018-09-04 12:08:27 +00:00
|
|
|
effects->addRepaint(m_lastRect[0].adjusted(-1,-1,1,1));
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->postPaintScreen();
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2012-04-19 19:06:11 +00:00
|
|
|
bool TrackMouseEffect::init()
|
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();
|
2012-04-19 19:06:11 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2015-05-20 12:45:53 +00:00
|
|
|
if (!(m_texture[0] || m_picture[0] || !m_image[0].isNull())) {
|
2012-04-19 19:06:11 +00:00
|
|
|
loadTexture();
|
2015-05-20 12:45:53 +00:00
|
|
|
if (!(m_texture[0] || m_picture[0] || !m_image[0].isNull()))
|
2012-04-19 19:06:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#else
|
2013-06-21 12:57:37 +00:00
|
|
|
if (!m_texture[0] || m_image[0].isNull()) {
|
2012-04-19 19:06:11 +00:00
|
|
|
loadTexture();
|
2013-06-21 12:57:37 +00:00
|
|
|
if (!m_texture[0] || m_image[0].isNull())
|
2012-04-19 19:06:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
m_lastRect[0].moveCenter(cursorPos());
|
|
|
|
m_lastRect[1].moveCenter(cursorPos());
|
|
|
|
m_angle = 0;
|
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-01-21 14:56:24 +00:00
|
|
|
|
2012-04-19 19:06:11 +00:00
|
|
|
void TrackMouseEffect::toggle()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
[effects/trackmouse] Allow to use both modifiers and shortcut
Summary:
The Track Mouse effect can be toggled either by pressing modifier keys
and moving mouse or by pressing a shortcut. It's not possible to use
the latter and then the former without changing config.
But there is one caveat, in order to use shortcut, you have to uncheck
all modifier keys. This seems to be not very intuitive.
In addition to that, the KCM allows to change shortcut even if there is
some checked modifier.
As the title says, this change makes possible to use both modifier keys
and shortcut to activate this effect without changing config.
KCM:
{F6237308, layout=center, size=full}
BUG: 398124
FIXED-IN: 5.14.0
Reviewers: #kwin, #plasma, #vdg, davidedmundson
Reviewed By: #kwin, #plasma, #vdg, davidedmundson
Subscribers: broulik, abetts, ngraham, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D15272
2018-09-04 12:08:27 +00:00
|
|
|
switch (m_state) {
|
|
|
|
case State::ActivatedByModifiers:
|
|
|
|
m_state = State::ActivatedByShortcut;
|
|
|
|
break;
|
2012-04-19 19:06:11 +00:00
|
|
|
|
[effects/trackmouse] Allow to use both modifiers and shortcut
Summary:
The Track Mouse effect can be toggled either by pressing modifier keys
and moving mouse or by pressing a shortcut. It's not possible to use
the latter and then the former without changing config.
But there is one caveat, in order to use shortcut, you have to uncheck
all modifier keys. This seems to be not very intuitive.
In addition to that, the KCM allows to change shortcut even if there is
some checked modifier.
As the title says, this change makes possible to use both modifier keys
and shortcut to activate this effect without changing config.
KCM:
{F6237308, layout=center, size=full}
BUG: 398124
FIXED-IN: 5.14.0
Reviewers: #kwin, #plasma, #vdg, davidedmundson
Reviewed By: #kwin, #plasma, #vdg, davidedmundson
Subscribers: broulik, abetts, ngraham, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D15272
2018-09-04 12:08:27 +00:00
|
|
|
case State::ActivatedByShortcut:
|
|
|
|
m_state = State::Inactive;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case State::Inactive:
|
|
|
|
if (!init()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_state = State::ActivatedByShortcut;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
break;
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
[effects/trackmouse] Allow to use both modifiers and shortcut
Summary:
The Track Mouse effect can be toggled either by pressing modifier keys
and moving mouse or by pressing a shortcut. It's not possible to use
the latter and then the former without changing config.
But there is one caveat, in order to use shortcut, you have to uncheck
all modifier keys. This seems to be not very intuitive.
In addition to that, the KCM allows to change shortcut even if there is
some checked modifier.
As the title says, this change makes possible to use both modifier keys
and shortcut to activate this effect without changing config.
KCM:
{F6237308, layout=center, size=full}
BUG: 398124
FIXED-IN: 5.14.0
Reviewers: #kwin, #plasma, #vdg, davidedmundson
Reviewed By: #kwin, #plasma, #vdg, davidedmundson
Subscribers: broulik, abetts, ngraham, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D15272
2018-09-04 12:08:27 +00:00
|
|
|
|
|
|
|
effects->addRepaint(m_lastRect[0].adjusted(-1, -1, 1, 1));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2012-04-19 19:06:11 +00:00
|
|
|
void TrackMouseEffect::slotMouseChanged(const QPoint&, const QPoint&,
|
|
|
|
Qt::MouseButtons, Qt::MouseButtons,
|
|
|
|
Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
[effects/trackmouse] Allow to use both modifiers and shortcut
Summary:
The Track Mouse effect can be toggled either by pressing modifier keys
and moving mouse or by pressing a shortcut. It's not possible to use
the latter and then the former without changing config.
But there is one caveat, in order to use shortcut, you have to uncheck
all modifier keys. This seems to be not very intuitive.
In addition to that, the KCM allows to change shortcut even if there is
some checked modifier.
As the title says, this change makes possible to use both modifier keys
and shortcut to activate this effect without changing config.
KCM:
{F6237308, layout=center, size=full}
BUG: 398124
FIXED-IN: 5.14.0
Reviewers: #kwin, #plasma, #vdg, davidedmundson
Reviewed By: #kwin, #plasma, #vdg, davidedmundson
Subscribers: broulik, abetts, ngraham, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D15272
2018-09-04 12:08:27 +00:00
|
|
|
if (!m_mousePolling) { // we didn't ask for it but maybe someone else did...
|
2012-04-19 19:06:11 +00:00
|
|
|
return;
|
[effects/trackmouse] Allow to use both modifiers and shortcut
Summary:
The Track Mouse effect can be toggled either by pressing modifier keys
and moving mouse or by pressing a shortcut. It's not possible to use
the latter and then the former without changing config.
But there is one caveat, in order to use shortcut, you have to uncheck
all modifier keys. This seems to be not very intuitive.
In addition to that, the KCM allows to change shortcut even if there is
some checked modifier.
As the title says, this change makes possible to use both modifier keys
and shortcut to activate this effect without changing config.
KCM:
{F6237308, layout=center, size=full}
BUG: 398124
FIXED-IN: 5.14.0
Reviewers: #kwin, #plasma, #vdg, davidedmundson
Reviewed By: #kwin, #plasma, #vdg, davidedmundson
Subscribers: broulik, abetts, ngraham, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D15272
2018-09-04 12:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (m_state) {
|
|
|
|
case State::ActivatedByModifiers:
|
|
|
|
if (modifiers == m_modifiers) {
|
2012-04-19 19:06:11 +00:00
|
|
|
return;
|
|
|
|
}
|
[effects/trackmouse] Allow to use both modifiers and shortcut
Summary:
The Track Mouse effect can be toggled either by pressing modifier keys
and moving mouse or by pressing a shortcut. It's not possible to use
the latter and then the former without changing config.
But there is one caveat, in order to use shortcut, you have to uncheck
all modifier keys. This seems to be not very intuitive.
In addition to that, the KCM allows to change shortcut even if there is
some checked modifier.
As the title says, this change makes possible to use both modifier keys
and shortcut to activate this effect without changing config.
KCM:
{F6237308, layout=center, size=full}
BUG: 398124
FIXED-IN: 5.14.0
Reviewers: #kwin, #plasma, #vdg, davidedmundson
Reviewed By: #kwin, #plasma, #vdg, davidedmundson
Subscribers: broulik, abetts, ngraham, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D15272
2018-09-04 12:08:27 +00:00
|
|
|
m_state = State::Inactive;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case State::ActivatedByShortcut:
|
|
|
|
return;
|
|
|
|
|
|
|
|
case State::Inactive:
|
|
|
|
if (modifiers != m_modifiers) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!init()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_state = State::ActivatedByModifiers;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
break;
|
2012-04-19 19:06:11 +00:00
|
|
|
}
|
[effects/trackmouse] Allow to use both modifiers and shortcut
Summary:
The Track Mouse effect can be toggled either by pressing modifier keys
and moving mouse or by pressing a shortcut. It's not possible to use
the latter and then the former without changing config.
But there is one caveat, in order to use shortcut, you have to uncheck
all modifier keys. This seems to be not very intuitive.
In addition to that, the KCM allows to change shortcut even if there is
some checked modifier.
As the title says, this change makes possible to use both modifier keys
and shortcut to activate this effect without changing config.
KCM:
{F6237308, layout=center, size=full}
BUG: 398124
FIXED-IN: 5.14.0
Reviewers: #kwin, #plasma, #vdg, davidedmundson
Reviewed By: #kwin, #plasma, #vdg, davidedmundson
Subscribers: broulik, abetts, ngraham, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D15272
2018-09-04 12:08:27 +00:00
|
|
|
|
|
|
|
effects->addRepaint(m_lastRect[0].adjusted(-1, -1, 1, 1));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void TrackMouseEffect::loadTexture()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2013-08-09 12:19:09 +00:00
|
|
|
QString f[2] = {QStandardPaths::locate(QStandardPaths::DataLocation, QStringLiteral("tm_outer.png")),
|
|
|
|
QStandardPaths::locate(QStandardPaths::DataLocation, QStringLiteral("tm_inner.png"))};
|
2012-04-19 19:06:11 +00:00
|
|
|
if (f[0].isEmpty() || f[1].isEmpty())
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2012-04-19 19:06:11 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
2012-09-20 09:33:32 +00:00
|
|
|
if ( effects->isOpenGLCompositing()) {
|
2012-04-19 19:06:11 +00:00
|
|
|
QImage img(f[i]);
|
|
|
|
m_texture[i] = new GLTexture(img);
|
|
|
|
m_lastRect[i].setSize(img.size());
|
|
|
|
}
|
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
|
|
|
if ( effects->compositingType() == XRenderCompositing) {
|
2013-08-13 05:19:09 +00:00
|
|
|
QImage pixmap(f[i]);
|
2013-02-12 11:34:51 +00:00
|
|
|
m_picture[i] = new XRenderPicture(pixmap);
|
|
|
|
m_size[i] = pixmap.size();
|
|
|
|
m_lastRect[i].setSize(pixmap.size());
|
2012-04-19 19:06:11 +00:00
|
|
|
}
|
|
|
|
#endif
|
2013-06-21 12:57:37 +00:00
|
|
|
if (effects->compositingType() == QPainterCompositing) {
|
|
|
|
m_image[i] = QImage(f[i]);
|
|
|
|
m_lastRect[i].setSize(m_image[i].size());
|
|
|
|
}
|
2012-04-19 19:06:11 +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 TrackMouseEffect::isActive() const
|
|
|
|
{
|
[effects/trackmouse] Allow to use both modifiers and shortcut
Summary:
The Track Mouse effect can be toggled either by pressing modifier keys
and moving mouse or by pressing a shortcut. It's not possible to use
the latter and then the former without changing config.
But there is one caveat, in order to use shortcut, you have to uncheck
all modifier keys. This seems to be not very intuitive.
In addition to that, the KCM allows to change shortcut even if there is
some checked modifier.
As the title says, this change makes possible to use both modifier keys
and shortcut to activate this effect without changing config.
KCM:
{F6237308, layout=center, size=full}
BUG: 398124
FIXED-IN: 5.14.0
Reviewers: #kwin, #plasma, #vdg, davidedmundson
Reviewed By: #kwin, #plasma, #vdg, davidedmundson
Subscribers: broulik, abetts, ngraham, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D15272
2018-09-04 12:08:27 +00:00
|
|
|
return m_state != State::Inactive;
|
2011-08-27 09:21:31 +00:00
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
} // namespace
|