diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,14 +31,15 @@ # Dependencies set(REQUIRED_QT_VERSION 5.11.0) -find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Concurrent Gui) +find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Concurrent Gui WaylandClient) find_package(Wayland 1.15 COMPONENTS Client Server) set_package_properties(Wayland PROPERTIES TYPE REQUIRED ) find_package(WaylandScanner) +find_package(QtWaylandScanner REQUIRED) find_package(WaylandProtocols 1.15) set_package_properties(WaylandProtocols PROPERTIES TYPE REQUIRED) diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -190,7 +190,7 @@ BASENAME xdg-decoration-unstable-v1 ) -ecm_add_wayland_client_protocol(CLIENT_LIB_SRCS +ecm_add_qtwayland_client_protocol(CLIENT_LIB_SRCS PROTOCOL ${KWayland_SOURCE_DIR}/src/client/protocols/keystate.xml BASENAME keystate ) @@ -245,6 +245,7 @@ PUBLIC Qt5::Gui PRIVATE Wayland::Client Qt5::Concurrent + Qt5::WaylandClient ) set_target_properties(KF5WaylandClient PROPERTIES VERSION ${KWAYLAND_VERSION_STRING} diff --git a/src/client/keystate.cpp b/src/client/keystate.cpp --- a/src/client/keystate.cpp +++ b/src/client/keystate.cpp @@ -20,56 +20,56 @@ #include "keystate.h" #include "wayland_pointer_p.h" #include +#include #include #include -#include +#include namespace KWayland { namespace Client { -class Q_DECL_HIDDEN Keystate::Private +class Keystate::Private : public QtWayland::org_kde_kwin_keystate, public QWaylandClientExtensionTemplate { public: - Private() {} - - WaylandPointer keystate; + Private(Keystate* q) : QWaylandClientExtensionTemplate(1), q(q) + { + } - static void org_kde_kwin_keystate_stateChanged(void *data, struct org_kde_kwin_keystate */*keystate*/, uint32_t k, uint32_t s) { - auto q = static_cast(data); - q->stateChanged(Key(k), State(s)); + void bind(struct ::wl_registry * registry, int id, int version) override { + QWaylandClientExtensionTemplate::bind(registry, id, version); + fetchStates(); } - static const org_kde_kwin_keystate_listener s_listener; -}; + void org_kde_kwin_keystate_stateChanged(uint32_t k, uint32_t s) override { + q->stateChanged(Key(key(k)), State(state(s))); + } -const org_kde_kwin_keystate_listener Keystate::Private::s_listener = { - org_kde_kwin_keystate_stateChanged + Keystate* const q; }; Keystate::Keystate(QObject *parent) : QObject(parent) - , d(new Private()) + , d(new Private(this)) { } Keystate::~Keystate() = default; void Keystate::fetchStates() { - org_kde_kwin_keystate_fetchStates(d->keystate); + d->fetchStates(); } void Keystate::setup(org_kde_kwin_keystate* keystate) { - d->keystate.setup(keystate); - org_kde_kwin_keystate_add_listener(keystate, &Keystate::Private::s_listener, this); + d->init(keystate); } void Keystate::destroy() { - d->keystate.destroy(); + d.reset(new Private(this)); } void Keystate::setEventQueue(KWayland::Client::EventQueue* /*queue*/) diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt --- a/src/server/CMakeLists.txt +++ b/src/server/CMakeLists.txt @@ -210,7 +210,7 @@ BASENAME eglstream-controller ) -ecm_add_wayland_server_protocol(SERVER_LIB_SRCS +ecm_add_qtwayland_server_protocol(SERVER_LIB_SRCS PROTOCOL ${KWayland_SOURCE_DIR}/src/client/protocols/keystate.xml BASENAME keystate ) diff --git a/src/server/keystate_interface.h b/src/server/keystate_interface.h --- a/src/server/keystate_interface.h +++ b/src/server/keystate_interface.h @@ -37,7 +37,7 @@ * * @since 5.58 **/ -class KWAYLANDSERVER_EXPORT KeyStateInterface : public Global +class KWAYLANDSERVER_EXPORT KeyStateInterface : public QObject { Q_OBJECT public: @@ -56,13 +56,15 @@ }; Q_ENUM(State) + void create(); void setState(Key k, State s); private: explicit KeyStateInterface(Display *display, QObject *parent = nullptr); friend class Display; class Private; + QScopedPointer d; }; } diff --git a/src/server/keystate_interface.cpp b/src/server/keystate_interface.cpp --- a/src/server/keystate_interface.cpp +++ b/src/server/keystate_interface.cpp @@ -25,70 +25,50 @@ #include #include #include -#include +#include namespace KWayland { namespace Server { -class KeyStateInterface::Private : public Global::Private +class KeyStateInterface::Private : public QtWaylandServer::org_kde_kwin_keystate { public: Private(Display *d) - : Global::Private(d, &org_kde_kwin_keystate_interface, s_version) + : QtWaylandServer::org_kde_kwin_keystate(*d, Private::s_version) {} - void bind(wl_client * client, uint32_t version, uint32_t id) override { - auto c = display->getConnection(client); - wl_resource *resource = c->createResource(&org_kde_kwin_keystate_interface, qMin(version, s_version), id); - if (!resource) { - wl_client_post_no_memory(client); - return; - } - wl_resource_set_implementation(resource, &s_interface, this, unbind); - m_resources << resource; - } - - static void unbind(wl_resource *resource) { - auto *d = reinterpret_cast(wl_resource_get_user_data(resource)); - d->m_resources.removeAll(resource); - } - - - static void fetchStatesCallback(struct wl_client */*client*/, struct wl_resource *resource) { - auto s = reinterpret_cast(wl_resource_get_user_data(resource)); - - for (int i=0; im_keyStates.count(); ++i) - org_kde_kwin_keystate_send_stateChanged(resource, i, s->m_keyStates[i]); + void org_kde_kwin_keystate_fetchStates(QtWaylandServer::org_kde_kwin_keystate::Resource * resource) override { + for (int i=0; ihandle, i, m_keyStates[i]); } static const quint32 s_version; - QVector m_resources; QVector m_keyStates = QVector(3, Unlocked); static const struct org_kde_kwin_keystate_interface s_interface; }; const quint32 KeyStateInterface::Private::s_version = 1; KeyStateInterface::KeyStateInterface(Display* d, QObject* parent) - : Global(new Private(d), parent) + : QObject(parent) + , d(new Private(d)) {} KeyStateInterface::~KeyStateInterface() = default; -const struct org_kde_kwin_keystate_interface KeyStateInterface::Private::s_interface = { - fetchStatesCallback -}; +void KeyStateInterface::create() +{ +} void KeyStateInterface::setState(KeyStateInterface::Key key, KeyStateInterface::State state) { auto dptr = static_cast(d.data()); dptr->m_keyStates[int(key)] = state; - for(auto r : qAsConst(dptr->m_resources)) { - org_kde_kwin_keystate_send_stateChanged(r, int(key), int(state)); - } + for (auto r : dptr->resourceMap()) + dptr->send_stateChanged(r->handle, int(key), int(state)); } }