2020-04-02 16:18:01 +00:00
|
|
|
/********************************************************************
|
2013-02-19 10:25:46 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2013 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
|
|
|
|
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/>.
|
|
|
|
*********************************************************************/
|
|
|
|
#ifndef KWIN_CURSOR_H
|
|
|
|
#define KWIN_CURSOR_H
|
2013-04-05 07:41:25 +00:00
|
|
|
// kwin
|
|
|
|
#include <kwinglobals.h>
|
2013-02-19 10:25:46 +00:00
|
|
|
// Qt
|
|
|
|
#include <QHash>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QPoint>
|
|
|
|
// xcb
|
|
|
|
#include <xcb/xcb.h>
|
|
|
|
|
|
|
|
class QTimer;
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2018-06-07 00:33:54 +00:00
|
|
|
namespace ExtendedCursor {
|
2019-02-02 14:59:42 +00:00
|
|
|
/**
|
|
|
|
* Extension of Qt::CursorShape with values not currently present there
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2018-06-07 00:33:54 +00:00
|
|
|
enum Shape {
|
|
|
|
SizeNorthWest = 0x100 + 0,
|
|
|
|
SizeNorth = 0x100 + 1,
|
|
|
|
SizeNorthEast = 0x100 + 2,
|
|
|
|
SizeEast = 0x100 + 3,
|
|
|
|
SizeWest = 0x100 + 4,
|
|
|
|
SizeSouthEast = 0x100 + 5,
|
|
|
|
SizeSouth = 0x100 + 6,
|
|
|
|
SizeSouthWest = 0x100 + 7
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Wrapper round Qt::CursorShape with extensions enums into a single entity
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2018-06-07 00:33:54 +00:00
|
|
|
class KWIN_EXPORT CursorShape {
|
|
|
|
public:
|
[wayland] Don't use hardcoded move-resize cursor
Summary:
Currently, when resizing a window the cursor doesn't match the resize
direction. The reason for that is the move-resize cursor is hardcoded.
To fix that, CursorImage::updateMoveResize has to use AbstractClient::cursor.
Also, because the move-resize cursor is updated after calling startMoveResize,
we have to connect to AbstractClient::moveResizeCursorChanged.
BUG: 370339
FIXED-IN: 5.15
Reviewers: #kwin, davidedmundson, broulik, romangg, graesslin
Reviewed By: #kwin, graesslin
Subscribers: davidedmundson, romangg, graesslin, kwin
Tags: #kwin
Maniphest Tasks: T5714
Differential Revision: https://phabricator.kde.org/D3202
2018-12-25 15:30:38 +00:00
|
|
|
CursorShape() = default;
|
2018-06-07 00:33:54 +00:00
|
|
|
CursorShape(Qt::CursorShape qtShape) {
|
|
|
|
m_shape = qtShape;
|
|
|
|
}
|
|
|
|
CursorShape(KWin::ExtendedCursor::Shape kwinShape) {
|
|
|
|
m_shape = kwinShape;
|
|
|
|
}
|
|
|
|
bool operator==(const CursorShape &o) const {
|
|
|
|
return m_shape == o.m_shape;
|
|
|
|
}
|
|
|
|
operator int() const {
|
|
|
|
return m_shape;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @brief The name of a cursor shape in the theme.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2018-06-07 00:33:54 +00:00
|
|
|
QByteArray name() const;
|
|
|
|
private:
|
|
|
|
int m_shape = Qt::ArrowCursor;
|
|
|
|
};
|
|
|
|
|
2013-02-19 10:25:46 +00:00
|
|
|
/**
|
|
|
|
* @short Replacement for QCursor.
|
|
|
|
*
|
|
|
|
* This class provides a similar API to QCursor and should be preferred inside KWin. It allows to
|
|
|
|
* get the position and warp the mouse cursor with static methods just like QCursor. It also provides
|
|
|
|
* the possibility to get an X11 cursor for a Qt::CursorShape - a functionality lost in Qt 5's QCursor
|
|
|
|
* implementation.
|
|
|
|
*
|
|
|
|
* In addition the class provides a mouse polling facility as required by e.g. Effects and ScreenEdges
|
|
|
|
* and emits signals when the mouse position changes. In opposite to QCursor this class is a QObject
|
|
|
|
* and cannot be constructed. Instead it provides a singleton getter, though the most important
|
|
|
|
* methods are wrapped in a static method, just like QCursor.
|
|
|
|
*
|
|
|
|
* The actual implementation is split into two parts: a system independent interface and a windowing
|
|
|
|
* system specific subclass. So far only an X11 backend is implemented which uses query pointer to
|
|
|
|
* fetch the position and warp pointer to set the position. It uses a timer based mouse polling and
|
|
|
|
* can provide X11 cursors through the XCursor library.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2015-05-05 15:58:09 +00:00
|
|
|
class KWIN_EXPORT Cursor : public QObject
|
2013-02-19 10:25:46 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2020-04-02 16:18:01 +00:00
|
|
|
Cursor(QObject* 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
|
|
|
~Cursor() override;
|
2013-02-19 10:25:46 +00:00
|
|
|
void startMousePolling();
|
|
|
|
void stopMousePolling();
|
2013-05-19 07:32:27 +00:00
|
|
|
/**
|
|
|
|
* @brief Enables tracking changes of cursor images.
|
|
|
|
*
|
2019-01-12 10:31:32 +00:00
|
|
|
* After enabling cursor change tracking the signal cursorChanged will be emitted
|
2013-05-19 07:32:27 +00:00
|
|
|
* whenever a change to the cursor image is recognized.
|
|
|
|
*
|
2019-01-12 10:31:32 +00:00
|
|
|
* Use stopCursorTracking to no longer emit this signal. Note: the signal will be
|
2013-05-19 07:32:27 +00:00
|
|
|
* emitted until each call of this method has been matched with a call to stopCursorTracking.
|
|
|
|
*
|
|
|
|
* This tracking is not about pointer position tracking.
|
|
|
|
* @see stopCursorTracking
|
|
|
|
* @see cursorChanged
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2013-05-19 07:32:27 +00:00
|
|
|
void startCursorTracking();
|
|
|
|
/**
|
|
|
|
* @brief Disables tracking changes of cursor images.
|
|
|
|
*
|
2019-01-11 13:36:17 +00:00
|
|
|
* Only call after using startCursorTracking.
|
2013-05-19 07:32:27 +00:00
|
|
|
*
|
|
|
|
* @see startCursorTracking
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2013-05-19 07:32:27 +00:00
|
|
|
void stopCursorTracking();
|
2013-02-19 10:25:46 +00:00
|
|
|
|
2013-06-27 07:06:16 +00:00
|
|
|
/**
|
|
|
|
* @brief The name of the currently used Cursor theme.
|
|
|
|
*
|
|
|
|
* @return const QString&
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2013-06-27 07:06:16 +00:00
|
|
|
const QString &themeName() const;
|
|
|
|
/**
|
|
|
|
* @brief The size of the currently used Cursor theme.
|
|
|
|
*
|
|
|
|
* @return int
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2013-06-27 07:06:16 +00:00
|
|
|
int themeSize() const;
|
2016-02-22 12:18:18 +00:00
|
|
|
/**
|
|
|
|
* @return list of alternative names for the cursor with @p name
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2020-05-18 19:37:41 +00:00
|
|
|
static QVector<QByteArray> cursorAlternativeNames(const QByteArray &name);
|
|
|
|
/**
|
|
|
|
* Returns the default Xcursor theme name.
|
|
|
|
*/
|
|
|
|
static QString defaultThemeName();
|
|
|
|
/**
|
|
|
|
* Returns the default Xcursor theme size.
|
|
|
|
*/
|
|
|
|
static int defaultThemeSize();
|
2013-06-27 07:06:16 +00:00
|
|
|
|
2013-02-19 10:25:46 +00:00
|
|
|
/**
|
|
|
|
* Returns the current cursor position. This method does an update of the mouse position if
|
|
|
|
* needed. It's save to call it multiple times.
|
|
|
|
*
|
2019-01-12 10:31:32 +00:00
|
|
|
* Implementing subclasses should prefer to use currentPos which is not performing a check
|
2013-02-19 10:25:46 +00:00
|
|
|
* for update.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2020-04-02 16:18:01 +00:00
|
|
|
QPoint pos();
|
2013-02-19 10:25:46 +00:00
|
|
|
/**
|
|
|
|
* Warps the mouse cursor to new @p pos.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2020-04-02 16:18:01 +00:00
|
|
|
void setPos(const QPoint &pos);
|
|
|
|
void setPos(int x, int y);
|
|
|
|
xcb_cursor_t x11Cursor(CursorShape shape);
|
2015-01-28 09:14:56 +00:00
|
|
|
/**
|
2018-06-07 00:33:54 +00:00
|
|
|
* Notice: if available always use the CursorShape variant to avoid cache duplicates for
|
2019-01-12 10:31:32 +00:00
|
|
|
* ambiguous cursor names in the non existing cursor name specification
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2020-04-02 16:18:01 +00:00
|
|
|
xcb_cursor_t x11Cursor(const QByteArray &name);
|
|
|
|
|
|
|
|
QImage image() const { return m_image; }
|
|
|
|
QPoint hotspot() const { return m_hotspot; }
|
|
|
|
QRect geometry() const;
|
|
|
|
|
|
|
|
void updateCursor(const QImage &image, const QPoint &hotspot);
|
|
|
|
void markAsRendered() {
|
|
|
|
Q_EMIT rendered(geometry());
|
|
|
|
}
|
2013-02-19 10:25:46 +00:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
2020-04-02 16:18:01 +00:00
|
|
|
void posChanged(const QPoint& pos);
|
2013-02-19 10:25:46 +00:00
|
|
|
void mouseChanged(const QPoint& pos, const QPoint& oldpos,
|
|
|
|
Qt::MouseButtons buttons, Qt::MouseButtons oldbuttons,
|
|
|
|
Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers);
|
2013-05-19 07:32:27 +00:00
|
|
|
/**
|
|
|
|
* @brief Signal emitted when the cursor image changes.
|
|
|
|
*
|
2019-01-11 13:36:17 +00:00
|
|
|
* To enable these signals use startCursorTracking.
|
2013-05-19 07:32:27 +00:00
|
|
|
*
|
|
|
|
* @see startCursorTracking
|
|
|
|
* @see stopCursorTracking
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2016-10-18 07:45:49 +00:00
|
|
|
void cursorChanged();
|
2013-06-27 07:06:16 +00:00
|
|
|
void themeChanged();
|
2013-02-19 10:25:46 +00:00
|
|
|
|
2020-04-02 16:18:01 +00:00
|
|
|
void rendered(const QRect &geometry);
|
|
|
|
|
2013-02-19 10:25:46 +00:00
|
|
|
protected:
|
|
|
|
/**
|
2019-01-12 10:31:32 +00:00
|
|
|
* Called from x11Cursor to actually retrieve the X11 cursor. Base implementation returns
|
2013-02-19 10:25:46 +00:00
|
|
|
* a null cursor, an implementing subclass should implement this method if it can provide X11
|
|
|
|
* mouse cursors.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2018-06-07 00:33:54 +00:00
|
|
|
virtual xcb_cursor_t getX11Cursor(CursorShape shape);
|
2015-01-28 09:14:56 +00:00
|
|
|
/**
|
2019-01-12 10:31:32 +00:00
|
|
|
* Called from x11Cursor to actually retrieve the X11 cursor. Base implementation returns
|
2015-01-28 09:14:56 +00:00
|
|
|
* a null cursor, an implementing subclass should implement this method if it can provide X11
|
|
|
|
* mouse cursors.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2015-01-28 09:14:56 +00:00
|
|
|
virtual xcb_cursor_t getX11Cursor(const QByteArray &name);
|
2013-02-19 10:25:46 +00:00
|
|
|
/**
|
|
|
|
* Performs the actual warping of the cursor.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2013-02-19 10:25:46 +00:00
|
|
|
virtual void doSetPos();
|
|
|
|
/**
|
2019-01-12 10:31:32 +00:00
|
|
|
* Called from @ref pos() to allow syncing the internal position with the underlying
|
2013-02-19 10:25:46 +00:00
|
|
|
* system's cursor position.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2013-02-19 10:25:46 +00:00
|
|
|
virtual void doGetPos();
|
|
|
|
/**
|
2019-01-12 10:31:32 +00:00
|
|
|
* Called from startMousePolling when the mouse polling gets activated. Base implementation
|
2013-02-19 10:25:46 +00:00
|
|
|
* does nothing, inheriting classes can overwrite to e.g. start a timer.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2013-02-19 10:25:46 +00:00
|
|
|
virtual void doStartMousePolling();
|
|
|
|
/**
|
2019-01-12 10:31:32 +00:00
|
|
|
* Called from stopMousePolling when the mouse polling gets deactivated. Base implementation
|
2013-02-19 10:25:46 +00:00
|
|
|
* does nothing, inheriting classes can overwrite to e.g. stop a timer.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2013-02-19 10:25:46 +00:00
|
|
|
virtual void doStopMousePolling();
|
2013-05-19 07:32:27 +00:00
|
|
|
/**
|
2019-01-12 10:31:32 +00:00
|
|
|
* Called from startCursorTracking when cursor image tracking gets activated. Inheriting class needs
|
2013-05-19 07:32:27 +00:00
|
|
|
* to overwrite to enable platform specific code for the tracking.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2013-05-19 07:32:27 +00:00
|
|
|
virtual void doStartCursorTracking();
|
|
|
|
/**
|
2019-01-12 10:31:32 +00:00
|
|
|
* Called from stopCursorTracking when cursor image tracking gets deactivated. Inheriting class needs
|
2013-05-19 07:32:27 +00:00
|
|
|
* to overwrite to disable platform specific code for the tracking.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2013-05-19 07:32:27 +00:00
|
|
|
virtual void doStopCursorTracking();
|
2015-02-21 08:44:43 +00:00
|
|
|
bool isCursorTracking() const;
|
2013-02-19 10:25:46 +00:00
|
|
|
/**
|
|
|
|
* Provides the actual internal cursor position to inheriting classes. If an inheriting class needs
|
2019-01-11 13:36:17 +00:00
|
|
|
* access to the cursor position this method should be used instead of the static @ref pos, as
|
2013-02-19 10:25:46 +00:00
|
|
|
* the static method syncs with the underlying system's cursor.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2013-02-19 10:25:46 +00:00
|
|
|
const QPoint ¤tPos() const;
|
|
|
|
/**
|
|
|
|
* Updates the internal position to @p pos without warping the pointer as
|
2019-01-12 10:31:32 +00:00
|
|
|
* setPos does.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2013-02-19 10:25:46 +00:00
|
|
|
void updatePos(const QPoint &pos);
|
|
|
|
void updatePos(int x, int y);
|
|
|
|
|
2013-06-27 07:06:16 +00:00
|
|
|
private Q_SLOTS:
|
|
|
|
void loadThemeSettings();
|
2015-01-08 16:03:25 +00:00
|
|
|
void slotKGlobalSettingsNotifyChange(int type, int arg);
|
2013-06-27 07:06:16 +00:00
|
|
|
|
2013-02-19 10:25:46 +00:00
|
|
|
private:
|
2015-01-08 14:09:23 +00:00
|
|
|
void updateTheme(const QString &name, int size);
|
2015-01-08 16:03:25 +00:00
|
|
|
void loadThemeFromKConfig();
|
2013-02-19 10:25:46 +00:00
|
|
|
QPoint m_pos;
|
2020-04-02 16:18:01 +00:00
|
|
|
QPoint m_hotspot;
|
|
|
|
QImage m_image;
|
2013-02-19 10:25:46 +00:00
|
|
|
int m_mousePollingCounter;
|
2013-05-19 07:32:27 +00:00
|
|
|
int m_cursorTrackingCounter;
|
2013-06-27 07:06:16 +00:00
|
|
|
QString m_themeName;
|
|
|
|
int m_themeSize;
|
2013-02-19 10:25:46 +00:00
|
|
|
};
|
|
|
|
|
2020-04-02 16:18:01 +00:00
|
|
|
|
|
|
|
class KWIN_EXPORT Cursors : public QObject
|
2013-06-26 12:32:03 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2020-04-02 16:18:01 +00:00
|
|
|
Cursor* mouse() const {
|
|
|
|
return m_mouse;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setMouse(Cursor* mouse) {
|
|
|
|
if (m_mouse != mouse) {
|
|
|
|
m_mouse = mouse;
|
|
|
|
|
|
|
|
addCursor(m_mouse);
|
|
|
|
setCurrentCursor(m_mouse);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void addCursor(Cursor* cursor);
|
|
|
|
void removeCursor(Cursor* cursor);
|
|
|
|
|
|
|
|
///@returns the last cursor that moved
|
|
|
|
Cursor* currentCursor() const {
|
|
|
|
return m_currentCursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Cursors* self();
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void currentCursorChanged(Cursor* cursor);
|
|
|
|
void currentCursorRendered(const QRect &geometry);
|
|
|
|
void positionChanged(Cursor* cursor, const QPoint &position);
|
|
|
|
|
2013-06-26 12:32:03 +00:00
|
|
|
private:
|
2020-04-02 16:18:01 +00:00
|
|
|
void emitCurrentCursorChanged();
|
|
|
|
void setCurrentCursor(Cursor* cursor);
|
|
|
|
|
|
|
|
static Cursors* s_self;
|
|
|
|
Cursor* m_currentCursor = nullptr;
|
|
|
|
Cursor* m_mouse = nullptr;
|
|
|
|
QVector<Cursor*> m_cursors;
|
2013-06-26 12:32:03 +00:00
|
|
|
};
|
|
|
|
|
2013-02-19 10:25:46 +00:00
|
|
|
inline const QPoint &Cursor::currentPos() const
|
|
|
|
{
|
|
|
|
return m_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Cursor::updatePos(int x, int y)
|
|
|
|
{
|
|
|
|
updatePos(QPoint(x, y));
|
|
|
|
}
|
|
|
|
|
2013-06-27 07:06:16 +00:00
|
|
|
inline const QString& Cursor::themeName() const
|
|
|
|
{
|
|
|
|
return m_themeName;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int Cursor::themeSize() const
|
|
|
|
{
|
|
|
|
return m_themeSize;
|
|
|
|
}
|
|
|
|
|
2015-02-21 08:44:43 +00:00
|
|
|
inline bool Cursor::isCursorTracking() const
|
|
|
|
{
|
|
|
|
return m_cursorTrackingCounter > 0;
|
|
|
|
}
|
|
|
|
|
2013-02-19 10:25:46 +00:00
|
|
|
}
|
|
|
|
|
[wayland] Don't use hardcoded move-resize cursor
Summary:
Currently, when resizing a window the cursor doesn't match the resize
direction. The reason for that is the move-resize cursor is hardcoded.
To fix that, CursorImage::updateMoveResize has to use AbstractClient::cursor.
Also, because the move-resize cursor is updated after calling startMoveResize,
we have to connect to AbstractClient::moveResizeCursorChanged.
BUG: 370339
FIXED-IN: 5.15
Reviewers: #kwin, davidedmundson, broulik, romangg, graesslin
Reviewed By: #kwin, graesslin
Subscribers: davidedmundson, romangg, graesslin, kwin
Tags: #kwin
Maniphest Tasks: T5714
Differential Revision: https://phabricator.kde.org/D3202
2018-12-25 15:30:38 +00:00
|
|
|
Q_DECLARE_METATYPE(KWin::CursorShape)
|
|
|
|
|
2013-02-19 10:25:46 +00:00
|
|
|
#endif // KWIN_CURSOR_H
|