wayland: Send SDL_TOUCH_MOUSEID mouse events for touches.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 05 Dec 2018 16:49:38 -0500
changeset 12455bc838d7a29dc
parent 12454 762a775a58cd
child 12456 f8041c025fd3
wayland: Send SDL_TOUCH_MOUSEID mouse events for touches.
src/video/wayland/SDL_waylandevents.c
src/video/wayland/SDL_waylandwindow.h
     1.1 --- a/src/video/wayland/SDL_waylandevents.c	Wed Dec 05 16:13:12 2018 +0100
     1.2 +++ b/src/video/wayland/SDL_waylandevents.c	Wed Dec 05 16:49:38 2018 -0500
     1.3 @@ -399,15 +399,21 @@
     1.4                     unsigned int timestamp, struct wl_surface *surface,
     1.5                     int id, wl_fixed_t fx, wl_fixed_t fy)
     1.6  {
     1.7 -    float x, y;
     1.8 -    SDL_WindowData* window;
     1.9 -
    1.10 -    window = (SDL_WindowData *)wl_surface_get_user_data(surface);
    1.11 -
    1.12 -    x = wl_fixed_to_double(fx) / window->sdlwindow->w;
    1.13 -    y = wl_fixed_to_double(fy) / window->sdlwindow->h;
    1.14 +    SDL_WindowData *window_data = (SDL_WindowData *)wl_surface_get_user_data(surface);
    1.15 +    const double dblx = wl_fixed_to_double(fx);
    1.16 +    const double dbly = wl_fixed_to_double(fy);
    1.17 +    const float x = dblx / window_data->sdlwindow->w;
    1.18 +    const float y = dbly / window_data->sdlwindow->h;
    1.19  
    1.20      touch_add(id, x, y, surface);
    1.21 +
    1.22 +    if (!window_data->finger_touching) {
    1.23 +        window_data->finger_touching = SDL_TRUE;
    1.24 +        window_data->first_finger = id;
    1.25 +        SDL_SendMouseMotion(window_data->sdlwindow, SDL_TOUCH_MOUSEID, 0, (int) dblx, (int) dbly);
    1.26 +        SDL_SendMouseButton(window_data->sdlwindow, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
    1.27 +    }
    1.28 +
    1.29      SDL_SendTouch(1, (SDL_FingerID)id, SDL_TRUE, x, y, 1.0f);
    1.30  }
    1.31  
    1.32 @@ -415,8 +421,14 @@
    1.33  touch_handler_up(void *data, struct wl_touch *touch, unsigned int serial,
    1.34                   unsigned int timestamp, int id)
    1.35  {
    1.36 +    SDL_WindowData *window_data = (SDL_WindowData *)wl_surface_get_user_data(touch_surface(id));
    1.37      float x = 0, y = 0;
    1.38  
    1.39 +    if ((window_data->finger_touching) && (window_data->first_finger == id)) {
    1.40 +        SDL_SendMouseButton(window_data->sdlwindow, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
    1.41 +        window_data->finger_touching = SDL_FALSE;
    1.42 +    }
    1.43 +
    1.44      touch_del(id, &x, &y);
    1.45      SDL_SendTouch(1, (SDL_FingerID)id, SDL_FALSE, x, y, 0.0f);
    1.46  }
    1.47 @@ -425,13 +437,15 @@
    1.48  touch_handler_motion(void *data, struct wl_touch *touch, unsigned int timestamp,
    1.49                       int id, wl_fixed_t fx, wl_fixed_t fy)
    1.50  {
    1.51 -    float x, y;
    1.52 -    SDL_WindowData* window;
    1.53 +    SDL_WindowData *window_data = (SDL_WindowData *)wl_surface_get_user_data(touch_surface(id));
    1.54 +    const double dblx = wl_fixed_to_double(fx);
    1.55 +    const double dbly = wl_fixed_to_double(fy);
    1.56 +    const float x = dblx / window_data->sdlwindow->w;
    1.57 +    const float y = dbly / window_data->sdlwindow->h;
    1.58  
    1.59 -    window = (SDL_WindowData *)wl_surface_get_user_data(touch_surface(id));
    1.60 -
    1.61 -    x = wl_fixed_to_double(fx) / window->sdlwindow->w;
    1.62 -    y = wl_fixed_to_double(fy) / window->sdlwindow->h;
    1.63 +    if ((window_data->finger_touching) && (window_data->first_finger == id)) {
    1.64 +        SDL_SendMouseMotion(window_data->sdlwindow, SDL_TOUCH_MOUSEID, 0, (int) dblx, (int) dbly);
    1.65 +    }
    1.66  
    1.67      touch_update(id, x, y);
    1.68      SDL_SendTouchMotion(1, (SDL_FingerID)id, x, y, 1.0f);
     2.1 --- a/src/video/wayland/SDL_waylandwindow.h	Wed Dec 05 16:13:12 2018 +0100
     2.2 +++ b/src/video/wayland/SDL_waylandwindow.h	Wed Dec 05 16:49:38 2018 -0500
     2.3 @@ -26,6 +26,7 @@
     2.4  
     2.5  #include "../SDL_sysvideo.h"
     2.6  #include "SDL_syswm.h"
     2.7 +#include "../../events/SDL_touch_c.h"
     2.8  
     2.9  #include "SDL_waylandvideo.h"
    2.10  
    2.11 @@ -74,6 +75,9 @@
    2.12          uint32_t serial;
    2.13          int width, height;
    2.14      } resize;
    2.15 +
    2.16 +    SDL_bool finger_touching;  /* for mapping touch events to mice */
    2.17 +    SDL_FingerID first_finger;
    2.18  } SDL_WindowData;
    2.19  
    2.20  extern void Wayland_ShowWindow(_THIS, SDL_Window *window);