src/video/wayland/SDL_waylandevents.c
author Philipp Wiesemann
Thu, 14 Apr 2016 21:11:43 +0200
changeset 10154 fae27a079fcb
parent 10099 c7932bb6dcee
child 10304 ee83e0b4a36f
permissions -rw-r--r--
Wayland: Removed not needed including and setting of errno.

One internal function was setting errno on error but it was not read afterwards.
gabomdq@8062
     1
/*
gabomdq@8062
     2
  Simple DirectMedia Layer
slouken@9998
     3
  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
gabomdq@8062
     4
gabomdq@8062
     5
  This software is provided 'as-is', without any express or implied
gabomdq@8062
     6
  warranty.  In no event will the authors be held liable for any damages
gabomdq@8062
     7
  arising from the use of this software.
gabomdq@8062
     8
gabomdq@8062
     9
  Permission is granted to anyone to use this software for any purpose,
gabomdq@8062
    10
  including commercial applications, and to alter it and redistribute it
gabomdq@8062
    11
  freely, subject to the following restrictions:
gabomdq@8062
    12
gabomdq@8062
    13
  1. The origin of this software must not be misrepresented; you must not
gabomdq@8062
    14
     claim that you wrote the original software. If you use this software
gabomdq@8062
    15
     in a product, an acknowledgment in the product documentation would be
gabomdq@8062
    16
     appreciated but is not required.
gabomdq@8062
    17
  2. Altered source versions must be plainly marked as such, and must not be
gabomdq@8062
    18
     misrepresented as being the original software.
gabomdq@8062
    19
  3. This notice may not be removed or altered from any source distribution.
gabomdq@8062
    20
*/
gabomdq@8062
    21
gabomdq@8104
    22
#include "../../SDL_internal.h"
gabomdq@8062
    23
icculus@8116
    24
#if SDL_VIDEO_DRIVER_WAYLAND
icculus@8116
    25
gabomdq@8062
    26
#include "SDL_stdinc.h"
gabomdq@8062
    27
#include "SDL_assert.h"
gabomdq@8062
    28
gabomdq@8062
    29
#include "../../events/SDL_sysevents.h"
gabomdq@8062
    30
#include "../../events/SDL_events_c.h"
gabomdq@8062
    31
#include "../../events/scancodes_xfree86.h"
gabomdq@8062
    32
gabomdq@8062
    33
#include "SDL_waylandvideo.h"
gabomdq@8062
    34
#include "SDL_waylandevents_c.h"
gabomdq@8062
    35
#include "SDL_waylandwindow.h"
gabomdq@8062
    36
gabomdq@8104
    37
#include "SDL_waylanddyn.h"
gabomdq@8104
    38
gabomdq@8062
    39
#include <linux/input.h>
gabomdq@8062
    40
#include <sys/select.h>
gabomdq@8062
    41
#include <sys/mman.h>
gabomdq@8062
    42
#include <poll.h>
gabomdq@8062
    43
#include <unistd.h>
gabomdq@8062
    44
#include <xkbcommon/xkbcommon.h>
gabomdq@8062
    45
gabomdq@8062
    46
struct SDL_WaylandInput {
gabomdq@8062
    47
    SDL_VideoData *display;
gabomdq@8062
    48
    struct wl_seat *seat;
gabomdq@8062
    49
    struct wl_pointer *pointer;
gabomdq@8062
    50
    struct wl_keyboard *keyboard;
gabomdq@8062
    51
    SDL_WindowData *pointer_focus;
gabomdq@8062
    52
    SDL_WindowData *keyboard_focus;
gabomdq@8062
    53
icculus@9554
    54
    /* Last motion location */
icculus@9554
    55
    wl_fixed_t sx_w;
icculus@9554
    56
    wl_fixed_t sy_w;
icculus@9554
    57
    
gabomdq@8062
    58
    struct {
gabomdq@8062
    59
        struct xkb_keymap *keymap;
gabomdq@8062
    60
        struct xkb_state *state;
gabomdq@8062
    61
    } xkb;
gabomdq@8062
    62
};
gabomdq@8062
    63
