summaryrefslogtreecommitdiffstats
path: root/src/compositor/wayland_wrapper
diff options
context:
space:
mode:
authorJørgen Lind <jorgen.lind@theqtcompany.com>2015-08-19 10:17:48 +0200
committerJørgen Lind <jorgen.lind@theqtcompany.com>2015-08-28 13:10:33 +0200
commite713952c87e2e7b653acc3463481ec885212daca (patch)
treeae1abc0226db387d9affdf14092ce3b8526db91d /src/compositor/wayland_wrapper
parent78be8272ff4f4c77b3892d84cbafff9e74b28a81 (diff)
Move QWaylandKeyboardPrivate away from wayland_wrapper
Diffstat (limited to 'src/compositor/wayland_wrapper')
-rw-r--r--src/compositor/wayland_wrapper/qwldatadevice.cpp1
-rw-r--r--src/compositor/wayland_wrapper/qwlinputmethod.cpp3
-rw-r--r--src/compositor/wayland_wrapper/qwlkeyboard.cpp384
-rw-r--r--src/compositor/wayland_wrapper/qwlkeyboard_p.h146
-rw-r--r--src/compositor/wayland_wrapper/wayland_wrapper.pri2
5 files changed, 2 insertions, 534 deletions
diff --git a/src/compositor/wayland_wrapper/qwldatadevice.cpp b/src/compositor/wayland_wrapper/qwldatadevice.cpp
index 7a375b628..b2eb25684 100644
--- a/src/compositor/wayland_wrapper/qwldatadevice.cpp
+++ b/src/compositor/wayland_wrapper/qwldatadevice.cpp
@@ -38,7 +38,6 @@
#include "qwldatasource_p.h"
#include "qwldataoffer_p.h"
-#include "qwlkeyboard_p.h"
#include "qwaylandsurface_p.h"
#include "qwltouch_p.h"
#include "qwldatadevicemanager_p.h"
diff --git a/src/compositor/wayland_wrapper/qwlinputmethod.cpp b/src/compositor/wayland_wrapper/qwlinputmethod.cpp
index 106cb40a7..febb47a1e 100644
--- a/src/compositor/wayland_wrapper/qwlinputmethod.cpp
+++ b/src/compositor/wayland_wrapper/qwlinputmethod.cpp
@@ -37,9 +37,10 @@
#include "qwlinputmethod_p.h"
#include <QtCompositor/QWaylandCompositor>
+#include <QtCompositor/QWaylandKeyboard>
+#include <QtCompositor/QWaylandInputDevice>
#include "qwlinputmethodcontext_p.h"
#include "qwlinputpanel_p.h"
-#include "qwlkeyboard_p.h"
#include "qwltextinput_p.h"
QT_BEGIN_NAMESPACE
diff --git a/src/compositor/wayland_wrapper/qwlkeyboard.cpp b/src/compositor/wayland_wrapper/qwlkeyboard.cpp
deleted file mode 100644
index 4977ce014..000000000
--- a/src/compositor/wayland_wrapper/qwlkeyboard.cpp
+++ /dev/null
@@ -1,384 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Copyright (C) 2013 Klarälvdalens Datakonsult AB (KDAB).
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the QtWaylandCompositor module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qwlkeyboard_p.h"
-#include "qwlshellsurface_p.h"
-
-#include <QFile>
-#include <QStandardPaths>
-
-#include <QtCompositor/QWaylandClient>
-#include <QtCompositor/QWaylandCompositor>
-
-#include <fcntl.h>
-#include <unistd.h>
-#ifndef QT_NO_WAYLAND_XKB
-#include <sys/mman.h>
-#include <sys/types.h>
-#endif
-
-QT_BEGIN_NAMESPACE
-
-QWaylandKeyboardPrivate::QWaylandKeyboardPrivate(QWaylandInputDevice *seat)
- : QtWaylandServer::wl_keyboard()
- , m_seat(seat)
- , m_grab(this)
- , m_focus()
- , m_focusResource()
- , m_keys()
- , m_modsDepressed()
- , m_modsLatched()
- , m_modsLocked()
- , m_group()
- , m_pendingKeymap(false)
-#ifndef QT_NO_WAYLAND_XKB
- , m_state(0)
-#endif
-{
-#ifndef QT_NO_WAYLAND_XKB
- initXKB();
-#endif
-}
-
-QWaylandKeyboardPrivate::~QWaylandKeyboardPrivate()
-{
-#ifndef QT_NO_WAYLAND_XKB
- 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
-}
-
-void QWaylandKeyboardPrivate::startGrab(QWaylandKeyboardGrabber *grab)
-{
- Q_Q(QWaylandKeyboard);
- m_grab = grab;
- m_grab->m_keyboard = q;
- m_grab->focused(m_focus);
-}
-
-void QWaylandKeyboardPrivate::endGrab()
-{
- m_grab = this;
-}
-
-QWaylandKeyboardGrabber *QWaylandKeyboardPrivate::currentGrab() const
-{
- return m_grab;
-}
-
-QWaylandKeyboardPrivate *QWaylandKeyboardPrivate::get(QWaylandKeyboard *keyboard)
-{
- return keyboard->d_func();
-}
-
-void QWaylandKeyboardPrivate::focused(QWaylandSurface *surface)
-{
- if (surface && surface->isCursorSurface())
- surface = Q_NULLPTR;
- if (m_focusResource && m_focus != surface) {
- uint32_t serial = compositor()->nextSerial();
- send_leave(m_focusResource->handle, serial, m_focus->resource());
- m_focusDestroyListener.reset();
- }
-
- Resource *resource = surface ? resourceMap().value(surface->waylandClient()) : 0;
-
- if (resource && (m_focus != surface || m_focusResource != resource)) {
- uint32_t serial = compositor()->nextSerial();
- send_modifiers(resource->handle, serial, m_modsDepressed, m_modsLatched, m_modsLocked, m_group);
- send_enter(resource->handle, serial, surface->resource(), QByteArray::fromRawData((char *)m_keys.data(), m_keys.size() * sizeof(uint32_t)));
- m_focusDestroyListener.listenForDestruction(surface->resource());
- }
-
- m_focusResource = resource;
- m_focus = surface;
- Q_EMIT q_func()->focusChanged(m_focus);
-}
-
-bool QWaylandKeyboardPrivate::setFocus(QWaylandSurface* surface)
-{
- QtWayland::ShellSurface *shellsurface = QtWayland::ShellSurface::findIn(surface);
- if (shellsurface && shellsurface->isTransientInactive())
- return false;
- m_grab->focused(surface);
- return true;
-}
-
-void QWaylandKeyboardPrivate::setKeymap(const QWaylandKeymap &keymap)
-{
- m_keymap = keymap;
-
- // If there is no key currently pressed, update right away the keymap
- // Otherwise, delay the update when keys are released
- // see http://lists.freedesktop.org/archives/wayland-devel/2013-October/011395.html
- if (m_keys.isEmpty()) {
- updateKeymap();
- } else {
- m_pendingKeymap = true;
- }
-}
-
-void QWaylandKeyboardPrivate::sendKeyModifiers(wl_keyboard::Resource *resource, uint32_t serial)
-{
- send_modifiers(resource->handle, serial, m_modsDepressed, m_modsLatched, m_modsLocked, m_group);
-}
-
-void QWaylandKeyboardPrivate::sendKeyPressEvent(uint code)
-{
- sendKeyEvent(code, WL_KEYBOARD_KEY_STATE_PRESSED);
-}
-
-void QWaylandKeyboardPrivate::sendKeyReleaseEvent(uint code)
-{
- sendKeyEvent(code, WL_KEYBOARD_KEY_STATE_RELEASED);
-}
-
-QWaylandSurface *QWaylandKeyboardPrivate::focus() const
-{
- return m_focus;
-}
-
-void QWaylandKeyboardPrivate::keyboard_bind_resource(wl_keyboard::Resource *resource)
-{
-#ifndef QT_NO_WAYLAND_XKB
- 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);
-}
-
-void QWaylandKeyboardPrivate::keyboard_destroy_resource(wl_keyboard::Resource *resource)
-{
- if (m_focusResource == resource)
- m_focusResource = 0;
-}
-
-void QWaylandKeyboardPrivate::keyboard_release(wl_keyboard::Resource *resource)
-{
- wl_resource_destroy(resource->handle);
-}
-
-void QWaylandKeyboardPrivate::key(uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
-{
- if (m_focusResource) {
- send_key(m_focusResource->handle, serial, time, key, state);
- }
-}
-
-void QWaylandKeyboardPrivate::keyEvent(uint code, uint32_t state)
-{
- uint key = code - 8;
- if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
- m_keys << key;
- } else {
- for (int i = 0; i < m_keys.size(); ++i) {
- if (m_keys.at(i) == key) {
- m_keys.remove(i);
- }
- }
- }
-}
-
-void QWaylandKeyboardPrivate::sendKeyEvent(uint code, uint32_t state)
-{
- uint32_t time = compositor()->currentTimeMsecs();
- uint32_t serial = compositor()->nextSerial();
- uint key = code - 8;
- m_grab->key(serial, time, key, state);
-}
-
-void QWaylandKeyboardPrivate::modifiers(uint32_t serial, uint32_t mods_depressed,
- uint32_t mods_latched, uint32_t mods_locked, uint32_t group)
-{
- if (m_focusResource) {
- send_modifiers(m_focusResource->handle, serial, mods_depressed, mods_latched, mods_locked, group);
- }
-}
-
-void QWaylandKeyboardPrivate::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);
- uint32_t modsLatched = xkb_state_serialize_mods(m_state, (xkb_state_component)XKB_STATE_LATCHED);
- uint32_t modsLocked = xkb_state_serialize_mods(m_state, (xkb_state_component)XKB_STATE_LOCKED);
- uint32_t group = xkb_state_serialize_group(m_state, (xkb_state_component)XKB_STATE_EFFECTIVE);
-
- if (modsDepressed == m_modsDepressed
- && modsLatched == m_modsLatched
- && modsLocked == m_modsLocked
- && group == m_group)
- return;
-
- m_modsDepressed = modsDepressed;
- m_modsLatched = modsLatched;
- m_modsLocked = modsLocked;
- m_group = group;
-
- m_grab->modifiers(compositor()->nextSerial(), m_modsDepressed, m_modsLatched, m_modsLocked, m_group);
-#else
- Q_UNUSED(code);
- Q_UNUSED(state);
-#endif
-}
-
-void QWaylandKeyboardPrivate::updateKeymap()
-{
- // There must be no keys pressed when changing the keymap,
- // see http://lists.freedesktop.org/archives/wayland-devel/2013-October/011395.html
- if (!m_pendingKeymap || !m_keys.isEmpty())
- return;
-
- 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);
- }
-
- xkb_state_update_mask(m_state, 0, m_modsLatched, m_modsLocked, 0, 0, 0);
- if (m_focusResource)
- sendKeyModifiers(m_focusResource, compositor()->nextSerial());
-#endif
-}
-
-#ifndef QT_NO_WAYLAND_XKB
-static int createAnonymousFile(size_t size)
-{
- QString path = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
- if (path.isEmpty())
- return -1;
-
- QByteArray name = QFile::encodeName(path + QStringLiteral("/qtwayland-XXXXXX"));
-
- int fd = mkstemp(name.data());
- if (fd < 0)
- return -1;
-
- long flags = fcntl(fd, F_GETFD);
- if (flags == -1 || fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1) {
- close(fd);
- fd = -1;
- }
- unlink(name.constData());
-
- if (fd < 0)
- return -1;
-
- if (ftruncate(fd, size) < 0) {
- close(fd);
- return -1;
- }
-
- return fd;
-}
-
-void QWaylandKeyboardPrivate::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 QWaylandKeyboardPrivate::createXKBKeymap()
-{
- if (!m_context)
- return;
-
- if (m_state)
- xkb_state_unref(m_state);
-
- struct xkb_rule_names rule_names = { strdup(qPrintable(m_keymap.rules())),
- strdup(qPrintable(m_keymap.model())),
- strdup(qPrintable(m_keymap.layout())),
- strdup(qPrintable(m_keymap.variant())),
- strdup(qPrintable(m_keymap.options())) };
- struct xkb_keymap *keymap = xkb_keymap_new_from_names(m_context, &rule_names, static_cast<xkb_keymap_compile_flags>(0));
-
- char *keymap_str = xkb_keymap_get_as_string(keymap, XKB_KEYMAP_FORMAT_TEXT_V1);
- if (!keymap_str)
- qFatal("Failed to compile global XKB keymap");
-
- m_keymap_size = strlen(keymap_str) + 1;
- m_keymap_fd = createAnonymousFile(m_keymap_size);
- if (m_keymap_fd < 0)
- qFatal("Failed to create anonymous file of size %lu", static_cast<unsigned long>(m_keymap_size));
-
- m_keymap_area = static_cast<char *>(mmap(0, m_keymap_size, PROT_READ | PROT_WRITE, MAP_SHARED, m_keymap_fd, 0));
- if (m_keymap_area == MAP_FAILED) {
- close(m_keymap_fd);
- qFatal("Failed to map shared memory segment");
- }
-
- strcpy(m_keymap_area, keymap_str);
- free(keymap_str);
-
- m_state = xkb_state_new(keymap);
-
- xkb_keymap_unref(keymap);
-
- free((char *)rule_names.rules);
- free((char *)rule_names.model);
- free((char *)rule_names.layout);
- free((char *)rule_names.variant);
- free((char *)rule_names.options);
-}
-#endif
-
-QT_END_NAMESPACE
diff --git a/src/compositor/wayland_wrapper/qwlkeyboard_p.h b/src/compositor/wayland_wrapper/qwlkeyboard_p.h
deleted file mode 100644
index bcd0bab69..000000000
--- a/src/compositor/wayland_wrapper/qwlkeyboard_p.h
+++ /dev/null
@@ -1,146 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Copyright (C) 2013 Klarälvdalens Datakonsult AB (KDAB).
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the QtWaylandCompositor module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QTWAYLAND_QWLKEYBOARD_P_H
-#define QTWAYLAND_QWLKEYBOARD_P_H
-
-#include <QtCompositor/qwaylandexport.h>
-#include <QtCompositor/qwaylandinput.h>
-#include <QtCompositor/qwaylandkeyboard.h>
-#include <QtCompositor/qwaylanddestroylistener.h>
-
-#include <QtCore/private/qobject_p.h>
-#include <QtCompositor/private/qwayland-server-wayland.h>
-
-#include <QtCore/QVector>
-
-#ifndef QT_NO_WAYLAND_XKB
-#include <xkbcommon/xkbcommon.h>
-#endif
-
-
-QT_BEGIN_NAMESPACE
-
-namespace QtWayland {
-
-class Compositor;
-class InputDevice;
-class Surface;
-class Keyboard;
-
-}
-
-class Q_COMPOSITOR_EXPORT QWaylandKeyboardPrivate : public QObjectPrivate
- , public QtWaylandServer::wl_keyboard
- , public QWaylandKeyboardGrabber
-{
-public:
- Q_DECLARE_PUBLIC(QWaylandKeyboard)
-
- QWaylandKeyboardPrivate(QWaylandInputDevice *seat);
- ~QWaylandKeyboardPrivate();
-
- QWaylandCompositor *compositor() const { return m_seat->compositor(); }
- bool setFocus(QWaylandSurface *surface);
- void setKeymap(const QWaylandKeymap &keymap);
-
- void sendKeyModifiers(Resource *resource, uint32_t serial);
- void sendKeyPressEvent(uint code);
- void sendKeyReleaseEvent(uint code);
-
- QWaylandSurface *focus() const;
- Resource *focusResource() const { return m_focusResource; }
-
- void focused(QWaylandSurface* surface);
- void key(uint32_t serial, uint32_t time, uint32_t key, uint32_t state);
- void modifiers(uint32_t serial, uint32_t mods_depressed,
- uint32_t mods_latched, uint32_t mods_locked, uint32_t group);
-
- void startGrab(QWaylandKeyboardGrabber *grab);
- void endGrab();
- QWaylandKeyboardGrabber *currentGrab() const;
-
- static QWaylandKeyboardPrivate *get(QWaylandKeyboard *keyboard);
-
-#ifndef QT_NO_WAYLAND_XKB
- struct xkb_state *xkbState() const { return m_state; }
- uint32_t xkbModsMask() const { return m_modsDepressed | m_modsLatched | m_modsLocked; }
-#endif
- void keyEvent(uint code, uint32_t state);
- void sendKeyEvent(uint code, uint32_t state);
- void updateModifierState(uint code, uint32_t state);
- void updateKeymap();
-
-protected:
- void keyboard_bind_resource(Resource *resource);
- void keyboard_destroy_resource(Resource *resource);
- void keyboard_release(Resource *resource) Q_DECL_OVERRIDE;
-
-private:
-
-#ifndef QT_NO_WAYLAND_XKB
- void initXKB();
- void createXKBKeymap();
-#endif
-
- QWaylandInputDevice *m_seat;
-
- QWaylandKeyboardGrabber* m_grab;
- QWaylandSurface *m_focus;
- Resource *m_focusResource;
- QWaylandDestroyListener m_focusDestroyListener;
-
- QVector<uint32_t> m_keys;
- uint32_t m_modsDepressed;
- uint32_t m_modsLatched;
- uint32_t m_modsLocked;
- uint32_t m_group;
-
- QWaylandKeymap m_keymap;
- bool m_pendingKeymap;
-#ifndef QT_NO_WAYLAND_XKB
- size_t m_keymap_size;
- int m_keymap_fd;
- char *m_keymap_area;
- struct xkb_context *m_context;
- struct xkb_state *m_state;
-#endif
-};
-
-QT_END_NAMESPACE
-
-#endif // QTWAYLAND_QWLKEYBOARD_P_H
diff --git a/src/compositor/wayland_wrapper/wayland_wrapper.pri b/src/compositor/wayland_wrapper/wayland_wrapper.pri
index 3ffc7148e..6355bbb2c 100644
--- a/src/compositor/wayland_wrapper/wayland_wrapper.pri
+++ b/src/compositor/wayland_wrapper/wayland_wrapper.pri
@@ -11,7 +11,6 @@ HEADERS += \
wayland_wrapper/qwldatasource_p.h \
wayland_wrapper/qwlinputmethod_p.h \
wayland_wrapper/qwlinputmethodcontext_p.h \
- wayland_wrapper/qwlkeyboard_p.h \
wayland_wrapper/qwlregion_p.h \
wayland_wrapper/qwlsurfacebuffer_p.h \
wayland_wrapper/qwltouch_p.h \
@@ -24,7 +23,6 @@ SOURCES += \
wayland_wrapper/qwldatasource.cpp \
wayland_wrapper/qwlinputmethod.cpp \
wayland_wrapper/qwlinputmethodcontext.cpp \
- wayland_wrapper/qwlkeyboard.cpp \
wayland_wrapper/qwlregion.cpp \
wayland_wrapper/qwlsurfacebuffer.cpp \
wayland_wrapper/qwltouch.cpp \