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