gabomdq@8062
    64
void
gabomdq@8062
    65
Wayland_PumpEvents(_THIS)
gabomdq@8062
    66
{
gabomdq@8062
    67
    SDL_VideoData *d = _this->driverdata;
gabomdq@8062
    68
    struct pollfd pfd[1];
gabomdq@8062
    69
gabomdq@8104
    70
    pfd[0].fd = WAYLAND_wl_display_get_fd(d->display);
gabomdq@8062
    71
    pfd[0].events = POLLIN;
gabomdq@8062
    72
    poll(pfd, 1, 0);
gabomdq@8062
    73
gabomdq@8062
    74
    if (pfd[0].revents & POLLIN)
gabomdq@8104
    75
        WAYLAND_wl_display_dispatch(d->display);
gabomdq@8062
    76
    else
gabomdq@8104
    77
        WAYLAND_wl_display_dispatch_pending(d->display);
gabomdq@8062
    78
}
gabomdq@8062
    79
gabomdq@8062
    80
static void
gabomdq@8062
    81
pointer_handle_enter(void *data, struct wl_pointer *pointer,
gabomdq@8062
    82
                     uint32_t serial, struct wl_surface *surface,
gabomdq@8062
    83
                     wl_fixed_t sx_w, wl_fixed_t sy_w)
gabomdq@8062
    84
{
gabomdq@8062
    85
    struct SDL_WaylandInput *input = data;
gabomdq@8062
    86
    SDL_WindowData *window;
gabomdq@8062
    87
gabomdq@8062
    88
    if (!surface) {
gabomdq@8062
    89
        /* enter event for a window we've just destroyed */
gabomdq@8062
    90
        return;
gabomdq@8062
    91
    }
gabomdq@8135
    92
    
gabomdq@8135
    93
    /* This handler will be called twice in Wayland 1.4
gabomdq@8135
    94
     * Once for the window surface which has valid user data
gabomdq@8135
    95
     * and again for the mouse cursor surface which does not have valid user data
gabomdq@8135
    96
     * We ignore the later
gabomdq@8135
    97
     */
gabomdq@8062
    98
gabomdq@8135
    99
    window = (SDL_WindowData *)wl_surface_get_user_data(surface);
gabomdq@8135
   100
    
gabomdq@8135
   101
    if (window) {
gabomdq@8135
   102
        input->pointer_focus = window;
gabomdq@8135
   103
        SDL_SetMouseFocus(window->sdlwindow);
gabomdq@8135
   104
    }
gabomdq@8062
   105
}
gabomdq@8062
   106
gabomdq@8062
   107
static void
gabomdq@8062
   108
pointer_handle_leave(void *data, struct wl_pointer *pointer,
gabomdq@8062
   109
                     uint32_t serial, struct wl_surface *surface)
gabomdq@8062
   110
{
gabomdq@8062
   111
    struct SDL_WaylandInput *input = data;
gabomdq@8062
   112
gabomdq@8135
   113
    if (input->pointer_focus) {
gabomdq@8135
   114
        SDL_SetMouseFocus(NULL);
gabomdq@8135
   115
        input->pointer_focus = NULL;
gabomdq@8135
   116
    }
gabomdq@8062
   117
}
gabomdq@8062
   118
gabomdq@8062
   119
static void
gabomdq@8062
   120
pointer_handle_motion(void *data, struct wl_pointer *pointer,
gabomdq@8062
   121
                      uint32_t time, wl_fixed_t sx_w, wl_fixed_t sy_w)
gabomdq@8062
   122
{
gabomdq@8062
   123
    struct SDL_WaylandInput *input = data;
gabomdq@8062
   124
    SDL_WindowData *window = input->pointer_focus;
icculus@9554
   125
    input->sx_w = sx_w;
icculus@9554
   126
    input->sy_w = sy_w;
gabomdq@8135
   127
    if (input->pointer_focus) {
icculus@9556
   128
        const int sx = wl_fixed_to_int(sx_w);
icculus@9556
   129
        const int sy = wl_fixed_to_int(sy_w);
gabomdq@8135
   130
        SDL_SendMouseMotion(window->sdlwindow, 0, 0, sx, sy);
gabomdq@8135
   131
    }
gabomdq@8062
   132
}
gabomdq@8062
   133
