src/video/wayland/SDL_waylandwindow.c
author Gabriel Jacobo <gabomdq@gmail.com>
Thu, 09 Jan 2014 13:56:21 -0300
changeset 8104 2e4f1bd21196
parent 8082 5b83ad3f01ac
child 8116 f7c2f71251e5
permissions -rw-r--r--
Dynamic loading support for Wayland
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
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
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: 8082
diff changeset
    22
#include "../../SDL_internal.h"
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    23
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    24
#include "../SDL_sysvideo.h"
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    25
#include "../../events/SDL_windowevents_c.h"
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    26
#include "../SDL_egl_c.h"
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    27
#include "SDL_waylandwindow.h"
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    28
#include "SDL_waylandvideo.h"
8082
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    29
#include "SDL_waylandtouch.h"
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    30
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    31
static void
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    32
handle_ping(void *data, struct wl_shell_surface *shell_surface,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    33
            uint32_t serial)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    34
{
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    35
    wl_shell_surface_pong(shell_surface, serial);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    36
}
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    37
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    38
static void
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    39
handle_configure(void *data, struct wl_shell_surface *shell_surface,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    40
                 uint32_t edges, int32_t width, int32_t height)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    41
{
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    42
}
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    43
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    44
static void
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    45
handle_popup_done(void *data, struct wl_shell_surface *shell_surface)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    46
{
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    47
}
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    48
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    49
static const struct wl_shell_surface_listener shell_surface_listener = {
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    50
    handle_ping,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    51
    handle_configure,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    52
    handle_popup_done
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    53
};
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    54
8082
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    55
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    56
static void
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    57
handle_onscreen_visibility(void *data,
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    58
        struct qt_extended_surface *qt_extended_surface, int32_t visible)
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    59
{
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    60
}
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    61
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    62
static void
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    63
handle_set_generic_property(void *data,
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    64
        struct qt_extended_surface *qt_extended_surface, const char *name,
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    65
        struct wl_array *value)
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    66
{
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    67
}
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    68
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    69
static void
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    70
handle_close(void *data, struct qt_extended_surface *qt_extended_surface)
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    71
{
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    72
    SDL_WindowData *window = (SDL_WindowData *)data;
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    73
    SDL_SendWindowEvent(window->sdlwindow, SDL_WINDOWEVENT_CLOSE, 0, 0);
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    74
}
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    75
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    76
static const struct qt_extended_surface_listener extended_surface_listener = {
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    77
    handle_onscreen_visibility,
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    78
    handle_set_generic_property,
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    79
    handle_close,
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    80
};
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    81
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    82
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    83
SDL_bool
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    84
Wayland_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    85
{
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    86
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    87
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    88
    info->info.wl.display = data->waylandData->display;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    89
    info->info.wl.surface = data->surface;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    90
    info->info.wl.shell_surface = data->shell_surface;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    91
    info->subsystem = SDL_SYSWM_WAYLAND;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    92
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    93
    return SDL_TRUE;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    94
}
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    95
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    96
void Wayland_ShowWindow(_THIS, SDL_Window *window)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    97
{
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    98
    SDL_WindowData *wind = window->driverdata;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    99
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   100
    if (window->flags & SDL_WINDOW_FULLSCREEN)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   101
        wl_shell_surface_set_fullscreen(wind->shell_surface,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   102
                                        WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   103
                                        0, NULL);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   104
    else
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   105
        wl_shell_surface_set_toplevel(wind->shell_surface);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   106
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
   107
    WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   108
}
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   109
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   110
void
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   111
Wayland_SetWindowFullscreen(_THIS, SDL_Window * window,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   112
                            SDL_VideoDisplay * _display, SDL_bool fullscreen)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   113
{
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   114
    SDL_WindowData *wind = window->driverdata;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   115
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   116
    if (fullscreen)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   117
        wl_shell_surface_set_fullscreen(wind->shell_surface,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   118
                                        WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   119
                                        0, NULL);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   120
    else
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   121
        wl_shell_surface_set_toplevel(wind->shell_surface);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   122
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
   123
    WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   124
}
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   125
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   126
int Wayland_CreateWindow(_THIS, SDL_Window *window)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   127
{
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   128
    SDL_WindowData *data;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   129
    SDL_VideoData *c;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   130
    struct wl_region *region;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   131
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   132
    data = calloc(1, sizeof *data);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   133
    if (data == NULL)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   134
        return 0;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   135
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   136
    c = _this->driverdata;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   137
    window->driverdata = data;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   138
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   139
    if (!(window->flags & SDL_WINDOW_OPENGL)) {
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   140
        SDL_GL_LoadLibrary(NULL);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   141
        window->flags |= SDL_WINDOW_OPENGL;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   142
    }
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   143
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   144
    if (window->x == SDL_WINDOWPOS_UNDEFINED) {
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   145
        window->x = 0;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   146
    }
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   147
    if (window->y == SDL_WINDOWPOS_UNDEFINED) {
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   148
        window->y = 0;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   149
    }
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   150
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   151
    data->waylandData = c;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   152
    data->sdlwindow = window;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   153
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   154
    data->surface =
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   155
        wl_compositor_create_surface(c->compositor);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   156
    wl_surface_set_user_data(data->surface, data);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   157
    data->shell_surface = wl_shell_get_shell_surface(c->shell,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   158
                                                     data->surface);
8082
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   159
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH    
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   160
    if (c->surface_extension) {
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   161
        data->extended_surface = qt_surface_extension_get_extended_surface(
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   162
                c->surface_extension, data->surface);
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   163
    }
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   164
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
   165
    data->egl_window = WAYLAND_wl_egl_window_create(data->surface,
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   166
                                            window->w, window->h);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   167
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   168
    /* Create the GLES window surface */
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   169
    data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->egl_window);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   170
    
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   171
    if (data->egl_surface == EGL_NO_SURFACE) {
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   172
        SDL_SetError("failed to create a window surface");
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   173
        return -1;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   174
    }
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   175
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   176
    if (data->shell_surface) {
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   177
        wl_shell_surface_set_user_data(data->shell_surface, data);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   178
        wl_shell_surface_add_listener(data->shell_surface,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   179
                                      &shell_surface_listener, data);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   180
    }
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   181
8082
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   182
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   183
    if (data->extended_surface) {
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   184
        qt_extended_surface_set_user_data(data->extended_surface, data);
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   185
        qt_extended_surface_add_listener(data->extended_surface,
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   186
                                         &extended_surface_listener, data);
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   187
    }
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   188
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   189
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   190
    region = wl_compositor_create_region(c->compositor);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   191
    wl_region_add(region, 0, 0, window->w, window->h);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   192
    wl_surface_set_opaque_region(data->surface, region);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   193
    wl_region_destroy(region);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   194
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
   195
    WAYLAND_wl_display_flush(c->display);
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   196
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   197
    return 0;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   198
}
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   199
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   200
void Wayland_SetWindowSize(_THIS, SDL_Window * window)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   201
{
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   202
    SDL_VideoData *data = _this->driverdata;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   203
    SDL_WindowData *wind = window->driverdata;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   204
    struct wl_region *region;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   205
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
   206
    WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   207
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
   208
    region =wl_compositor_create_region(data->compositor);
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   209
    wl_region_add(region, 0, 0, window->w, window->h);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   210
    wl_surface_set_opaque_region(wind->surface, region);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   211
    wl_region_destroy(region);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   212
}
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   213
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   214
void Wayland_DestroyWindow(_THIS, SDL_Window *window)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   215
{
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   216
    SDL_VideoData *data = _this->driverdata;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   217
    SDL_WindowData *wind = window->driverdata;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   218
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   219
    window->driverdata = NULL;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   220
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   221
    if (data) {
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   222
        SDL_EGL_DestroySurface(_this, wind->egl_surface);
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
   223
        WAYLAND_wl_egl_window_destroy(wind->egl_window);
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   224
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   225
        if (wind->shell_surface)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   226
            wl_shell_surface_destroy(wind->shell_surface);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   227
8082
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   228
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   229
        if (wind->extended_surface)
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   230
            qt_extended_surface_destroy(wind->extended_surface);
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   231
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   232
        wl_surface_destroy(wind->surface);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   233
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   234
        SDL_free(wind);
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
   235
        WAYLAND_wl_display_flush(data->display);
8062
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
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   239
/* vi: set ts=4 sw=4 expandtab: */