KWin
Loading...
Searching...
No Matches
buttonrebindsfilter.h
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2022 David Redondo <kde@david-redono.de>
3 SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
4
5 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
6*/
7
8#pragma once
9
10#include "plugin.h"
11#include <array>
12#include <optional>
13#include <variant>
14
15#include "core/inputdevice.h"
16#include "input.h"
17#include "input_event.h"
18
19#include <QKeySequence>
20
22{
23 QString sysName() const override;
24 QString name() const override;
25
26 bool isEnabled() const override;
27 void setEnabled(bool enabled) override;
28
29 void setLeds(KWin::LEDs leds) override;
30 KWin::LEDs leds() const override;
31
32 bool isKeyboard() const override;
33 bool isPointer() const override;
34 bool isTouchpad() const override;
35 bool isTouch() const override;
36 bool isTabletTool() const override;
37 bool isTabletPad() const override;
38 bool isTabletModeSwitch() const override;
39 bool isLidSwitch() const override;
40};
41
42struct Trigger
43{
44 QString device;
45 uint button;
46 bool operator==(const Trigger &o) const
47 {
48 return button == o.button && device == o.device;
49 }
50};
51
53{
54 Q_OBJECT
55public:
62 Q_ENUM(TriggerType)
64 {
65 quint32 button;
66 };
68 {
69 quint32 button;
70 };
71
72 explicit ButtonRebindsFilter();
73 bool pointerEvent(KWin::MouseEvent *event, quint32 nativeButton) override;
74 bool tabletPadButtonEvent(uint button, bool pressed, const KWin::TabletPadId &tabletPadId, std::chrono::microseconds time) override;
75 bool tabletToolButtonEvent(uint button, bool pressed, const KWin::TabletToolId &tabletToolId, std::chrono::microseconds time) override;
76
77private:
78 void loadConfig(const KConfigGroup &group);
79 void insert(TriggerType type, const Trigger &trigger, const QStringList &action);
80 bool send(TriggerType type, const Trigger &trigger, bool pressed, std::chrono::microseconds timestamp);
81 bool sendKeySequence(const QKeySequence &sequence, bool pressed, std::chrono::microseconds time);
82 bool sendMouseButton(quint32 button, bool pressed, std::chrono::microseconds time);
83 bool sendTabletToolButton(quint32 button, bool pressed, std::chrono::microseconds time);
84
85 InputDevice m_inputDevice;
86 std::array<QHash<Trigger, std::variant<QKeySequence, MouseButton, TabletToolButton>>, LastType> m_actions;
87 KConfigWatcher::Ptr m_configWatcher;
88 std::optional<KWin::TabletToolId> m_tabletTool;
89};
bool tabletToolButtonEvent(uint button, bool pressed, const KWin::TabletToolId &tabletToolId, std::chrono::microseconds time) override
bool pointerEvent(KWin::MouseEvent *event, quint32 nativeButton) override
bool tabletPadButtonEvent(uint button, bool pressed, const KWin::TabletPadId &tabletPadId, std::chrono::microseconds time) override
bool operator==(const Trigger &o) const