8#include "kmodifierkeyinfoprovider_wayland.h"
10#include <QGuiApplication>
12#include <QWaylandClientExtensionTemplate>
13#include <wayland-client-core.h>
15#include "qwayland-keystate.h"
17class KeyState :
public QWaylandClientExtensionTemplate<KeyState>,
public QtWayland::org_kde_kwin_keystate
22 : QWaylandClientExtensionTemplate<KeyState>(5)
28 if (isInitialized() && qGuiApp) {
29 if (QtWayland::org_kde_kwin_keystate::version() >= ORG_KDE_KWIN_KEYSTATE_DESTROY_SINCE_VERSION) {
32 wl_proxy_destroy(
reinterpret_cast<struct wl_proxy *
>(
object()));
37 void org_kde_kwin_keystate_stateChanged(uint32_t key, uint32_t state)
override
39 Q_EMIT stateChanged(toKey(
static_cast<KeyState::key
>(key)), toState(
static_cast<KeyState::state
>(state)));
42 KModifierKeyInfoProvider::ModifierState toState(KeyState::state state)
45 case KeyState::state::state_unlocked:
46 return KModifierKeyInfoProvider::Nothing;
47 case KeyState::state::state_locked:
48 return KModifierKeyInfoProvider::Locked;
49 case KeyState::state::state_latched:
50 return KModifierKeyInfoProvider::Latched;
51 case KeyState::state::state_pressed:
52 return KModifierKeyInfoProvider::Pressed;
55 return KModifierKeyInfoProvider::Nothing;
58 Qt::Key toKey(KeyState::key key)
61 case KeyState::key::key_capslock:
63 case KeyState::key::key_numlock:
65 case KeyState::key::key_scrolllock:
67 case KeyState::key_alt:
69 case KeyState::key_shift:
71 case KeyState::key_control:
73 case KeyState::key_meta:
75 case KeyState::key_altgr:
82 Q_SIGNAL
void stateChanged(
Qt::Key key, KModifierKeyInfoProvider::ModifierState state);
85KModifierKeyInfoProviderWayland::KModifierKeyInfoProviderWayland()
87 m_keystate =
new KeyState;
90 if (m_keystate->isActive()) {
91 m_keystate->fetchStates();
95 connect(m_keystate, &KeyState::stateChanged,
this, &KModifierKeyInfoProviderWayland::stateUpdated);
100 stateUpdated(
Qt::Key_Alt, KModifierKeyInfoProvider::Nothing);
101 stateUpdated(
Qt::Key_Shift, KModifierKeyInfoProvider::Nothing);
103 stateUpdated(
Qt::Key_Meta, KModifierKeyInfoProvider::Nothing);
104 stateUpdated(
Qt::Key_AltGr, KModifierKeyInfoProvider::Nothing);
107KModifierKeyInfoProviderWayland::~KModifierKeyInfoProviderWayland()
112bool KModifierKeyInfoProviderWayland::setKeyLatched(
Qt::Key ,
bool )
117bool KModifierKeyInfoProviderWayland::setKeyLocked(
Qt::Key ,
bool )
122#include "kmodifierkeyinfoprovider_wayland.moc"
123#include "moc_kmodifierkeyinfoprovider_wayland.cpp"
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)