File indexing completed on 2024-11-10 04:57:28
0001 /* 0002 SPDX-FileCopyrightText: 2019 Aleix Pol Gonzalez <aleixpol@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include "keystate.h" 0008 #include "display.h" 0009 0010 #include "keyboard_input.h" 0011 #include "xkb.h" 0012 0013 #include <QDebug> 0014 #include <QList> 0015 #include <qwayland-server-keystate.h> 0016 0017 namespace KWin 0018 { 0019 0020 static const quint32 s_version = 1; 0021 0022 class KeyStateInterfacePrivate : public QtWaylandServer::org_kde_kwin_keystate 0023 { 0024 public: 0025 KeyStateInterfacePrivate(Display *d) 0026 : QtWaylandServer::org_kde_kwin_keystate(*d, s_version) 0027 { 0028 } 0029 0030 void org_kde_kwin_keystate_fetchStates(Resource *resource) override 0031 { 0032 const LEDs leds = input()->keyboard()->xkb()->leds(); 0033 0034 send_stateChanged(resource->handle, key_capslock, leds & LED::CapsLock ? state_locked : state_unlocked); 0035 send_stateChanged(resource->handle, key_numlock, leds & LED::NumLock ? state_locked : state_unlocked); 0036 send_stateChanged(resource->handle, key_scrolllock, leds & LED::ScrollLock ? state_locked : state_unlocked); 0037 } 0038 }; 0039 0040 KeyStateInterface::KeyStateInterface(Display *display, QObject *parent) 0041 : QObject(parent) 0042 , d(new KeyStateInterfacePrivate(display)) 0043 { 0044 connect(input()->keyboard(), &KeyboardInputRedirection::ledsChanged, this, [this]() { 0045 const auto resources = d->resourceMap(); 0046 for (const auto &resource : resources) { 0047 d->org_kde_kwin_keystate_fetchStates(resource); 0048 } 0049 }); 0050 } 0051 0052 KeyStateInterface::~KeyStateInterface() = default; 0053 0054 } 0055 0056 #include "moc_keystate.cpp"