src/video/wayland/SDL_waylandwindow.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 05 Oct 2018 17:24:03 -0400
changeset 12298 c4d5e502c1f4
parent 12201 8bdc4d340419
child 12381 dc9108cd4340
permissions -rw-r--r--
wayland: Fixed missing window sizing events.

Fixes Bugzilla #4242.
gabomdq@8062
     1
/*
gabomdq@8062
     2
  Simple DirectMedia Layer
slouken@11811
     3
  Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
gabomdq@8062
     4
gabomdq@8062
     5
  This software is provided 'as-is', without any express or implied
gabomdq@8062
     6
  warranty.  In no event will the authors be held liable for any damages
gabomdq@8062
     7
  arising from the use of this software.
gabomdq@8062
     8
gabomdq@8062
     9
  Permission is granted to anyone to use this software for any purpose,
gabomdq@8062
    10
  including commercial applications, and to alter it and redistribute it
gabomdq@8062
    11
  freely, subject to the following restrictions:
gabomdq@8062
    12
gabomdq@8062
    13
  1. The origin of this software must not be misrepresented; you must not
gabomdq@8062
    14
     claim that you wrote the original software. If you use this software
gabomdq@8062
    15
     in a product, an acknowledgment in the product documentation would be
gabomdq@8062
    16
     appreciated but is not required.
gabomdq@8062
    17
  2. Altered source versions must be plainly marked as such, and must not be
gabomdq@8062
    18
     misrepresented as being the original software.
gabomdq@8062
    19
  3. This notice may not be removed or altered from any source distribution.
gabomdq@8062
    20
*/
gabomdq@8062
    21
gabomdq@8104
    22
#include "../../SDL_internal.h"
gabomdq@8062
    23
icculus@8116
    24
#if SDL_VIDEO_DRIVER_WAYLAND && SDL_VIDEO_OPENGL_EGL
icculus@8116
    25
gabomdq@8062
    26
#include "../SDL_sysvideo.h"
gabomdq@8062
    27
#include "../../events/SDL_windowevents_c.h"
gabomdq@8062
    28
#include "../SDL_egl_c.h"
slouken@10304
    29
#include "SDL_waylandevents_c.h"
gabomdq@8062
    30
#include "SDL_waylandwindow.h"
gabomdq@8062
    31
#include "SDL_waylandvideo.h"
gabomdq@8082
    32
#include "SDL_waylandtouch.h"
arnej@9362
    33
#include "SDL_waylanddyn.h"
m@10614
    34
#include "SDL_hints.h"
gabomdq@8062
    35
icculus@12033
    36
#include "xdg-shell-client-protocol.h"
icculus@11848
    37
#include "xdg-shell-unstable-v6-client-protocol.h"
icculus@11848
    38
icculus@11848
    39
/* On modern desktops, we probably will use the xdg-shell protocol instead
icculus@11848
    40
   of wl_shell, but wl_shell might be useful on older Wayland installs that
icculus@11848
    41
   don't have the newer protocol, or embedded things that don't have a full
icculus@11848
    42
   window manager. */
icculus@11848
    43
gabomdq@8062
    44
static void
icculus@11848
    45
handle_ping_wl_shell_surface(void *data, struct wl_shell_surface *shell_surface,
gabomdq@8062
    46
            uint32_t serial)
gabomdq@8062
    47
{
gabomdq@8062
    48
    wl_shell_surface_pong(shell_surface, serial);
gabomdq@8062
    49
}
gabomdq@8062
    50
gabomdq@8062
    51
static void
icculus@11848
    52
handle_configure_wl_shell_surface(void *data, struct wl_shell_surface *shell_surface,
gabomdq@8062
    53
                 uint32_t edges, int32_t width, int32_t height)
gabomdq@8062
    54
{
gabomdq@8766
    55
    SDL_WindowData *wind = (SDL_WindowData *)data;
gabomdq@8766
    56
    SDL_Window *window = wind->sdlwindow;
gabomdq@8766
    57
    struct wl_region *region;
gabomdq@8766
    58
slouken@10492
    59
    /* wl_shell_surface spec states that this is a suggestion.
slouken@10492
    60
       Ignore if less than or greater than max/min size. */
slouken@10492
    61
slouken@10492
    62
    if (width == 0 || height == 0) {
slouken@10492
    63
        return;
slouken@10492
    64
    }
slouken@10492
    65
slouken@10492
    66
    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
slouken@10492
    67
        if ((window->flags & SDL_WINDOW_RESIZABLE)) {
slouken@10492
    68
            if (window->max_w > 0) {
slouken@10492
    69
                width = SDL_min(width, window->max_w);
slouken@10492
    70
            } 
slouken@10492
    71
            width = SDL_max(width, window->min_w);
slouken@10492
    72
slouken@10492
    73
            if (window->max_h > 0) {
slouken@10492
    74
                height = SDL_min(height, window->max_h);
slouken@10492
    75
            }
slouken@10492
    76
            height = SDL_max(height, window->min_h);
slouken@10492
    77
        } else {
slouken@10492
    78
            return;
slouken@10492
    79
        }
slouken@10492
    80
    }
slouken@10492
    81
icculus@12298
    82
    WAYLAND_wl_egl_window_resize(wind->egl_window, width, height, 0, 0);
