Handle touch events on wayland device

This commit is contained in:
Deve 2019-01-08 22:31:37 +01:00
parent ec91f9d8db
commit 8257d9eeee
4 changed files with 98 additions and 21 deletions

View File

@ -74,6 +74,7 @@ public:
static const wl_pointer_listener pointer_listener; static const wl_pointer_listener pointer_listener;
static const wl_seat_listener seat_listener; static const wl_seat_listener seat_listener;
static const wl_keyboard_listener keyboard_listener; static const wl_keyboard_listener keyboard_listener;
static const wl_touch_listener touch_listener;
static const wl_output_listener output_listener; static const wl_output_listener output_listener;
static const wl_shell_surface_listener shell_surface_listener; static const wl_shell_surface_listener shell_surface_listener;
static const wl_registry_listener registry_listener; static const wl_registry_listener registry_listener;
@ -436,6 +437,60 @@ public:
device->m_repeat_delay = delay; device->m_repeat_delay = delay;
} }
static void touch_handle_down(void* data, wl_touch* touch, uint32_t serial,
uint32_t time, wl_surface *surface,
int32_t id, wl_fixed_t x, wl_fixed_t y)
{
CIrrDeviceWayland* device = static_cast<CIrrDeviceWayland*>(data);
SEvent event;
event.EventType = EET_TOUCH_INPUT_EVENT;
event.TouchInput.Event = ETIE_PRESSED_DOWN;
event.TouchInput.ID = id;
event.TouchInput.X = wl_fixed_to_int(x);
event.TouchInput.Y = wl_fixed_to_int(y);
device->signalEvent(event);
}
static void touch_handle_up(void* data, wl_touch* touch, uint32_t serial,
uint32_t time, int32_t id)
{
CIrrDeviceWayland* device = static_cast<CIrrDeviceWayland*>(data);
SEvent event;
event.EventType = EET_TOUCH_INPUT_EVENT;
event.TouchInput.Event = ETIE_LEFT_UP;
event.TouchInput.ID = id;
event.TouchInput.X = 0;
event.TouchInput.Y = 0;
device->signalEvent(event);
}
static void touch_handle_motion(void* data, wl_touch* touch, uint32_t time,
int32_t id, wl_fixed_t x, wl_fixed_t y)
{
CIrrDeviceWayland* device = static_cast<CIrrDeviceWayland*>(data);
SEvent event;
event.EventType = EET_TOUCH_INPUT_EVENT;
event.TouchInput.Event = ETIE_MOVED;
event.TouchInput.ID = id;
event.TouchInput.X = wl_fixed_to_int(x);
event.TouchInput.Y = wl_fixed_to_int(y);
device->signalEvent(event);
}
static void touch_handle_frame(void* data, wl_touch* touch)
{
}
static void touch_handle_cancel(void* data, wl_touch* touch)
{
}
static void seat_capabilities(void* data, wl_seat* seat, uint32_t caps) static void seat_capabilities(void* data, wl_seat* seat, uint32_t caps)
{ {
CIrrDeviceWayland* device = static_cast<CIrrDeviceWayland*>(data); CIrrDeviceWayland* device = static_cast<CIrrDeviceWayland*>(data);
@ -462,6 +517,18 @@ public:
wl_keyboard_destroy(device->m_keyboard); wl_keyboard_destroy(device->m_keyboard);
device->m_keyboard = NULL; device->m_keyboard = NULL;
} }
if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !device->m_touch)
{
device->m_touch = wl_seat_get_touch(seat);
wl_touch_add_listener(device->m_touch, &touch_listener,
device);
}
else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && device->m_touch)
{
wl_touch_destroy(device->m_touch);
device->m_touch = NULL;
}
} }
static void seat_name(void* data, wl_seat* wl_seat, const char* name) static void seat_name(void* data, wl_seat* wl_seat, const char* name)
@ -645,6 +712,15 @@ const wl_keyboard_listener WaylandCallbacks::keyboard_listener =
WaylandCallbacks::keyboard_repeat_info WaylandCallbacks::keyboard_repeat_info
}; };
const wl_touch_listener WaylandCallbacks::touch_listener =
{
WaylandCallbacks::touch_handle_down,
WaylandCallbacks::touch_handle_up,
WaylandCallbacks::touch_handle_motion,
WaylandCallbacks::touch_handle_frame,
WaylandCallbacks::touch_handle_cancel
};
const wl_seat_listener WaylandCallbacks::seat_listener = const wl_seat_listener WaylandCallbacks::seat_listener =
{ {
WaylandCallbacks::seat_capabilities, WaylandCallbacks::seat_capabilities,

View File

@ -169,6 +169,7 @@ namespace irr
wl_display* m_display; wl_display* m_display;
wl_egl_window* m_egl_window; wl_egl_window* m_egl_window;
wl_keyboard* m_keyboard; wl_keyboard* m_keyboard;
wl_touch* m_touch;
wl_output* m_output; wl_output* m_output;
wl_pointer* m_pointer; wl_pointer* m_pointer;
wl_registry* m_registry; wl_registry* m_registry;

View File

@ -479,7 +479,7 @@ namespace UserConfigParams
"Settings for the multitouch device") ); "Settings for the multitouch device") );
PARAM_PREFIX BoolUserConfigParam m_multitouch_enabled PARAM_PREFIX BoolUserConfigParam m_multitouch_enabled
PARAM_DEFAULT( BoolUserConfigParam(false, "multitouch_enabled", PARAM_DEFAULT( BoolUserConfigParam(true, "multitouch_enabled",
&m_multitouch_group, &m_multitouch_group,
"Enable multitouch support.") ); "Enable multitouch support.") );

View File

@ -1234,29 +1234,29 @@ EventPropagation InputManager::input(const SEvent& event)
} }
// Simulate touch event on non-android devices // Simulate touch event on non-android devices
#if !defined(ANDROID) //~ #if !defined(ANDROID)
MultitouchDevice* device = m_device_manager->getMultitouchDevice(); //~ MultitouchDevice* device = m_device_manager->getMultitouchDevice();
if (device != NULL && (type == EMIE_LMOUSE_PRESSED_DOWN || //~ if (device != NULL && (type == EMIE_LMOUSE_PRESSED_DOWN ||
type == EMIE_LMOUSE_LEFT_UP || type == EMIE_MOUSE_MOVED)) //~ type == EMIE_LMOUSE_LEFT_UP || type == EMIE_MOUSE_MOVED))
{ //~ {
device->m_events[0].id = 0; //~ device->m_events[0].id = 0;
device->m_events[0].x = event.MouseInput.X; //~ device->m_events[0].x = event.MouseInput.X;
device->m_events[0].y = event.MouseInput.Y; //~ device->m_events[0].y = event.MouseInput.Y;
if (type == EMIE_LMOUSE_PRESSED_DOWN) //~ if (type == EMIE_LMOUSE_PRESSED_DOWN)
{ //~ {
device->m_events[0].touched = true; //~ device->m_events[0].touched = true;
} //~ }
else if (type == EMIE_LMOUSE_LEFT_UP) //~ else if (type == EMIE_LMOUSE_LEFT_UP)
{ //~ {
device->m_events[0].touched = false; //~ device->m_events[0].touched = false;
} //~ }
m_device_manager->updateMultitouchDevice(); //~ m_device_manager->updateMultitouchDevice();
device->updateDeviceState(0); //~ device->updateDeviceState(0);
} //~ }
#endif //~ #endif
/* /*
EMIE_LMOUSE_PRESSED_DOWN Left mouse button was pressed down. EMIE_LMOUSE_PRESSED_DOWN Left mouse button was pressed down.