icculus@9554
   134
static SDL_bool
icculus@9554
   135
ProcessHitTest(struct SDL_WaylandInput *input, uint32_t serial)
icculus@9554
   136
{
icculus@9554
   137
    SDL_WindowData *window_data = input->pointer_focus;
icculus@9554
   138
    SDL_Window *window = window_data->sdlwindow;
icculus@9554
   139
icculus@9554
   140
    if (window->hit_test) {
icculus@9554
   141
        const SDL_Point point = { wl_fixed_to_int(input->sx_w), wl_fixed_to_int(input->sy_w) };
icculus@9554
   142
        const SDL_HitTestResult rc = window->hit_test(window, &point, window->hit_test_data);
icculus@9555
   143
        static const uint32_t directions[] = {
icculus@9555
   144
            WL_SHELL_SURFACE_RESIZE_TOP_LEFT, WL_SHELL_SURFACE_RESIZE_TOP,
icculus@9555
   145
            WL_SHELL_SURFACE_RESIZE_TOP_RIGHT, WL_SHELL_SURFACE_RESIZE_RIGHT,
icculus@9555
   146
            WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT, WL_SHELL_SURFACE_RESIZE_BOTTOM,
icculus@9555
   147
            WL_SHELL_SURFACE_RESIZE_BOTTOM_LEFT, WL_SHELL_SURFACE_RESIZE_LEFT
icculus@9555
   148
        };
icculus@9554
   149
        switch (rc) {
icculus@9555
   150
            case SDL_HITTEST_DRAGGABLE:
icculus@9555
   151
                wl_shell_surface_move(window_data->shell_surface, input->seat, serial);
icculus@9555
   152
                return SDL_TRUE;
icculus@9555
   153
icculus@9555
   154
            case SDL_HITTEST_RESIZE_TOPLEFT:
icculus@9555
   155
            case SDL_HITTEST_RESIZE_TOP:
icculus@9555
   156
            case SDL_HITTEST_RESIZE_TOPRIGHT:
icculus@9555
   157
            case SDL_HITTEST_RESIZE_RIGHT:
icculus@9555
   158
            case SDL_HITTEST_RESIZE_BOTTOMRIGHT:
icculus@9555
   159
            case SDL_HITTEST_RESIZE_BOTTOM:
icculus@9555
   160
            case SDL_HITTEST_RESIZE_BOTTOMLEFT:
icculus@9555
   161
            case SDL_HITTEST_RESIZE_LEFT:
icculus@9555
   162
                wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, directions[rc - SDL_HITTEST_RESIZE_TOPLEFT]);
icculus@9555
   163
                return SDL_TRUE;
icculus@9555
   164
icculus@9555
   165
            default: return SDL_FALSE;
icculus@9554
   166
        }
icculus@9554
   167
    }
icculus@9554
   168
icculus@9555
   169
    return SDL_FALSE;
icculus@9554
   170
}
icculus@9554
   171
gabomdq@8062
   172
static void
gabomdq@8062
   173
pointer_handle_button(void *data, struct wl_pointer *pointer, uint32_t serial,
gabomdq@8062
   174
                      uint32_t time, uint32_t button, uint32_t state_w)