icculus@12298
    83
    region = wl_compositor_create_region(wind->waylandData->compositor);
icculus@12298
    84
    wl_region_add(region, 0, 0, width, height);
icculus@12298
    85
    wl_surface_set_opaque_region(wind->surface, region);
icculus@12298
    86
    wl_region_destroy(region);
slouken@10492
    87
icculus@12298
    88
    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, width, height);
gabomdq@8766
    89
    window->w = width;
gabomdq@8766
    90
    window->h = height;
gabomdq@8062
    91
}
gabomdq@8062
    92
gabomdq@8062
    93
static void
icculus@11848
    94
handle_popup_done_wl_shell_surface(void *data, struct wl_shell_surface *shell_surface)
gabomdq@8062
    95
{
gabomdq@8062
    96
}
gabomdq@8062
    97
icculus@11848
    98
static const struct wl_shell_surface_listener shell_surface_listener_wl = {
icculus@11848
    99
    handle_ping_wl_shell_surface,
icculus@11848
   100
    handle_configure_wl_shell_surface,
icculus@11848
   101
    handle_popup_done_wl_shell_surface
gabomdq@8062
   102
};
gabomdq@8062
   103
icculus@11848
   104
icculus@11848
   105
icculus@11848
   106
icculus@11848
   107
static void
icculus@11848
   108
handle_configure_zxdg_shell_surface(void *data, struct zxdg_surface_v6 *zxdg, uint32_t serial)
icculus@11848
   109
{
icculus@11848
   110
    SDL_WindowData *wind = (SDL_WindowData *)data;
icculus@11848
   111
    SDL_Window *window = wind->sdlwindow;
icculus@11848
   112
    struct wl_region *region;
icculus@11944
   113
icculus@11944
   114
    wind->shell_surface.zxdg.initial_configure_seen = SDL_TRUE;
icculus@11944
   115
icculus@11848
   116
    WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
icculus@11848
   117
icculus@11848
   118
    region = wl_compositor_create_region(wind->waylandData->compositor);
icculus@11848
   119
    wl_region_add(region, 0, 0, window->w, window->h);
icculus@11848
   120
    wl_surface_set_opaque_region(wind->surface, region);
icculus@11848
   121
    wl_region_destroy(region);
icculus@11848
   122
    zxdg_surface_v6_ack_configure(zxdg, serial);
icculus@11848
   123
}
icculus@11848
   124
icculus@11848
   125
static const struct zxdg_surface_v6_listener shell_surface_listener_zxdg = {
icculus@11848
   126
    handle_configure_zxdg_shell_surface
icculus@11848
   127
};
icculus@11848
   128
icculus@11848
   129
icculus@11848
   130
static void
icculus@11848
   131
handle_configure_zxdg_toplevel(void *data,
slouken@12201
   132
              struct zxdg_toplevel_v6 *zxdg_toplevel_v6,
slouken@12201
   133
              int32_t width,
slouken@12201
   134
              int32_t height,
slouken@12201
   135
              struct wl_array *states)
icculus@11848
   136
{
icculus@11848
   137
    SDL_WindowData *wind = (SDL_WindowData *)data;
icculus@11848
   138
    SDL_Window *window = wind->sdlwindow;
icculus@11848
   139
icculus@11848
   140
    /* wl_shell_surface spec states that this is a suggestion.
icculus@11848
   141
       Ignore if less than or greater than max/min size. */
icculus@11848
   142
icculus@11848
   143
    if (width == 0 || height == 0) {
icculus@11848
   144
        return;
icculus@11848
   145
    }
icculus@11848
   146
icculus@11848
   147
    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
icculus@11848
   148
        if ((window->flags & SDL_WINDOW_RESIZABLE)) {
icculus@11848
   149
            if (window->max_w > 0) {
icculus@11848
   150
                width = SDL_min(width, window->max_w);
icculus@11848
   151
            } 
icculus@11848
   152
            width = SDL_max(width, window->min_w);
icculus@11848
   153
icculus@11848
   154
            if (window->max_h > 0) {
icculus@11848
   155
                height = SDL_min(height, window->max_h);
icculus@11848
   156
            }
icculus@11848
   157
            height = SDL_max(height, window->min_h);
icculus@11848
   158
        } else {
icculus@11848
   159
            return;
icculus@11848
   160
        }
icculus@11848
   161
    }
icculus@11848
   162
icculus@12298
   163
    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, width, height);
icculus@11848
   164
    window->w = width;
icculus@11848
   165
    window->h = height;
icculus@11848
   166
}
icculus@11848
   167
icculus@11848
   168
static void
icculus@11848
   169
handle_close_zxdg_toplevel(void *data, struct zxdg_toplevel_v6 *zxdg_toplevel_v6)
icculus@11848
   170
{
icculus@11848
   171
    SDL_WindowData *window = (SDL_WindowData *)data;
icculus@11848
   172
    SDL_SendWindowEvent(window->sdlwindow, SDL_WINDOWEVENT_CLOSE, 0, 0);
icculus@11848
   173
}
icculus@11848
   174
icculus@11848
   175
