From 1a341d8333c95708759706aa78fbc7828d837bf2 Mon Sep 17 00:00:00 2001 From: Gatis Paeglis Date: Fri, 2 Feb 2018 15:03:39 +0100 Subject: xcb: cleanup TODOs for KeyboardLayoutChange Change-Id: I5d2207fdb21cbabb04460faf73c35275bc76b7b0 Reviewed-by: Allan Sandfeld Jensen --- src/plugins/platforms/xcb/qxcbkeyboard.cpp | 40 ++++++++++++++++-------------- src/plugins/platforms/xcb/qxcbkeyboard.h | 1 + 2 files changed, 23 insertions(+), 18 deletions(-) (limited to 'src/plugins/platforms/xcb') diff --git a/src/plugins/platforms/xcb/qxcbkeyboard.cpp b/src/plugins/platforms/xcb/qxcbkeyboard.cpp index b267cc6dc1..b097ca7b45 100644 --- a/src/plugins/platforms/xcb/qxcbkeyboard.cpp +++ b/src/plugins/platforms/xcb/qxcbkeyboard.cpp @@ -770,7 +770,7 @@ void QXcbKeyboard::updateKeymap() void QXcbKeyboard::updateXKBState(xcb_xkb_state_notify_event_t *state) { if (m_config && connection()->hasXKB()) { - const xkb_state_component newState + const xkb_state_component changedComponents = xkb_state_update_mask(m_xkbState.get(), state->baseMods, state->latchedMods, @@ -779,9 +779,7 @@ void QXcbKeyboard::updateXKBState(xcb_xkb_state_notify_event_t *state) state->latchedGroup, state->lockedGroup); - if ((newState & XKB_STATE_LAYOUT_EFFECTIVE) == XKB_STATE_LAYOUT_EFFECTIVE) { - //qWarning("TODO: Support KeyboardLayoutChange on QPA (QTBUG-27681)"); - } + handleStateChanges(changedComponents); } } #endif @@ -809,9 +807,7 @@ void QXcbKeyboard::updateXKBStateFromCore(quint16 state) xkb_state_component changedComponents = xkb_state_update_mask( xkbState, depressed, latched, locked, 0, 0, lockedGroup(state)); - if ((changedComponents & XKB_STATE_LAYOUT_EFFECTIVE) == XKB_STATE_LAYOUT_EFFECTIVE) { - //qWarning("TODO: Support KeyboardLayoutChange on QPA (QTBUG-27681)"); - } + handleStateChanges(changedComponents); } } @@ -821,21 +817,29 @@ void QXcbKeyboard::updateXKBStateFromXI(void *modInfo, void *groupInfo) if (m_config && !connection()->hasXKB()) { xXIModifierInfo *mods = static_cast(modInfo); xXIGroupInfo *group = static_cast(groupInfo); - const xkb_state_component newState = xkb_state_update_mask(m_xkbState.get(), - mods->base_mods, - mods->latched_mods, - mods->locked_mods, - group->base_group, - group->latched_group, - group->locked_group); - - if ((newState & XKB_STATE_LAYOUT_EFFECTIVE) == XKB_STATE_LAYOUT_EFFECTIVE) { - //qWarning("TODO: Support KeyboardLayoutChange on QPA (QTBUG-27681)"); - } + const xkb_state_component changedComponents + = xkb_state_update_mask(m_xkbState.get(), + mods->base_mods, + mods->latched_mods, + mods->locked_mods, + group->base_group, + group->latched_group, + group->locked_group); + + handleStateChanges(changedComponents); } } #endif +void QXcbKeyboard::handleStateChanges(xkb_state_component changedComponents) +{ + // Note: Ubuntu (with Unity) always creates a new keymap when layout is changed + // via system settings, which means that the layout change would not be detected + // by this code. That can be solved by emitting KeyboardLayoutChange also from updateKeymap(). + if ((changedComponents & XKB_STATE_LAYOUT_EFFECTIVE) == XKB_STATE_LAYOUT_EFFECTIVE) + qCDebug(lcQpaKeyboard, "TODO: Support KeyboardLayoutChange on QPA (QTBUG-27681)"); +} + xkb_mod_mask_t QXcbKeyboard::xkbModMask(quint16 state) { xkb_mod_mask_t xkb_mask = 0; diff --git a/src/plugins/platforms/xcb/qxcbkeyboard.h b/src/plugins/platforms/xcb/qxcbkeyboard.h index a7ab88b9d9..eab917e5b4 100644 --- a/src/plugins/platforms/xcb/qxcbkeyboard.h +++ b/src/plugins/platforms/xcb/qxcbkeyboard.h @@ -82,6 +82,7 @@ public: int coreDeviceId() const { return core_device_id; } void updateXKBState(xcb_xkb_state_notify_event_t *state); #endif + void handleStateChanges(xkb_state_component changedComponents); protected: void handleKeyEvent(xcb_window_t sourceWindow, QEvent::Type type, xcb_keycode_t code, -- cgit v1.2.3