KWin
Loading...
Searching...
No Matches
input.h
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2013 Martin Gräßlin <mgraesslin@kde.org>
6 SPDX-FileCopyrightText: 2018 Roman Gilg <subdiff@gmail.com>
7 SPDX-FileCopyrightText: 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
8
9 SPDX-License-Identifier: GPL-2.0-or-later
10*/
11#pragma once
12#include <config-kwin.h>
13
14#include "effect/globals.h"
15#include <QObject>
16#include <QPoint>
17#include <QPointer>
18
19#include <KConfigWatcher>
20#include <KSharedConfig>
21#include <QSet>
22
23#include "config-kwin.h"
24#include <functional>
25
26class KGlobalAccelInterface;
27class QAction;
28class QKeySequence;
29class QMouseEvent;
30class QKeyEvent;
31class QWheelEvent;
32
33namespace KWin
34{
35class IdleDetector;
36class Window;
37class GlobalShortcutsManager;
38class InputEventFilter;
39class InputEventSpy;
40class KeyboardInputRedirection;
41class PointerInputRedirection;
42class TabletInputRedirection;
43class TouchInputRedirection;
44class WindowSelectorFilter;
45class SwitchEvent;
46class TabletEvent;
47class TabletToolId;
48class TabletPadId;
49class MouseEvent;
50class WheelEvent;
51class KeyEvent;
52
53namespace Decoration
54{
55class DecoratedClientImpl;
56}
57
58class InputBackend;
59class InputDevice;
60
69class KWIN_EXPORT InputRedirection : public QObject
70{
71 Q_OBJECT
72public:
75 PointerButtonPressed
76 };
79 PointerAxisHorizontal
80 };
117
118 ~InputRedirection() override;
119 void init();
120
124 QPointF globalPointer() const;
125 Qt::MouseButtons qtButtonStates() const;
126 Qt::KeyboardModifiers keyboardModifiers() const;
127 Qt::KeyboardModifiers modifiersRelevantForGlobalShortcuts() const;
128
129 void registerPointerShortcut(Qt::KeyboardModifiers modifiers, Qt::MouseButton pointerButtons, QAction *action);
130 void registerAxisShortcut(Qt::KeyboardModifiers modifiers, PointerAxisDirection axis, QAction *action);
131 void registerTouchpadSwipeShortcut(SwipeDirection direction, uint32_t fingerCount, QAction *onUp, std::function<void(qreal)> progressCallback = {});
132 void registerTouchpadPinchShortcut(PinchDirection direction, uint32_t fingerCount, QAction *onUp, std::function<void(qreal)> progressCallback = {});
133 void registerTouchscreenSwipeShortcut(SwipeDirection direction, uint32_t fingerCount, QAction *action, std::function<void(qreal)> progressCallback = {});
134 void forceRegisterTouchscreenSwipeShortcut(SwipeDirection direction, uint32_t fingerCount, QAction *action, std::function<void(qreal)> progressCallback = {});
135 void registerGlobalAccel(KGlobalAccelInterface *interface);
136
137 bool supportsPointerWarping() const;
138 void warpPointer(const QPointF &pos);
139
147 void prependInputEventFilter(InputEventFilter *filter);
148 void uninstallInputEventFilter(InputEventFilter *filter);
149
153 void installInputEventSpy(InputEventSpy *spy);
154
158 void uninstallInputEventSpy(InputEventSpy *spy);
159
160 void simulateUserActivity();
161
162 void addIdleDetector(IdleDetector *detector);
163 void removeIdleDetector(IdleDetector *detector);
164
165 QList<Window *> idleInhibitors() const;
166 void addIdleInhibitor(Window *inhibitor);
167 void removeIdleInhibitor(Window *inhibitor);
168
169 Window *findToplevel(const QPointF &pos);
170#if KWIN_BUILD_GLOBALSHORTCUTS
171 GlobalShortcutsManager *shortcuts() const
172 {
173 return m_shortcuts;
174 }
175#endif
176
191 template<class UnaryPredicate>
192 void processFilters(UnaryPredicate function)
193 {
194 std::any_of(m_filters.constBegin(), m_filters.constEnd(), function);
195 }
196
210 template<class UnaryFunction>
211 void processSpies(UnaryFunction function)
212 {
213 std::for_each(m_spies.constBegin(), m_spies.constEnd(), function);
214 }
215
217 {
218 return m_keyboard;
219 }
221 {
222 return m_pointer;
223 }
225 {
226 return m_tablet;
227 }
229 {
230 return m_touch;
231 }
232
236 void setLastInputHandler(QObject *device);
237 QObject *lastInputHandler() const;
238
239 QList<InputDevice *> devices() const;
240
242 bool hasPointer() const;
243 bool hasTouch() const;
244 bool hasTabletModeSwitch();
245
246 void startInteractiveWindowSelection(std::function<void(KWin::Window *)> callback, const QByteArray &cursorName);
247 void startInteractivePositionSelection(std::function<void(const QPoint &)> callback);
248 bool isSelectingWindow() const;
249
250 void toggleTouchpads();
251 void enableTouchpads();
252 void disableTouchpads();
253
254Q_SIGNALS:
262 void globalPointerChanged(const QPointF &pos);
286 void keyboardModifiersChanged(Qt::KeyboardModifiers newMods, Qt::KeyboardModifiers oldMods);
294
295 void hasKeyboardChanged(bool set);
297 void hasPointerChanged(bool set);
298 void hasTouchChanged(bool set);
300
301public Q_SLOTS:
302 void addInputDevice(InputDevice *device);
303 void removeInputDevice(InputDevice *device);
304
305private Q_SLOTS:
306 void handleInputConfigChanged(const KConfigGroup &group);
307 void updateScreens();
308
309private:
310 void setupInputBackends();
311 void setupTouchpadShortcuts();
312 void setupWorkspace();
313 void setupInputFilters();
314 void installInputEventFilter(InputEventFilter *filter);
315 void updateLeds(LEDs leds);
316 void updateAvailableInputDevices();
317 void addInputBackend(std::unique_ptr<InputBackend> &&inputBackend);
318 KeyboardInputRedirection *m_keyboard;
319 PointerInputRedirection *m_pointer;
320 TabletInputRedirection *m_tablet;
321 TouchInputRedirection *m_touch;
322 QObject *m_lastInputDevice = nullptr;
323
324#if KWIN_BUILD_GLOBALSHORTCUTS
325 GlobalShortcutsManager *m_shortcuts;
326#endif
327
328 std::vector<std::unique_ptr<InputBackend>> m_inputBackends;
329 QList<InputDevice *> m_inputDevices;
330
331 QList<IdleDetector *> m_idleDetectors;
332 QList<Window *> m_idleInhibitors;
333 std::unique_ptr<WindowSelectorFilter> m_windowSelector;
334
335 QList<InputEventFilter *> m_filters;
336 QList<InputEventSpy *> m_spies;
337 KConfigWatcher::Ptr m_inputConfigWatcher;
338
339 std::unique_ptr<InputEventFilter> m_virtualTerminalFilter;
340 std::unique_ptr<InputEventFilter> m_dragAndDropFilter;
341 std::unique_ptr<InputEventFilter> m_lockscreenFilter;
342 std::unique_ptr<InputEventFilter> m_screenEdgeFilter;
343 std::unique_ptr<InputEventFilter> m_tabboxFilter;
344 std::unique_ptr<InputEventFilter> m_globalShortcutFilter;
345 std::unique_ptr<InputEventFilter> m_effectsFilter;
346 std::unique_ptr<InputEventFilter> m_interactiveMoveResizeFilter;
347 std::unique_ptr<InputEventFilter> m_popupFilter;
348 std::unique_ptr<InputEventFilter> m_decorationFilter;
349 std::unique_ptr<InputEventFilter> m_windowActionFilter;
350 std::unique_ptr<InputEventFilter> m_internalWindowFilter;
351 std::unique_ptr<InputEventFilter> m_inputKeyboardFilter;
352 std::unique_ptr<InputEventFilter> m_forwardFilter;
353 std::unique_ptr<InputEventFilter> m_tabletFilter;
354
355 std::unique_ptr<InputEventSpy> m_hideCursorSpy;
356 std::unique_ptr<InputEventSpy> m_userActivitySpy;
357 std::unique_ptr<InputEventSpy> m_windowInteractedSpy;
358
359 LEDs m_leds;
360 bool m_hasKeyboard = false;
361 bool m_hasPointer = false;
362 bool m_hasTouch = false;
363 bool m_hasTabletModeSwitch = false;
364 bool m_touchpadsEnabled = true;
365
367 friend InputRedirection *input();
370 friend class ForwardInputFilter;
371};
372
392class KWIN_EXPORT InputEventFilter
393{
394public:
396 virtual ~InputEventFilter();
397
410 virtual bool pointerEvent(MouseEvent *event, quint32 nativeButton);
411 virtual bool pointerFrame();
418 virtual bool wheelEvent(WheelEvent *event);
425 virtual bool keyEvent(KeyEvent *event);
426 virtual bool touchDown(qint32 id, const QPointF &pos, std::chrono::microseconds time);
427 virtual bool touchMotion(qint32 id, const QPointF &pos, std::chrono::microseconds time);
428 virtual bool touchUp(qint32 id, std::chrono::microseconds time);
429 virtual bool touchCancel();
430 virtual bool touchFrame();
431
432 virtual bool pinchGestureBegin(int fingerCount, std::chrono::microseconds time);
433 virtual bool pinchGestureUpdate(qreal scale, qreal angleDelta, const QPointF &delta, std::chrono::microseconds time);
434 virtual bool pinchGestureEnd(std::chrono::microseconds time);
435 virtual bool pinchGestureCancelled(std::chrono::microseconds time);
436
437 virtual bool swipeGestureBegin(int fingerCount, std::chrono::microseconds time);
438 virtual bool swipeGestureUpdate(const QPointF &delta, std::chrono::microseconds time);
439 virtual bool swipeGestureEnd(std::chrono::microseconds time);
440 virtual bool swipeGestureCancelled(std::chrono::microseconds time);
441
442 virtual bool holdGestureBegin(int fingerCount, std::chrono::microseconds time);
443 virtual bool holdGestureEnd(std::chrono::microseconds time);
444 virtual bool holdGestureCancelled(std::chrono::microseconds time);
445
446 virtual bool switchEvent(SwitchEvent *event);
447
448 virtual bool tabletToolEvent(TabletEvent *event);
449 virtual bool tabletToolButtonEvent(uint button, bool pressed, const TabletToolId &tabletToolId, std::chrono::microseconds time);
450 virtual bool tabletPadButtonEvent(uint button, bool pressed, const TabletPadId &tabletPadId, std::chrono::microseconds time);
451 virtual bool tabletPadStripEvent(int number, int position, bool isFinger, const TabletPadId &tabletPadId, std::chrono::microseconds time);
452 virtual bool tabletPadRingEvent(int number, int position, bool isFinger, const TabletPadId &tabletPadId, std::chrono::microseconds time);
453
454protected:
455 void passToWaylandServer(QKeyEvent *event);
456 bool passToInputMethod(QKeyEvent *event);
457};
458
459class KWIN_EXPORT InputDeviceHandler : public QObject
460{
461 Q_OBJECT
462public:
464 virtual void init();
465
466 void update();
467
475 Window *hover() const;
483 Window *focus() const;
484
490
491 virtual QPointF position() const = 0;
492
493 void setFocus(Window *window);
494 void setDecoration(Decoration::DecoratedClientImpl *decoration);
495
496Q_SIGNALS:
498
499protected:
500 explicit InputDeviceHandler(InputRedirection *parent);
501
503
504 virtual void focusUpdate(Window *old, Window *now) = 0;
505
511 virtual bool positionValid() const
512 {
513 return true;
514 }
515 virtual bool focusUpdatesBlocked()
516 {
517 return false;
518 }
519
520 inline bool inited() const
521 {
522 return m_inited;
523 }
524 inline void setInited(bool set)
525 {
526 m_inited = set;
527 }
528
529private:
530 bool setHover(Window *window);
531 void updateFocus();
532 void updateDecoration();
533
534 struct
535 {
536 QPointer<Window> window;
537 QMetaObject::Connection surfaceCreatedConnection;
538 } m_hover;
539
540 struct
541 {
542 QPointer<Window> window;
543 QPointer<Decoration::DecoratedClientImpl> decoration;
544 } m_focus;
545
546 bool m_inited = false;
547};
548
550{
551 return InputRedirection::s_self;
552}
553
554inline QList<InputDevice *> InputRedirection::devices() const
555{
556 return m_inputDevices;
557}
558
559} // namespace KWin
560
Manager for the global shortcut system inside KWin.
QPointer< Window > window
Definition input.h:536
bool inited() const
Definition input.h:520
virtual bool positionValid() const
Definition input.h:511
Decoration::DecoratedClientImpl * decoration() const
The Decoration currently receiving events.
virtual void cleanupDecoration(Decoration::DecoratedClientImpl *old, Decoration::DecoratedClientImpl *now)=0
virtual void focusUpdate(Window *old, Window *now)=0
virtual bool focusUpdatesBlocked()
Definition input.h:515
virtual QPointF position() const =0
QMetaObject::Connection surfaceCreatedConnection
Definition input.h:537
void setInited(bool set)
Definition input.h:524
~InputDeviceHandler() override
QPointer< Decoration::DecoratedClientImpl > decoration
Definition input.h:543
This class is responsible for redirecting incoming input to the surface which currently has input or ...
Definition input.h:70
void deviceAdded(InputDevice *device)
QList< InputDevice * > devices() const
Definition input.h:554
KeyboardInputRedirection * keyboard() const
Definition input.h:216
TabletInputRedirection * tablet() const
Definition input.h:224
void hasTabletModeSwitchChanged(bool set)
void deviceRemoved(InputDevice *device)
void keyboardModifiersChanged(Qt::KeyboardModifiers newMods, Qt::KeyboardModifiers oldMods)
Emitted when the modifiers changes.
void globalPointerChanged(const QPointF &pos)
Emitted when the global pointer position changed.
TouchInputRedirection * touch() const
Definition input.h:228
void processSpies(UnaryFunction function)
Definition input.h:211
void hasPointerChanged(bool set)
void processFilters(UnaryPredicate function)
Definition input.h:192
PointerInputRedirection * pointer() const
Definition input.h:220
void hasTouchChanged(bool set)
void hasKeyboardChanged(bool set)
void pointerButtonStateChanged(uint32_t button, InputRedirection::PointerButtonState state)
Emitted when the state of a pointer button changed.
void pointerAxisChanged(InputRedirection::PointerAxis axis, qreal delta)
Emitted when a pointer axis changed.
void hasAlphaNumericKeyboardChanged(bool set)
void keyStateChanged(quint32 keyCode, InputRedirection::KeyboardKeyState state)
Emitted when the state of a key changed.
#define KWIN_SINGLETON(ClassName)
Definition globals.h:323
Q_DECLARE_METATYPE(KWin::SwitchEvent::State)
PointerAxisDirection
The direction in which a pointer axis is moved.
Definition globals.h:104
SwipeDirection
Directions for swipe gestures.
Definition globals.h:115
InputRedirection * input()
Definition input.h:549