summaryrefslogtreecommitdiffstats
path: root/src/compositor/wayland_wrapper/wlinputdevice.cpp
diff options
context:
space:
mode:
authorJørgen Lind <jorgen.lind@nokia.com>2012-01-11 09:35:39 +0100
committerLaszlo Agocs <laszlo.p.agocs@nokia.com>2012-01-11 11:07:24 +0100
commit8894f58e01b51e9b2072973edbe043ebe62858b4 (patch)
tree1a449793f14256d228b0ea0251e289a9013f13de /src/compositor/wayland_wrapper/wlinputdevice.cpp
parentbf850bd6ea971a44a0af8e6940edb3ba419da962 (diff)
Move event handling into WaylandInput api
Qt only gives us 1 input device as of now, ie. the mouse/keyboard and touch events. However, at some point in the future, this will change, so that the events will have a device id. This will ie on x map to the same device, but on evdev this can be different devices. Also this is part of what is needed to implement grabbing Change-Id: Ice049502d6f0f53fd06142d4dedde05806d60120 Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Laszlo Agocs <laszlo.p.agocs@nokia.com>
Diffstat (limited to 'src/compositor/wayland_wrapper/wlinputdevice.cpp')
-rw-r--r--src/compositor/wayland_wrapper/wlinputdevice.cpp181
1 files changed, 173 insertions, 8 deletions
diff --git a/src/compositor/wayland_wrapper/wlinputdevice.cpp b/src/compositor/wayland_wrapper/wlinputdevice.cpp
index 511ac483a..92eb12238 100644
--- a/src/compositor/wayland_wrapper/wlinputdevice.cpp
+++ b/src/compositor/wayland_wrapper/wlinputdevice.cpp
@@ -45,28 +45,169 @@
#include "wldatadevice.h"
#include "wlsurface.h"
-#include <QtCore/QDebug>
-
#include "waylandcompositor.h"
+#include <QtGui/QTouchEvent>
+
namespace Wayland {
static ShmBuffer *currentCursor;
-InputDevice::InputDevice(Compositor *compositor)
- : m_compositor(compositor)
+InputDevice::InputDevice(WaylandInputDevice *handle, Compositor *compositor)
+ : m_handle(handle)
+ , m_compositor(compositor)
{
wl_input_device_init(base());
wl_display_add_global(compositor->wl_display(),&wl_input_device_interface,this,InputDevice::bind_func);
}
+void InputDevice::sendMousePressEvent(Qt::MouseButton button, const QPoint &localPos, const QPoint &globalPos)
+{
+ sendMouseMoveEvent(localPos,globalPos);
+
+ uint32_t time = m_compositor->currentTimeMsecs();
+ struct wl_resource *pointer_focus_resource = base()->pointer_focus_resource;
+ if (pointer_focus_resource) {
+ wl_resource_post_event(pointer_focus_resource,
+ WL_INPUT_DEVICE_BUTTON, time, toWaylandButton(button), 1);
+ }
+}
+
+void InputDevice::sendMouseReleaseEvent(Qt::MouseButton button, const QPoint &localPos, const QPoint &globalPos)
+{
+ sendMouseMoveEvent(localPos,globalPos);
+
+ uint32_t time = m_compositor->currentTimeMsecs();
+ struct wl_resource *pointer_focus_resource = base()->pointer_focus_resource;
+ if (pointer_focus_resource) {
+ wl_resource_post_event(pointer_focus_resource,
+ WL_INPUT_DEVICE_BUTTON, time, toWaylandButton(button), 0);
+ }
+}
+
+void InputDevice::sendMouseMoveEvent(const QPoint &localPos, const QPoint &globalPos)
+{
+ uint32_t time = m_compositor->currentTimeMsecs();
+ struct wl_resource *pointer_focus_resource = base()->pointer_focus_resource;
+ if (pointer_focus_resource) {
+ QPoint validGlobalPos = globalPos.isNull()?localPos:globalPos;
+ wl_resource_post_event(pointer_focus_resource,
+ WL_INPUT_DEVICE_MOTION,
+ time,
+ validGlobalPos.x(), validGlobalPos.y(), //wayland sends globals before locals
+ localPos.x(), localPos.y());
+ }
+}
+
+void InputDevice::sendMouseMoveEvent(Surface *surface, const QPoint &localPos, const QPoint &globalPos)
+{
+ if (mouseFocus() != surface) {
+ setMouseFocus(surface,localPos,globalPos);
+ }
+ sendMouseMoveEvent(localPos,globalPos);
+}
+
+void InputDevice::sendKeyPressEvent(uint code)
+{
+ if (base()->keyboard_focus_resource != NULL) {
+ uint32_t time = m_compositor->currentTimeMsecs();
+ wl_resource_post_event(base()->keyboard_focus_resource,
+ WL_INPUT_DEVICE_KEY, time, code - 8, 1);
+ }
+}
+
+void InputDevice::sendKeyReleaseEvent(uint code)
+{
+ if (base()->keyboard_focus_resource != NULL) {
+ uint32_t time = m_compositor->currentTimeMsecs();
+ wl_resource_post_event(base()->keyboard_focus_resource,
+ WL_INPUT_DEVICE_KEY, time, code - 8, 0);
+ }
+}
+
+void InputDevice::sendTouchPointEvent(int id, int x, int y, Qt::TouchPointState state)
+{
+ uint32_t time = m_compositor->currentTimeMsecs();
+ struct wl_resource *resource = base()->pointer_focus_resource;
+ switch (state) {
+ case Qt::TouchPointPressed:
+ wl_resource_post_event(resource, WL_INPUT_DEVICE_TOUCH_DOWN, time, this, id, x, y);
+ break;
+ case Qt::TouchPointMoved:
+ wl_resource_post_event(resource, WL_INPUT_DEVICE_TOUCH_MOTION, time, id, x, y);
+ break;
+ case Qt::TouchPointReleased:
+ wl_resource_post_event(resource, WL_INPUT_DEVICE_TOUCH_UP, time, id);
+ break;
+ case Qt::TouchPointStationary:
+ // stationary points are not sent through wayland, the client must cache them
+ break;
+ default:
+ break;
+ }
+}
+
+void InputDevice::sendTouchFrameEvent()
+{
+ struct wl_resource *resource = base()->pointer_focus_resource;
+ wl_resource_post_event(resource,
+ WL_INPUT_DEVICE_TOUCH_FRAME);
+}
+
+void InputDevice::sendTouchCancelEvent()
+{
+ struct wl_resource *resource = base()->pointer_focus_resource;
+ wl_resource_post_event(resource,
+ WL_INPUT_DEVICE_TOUCH_CANCEL);
+}
+
+void InputDevice::sendFullTouchEvent(QTouchEvent *event)
+{
+ const QList<QTouchEvent::TouchPoint> points = event->touchPoints();
+ if (points.isEmpty())
+ return;
+ const int pointCount = points.count();
+ QPointF pos = mouseFocus()? mouseFocus()->pos():QPointF(0,0);
+ for (int i = 0; i < pointCount; ++i) {
+ const QTouchEvent::TouchPoint &tp(points.at(i));
+ // Convert the local pos in the compositor window to surface-relative.
+ QPoint p = (tp.pos() - pos).toPoint();
+ sendTouchPointEvent(tp.id(), p.x(), p.y(), tp.state());
+ }
+ sendTouchFrameEvent();
+}
+
+Surface *InputDevice::keyboardFocus() const
+{
+ return wayland_cast<Surface *>(base()->keyboard_focus);
+}
+
+void InputDevice::setKeyboardFocus(Surface *surface)
+{
+ sendSelectionFocus(surface);
+ wl_input_device_set_keyboard_focus(base(), surface ? surface->base() : 0, m_compositor->currentTimeMsecs());
+}
+
+Surface *InputDevice::mouseFocus() const
+{
+ return wayland_cast<Surface *>(base()->pointer_focus);
+}
+
+void InputDevice::setMouseFocus(Surface *surface, const QPoint &globalPos, const QPoint &localPos)
+{
+ wl_input_device_set_pointer_focus(base(),
+ surface ? surface->base() : 0,
+ m_compositor->currentTimeMsecs(),
+ globalPos.x(), globalPos.y(),
+ localPos.x(), localPos.y());
+}
+
void InputDevice::clientRequestedDataDevice(DataDeviceManager *data_device_manager, struct wl_client *client, uint32_t id)
{
for (int i = 0; i < m_data_devices.size(); i++) {
struct wl_resource *data_device_resource =
m_data_devices.at(i)->dataDeviceResource();
if (data_device_resource->client == client) {
- qDebug() << "Client created data device, but already has one; removing the old one!";
m_data_devices.removeAt(i);
free(data_device_resource);
break;
@@ -74,7 +215,6 @@ void InputDevice::clientRequestedDataDevice(DataDeviceManager *data_device_manag
}
DataDevice *dataDevice = new DataDevice(data_device_manager,client,id);
m_data_devices.append(dataDevice);
- qDebug("created datadevice %p resource %p", dataDevice, dataDevice->dataDeviceResource());
}
void InputDevice::sendSelectionFocus(Surface *surface)
@@ -87,6 +227,33 @@ void InputDevice::sendSelectionFocus(Surface *surface)
}
}
+Compositor *InputDevice::compositor() const
+{
+ return m_compositor;
+}
+
+WaylandInputDevice *InputDevice::handle() const
+{
+ return m_handle;
+}
+
+uint32_t InputDevice::toWaylandButton(Qt::MouseButton button)
+{
+#ifndef BTN_LEFT
+ uint32_t BTN_LEFT = 0x110;
+ uint32_t BTN_RIGHT = 0x111;
+ uint32_t BTN_MIDDLE = 0x112;
+#endif
+ switch (button) {
+ case Qt::LeftButton:
+ return BTN_LEFT;
+ case Qt::RightButton:
+ return BTN_RIGHT;
+ default:
+ return BTN_MIDDLE;
+ }
+}
+
DataDevice *InputDevice::dataDevice(struct wl_client *client) const
{
for (int i = 0; i < m_data_devices.size();i++) {
@@ -118,7 +285,6 @@ void InputDevice::input_device_attach(struct wl_client *client,
struct wl_input_device *device_base = reinterpret_cast<struct wl_input_device *>(device_resource->data);
struct wl_buffer *buffer = reinterpret_cast<struct wl_buffer *>(buffer_resource);
- qDebug() << "Client input device attach" << client << buffer << x << y;
InputDevice *inputDevice = wayland_cast<InputDevice *>(device_base);
if (wl_buffer_is_shm(buffer)) {
@@ -136,7 +302,6 @@ const struct wl_input_device_interface InputDevice::input_device_interface = {
void InputDevice::destroy_resource(wl_resource *resource)
{
- qDebug() << "input device resource destroy" << resource;
InputDevice *input_device = static_cast<InputDevice *>(resource->data);
if (input_device->base()->keyboard_focus_resource == resource) {
input_device->base()->keyboard_focus_resource = 0;