src/video/wayland/SDL_waylandwindow.c
author Gabriel Jacobo <gabomdq@gmail.com>
Sat, 10 May 2014 16:50:05 -0300
changeset 8766 e5f584f77609
parent 8712 e33b5f7df761
child 8978 7753e4fd3d1d
permissions -rw-r--r--
Fixes #2512, handle configuration change messages sent by Wayland. Patch by Bryan Cain.
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
8149
681eb46b8ac4 Fixed bug 2374 - Update copyright for 2014...
Sam Lantinga <slouken@libsdl.org>
parents: 8116
diff changeset
     3
  Copyright (C) 1997-2014 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: 8082
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 && SDL_VIDEO_OPENGL_EGL
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_sysvideo.h"
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    27
#include "../../events/SDL_windowevents_c.h"
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    28
#include "../SDL_egl_c.h"
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    29
#include "SDL_waylandwindow.h"
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    30
#include "SDL_waylandvideo.h"
8082
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    31
#include "SDL_waylandtouch.h"
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    32
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    33
static void
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    34
handle_ping(void *data, struct wl_shell_surface *shell_surface,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    35
            uint32_t 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
    wl_shell_surface_pong(shell_surface, serial);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    38
}
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    39
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    40
static void
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    41
handle_configure(void *data, struct wl_shell_surface *shell_surface,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    42
                 uint32_t edges, int32_t width, int32_t height)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    43
{
8766
e5f584f77609 Fixes #2512, handle configuration change messages sent by Wayland. Patch by Bryan Cain.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8712
diff changeset
    44
    SDL_WindowData *wind = (SDL_WindowData *)data;
e5f584f77609 Fixes #2512, handle configuration change messages sent by Wayland. Patch by Bryan Cain.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8712
diff changeset
    45
    SDL_Window *window = wind->sdlwindow;
e5f584f77609 Fixes #2512, handle configuration change messages sent by Wayland. Patch by Bryan Cain.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8712
diff changeset
    46
    struct wl_region *region;
e5f584f77609 Fixes #2512, handle configuration change messages sent by Wayland. Patch by Bryan Cain.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8712
diff changeset
    47
e5f584f77609 Fixes #2512, handle configuration change messages sent by Wayland. Patch by Bryan Cain.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8712
diff changeset
    48
    window->w = width;
e5f584f77609 Fixes #2512, handle configuration change messages sent by Wayland. Patch by Bryan Cain.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8712
diff changeset
    49
    window->h = height;
e5f584f77609 Fixes #2512, handle configuration change messages sent by Wayland. Patch by Bryan Cain.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8712
diff changeset
    50
    WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
e5f584f77609 Fixes #2512, handle configuration change messages sent by Wayland. Patch by Bryan Cain.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8712
diff changeset
    51
e5f584f77609 Fixes #2512, handle configuration change messages sent by Wayland. Patch by Bryan Cain.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8712
diff changeset
    52
    region = wl_compositor_create_region(wind->waylandData->compositor);
e5f584f77609 Fixes #2512, handle configuration change messages sent by Wayland. Patch by Bryan Cain.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8712
diff changeset
    53
    wl_region_add(region, 0, 0, window->w, window->h);
e5f584f77609 Fixes #2512, handle configuration change messages sent by Wayland. Patch by Bryan Cain.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8712
diff changeset
    54
    wl_surface_set_opaque_region(wind->surface, region);
e5f584f77609 Fixes #2512, handle configuration change messages sent by Wayland. Patch by Bryan Cain.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8712
diff changeset
    55
    wl_region_destroy(region);
e5f584f77609 Fixes #2512, handle configuration change messages sent by Wayland. Patch by Bryan Cain.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8712
diff changeset
    56
    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, window->w, window->h);
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    57
}
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    58
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    59
static void
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    60
handle_popup_done(void *data, struct wl_shell_surface *shell_surface)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    61
{
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    62
}
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    63
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    64
static const struct wl_shell_surface_listener shell_surface_listener = {
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    65
    handle_ping,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    66
    handle_configure,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    67
    handle_popup_done
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    68
};
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    69
8082
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    70
#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
    71
static void
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    72
handle_onscreen_visibility(void *data,
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    73
        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
    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
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    77
static void
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    78
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
    79
        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
    80
        struct wl_array *value)
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    81
{
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    82
}
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    83
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    84
static void
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    85
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
    86
{
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    87
    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
    88
    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
    89
}
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    90
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    91
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
    92
    handle_onscreen_visibility,
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    93
    handle_set_generic_property,
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    94
    handle_close,
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    95
};
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    96
#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
    97
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    98
SDL_bool
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    99
Wayland_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   100
{
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   101
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   102
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   103
    info->info.wl.display = data->waylandData->display;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   104
    info->info.wl.surface = data->surface;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   105
    info->info.wl.shell_surface = data->shell_surface;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   106
    info->subsystem = SDL_SYSWM_WAYLAND;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   107
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   108
    return SDL_TRUE;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   109
}
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   110
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   111
void Wayland_ShowWindow(_THIS, SDL_Window *window)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   112
{
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   113
    SDL_WindowData *wind = window->driverdata;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   114
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   115
    if (window->flags & SDL_WINDOW_FULLSCREEN)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   116
        wl_shell_surface_set_fullscreen(wind->shell_surface,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   117
                                        WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   118
                                        0, NULL);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   119
    else
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   120
        wl_shell_surface_set_toplevel(wind->shell_surface);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   121
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
   122
    WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   123
}
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   124
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   125
void
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   126
Wayland_SetWindowFullscreen(_THIS, SDL_Window * window,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   127
                            SDL_VideoDisplay * _display, SDL_bool fullscreen)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   128
{
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   129
    SDL_WindowData *wind = window->driverdata;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   130
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   131
    if (fullscreen)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   132
        wl_shell_surface_set_fullscreen(wind->shell_surface,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   133
                                        WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   134
                                        0, NULL);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   135
    else
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   136
        wl_shell_surface_set_toplevel(wind->shell_surface);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   137
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
   138
    WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   139
}
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   140
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   141
int Wayland_CreateWindow(_THIS, SDL_Window *window)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   142
{
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   143
    SDL_WindowData *data;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   144
    SDL_VideoData *c;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   145
    struct wl_region *region;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   146
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   147
    data = calloc(1, sizeof *data);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   148
    if (data == NULL)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   149
        return 0;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   150
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   151
    c = _this->driverdata;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   152
    window->driverdata = data;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   153
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   154
    if (!(window->flags & SDL_WINDOW_OPENGL)) {
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   155
        SDL_GL_LoadLibrary(NULL);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   156
        window->flags |= SDL_WINDOW_OPENGL;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   157
    }
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   158
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   159
    if (window->x == SDL_WINDOWPOS_UNDEFINED) {
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   160
        window->x = 0;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   161
    }
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   162
    if (window->y == SDL_WINDOWPOS_UNDEFINED) {
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   163
        window->y = 0;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   164
    }
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   165
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   166
    data->waylandData = c;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   167
    data->sdlwindow = window;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   168
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   169
    data->surface =
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   170
        wl_compositor_create_surface(c->compositor);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   171
    wl_surface_set_user_data(data->surface, data);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   172
    data->shell_surface = wl_shell_get_shell_surface(c->shell,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   173
                                                     data->surface);
8082
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   174
#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
   175
    if (c->surface_extension) {
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   176
        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
   177
                c->surface_extension, data->surface);
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   178
    }
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   179
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
8712
e33b5f7df761 Wayland: Resize windows with 0x0 requested size to screen size
Thomas Perl <m@thp.io>
parents: 8149
diff changeset
   180
e33b5f7df761 Wayland: Resize windows with 0x0 requested size to screen size
Thomas Perl <m@thp.io>
parents: 8149
diff changeset
   181
    /**
e33b5f7df761 Wayland: Resize windows with 0x0 requested size to screen size
Thomas Perl <m@thp.io>
parents: 8149
diff changeset
   182
     * If the user specified 0x0 as the size (turned to 1x1 by SDL_CreateWindow
e33b5f7df761 Wayland: Resize windows with 0x0 requested size to screen size
Thomas Perl <m@thp.io>
parents: 8149
diff changeset
   183
     * in SDL_video.c), we want to make the window fill the whole screen
e33b5f7df761 Wayland: Resize windows with 0x0 requested size to screen size
Thomas Perl <m@thp.io>
parents: 8149
diff changeset
   184
     **/
e33b5f7df761 Wayland: Resize windows with 0x0 requested size to screen size
Thomas Perl <m@thp.io>
parents: 8149
diff changeset
   185
    if (window->w == 1) {
e33b5f7df761 Wayland: Resize windows with 0x0 requested size to screen size
Thomas Perl <m@thp.io>
parents: 8149
diff changeset
   186
        window->w = c->screen_allocation.width;
e33b5f7df761 Wayland: Resize windows with 0x0 requested size to screen size
Thomas Perl <m@thp.io>
parents: 8149
diff changeset
   187
    }
e33b5f7df761 Wayland: Resize windows with 0x0 requested size to screen size
Thomas Perl <m@thp.io>
parents: 8149
diff changeset
   188
    if (window->h == 1) {
e33b5f7df761 Wayland: Resize windows with 0x0 requested size to screen size
Thomas Perl <m@thp.io>
parents: 8149
diff changeset
   189
        window->h = c->screen_allocation.height;
e33b5f7df761 Wayland: Resize windows with 0x0 requested size to screen size
Thomas Perl <m@thp.io>
parents: 8149
diff changeset
   190
    }
e33b5f7df761 Wayland: Resize windows with 0x0 requested size to screen size
Thomas Perl <m@thp.io>
parents: 8149
diff changeset
   191
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
   192
    data->egl_window = WAYLAND_wl_egl_window_create(data->surface,
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   193
                                            window->w, window->h);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   194
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   195
    /* Create the GLES window surface */
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   196
    data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->egl_window);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   197
    
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   198
    if (data->egl_surface == EGL_NO_SURFACE) {
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   199
        SDL_SetError("failed to create a window surface");
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   200
        return -1;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   201
    }
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   202
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   203
    if (data->shell_surface) {
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   204
        wl_shell_surface_set_user_data(data->shell_surface, data);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   205
        wl_shell_surface_add_listener(data->shell_surface,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   206
                                      &shell_surface_listener, data);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   207
    }
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   208
8082
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   209
#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
   210
    if (data->extended_surface) {
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   211
        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
   212
        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
   213
                                         &extended_surface_listener, data);
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   214
    }
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   215
#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
   216
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   217
    region = wl_compositor_create_region(c->compositor);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   218
    wl_region_add(region, 0, 0, window->w, window->h);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   219
    wl_surface_set_opaque_region(data->surface, region);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   220
    wl_region_destroy(region);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   221
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
   222
    WAYLAND_wl_display_flush(c->display);
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   223
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   224
    return 0;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   225
}
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   226
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   227
void Wayland_SetWindowSize(_THIS, SDL_Window * window)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   228
{
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   229
    SDL_VideoData *data = _this->driverdata;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   230
    SDL_WindowData *wind = window->driverdata;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   231
    struct wl_region *region;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   232
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
   233
    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
   234
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
   235
    region =wl_compositor_create_region(data->compositor);
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   236
    wl_region_add(region, 0, 0, window->w, window->h);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   237
    wl_surface_set_opaque_region(wind->surface, region);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   238
    wl_region_destroy(region);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   239
}
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   240
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   241
void Wayland_DestroyWindow(_THIS, SDL_Window *window)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   242
{
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   243
    SDL_VideoData *data = _this->driverdata;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   244
    SDL_WindowData *wind = window->driverdata;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   245
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   246
    window->driverdata = NULL;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   247
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   248
    if (data) {
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   249
        SDL_EGL_DestroySurface(_this, wind->egl_surface);
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
   250
        WAYLAND_wl_egl_window_destroy(wind->egl_window);
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   251
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   252
        if (wind->shell_surface)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   253
            wl_shell_surface_destroy(wind->shell_surface);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   254
8082
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   255
#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
   256
        if (wind->extended_surface)
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   257
            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
   258
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   259
        wl_surface_destroy(wind->surface);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   260
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   261
        SDL_free(wind);
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
   262
        WAYLAND_wl_display_flush(data->display);
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   263
    }
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   264
}
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   265
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
   266
#endif /* SDL_VIDEO_DRIVER_WAYLAND && SDL_VIDEO_OPENGL_EGL */
f7c2f71251e5 Patched to compile if Wayland is disabled via SDL_config.h (thanks, Martin!).
Ryan C. Gordon <icculus@icculus.org>
parents: 8104
diff changeset
   267
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   268
/* vi: set ts=4 sw=4 expandtab: */