static const struct zxdg_toplevel_v6_listener toplevel_listener_zxdg = {
icculus@11848
   176
    handle_configure_zxdg_toplevel,
icculus@11848
   177
    handle_close_zxdg_toplevel
icculus@11848
   178
};
icculus@11848
   179
icculus@11848
   180
icculus@12033
   181
icculus@12033
   182
static void
icculus@12033
   183
handle_configure_xdg_shell_surface(void *data, struct xdg_surface *xdg, uint32_t serial)
icculus@12033
   184
{
icculus@12033
   185
    SDL_WindowData *wind = (SDL_WindowData *)data;
icculus@12033
   186
    SDL_Window *window = wind->sdlwindow;
icculus@12033
   187
    struct wl_region *region;
icculus@12033
   188
icculus@12033
   189
    wind->shell_surface.xdg.initial_configure_seen = SDL_TRUE;
icculus@12033
   190
icculus@12033
   191
    WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
icculus@12033
   192
icculus@12033
   193
    region = wl_compositor_create_region(wind->waylandData->compositor);
icculus@12033
   194
    wl_region_add(region, 0, 0, window->w, window->h);
icculus@12033
   195
    wl_surface_set_opaque_region(wind->surface, region);
icculus@12033
   196
    wl_region_destroy(region);
icculus@12033
   197
    xdg_surface_ack_configure(xdg, serial);
icculus@12033
   198
}
icculus@12033
   199
icculus@12033
   200
static const struct xdg_surface_listener shell_surface_listener_xdg = {
icculus@12033
   201
    handle_configure_xdg_shell_surface
icculus@12033
   202
};
icculus@12033
   203
icculus@12033
   204
icculus@12033
   205
static void
icculus@12033
   206
handle_configure_xdg_toplevel(void *data,
slouken@12201
   207
              struct xdg_toplevel *xdg_toplevel,
slouken@12201
   208
              int32_t width,
slouken@12201
   209
              int32_t height,
slouken@12201
   210
              struct wl_array *states)
icculus@12033
   211
{
icculus@12033
   212
    SDL_WindowData *wind = (SDL_WindowData *)data;
icculus@12033
   213
    SDL_Window *window = wind->sdlwindow;
icculus@12033
   214
icculus@12033
   215
    /* wl_shell_surface spec states that this is a suggestion.
icculus@12033
   216
       Ignore if less than or greater than max/min size. */
icculus@12033
   217
icculus@12033
   218
    if (width == 0 || height == 0) {
icculus@12033
   219
        return;
icculus@12033
   220
    }
icculus@12033
   221
icculus@12033
   222
    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
icculus@12033
   223
        if ((window->flags & SDL_WINDOW_RESIZABLE)) {
icculus@12033
   224
            if (window->max_w > 0) {
icculus@12033
   225
                width = SDL_min(width, window->max_w);
icculus@12033
   226
            } 
icculus@12033
   227
            width = SDL_max(width, window->min_w);
icculus@12033
   228
icculus@12033
   229
            if (window->max_h > 0) {
icculus@12033
   230
                height = SDL_min(height, window->max_h);
icculus@12033
   231
            }
icculus@12033
   232
            height = SDL_max(height, window->min_h);
icculus@12033
   233
        } else {
icculus@12033
   234
            return;
icculus@12033
   235
        }
icculus@12033
   236
    }
icculus@12033
   237
icculus@12033
   238
    if (width == window->w && height == window->h) {
icculus@12033
   239
        return;
icculus@12033
   240
    }
icculus@12033
   241
icculus@12298
   242
    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, width, height);
icculus@12033
   243
    window->w = width;
icculus@12033
   244
    window->h = height;
icculus@12033
   245
}
icculus@12033
   246
icculus@12033
   247
static void
icculus@12033
   248
handle_close_xdg_toplevel(void *data, struct xdg_toplevel *xdg_toplevel)
icculus@12033
   249
{
icculus@12033
   250
    SDL_WindowData *window = (SDL_WindowData *)data;
icculus@12033
   251
    SDL_SendWindowEvent(window->sdlwindow, SDL_WINDOWEVENT_CLOSE, 0, 0);
icculus@12033
   252
}
icculus@12033
   253
icculus@12033
   254
static const struct xdg_toplevel_listener toplevel_listener_xdg = {
icculus@12033
   255
    handle_configure_xdg_toplevel,
icculus@12033
   256
    handle_close_xdg_toplevel
icculus@12033
   257
};
icculus@12033
   258
icculus@12033
   259
icculus@12033
   260
icculus@12033
   261
gabomdq@8082
   262
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
gabomdq@8082
   263
static void
gabomdq@8082
   264
handle_onscreen_visibility(void *data,
gabomdq@8082
   265
        struct qt_extended_surface *qt_extended_surface, int32_t visible)
gabomdq@8082
   266
{
gabomdq@8082
   267
}
gabomdq@8082
   268
gabomdq@8082
   269
static void
gabomdq@8082
   270
handle_set_generic_property(void *data,
gabomdq@8082
   271
        struct qt_extended_surface *qt_extended_surface, const char *name,
gabomdq@8082
   272
        struct wl_array *value)
gabomdq@8082
   273
{
gabomdq@8082
   274
}
gabomdq@8082
   275
gabomdq@8082
   276
static void
gabomdq@8082
   277