gabomdq@8062
   175
{
gabomdq@8062
   176
    struct SDL_WaylandInput *input = data;
gabomdq@8062
   177
    SDL_WindowData *window = input->pointer_focus;
gabomdq@8062
   178
    enum wl_pointer_button_state state = state_w;
gabomdq@8062
   179
    uint32_t sdl_button;
gabomdq@8135
   180
    
gabomdq@8135
   181
    if  (input->pointer_focus) {
gabomdq@8135
   182
        switch (button) {
gabomdq@8135
   183
            case BTN_LEFT:
gabomdq@8135
   184
                sdl_button = SDL_BUTTON_LEFT;
icculus@9554
   185
                if (ProcessHitTest(data, serial)) {
icculus@9554
   186
                    return;  /* don't pass this event on to app. */
icculus@9554
   187
                }
gabomdq@8135
   188
                break;
gabomdq@8135
   189
            case BTN_MIDDLE:
gabomdq@8135
   190
                sdl_button = SDL_BUTTON_MIDDLE;
gabomdq@8135
   191
                break;
gabomdq@8135
   192
            case BTN_RIGHT:
gabomdq@8135
   193
                sdl_button = SDL_BUTTON_RIGHT;
gabomdq@8135
   194
                break;
gabomdq@8135
   195
            case BTN_SIDE:
gabomdq@8135
   196
                sdl_button = SDL_BUTTON_X1;
gabomdq@8135
   197
                break;
gabomdq@8135
   198
            case BTN_EXTRA:
gabomdq@8135
   199
                sdl_button = SDL_BUTTON_X2;
gabomdq@8135
   200
                break;
gabomdq@8135
   201
            default:
gabomdq@8135
   202
                return;
gabomdq@8135
   203
        }
gabomdq@8062
   204
gabomdq@8135
   205
        SDL_SendMouseButton(window->sdlwindow, 0,
gabomdq@8135
   206
                            state ? SDL_PRESSED : SDL_RELEASED, sdl_button);
gabomdq@8062
   207
    }
gabomdq@8062
   208
}
gabomdq@8062
   209
gabomdq@8062
   210
static void
gabomdq@8062
   211
pointer_handle_axis(void *data, struct wl_pointer *pointer,
gabomdq@8062
   212
                    uint32_t time, uint32_t axis, wl_fixed_t value)
gabomdq@8062
   213
{
gabomdq@8062
   214
    struct SDL_WaylandInput *input = data;
gabomdq@8062
   215
    SDL_WindowData *window = input->pointer_focus;
gabomdq@8062
   216
    enum wl_pointer_axis a = axis;
gabomdq@8062
   217
    int x, y;
gabomdq@8062
   218
gabomdq@8135
   219
    if (input->pointer_focus) {
gabomdq@8135
   220
        switch (a) {
gabomdq@8135
   221
            case WL_POINTER_AXIS_VERTICAL_SCROLL:
gabomdq@8135
   222
                x = 0;
gabomdq@8135
   223
                y = wl_fixed_to_int(value);
gabomdq@8135
   224
                break;
gabomdq@8135
   225
            case WL_POINTER_AXIS_HORIZONTAL_SCROLL:
gabomdq@8135
   226
                x = wl_fixed_to_int(value);
gabomdq@8135
   227
                y = 0;
gabomdq@8135
   228
                break;
gabomdq@8135
   229
            default:
gabomdq@8135
   230
                return;
gabomdq@8135
   231
        }
gabomdq@8135
   232
urkle@9257
   233
        SDL_SendMouseWheel(window->sdlwindow, 0, x, y, SDL_MOUSEWHEEL_NORMAL);
gabomdq@8062
   234
    }
gabomdq@8062
   235
}
gabomdq@8062
   236
gabomdq@8062
   237
static const struct wl_pointer_listener pointer_listener = {
gabomdq@8062
   238
    pointer_handle_enter,
gabomdq@8062
   239
    pointer_handle_leave,
gabomdq@8062
   240
    pointer_handle_motion,
gabomdq@8062
   241
    pointer_handle_button,
gabomdq@8062
   242
    pointer_handle_axis,
gabomdq@8062
   243
};
gabomdq@8062
   244
gabomdq@8062
   245
static void
gabomdq@8062
   246
keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
gabomdq@8062
   247
                       uint32_t format, int fd, uint32_t size)
