From 01ac0abfd7c4cc7491fd5fdf5e9b71bb9e3a7f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Sat, 13 Jun 2015 17:54:08 +0200 Subject: [PATCH] [wayland] Change keyboard focus window when active window changes We used to change it only on keypresses. This resulted in the strange situation that e.g. the input method virtual keyboard doesn't show up until one presses a real key, because e.g. maliit only activates the keyboard if there is an active focus object in the Qt application. --- input.cpp | 53 +++++++++++++++++++++++++++++++++++++---------------- input.h | 2 ++ 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/input.cpp b/input.cpp index 73bb272bde..f4aefbb3c2 100644 --- a/input.cpp +++ b/input.cpp @@ -256,6 +256,7 @@ InputRedirection::InputRedirection(QObject *parent) } } #endif + connect(kwinApp(), &Application::workspaceCreated, this, &InputRedirection::setupWorkspace); } InputRedirection::~InputRedirection() @@ -263,6 +264,15 @@ InputRedirection::~InputRedirection() s_self = NULL; } +void InputRedirection::setupWorkspace() +{ +#if HAVE_WAYLAND + if (waylandServer()) { + connect(workspace(), &Workspace::clientActivated, this, &InputRedirection::updateKeyboardWindow); + } +#endif +} + #if HAVE_WAYLAND static KWayland::Server::SeatInterface *findSeat() { @@ -732,6 +742,32 @@ void InputRedirection::processPointerAxis(InputRedirection::PointerAxis axis, qr #endif } +void InputRedirection::updateKeyboardWindow() +{ +#if HAVE_WAYLAND + if (!workspace()) { + return; + } + if (auto seat = findSeat()) { + // TODO: this needs better integration + // check unmanaged + Toplevel *t = nullptr; + if (!workspace()->unmanagedList().isEmpty()) { + // TODO: better check whether this unmanaged should get the key event + t = workspace()->unmanagedList().first(); + } + if (!t) { + t = workspace()->activeClient(); + } + if (t && t->surface()) { + if (t->surface() != seat->focusedKeyboardSurface()) { + seat->setFocusedKeyboardSurface(t->surface()); + } + } + } +#endif +} + void InputRedirection::processKeyboardKey(uint32_t key, InputRedirection::KeyboardKeyState state, uint32_t time) { #if HAVE_XKB @@ -786,22 +822,7 @@ void InputRedirection::processKeyboardKey(uint32_t key, InputRedirection::Keyboa #if HAVE_WAYLAND if (auto seat = findSeat()) { seat->setTimestamp(time); - // TODO: this needs better integration - // check unmanaged - Toplevel *t = nullptr; - if (!workspace()->unmanagedList().isEmpty()) { - // TODO: better check whether this unmanaged should get the key event - t = workspace()->unmanagedList().first(); - } - if (!t) { - t = workspace()->activeClient(); - } - if (t && t->surface()) { - if (t->surface() != seat->focusedKeyboardSurface()) { - seat->setFocusedKeyboardSurface(t->surface()); - } - state == InputRedirection::KeyboardKeyPressed ? seat->keyPressed(key) : seat->keyReleased(key); - } + state == InputRedirection::KeyboardKeyPressed ? seat->keyPressed(key) : seat->keyReleased(key); } #endif } diff --git a/input.h b/input.h index 5a58e6e9c6..c354700092 100644 --- a/input.h +++ b/input.h @@ -197,6 +197,8 @@ private: void pointerInternalWindowVisibilityChanged(bool visible); void installCursorFromDecoration(); bool areButtonsPressed() const; + void updateKeyboardWindow(); + void setupWorkspace(); QPointF m_globalPointer; QHash m_pointerButtons; #if HAVE_XKB