handle_close(void *data, struct qt_extended_surface *qt_extended_surface)
gabomdq@8082
   278
{
gabomdq@8082
   279
    SDL_WindowData *window = (SDL_WindowData *)data;
gabomdq@8082
   280
    SDL_SendWindowEvent(window->sdlwindow, SDL_WINDOWEVENT_CLOSE, 0, 0);
gabomdq@8082
   281
}
gabomdq@8082
   282
gabomdq@8082
   283
static const struct qt_extended_surface_listener extended_surface_listener = {
gabomdq@8082
   284
    handle_onscreen_visibility,
gabomdq@8082
   285
    handle_set_generic_property,
gabomdq@8082
   286
    handle_close,
gabomdq@8082
   287
};
gabomdq@8082
   288
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
gabomdq@8082
   289
gabomdq@8062
   290
SDL_bool
gabomdq@8062
   291
Wayland_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
gabomdq@8062
   292
{
gabomdq@8062
   293
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
icculus@11088
   294
    const Uint32 version = ((((Uint32) info->version.major) * 1000000) +
icculus@11088
   295
                            (((Uint32) info->version.minor) * 10000) +
icculus@11088
   296
                            (((Uint32) info->version.patch)));
icculus@11088
   297
icculus@11088
   298
    /* Before 2.0.6, it was possible to build an SDL with Wayland support
icculus@11088
   299
       (SDL_SysWMinfo will be large enough to hold Wayland info), but build
icculus@11088
   300
       your app against SDL headers that didn't have Wayland support
icculus@11088
   301
       (SDL_SysWMinfo could be smaller than Wayland needs. This would lead
icculus@11088
   302
       to an app properly using SDL_GetWindowWMInfo() but we'd accidentally
icculus@11088
   303
       overflow memory on the stack or heap. To protect against this, we've
icculus@11088
   304
       padded out the struct unconditionally in the headers and Wayland will
icculus@11088
   305
       just return an error for older apps using this function. Those apps
icculus@11088
   306
       will need to be recompiled against newer headers or not use Wayland,
icculus@11088
   307
       maybe by forcing SDL_VIDEODRIVER=x11. */
icculus@11088
   308
    if (version < 2000006) {
icculus@11088
   309
        info->subsystem = SDL_SYSWM_UNKNOWN;
philipp@11092
   310
        SDL_SetError("Version must be 2.0.6 or newer");
icculus@11088
   311
        return SDL_FALSE;
icculus@11088
   312
    }
gabomdq@8062
   313
gabomdq@8062
   314
    info->info.wl.display = data->waylandData->display;
gabomdq@8062
   315
    info->info.wl.surface = data->surface;
icculus@11848
   316
    info->info.wl.shell_surface = data->shell_surface.wl;
gabomdq@8062
   317
    info->subsystem = SDL_SYSWM_WAYLAND;
gabomdq@8062
   318
gabomdq@8062
   319
    return SDL_TRUE;
gabomdq@8062
   320
}
gabomdq@8062
   321
icculus@9554
   322
int
icculus@9554
   323
Wayland_SetWindowHitTest(SDL_Window *window, SDL_bool enabled)
icculus@9554
   324
{
icculus@9554
   325
    return 0;  /* just succeed, the real work is done elsewhere. */
icculus@9554
   326
}
icculus@9554
   327
icculus@11848
   328
static void
icculus@11848
   329
SetFullscreen(_THIS, SDL_Window * window, struct wl_output *output)
icculus@11848
   330
{
icculus@11848
   331
    const SDL_VideoData *viddata = (const SDL_VideoData *) _this->driverdata;
icculus@11848
   332
    SDL_WindowData *wind = window->driverdata;
icculus@11848
   333
icculus@12033
   334
    if (viddata->shell.xdg) {
icculus@12033
   335
        if (output) {
icculus@12033
   336
            xdg_toplevel_set_fullscreen(wind->shell_surface.xdg.roleobj.toplevel, output);
icculus@12033
   337
        } else {
icculus@12033
   338
            xdg_toplevel_unset_fullscreen(wind->shell_surface.xdg.roleobj.toplevel);
icculus@12033
   339
        }
icculus@12033
   340
    } else if (viddata->shell.zxdg) {
icculus@11848
   341
        if (output) {
icculus@11848
   342
            zxdg_toplevel_v6_set_fullscreen(wind->shell_surface.zxdg.roleobj.toplevel, output);
icculus@11848
   343
        } else {
icculus@11848
   344
            zxdg_toplevel_v6_unset_fullscreen(wind->shell_surface.zxdg.roleobj.toplevel);
icculus@11848
   345
        }
icculus@11848
   346
    } else {
icculus@11848
   347
        if (output) {
icculus@11848
   348
            wl_shell_surface_set_fullscreen(wind->shell_surface.wl,
icculus@11848
   349
                                            WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
icculus@11848
   350
                                            0, output);
icculus@11848
   351
        } else {
icculus@11848
   352
            wl_shell_surface_set_toplevel(wind->shell_surface.wl);
icculus@11848
   353
        }
icculus@11848
   354
    }
icculus@11848
   355
icculus@11848
   356
    WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
icculus@11848
   357
}
icculus@11848
   358
gabomdq@8062
   359