gabomdq@8062
   248
{
gabomdq@8062
   249
    struct SDL_WaylandInput *input = data;
gabomdq@8062
   250
    char *map_str;
gabomdq@8062
   251
gabomdq@8062
   252
    if (!data) {
gabomdq@8062
   253
        close(fd);
gabomdq@8062
   254
        return;
gabomdq@8062
   255
    }
gabomdq@8062
   256
gabomdq@8062
   257
    if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
gabomdq@8062
   258
        close(fd);
gabomdq@8062
   259
        return;
gabomdq@8062
   260
    }
gabomdq@8062
   261
gabomdq@8062
   262
    map_str = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
gabomdq@8062
   263
    if (map_str == MAP_FAILED) {
gabomdq@8062
   264
        close(fd);
gabomdq@8062
   265
        return;
gabomdq@8062
   266
    }
gabomdq@8062
   267
gabomdq@8104
   268
    input->xkb.keymap = WAYLAND_xkb_keymap_new_from_string(input->display->xkb_context,
gabomdq@8062
   269
                                                map_str,
gabomdq@8062
   270
                                                XKB_KEYMAP_FORMAT_TEXT_V1,
gabomdq@8062
   271
                                                0);
gabomdq@8062
   272
    munmap(map_str, size);
gabomdq@8062
   273
    close(fd);
gabomdq@8062
   274
gabomdq@8062
   275
    if (!input->xkb.keymap) {
gabomdq@8062
   276
        fprintf(stderr, "failed to compile keymap\n");
gabomdq@8062
   277
        return;
gabomdq@8062
   278
    }
gabomdq@8062
   279
gabomdq@8104
   280
    input->xkb.state = WAYLAND_xkb_state_new(input->xkb.keymap);
gabomdq@8062
   281
    if (!input->xkb.state) {
gabomdq@8062
   282
        fprintf(stderr, "failed to create XKB state\n");
gabomdq@8104
   283
        WAYLAND_xkb_keymap_unref(input->xkb.keymap);
gabomdq@8062
   284
        input->xkb.keymap = NULL;
gabomdq@8062
   285
        return;
gabomdq@8062
   286
    }
gabomdq@8062
   287
}
gabomdq@8062
   288
gabomdq@8062
   289
static void
gabomdq@8062
   290
keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,
gabomdq@8062
   291
                      uint32_t serial, struct wl_surface *surface,
gabomdq@8062
   292
                      struct wl_array *keys)
gabomdq@8062
   293
{
gabomdq@8062
   294
    struct SDL_WaylandInput *input = data;
icculus@9656
   295
    SDL_WindowData *window;
icculus@9655
   296
icculus@9655
   297
    if (!surface) {
icculus@9655
   298
        /* enter event for a window we've just destroyed */
icculus@9655
   299
        return;
icculus@9655
   300
    }
icculus@9655
   301
 
icculus@9656
   302
    window = wl_surface_get_user_data(surface);
gabomdq@8062
   303
gabomdq@8135
   304
    if (window) {
philipp@10099
   305
        input->keyboard_focus = window;
philipp@10099
   306
        window->keyboard_device = input;
gabomdq@8135
   307
        SDL_SetKeyboardFocus(window->sdlwindow);
gabomdq@8135
   308
    }
gabomdq@8062
   309
}
gabomdq@8062
   310
gabomdq@8062
   311
static void
gabomdq@8062
   312
keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,
gabomdq@8062
   313
                      uint32_t serial, struct wl_surface *surface)
gabomdq@8062
   314
{
gabomdq@8062
   315
    SDL_SetKeyboardFocus(NULL);
gabomdq@8062
   316
}
gabomdq@8062
   317
gabomdq@8062
   318
static void
gabomdq@8062
   319
keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
gabomdq@8062
   320
                    uint32_t serial, uint32_t time, uint32_t key,
gabomdq@8062
   321
                    uint32_t state_w)
