Ejemplo n.º 1
0
static void
handle_pointer_axis(struct libinput_device *libinput_device,
		    struct libinput_event_pointer *pointer_event)
{
	struct evdev_device *device =
		libinput_device_get_user_data(libinput_device);
	double value;
	enum libinput_pointer_axis axis;

	axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
	if (libinput_event_pointer_has_axis(pointer_event, axis)) {
		value = normalize_scroll(pointer_event, axis);
		notify_axis(device->seat,
			    libinput_event_pointer_get_time(pointer_event),
			    WL_POINTER_AXIS_VERTICAL_SCROLL,
			    wl_fixed_from_double(value));
	}

	axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
	if (libinput_event_pointer_has_axis(pointer_event, axis)) {
		value = normalize_scroll(pointer_event, axis);
		notify_axis(device->seat,
			    libinput_event_pointer_get_time(pointer_event),
			    WL_POINTER_AXIS_HORIZONTAL_SCROLL,
			    wl_fixed_from_double(value));
	}
}
Ejemplo n.º 2
0
void CLibInputPointer::ProcessAxis(libinput_event_pointer *e)
{
  unsigned char scroll = 0;
  if (!libinput_event_pointer_has_axis(e, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL))
    return;

  const double v = libinput_event_pointer_get_axis_value(e, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
  if (v < 0)
    scroll = XBMC_BUTTON_WHEELUP;
  else
    scroll = XBMC_BUTTON_WHEELDOWN;

  XBMC_Event event;
  memset(&event, 0, sizeof(event));

  event.type = XBMC_MOUSEBUTTONDOWN;
  event.button.button = scroll;
  event.button.x = static_cast<uint16_t>(m_pos.X);
  event.button.y = static_cast<uint16_t>(m_pos.Y);

  CLog::Log(LOGDEBUG, "CLibInputPointer::%s - scroll: %s, event.button.x: %i, event.button.y: %i", __FUNCTION__, scroll == XBMC_BUTTON_WHEELUP ? "up" : "down", event.button.x, event.button.y);

  std::shared_ptr<CAppInboundProtocol> appPort = CServiceBroker::GetAppPort();
  if (appPort)
    appPort->OnEvent(event);

  event.type = XBMC_MOUSEBUTTONUP;

  if (appPort)
    appPort->OnEvent(event);
}
Ejemplo n.º 3
0
void QLibInputPointer::processAxis(libinput_event_pointer *e)
{
#if QT_LIBINPUT_VERSION_MAJOR == 0 && QT_LIBINPUT_VERSION_MINOR <= 7
    const double v = libinput_event_pointer_get_axis_value(e) * 120;
    const Qt::Orientation ori = libinput_event_pointer_get_axis(e) == LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL
        ? Qt::Vertical : Qt::Horizontal;
    QWindowSystemInterface::handleWheelEvent(Q_NULLPTR, m_pos, m_pos, qRound(-v), ori, QGuiApplication::keyboardModifiers());
#else
    if (libinput_event_pointer_has_axis(e, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) {
        const double v = libinput_event_pointer_get_axis_value(e, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL) * 120;
        QWindowSystemInterface::handleWheelEvent(Q_NULLPTR, m_pos, m_pos, qRound(-v), Qt::Vertical, QGuiApplication::keyboardModifiers());
    }
    if (libinput_event_pointer_has_axis(e, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)) {
        const double v = libinput_event_pointer_get_axis_value(e, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL) * 120;
        QWindowSystemInterface::handleWheelEvent(Q_NULLPTR, m_pos, m_pos, qRound(-v), Qt::Horizontal, QGuiApplication::keyboardModifiers());
    }
#endif
}
Ejemplo n.º 4
0
Archivo: udev.c Proyecto: Azarn/wlc
static int
input_event(int fd, uint32_t mask, void *data)
{
   (void)fd, (void)mask;
   struct input *input = data;

   if (libinput_dispatch(input->handle) != 0)
      wlc_log(WLC_LOG_WARN, "Failed to dispatch libinput");

   struct libinput_event *event;
   while ((event = libinput_get_event(input->handle))) {
      struct libinput *handle = libinput_event_get_context(event);
      struct libinput_device *device = libinput_event_get_device(event);
      (void)handle;

      switch (libinput_event_get_type(event)) {
         case LIBINPUT_EVENT_DEVICE_ADDED:
            WLC_INTERFACE_EMIT(input.created, device);
            break;

         case LIBINPUT_EVENT_DEVICE_REMOVED:
            WLC_INTERFACE_EMIT(input.destroyed, device);
            break;

         case LIBINPUT_EVENT_POINTER_MOTION:
         {
            struct libinput_event_pointer *pev = libinput_event_get_pointer_event(event);
            struct wlc_input_event ev = {0};
            ev.type = WLC_INPUT_EVENT_MOTION;
            ev.time = libinput_event_pointer_get_time(pev);
            ev.motion.dx = libinput_event_pointer_get_dx(pev);
            ev.motion.dy = libinput_event_pointer_get_dy(pev);
            wl_signal_emit(&wlc_system_signals()->input, &ev);
         }
         break;

         case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
         {
            struct libinput_event_pointer *pev = libinput_event_get_pointer_event(event);
            struct wlc_input_event ev = {0};
            ev.type = WLC_INPUT_EVENT_MOTION_ABSOLUTE;
            ev.time = libinput_event_pointer_get_time(pev);
            ev.motion_abs.x = pointer_abs_x;
            ev.motion_abs.y = pointer_abs_y;
            ev.motion_abs.internal = pev;
            wl_signal_emit(&wlc_system_signals()->input, &ev);
         }
         break;

         case LIBINPUT_EVENT_POINTER_BUTTON:
         {
            struct libinput_event_pointer *pev = libinput_event_get_pointer_event(event);
            struct wlc_input_event ev = {0};
            ev.type = WLC_INPUT_EVENT_BUTTON;
            ev.time = libinput_event_pointer_get_time(pev);
            ev.button.code = libinput_event_pointer_get_button(pev);
            ev.button.state = (enum wl_pointer_button_state)libinput_event_pointer_get_button_state(pev);
            wl_signal_emit(&wlc_system_signals()->input, &ev);
         }
         break;

         case LIBINPUT_EVENT_POINTER_AXIS:
         {
            struct libinput_event_pointer *pev = libinput_event_get_pointer_event(event);
            struct wlc_input_event ev = {0};
            ev.type = WLC_INPUT_EVENT_SCROLL;
            ev.time = libinput_event_pointer_get_time(pev);

#if LIBINPUT_VERSION_MAJOR == 0 && LIBINPUT_VERSION_MINOR < 8
            /* < libinput 0.8.x (at least to 0.6.x) */
            const enum wl_pointer_axis axis = libinput_event_pointer_get_axis(pev);
            ev.scroll.amount[(axis == LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)] = libinput_event_pointer_get_axis_value(pev);
            ev.scroll.axis_bits |= (axis == LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL ? WLC_SCROLL_AXIS_HORIZONTAL : WLC_SCROLL_AXIS_VERTICAL);
#else
            /* > libinput 0.8.0 */
            if (libinput_event_pointer_has_axis(pev, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) {
               ev.scroll.amount[0] = libinput_event_pointer_get_axis_value(pev, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
               ev.scroll.axis_bits |= WLC_SCROLL_AXIS_VERTICAL;
            }

            if (libinput_event_pointer_has_axis(pev, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)) {
               ev.scroll.amount[1] = libinput_event_pointer_get_axis_value(pev, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
               ev.scroll.axis_bits |= WLC_SCROLL_AXIS_HORIZONTAL;
            }
#endif

            // We should get other axis information from libinput as well, like source (finger, wheel) (v0.8)
            wl_signal_emit(&wlc_system_signals()->input, &ev);
         }
         break;

         case LIBINPUT_EVENT_KEYBOARD_KEY:
         {
            struct libinput_event_keyboard *kev = libinput_event_get_keyboard_event(event);
            struct wlc_input_event ev = {0};
            ev.type = WLC_INPUT_EVENT_KEY;
            ev.time = libinput_event_keyboard_get_time(kev);
            ev.key.code = libinput_event_keyboard_get_key(kev);
            ev.key.state = (enum wl_keyboard_key_state)libinput_event_keyboard_get_key_state(kev);
            ev.device = device;
            wl_signal_emit(&wlc_system_signals()->input, &ev);
         }
         break;

         case LIBINPUT_EVENT_TOUCH_UP:
         {
            struct libinput_event_touch *tev = libinput_event_get_touch_event(event);
            struct wlc_input_event ev = {0};
            ev.type = WLC_INPUT_EVENT_TOUCH;
            ev.time = libinput_event_touch_get_time(tev);
            ev.touch.type = wlc_touch_type_for_libinput_type(libinput_event_get_type(event));
            ev.touch.slot = libinput_event_touch_get_seat_slot(tev);
            wl_signal_emit(&wlc_system_signals()->input, &ev);
         }
         break;

         case LIBINPUT_EVENT_TOUCH_DOWN:
         case LIBINPUT_EVENT_TOUCH_MOTION:
         {
            struct libinput_event_touch *tev = libinput_event_get_touch_event(event);
            struct wlc_input_event ev = {0};
            ev.type = WLC_INPUT_EVENT_TOUCH;
            ev.time = libinput_event_touch_get_time(tev);
            ev.touch.type = wlc_touch_type_for_libinput_type(libinput_event_get_type(event));
            ev.touch.x = touch_abs_x;
            ev.touch.y = touch_abs_y;
            ev.touch.internal = tev;
            ev.touch.slot = libinput_event_touch_get_seat_slot(tev);
            wl_signal_emit(&wlc_system_signals()->input, &ev);
         }
         break;

         case LIBINPUT_EVENT_TOUCH_FRAME:
         case LIBINPUT_EVENT_TOUCH_CANCEL:
         {
            struct libinput_event_touch *tev = libinput_event_get_touch_event(event);
            struct wlc_input_event ev = {0};
            ev.type = WLC_INPUT_EVENT_TOUCH;
            ev.time = libinput_event_touch_get_time(tev);
            ev.touch.type = wlc_touch_type_for_libinput_type(libinput_event_get_type(event));
            wl_signal_emit(&wlc_system_signals()->input, &ev);
         }
         break;

         default: break;
      }

      libinput_event_destroy(event);
   }

   return 0;
}
Ejemplo n.º 5
0
void LibinputServer::processEvents()
{
    libinput_dispatch(m_libinput);

    while (auto* event = libinput_get_event(m_libinput)) {
        switch (libinput_event_get_type(event)) {
        case LIBINPUT_EVENT_TOUCH_DOWN: 
            if (m_handleTouchEvents)	
                handleTouchEvent(event, Input::TouchEvent::Type::Down);
            break;
        case LIBINPUT_EVENT_TOUCH_UP:	
            if (m_handleTouchEvents)	
                handleTouchEvent(event, Input::TouchEvent::Type::Up);    
            break;
        case LIBINPUT_EVENT_TOUCH_MOTION:
            if (m_handleTouchEvents)	
                handleTouchEvent(event, Input::TouchEvent::Type::Motion);    
            break;        
        case LIBINPUT_EVENT_KEYBOARD_KEY:
        {
            auto* keyEvent = libinput_event_get_keyboard_event(event);

            Input::KeyboardEvent::Raw rawEvent{
                libinput_event_keyboard_get_time(keyEvent),
                libinput_event_keyboard_get_key(keyEvent),
                libinput_event_keyboard_get_key_state(keyEvent)
            };

            Input::KeyboardEventHandler::Result result = m_keyboardEventHandler->handleKeyboardEvent(rawEvent);
            m_client->handleKeyboardEvent({ rawEvent.time, std::get<0>(result), std::get<1>(result), !!rawEvent.state, std::get<2>(result) });

            if (!!rawEvent.state)
                m_keyboardEventRepeating->schedule(rawEvent);
            else
                m_keyboardEventRepeating->cancel();

            break;
        }
        case LIBINPUT_EVENT_POINTER_MOTION:
        {
            if (!m_handlePointerEvents)
                break;

            auto* pointerEvent = libinput_event_get_pointer_event(event);

            double dx = libinput_event_pointer_get_dx(pointerEvent);
            double dy = libinput_event_pointer_get_dy(pointerEvent);
            m_pointerCoords.first = std::min<int32_t>(std::max<uint32_t>(0, m_pointerCoords.first + dx), m_pointerBounds.first - 1);
            m_pointerCoords.second = std::min<int32_t>(std::max<uint32_t>(0, m_pointerCoords.second + dy), m_pointerBounds.second - 1);

            m_client->handlePointerEvent({ Input::PointerEvent::Motion, libinput_event_pointer_get_time(pointerEvent),
                m_pointerCoords.first, m_pointerCoords.second, 0, 0 });
            break;
        }
        case LIBINPUT_EVENT_POINTER_BUTTON:
        {
            if (!m_handlePointerEvents)
                break;

            auto* pointerEvent = libinput_event_get_pointer_event(event);
            m_client->handlePointerEvent({ Input::PointerEvent::Button, libinput_event_pointer_get_time(pointerEvent),
                m_pointerCoords.first, m_pointerCoords.second,
                libinput_event_pointer_get_button(pointerEvent), libinput_event_pointer_get_button_state(pointerEvent) });
            break;
        }
        case LIBINPUT_EVENT_POINTER_AXIS:
        {
            if (!m_handlePointerEvents)
                break;

            auto* pointerEvent = libinput_event_get_pointer_event(event);

            // Support only wheel events for now.
            if (libinput_event_pointer_get_axis_source(pointerEvent) != LIBINPUT_POINTER_AXIS_SOURCE_WHEEL)
                break;

            if (libinput_event_pointer_has_axis(pointerEvent, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) {
                auto axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
                int32_t axisValue = libinput_event_pointer_get_axis_value(pointerEvent, axis);
                m_client->handleAxisEvent({ Input::AxisEvent::Motion, libinput_event_pointer_get_time(pointerEvent),
                    m_pointerCoords.first, m_pointerCoords.second,
                    axis, -axisValue });
            }

            if (libinput_event_pointer_has_axis(pointerEvent, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)) {
                auto axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
                int32_t axisValue = libinput_event_pointer_get_axis_value(pointerEvent, axis);
                m_client->handleAxisEvent({ Input::AxisEvent::Motion, libinput_event_pointer_get_time(pointerEvent),
                    m_pointerCoords.first, m_pointerCoords.second,
                    axis, axisValue });
            }

            break;
        }
        default:
            break;
        }

        libinput_event_destroy(event);
    }
}