void Wayland_ShowWindow(_THIS, SDL_Window *window)
gabomdq@8062
   360
{
icculus@11848
   361
    struct wl_output *output = (struct wl_output *) window->fullscreen_mode.driverdata;
icculus@11848
   362
    SetFullscreen(_this, window, (window->flags & SDL_WINDOW_FULLSCREEN) ? output : NULL);
gabomdq@8062
   363
}
gabomdq@8062
   364
m@10614
   365
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
slouken@11284
   366
static void SDLCALL
slouken@11284
   367
QtExtendedSurface_OnHintChanged(void *userdata, const char *name,
m@10614
   368
        const char *oldValue, const char *newValue)
m@10614
   369
{
m@10614
   370
    struct qt_extended_surface *qt_extended_surface = userdata;
m@10614
   371
m@10614
   372
    if (name == NULL) {
m@10614
   373
        return;
m@10614
   374
    }
m@10614
   375
m@10614
   376
    if (strcmp(name, SDL_HINT_QTWAYLAND_CONTENT_ORIENTATION) == 0) {
m@10614
   377
        int32_t orientation = QT_EXTENDED_SURFACE_ORIENTATION_PRIMARYORIENTATION;
m@10614
   378
m@10614
   379
        if (newValue != NULL) {
m@10614
   380
            if (strcmp(newValue, "portrait") == 0) {
m@10614
   381
                orientation = QT_EXTENDED_SURFACE_ORIENTATION_PORTRAITORIENTATION;
m@10614
   382
            } else if (strcmp(newValue, "landscape") == 0) {
m@10614
   383
                orientation = QT_EXTENDED_SURFACE_ORIENTATION_LANDSCAPEORIENTATION;
m@10614
   384
            } else if (strcmp(newValue, "inverted-portrait") == 0) {
m@10614
   385
                orientation = QT_EXTENDED_SURFACE_ORIENTATION_INVERTEDPORTRAITORIENTATION;
m@10614
   386
            } else if (strcmp(newValue, "inverted-landscape") == 0) {
m@10614
   387
                orientation = QT_EXTENDED_SURFACE_ORIENTATION_INVERTEDLANDSCAPEORIENTATION;
m@10614
   388
            }
m@10614
   389
        }
m@10614
   390
m@10614
   391
        qt_extended_surface_set_content_orientation(qt_extended_surface, orientation);
m@10614
   392
    } else if (strcmp(name, SDL_HINT_QTWAYLAND_WINDOW_FLAGS) == 0) {
m@10614
   393
        uint32_t flags = 0;
m@10614
   394
m@10614
   395
        if (newValue != NULL) {
m@10614
   396
            char *tmp = strdup(newValue);
m@10614
   397
            char *saveptr = NULL;
m@10614
   398
m@10614
   399
            char *flag = strtok_r(tmp, " ", &saveptr);
m@10614
   400
            while (flag) {
m@10614
   401
                if (strcmp(flag, "OverridesSystemGestures") == 0) {
m@10614
   402
                    flags |= QT_EXTENDED_SURFACE_WINDOWFLAG_OVERRIDESSYSTEMGESTURES;
m@10614
   403
                } else if (strcmp(flag, "StaysOnTop") == 0) {
m@10614
   404
                    flags |= QT_EXTENDED_SURFACE_WINDOWFLAG_STAYSONTOP;
m@10614
   405
                } else if (strcmp(flag, "BypassWindowManager") == 0) {
m@10614
   406
                    // See https://github.com/qtproject/qtwayland/commit/fb4267103d
m@10614
   407
                    flags |= 4 /* QT_EXTENDED_SURFACE_WINDOWFLAG_BYPASSWINDOWMANAGER */;
m@10614
   408
                }
m@10614
   409
m@10614
   410
                flag = strtok_r(NULL, " ", &saveptr);
m@10614
   411
            }
m@10614
   412
m@10614
   413
            free(tmp);
m@10614
   414
        }
m@10614
   415
m@10614
   416
        qt_extended_surface_set_window_flags(qt_extended_surface, flags);
m@10614
   417
    }
m@10614
   418
}
m@10614
   419
m@10614
   420
static void QtExtendedSurface_Subscribe(struct qt_extended_surface *surface, const char *name)
m@10614
   421
{
m@10614
   422
    SDL_AddHintCallback(name, QtExtendedSurface_OnHintChanged, surface);
m@10614
   423
}
m@10614
   424
m@10614
   425
static void QtExtendedSurface_Unsubscribe(struct qt_extended_surface *surface, const char *name)
m@10614
   426
{
m@10614
   427
    SDL_DelHintCallback(name, QtExtendedSurface_OnHintChanged, surface);
m@10614
   428
}
m@10614
   429
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
m@10614
   430
gabomdq@8062
   431
void
gabomdq@8062
   432
Wayland_SetWindowFullscreen(_THIS, SDL_Window * window,
gabomdq@8062
   433
                            SDL_VideoDisplay * _display, SDL_bool fullscreen)
gabomdq@8062
   434
{
icculus@11848
   435
    struct wl_output *output = (struct wl_output *) _display->driverdata;
icculus@11848
   436
    SetFullscreen(_this, window, fullscreen ? output : NULL);
gabomdq@8062
   437
}
gabomdq@8062
   438
slouken@10492
   439