gabomdq@8062
   322
{
gabomdq@8062
   323
    struct SDL_WaylandInput *input = data;
gabomdq@8062
   324
    SDL_WindowData *window = input->keyboard_focus;
gabomdq@8062
   325
    enum wl_keyboard_key_state state = state_w;
gabomdq@8062
   326
    const xkb_keysym_t *syms;
gabomdq@8062
   327
    uint32_t scancode;
gabomdq@8062
   328
    char text[8];
gabomdq@8062
   329
    int size;
gabomdq@8062
   330
gabomdq@8062
   331
    if (key < SDL_arraysize(xfree86_scancode_table2)) {
gabomdq@8062
   332
        scancode = xfree86_scancode_table2[key];
gabomdq@8062
   333
gabomdq@8062
   334
        // TODO when do we get WL_KEYBOARD_KEY_STATE_REPEAT?
gabomdq@8062
   335
        if (scancode != SDL_SCANCODE_UNKNOWN)
gabomdq@8062
   336
            SDL_SendKeyboardKey(state == WL_KEYBOARD_KEY_STATE_PRESSED ?
gabomdq@8062
   337
                                SDL_PRESSED : SDL_RELEASED, scancode);
gabomdq@8062
   338
    }
gabomdq@8062
   339
gabomdq@8062
   340
    if (!window || window->keyboard_device != input || !input->xkb.state)
gabomdq@8062
   341
        return;
gabomdq@8062
   342
gabomdq@8062
   343
    // TODO can this happen?
gabomdq@8104
   344
    if (WAYLAND_xkb_state_key_get_syms(input->xkb.state, key + 8, &syms) != 1)
gabomdq@8062
   345
        return;
gabomdq@8062
   346
gabomdq@8062
   347
    if (state) {
gabomdq@8104
   348
        size = WAYLAND_xkb_keysym_to_utf8(syms[0], text, sizeof text);
gabomdq@8062
   349
gabomdq@8062
   350
        if (size > 0) {
gabomdq@8062
   351
            text[size] = 0;
gabomdq@8062
   352
            SDL_SendKeyboardText(text);
gabomdq@8062
   353
        }
gabomdq@8062
   354
    }
gabomdq@8062
   355
}
gabomdq@8062
   356
gabomdq@8062
   357
static void
gabomdq@8062
   358
keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard,
gabomdq@8062
   359
                          uint32_t serial, uint32_t mods_depressed,
gabomdq@8062
   360
                          uint32_t mods_latched, uint32_t mods_locked,
gabomdq@8062
   361
                          uint32_t group)
gabomdq@8062
   362
{
gabomdq@8062
   363
    struct SDL_WaylandInput *input = data;
gabomdq@8062
   364
gabomdq@8104
   365
    WAYLAND_xkb_state_update_mask(input->xkb.state, mods_depressed, mods_latched,
gabomdq@8062
   366
                          mods_locked, 0, 0, group);
gabomdq@8062
   367
}
gabomdq@8062
   368
gabomdq@8062
   369
static const struct wl_keyboard_listener keyboard_listener = {
gabomdq@8062
   370
    keyboard_handle_keymap,
gabomdq@8062
   371
    keyboard_handle_enter,
gabomdq@8062
   372
    keyboard_handle_leave,
gabomdq@8062
   373
    keyboard_handle_key,
gabomdq@8062
   374
    keyboard_handle_modifiers,
gabomdq@8062
   375
};
gabomdq@8062
   376
gabomdq@8062
   377
static void
gabomdq@8062
   378
seat_handle_capabilities(void *data, struct wl_seat *seat,
gabomdq@8062
   379
                         enum wl_seat_capability caps)
gabomdq@8062
   380
{
gabomdq@8062
   381
    struct SDL_WaylandInput *input = data;
gabomdq@8062
   382
gabomdq@8062
   383
    if ((caps & WL_SEAT_CAPABILITY_POINTER) && !input->pointer) {
gabomdq@8062
   384
        input->pointer = wl_seat_get_pointer(seat);
gabomdq@8062
   385
        input->display->pointer = input->pointer;
gabomdq@8062
   386
        wl_pointer_set_user_data(input->pointer, input);
gabomdq@8062
   387
        wl_pointer_add_listener(input->pointer, &pointer_listener,
gabomdq@8062
   388
                                input);
gabomdq@8062
   389
    } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->pointer) {
gabomdq@8062
   390
        wl_pointer_destroy(input->pointer);
gabomdq@8062
   391
        input->pointer = NULL;
gabomdq@8062
   392
    }
