2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2016-02-12 12:30:00 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2013, 2016 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
SPDX-FileCopyrightText: 2018 Roman Gilg <subdiff@gmail.com>
|
|
|
|
SPDX-FileCopyrightText: 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
2016-02-12 12:30:00 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2016-02-12 12:30:00 +00:00
|
|
|
#ifndef KWIN_POINTER_INPUT_H
|
|
|
|
#define KWIN_POINTER_INPUT_H
|
|
|
|
|
|
|
|
#include "input.h"
|
2020-04-02 16:18:01 +00:00
|
|
|
#include "cursor.h"
|
2020-05-18 19:37:41 +00:00
|
|
|
#include "xcursortheme.h"
|
2016-02-12 12:30:00 +00:00
|
|
|
|
2016-02-23 11:29:05 +00:00
|
|
|
#include <QElapsedTimer>
|
2016-02-12 12:30:00 +00:00
|
|
|
#include <QObject>
|
|
|
|
#include <QPointer>
|
|
|
|
#include <QPointF>
|
|
|
|
|
|
|
|
class QWindow;
|
|
|
|
|
2020-04-29 15:18:41 +00:00
|
|
|
namespace KWaylandServer
|
2016-08-22 17:20:57 +00:00
|
|
|
{
|
|
|
|
class SurfaceInterface;
|
|
|
|
}
|
|
|
|
|
2016-02-12 12:30:00 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
2016-02-23 11:29:05 +00:00
|
|
|
class CursorImage;
|
2016-02-12 12:30:00 +00:00
|
|
|
class InputRedirection;
|
|
|
|
class Toplevel;
|
2018-06-07 00:33:54 +00:00
|
|
|
class CursorShape;
|
2016-02-12 12:30:00 +00:00
|
|
|
|
|
|
|
namespace Decoration
|
|
|
|
{
|
|
|
|
class DecoratedClientImpl;
|
|
|
|
}
|
|
|
|
|
2016-05-24 08:57:57 +00:00
|
|
|
namespace LibInput
|
|
|
|
{
|
|
|
|
class Device;
|
|
|
|
}
|
|
|
|
|
2019-12-05 14:34:23 +00:00
|
|
|
uint32_t qtMouseButtonToButton(Qt::MouseButton button);
|
|
|
|
|
2016-05-12 14:33:03 +00:00
|
|
|
class KWIN_EXPORT PointerInputRedirection : public InputDeviceHandler
|
2016-02-12 12:30:00 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit PointerInputRedirection(InputRedirection *parent);
|
Run clang-tidy with modernize-use-override check
Summary:
Currently code base of kwin can be viewed as two pieces. One is very
ancient, and the other one is more modern, which uses new C++ features.
The main problem with the ancient code is that it was written before
C++11 era. So, no override or final keywords, lambdas, etc.
Quite recently, KDE compiler settings were changed to show a warning if
a virtual method has missing override keyword. As you might have already
guessed, this fired back at us because of that ancient code. We had
about 500 new compiler warnings.
A "solution" was proposed to that problem - disable -Wno-suggest-override
and the other similar warning for clang. It's hard to call a solution
because those warnings are disabled not only for the old code, but also
for new. This is not what we want!
The main argument for not actually fixing the problem was that git
history will be screwed as well because of human factor. While good git
history is a very important thing, we should not go crazy about it and
block every change that somehow alters git history. git blame allows to
specify starting revision for a reason.
The other argument (human factor) can be easily solved by using tools
such as clang-tidy. clang-tidy is a clang-based linter for C++. It can
be used for various things, e.g. fixing coding style(e.g. add missing
braces to if statements, readability-braces-around-statements check),
or in our case add missing override keywords.
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, apol, romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D22371
2019-07-22 16:52:26 +00:00
|
|
|
~PointerInputRedirection() override;
|
2016-02-12 12:30:00 +00:00
|
|
|
|
Run clang-tidy with modernize-use-override check
Summary:
Currently code base of kwin can be viewed as two pieces. One is very
ancient, and the other one is more modern, which uses new C++ features.
The main problem with the ancient code is that it was written before
C++11 era. So, no override or final keywords, lambdas, etc.
Quite recently, KDE compiler settings were changed to show a warning if
a virtual method has missing override keyword. As you might have already
guessed, this fired back at us because of that ancient code. We had
about 500 new compiler warnings.
A "solution" was proposed to that problem - disable -Wno-suggest-override
and the other similar warning for clang. It's hard to call a solution
because those warnings are disabled not only for the old code, but also
for new. This is not what we want!
The main argument for not actually fixing the problem was that git
history will be screwed as well because of human factor. While good git
history is a very important thing, we should not go crazy about it and
block every change that somehow alters git history. git blame allows to
specify starting revision for a reason.
The other argument (human factor) can be easily solved by using tools
such as clang-tidy. clang-tidy is a clang-based linter for C++. It can
be used for various things, e.g. fixing coding style(e.g. add missing
braces to if statements, readability-braces-around-statements check),
or in our case add missing override keywords.
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, apol, romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D22371
2019-07-22 16:52:26 +00:00
|
|
|
void init() override;
|
2016-02-12 12:30:00 +00:00
|
|
|
|
|
|
|
void updateAfterScreenChange();
|
|
|
|
bool supportsWarping() const;
|
|
|
|
void warp(const QPointF &pos);
|
|
|
|
|
|
|
|
QPointF pos() const {
|
|
|
|
return m_pos;
|
|
|
|
}
|
|
|
|
Qt::MouseButtons buttons() const {
|
|
|
|
return m_qtButtons;
|
|
|
|
}
|
2018-09-15 00:00:24 +00:00
|
|
|
bool areButtonsPressed() const;
|
2016-02-12 12:30:00 +00:00
|
|
|
|
2016-02-23 11:29:05 +00:00
|
|
|
void setEffectsOverrideCursor(Qt::CursorShape shape);
|
|
|
|
void removeEffectsOverrideCursor();
|
2016-11-15 13:23:51 +00:00
|
|
|
void setWindowSelectionCursor(const QByteArray &shape);
|
|
|
|
void removeWindowSelectionCursor();
|
2016-02-12 12:30:00 +00:00
|
|
|
|
2018-06-11 20:45:09 +00:00
|
|
|
void updatePointerConstraints();
|
2016-11-25 06:17:43 +00:00
|
|
|
|
2018-07-15 18:44:21 +00:00
|
|
|
void setEnableConstraints(bool set);
|
|
|
|
|
2016-11-25 06:17:43 +00:00
|
|
|
bool isConstrained() const {
|
|
|
|
return m_confined || m_locked;
|
|
|
|
}
|
|
|
|
|
2018-09-15 00:00:24 +00:00
|
|
|
bool focusUpdatesBlocked() override;
|
|
|
|
|
2016-02-12 12:30:00 +00:00
|
|
|
/**
|
|
|
|
* @internal
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2016-05-24 08:57:57 +00:00
|
|
|
void processMotion(const QPointF &pos, uint32_t time, LibInput::Device *device = nullptr);
|
2016-10-07 12:47:25 +00:00
|
|
|
/**
|
|
|
|
* @internal
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2016-10-07 12:47:25 +00:00
|
|
|
void processMotion(const QPointF &pos, const QSizeF &delta, const QSizeF &deltaNonAccelerated, uint32_t time, quint64 timeUsec, LibInput::Device *device);
|
2016-02-12 12:30:00 +00:00
|
|
|
/**
|
|
|
|
* @internal
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2016-05-24 08:57:57 +00:00
|
|
|
void processButton(uint32_t button, InputRedirection::PointerButtonState state, uint32_t time, LibInput::Device *device = nullptr);
|
2016-02-12 12:30:00 +00:00
|
|
|
/**
|
|
|
|
* @internal
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
Send axis_source, axis_discrete, and axis_stop
Summary:
So far KWin didn't send axis_source, axis_discrete, and axis_stop. Even
though most of those events are optional, clients need them to work as
expected. For example, one needs axis_source and axis_stop to implement
kinetic scrolling; Xwayland needs axis_discrete to prevent multiple
scroll events when the compositor sends axis deltas greater than 10, etc.
BUG: 404152
FIXED-IN: 5.17.0
Test Plan:
* Content of a webpage in Firefox is moved by one line per each mouse
wheel "click";
* Scrolled gedit using 2 fingers on GNOME Shell, sway, and KDE Plasma;
in all three cases wayland debug looked the same (except diagonal scroll
motions).
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D19000
2019-02-12 09:14:51 +00:00
|
|
|
void processAxis(InputRedirection::PointerAxis axis, qreal delta, qint32 discreteDelta, InputRedirection::PointerAxisSource source, uint32_t time, LibInput::Device *device = nullptr);
|
2016-08-05 12:35:33 +00:00
|
|
|
/**
|
|
|
|
* @internal
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2016-08-05 12:35:33 +00:00
|
|
|
void processSwipeGestureBegin(int fingerCount, quint32 time, KWin::LibInput::Device *device = nullptr);
|
|
|
|
/**
|
|
|
|
* @internal
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2016-08-05 12:35:33 +00:00
|
|
|
void processSwipeGestureUpdate(const QSizeF &delta, quint32 time, KWin::LibInput::Device *device = nullptr);
|
|
|
|
/**
|
|
|
|
* @internal
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2016-08-05 12:35:33 +00:00
|
|
|
void processSwipeGestureEnd(quint32 time, KWin::LibInput::Device *device = nullptr);
|
|
|
|
/**
|
|
|
|
* @internal
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2016-08-05 12:35:33 +00:00
|
|
|
void processSwipeGestureCancelled(quint32 time, KWin::LibInput::Device *device = nullptr);
|
|
|
|
/**
|
|
|
|
* @internal
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2016-08-05 12:35:33 +00:00
|
|
|
void processPinchGestureBegin(int fingerCount, quint32 time, KWin::LibInput::Device *device = nullptr);
|
|
|
|
/**
|
|
|
|
* @internal
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2016-08-05 12:35:33 +00:00
|
|
|
void processPinchGestureUpdate(qreal scale, qreal angleDelta, const QSizeF &delta, quint32 time, KWin::LibInput::Device *device = nullptr);
|
|
|
|
/**
|
|
|
|
* @internal
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2016-08-05 12:35:33 +00:00
|
|
|
void processPinchGestureEnd(quint32 time, KWin::LibInput::Device *device = nullptr);
|
|
|
|
/**
|
|
|
|
* @internal
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2016-08-05 12:35:33 +00:00
|
|
|
void processPinchGestureCancelled(quint32 time, KWin::LibInput::Device *device = nullptr);
|
2016-02-12 12:30:00 +00:00
|
|
|
|
|
|
|
private:
|
2018-09-15 00:00:24 +00:00
|
|
|
void cleanupInternalWindow(QWindow *old, QWindow *now) override;
|
|
|
|
void cleanupDecoration(Decoration::DecoratedClientImpl *old, Decoration::DecoratedClientImpl *now) override;
|
|
|
|
|
|
|
|
void focusUpdate(Toplevel *focusOld, Toplevel *focusNow) override;
|
|
|
|
|
|
|
|
QPointF position() const override;
|
|
|
|
|
2016-10-24 15:09:40 +00:00
|
|
|
void updateOnStartMoveResize();
|
2016-11-15 13:23:51 +00:00
|
|
|
void updateToReset();
|
2016-02-12 12:30:00 +00:00
|
|
|
void updatePosition(const QPointF &pos);
|
|
|
|
void updateButton(uint32_t button, InputRedirection::PointerButtonState state);
|
2020-04-29 15:18:41 +00:00
|
|
|
void warpXcbOnSurfaceLeft(KWaylandServer::SurfaceInterface *surface);
|
2016-11-25 06:17:43 +00:00
|
|
|
QPointF applyPointerConfinement(const QPointF &pos) const;
|
|
|
|
void disconnectConfinedPointerRegionConnection();
|
2018-07-18 07:06:56 +00:00
|
|
|
void disconnectLockedPointerAboutToBeUnboundConnection();
|
2016-11-25 06:17:43 +00:00
|
|
|
void disconnectPointerConstraintsConnection();
|
2020-04-29 15:18:41 +00:00
|
|
|
void breakPointerConstraints(KWaylandServer::SurfaceInterface *surface);
|
2016-02-23 11:29:05 +00:00
|
|
|
CursorImage *m_cursor;
|
2016-02-12 12:30:00 +00:00
|
|
|
bool m_supportsWarping;
|
|
|
|
QPointF m_pos;
|
|
|
|
QHash<uint32_t, InputRedirection::PointerButtonState> m_buttons;
|
|
|
|
Qt::MouseButtons m_qtButtons;
|
2018-09-15 00:00:24 +00:00
|
|
|
QMetaObject::Connection m_focusGeometryConnection;
|
2016-02-12 12:30:00 +00:00
|
|
|
QMetaObject::Connection m_internalWindowConnection;
|
2016-11-25 06:17:43 +00:00
|
|
|
QMetaObject::Connection m_constraintsConnection;
|
2018-06-18 18:14:04 +00:00
|
|
|
QMetaObject::Connection m_constraintsActivatedConnection;
|
2016-11-25 06:17:43 +00:00
|
|
|
QMetaObject::Connection m_confinedPointerRegionConnection;
|
2018-07-18 07:06:56 +00:00
|
|
|
QMetaObject::Connection m_lockedPointerAboutToBeUnboundConnection;
|
2017-09-27 16:17:33 +00:00
|
|
|
QMetaObject::Connection m_decorationGeometryConnection;
|
2016-11-25 06:17:43 +00:00
|
|
|
bool m_confined = false;
|
|
|
|
bool m_locked = false;
|
2018-07-15 18:44:21 +00:00
|
|
|
bool m_enableConstraints = true;
|
2016-02-12 12:30:00 +00:00
|
|
|
};
|
|
|
|
|
2020-04-02 16:18:01 +00:00
|
|
|
class WaylandCursorImage : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2020-05-18 19:37:41 +00:00
|
|
|
explicit WaylandCursorImage(QObject *parent = nullptr);
|
|
|
|
|
2020-04-02 16:18:01 +00:00
|
|
|
struct Image {
|
|
|
|
QImage image;
|
|
|
|
QPoint hotspot;
|
|
|
|
};
|
2020-05-18 19:37:41 +00:00
|
|
|
|
|
|
|
void loadThemeCursor(const CursorShape &shape, Image *cursorImage);
|
|
|
|
void loadThemeCursor(const QByteArray &name, Image *cursorImage);
|
2020-04-02 16:18:01 +00:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void themeChanged();
|
|
|
|
|
|
|
|
private:
|
2020-05-18 19:37:41 +00:00
|
|
|
bool loadThemeCursor_helper(const QByteArray &name, Image *cursorImage);
|
|
|
|
bool ensureCursorTheme();
|
|
|
|
void invalidateCursorTheme();
|
|
|
|
|
|
|
|
KXcursorTheme m_cursorTheme;
|
2020-04-02 16:18:01 +00:00
|
|
|
};
|
|
|
|
|
2016-02-23 11:29:05 +00:00
|
|
|
class CursorImage : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit CursorImage(PointerInputRedirection *parent = nullptr);
|
Run clang-tidy with modernize-use-override check
Summary:
Currently code base of kwin can be viewed as two pieces. One is very
ancient, and the other one is more modern, which uses new C++ features.
The main problem with the ancient code is that it was written before
C++11 era. So, no override or final keywords, lambdas, etc.
Quite recently, KDE compiler settings were changed to show a warning if
a virtual method has missing override keyword. As you might have already
guessed, this fired back at us because of that ancient code. We had
about 500 new compiler warnings.
A "solution" was proposed to that problem - disable -Wno-suggest-override
and the other similar warning for clang. It's hard to call a solution
because those warnings are disabled not only for the old code, but also
for new. This is not what we want!
The main argument for not actually fixing the problem was that git
history will be screwed as well because of human factor. While good git
history is a very important thing, we should not go crazy about it and
block every change that somehow alters git history. git blame allows to
specify starting revision for a reason.
The other argument (human factor) can be easily solved by using tools
such as clang-tidy. clang-tidy is a clang-based linter for C++. It can
be used for various things, e.g. fixing coding style(e.g. add missing
braces to if statements, readability-braces-around-statements check),
or in our case add missing override keywords.
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, apol, romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D22371
2019-07-22 16:52:26 +00:00
|
|
|
~CursorImage() override;
|
2016-02-23 11:29:05 +00:00
|
|
|
|
|
|
|
void setEffectsOverrideCursor(Qt::CursorShape shape);
|
|
|
|
void removeEffectsOverrideCursor();
|
2016-11-15 13:23:51 +00:00
|
|
|
void setWindowSelectionCursor(const QByteArray &shape);
|
|
|
|
void removeWindowSelectionCursor();
|
2016-02-23 11:29:05 +00:00
|
|
|
|
|
|
|
QImage image() const;
|
|
|
|
QPoint hotSpot() const;
|
|
|
|
void markAsRendered();
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void changed();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void reevaluteSource();
|
|
|
|
void update();
|
|
|
|
void updateServerCursor();
|
|
|
|
void updateDecoration();
|
|
|
|
void updateDecorationCursor();
|
2016-02-23 13:08:28 +00:00
|
|
|
void updateMoveResize();
|
2016-03-01 07:42:07 +00:00
|
|
|
void updateDrag();
|
|
|
|
void updateDragCursor();
|
2020-04-02 16:18:01 +00:00
|
|
|
|
|
|
|
void loadThemeCursor(CursorShape shape, WaylandCursorImage::Image *image);
|
|
|
|
void loadThemeCursor(const QByteArray &shape, WaylandCursorImage::Image *image);
|
2016-02-23 11:29:05 +00:00
|
|
|
|
|
|
|
enum class CursorSource {
|
|
|
|
LockScreen,
|
|
|
|
EffectsOverride,
|
2016-02-23 13:08:28 +00:00
|
|
|
MoveResize,
|
2016-02-23 11:29:05 +00:00
|
|
|
PointerSurface,
|
|
|
|
Decoration,
|
2016-03-01 07:42:07 +00:00
|
|
|
DragAndDrop,
|
2016-11-15 13:23:51 +00:00
|
|
|
Fallback,
|
|
|
|
WindowSelector
|
2016-02-23 11:29:05 +00:00
|
|
|
};
|
|
|
|
void setSource(CursorSource source);
|
|
|
|
|
|
|
|
PointerInputRedirection *m_pointer;
|
|
|
|
CursorSource m_currentSource = CursorSource::Fallback;
|
2020-04-02 16:18:01 +00:00
|
|
|
WaylandCursorImage m_waylandImage;
|
2016-02-23 11:29:05 +00:00
|
|
|
|
2020-04-02 16:18:01 +00:00
|
|
|
WaylandCursorImage::Image m_effectsCursor;
|
|
|
|
WaylandCursorImage::Image m_decorationCursor;
|
2016-02-23 11:29:05 +00:00
|
|
|
QMetaObject::Connection m_decorationConnection;
|
2020-04-02 16:18:01 +00:00
|
|
|
WaylandCursorImage::Image m_fallbackCursor;
|
|
|
|
WaylandCursorImage::Image m_moveResizeCursor;
|
|
|
|
WaylandCursorImage::Image m_windowSelectionCursor;
|
2016-02-23 11:29:05 +00:00
|
|
|
QElapsedTimer m_surfaceRenderedTimer;
|
2016-03-01 07:42:07 +00:00
|
|
|
struct {
|
2020-04-02 16:18:01 +00:00
|
|
|
WaylandCursorImage::Image cursor;
|
2016-03-01 07:42:07 +00:00
|
|
|
QMetaObject::Connection connection;
|
|
|
|
} m_drag;
|
2020-04-02 16:18:01 +00:00
|
|
|
struct {
|
|
|
|
QMetaObject::Connection connection;
|
|
|
|
WaylandCursorImage::Image cursor;
|
|
|
|
} m_serverCursor;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Implementation using the InputRedirection framework to get pointer positions.
|
|
|
|
*
|
|
|
|
* Does not support warping of cursor.
|
|
|
|
*/
|
|
|
|
class InputRedirectionCursor : public KWin::Cursor
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit InputRedirectionCursor(QObject *parent);
|
|
|
|
~InputRedirectionCursor() override;
|
|
|
|
protected:
|
|
|
|
void doSetPos() override;
|
|
|
|
void doStartCursorTracking() override;
|
|
|
|
void doStopCursorTracking() override;
|
|
|
|
private Q_SLOTS:
|
|
|
|
void slotPosChanged(const QPointF &pos);
|
|
|
|
void slotPointerButtonChanged();
|
|
|
|
void slotModifiersChanged(Qt::KeyboardModifiers mods, Qt::KeyboardModifiers oldMods);
|
|
|
|
private:
|
|
|
|
Qt::MouseButtons m_currentButtons;
|
2016-02-23 11:29:05 +00:00
|
|
|
};
|
|
|
|
|
2016-02-12 12:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|