void
slouken@10492
   440
Wayland_RestoreWindow(_THIS, SDL_Window * window)
slouken@10492
   441
{
slouken@10492
   442
    SDL_WindowData *wind = window->driverdata;
icculus@11848
   443
    const SDL_VideoData *viddata = (const SDL_VideoData *) _this->driverdata;
slouken@10492
   444
icculus@12033
   445
    if (viddata->shell.xdg) {
icculus@12033
   446
    } else if (viddata->shell.zxdg) {
icculus@11848
   447
    } else {
icculus@11848
   448
        wl_shell_surface_set_toplevel(wind->shell_surface.wl);
icculus@11848
   449
    }
slouken@10492
   450
slouken@10492
   451
    WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
slouken@10492
   452
}
slouken@10492
   453
slouken@10492
   454
void
slouken@10492
   455
Wayland_MaximizeWindow(_THIS, SDL_Window * window)
slouken@10492
   456
{
slouken@10492
   457
    SDL_WindowData *wind = window->driverdata;
icculus@11848
   458
    SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
slouken@10492
   459
icculus@12033
   460
    if (viddata->shell.xdg) {
icculus@12033
   461
        xdg_toplevel_set_maximized(wind->shell_surface.xdg.roleobj.toplevel);
icculus@12033
   462
    } else if (viddata->shell.zxdg) {
icculus@11848
   463
        zxdg_toplevel_v6_set_maximized(wind->shell_surface.zxdg.roleobj.toplevel);
icculus@11848
   464
    } else {
icculus@11848
   465
        wl_shell_surface_set_maximized(wind->shell_surface.wl, NULL);
icculus@11848
   466
    }
slouken@10492
   467
icculus@11848
   468
    WAYLAND_wl_display_flush( viddata->display );
slouken@10492
   469
}
slouken@10492
   470
gabomdq@8062
   471
int Wayland_CreateWindow(_THIS, SDL_Window *window)
gabomdq@8062
   472
{
gabomdq@8062
   473
    SDL_WindowData *data;
gabomdq@8062
   474
    SDL_VideoData *c;
gabomdq@8062
   475
    struct wl_region *region;
gabomdq@8062
   476
gabomdq@8062
   477
    data = calloc(1, sizeof *data);
gabomdq@8062
   478
    if (data == NULL)
philipp@9483
   479
        return SDL_OutOfMemory();
gabomdq@8062
   480
gabomdq@8062
   481
    c = _this->driverdata;
gabomdq@8062
   482
    window->driverdata = data;
gabomdq@8062
   483
gabomdq@8062
   484
    if (!(window->flags & SDL_WINDOW_OPENGL)) {
gabomdq@8062
   485
        SDL_GL_LoadLibrary(NULL);
gabomdq@8062
   486
        window->flags |= SDL_WINDOW_OPENGL;
gabomdq@8062
   487
    }
gabomdq@8062
   488
gabomdq@8062
   489
    if (window->x == SDL_WINDOWPOS_UNDEFINED) {
gabomdq@8062
   490
        window->x = 0;
gabomdq@8062
   491
    }
gabomdq@8062
   492
    if (window->y == SDL_WINDOWPOS_UNDEFINED) {
gabomdq@8062
   493
        window->y = 0;
gabomdq@8062
   494
    }
gabomdq@8062
   495
gabomdq@8062
   496
    data->waylandData = c;
gabomdq@8062
   497
    data->sdlwindow = window;
gabomdq@8062
   498
gabomdq@8062
   499
    data->surface =
gabomdq@8062
   500
        wl_compositor_create_surface(c->compositor);
gabomdq@8062
   501
    wl_surface_set_user_data(data->surface, data);
icculus@11848
   502
icculus@12033
   503
    if (c->shell.xdg) {
icculus@12033
   504
        data->shell_surface.xdg.surface = xdg_wm_base_get_xdg_surface(c->shell.xdg, data->surface);
icculus@12033
   505
        /* !!! FIXME: add popup role */
icculus@12033
   506
        data->shell_surface.xdg.roleobj.toplevel = xdg_surface_get_toplevel(data->shell_surface.xdg.surface);
icculus@12033
   507
        xdg_toplevel_add_listener(data->shell_surface.xdg.roleobj.toplevel, &toplevel_listener_xdg, data);
icculus@12033
   508
        xdg_toplevel_set_app_id(data->shell_surface.xdg.roleobj.toplevel, c->classname);
icculus@12033
   509
    } else if (c->shell.zxdg) {
icculus@11848
   510
        data->shell_surface.zxdg.surface = zxdg_shell_v6_get_xdg_surface(c->shell.zxdg, data->surface);
icculus@11848
   511
        /* !!! FIXME: add popup role */
icculus@11848
   512
        data->shell_surface.zxdg.roleobj.toplevel = zxdg_surface_v6_get_toplevel(data->shell_surface.zxdg.surface);
icculus@11848
   513
        zxdg_toplevel_v6_add_listener(data->shell_surface.zxdg.roleobj.toplevel, &toplevel_listener_zxdg, data);
icculus@11848
   514
        zxdg_toplevel_v6_set_app_id(data->shell_surface.zxdg.roleobj.toplevel, c->classname);
icculus@11848
   515
    } else {
icculus@11848
   516
        data->shell_surface.wl = wl_shell_get_shell_surface(c->shell.wl, data->surface);
icculus@11848
   517
        wl_shell_surface_set_class(data->shell_surface.wl, c->classname);
icculus@11848
   518
    }
icculus@11848
   519
m@10614
   520
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
gabomdq@8082
   521
    if (c->surface_extension) {
gabomdq@8082
   522
        data->extended_surface = qt_surface_extension_get_extended_surface(
gabomdq@8082
   523
                c->surface_extension, data->surface);
m@10614
   524
m@10614
   525
        QtExtendedSurface_Subscribe(data->extended_surface, SDL_HINT_QTWAYLAND_CONTENT_ORIENTATION);
m@10614
   526
        QtExtendedSurface_Subscribe(data->extended_surface, SDL_HINT_QTWAYLAND_WINDOW_FLAGS);
gabomdq@8082
   527
    }
gabomdq@8082
   528
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
m@8712
   529
gabomdq@8104
   530
    data->egl_window = WAYLAND_wl_egl_window_create(data->surface,
gabomdq@8062
   531
                                            window->w, window->h);
gabomdq@8062
   532
gabomdq@8062
   533
    /* Create the GLES window surface */
gabomdq@8062
   534
    data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->egl_window);
