backends/wayland: Stop forwarding keymap and modifiers

These concepts are hard to map to InputDevice abstractions, so remove
them and let kwin use its own internal keymap instead (rather than
get it overridden by the host compositor's keymap) and track modifiers
based on the events it receives.

If the goal is to have these at any cost, I think the way out of it
would be to provide wayland backend specific signals. I would like to
avoid doing that though because it breaks encapsulation and we would
need some casts in kwin to wire in these events.
This commit is contained in:
Vlad Zahorodnii 2022-11-17 13:46:48 +02:00
parent c1ecce9ec3
commit b867f76d41
5 changed files with 2 additions and 69 deletions

View file

@ -21,7 +21,6 @@
#include "cursor.h"
#include "dpmsinputeventfilter.h"
#include "input.h"
#include "keyboard_input.h"
#include "pointer_input.h"
#include <KWayland/Client/buffer.h>
@ -203,12 +202,6 @@ WaylandInputDevice::WaylandInputDevice(KWayland::Client::Keyboard *keyboard, Way
}
Q_EMIT keyChanged(key, state, time, this);
});
connect(keyboard, &Keyboard::modifiersChanged, this, [](quint32 depressed, quint32 latched, quint32 locked, quint32 group) {
input()->keyboard()->processModifiers(depressed, latched, locked, group);
});
connect(keyboard, &Keyboard::keymapChanged, this, [](int fd, quint32 size) {
input()->keyboard()->processKeymapChange(fd, size);
});
}
WaylandInputDevice::WaylandInputDevice(KWayland::Client::Pointer *pointer, WaylandSeat *seat)

View file

@ -100,11 +100,7 @@ public:
if (event->isAutoRepeat()) {
return;
}
updateModifiers(event->modifiers());
}
void updateModifiers(Qt::KeyboardModifiers mods)
{
const Qt::KeyboardModifiers mods = event->modifiers();
if (mods == m_modifiers) {
return;
}
@ -282,26 +278,4 @@ void KeyboardInputRedirection::processKey(uint32_t key, InputRedirection::Keyboa
}
}
void KeyboardInputRedirection::processModifiers(uint32_t modsDepressed, uint32_t modsLatched, uint32_t modsLocked, uint32_t group)
{
if (!m_inited) {
return;
}
const quint32 previousLayout = m_xkb->currentLayout();
// TODO: send to proper Client and also send when active Client changes
m_xkb->updateModifiers(modsDepressed, modsLatched, modsLocked, group);
m_modifiersChangedSpy->updateModifiers(modifiers());
m_keyboardLayout->checkLayoutChange(previousLayout);
}
void KeyboardInputRedirection::processKeymapChange(int fd, uint32_t size)
{
if (!m_inited) {
return;
}
// TODO: should we pass the keymap to our Clients? Or only to the currently active one and update
m_xkb->installKeymap(fd, size);
m_keyboardLayout->resetLayout();
}
}

View file

@ -54,14 +54,6 @@ public:
* @internal
*/
void processKey(uint32_t key, InputRedirection::KeyboardKeyState state, uint32_t time, InputDevice *device = nullptr);
/**
* @internal
*/
void processModifiers(uint32_t modsDepressed, uint32_t modsLatched, uint32_t modsLocked, uint32_t group);
/**
* @internal
*/
void processKeymapChange(int fd, uint32_t size);
Xkb *xkb() const;
Qt::KeyboardModifiers modifiers() const;

View file

@ -256,25 +256,6 @@ xkb_keymap *Xkb::loadKeymapFromLocale1()
return xkb_keymap_new_from_names(m_context, &ruleNames, XKB_KEYMAP_COMPILE_NO_FLAGS);
}
void Xkb::installKeymap(int fd, uint32_t size)
{
if (!m_context) {
return;
}
char *map = reinterpret_cast<char *>(mmap(nullptr, size, PROT_READ, MAP_SHARED, fd, 0));
if (map == MAP_FAILED) {
return;
}
xkb_keymap *keymap = xkb_keymap_new_from_string(m_context, map, XKB_KEYMAP_FORMAT_TEXT_V1, XKB_MAP_COMPILE_PLACEHOLDER);
munmap(map, size);
if (!keymap) {
qCDebug(KWIN_XKB) << "Could not map keymap from file";
return;
}
m_ownership = Ownership::Client;
updateKeymap(keymap);
}
void Xkb::updateKeymap(xkb_keymap *keymap)
{
Q_ASSERT(keymap);
@ -318,7 +299,7 @@ void Xkb::updateKeymap(xkb_keymap *keymap)
m_modifierState.locked = xkb_state_serialize_mods(m_state, xkb_state_component(XKB_STATE_MODS_LOCKED));
auto setLock = [this](xkb_mod_index_t modifier, bool value) {
if (m_ownership == Ownership::Server && modifier != XKB_MOD_INVALID) {
if (modifier != XKB_MOD_INVALID) {
std::bitset<sizeof(xkb_mod_mask_t) * 8> mask{m_modifierState.locked};
if (mask.size() > modifier) {
mask[modifier] = value;

View file

@ -48,7 +48,6 @@ public:
void setConfig(const KSharedConfigPtr &config);
void setNumLockConfig(const KSharedConfigPtr &config);
void installKeymap(int fd, uint32_t size);
void updateModifiers(uint32_t modsDepressed, uint32_t modsLatched, uint32_t modsLocked, uint32_t group);
void updateKey(uint32_t key, InputRedirection::KeyboardKeyState state);
xkb_keysym_t toKeysym(uint32_t key);
@ -160,12 +159,6 @@ private:
xkb_mod_index_t locked = 0;
} m_modifierState;
enum class Ownership {
Server,
Client
};
Ownership m_ownership = Ownership::Server;
QPointer<KWaylandServer::SeatInterface> m_seat;
const bool m_followLocale1;
};