static void handle_touch_with_coords(struct libinput_device *libinput_device, struct libinput_event_touch *touch_event, int touch_type) { struct evdev_device *device = libinput_device_get_user_data(libinput_device); wl_fixed_t x; wl_fixed_t y; uint32_t width, height; uint32_t time; int32_t slot; if (!device->output) return; time = libinput_event_touch_get_time(touch_event); slot = libinput_event_touch_get_seat_slot(touch_event); width = device->output->current_mode->width; height = device->output->current_mode->height; x = wl_fixed_from_double( libinput_event_touch_get_x_transformed(touch_event, width)); y = wl_fixed_from_double( libinput_event_touch_get_y_transformed(touch_event, height)); weston_output_transform_coordinate(device->output, x, y, &x, &y); notify_touch(device->seat, time, slot, x, y, touch_type); }
void LibinputServer::handleTouchEvent(struct libinput_event *event, Input::TouchEvent::Type type) { auto* touchEvent = libinput_event_get_touch_event(event); uint32_t time = libinput_event_touch_get_time(touchEvent); int id = libinput_event_touch_get_slot(touchEvent); auto& targetPoint = m_touchEvents[id]; int32_t x, y; if (type != Input::TouchEvent::Up) { x = libinput_event_touch_get_x_transformed(touchEvent, m_pointerBounds.first); y = libinput_event_touch_get_y_transformed(touchEvent, m_pointerBounds.second); } else { // libinput can't return pointer position on touch-up x = targetPoint.x; y = targetPoint.y; } targetPoint = Input::TouchEvent::Raw{ type, time, id, x, y }; m_client->handleTouchEvent({ m_touchEvents, type, id, time }); if (type == Input::TouchEvent::Up) { targetPoint = Input::TouchEvent::Raw{ Input::TouchEvent::Null, 0, -1, -1, -1 }; } }
static double touch_abs_y(void *internal, uint32_t height) { struct libinput_event_touch *tev = internal; return libinput_event_touch_get_y_transformed(tev, height); }
inline void LibInputHandler::HandleEvent(struct libinput_event *li_event) { int type = libinput_event_get_type(li_event); switch (type) { case LIBINPUT_EVENT_KEYBOARD_KEY: { /* Discard all data on stdin to avoid that keyboard input data is read * on the executing shell. */ tcflush(STDIN_FILENO, TCIFLUSH); libinput_event_keyboard *kb_li_event = libinput_event_get_keyboard_event(li_event); uint32_t key_code = libinput_event_keyboard_get_key(kb_li_event); libinput_key_state key_state = libinput_event_keyboard_get_key_state(kb_li_event); queue.Push(Event(key_state == LIBINPUT_KEY_STATE_PRESSED ? Event::KEY_DOWN : Event::KEY_UP, key_code)); } break; case LIBINPUT_EVENT_POINTER_MOTION: { libinput_event_pointer *ptr_li_event = libinput_event_get_pointer_event(li_event); if (-1.0 == x) x = 0.0; if (-1.0 == y) y = 0.0; x += libinput_event_pointer_get_dx(ptr_li_event); x = Clamp<double>(x, 0, width); y += libinput_event_pointer_get_dy(ptr_li_event); y = Clamp<double>(y, 0, height); queue.Push(Event(Event::MOUSE_MOTION, (unsigned) x, (unsigned) y)); } break; case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: { libinput_event_pointer *ptr_li_event = libinput_event_get_pointer_event(li_event); x = libinput_event_pointer_get_absolute_x_transformed(ptr_li_event, width); y = libinput_event_pointer_get_absolute_y_transformed(ptr_li_event, height); queue.Push(Event(Event::MOUSE_MOTION, (unsigned) x, (unsigned) y)); } break; case LIBINPUT_EVENT_POINTER_BUTTON: { libinput_event_pointer *ptr_li_event = libinput_event_get_pointer_event(li_event); libinput_button_state btn_state = libinput_event_pointer_get_button_state(ptr_li_event); queue.Push(Event(btn_state == LIBINPUT_BUTTON_STATE_PRESSED ? Event::MOUSE_DOWN : Event::MOUSE_UP, (unsigned) x, (unsigned) y)); } break; case LIBINPUT_EVENT_POINTER_AXIS: { libinput_event_pointer *ptr_li_event = libinput_event_get_pointer_event(li_event); double axis_value = libinput_event_pointer_get_axis_value(ptr_li_event); Event event(Event::MOUSE_WHEEL, (unsigned) x, (unsigned) y); event.param = unsigned((int) axis_value); queue.Push(event); } break; case LIBINPUT_EVENT_TOUCH_DOWN: { libinput_event_touch *touch_li_event = libinput_event_get_touch_event(li_event); x = libinput_event_touch_get_x_transformed(touch_li_event, width); y = libinput_event_touch_get_y_transformed(touch_li_event, height); queue.Push(Event(Event::MOUSE_DOWN, (unsigned) x, (unsigned) y)); } break; case LIBINPUT_EVENT_TOUCH_UP: { queue.Push(Event(Event::MOUSE_UP, (unsigned) x, (unsigned) y)); } break; case LIBINPUT_EVENT_TOUCH_MOTION: { libinput_event_touch *touch_li_event = libinput_event_get_touch_event(li_event); x = libinput_event_touch_get_x_transformed(touch_li_event, width); y = libinput_event_touch_get_y_transformed(touch_li_event, height); queue.Push(Event(Event::MOUSE_MOTION, (unsigned) x, (unsigned) y)); } break; } }