gabomdq@8062
   535
    
gabomdq@8062
   536
    if (data->egl_surface == EGL_NO_SURFACE) {
philipp@9543
   537
        return SDL_SetError("failed to create a window surface");
gabomdq@8062
   538
    }
gabomdq@8062
   539
icculus@12033
   540
    if (c->shell.xdg) {
icculus@12033
   541
        if (data->shell_surface.xdg.surface) {
icculus@12033
   542
            xdg_surface_set_user_data(data->shell_surface.xdg.surface, data);
icculus@12033
   543
            xdg_surface_add_listener(data->shell_surface.xdg.surface, &shell_surface_listener_xdg, data);
icculus@12033
   544
        }
icculus@12033
   545
    } else if (c->shell.zxdg) {
icculus@11848
   546
        if (data->shell_surface.zxdg.surface) {
icculus@11848
   547
            zxdg_surface_v6_set_user_data(data->shell_surface.zxdg.surface, data);
icculus@11848
   548
            zxdg_surface_v6_add_listener(data->shell_surface.zxdg.surface, &shell_surface_listener_zxdg, data);
icculus@11848
   549
        }
icculus@11848
   550
    } else {
icculus@11848
   551
        if (data->shell_surface.wl) {
icculus@11848
   552
            wl_shell_surface_set_user_data(data->shell_surface.wl, data);
icculus@11848
   553
            wl_shell_surface_add_listener(data->shell_surface.wl, &shell_surface_listener_wl, data);
icculus@11848
   554
        }
gabomdq@8062
   555
    }
gabomdq@8062
   556
gabomdq@8082
   557
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
gabomdq@8082
   558
    if (data->extended_surface) {
gabomdq@8082
   559
        qt_extended_surface_set_user_data(data->extended_surface, data);
gabomdq@8082
   560
        qt_extended_surface_add_listener(data->extended_surface,
gabomdq@8082
   561
                                         &extended_surface_listener, data);
gabomdq@8082
   562
    }
gabomdq@8082
   563
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
gabomdq@8082
   564
gabomdq@8062
   565
    region = wl_compositor_create_region(c->compositor);
gabomdq@8062
   566
    wl_region_add(region, 0, 0, window->w, window->h);
gabomdq@8062
   567
    wl_surface_set_opaque_region(data->surface, region);
gabomdq@8062
   568
    wl_region_destroy(region);
gabomdq@8062
   569
slouken@10304
   570
    if (c->relative_mouse_mode) {
slouken@10304
   571
        Wayland_input_lock_pointer(c->input);
slouken@10304
   572
    }
slouken@10304
   573
icculus@11848
   574
    wl_surface_commit(data->surface);
gabomdq@8104
   575
    WAYLAND_wl_display_flush(c->display);
gabomdq@8062
   576
icculus@11944
   577
    /* we have to wait until the surface gets a "configure" event, or
icculus@11944
   578
       use of this surface will fail. This is a new rule for xdg_shell. */
icculus@12033
   579
    if (c->shell.xdg) {
icculus@12033
   580
        if (data->shell_surface.xdg.surface) {
icculus@12033
   581
            while (!data->shell_surface.xdg.initial_configure_seen) {
icculus@12033
   582
                WAYLAND_wl_display_flush(c->display);
icculus@12033
   583
                WAYLAND_wl_display_dispatch(c->display);
icculus@12033
   584
            }
icculus@12033
   585
        }
icculus@12033
   586
    } else if (c->shell.zxdg) {
icculus@11944
   587
        if (data->shell_surface.zxdg.surface) {
icculus@11944
   588
            while (!data->shell_surface.zxdg.initial_configure_seen) {
icculus@11944
   589
                WAYLAND_wl_display_flush(c->display);
icculus@11944
   590
                WAYLAND_wl_display_dispatch(c->display);
icculus@11944
   591
            }
icculus@11944
   592
        }
icculus@11944
   593
    }
icculus@11944
   594
