Changeset View
Changeset View
Standalone View
Standalone View
src/client/keystate.cpp
Show All 14 Lines | |||||
15 | Lesser General Public License for more details. | 15 | Lesser General Public License for more details. | ||
16 | 16 | | |||
17 | You should have received a copy of the GNU Lesser General Public | 17 | You should have received a copy of the GNU Lesser General Public | ||
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 19 | *********************************************************************/ | ||
20 | #include "keystate.h" | 20 | #include "keystate.h" | ||
21 | #include "wayland_pointer_p.h" | 21 | #include "wayland_pointer_p.h" | ||
22 | #include <QPointer> | 22 | #include <QPointer> | ||
23 | #include <QWaylandClientExtensionTemplate> | ||||
23 | #include <QDebug> | 24 | #include <QDebug> | ||
24 | #include <wayland-client-protocol.h> | 25 | #include <wayland-client-protocol.h> | ||
25 | #include <wayland-keystate-client-protocol.h> | 26 | #include <qwayland-keystate.h> | ||
26 | 27 | | |||
27 | namespace KWayland | 28 | namespace KWayland | ||
28 | { | 29 | { | ||
29 | namespace Client | 30 | namespace Client | ||
30 | { | 31 | { | ||
31 | 32 | | |||
32 | class Q_DECL_HIDDEN Keystate::Private | 33 | class Keystate::Private : public QtWayland::org_kde_kwin_keystate, public QWaylandClientExtensionTemplate<Keystate::Private> | ||
33 | { | 34 | { | ||
34 | public: | 35 | public: | ||
35 | Private() {} | 36 | Private(Keystate* q) : QWaylandClientExtensionTemplate<Keystate::Private>(1), q(q) | ||
36 | 37 | { | |||
37 | WaylandPointer<org_kde_kwin_keystate, org_kde_kwin_keystate_destroy> keystate; | 38 | } | ||
38 | 39 | | |||
39 | static void org_kde_kwin_keystate_stateChanged(void *data, struct org_kde_kwin_keystate */*keystate*/, uint32_t k, uint32_t s) { | 40 | void bind(struct ::wl_registry * registry, int id, int version) override { | ||
40 | auto q = static_cast<Keystate*>(data); | 41 | QWaylandClientExtensionTemplate<Keystate::Private>::bind(registry, id, version); | ||
41 | q->stateChanged(Key(k), State(s)); | 42 | fetchStates(); | ||
42 | } | 43 | } | ||
43 | 44 | | |||
44 | static const org_kde_kwin_keystate_listener s_listener; | 45 | void org_kde_kwin_keystate_stateChanged(uint32_t k, uint32_t s) override { | ||
45 | }; | 46 | q->stateChanged(Key(key(k)), State(state(s))); | ||
47 | } | ||||
46 | 48 | | |||
47 | const org_kde_kwin_keystate_listener Keystate::Private::s_listener = { | 49 | Keystate* const q; | ||
48 | org_kde_kwin_keystate_stateChanged | | |||
49 | }; | 50 | }; | ||
50 | 51 | | |||
51 | Keystate::Keystate(QObject *parent) | 52 | Keystate::Keystate(QObject *parent) | ||
52 | : QObject(parent) | 53 | : QObject(parent) | ||
53 | , d(new Private()) | 54 | , d(new Private(this)) | ||
54 | { | 55 | { | ||
55 | } | 56 | } | ||
56 | 57 | | |||
57 | Keystate::~Keystate() = default; | 58 | Keystate::~Keystate() = default; | ||
58 | 59 | | |||
59 | void Keystate::fetchStates() | 60 | void Keystate::fetchStates() | ||
60 | { | 61 | { | ||
61 | org_kde_kwin_keystate_fetchStates(d->keystate); | 62 | d->fetchStates(); | ||
62 | } | 63 | } | ||
63 | 64 | | |||
64 | void Keystate::setup(org_kde_kwin_keystate* keystate) | 65 | void Keystate::setup(org_kde_kwin_keystate* keystate) | ||
65 | { | 66 | { | ||
66 | d->keystate.setup(keystate); | 67 | d->init(keystate); | ||
67 | org_kde_kwin_keystate_add_listener(keystate, &Keystate::Private::s_listener, this); | | |||
68 | } | 68 | } | ||
69 | 69 | | |||
70 | void Keystate::destroy() | 70 | void Keystate::destroy() | ||
71 | { | 71 | { | ||
72 | d->keystate.destroy(); | 72 | d.reset(new Private(this)); | ||
73 | } | 73 | } | ||
74 | 74 | | |||
75 | void Keystate::setEventQueue(KWayland::Client::EventQueue* /*queue*/) | 75 | void Keystate::setEventQueue(KWayland::Client::EventQueue* /*queue*/) | ||
76 | { | 76 | { | ||
77 | } | 77 | } | ||
78 | 78 | | |||
79 | 79 | | |||
80 | } | 80 | } | ||
81 | } | 81 | } |