diff options
author | Olivier Blin <olivier.blin@softathome.com> | 2012-11-23 16:16:52 +0100 |
---|---|---|
committer | Olivier Blin <qt@blino.org> | 2014-10-23 10:26:48 +0200 |
commit | f9a961c84f08f66025533ac8dbf12b2906951cd3 (patch) | |
tree | e4fd02ce345646476594aad26a5d9dc115a7bbfe | |
parent | 9f09b33d05249e9121092953ffcd2a2c82b9eeef (diff) | |
download | qtwayland-f9a961c84f08f66025533ac8dbf12b2906951cd3.tar.gz |
Gracefully fallback when xkb context creation fails
xkb context creation can fail when xkeyboard-config files are not
available.
This changes qwlkeyboard to gracefully fallback on the
QT_NO_WAYLAND_XKB path, as suggested by Giulio Camuffo.
Change-Id: Ic57d80b6aa3e9fbd8a393a3ca54dff768a4c3e83
Reviewed-by: Giulio Camuffo <giulio.camuffo@jollamobile.com>
-rw-r--r-- | src/compositor/wayland_wrapper/qwlkeyboard.cpp | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/src/compositor/wayland_wrapper/qwlkeyboard.cpp b/src/compositor/wayland_wrapper/qwlkeyboard.cpp index 881f13bc..748639c8 100644 --- a/src/compositor/wayland_wrapper/qwlkeyboard.cpp +++ b/src/compositor/wayland_wrapper/qwlkeyboard.cpp @@ -84,11 +84,13 @@ Keyboard::Keyboard(Compositor *compositor, InputDevice *seat) Keyboard::~Keyboard() { #ifndef QT_NO_WAYLAND_XKB - if (m_keymap_area) - munmap(m_keymap_area, m_keymap_size); - close(m_keymap_fd); - xkb_context_unref(m_context); - xkb_state_unref(m_state); + if (m_context) { + if (m_keymap_area) + munmap(m_keymap_area, m_keymap_size); + close(m_keymap_fd); + xkb_context_unref(m_context); + xkb_state_unref(m_state); + } #endif } @@ -183,14 +185,16 @@ QtWaylandServer::wl_keyboard::Resource *Keyboard::focusResource() const void Keyboard::keyboard_bind_resource(wl_keyboard::Resource *resource) { #ifndef QT_NO_WAYLAND_XKB - send_keymap(resource->handle, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, - m_keymap_fd, m_keymap_size); -#else + if (m_context) { + send_keymap(resource->handle, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, + m_keymap_fd, m_keymap_size); + return; + } +#endif int null_fd = open("/dev/null", O_RDONLY); send_keymap(resource->handle, 0 /* WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP */, null_fd, 0); close(null_fd); -#endif } void Keyboard::keyboard_destroy_resource(wl_keyboard::Resource *resource) @@ -240,6 +244,9 @@ void Keyboard::modifiers(uint32_t serial, uint32_t mods_depressed, void Keyboard::updateModifierState(uint code, uint32_t state) { #ifndef QT_NO_WAYLAND_XKB + if (!m_context) + return; + xkb_state_update_key(m_state, code, state == WL_KEYBOARD_KEY_STATE_PRESSED ? XKB_KEY_DOWN : XKB_KEY_UP); uint32_t modsDepressed = xkb_state_serialize_mods(m_state, (xkb_state_component)XKB_STATE_DEPRESSED); @@ -269,6 +276,9 @@ void Keyboard::updateKeymap() { m_pendingKeymap = false; #ifndef QT_NO_WAYLAND_XKB + if (!m_context) + return; + createXKBKeymap(); foreach (Resource *res, resourceMap()) { send_keymap(res->handle, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, m_keymap_fd, m_keymap_size); @@ -314,11 +324,19 @@ static int createAnonymousFile(size_t size) void Keyboard::initXKB() { m_context = xkb_context_new(static_cast<xkb_context_flags>(0)); + if (!m_context) { + qWarning("Failed to create a XKB context: keymap will not be supported"); + return; + } + createXKBKeymap(); } void Keyboard::createXKBKeymap() { + if (!m_context) + return; + if (m_state) xkb_state_unref(m_state); |