2013-06-26 08:15:20 +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_INPUT_H
|
|
|
|
#define KWIN_INPUT_H
|
|
|
|
#include <kwinglobals.h>
|
2015-02-19 09:38:49 +00:00
|
|
|
#include <QAction>
|
2013-06-26 08:15:20 +00:00
|
|
|
#include <QObject>
|
|
|
|
#include <QPoint>
|
2016-05-12 14:33:03 +00:00
|
|
|
#include <QPointer>
|
2013-07-02 09:44:18 +00:00
|
|
|
#include <config-kwin.h>
|
2013-06-26 08:15:20 +00:00
|
|
|
|
2016-05-06 07:53:36 +00:00
|
|
|
#include <KSharedConfig>
|
|
|
|
|
2015-06-26 11:47:08 +00:00
|
|
|
class KGlobalAccelInterface;
|
2013-07-10 09:41:16 +00:00
|
|
|
class QKeySequence;
|
2016-02-15 12:51:36 +00:00
|
|
|
class QMouseEvent;
|
|
|
|
class QKeyEvent;
|
|
|
|
class QWheelEvent;
|
2013-07-10 09:41:16 +00:00
|
|
|
|
2013-06-26 08:15:20 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
2013-07-10 09:41:16 +00:00
|
|
|
class GlobalShortcutsManager;
|
2013-07-01 06:37:59 +00:00
|
|
|
class Toplevel;
|
2016-02-03 14:17:49 +00:00
|
|
|
class InputEventFilter;
|
2016-02-15 12:42:48 +00:00
|
|
|
class KeyboardInputRedirection;
|
2016-02-12 12:30:00 +00:00
|
|
|
class PointerInputRedirection;
|
2016-02-15 08:36:59 +00:00
|
|
|
class TouchInputRedirection;
|
2013-06-26 08:15:20 +00:00
|
|
|
|
2016-05-12 14:33:03 +00:00
|
|
|
namespace Decoration
|
|
|
|
{
|
|
|
|
class DecoratedClientImpl;
|
|
|
|
}
|
|
|
|
|
2015-03-30 06:55:41 +00:00
|
|
|
namespace LibInput
|
|
|
|
{
|
|
|
|
class Connection;
|
|
|
|
}
|
|
|
|
|
2013-06-26 08:15:20 +00:00
|
|
|
/**
|
|
|
|
* @brief This class is responsible for redirecting incoming input to the surface which currently
|
|
|
|
* has input or send enter/leave events.
|
|
|
|
*
|
|
|
|
* In addition input is intercepted before passed to the surfaces to have KWin internal areas
|
|
|
|
* getting input first (e.g. screen edges) and filter the input event out if we currently have
|
|
|
|
* a full input grab.
|
|
|
|
*
|
|
|
|
*/
|
2015-06-26 11:47:08 +00:00
|
|
|
class KWIN_EXPORT InputRedirection : public QObject
|
2013-06-26 08:15:20 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
enum PointerButtonState {
|
|
|
|
PointerButtonReleased,
|
|
|
|
PointerButtonPressed
|
|
|
|
};
|
|
|
|
enum PointerAxis {
|
|
|
|
PointerAxisVertical,
|
|
|
|
PointerAxisHorizontal
|
|
|
|
};
|
2013-07-02 09:44:18 +00:00
|
|
|
enum KeyboardKeyState {
|
|
|
|
KeyboardKeyReleased,
|
2016-02-19 06:53:20 +00:00
|
|
|
KeyboardKeyPressed,
|
|
|
|
KeyboardKeyAutoRepeat
|
2013-07-02 09:44:18 +00:00
|
|
|
};
|
2013-06-26 08:15:20 +00:00
|
|
|
virtual ~InputRedirection();
|
2015-06-26 11:47:08 +00:00
|
|
|
void init();
|
2013-06-26 08:15:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return const QPointF& The current global pointer position
|
|
|
|
*/
|
2016-02-12 12:30:00 +00:00
|
|
|
QPointF globalPointer() const;
|
2013-06-26 12:32:03 +00:00
|
|
|
Qt::MouseButtons qtButtonStates() const;
|
2013-07-02 09:44:18 +00:00
|
|
|
Qt::KeyboardModifiers keyboardModifiers() const;
|
2013-06-26 08:15:20 +00:00
|
|
|
|
2013-07-10 09:41:16 +00:00
|
|
|
void registerShortcut(const QKeySequence &shortcut, QAction *action);
|
2015-02-19 09:38:49 +00:00
|
|
|
/**
|
|
|
|
* @overload
|
|
|
|
*
|
|
|
|
* Like registerShortcut, but also connects QAction::triggered to the @p slot on @p receiver.
|
|
|
|
* It's recommended to use this method as it ensures that the X11 timestamp is updated prior
|
|
|
|
* to the @p slot being invoked. If not using this overload it's required to ensure that
|
|
|
|
* registerShortcut is called before connecting to QAction's triggered signal.
|
|
|
|
**/
|
|
|
|
template <typename T>
|
|
|
|
void registerShortcut(const QKeySequence &shortcut, QAction *action, T *receiver, void (T::*slot)());
|
2013-07-14 20:52:58 +00:00
|
|
|
void registerPointerShortcut(Qt::KeyboardModifiers modifiers, Qt::MouseButton pointerButtons, QAction *action);
|
2013-07-15 09:26:56 +00:00
|
|
|
void registerAxisShortcut(Qt::KeyboardModifiers modifiers, PointerAxisDirection axis, QAction *action);
|
2015-06-26 11:47:08 +00:00
|
|
|
void registerGlobalAccel(KGlobalAccelInterface *interface);
|
2013-07-10 09:41:16 +00:00
|
|
|
|
2013-06-26 08:15:20 +00:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
void processPointerMotion(const QPointF &pos, uint32_t time);
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
void processPointerButton(uint32_t button, PointerButtonState state, uint32_t time);
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
void processPointerAxis(PointerAxis axis, qreal delta, uint32_t time);
|
2013-07-02 09:44:18 +00:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
void processKeyboardKey(uint32_t key, KeyboardKeyState state, uint32_t time);
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
void processKeyboardModifiers(uint32_t modsDepressed, uint32_t modsLatched, uint32_t modsLocked, uint32_t group);
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
**/
|
|
|
|
void processKeymapChange(int fd, uint32_t size);
|
2015-03-25 13:50:14 +00:00
|
|
|
void processTouchDown(qint32 id, const QPointF &pos, quint32 time);
|
|
|
|
void processTouchUp(qint32 id, quint32 time);
|
|
|
|
void processTouchMotion(qint32 id, const QPointF &pos, quint32 time);
|
|
|
|
void cancelTouch();
|
|
|
|
void touchFrame();
|
2013-06-26 08:15:20 +00:00
|
|
|
|
2015-06-05 04:43:12 +00:00
|
|
|
bool supportsPointerWarping() const;
|
|
|
|
void warpPointer(const QPointF &pos);
|
|
|
|
|
2016-02-15 14:40:25 +00:00
|
|
|
/**
|
|
|
|
* Adds the @p filter to the list of event filters and makes it the first
|
|
|
|
* event filter in processing.
|
|
|
|
*
|
|
|
|
* Note: the event filter will get events before the lock screen can get them, thus
|
|
|
|
* this is a security relevant method.
|
|
|
|
**/
|
|
|
|
void prepandInputEventFilter(InputEventFilter *filter);
|
2016-02-03 14:17:49 +00:00
|
|
|
void uninstallInputEventFilter(InputEventFilter *filter);
|
|
|
|
Toplevel *findToplevel(const QPoint &pos);
|
|
|
|
GlobalShortcutsManager *shortcuts() const {
|
|
|
|
return m_shortcuts;
|
|
|
|
}
|
|
|
|
|
2016-02-12 12:30:00 +00:00
|
|
|
QVector<InputEventFilter*> filters() const {
|
|
|
|
return m_filters;
|
|
|
|
}
|
2016-02-15 12:42:48 +00:00
|
|
|
KeyboardInputRedirection *keyboard() const {
|
|
|
|
return m_keyboard;
|
|
|
|
}
|
2016-02-12 12:30:00 +00:00
|
|
|
PointerInputRedirection *pointer() const {
|
|
|
|
return m_pointer;
|
|
|
|
}
|
2016-02-15 08:36:59 +00:00
|
|
|
TouchInputRedirection *touch() const {
|
|
|
|
return m_touch;
|
|
|
|
}
|
2013-07-01 06:37:59 +00:00
|
|
|
|
2016-08-03 06:31:58 +00:00
|
|
|
bool hasAlphaNumericKeyboard();
|
|
|
|
|
2013-06-26 08:15:20 +00:00
|
|
|
Q_SIGNALS:
|
|
|
|
/**
|
|
|
|
* @brief Emitted when the global pointer position changed
|
|
|
|
*
|
|
|
|
* @param pos The new global pointer position.
|
|
|
|
*/
|
|
|
|
void globalPointerChanged(const QPointF &pos);
|
|
|
|
/**
|
|
|
|
* @brief Emitted when the state of a pointer button changed.
|
|
|
|
*
|
|
|
|
* @param button The button which changed
|
|
|
|
* @param state The new button state
|
|
|
|
*/
|
2013-06-26 12:32:03 +00:00
|
|
|
void pointerButtonStateChanged(uint32_t button, InputRedirection::PointerButtonState state);
|
2013-06-26 08:15:20 +00:00
|
|
|
/**
|
|
|
|
* @brief Emitted when a pointer axis changed
|
|
|
|
*
|
|
|
|
* @param axis The axis on which the even occurred
|
|
|
|
* @param delta The delta of the event.
|
|
|
|
*/
|
2013-06-26 12:32:03 +00:00
|
|
|
void pointerAxisChanged(InputRedirection::PointerAxis axis, qreal delta);
|
2013-07-02 10:16:03 +00:00
|
|
|
/**
|
|
|
|
* @brief Emitted when the modifiers changes.
|
|
|
|
*
|
|
|
|
* Only emitted for the mask which is provided by Qt::KeyboardModifiers, if other modifiers
|
|
|
|
* change signal is not emitted
|
|
|
|
*
|
|
|
|
* @param newMods The new modifiers state
|
|
|
|
* @param oldMods The previous modifiers state
|
|
|
|
*/
|
|
|
|
void keyboardModifiersChanged(Qt::KeyboardModifiers newMods, Qt::KeyboardModifiers oldMods);
|
2015-08-31 06:55:26 +00:00
|
|
|
/**
|
|
|
|
* @brief Emitted when the state of a key changed.
|
|
|
|
*
|
|
|
|
* @param keyCode The keycode of the key which changed
|
|
|
|
* @param oldMods The new key state
|
|
|
|
*/
|
|
|
|
void keyStateChanged(quint32 keyCode, InputRedirection::KeyboardKeyState state);
|
2013-06-26 08:15:20 +00:00
|
|
|
|
2016-08-03 06:31:58 +00:00
|
|
|
void hasAlphaNumericKeyboardChanged(bool set);
|
|
|
|
|
2013-06-26 08:15:20 +00:00
|
|
|
private:
|
2014-08-15 07:30:08 +00:00
|
|
|
void setupLibInput();
|
2015-03-30 06:55:41 +00:00
|
|
|
void setupLibInputWithScreens();
|
2015-02-19 09:38:49 +00:00
|
|
|
void registerShortcutForGlobalAccelTimestamp(QAction *action);
|
2015-06-13 15:54:08 +00:00
|
|
|
void setupWorkspace();
|
2015-09-15 08:29:06 +00:00
|
|
|
void reconfigure();
|
2016-02-03 14:17:49 +00:00
|
|
|
void setupInputFilters();
|
|
|
|
void installInputEventFilter(InputEventFilter *filter);
|
2016-02-15 12:42:48 +00:00
|
|
|
KeyboardInputRedirection *m_keyboard;
|
2016-02-12 12:30:00 +00:00
|
|
|
PointerInputRedirection *m_pointer;
|
2016-02-15 08:36:59 +00:00
|
|
|
TouchInputRedirection *m_touch;
|
2013-06-26 08:15:20 +00:00
|
|
|
|
2013-07-10 09:41:16 +00:00
|
|
|
GlobalShortcutsManager *m_shortcuts;
|
|
|
|
|
2015-03-30 06:55:41 +00:00
|
|
|
LibInput::Connection *m_libInput = nullptr;
|
|
|
|
|
2016-02-03 14:17:49 +00:00
|
|
|
QVector<InputEventFilter*> m_filters;
|
2016-05-06 07:53:36 +00:00
|
|
|
KSharedConfigPtr m_inputConfig;
|
2016-02-03 14:17:49 +00:00
|
|
|
|
2013-06-26 08:15:20 +00:00
|
|
|
KWIN_SINGLETON(InputRedirection)
|
|
|
|
friend InputRedirection *input();
|
2016-02-03 14:17:49 +00:00
|
|
|
friend class DecorationEventFilter;
|
|
|
|
friend class InternalWindowEventFilter;
|
|
|
|
friend class ForwardInputFilter;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class for filtering input events inside InputRedirection.
|
|
|
|
*
|
|
|
|
* The idea behind the InputEventFilter is to have task oriented
|
|
|
|
* filters. E.g. there is one filter taking care of a locked screen,
|
|
|
|
* one to take care of interacting with window decorations, etc.
|
|
|
|
*
|
|
|
|
* A concrete subclass can reimplement the virtual methods and decide
|
|
|
|
* whether an event should be filtered out or not by returning either
|
|
|
|
* @c true or @c false. E.g. the lock screen filter can easily ensure
|
|
|
|
* that all events are filtered out.
|
|
|
|
*
|
|
|
|
* As soon as a filter returns @c true the processing is stopped. If
|
|
|
|
* a filter returns @c false the next one is invoked. This means a filter
|
|
|
|
* installed early gets to see more events than a filter installed later on.
|
|
|
|
*
|
|
|
|
* Deleting an instance of InputEventFilter automatically uninstalls it from
|
|
|
|
* InputRedirection.
|
|
|
|
**/
|
2016-02-15 14:40:25 +00:00
|
|
|
class KWIN_EXPORT InputEventFilter
|
2016-02-03 14:17:49 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
InputEventFilter();
|
|
|
|
virtual ~InputEventFilter();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event filter for pointer events which can be described by a QMouseEvent.
|
|
|
|
*
|
|
|
|
* Please note that the button translation in QMouseEvent cannot cover all
|
|
|
|
* possible buttons. Because of that also the @p nativeButton code is passed
|
|
|
|
* through the filter. For internal areas it's fine to use @p event, but for
|
|
|
|
* passing to client windows the @p nativeButton should be used.
|
|
|
|
*
|
|
|
|
* @param event The event information about the move or button press/release
|
|
|
|
* @param nativeButton The native key code of the button, for move events 0
|
|
|
|
* @return @c true to stop further event processing, @c false to pass to next filter
|
|
|
|
**/
|
|
|
|
virtual bool pointerEvent(QMouseEvent *event, quint32 nativeButton);
|
|
|
|
/**
|
|
|
|
* Event filter for pointer axis events.
|
|
|
|
*
|
|
|
|
* @param event The event information about the axis event
|
|
|
|
* @return @c true to stop further event processing, @c false to pass to next filter
|
|
|
|
**/
|
|
|
|
virtual bool wheelEvent(QWheelEvent *event);
|
|
|
|
/**
|
|
|
|
* Event filter for keyboard events.
|
|
|
|
*
|
|
|
|
* @param event The event information about the key event
|
|
|
|
* @return @c tru to stop further event processing, @c false to pass to next filter.
|
|
|
|
**/
|
|
|
|
virtual bool keyEvent(QKeyEvent *event);
|
|
|
|
virtual bool touchDown(quint32 id, const QPointF &pos, quint32 time);
|
|
|
|
virtual bool touchMotion(quint32 id, const QPointF &pos, quint32 time);
|
|
|
|
virtual bool touchUp(quint32 id, quint32 time);
|
2016-08-05 12:35:33 +00:00
|
|
|
|
|
|
|
virtual bool pinchGestureBegin(int fingerCount, quint32 time);
|
|
|
|
virtual bool pinchGestureUpdate(qreal scale, qreal angleDelta, const QSizeF &delta, quint32 time);
|
|
|
|
virtual bool pinchGestureEnd(quint32 time);
|
|
|
|
virtual bool pinchGestureCancelled(quint32 time);
|
|
|
|
|
|
|
|
virtual bool swipeGestureBegin(int fingerCount, quint32 time);
|
|
|
|
virtual bool swipeGestureUpdate(const QSizeF &delta, quint32 time);
|
|
|
|
virtual bool swipeGestureEnd(quint32 time);
|
|
|
|
virtual bool swipeGestureCancelled(quint32 time);
|
2013-06-26 08:15:20 +00:00
|
|
|
};
|
|
|
|
|
2016-05-12 14:33:03 +00:00
|
|
|
class InputDeviceHandler : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
virtual ~InputDeviceHandler();
|
|
|
|
|
|
|
|
QPointer<Toplevel> window() const {
|
|
|
|
return m_window;
|
|
|
|
}
|
|
|
|
QPointer<Decoration::DecoratedClientImpl> decoration() const {
|
|
|
|
return m_decoration;
|
|
|
|
}
|
2016-05-23 15:07:08 +00:00
|
|
|
QPointer<QWindow> internalWindow() const {
|
|
|
|
return m_internalWindow;
|
|
|
|
}
|
2016-05-12 14:33:03 +00:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void decorationChanged();
|
2016-05-23 15:07:08 +00:00
|
|
|
void internalWindowChanged();
|
2016-05-12 14:33:03 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
explicit InputDeviceHandler(InputRedirection *parent);
|
|
|
|
void updateDecoration(Toplevel *t, const QPointF &pos);
|
2016-05-23 15:07:08 +00:00
|
|
|
void updateInternalWindow(const QPointF &pos);
|
2016-05-12 14:33:03 +00:00
|
|
|
InputRedirection *m_input;
|
|
|
|
/**
|
|
|
|
* @brief The Toplevel which currently receives events
|
|
|
|
*/
|
|
|
|
QPointer<Toplevel> m_window;
|
|
|
|
/**
|
|
|
|
* @brief The Decoration which currently receives events.
|
|
|
|
**/
|
|
|
|
QPointer<Decoration::DecoratedClientImpl> m_decoration;
|
2016-05-23 15:07:08 +00:00
|
|
|
QPointer<QWindow> m_internalWindow;
|
2016-05-12 14:33:03 +00:00
|
|
|
};
|
|
|
|
|
2013-06-26 08:15:20 +00:00
|
|
|
inline
|
|
|
|
InputRedirection *input()
|
|
|
|
{
|
|
|
|
return InputRedirection::s_self;
|
|
|
|
}
|
|
|
|
|
2015-02-19 09:38:49 +00:00
|
|
|
template <typename T>
|
|
|
|
inline
|
|
|
|
void InputRedirection::registerShortcut(const QKeySequence &shortcut, QAction *action, T *receiver, void (T::*slot)()) {
|
|
|
|
registerShortcut(shortcut, action);
|
|
|
|
connect(action, &QAction::triggered, receiver, slot);
|
|
|
|
}
|
|
|
|
|
2013-06-26 08:15:20 +00:00
|
|
|
} // namespace KWin
|
|
|
|
|
2015-09-02 08:10:49 +00:00
|
|
|
Q_DECLARE_METATYPE(KWin::InputRedirection::KeyboardKeyState)
|
|
|
|
Q_DECLARE_METATYPE(KWin::InputRedirection::PointerButtonState)
|
|
|
|
Q_DECLARE_METATYPE(KWin::InputRedirection::PointerAxis)
|
|
|
|
|
2013-06-26 08:15:20 +00:00
|
|
|
#endif // KWIN_INPUT_H
|