gabomdq@8062
   393
gabomdq@8062
   394
    if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !input->keyboard) {
gabomdq@8062
   395
        input->keyboard = wl_seat_get_keyboard(seat);
gabomdq@8062
   396
        wl_keyboard_set_user_data(input->keyboard, input);
gabomdq@8062
   397
        wl_keyboard_add_listener(input->keyboard, &keyboard_listener,
gabomdq@8062
   398
                                 input);
gabomdq@8062
   399
    } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && input->keyboard) {
gabomdq@8062
   400
        wl_keyboard_destroy(input->keyboard);
gabomdq@8062
   401
        input->keyboard = NULL;
gabomdq@8062
   402
    }
gabomdq@8062
   403
}
gabomdq@8062
   404
gabomdq@8062
   405
static const struct wl_seat_listener seat_listener = {
gabomdq@8062
   406
    seat_handle_capabilities,
gabomdq@8062
   407
};
gabomdq@8062
   408
gabomdq@8062
   409
void
gabomdq@8062
   410
Wayland_display_add_input(SDL_VideoData *d, uint32_t id)
gabomdq@8062
   411
{
gabomdq@8062
   412
    struct SDL_WaylandInput *input;
gabomdq@8062
   413
gabomdq@8135
   414
    input = SDL_calloc(1, sizeof *input);
gabomdq@8062
   415
    if (input == NULL)
gabomdq@8062
   416
        return;
gabomdq@8062
   417
gabomdq@8062
   418
    input->display = d;
gabomdq@8062
   419
    input->seat = wl_registry_bind(d->registry, id, &wl_seat_interface, 1);
icculus@9554
   420
    input->sx_w = wl_fixed_from_int(0);
icculus@9554
   421
    input->sy_w = wl_fixed_from_int(0);
gabomdq@8062
   422
    d->input = input;
gabomdq@8062
   423
gabomdq@8062
   424
    wl_seat_add_listener(input->seat, &seat_listener, input);
gabomdq@8062
   425
    wl_seat_set_user_data(input->seat, input);
gabomdq@8062
   426
gabomdq@8104
   427
    WAYLAND_wl_display_flush(d->display);
gabomdq@8062
   428
}
gabomdq@8062
   429
gabomdq@8062
   430
void Wayland_display_destroy_input(SDL_VideoData *d)
gabomdq@8062
   431
{
gabomdq@8062
   432
    struct SDL_WaylandInput *input = d->input;
gabomdq@8062
   433
gabomdq@8062
   434
    if (!input)
gabomdq@8062
   435
        return;
gabomdq@8062
   436
gabomdq@8062
   437
    if (input->keyboard)
gabomdq@8062
   438
        wl_keyboard_destroy(input->keyboard);
gabomdq@8062
   439
gabomdq@8062
   440
    if (input->pointer)
gabomdq@8062
   441
        wl_pointer_destroy(input->pointer);
gabomdq@8062
   442
gabomdq@8062
   443
    if (input->seat)
gabomdq@8062
   444
        wl_seat_destroy(input->seat);
gabomdq@8062
   445
gabomdq@8062
   446
    if (input->xkb.state)
gabomdq@8104
   447
        WAYLAND_xkb_state_unref(input->xkb.state);
gabomdq@8062
   448
gabomdq@8062
   449
    if (input->xkb.keymap)
gabomdq@8104
   450
        WAYLAND_xkb_keymap_unref(input->xkb.keymap);
gabomdq@8062
   451
gabomdq@8135
   452
    SDL_free(input);
gabomdq@8062
   453
    d->input = NULL;
gabomdq@8062
   454
}
gabomdq@8062
   455
icculus@8116
   456
#endif /* SDL_VIDEO_DRIVER_WAYLAND */
icculus@8116
   457
gabomdq@8062
   458
/* vi: set ts=4 sw=4 expandtab: */