Commit e6a2cbc3 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii Committed by Merge Service
Browse files

wayland: Simplify keystate protocol implementation

Access input machinery directly to monitor modifiers.

Tested-by: Merge Service <!2447>
Part-of: <!2447>
parent f64214e8
Pipeline #179872 passed with stage
in 14 minutes and 3 seconds
......@@ -7,12 +7,18 @@
#include "keystate_interface.h"
#include "display.h"
#include "keyboard_input.h"
#include "xkb.h"
#include <QDebug>
#include <QVector>
#include <qwayland-server-keystate.h>
using namespace KWin;
namespace KWaylandServer
{
static const quint32 s_version = 1;
class KeyStateInterfacePrivate : public QtWaylandServer::org_kde_kwin_keystate
......@@ -25,29 +31,26 @@ public:
void org_kde_kwin_keystate_fetchStates(Resource *resource) override
{
for (int i = 0; i < m_keyStates.count(); ++i) {
send_stateChanged(resource->handle, i, m_keyStates[i]);
}
}
const LEDs leds = input()->keyboard()->xkb()->leds();
QVector<KeyStateInterface::State> m_keyStates = QVector<KeyStateInterface::State>(3, KeyStateInterface::Unlocked);
send_stateChanged(resource->handle, key_capslock, leds & LED::CapsLock ? state_locked : state_unlocked);
send_stateChanged(resource->handle, key_numlock, leds & LED::NumLock ? state_locked : state_unlocked);
send_stateChanged(resource->handle, key_scrolllock, leds & LED::ScrollLock ? state_locked : state_unlocked);
}
};
KeyStateInterface::KeyStateInterface(Display *d, QObject *parent)
KeyStateInterface::KeyStateInterface(Display *display, QObject *parent)
: QObject(parent)
, d(new KeyStateInterfacePrivate(d))
, d(new KeyStateInterfacePrivate(display))
{
connect(input()->keyboard(), &KeyboardInputRedirection::ledsChanged, this, [this]() {
const auto resources = d->resourceMap();
for (const auto &resource : resources) {
d->org_kde_kwin_keystate_fetchStates(resource);
}
});
}
KeyStateInterface::~KeyStateInterface() = default;
void KeyStateInterface::setState(KeyStateInterface::Key key, KeyStateInterface::State state)
{
d->m_keyStates[int(key)] = state;
for (auto r : d->resourceMap()) {
d->send_stateChanged(r->handle, int(key), int(state));
}
}
}
......@@ -24,22 +24,7 @@ class KWIN_EXPORT KeyStateInterface : public QObject
public:
explicit KeyStateInterface(Display *display, QObject *parent = nullptr);
virtual ~KeyStateInterface();
enum class Key {
CapsLock = 0,
NumLock = 1,
ScrollLock = 2,
};
Q_ENUM(Key);
enum State {
Unlocked = 0,
Latched = 1,
Locked = 2,
};
Q_ENUM(State)
void setState(Key k, State s);
~KeyStateInterface() override;
private:
QScopedPointer<KeyStateInterfacePrivate> d;
......
......@@ -487,7 +487,6 @@ bool WaylandServer::init(InitializationFlags flags)
m_xdgOutputManagerV1 = new XdgOutputManagerV1Interface(m_display, m_display);
new SubCompositorInterface(m_display, m_display);
m_XdgForeign = new XdgForeignV2Interface(m_display, m_display);
m_keyState = new KeyStateInterface(m_display, m_display);
m_inputMethod = new InputMethodV1Interface(m_display, m_display);
auto activation = new KWaylandServer::XdgActivationV1Interface(m_display, this);
......@@ -524,9 +523,7 @@ void WaylandServer::windowShown(Window *window)
void WaylandServer::initWorkspace()
{
// TODO: Moe the keyboard leds somewhere else.
updateKeyState(input()->keyboard()->xkb()->leds());
connect(input()->keyboard(), &KeyboardInputRedirection::ledsChanged, this, &WaylandServer::updateKeyState);
new KeyStateInterface(m_display, m_display);
VirtualDesktopManager::self()->setVirtualDesktopManagement(m_virtualDesktopManagement);
......@@ -747,17 +744,6 @@ void WaylandServer::simulateUserActivity()
}
}
void WaylandServer::updateKeyState(KWin::LEDs leds)
{
if (!m_keyState) {
return;
}
m_keyState->setState(KeyStateInterface::Key::CapsLock, leds & KWin::LED::CapsLock ? KeyStateInterface::State::Locked : KeyStateInterface::State::Unlocked);
m_keyState->setState(KeyStateInterface::Key::NumLock, leds & KWin::LED::NumLock ? KeyStateInterface::State::Locked : KeyStateInterface::State::Unlocked);
m_keyState->setState(KeyStateInterface::Key::ScrollLock, leds & KWin::LED::ScrollLock ? KeyStateInterface::State::Locked : KeyStateInterface::State::Unlocked);
}
bool WaylandServer::isKeyboardShortcutsInhibited() const
{
auto surface = seat()->focusedKeyboardSurface();
......
......@@ -42,7 +42,6 @@ class PrimaryOutputV1Interface;
class OutputManagementV2Interface;
class XdgForeignV2Interface;
class XdgOutputManagerV1Interface;
class KeyStateInterface;
class LinuxDmaBufV1ClientBufferIntegration;
class LinuxDmaBufV1ClientBuffer;
class TabletManagerV2Interface;
......@@ -210,7 +209,6 @@ public:
SocketPairConnection createConnection();
void simulateUserActivity();
void updateKeyState(KWin::LEDs leds);
QSet<KWaylandServer::LinuxDmaBufV1ClientBuffer *> linuxDmabufBuffers() const
{
......@@ -291,7 +289,6 @@ private:
QPointer<KWaylandServer::ClientConnection> m_inputMethodServerConnection;
KWaylandServer::ClientConnection *m_screenLockerClientConnection = nullptr;
KWaylandServer::XdgForeignV2Interface *m_XdgForeign = nullptr;
KWaylandServer::KeyStateInterface *m_keyState = nullptr;
KWaylandServer::PrimaryOutputV1Interface *m_primary = nullptr;
XdgActivationV1Integration *m_xdgActivationIntegration = nullptr;
QList<Window *> m_windows;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment