src/video/wayland/SDL_waylandvideo.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Wed, 16 Mar 2016 22:09:23 +0100
changeset 10119 ac9831ff70d1
parent 9998 f67cf37e9cd4
child 10187 1f0f8c95531d
permissions -rw-r--r--
Wayland: Fixed storing a theme cursor which is never used in video data.
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: 9619
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: 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
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_video.h"
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    27
#include "SDL_mouse.h"
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
    28
#include "SDL_stdinc.h"
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    29
#include "../../events/SDL_events_c.h"
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    30
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    31
#include "SDL_waylandvideo.h"
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    32
#include "SDL_waylandevents_c.h"
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    33
#include "SDL_waylandwindow.h"
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    34
#include "SDL_waylandopengles.h"
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    35
#include "SDL_waylandmouse.h"
8082
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
    36
#include "SDL_waylandtouch.h"
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    37
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    38
#include <fcntl.h>
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    39
#include <xkbcommon/xkbcommon.h>
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    40
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
    41
#include "SDL_waylanddyn.h"
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
    42
#include <wayland-util.h>
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
    43
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    44
#define WAYLANDVID_DRIVER_NAME "wayland"
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    45
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    46
/* Initialization/Query functions */
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    47
static int
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    48
Wayland_VideoInit(_THIS);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    49
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    50
static void
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    51
Wayland_GetDisplayModes(_THIS, SDL_VideoDisplay *sdl_display);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    52
static int
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    53
Wayland_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    54
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    55
static void
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    56
Wayland_VideoQuit(_THIS);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    57
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    58
/* Wayland driver bootstrap functions */
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    59
static int
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    60
Wayland_Available(void)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    61
{
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    62
    struct wl_display *display = NULL;
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
    63
    if (SDL_WAYLAND_LoadSymbols()) {
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
    64
        display = WAYLAND_wl_display_connect(NULL);
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
    65
        if (display != NULL) {
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
    66
            WAYLAND_wl_display_disconnect(display);
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
    67
        }
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
    68
        SDL_WAYLAND_UnloadSymbols();
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    69
    }
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    70
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    71
    return (display != NULL);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    72
}
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    73
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    74
static void
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    75
Wayland_DeleteDevice(SDL_VideoDevice *device)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    76
{
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    77
    SDL_free(device);
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
    78
    SDL_WAYLAND_UnloadSymbols();
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 SDL_VideoDevice *
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    82
Wayland_CreateDevice(int devindex)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    83
{
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    84
    SDL_VideoDevice *device;
9467
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
    85
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
    86
    if (!SDL_WAYLAND_LoadSymbols()) {
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
    87
        return NULL;
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
    88
    }
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    89
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    90
    /* Initialize all variables that we clean on shutdown */
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    91
    device = SDL_calloc(1, sizeof(SDL_VideoDevice));
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    92
    if (!device) {
8160
71639d445b59 Unload Wayland libs if memory allocation fails during init.
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
    93
        SDL_WAYLAND_UnloadSymbols();
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    94
        SDL_OutOfMemory();
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    95
        return NULL;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    96
    }
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    97
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    98
    /* Set the function pointers */
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    99
    device->VideoInit = Wayland_VideoInit;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   100
    device->VideoQuit = Wayland_VideoQuit;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   101
    device->SetDisplayMode = Wayland_SetDisplayMode;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   102
    device->GetDisplayModes = Wayland_GetDisplayModes;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   103
    device->GetWindowWMInfo = Wayland_GetWindowWMInfo;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   104
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   105
    device->PumpEvents = Wayland_PumpEvents;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   106
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   107
    device->GL_SwapWindow = Wayland_GLES_SwapWindow;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   108
    device->GL_GetSwapInterval = Wayland_GLES_GetSwapInterval;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   109
    device->GL_SetSwapInterval = Wayland_GLES_SetSwapInterval;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   110
    device->GL_MakeCurrent = Wayland_GLES_MakeCurrent;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   111
    device->GL_CreateContext = Wayland_GLES_CreateContext;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   112
    device->GL_LoadLibrary = Wayland_GLES_LoadLibrary;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   113
    device->GL_UnloadLibrary = Wayland_GLES_UnloadLibrary;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   114
    device->GL_GetProcAddress = Wayland_GLES_GetProcAddress;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   115
    device->GL_DeleteContext = Wayland_GLES_DeleteContext;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   116
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   117
    device->CreateWindow = Wayland_CreateWindow;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   118
    device->ShowWindow = Wayland_ShowWindow;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   119
    device->SetWindowFullscreen = Wayland_SetWindowFullscreen;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   120
    device->SetWindowSize = Wayland_SetWindowSize;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   121
    device->DestroyWindow = Wayland_DestroyWindow;
9554
879f71e1478b Implemented SetWindowHitTest() for Wayland (thanks, x414e54!).
Ryan C. Gordon <icculus@icculus.org>
parents: 9486
diff changeset
   122
    device->SetWindowHitTest = Wayland_SetWindowHitTest;
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
    device->free = Wayland_DeleteDevice;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   125
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   126
    return device;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   127
}
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   128
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   129
VideoBootStrap Wayland_bootstrap = {
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   130
    WAYLANDVID_DRIVER_NAME, "SDL Wayland video driver",
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   131
    Wayland_Available, Wayland_CreateDevice
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   132
};
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   133
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   134
static void
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   135
display_handle_geometry(void *data,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   136
                        struct wl_output *output,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   137
                        int x, int y,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   138
                        int physical_width,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   139
                        int physical_height,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   140
                        int subpixel,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   141
                        const char *make,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   142
                        const char *model,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   143
                        int transform)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   144
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   145
{
9467
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   146
    SDL_VideoDisplay *display = data;
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   147
9467
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   148
    display->name = strdup(model);
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   149
    display->driverdata = output;
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   150
}
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   151
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   152
static void
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   153
display_handle_mode(void *data,
9467
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   154
                    struct wl_output *output,
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   155
                    uint32_t flags,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   156
                    int width,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   157
                    int height,
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   158
                    int refresh)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   159
{
9467
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   160
    SDL_VideoDisplay *display = data;
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   161
    SDL_DisplayMode mode;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   162
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   163
    SDL_zero(mode);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   164
    mode.w = width;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   165
    mode.h = height;
9467
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   166
    mode.refresh_rate = refresh / 1000; // mHz to Hz
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   167
    SDL_AddDisplayMode(display, &mode);
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   168
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   169
    if (flags & WL_OUTPUT_MODE_CURRENT) {
9467
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   170
        display->current_mode = mode;
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   171
        display->desktop_mode = mode;
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   172
    }
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   173
}
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   174
9467
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   175
static void
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   176
display_handle_done(void *data,
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   177
                    struct wl_output *output)
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   178
{
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   179
    SDL_VideoDisplay *display = data;
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   180
    SDL_AddVideoDisplay(display);
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   181
    SDL_free(display->name);
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   182
    SDL_free(display);
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   183
}
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   184
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   185
static void
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   186
display_handle_scale(void *data,
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   187
                     struct wl_output *output,
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   188
                     int32_t factor)
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   189
{
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   190
    // TODO: do HiDPI stuff.
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   191
}
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   192
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   193
static const struct wl_output_listener output_listener = {
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   194
    display_handle_geometry,
9467
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   195
    display_handle_mode,
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   196
    display_handle_done,
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   197
    display_handle_scale
8062
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
static void
9467
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   201
Wayland_add_display(SDL_VideoData *d, uint32_t id)
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   202
{
9472
14813191e6cf Patched to compile on C89 compilers.
Ryan C. Gordon <icculus@icculus.org>
parents: 9469
diff changeset
   203
    struct wl_output *output;
9467
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   204
    SDL_VideoDisplay *display = SDL_malloc(sizeof *display);
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   205
    if (!display) {
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   206
        SDL_OutOfMemory();
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   207
        return;
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   208
    }
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   209
    SDL_zero(*display);
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   210
9472
14813191e6cf Patched to compile on C89 compilers.
Ryan C. Gordon <icculus@icculus.org>
parents: 9469
diff changeset
   211
    output = wl_registry_bind(d->registry, id, &wl_output_interface, 2);
9467
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   212
    if (!output) {
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   213
        SDL_SetError("Failed to retrieve output.");
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   214
        return;
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   215
    }
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   216
9467
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   217
    wl_output_add_listener(output, &output_listener, display);
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   218
}
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   219
8082
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   220
#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
   221
static void
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   222
windowmanager_hints(void *data, struct qt_windowmanager *qt_windowmanager,
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   223
        int32_t show_is_fullscreen)
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   224
{
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   225
}
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   226
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   227
static void
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   228
windowmanager_quit(void *data, struct qt_windowmanager *qt_windowmanager)
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   229
{
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   230
    SDL_SendQuit();
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   231
}
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   232
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   233
static const struct qt_windowmanager_listener windowmanager_listener = {
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   234
    windowmanager_hints,
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   235
    windowmanager_quit,
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   236
};
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   237
#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
   238
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   239
static void
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   240
display_handle_global(void *data, struct wl_registry *registry, uint32_t id,
9467
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   241
                      const char *interface, uint32_t version)
8062
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 *d = data;
9467
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   244
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   245
    if (strcmp(interface, "wl_compositor") == 0) {
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   246
        d->compositor = wl_registry_bind(d->registry, id, &wl_compositor_interface, 1);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   247
    } else if (strcmp(interface, "wl_output") == 0) {
9467
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   248
        Wayland_add_display(d, id);
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   249
    } else if (strcmp(interface, "wl_seat") == 0) {
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   250
        Wayland_display_add_input(d, id);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   251
    } else if (strcmp(interface, "wl_shell") == 0) {
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   252
        d->shell = wl_registry_bind(d->registry, id, &wl_shell_interface, 1);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   253
    } else if (strcmp(interface, "wl_shm") == 0) {
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   254
        d->shm = wl_registry_bind(registry, id, &wl_shm_interface, 1);
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
   255
        d->cursor_theme = WAYLAND_wl_cursor_theme_load(NULL, 32, d->shm);
9467
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   256
8082
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   257
#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
   258
    } else if (strcmp(interface, "qt_touch_extension") == 0) {
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   259
        Wayland_touch_create(d, id);
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   260
    } else if (strcmp(interface, "qt_surface_extension") == 0) {
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   261
        d->surface_extension = wl_registry_bind(registry, id,
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   262
                &qt_surface_extension_interface, 1);
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   263
    } else if (strcmp(interface, "qt_windowmanager") == 0) {
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   264
        d->windowmanager = wl_registry_bind(registry, id,
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   265
                &qt_windowmanager_interface, 1);
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   266
        qt_windowmanager_add_listener(d->windowmanager, &windowmanager_listener, d);
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   267
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   268
    }
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   269
}
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   270
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   271
static const struct wl_registry_listener registry_listener = {
9467
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   272
    display_handle_global
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   273
};
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   274
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   275
int
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   276
Wayland_VideoInit(_THIS)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   277
{
9467
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   278
    SDL_VideoData *data = SDL_malloc(sizeof *data);
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   279
    if (data == NULL)
9484
8828b1a0ab67 Wayland: Fixed accessing not fully initialized subsystem if errors happened.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9476
diff changeset
   280
        return SDL_OutOfMemory();
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   281
    memset(data, 0, sizeof *data);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   282
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   283
    _this->driverdata = data;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   284
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
   285
    data->display = WAYLAND_wl_display_connect(NULL);
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   286
    if (data->display == NULL) {
9484
8828b1a0ab67 Wayland: Fixed accessing not fully initialized subsystem if errors happened.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9476
diff changeset
   287
        return SDL_SetError("Failed to connect to a Wayland display");
8062
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
    data->registry = wl_display_get_registry(data->display);
9467
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   291
    if (data->registry == NULL) {
9484
8828b1a0ab67 Wayland: Fixed accessing not fully initialized subsystem if errors happened.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9476
diff changeset
   292
        return SDL_SetError("Failed to get the Wayland registry");
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
   293
    }
9467
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   294
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   295
    wl_registry_add_listener(data->registry, &registry_listener, data);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   296
9467
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   297
    // First roundtrip to receive all registry objects.
9476
2928e95ffcaf Wayland: Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 9472
diff changeset
   298
    WAYLAND_wl_display_roundtrip(data->display);
9467
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   299
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   300
    // Second roundtrip to receive all output events.
9476
2928e95ffcaf Wayland: Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 9472
diff changeset
   301
    WAYLAND_wl_display_roundtrip(data->display);
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   302
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
   303
    data->xkb_context = WAYLAND_xkb_context_new(0);
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   304
    if (!data->xkb_context) {
9484
8828b1a0ab67 Wayland: Fixed accessing not fully initialized subsystem if errors happened.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9476
diff changeset
   305
        return SDL_SetError("Failed to create XKB context");
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   306
    }
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   307
9467
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   308
    Wayland_InitMouse();
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   309
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
   310
    WAYLAND_wl_display_flush(data->display);
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   311
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   312
    return 0;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   313
}
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   314
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   315
static void
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   316
Wayland_GetDisplayModes(_THIS, SDL_VideoDisplay *sdl_display)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   317
{
9467
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   318
    // Nothing to do here, everything was already done in the wl_output
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   319
    // callbacks.
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   320
}
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   321
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   322
static int
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   323
Wayland_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   324
{
9469
3f8d36ffd19d Wayland: changed a few "SetError(); return -1;" to "return SetError()".
Ryan C. Gordon <icculus@icculus.org>
parents: 9467
diff changeset
   325
    return SDL_Unsupported();
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   326
}
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   327
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   328
void
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   329
Wayland_VideoQuit(_THIS)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   330
{
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   331
    SDL_VideoData *data = _this->driverdata;
9467
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   332
    int i;
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   333
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   334
    Wayland_FiniMouse ();
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   335
9467
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   336
    for (i = 0; i < _this->num_displays; ++i) {
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   337
        SDL_VideoDisplay *display = &_this->displays[i];
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   338
        wl_output_destroy(display->driverdata);
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   339
        display->driverdata = NULL;
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   340
    }
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   341
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   342
    Wayland_display_destroy_input(data);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   343
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   344
    if (data->xkb_context) {
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
   345
        WAYLAND_xkb_context_unref(data->xkb_context);
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   346
        data->xkb_context = NULL;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   347
    }
8082
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   348
#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
   349
    if (data->windowmanager)
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   350
        qt_windowmanager_destroy(data->windowmanager);
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   351
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   352
    if (data->surface_extension)
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   353
        qt_surface_extension_destroy(data->surface_extension);
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   354
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   355
    Wayland_touch_destroy(data);
5b83ad3f01ac Implements touch support on QTWayland. Contributed by Thomas Perl.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8062
diff changeset
   356
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   357
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   358
    if (data->shm)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   359
        wl_shm_destroy(data->shm);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   360
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   361
    if (data->cursor_theme)
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
   362
        WAYLAND_wl_cursor_theme_destroy(data->cursor_theme);
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   363
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   364
    if (data->shell)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   365
        wl_shell_destroy(data->shell);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   366
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   367
    if (data->compositor)
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   368
        wl_compositor_destroy(data->compositor);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   369
9467
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   370
    if (data->registry)
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   371
        wl_registry_destroy(data->registry);
975453c4e217 Wayland: Properly discover displays and their modes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8160
diff changeset
   372
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   373
    if (data->display) {
8104
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
   374
        WAYLAND_wl_display_flush(data->display);
2e4f1bd21196 Dynamic loading support for Wayland
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8082
diff changeset
   375
        WAYLAND_wl_display_disconnect(data->display);
8062
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
    free(data);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   379
    _this->driverdata = NULL;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   380
}
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   381
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
   382
#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
   383
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   384
/* vi: set ts=4 sw=4 expandtab: */