2 * Copyright (C) 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 "InputDispatcherFilter.h"
18#include "MousePointer.h"
21#include <QGuiApplication>
23#include <qpa/qplatformnativeinterface.h>
24#include <qpa/qplatformscreen.h>
26InputDispatcherFilter *InputDispatcherFilter::instance()
28 static InputDispatcherFilter filter;
32InputDispatcherFilter::InputDispatcherFilter(QObject *parent)
35 QPlatformNativeInterface *ni = QGuiApplication::platformNativeInterface();
36 m_inputDispatcher = static_cast<QObject*>(ni->nativeResourceForIntegration("InputDispatcher"));
37 if (m_inputDispatcher) {
38 m_inputDispatcher->installEventFilter(this);
42void InputDispatcherFilter::registerPointer(MousePointer *pointer)
44 // allow first registered pointer to be visible.
45 pointer->setVisible(m_pointers.count() == 0);
47 m_pointers.insert(pointer);
48 connect(pointer, &MousePointer::mouseMoved, this, [this, pointer]() {
49 Q_FOREACH(auto p, m_pointers) {
50 p->setVisible(p == pointer);
55void InputDispatcherFilter::unregisterPointer(MousePointer *pointer)
57 m_pointers.remove(pointer);
58 disconnect(pointer, &MousePointer::mouseMoved, this, 0);
61void InputDispatcherFilter::setPosition(const QPointF &pos)
66bool InputDispatcherFilter::eventFilter(QObject *o, QEvent *e)
68 if (o != m_inputDispatcher) return false;
71 case QEvent::MouseMove:
72 case QEvent::MouseButtonPress:
73 case QEvent::MouseButtonRelease:
75 // FIXME - removed all input filtering for now - this was for extended display
78// QMouseEvent* me = static_cast<QMouseEvent*>(e);
80// // Local position gives relative change of mouse pointer.
81// QPointF localPos = me->localPos();
82// QPointF globalPos = me->screenPos();
84// // Adjust the position
85// QPointF oldPos(mousePosition.isNull() ? globalPos : mousePosition);
86// QPointF newPos = adjustedPositionForMovement(oldPos, localPos);
88// QScreen* currentScreen = screenAt(newPos);
89// if (currentScreen) {
90// QRect screenRect = currentScreen->geometry();
91// qreal unadjustedX = (oldPos + localPos).x();
92// if (unadjustedX < screenRect.left()) {
93// Q_EMIT pushedLeftBoundary(currentScreen, qAbs(unadjustedX - screenRect.left()), me->buttons());
94// } else if (unadjustedX > screenRect.right()) {
95// Q_EMIT pushedRightBoundary(currentScreen, qAbs(unadjustedX - screenRect.right()), me->buttons());
100// QMouseEvent eCopy(me->type(), me->localPos(), newPos, me->button(), me->buttons(), me->modifiers());
101// eCopy.setTimestamp(me->timestamp());
111QPointF InputDispatcherFilter::adjustedPositionForMovement(const QPointF &pt, const QPointF &movement) const
113 QPointF adjusted = pt + movement;
115 auto screen = screenAt(adjusted); // first check if our move was to a valid screen.
118 } else if ((screen = screenAt(pt))) { // then check if our old position was valid
119 QRectF screenBounds = screen->geometry();
120 // bound the new position to the old screen geometry
121 adjusted.rx() = qMax(screenBounds.left(), qMin(adjusted.x(), screenBounds.right()-1));
122 adjusted.ry() = qMax(screenBounds.top(), qMin(adjusted.y(), screenBounds.bottom()-1));
124 auto screens = QGuiApplication::screens();
126 // center of first screen with a pointer.
127 Q_FOREACH(QScreen* screen, screens) {
128 Q_FOREACH(MousePointer* pointer, m_pointers) {
129 if (pointer->screen() == screen) {
130 return screen->geometry().center();
138QScreen *InputDispatcherFilter::screenAt(const QPointF &pt) const
140 Q_FOREACH(MousePointer* pointer, m_pointers) {
141 QScreen* screen = pointer->screen();
142 if (screen && screen->geometry().contains(pt.toPoint()))
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