2 * Copyright (C) 2015-2016 Canonical, Ltd.
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17#include "MousePointer.h"
18#include "CursorImageProvider.h"
21#include <unity/shell/application/MirPlatformCursor.h>
23#include <QQuickWindow>
24#include <QGuiApplication>
26#include <qpa/qwindowsysteminterface.h>
28MousePointer::MousePointer(QQuickItem *parent)
29 : MirMousePointerInterface(parent)
30 , m_cursorName(QStringLiteral("left_ptr"))
31 , m_themeName(QStringLiteral("default"))
35void MousePointer::handleMouseEvent(ulong timestamp, QPointF movement, Qt::MouseButtons buttons,
36 Qt::KeyboardModifiers modifiers)
42 if (!movement.isNull()) {
46 m_accumulatedMovement += movement;
47 // don't apply the fractional part
48 QPointF appliedMovement(int(m_accumulatedMovement.x()), int(m_accumulatedMovement.y()));
49 m_accumulatedMovement -= appliedMovement;
51 qreal newX = x() + appliedMovement.x();
53 Q_EMIT pushedLeftBoundary(qAbs(newX), buttons);
55 } else if (newX >= parentItem()->width()) {
56 Q_EMIT pushedRightBoundary(newX - (parentItem()->width() - 1), buttons);
57 newX = parentItem()->width() - 1;
61 qreal newY = y() + appliedMovement.y();
64 } else if (newY >= parentItem()->height()) {
65 newY = parentItem()->height() - 1;
69 QPointF scenePosition = mapToItem(nullptr, QPointF(0, 0));
70 QWindowSystemInterface::handleMouseEvent(window(), timestamp, scenePosition /*local*/, scenePosition /*global*/,
74void MousePointer::handleWheelEvent(ulong timestamp, QPoint angleDelta, Qt::KeyboardModifiers modifiers)
80 QPointF scenePosition = mapToItem(nullptr, QPointF(0, 0));
81 QWindowSystemInterface::handleWheelEvent(window(), timestamp, scenePosition /* local */, scenePosition /* global */,
82 QPoint() /* pixelDelta */, angleDelta, modifiers, Qt::ScrollUpdate);
85void MousePointer::itemChange(ItemChange change, const ItemChangeData &value)
87 if (change == ItemSceneChange) {
88 registerWindow(value.window);
92void MousePointer::registerWindow(QWindow *window)
94 if (window == m_registeredWindow) {
98 if (m_registeredWindow) {
99 m_registeredWindow->disconnect(this);
102 m_registeredWindow = window;
104 if (m_registeredWindow) {
105 connect(window, &QWindow::screenChanged, this, &MousePointer::registerScreen);
106 registerScreen(window->screen());
108 registerScreen(nullptr);
112void MousePointer::registerScreen(QScreen *screen)
114 if (m_registeredScreen == screen) {
118 if (m_registeredScreen) {
119 auto previousCursor = dynamic_cast<MirPlatformCursor*>(m_registeredScreen->handle()->cursor());
120 if (previousCursor) {
121 previousCursor->setMousePointer(nullptr);
123 qCritical("QPlatformCursor is not a MirPlatformCursor! Cursor module only works in a Mir server.");
127 m_registeredScreen = screen;
129 if (m_registeredScreen) {
130 auto cursor = dynamic_cast<MirPlatformCursor*>(m_registeredScreen->handle()->cursor());
132 cursor->setMousePointer(this);
134 qCritical("QPlaformCursor is not a MirPlatformCursor! Cursor module only works in Mir.");
139void MousePointer::setCursorName(const QString &cursorName)
141 if (cursorName != m_cursorName) {
142 m_cursorName = cursorName;
143 Q_EMIT cursorNameChanged(m_cursorName);
147void MousePointer::setThemeName(const QString &themeName)
149 if (m_themeName != themeName) {
150 m_themeName = themeName;
151 Q_EMIT themeNameChanged(m_themeName);
155void MousePointer::setCustomCursor(const QCursor &customCursor)
157 CursorImageProvider::instance()->setCustomCursor(customCursor);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list