summaryrefslogtreecommitdiffstats
path: root/src/compositor/wayland_wrapper/wlinputdevice.cpp
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.p.agocs@nokia.com>2012-05-17 13:03:57 +0300
committerLaszlo Agocs <laszlo.p.agocs@nokia.com>2012-05-20 16:13:02 +0200
commit8b991cabcc9289455f963aadb8c0666068efe476 (patch)
tree11192d9cb23c2aedf29db9dad1af32b7cfbb8fd1 /src/compositor/wayland_wrapper/wlinputdevice.cpp
parent3836847ab68c52e4fe39dff94649534ffda99418 (diff)
Migrate from wl_input_device to wl_seat
Change-Id: I0d218c32478c2acce4d7012bdb26b0cde50ee633 Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
Diffstat (limited to 'src/compositor/wayland_wrapper/wlinputdevice.cpp')
-rw-r--r--src/compositor/wayland_wrapper/wlinputdevice.cpp342
1 files changed, 238 insertions, 104 deletions
diff --git a/src/compositor/wayland_wrapper/wlinputdevice.cpp b/src/compositor/wayland_wrapper/wlinputdevice.cpp
index 2e111536c..10be24b69 100644
--- a/src/compositor/wayland_wrapper/wlinputdevice.cpp
+++ b/src/compositor/wayland_wrapper/wlinputdevice.cpp
@@ -57,43 +57,193 @@ 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);
+ wl_seat_init(base());
+ initDevices();
+ wl_display_add_global(compositor->wl_display(),
+ &wl_seat_interface,
+ this,
+ InputDevice::bind_func);
}
InputDevice::~InputDevice()
{
qDeleteAll(m_data_devices);
+ releaseDevices();
+}
+
+void InputDevice::initDevices()
+{
+ wl_pointer_init(&m_device_interfaces.pointer);
+ wl_seat_set_pointer(base(), &m_device_interfaces.pointer);
+
+ wl_keyboard_init(&m_device_interfaces.keyboard);
+ wl_seat_set_keyboard(base(), &m_device_interfaces.keyboard);
+
+ wl_touch_init(&m_device_interfaces.touch);
+ wl_seat_set_touch(base(), &m_device_interfaces.touch);
+}
+
+void InputDevice::releaseDevices()
+{
+ wl_pointer_release(&m_device_interfaces.pointer);
+ wl_keyboard_release(&m_device_interfaces.keyboard);
+ wl_touch_release(&m_device_interfaces.touch);
+}
+
+wl_pointer *InputDevice::pointerDevice()
+{
+ return &m_device_interfaces.pointer;
+}
+
+wl_keyboard *InputDevice::keyboardDevice()
+{
+ return &m_device_interfaces.keyboard;
+}
+
+wl_touch *InputDevice::touchDevice()
+{
+ return &m_device_interfaces.touch;
+}
+
+const wl_pointer *InputDevice::pointerDevice() const
+{
+ return &m_device_interfaces.pointer;
+}
+
+const wl_keyboard *InputDevice::keyboardDevice() const
+{
+ return &m_device_interfaces.keyboard;
+}
+
+const wl_touch *InputDevice::touchDevice() const
+{
+ return &m_device_interfaces.touch;
+}
+
+void InputDevice::destroy_resource(wl_resource *resource)
+{
+ InputDevice *input_device = static_cast<InputDevice *>(resource->data);
+ if (input_device->keyboardDevice()->focus_resource == resource) {
+ input_device->keyboardDevice()->focus_resource = 0;
+ }
+ if (input_device->pointerDevice()->focus_resource == resource) {
+ input_device->pointerDevice()->focus_resource = 0;
+ }
+
+ input_device->cleanupDataDeviceForClient(resource->client, true);
+
+ wl_list_remove(&resource->link);
+
+ free(resource);
+}
+
+void InputDevice::bind_func(struct wl_client *client, void *data,
+ uint32_t version, uint32_t id)
+{
+ Q_UNUSED(version);
+ struct wl_resource *resource = wl_client_add_object(client,
+ &wl_seat_interface,
+ &seat_interface,
+ id,
+ data);
+
+ struct wl_seat *seat = static_cast<struct wl_seat *>(data);
+ resource->destroy = destroy_resource;
+ wl_list_insert(&seat->base_resource_list, &resource->link);
+
+ uint32_t caps = WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_KEYBOARD;
+ if (!QTouchDevice::devices().isEmpty())
+ caps |= WL_SEAT_CAPABILITY_TOUCH;
+
+ wl_seat_send_capabilities(resource, caps);
+}
+
+const struct wl_seat_interface InputDevice::seat_interface = {
+ get_pointer,
+ get_keyboard,
+ get_touch
+};
+
+void InputDevice::destroy_device_resource(wl_resource *resource)
+{
+ wl_list_remove(&resource->link);
+ free(resource);
+}
+
+void InputDevice::get_pointer(struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t id)
+{
+ InputDevice *inputDevice = static_cast<InputDevice *>(resource->data);
+ wl_pointer *pointer = inputDevice->pointerDevice();
+ wl_resource *clientResource = wl_client_add_object(client,
+ &wl_pointer_interface,
+ &pointer_interface,
+ id,
+ pointer);
+ wl_list_insert(&pointer->resource_list, &clientResource->link);
+ clientResource->destroy = InputDevice::destroy_device_resource;
+}
+
+void InputDevice::get_keyboard(struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t id)
+{
+ InputDevice *inputDevice = static_cast<InputDevice *>(resource->data);
+ wl_keyboard *keyboard = inputDevice->keyboardDevice();
+ wl_resource *clientResource = wl_client_add_object(client,
+ &wl_keyboard_interface,
+ 0,
+ id,
+ keyboard);
+ wl_list_insert(&keyboard->resource_list, &clientResource->link);
+ clientResource->destroy = InputDevice::destroy_device_resource;
+}
+
+void InputDevice::get_touch(struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t id)
+{
+ InputDevice *inputDevice = static_cast<InputDevice *>(resource->data);
+ wl_touch *touch = inputDevice->touchDevice();
+ wl_resource *clientResource = wl_client_add_object(client,
+ &wl_touch_interface,
+ 0,
+ id,
+ touch);
+ wl_list_insert(&touch->resource_list, &clientResource->link);
+ clientResource->destroy = InputDevice::destroy_device_resource;
}
void InputDevice::sendMousePressEvent(Qt::MouseButton button, const QPointF &localPos, const QPointF &globalPos)
{
sendMouseMoveEvent(localPos,globalPos);
-
- base()->button_count++;
+ wl_pointer *pointer = pointerDevice();
+ pointer->button_count++;
uint32_t time = m_compositor->currentTimeMsecs();
- const struct wl_pointer_grab_interface *interface = base()->pointer_grab->interface;
- interface->button(base()->pointer_grab,time,toWaylandButton(button),1);
+ const struct wl_pointer_grab_interface *interface = pointer->grab->interface;
+ interface->button(pointer->grab, time, toWaylandButton(button), 1);
}
void InputDevice::sendMouseReleaseEvent(Qt::MouseButton button, const QPointF &localPos, const QPointF &globalPos)
{
sendMouseMoveEvent(localPos,globalPos);
-
- base()->button_count--;
+ wl_pointer *pointer = pointerDevice();
+ pointer->button_count--;
uint32_t time = m_compositor->currentTimeMsecs();
- const struct wl_pointer_grab_interface *interface = base()->pointer_grab->interface;
- interface->button(base()->pointer_grab,time,toWaylandButton(button),0);
+ const struct wl_pointer_grab_interface *interface = pointer->grab->interface;
+ interface->button(pointer->grab, time, toWaylandButton(button), 0);
}
void InputDevice::sendMouseMoveEvent(const QPointF &localPos, const QPointF &globalPos)
{
Q_UNUSED(globalPos);
uint32_t time = m_compositor->currentTimeMsecs();
- const struct wl_pointer_grab_interface *interface = base()->pointer_grab->interface;
- base()->x = wl_fixed_from_double(globalPos.x());
- base()->y = wl_fixed_from_double(globalPos.y());
- interface->motion(base()->pointer_grab,
+ wl_pointer *pointer = pointerDevice();
+ const struct wl_pointer_grab_interface *interface = pointer->grab->interface;
+ pointer->x = wl_fixed_from_double(globalPos.x());
+ pointer->y = wl_fixed_from_double(globalPos.y());
+ interface->motion(pointer->grab,
time,
wl_fixed_from_double(localPos.x()), wl_fixed_from_double(localPos.y()));
}
@@ -106,32 +256,35 @@ void InputDevice::sendMouseMoveEvent(Surface *surface, const QPointF &localPos,
void InputDevice::sendMouseWheelEvent(Qt::Orientation orientation, int delta)
{
- struct wl_resource *resource = base()->pointer_focus_resource;
+ wl_pointer *pointer = pointerDevice();
+ struct wl_resource *resource = pointer->focus_resource;
if (!resource)
return;
uint32_t time = m_compositor->currentTimeMsecs();
- uint32_t axis = orientation == Qt::Horizontal ? WL_INPUT_DEVICE_AXIS_HORIZONTAL_SCROLL
- : WL_INPUT_DEVICE_AXIS_VERTICAL_SCROLL;
- wl_input_device_send_axis(resource, time, axis, delta);
+ uint32_t axis = orientation == Qt::Horizontal ? WL_POINTER_AXIS_HORIZONTAL_SCROLL
+ : WL_POINTER_AXIS_VERTICAL_SCROLL;
+ wl_pointer_send_axis(resource, time, axis, delta);
}
void InputDevice::sendKeyPressEvent(uint code)
{
- if (base()->keyboard_focus_resource != NULL) {
+ wl_keyboard *keyboard = keyboardDevice();
+ if (keyboard->focus_resource) {
uint32_t time = m_compositor->currentTimeMsecs();
uint32_t serial = wl_display_next_serial(m_compositor->wl_display());
- wl_input_device_send_key(base()->keyboard_focus_resource,
- serial, time, code - 8, 1);
+ wl_keyboard_send_key(keyboard->focus_resource,
+ serial, time, code - 8, 1);
}
}
void InputDevice::sendKeyReleaseEvent(uint code)
{
- if (base()->keyboard_focus_resource != NULL) {
+ wl_keyboard *keyboard = keyboardDevice();
+ if (keyboard->focus_resource) {
uint32_t time = m_compositor->currentTimeMsecs();
uint32_t serial = wl_display_next_serial(m_compositor->wl_display());
- wl_input_device_send_key(base()->keyboard_focus_resource,
- serial, time, code - 8, 0);
+ wl_keyboard_send_key(keyboard->focus_resource,
+ serial, time, code - 8, 0);
}
}
@@ -139,20 +292,21 @@ void InputDevice::sendTouchPointEvent(int id, double x, double y, Qt::TouchPoint
{
uint32_t time = m_compositor->currentTimeMsecs();
uint32_t serial = 0;
- struct wl_resource *resource = base()->pointer_focus_resource;
+ wl_touch *touch = touchDevice();
+ wl_resource *resource = touch->focus_resource;
if (!resource)
return;
switch (state) {
case Qt::TouchPointPressed:
- wl_input_device_send_touch_down(resource, serial, time, &base()->pointer_focus->resource, id,
- wl_fixed_from_double(x), wl_fixed_from_double(y));
+ wl_touch_send_down(resource, serial, time, &touch->focus->resource, id,
+ wl_fixed_from_double(x), wl_fixed_from_double(y));
break;
case Qt::TouchPointMoved:
- wl_input_device_send_touch_motion(resource, time, id,
- wl_fixed_from_double(x), wl_fixed_from_double(y));
+ wl_touch_send_motion(resource, time, id,
+ wl_fixed_from_double(x), wl_fixed_from_double(y));
break;
case Qt::TouchPointReleased:
- wl_input_device_send_touch_up(resource, serial, time, id);
+ wl_touch_send_up(resource, serial, time, id);
break;
case Qt::TouchPointStationary:
// stationary points are not sent through wayland, the client must cache them
@@ -164,18 +318,18 @@ void InputDevice::sendTouchPointEvent(int id, double x, double y, Qt::TouchPoint
void InputDevice::sendTouchFrameEvent()
{
- struct wl_resource *resource = base()->pointer_focus_resource;
- if (resource) {
- wl_input_device_send_touch_frame(resource);
- }
+ wl_touch *touch = touchDevice();
+ wl_resource *resource = touch->focus_resource;
+ if (resource)
+ wl_touch_send_frame(resource);
}
void InputDevice::sendTouchCancelEvent()
{
- struct wl_resource *resource = base()->pointer_focus_resource;
- if (resource) {
- wl_input_device_send_touch_cancel(resource);
- }
+ wl_touch *touch = touchDevice();
+ wl_resource *resource = touch->focus_resource;
+ if (resource)
+ wl_touch_send_cancel(resource);
}
void InputDevice::sendFullKeyEvent(QKeyEvent *event)
@@ -228,30 +382,37 @@ void InputDevice::sendFullTouchEvent(QTouchEvent *event)
Surface *InputDevice::keyboardFocus() const
{
- return wayland_cast<Surface>(base()->keyboard_focus);
+ return wayland_cast<Surface>(keyboardDevice()->focus);
}
void InputDevice::setKeyboardFocus(Surface *surface)
{
sendSelectionFocus(surface);
- wl_input_device_set_keyboard_focus(base(), surface ? surface->base() : 0);
+ wl_keyboard_set_focus(keyboardDevice(), surface ? surface->base() : 0);
}
Surface *InputDevice::mouseFocus() const
{
- return wayland_cast<Surface>(base()->pointer_focus);
+ return wayland_cast<Surface>(pointerDevice()->focus);
}
void InputDevice::setMouseFocus(Surface *surface, const QPointF &globalPos, const QPointF &localPos)
{
- base()->x = wl_fixed_from_double(globalPos.x());
- base()->y = wl_fixed_from_double(globalPos.y());
- base()->current = surface ? surface->base() : 0;
- base()->current_x = wl_fixed_from_double(localPos.x());
- base()->current_y = wl_fixed_from_double(localPos.y());
- base()->pointer_grab->interface->focus(base()->pointer_grab,
- surface ? surface->base() : 0,
- wl_fixed_from_double(localPos.x()), wl_fixed_from_double(localPos.y()));
+ wl_pointer *pointer = pointerDevice();
+ pointer->x = wl_fixed_from_double(globalPos.x());
+ pointer->y = wl_fixed_from_double(globalPos.y());
+ pointer->current = surface ? surface->base() : 0;
+ pointer->current_x = wl_fixed_from_double(localPos.x());
+ pointer->current_y = wl_fixed_from_double(localPos.y());
+ pointer->grab->interface->focus(pointer->grab,
+ surface ? surface->base() : 0,
+ wl_fixed_from_double(localPos.x()), wl_fixed_from_double(localPos.y()));
+
+ // We have no separate touch focus management so make it match the pointer focus always.
+ // No wl_touch_set_focus() is available so set it manually.
+ wl_touch *touch = touchDevice();
+ touch->focus = surface ? surface->base() : 0;
+ touch->focus_resource = Compositor::resourceForSurface(&touch->resource_list, surface);
}
void InputDevice::cleanupDataDeviceForClient(struct wl_client *client, bool destroyDev)
@@ -303,24 +464,24 @@ uint32_t InputDevice::toWaylandButton(Qt::MouseButton button)
// the range of valid buttons (evdev module) is from 0x110
// through 0x11f. 0x120 is the first 'Joystick' button.
switch (button) {
- case Qt::LeftButton: return BTN_LEFT;
- case Qt::RightButton: return uint32_t(0x111);
- case Qt::MiddleButton: return uint32_t(0x112);
- case Qt::ExtraButton1: return uint32_t(0x113); // AKA Qt::BackButton, Qt::XButton1
- case Qt::ExtraButton2: return uint32_t(0x114); // AKA Qt::ForwardButton, Qt::XButton2
- case Qt::ExtraButton3: return uint32_t(0x115);
- case Qt::ExtraButton4: return uint32_t(0x116);
- case Qt::ExtraButton5: return uint32_t(0x117);
- case Qt::ExtraButton6: return uint32_t(0x118);
- case Qt::ExtraButton7: return uint32_t(0x119);
- case Qt::ExtraButton8: return uint32_t(0x11a);
- case Qt::ExtraButton9: return uint32_t(0x11b);
- case Qt::ExtraButton10: return uint32_t(0x11c);
- case Qt::ExtraButton11: return uint32_t(0x11d);
- case Qt::ExtraButton12: return uint32_t(0x11e);
- case Qt::ExtraButton13: return uint32_t(0x11f);
+ case Qt::LeftButton: return BTN_LEFT;
+ case Qt::RightButton: return uint32_t(0x111);
+ case Qt::MiddleButton: return uint32_t(0x112);
+ case Qt::ExtraButton1: return uint32_t(0x113); // AKA Qt::BackButton, Qt::XButton1
+ case Qt::ExtraButton2: return uint32_t(0x114); // AKA Qt::ForwardButton, Qt::XButton2
+ case Qt::ExtraButton3: return uint32_t(0x115);
+ case Qt::ExtraButton4: return uint32_t(0x116);
+ case Qt::ExtraButton5: return uint32_t(0x117);
+ case Qt::ExtraButton6: return uint32_t(0x118);
+ case Qt::ExtraButton7: return uint32_t(0x119);
+ case Qt::ExtraButton8: return uint32_t(0x11a);
+ case Qt::ExtraButton9: return uint32_t(0x11b);
+ case Qt::ExtraButton10: return uint32_t(0x11c);
+ case Qt::ExtraButton11: return uint32_t(0x11d);
+ case Qt::ExtraButton12: return uint32_t(0x11e);
+ case Qt::ExtraButton13: return uint32_t(0x11f);
// default should not occur; but if it does, then return Wayland's highest possible button number.
- default: return uint32_t(0x11f);
+ default: return uint32_t(0x11f);
}
}
@@ -334,29 +495,22 @@ DataDevice *InputDevice::dataDevice(struct wl_client *client) const
return 0;
}
-void InputDevice::bind_func(struct wl_client *client, void *data,
- uint32_t version, uint32_t id)
-{
- Q_UNUSED(version);
- struct wl_resource *resource = wl_client_add_object(client,&wl_input_device_interface ,&input_device_interface,id,data);
-
- struct wl_input_device *input_device = static_cast<struct wl_input_device *>(data);
- resource->destroy = destroy_resource;
- wl_list_insert(&input_device->resource_list,&resource->link);
-}
+const struct wl_pointer_interface InputDevice::pointer_interface = {
+ InputDevice::pointer_attach
+};
-void InputDevice::input_device_attach(struct wl_client *client,
- struct wl_resource *device_resource,
- uint32_t time,
- struct wl_resource *buffer_resource, int32_t x, int32_t y)
+void InputDevice::pointer_attach(struct wl_client *client,
+ struct wl_resource *device_resource,
+ uint32_t serial,
+ struct wl_resource *buffer_resource, int32_t x, int32_t y)
{
Q_UNUSED(client);
- Q_UNUSED(time);
+ Q_UNUSED(serial);
- 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);
+ wl_pointer *pointer = reinterpret_cast<wl_pointer *>(device_resource->data);
+ InputDevice *inputDevice = wayland_cast<InputDevice>(pointer->seat);
+ wl_buffer *buffer = reinterpret_cast<wl_buffer *>(buffer_resource);
- InputDevice *inputDevice = wayland_cast<InputDevice>(device_base);
if (wl_buffer_is_shm(buffer)) {
int stride = wl_shm_buffer_get_stride(buffer);
uint format = wl_shm_buffer_get_format(buffer);
@@ -372,25 +526,5 @@ void InputDevice::input_device_attach(struct wl_client *client,
}
}
-const struct wl_input_device_interface InputDevice::input_device_interface = {
- InputDevice::input_device_attach,
-};
-
-void InputDevice::destroy_resource(wl_resource *resource)
-{
- InputDevice *input_device = static_cast<InputDevice *>(resource->data);
- if (input_device->base()->keyboard_focus_resource == resource) {
- input_device->base()->keyboard_focus_resource = 0;
- }
- if (input_device->base()->pointer_focus_resource == resource) {
- input_device->base()->pointer_focus_resource = 0;
- }
-
- input_device->cleanupDataDeviceForClient(resource->client, true);
-
- wl_list_remove(&resource->link);
-
- free(resource);
-}
}