gabomdq@8062
   595
    return 0;
gabomdq@8062
   596
}
gabomdq@8062
   597
gabomdq@8062
   598
void Wayland_SetWindowSize(_THIS, SDL_Window * window)
gabomdq@8062
   599
{
gabomdq@8062
   600
    SDL_VideoData *data = _this->driverdata;
gabomdq@8062
   601
    SDL_WindowData *wind = window->driverdata;
gabomdq@8062
   602
    struct wl_region *region;
gabomdq@8062
   603
gabomdq@8104
   604
    WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
gabomdq@8062
   605
gabomdq@8104
   606
    region =wl_compositor_create_region(data->compositor);
gabomdq@8062
   607
    wl_region_add(region, 0, 0, window->w, window->h);
gabomdq@8062
   608
    wl_surface_set_opaque_region(wind->surface, region);
gabomdq@8062
   609
    wl_region_destroy(region);
gabomdq@8062
   610
}
gabomdq@8062
   611
slouken@10492
   612
void Wayland_SetWindowTitle(_THIS, SDL_Window * window)
slouken@10492
   613
{
slouken@10492
   614
    SDL_WindowData *wind = window->driverdata;
icculus@11848
   615
    SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
slouken@10492
   616
    
slouken@10492
   617
    if (window->title != NULL) {
icculus@12033
   618
        if (viddata->shell.xdg) {
icculus@12033
   619
            xdg_toplevel_set_title(wind->shell_surface.xdg.roleobj.toplevel, window->title);
icculus@12033
   620
        } else if (viddata->shell.zxdg) {
icculus@11848
   621
            zxdg_toplevel_v6_set_title(wind->shell_surface.zxdg.roleobj.toplevel, window->title);
icculus@11848
   622
        } else {
icculus@11848
   623
            wl_shell_surface_set_title(wind->shell_surface.wl, window->title);
icculus@11848
   624
        }
slouken@10492
   625
    }
slouken@10492
   626
slouken@10492
   627
    WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
slouken@10492
   628
}
slouken@10492
   629
gabomdq@8062
   630
void Wayland_DestroyWindow(_THIS, SDL_Window *window)
gabomdq@8062
   631
{
gabomdq@8062
   632
    SDL_VideoData *data = _this->driverdata;
gabomdq@8062
   633
    SDL_WindowData *wind = window->driverdata;
gabomdq@8062
   634
gabomdq@8062
   635
    if (data) {
gabomdq@8062
   636
        SDL_EGL_DestroySurface(_this, wind->egl_surface);
gabomdq@8104
   637
        WAYLAND_wl_egl_window_destroy(wind->egl_window);
gabomdq@8062
   638
icculus@12033
   639
        if (data->shell.xdg) {
icculus@12033
   640
            if (wind->shell_surface.xdg.roleobj.toplevel) {
icculus@12033
   641
                xdg_toplevel_destroy(wind->shell_surface.xdg.roleobj.toplevel);
icculus@12033
   642
            }
icculus@12033
   643
            if (wind->shell_surface.zxdg.surface) {
icculus@12033
   644
                xdg_surface_destroy(wind->shell_surface.xdg.surface);
icculus@12033
   645
            }
icculus@12033
   646
        } else if (data->shell.zxdg) {
icculus@11848
   647
            if (wind->shell_surface.zxdg.roleobj.toplevel) {
icculus@11848
   648
                zxdg_toplevel_v6_destroy(wind->shell_surface.zxdg.roleobj.toplevel);
icculus@11848
   649
            }
icculus@11848
   650
            if (wind->shell_surface.zxdg.surface) {
icculus@11848
   651
                zxdg_surface_v6_destroy(wind->shell_surface.zxdg.surface);
icculus@11848
   652
            }
icculus@11848
   653
        } else {
icculus@11848
   654
            if (wind->shell_surface.wl) {
icculus@11848
   655
                wl_shell_surface_destroy(wind->shell_surface.wl);
icculus@11848
   656
            }
icculus@11848
   657
        }
gabomdq@8062
   658
gabomdq@8082
   659
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
m@10614
   660
        if (wind->extended_surface) {
m@10614
   661
            QtExtendedSurface_Unsubscribe(wind->extended_surface, SDL_HINT_QTWAYLAND_CONTENT_ORIENTATION);
m@10614
   662
            QtExtendedSurface_Unsubscribe(wind->extended_surface, SDL_HINT_QTWAYLAND_WINDOW_FLAGS);
gabomdq@8082
   663
            qt_extended_surface_destroy(wind->extended_surface);
m@10614
   664
        }
gabomdq@8082
   665
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
gabomdq@8062
   666
        wl_surface_destroy(wind->surface);
gabomdq@8062
   667
gabomdq@8062
   668
        SDL_free(wind);
gabomdq@8104
   669
        WAYLAND_wl_display_flush(data->display);
gabomdq@8062
   670
    }
slouken@8978
   671
    window->driverdata = NULL;
gabomdq@8062
   672
}
gabomdq@8062
   673
icculus@8116
   674
#endif /* SDL_VIDEO_DRIVER_WAYLAND && SDL_VIDEO_OPENGL_EGL */
icculus@8116
   675
gabomdq@8062
   676
/* vi: set ts=4 sw=4 expandtab: */