src/video/wayland/SDL_waylandevents.c
changeset 13805 4709c1dfeabb
parent 13701 3cc182fa6110
child 13878 a9b4bd264f3c
     1.1 --- a/src/video/wayland/SDL_waylandevents.c	Mon May 11 14:36:23 2020 -0700
     1.2 +++ b/src/video/wayland/SDL_waylandevents.c	Fri Apr 17 13:55:44 2020 -0400
     1.3 @@ -65,6 +65,7 @@
     1.4      struct wl_keyboard *keyboard;
     1.5      SDL_WaylandDataDevice *data_device;
     1.6      struct zwp_relative_pointer_v1 *relative_pointer;
     1.7 +    struct zwp_confined_pointer_v1 *confined_pointer;
     1.8      SDL_WindowData *pointer_focus;
     1.9      SDL_WindowData *keyboard_focus;
    1.10  
    1.11 @@ -1263,6 +1264,64 @@
    1.12      return 0;
    1.13  }
    1.14  
    1.15 +static void
    1.16 +confined_pointer_confined(void *data,
    1.17 +                          struct zwp_confined_pointer_v1 *confined_pointer)
    1.18 +{
    1.19 +}
    1.20 +
    1.21 +static void
    1.22 +confined_pointer_unconfined(void *data,
    1.23 +                            struct zwp_confined_pointer_v1 *confined_pointer)
    1.24 +{
    1.25 +}
    1.26 +
    1.27 +static const struct zwp_confined_pointer_v1_listener confined_pointer_listener = {
    1.28 +    confined_pointer_confined,
    1.29 +    confined_pointer_unconfined,
    1.30 +};
    1.31 +
    1.32 +int Wayland_input_confine_pointer(SDL_Window *window, struct SDL_WaylandInput *input)
    1.33 +{
    1.34 +    SDL_WindowData *w = window->driverdata;
    1.35 +    SDL_VideoData *d = input->display;
    1.36 +    struct zwp_confined_pointer_v1 *confined_pointer;
    1.37 +
    1.38 +    if (!d->pointer_constraints)
    1.39 +        return -1;
    1.40 +
    1.41 +    if (!input->pointer)
    1.42 +        return -1;
    1.43 +
    1.44 +    /* A confine may already be active, in which case we should destroy it and
    1.45 +     * create a new one. */
    1.46 +    if (input->confined_pointer)
    1.47 +        Wayland_input_unconfine_pointer(input);
    1.48 +
    1.49 +    confined_pointer =
    1.50 +        zwp_pointer_constraints_v1_confine_pointer(d->pointer_constraints,
    1.51 +                                                   w->surface,
    1.52 +                                                   input->pointer,
    1.53 +                                                   NULL,
    1.54 +                                                   ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT);
    1.55 +    zwp_confined_pointer_v1_add_listener(confined_pointer,
    1.56 +                                         &confined_pointer_listener,
    1.57 +                                         window);
    1.58 +
    1.59 +    input->confined_pointer = confined_pointer;
    1.60 +    return 0;
    1.61 +}
    1.62 +
    1.63 +int Wayland_input_unconfine_pointer(struct SDL_WaylandInput *input)
    1.64 +{
    1.65 +    if (input->confined_pointer) {
    1.66 +        zwp_confined_pointer_v1_destroy(input->confined_pointer);
    1.67 +        input->confined_pointer = NULL;
    1.68 +    }
    1.69 +
    1.70 +    return 0;
    1.71 +}
    1.72 +
    1.73  #endif /* SDL_VIDEO_DRIVER_WAYLAND */
    1.74  
    1.75  /* vi: set ts=4 sw=4 expandtab: */