src/video/wayland/SDL_waylandwindow.c
author Ryan C. Gordon <icculus@icculus.org>
Wed, 19 Jun 2019 00:52:34 -0400
changeset 12889 32d98e72ed94
parent 12844 d92b5fbb5ac0
permissions -rw-r--r--
wayland: Fixed C99-style variable declaration inside for-loop.
gabomdq@8062
     1
/*
gabomdq@8062
     2
  Simple DirectMedia Layer
slouken@12503
     3
  Copyright (C) 1997-2019 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"
dos@12426
    38
#include "xdg-decoration-unstable-v1-client-protocol.h"
icculus@12367
    39
#include "org-kde-kwin-server-decoration-manager-client-protocol.h"
icculus@11848
    40
dos@12844
    41
static float get_window_scale_factor(SDL_Window *window) {
dos@12844
    42
      return ((SDL_WindowData*)window->driverdata)->scale_factor;
dos@12844
    43
}
dos@12844
    44
icculus@11848
    45
/* On modern desktops, we probably will use the xdg-shell protocol instead
icculus@11848
    46
   of wl_shell, but wl_shell might be useful on older Wayland installs that
icculus@11848
    47
   don't have the newer protocol, or embedded things that don't have a full
icculus@11848
    48
   window manager. */
icculus@11848
    49
gabomdq@8062
    50
static void
icculus@11848
    51
handle_ping_wl_shell_surface(void *data, struct wl_shell_surface *shell_surface,
gabomdq@8062
    52
            uint32_t serial)
gabomdq@8062
    53
{
gabomdq@8062
    54
    wl_shell_surface_pong(shell_surface, serial);
gabomdq@8062
    55
}
gabomdq@8062
    56
gabomdq@8062
    57
static void
icculus@11848
    58
handle_configure_wl_shell_surface(void *data, struct wl_shell_surface *shell_surface,
gabomdq@8062
    59
                 uint32_t edges, int32_t width, int32_t height)
gabomdq@8062
    60
{
gabomdq@8766
    61
    SDL_WindowData *wind = (SDL_WindowData *)data;
gabomdq@8766
    62
    SDL_Window *window = wind->sdlwindow;
gabomdq@8766
    63
slouken@10492
    64
    /* wl_shell_surface spec states that this is a suggestion.
slouken@10492
    65
       Ignore if less than or greater than max/min size. */
slouken@10492
    66
slouken@10492
    67
    if (width == 0 || height == 0) {
slouken@10492
    68
        return;
slouken@10492
    69
    }
slouken@10492
    70
slouken@10492
    71
    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
slouken@10492
    72
        if ((window->flags & SDL_WINDOW_RESIZABLE)) {
slouken@10492
    73
            if (window->max_w > 0) {
slouken@10492
    74
                width = SDL_min(width, window->max_w);
dos@12400
    75
            }
slouken@10492
    76
            width = SDL_max(width, window->min_w);
slouken@10492
    77
slouken@10492
    78
            if (window->max_h > 0) {
slouken@10492
    79
                height = SDL_min(height, window->max_h);
slouken@10492
    80
            }
slouken@10492
    81
            height = SDL_max(height, window->min_h);
slouken@10492
    82
        } else {
slouken@10492
    83
            return;
slouken@10492
    84
        }
slouken@10492
    85
    }
slouken@10492
    86
dos@12400
    87
    wind->resize.width = width;
dos@12400
    88
    wind->resize.height = height;
dos@12400
    89
    wind->resize.pending = SDL_TRUE;
gabomdq@8062
    90
}
gabomdq@8062
    91
gabomdq@8062
    92
static void
icculus@11848
    93
handle_popup_done_wl_shell_surface(void *data, struct wl_shell_surface *shell_surface)
gabomdq@8062
    94
{
gabomdq@8062
    95
}
gabomdq@8062
    96
icculus@11848
    97
static const struct wl_shell_surface_listener shell_surface_listener_wl = {
icculus@11848
    98
    handle_ping_wl_shell_surface,
icculus@11848
    99
    handle_configure_wl_shell_surface,
icculus@11848
   100
    handle_popup_done_wl_shell_surface
gabomdq@8062
   101
};
gabomdq@8062
   102
icculus@11848
   103
icculus@11848
   104
icculus@11848
   105
icculus@11848
   106
static void
icculus@11848
   107
handle_configure_zxdg_shell_surface(void *data, struct zxdg_surface_v6 *zxdg, uint32_t serial)
icculus@11848
   108
{
icculus@11848
   109
    SDL_WindowData *wind = (SDL_WindowData *)data;
icculus@11848
   110
    SDL_Window *window = wind->sdlwindow;
icculus@11848
   111
    struct wl_region *region;
icculus@11944
   112
dos@12400
   113
    if (!wind->shell_surface.zxdg.initial_configure_seen) {
dos@12844
   114
        window->w = 0;
dos@12844
   115
        window->h = 0;
dos@12400
   116
        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, wind->resize.width, wind->resize.height);
dos@12400
   117
        window->w = wind->resize.width;
dos@12400
   118
        window->h = wind->resize.height;
icculus@11944
   119
dos@12844
   120
        wl_surface_set_buffer_scale(wind->surface, get_window_scale_factor(window));
dos@12844
   121
        WAYLAND_wl_egl_window_resize(wind->egl_window, window->w * get_window_scale_factor(window), window->h * get_window_scale_factor(window), 0, 0);
icculus@11848
   122
dos@12400
   123
        zxdg_surface_v6_ack_configure(zxdg, serial);
dos@12400
   124
dos@12400
   125
        region = wl_compositor_create_region(wind->waylandData->compositor);
dos@12400
   126
        wl_region_add(region, 0, 0, window->w, window->h);
dos@12400
   127
        wl_surface_set_opaque_region(wind->surface, region);
dos@12400
   128
        wl_region_destroy(region);
dos@12400
   129
dos@12400
   130
        wind->shell_surface.zxdg.initial_configure_seen = SDL_TRUE;
dos@12400
   131
    } else {
dos@12400
   132
        wind->resize.pending = SDL_TRUE;
dos@12844
   133
        wind->resize.configure = SDL_TRUE;
dos@12400
   134
        wind->resize.serial = serial;
dos@12400
   135
    }
icculus@11848
   136
}
icculus@11848
   137
icculus@11848
   138
static const struct zxdg_surface_v6_listener shell_surface_listener_zxdg = {
icculus@11848
   139
    handle_configure_zxdg_shell_surface
icculus@11848
   140
};
icculus@11848
   141
icculus@11848
   142
icculus@11848
   143
static void
icculus@11848
   144
handle_configure_zxdg_toplevel(void *data,
slouken@12201
   145
              struct zxdg_toplevel_v6 *zxdg_toplevel_v6,
slouken@12201
   146
              int32_t width,
slouken@12201
   147
              int32_t height,
slouken@12201
   148
              struct wl_array *states)
icculus@12033
   149
{
icculus@12033
   150
    SDL_WindowData *wind = (SDL_WindowData *)data;
icculus@12033
   151
    SDL_Window *window = wind->sdlwindow;
icculus@12033
   152
dos@12400
   153
    enum zxdg_toplevel_v6_state *state;
dos@12400
   154
    SDL_bool fullscreen = SDL_FALSE;
dos@12400
   155
    wl_array_for_each(state, states) {
dos@12400
   156
        if (*state == ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN) {
dos@12400
   157
            fullscreen = SDL_TRUE;
dos@12400
   158
        }
icculus@12033
   159
    }
icculus@12033
   160
dos@12400
   161
    if (!fullscreen) {
dos@12400
   162
        if (width == 0 || height == 0) {
dos@12400
   163
            width = window->windowed.w;
dos@12400
   164
            height = window->windowed.h;
dos@12400
   165
        }
dos@12400
   166
dos@12400
   167
        /* zxdg_toplevel spec states that this is a suggestion.
dos@12400
   168
           Ignore if less than or greater than max/min size. */
dos@12400
   169
icculus@12033
   170
        if ((window->flags & SDL_WINDOW_RESIZABLE)) {
icculus@12033
   171
            if (window->max_w > 0) {
icculus@12033
   172
                width = SDL_min(width, window->max_w);
dos@12400
   173
            }
icculus@12033
   174
            width = SDL_max(width, window->min_w);
icculus@12033
   175
icculus@12033
   176
            if (window->max_h > 0) {
icculus@12033
   177
                height = SDL_min(height, window->max_h);
icculus@12033
   178
            }
icculus@12033
   179
            height = SDL_max(height, window->min_h);
icculus@12033
   180
        } else {
dos@12400
   181
            wind->resize.width = window->w;
dos@12400
   182
            wind->resize.height = window->h;
icculus@12033
   183
            return;
icculus@12033
   184
        }
icculus@12033
   185
    }
icculus@12033
   186
dos@12400
   187
    if (width == 0 || height == 0) {
dos@12400
   188
        wind->resize.width = window->w;
dos@12400
   189
        wind->resize.height = window->h;
dos@12400
   190
        return;
dos@12400
   191
    }
dos@12400
   192
dos@12400
   193
    wind->resize.width = width;
dos@12400
   194
    wind->resize.height = height;
icculus@12033
   195
}
icculus@12033
   196
icculus@12033
   197
static void
icculus@12033
   198
handle_close_zxdg_toplevel(void *data, struct zxdg_toplevel_v6 *zxdg_toplevel_v6)
icculus@12033
   199
{
icculus@12033
   200
    SDL_WindowData *window = (SDL_WindowData *)data;
icculus@12033
   201
    SDL_SendWindowEvent(window->sdlwindow, SDL_WINDOWEVENT_CLOSE, 0, 0);
icculus@12033
   202
}
icculus@12033
   203
icculus@12033
   204
static const struct zxdg_toplevel_v6_listener toplevel_listener_zxdg = {
icculus@12033
   205
    handle_configure_zxdg_toplevel,
icculus@12033
   206
    handle_close_zxdg_toplevel
icculus@12033
   207
};
icculus@12033
   208
icculus@12033
   209
icculus@12033
   210
icculus@12033
   211
static void
icculus@12033
   212
handle_configure_xdg_shell_surface(void *data, struct xdg_surface *xdg, uint32_t serial)
icculus@12033
   213
{
icculus@12033
   214
    SDL_WindowData *wind = (SDL_WindowData *)data;
icculus@12033
   215
    SDL_Window *window = wind->sdlwindow;
icculus@12033
   216
    struct wl_region *region;
icculus@12033
   217
dos@12400
   218
    if (!wind->shell_surface.xdg.initial_configure_seen) {
dos@12844
   219
        window->w = 0;
dos@12844
   220
        window->h = 0;
dos@12400
   221
        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, wind->resize.width, wind->resize.height);
dos@12400
   222
        window->w = wind->resize.width;
dos@12400
   223
        window->h = wind->resize.height;
icculus@12033
   224
dos@12844
   225
        wl_surface_set_buffer_scale(wind->surface, get_window_scale_factor(window));
dos@12844
   226
        WAYLAND_wl_egl_window_resize(wind->egl_window, window->w * get_window_scale_factor(window), window->h * get_window_scale_factor(window), 0, 0);
icculus@12033
   227
dos@12400
   228
        xdg_surface_ack_configure(xdg, serial);
dos@12400
   229
dos@12400
   230
        region = wl_compositor_create_region(wind->waylandData->compositor);
dos@12400
   231
        wl_region_add(region, 0, 0, window->w, window->h);
dos@12400
   232
        wl_surface_set_opaque_region(wind->surface, region);
dos@12400
   233
        wl_region_destroy(region);
dos@12400
   234
dos@12400
   235
        wind->shell_surface.xdg.initial_configure_seen = SDL_TRUE;
dos@12400
   236
    } else {
dos@12400
   237
        wind->resize.pending = SDL_TRUE;
dos@12844
   238
        wind->resize.configure = SDL_TRUE;
dos@12400
   239
        wind->resize.serial = serial;
dos@12400
   240
    }
icculus@12033
   241
}
icculus@12033
   242
icculus@12033
   243
static const struct xdg_surface_listener shell_surface_listener_xdg = {
icculus@12033
   244
    handle_configure_xdg_shell_surface
icculus@12033
   245
};
icculus@12033
   246
icculus@12033
   247
icculus@12033
   248
static void
icculus@12033
   249
handle_configure_xdg_toplevel(void *data,
slouken@12201
   250
              struct xdg_toplevel *xdg_toplevel,
slouken@12201
   251
              int32_t width,
slouken@12201
   252
              int32_t height,
slouken@12201
   253
              struct wl_array *states)
icculus@11848
   254
{
icculus@11848
   255
    SDL_WindowData *wind = (SDL_WindowData *)data;
icculus@11848
   256
    SDL_Window *window = wind->sdlwindow;
icculus@11848
   257
dos@12400
   258
    enum xdg_toplevel_state *state;
dos@12400
   259
    SDL_bool fullscreen = SDL_FALSE;
dos@12400
   260
    wl_array_for_each(state, states) {
dos@12400
   261
        if (*state == XDG_TOPLEVEL_STATE_FULLSCREEN) {
dos@12400
   262
            fullscreen = SDL_TRUE;
dos@12400
   263
        }
dos@12400
   264
     }
icculus@11848
   265
dos@12400
   266
    if (!fullscreen) {
dos@12400
   267
        if (width == 0 || height == 0) {
dos@12400
   268
            width = window->windowed.w;
dos@12400
   269
            height = window->windowed.h;
dos@12400
   270
        }
icculus@11848
   271
dos@12400
   272
        /* xdg_toplevel spec states that this is a suggestion.
dos@12400
   273
           Ignore if less than or greater than max/min size. */
dos@12400
   274
icculus@11848
   275
        if ((window->flags & SDL_WINDOW_RESIZABLE)) {
icculus@11848
   276
            if (window->max_w > 0) {
icculus@11848
   277
                width = SDL_min(width, window->max_w);
dos@12400
   278
            }
icculus@11848
   279
            width = SDL_max(width, window->min_w);
icculus@11848
   280
icculus@11848
   281
            if (window->max_h > 0) {
icculus@11848
   282
                height = SDL_min(height, window->max_h);
icculus@11848
   283
            }
icculus@11848
   284
            height = SDL_max(height, window->min_h);
icculus@11848
   285
        } else {
dos@12400
   286
            wind->resize.width = window->w;
dos@12400
   287
            wind->resize.height = window->h;
icculus@11848
   288
            return;
icculus@11848
   289
        }
icculus@11848
   290
    }
icculus@11848
   291
dos@12400
   292
    if (width == 0 || height == 0) {
dos@12400
   293
        wind->resize.width = window->w;
dos@12400
   294
        wind->resize.height = window->h;
icculus@11848
   295
        return;
icculus@11848
   296
    }
icculus@11848
   297
dos@12400
   298
    wind->resize.width = width;
dos@12400
   299
    wind->resize.height = height;
icculus@12033
   300
}
icculus@12033
   301
icculus@12033
   302
static void
icculus@12033
   303
handle_close_xdg_toplevel(void *data, struct xdg_toplevel *xdg_toplevel)
icculus@12033
   304
{
icculus@12033
   305
    SDL_WindowData *window = (SDL_WindowData *)data;
icculus@12033
   306
    SDL_SendWindowEvent(window->sdlwindow, SDL_WINDOWEVENT_CLOSE, 0, 0);
icculus@12033
   307
}
icculus@12033
   308
icculus@12033
   309
static const struct xdg_toplevel_listener toplevel_listener_xdg = {
icculus@12033
   310
    handle_configure_xdg_toplevel,
icculus@12033
   311
    handle_close_xdg_toplevel
icculus@12033
   312
};
icculus@12033
   313
icculus@12033
   314
icculus@12033
   315
icculus@12033
   316
gabomdq@8082
   317
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
gabomdq@8082
   318
static void
gabomdq@8082
   319
handle_onscreen_visibility(void *data,
gabomdq@8082
   320
        struct qt_extended_surface *qt_extended_surface, int32_t visible)
gabomdq@8082
   321
{
gabomdq@8082
   322
}
gabomdq@8082
   323
gabomdq@8082
   324
static void
gabomdq@8082
   325
handle_set_generic_property(void *data,
gabomdq@8082
   326
        struct qt_extended_surface *qt_extended_surface, const char *name,
gabomdq@8082
   327
        struct wl_array *value)
gabomdq@8082
   328
{
gabomdq@8082
   329
}
gabomdq@8082
   330
gabomdq@8082
   331
static void
gabomdq@8082
   332
handle_close(void *data, struct qt_extended_surface *qt_extended_surface)
gabomdq@8082
   333
{
gabomdq@8082
   334
    SDL_WindowData *window = (SDL_WindowData *)data;
gabomdq@8082
   335
    SDL_SendWindowEvent(window->sdlwindow, SDL_WINDOWEVENT_CLOSE, 0, 0);
gabomdq@8082
   336
}
gabomdq@8082
   337
gabomdq@8082
   338
static const struct qt_extended_surface_listener extended_surface_listener = {
gabomdq@8082
   339
    handle_onscreen_visibility,
gabomdq@8082
   340
    handle_set_generic_property,
gabomdq@8082
   341
    handle_close,
gabomdq@8082
   342
};
gabomdq@8082
   343
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
gabomdq@8082
   344
dos@12844
   345
static void
dos@12844
   346
update_scale_factor(SDL_WindowData *window) {
dos@12844
   347
   float old_factor = window->scale_factor, new_factor = 0.0;
icculus@12889
   348
   int i;
dos@12844
   349
dos@12844
   350
   if (!(window->sdlwindow->flags & SDL_WINDOW_ALLOW_HIGHDPI)) {
dos@12844
   351
       return;
dos@12844
   352
   }
dos@12844
   353
dos@12844
   354
   if (!window->num_outputs) {
dos@12844
   355
       new_factor = old_factor;
dos@12844
   356
   }
dos@12844
   357
dos@12844
   358
   if (FULLSCREEN_VISIBLE(window->sdlwindow) && window->sdlwindow->fullscreen_mode.driverdata) {
dos@12844
   359
       new_factor = ((SDL_WaylandOutputData*)(wl_output_get_user_data(window->sdlwindow->fullscreen_mode.driverdata)))->scale_factor;
dos@12844
   360
   }
dos@12844
   361
icculus@12889
   362
   for (i = 0; i < window->num_outputs; i++) {
dos@12844
   363
       float factor = ((SDL_WaylandOutputData*)(wl_output_get_user_data(window->outputs[i])))->scale_factor;
dos@12844
   364
       if (factor > new_factor) {
dos@12844
   365
           new_factor = factor;
dos@12844
   366
       }
dos@12844
   367
   }
dos@12844
   368
dos@12844
   369
   if (new_factor != old_factor) {
dos@12844
   370
       /* force the resize event to trigger, as the logical size didn't change */
dos@12844
   371
       window->resize.width = window->sdlwindow->w;
dos@12844
   372
       window->resize.height = window->sdlwindow->h;
dos@12844
   373
       window->resize.scale_factor = new_factor;
dos@12844
   374
       window->resize.pending = SDL_TRUE;
dos@12844
   375
   }
dos@12844
   376
}
dos@12844
   377
dos@12844
   378
static void
dos@12844
   379
handle_surface_enter(void *data, struct wl_surface *surface,
dos@12844
   380
        struct wl_output *output) {
dos@12844
   381
    SDL_WindowData *window = data;
dos@12844
   382
dos@12844
   383
    window->outputs = SDL_realloc(window->outputs, (window->num_outputs + 1) * sizeof *window->outputs);
dos@12844
   384
    window->outputs[window->num_outputs++] = output;
dos@12844
   385
    update_scale_factor(window);
dos@12844
   386
}
dos@12844
   387
dos@12844
   388
static void
dos@12844
   389
handle_surface_leave(void *data, struct wl_surface *surface,
dos@12844
   390
        struct wl_output *output) {
dos@12844
   391
    SDL_WindowData *window = data;
icculus@12889
   392
    int i;
dos@12844
   393
dos@12844
   394
    if (window->num_outputs > 1) {
dos@12844
   395
       struct wl_output **new_outputs = SDL_malloc((window->num_outputs - 1) * sizeof *window->outputs), **iter = new_outputs;
icculus@12889
   396
       for (i=0; i < window->num_outputs; i++) {
dos@12844
   397
           if (window->outputs[i] != output) {
dos@12844
   398
               *iter = window->outputs[i];
dos@12844
   399
               iter++;
dos@12844
   400
           }
dos@12844
   401
       }
dos@12844
   402
       SDL_free(window->outputs);
dos@12844
   403
       window->outputs = new_outputs;
dos@12844
   404
       window->num_outputs--;
dos@12844
   405
    } else {
dos@12844
   406
       window->num_outputs = 0;
dos@12844
   407
       SDL_free(window->outputs);
dos@12844
   408
       window->outputs = NULL;
dos@12844
   409
    }
dos@12844
   410
dos@12844
   411
    update_scale_factor(window);
dos@12844
   412
}
dos@12844
   413
dos@12844
   414
static const struct wl_surface_listener surface_listener = {
dos@12844
   415
    handle_surface_enter,
dos@12844
   416
    handle_surface_leave
dos@12844
   417
};
dos@12844
   418
gabomdq@8062
   419
SDL_bool
gabomdq@8062
   420
Wayland_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
gabomdq@8062
   421
{
gabomdq@8062
   422
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
icculus@11088
   423
    const Uint32 version = ((((Uint32) info->version.major) * 1000000) +
icculus@11088
   424
                            (((Uint32) info->version.minor) * 10000) +
icculus@11088
   425
                            (((Uint32) info->version.patch)));
icculus@11088
   426
icculus@11088
   427
    /* Before 2.0.6, it was possible to build an SDL with Wayland support
icculus@11088
   428
       (SDL_SysWMinfo will be large enough to hold Wayland info), but build
icculus@11088
   429
       your app against SDL headers that didn't have Wayland support
icculus@11088
   430
       (SDL_SysWMinfo could be smaller than Wayland needs. This would lead
icculus@11088
   431
       to an app properly using SDL_GetWindowWMInfo() but we'd accidentally
icculus@11088
   432
       overflow memory on the stack or heap. To protect against this, we've
icculus@11088
   433
       padded out the struct unconditionally in the headers and Wayland will
icculus@11088
   434
       just return an error for older apps using this function. Those apps
icculus@11088
   435
       will need to be recompiled against newer headers or not use Wayland,
icculus@11088
   436
       maybe by forcing SDL_VIDEODRIVER=x11. */
icculus@11088
   437
    if (version < 2000006) {
icculus@11088
   438
        info->subsystem = SDL_SYSWM_UNKNOWN;
philipp@11092
   439
        SDL_SetError("Version must be 2.0.6 or newer");
icculus@11088
   440
        return SDL_FALSE;
icculus@11088
   441
    }
gabomdq@8062
   442
gabomdq@8062
   443
    info->info.wl.display = data->waylandData->display;
gabomdq@8062
   444
    info->info.wl.surface = data->surface;
icculus@11848
   445
    info->info.wl.shell_surface = data->shell_surface.wl;
gabomdq@8062
   446
    info->subsystem = SDL_SYSWM_WAYLAND;
gabomdq@8062
   447
gabomdq@8062
   448
    return SDL_TRUE;
gabomdq@8062
   449
}
gabomdq@8062
   450
icculus@9554
   451
int
icculus@9554
   452
Wayland_SetWindowHitTest(SDL_Window *window, SDL_bool enabled)
icculus@9554
   453
{
icculus@9554
   454
    return 0;  /* just succeed, the real work is done elsewhere. */
icculus@9554
   455
}
icculus@9554
   456
icculus@11848
   457
static void
icculus@11848
   458
SetFullscreen(_THIS, SDL_Window * window, struct wl_output *output)
icculus@11848
   459
{
icculus@11848
   460
    const SDL_VideoData *viddata = (const SDL_VideoData *) _this->driverdata;
icculus@11848
   461
    SDL_WindowData *wind = window->driverdata;
icculus@11848
   462
icculus@12033
   463
    if (viddata->shell.xdg) {
icculus@12033
   464
        if (output) {
icculus@12033
   465
            xdg_toplevel_set_fullscreen(wind->shell_surface.xdg.roleobj.toplevel, output);
icculus@12033
   466
        } else {
icculus@12033
   467
            xdg_toplevel_unset_fullscreen(wind->shell_surface.xdg.roleobj.toplevel);
icculus@12033
   468
        }
icculus@12033
   469
    } else if (viddata->shell.zxdg) {
icculus@11848
   470
        if (output) {
icculus@11848
   471
            zxdg_toplevel_v6_set_fullscreen(wind->shell_surface.zxdg.roleobj.toplevel, output);
icculus@11848
   472
        } else {
icculus@11848
   473
            zxdg_toplevel_v6_unset_fullscreen(wind->shell_surface.zxdg.roleobj.toplevel);
icculus@11848
   474
        }
icculus@11848
   475
    } else {
icculus@11848
   476
        if (output) {
icculus@11848
   477
            wl_shell_surface_set_fullscreen(wind->shell_surface.wl,
icculus@11848
   478
                                            WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
icculus@11848
   479
                                            0, output);
icculus@11848
   480
        } else {
icculus@11848
   481
            wl_shell_surface_set_toplevel(wind->shell_surface.wl);
icculus@11848
   482
        }
icculus@11848
   483
    }
icculus@11848
   484
icculus@11848
   485
    WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
icculus@11848
   486
}
icculus@11848
   487
gabomdq@8062
   488
void Wayland_ShowWindow(_THIS, SDL_Window *window)
gabomdq@8062
   489
{
icculus@11848
   490
    struct wl_output *output = (struct wl_output *) window->fullscreen_mode.driverdata;
icculus@11848
   491
    SetFullscreen(_this, window, (window->flags & SDL_WINDOW_FULLSCREEN) ? output : NULL);
gabomdq@8062
   492
}
gabomdq@8062
   493
m@10614
   494
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
slouken@11284
   495
static void SDLCALL
slouken@11284
   496
QtExtendedSurface_OnHintChanged(void *userdata, const char *name,
m@10614
   497
        const char *oldValue, const char *newValue)
m@10614
   498
{
m@10614
   499
    struct qt_extended_surface *qt_extended_surface = userdata;
m@10614
   500
m@10614
   501
    if (name == NULL) {
m@10614
   502
        return;
m@10614
   503
    }
m@10614
   504
m@10614
   505
    if (strcmp(name, SDL_HINT_QTWAYLAND_CONTENT_ORIENTATION) == 0) {
m@10614
   506
        int32_t orientation = QT_EXTENDED_SURFACE_ORIENTATION_PRIMARYORIENTATION;
m@10614
   507
m@10614
   508
        if (newValue != NULL) {
m@10614
   509
            if (strcmp(newValue, "portrait") == 0) {
m@10614
   510
                orientation = QT_EXTENDED_SURFACE_ORIENTATION_PORTRAITORIENTATION;
m@10614
   511
            } else if (strcmp(newValue, "landscape") == 0) {
m@10614
   512
                orientation = QT_EXTENDED_SURFACE_ORIENTATION_LANDSCAPEORIENTATION;
m@10614
   513
            } else if (strcmp(newValue, "inverted-portrait") == 0) {
m@10614
   514
                orientation = QT_EXTENDED_SURFACE_ORIENTATION_INVERTEDPORTRAITORIENTATION;
m@10614
   515
            } else if (strcmp(newValue, "inverted-landscape") == 0) {
m@10614
   516
                orientation = QT_EXTENDED_SURFACE_ORIENTATION_INVERTEDLANDSCAPEORIENTATION;
m@10614
   517
            }
m@10614
   518
        }
m@10614
   519
m@10614
   520
        qt_extended_surface_set_content_orientation(qt_extended_surface, orientation);
m@10614
   521
    } else if (strcmp(name, SDL_HINT_QTWAYLAND_WINDOW_FLAGS) == 0) {
m@10614
   522
        uint32_t flags = 0;
m@10614
   523
m@10614
   524
        if (newValue != NULL) {
m@10614
   525
            char *tmp = strdup(newValue);
m@10614
   526
            char *saveptr = NULL;
m@10614
   527
m@10614
   528
            char *flag = strtok_r(tmp, " ", &saveptr);
m@10614
   529
            while (flag) {
m@10614
   530
                if (strcmp(flag, "OverridesSystemGestures") == 0) {
m@10614
   531
                    flags |= QT_EXTENDED_SURFACE_WINDOWFLAG_OVERRIDESSYSTEMGESTURES;
m@10614
   532
                } else if (strcmp(flag, "StaysOnTop") == 0) {
m@10614
   533
                    flags |= QT_EXTENDED_SURFACE_WINDOWFLAG_STAYSONTOP;
m@10614
   534
                } else if (strcmp(flag, "BypassWindowManager") == 0) {
m@10614
   535
                    // See https://github.com/qtproject/qtwayland/commit/fb4267103d
m@10614
   536
                    flags |= 4 /* QT_EXTENDED_SURFACE_WINDOWFLAG_BYPASSWINDOWMANAGER */;
m@10614
   537
                }
m@10614
   538
m@10614
   539
                flag = strtok_r(NULL, " ", &saveptr);
m@10614
   540
            }
m@10614
   541
m@10614
   542
            free(tmp);
m@10614
   543
        }
m@10614
   544
m@10614
   545
        qt_extended_surface_set_window_flags(qt_extended_surface, flags);
m@10614
   546
    }
m@10614
   547
}
m@10614
   548
m@10614
   549
static void QtExtendedSurface_Subscribe(struct qt_extended_surface *surface, const char *name)
m@10614
   550
{
m@10614
   551
    SDL_AddHintCallback(name, QtExtendedSurface_OnHintChanged, surface);
m@10614
   552
}
m@10614
   553
m@10614
   554
static void QtExtendedSurface_Unsubscribe(struct qt_extended_surface *surface, const char *name)
m@10614
   555
{
m@10614
   556
    SDL_DelHintCallback(name, QtExtendedSurface_OnHintChanged, surface);
m@10614
   557
}
m@10614
   558
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
m@10614
   559
gabomdq@8062
   560
void
gabomdq@8062
   561
Wayland_SetWindowFullscreen(_THIS, SDL_Window * window,
gabomdq@8062
   562
                            SDL_VideoDisplay * _display, SDL_bool fullscreen)
gabomdq@8062
   563
{
dos@12844
   564
    struct wl_output *output = ((SDL_WaylandOutputData*) _display->driverdata)->output;
icculus@11848
   565
    SetFullscreen(_this, window, fullscreen ? output : NULL);
gabomdq@8062
   566
}
gabomdq@8062
   567
slouken@10492
   568
void
slouken@10492
   569
Wayland_RestoreWindow(_THIS, SDL_Window * window)
slouken@10492
   570
{
slouken@10492
   571
    SDL_WindowData *wind = window->driverdata;
icculus@11848
   572
    const SDL_VideoData *viddata = (const SDL_VideoData *) _this->driverdata;
slouken@10492
   573
icculus@12033
   574
    if (viddata->shell.xdg) {
icculus@12033
   575
    } else if (viddata->shell.zxdg) {
icculus@11848
   576
    } else {
icculus@11848
   577
        wl_shell_surface_set_toplevel(wind->shell_surface.wl);
icculus@11848
   578
    }
slouken@10492
   579
slouken@10492
   580
    WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
slouken@10492
   581
}
slouken@10492
   582
slouken@10492
   583
void
icculus@12367
   584
Wayland_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
icculus@12367
   585
{
icculus@12367
   586
    SDL_WindowData *wind = window->driverdata;
icculus@12367
   587
    const SDL_VideoData *viddata = (const SDL_VideoData *) _this->driverdata;
dos@12426
   588
    if ((viddata->decoration_manager) && (wind->server_decoration)) {
dos@12426
   589
        const enum zxdg_toplevel_decoration_v1_mode mode = bordered ? ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE : ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE;
dos@12426
   590
        zxdg_toplevel_decoration_v1_set_mode(wind->server_decoration, mode);
dos@12426
   591
    } else if ((viddata->kwin_server_decoration_manager) && (wind->kwin_server_decoration)) {
icculus@12367
   592
        const enum org_kde_kwin_server_decoration_mode mode = bordered ? ORG_KDE_KWIN_SERVER_DECORATION_MANAGER_MODE_SERVER : ORG_KDE_KWIN_SERVER_DECORATION_MANAGER_MODE_NONE;
icculus@12367
   593
        org_kde_kwin_server_decoration_request_mode(wind->kwin_server_decoration, mode);
icculus@12367
   594
    }
icculus@12367
   595
}
icculus@12367
   596
icculus@12367
   597
void
slouken@10492
   598
Wayland_MaximizeWindow(_THIS, SDL_Window * window)
slouken@10492
   599
{
slouken@10492
   600
    SDL_WindowData *wind = window->driverdata;
icculus@11848
   601
    SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
slouken@10492
   602
icculus@12033
   603
    if (viddata->shell.xdg) {
icculus@12033
   604
        xdg_toplevel_set_maximized(wind->shell_surface.xdg.roleobj.toplevel);
icculus@12033
   605
    } else if (viddata->shell.zxdg) {
icculus@11848
   606
        zxdg_toplevel_v6_set_maximized(wind->shell_surface.zxdg.roleobj.toplevel);
icculus@11848
   607
    } else {
icculus@11848
   608
        wl_shell_surface_set_maximized(wind->shell_surface.wl, NULL);
icculus@11848
   609
    }
slouken@10492
   610
icculus@11848
   611
    WAYLAND_wl_display_flush( viddata->display );
slouken@10492
   612
}
slouken@10492
   613
gabomdq@8062
   614
int Wayland_CreateWindow(_THIS, SDL_Window *window)
gabomdq@8062
   615
{
gabomdq@8062
   616
    SDL_WindowData *data;
gabomdq@8062
   617
    SDL_VideoData *c;
gabomdq@8062
   618
    struct wl_region *region;
gabomdq@8062
   619
gabomdq@8062
   620
    data = calloc(1, sizeof *data);
gabomdq@8062
   621
    if (data == NULL)
philipp@9483
   622
        return SDL_OutOfMemory();
gabomdq@8062
   623
gabomdq@8062
   624
    c = _this->driverdata;
gabomdq@8062
   625
    window->driverdata = data;
gabomdq@8062
   626
gabomdq@8062
   627
    if (!(window->flags & SDL_WINDOW_OPENGL)) {
gabomdq@8062
   628
        SDL_GL_LoadLibrary(NULL);
gabomdq@8062
   629
        window->flags |= SDL_WINDOW_OPENGL;
gabomdq@8062
   630
    }
gabomdq@8062
   631
gabomdq@8062
   632
    if (window->x == SDL_WINDOWPOS_UNDEFINED) {
gabomdq@8062
   633
        window->x = 0;
gabomdq@8062
   634
    }
gabomdq@8062
   635
    if (window->y == SDL_WINDOWPOS_UNDEFINED) {
gabomdq@8062
   636
        window->y = 0;
gabomdq@8062
   637
    }
gabomdq@8062
   638
gabomdq@8062
   639
    data->waylandData = c;
gabomdq@8062
   640
    data->sdlwindow = window;
gabomdq@8062
   641
dos@12844
   642
    data->scale_factor = 1.0;
dos@12844
   643
dos@12844
   644
    if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
icculus@12889
   645
        int i;
icculus@12889
   646
        for (i=0; i < SDL_GetVideoDevice()->num_displays; i++) {
dos@12844
   647
            float scale = ((SDL_WaylandOutputData*)SDL_GetVideoDevice()->displays[i].driverdata)->scale_factor;
dos@12844
   648
            if (scale > data->scale_factor) {
dos@12844
   649
                data->scale_factor = scale;
dos@12844
   650
            }
dos@12844
   651
        }
dos@12844
   652
    }
dos@12844
   653
dos@12400
   654
    data->resize.pending = SDL_FALSE;
dos@12844
   655
    data->resize.width = window->w;
dos@12844
   656
    data->resize.height = window->h;
dos@12844
   657
    data->resize.scale_factor = data->scale_factor;
dos@12844
   658
dos@12844
   659
    data->outputs = NULL;
dos@12844
   660
    data->num_outputs = 0;
dos@12400
   661
gabomdq@8062
   662
    data->surface =
gabomdq@8062
   663
        wl_compositor_create_surface(c->compositor);
dos@12844
   664
    wl_surface_add_listener(data->surface, &surface_listener, data);
icculus@11848
   665
icculus@12033
   666
    if (c->shell.xdg) {
icculus@12033
   667
        data->shell_surface.xdg.surface = xdg_wm_base_get_xdg_surface(c->shell.xdg, data->surface);
icculus@12033
   668
        /* !!! FIXME: add popup role */
icculus@12033
   669
        data->shell_surface.xdg.roleobj.toplevel = xdg_surface_get_toplevel(data->shell_surface.xdg.surface);
icculus@12033
   670
        xdg_toplevel_add_listener(data->shell_surface.xdg.roleobj.toplevel, &toplevel_listener_xdg, data);
icculus@12033
   671
        xdg_toplevel_set_app_id(data->shell_surface.xdg.roleobj.toplevel, c->classname);
icculus@12033
   672
    } else if (c->shell.zxdg) {
icculus@11848
   673
        data->shell_surface.zxdg.surface = zxdg_shell_v6_get_xdg_surface(c->shell.zxdg, data->surface);
icculus@11848
   674
        /* !!! FIXME: add popup role */
icculus@11848
   675
        data->shell_surface.zxdg.roleobj.toplevel = zxdg_surface_v6_get_toplevel(data->shell_surface.zxdg.surface);
icculus@11848
   676
        zxdg_toplevel_v6_add_listener(data->shell_surface.zxdg.roleobj.toplevel, &toplevel_listener_zxdg, data);
icculus@11848
   677
        zxdg_toplevel_v6_set_app_id(data->shell_surface.zxdg.roleobj.toplevel, c->classname);
icculus@11848
   678
    } else {
icculus@11848
   679
        data->shell_surface.wl = wl_shell_get_shell_surface(c->shell.wl, data->surface);
icculus@11848
   680
        wl_shell_surface_set_class(data->shell_surface.wl, c->classname);
icculus@11848
   681
    }
icculus@11848
   682
m@10614
   683
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
gabomdq@8082
   684
    if (c->surface_extension) {
gabomdq@8082
   685
        data->extended_surface = qt_surface_extension_get_extended_surface(
gabomdq@8082
   686
                c->surface_extension, data->surface);
m@10614
   687
m@10614
   688
        QtExtendedSurface_Subscribe(data->extended_surface, SDL_HINT_QTWAYLAND_CONTENT_ORIENTATION);
m@10614
   689
        QtExtendedSurface_Subscribe(data->extended_surface, SDL_HINT_QTWAYLAND_WINDOW_FLAGS);
gabomdq@8082
   690
    }
gabomdq@8082
   691
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
m@8712
   692
gabomdq@8104
   693
    data->egl_window = WAYLAND_wl_egl_window_create(data->surface,
dos@12844
   694
                                            window->w * data->scale_factor, window->h * data->scale_factor);
gabomdq@8062
   695
gabomdq@8062
   696
    /* Create the GLES window surface */
gabomdq@8062
   697
    data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->egl_window);
gabomdq@8062
   698
    
gabomdq@8062
   699
    if (data->egl_surface == EGL_NO_SURFACE) {
philipp@9543
   700
        return SDL_SetError("failed to create a window surface");
gabomdq@8062
   701
    }
gabomdq@8062
   702
icculus@12033
   703
    if (c->shell.xdg) {
icculus@12033
   704
        if (data->shell_surface.xdg.surface) {
icculus@12033
   705
            xdg_surface_set_user_data(data->shell_surface.xdg.surface, data);
icculus@12033
   706
            xdg_surface_add_listener(data->shell_surface.xdg.surface, &shell_surface_listener_xdg, data);
icculus@12033
   707
        }
icculus@12033
   708
    } else if (c->shell.zxdg) {
icculus@11848
   709
        if (data->shell_surface.zxdg.surface) {
icculus@11848
   710
            zxdg_surface_v6_set_user_data(data->shell_surface.zxdg.surface, data);
icculus@11848
   711
            zxdg_surface_v6_add_listener(data->shell_surface.zxdg.surface, &shell_surface_listener_zxdg, data);
icculus@11848
   712
        }
icculus@11848
   713
    } else {
icculus@11848
   714
        if (data->shell_surface.wl) {
icculus@11848
   715
            wl_shell_surface_set_user_data(data->shell_surface.wl, data);
icculus@11848
   716
            wl_shell_surface_add_listener(data->shell_surface.wl, &shell_surface_listener_wl, data);
icculus@11848
   717
        }
gabomdq@8062
   718
    }
gabomdq@8062
   719
gabomdq@8082
   720
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
gabomdq@8082
   721
    if (data->extended_surface) {
gabomdq@8082
   722
        qt_extended_surface_set_user_data(data->extended_surface, data);
gabomdq@8082
   723
        qt_extended_surface_add_listener(data->extended_surface,
gabomdq@8082
   724
                                         &extended_surface_listener, data);
gabomdq@8082
   725
    }
gabomdq@8082
   726
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
gabomdq@8082
   727
dos@12426
   728
    if (c->decoration_manager && c->shell.xdg && data->shell_surface.xdg.surface) {
dos@12426
   729
        data->server_decoration = zxdg_decoration_manager_v1_get_toplevel_decoration(c->decoration_manager, data->shell_surface.xdg.roleobj.toplevel);
dos@12426
   730
        if (data->server_decoration) {
dos@12426
   731
            const SDL_bool bordered = (window->flags & SDL_WINDOW_BORDERLESS) == 0;
dos@12426
   732
            const enum zxdg_toplevel_decoration_v1_mode mode = bordered ? ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE : ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE;
dos@12426
   733
            zxdg_toplevel_decoration_v1_set_mode(data->server_decoration, mode);
dos@12426
   734
        }
dos@12426
   735
    } else if (c->kwin_server_decoration_manager) {
icculus@12367
   736
        data->kwin_server_decoration = org_kde_kwin_server_decoration_manager_create(c->kwin_server_decoration_manager, data->surface);
icculus@12367
   737
        if (data->kwin_server_decoration) {
icculus@12367
   738
            const SDL_bool bordered = (window->flags & SDL_WINDOW_BORDERLESS) == 0;
icculus@12367
   739
            const enum org_kde_kwin_server_decoration_mode mode = bordered ? ORG_KDE_KWIN_SERVER_DECORATION_MANAGER_MODE_SERVER : ORG_KDE_KWIN_SERVER_DECORATION_MANAGER_MODE_NONE;
icculus@12367
   740
            org_kde_kwin_server_decoration_request_mode(data->kwin_server_decoration, mode);
icculus@12367
   741
        }
icculus@12367
   742
    }
icculus@12367
   743
gabomdq@8062
   744
    region = wl_compositor_create_region(c->compositor);
gabomdq@8062
   745
    wl_region_add(region, 0, 0, window->w, window->h);
gabomdq@8062
   746
    wl_surface_set_opaque_region(data->surface, region);
gabomdq@8062
   747
    wl_region_destroy(region);
gabomdq@8062
   748
slouken@10304
   749
    if (c->relative_mouse_mode) {
slouken@10304
   750
        Wayland_input_lock_pointer(c->input);
slouken@10304
   751
    }
slouken@10304
   752
icculus@11848
   753
    wl_surface_commit(data->surface);
gabomdq@8104
   754
    WAYLAND_wl_display_flush(c->display);
gabomdq@8062
   755
icculus@11944
   756
    /* we have to wait until the surface gets a "configure" event, or
icculus@11944
   757
       use of this surface will fail. This is a new rule for xdg_shell. */
icculus@12033
   758
    if (c->shell.xdg) {
icculus@12033
   759
        if (data->shell_surface.xdg.surface) {
icculus@12033
   760
            while (!data->shell_surface.xdg.initial_configure_seen) {
icculus@12033
   761
                WAYLAND_wl_display_flush(c->display);
icculus@12033
   762
                WAYLAND_wl_display_dispatch(c->display);
icculus@12033
   763
            }
icculus@12033
   764
        }
icculus@12033
   765
    } else if (c->shell.zxdg) {
icculus@11944
   766
        if (data->shell_surface.zxdg.surface) {
icculus@11944
   767
            while (!data->shell_surface.zxdg.initial_configure_seen) {
icculus@11944
   768
                WAYLAND_wl_display_flush(c->display);
icculus@11944
   769
                WAYLAND_wl_display_dispatch(c->display);
icculus@11944
   770
            }
icculus@11944
   771
        }
icculus@11944
   772
    }
icculus@11944
   773
gabomdq@8062
   774
    return 0;
gabomdq@8062
   775
}
gabomdq@8062
   776
gabomdq@8062
   777
void Wayland_SetWindowSize(_THIS, SDL_Window * window)
gabomdq@8062
   778
{
gabomdq@8062
   779
    SDL_VideoData *data = _this->driverdata;
gabomdq@8062
   780
    SDL_WindowData *wind = window->driverdata;
gabomdq@8062
   781
    struct wl_region *region;
gabomdq@8062
   782
dos@12844
   783
    wl_surface_set_buffer_scale(wind->surface, get_window_scale_factor(window));
dos@12844
   784
    WAYLAND_wl_egl_window_resize(wind->egl_window, window->w * get_window_scale_factor(window), window->h * get_window_scale_factor(window), 0, 0);
gabomdq@8062
   785
dos@12844
   786
    region = wl_compositor_create_region(data->compositor);
gabomdq@8062
   787
    wl_region_add(region, 0, 0, window->w, window->h);
gabomdq@8062
   788
    wl_surface_set_opaque_region(wind->surface, region);
gabomdq@8062
   789
    wl_region_destroy(region);
gabomdq@8062
   790
}
gabomdq@8062
   791
slouken@10492
   792
void Wayland_SetWindowTitle(_THIS, SDL_Window * window)
slouken@10492
   793
{
slouken@10492
   794
    SDL_WindowData *wind = window->driverdata;
icculus@11848
   795
    SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
slouken@10492
   796
    
slouken@10492
   797
    if (window->title != NULL) {
icculus@12033
   798
        if (viddata->shell.xdg) {
icculus@12033
   799
            xdg_toplevel_set_title(wind->shell_surface.xdg.roleobj.toplevel, window->title);
icculus@12033
   800
        } else if (viddata->shell.zxdg) {
icculus@11848
   801
            zxdg_toplevel_v6_set_title(wind->shell_surface.zxdg.roleobj.toplevel, window->title);
icculus@11848
   802
        } else {
icculus@11848
   803
            wl_shell_surface_set_title(wind->shell_surface.wl, window->title);
icculus@11848
   804
        }
slouken@10492
   805
    }
slouken@10492
   806
slouken@10492
   807
    WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
slouken@10492
   808
}
slouken@10492
   809
gabomdq@8062
   810
void Wayland_DestroyWindow(_THIS, SDL_Window *window)
gabomdq@8062
   811
{
gabomdq@8062
   812
    SDL_VideoData *data = _this->driverdata;
gabomdq@8062
   813
    SDL_WindowData *wind = window->driverdata;
gabomdq@8062
   814
gabomdq@8062
   815
    if (data) {
gabomdq@8062
   816
        SDL_EGL_DestroySurface(_this, wind->egl_surface);
gabomdq@8104
   817
        WAYLAND_wl_egl_window_destroy(wind->egl_window);
gabomdq@8062
   818
dos@12426
   819
        if (wind->server_decoration) {
dos@12426
   820
           zxdg_toplevel_decoration_v1_destroy(wind->server_decoration);
dos@12426
   821
        }
dos@12426
   822
icculus@12367
   823
        if (wind->kwin_server_decoration) {
icculus@12367
   824
            org_kde_kwin_server_decoration_release(wind->kwin_server_decoration);
icculus@12367
   825
        }
icculus@12367
   826
icculus@12033
   827
        if (data->shell.xdg) {
icculus@12033
   828
            if (wind->shell_surface.xdg.roleobj.toplevel) {
icculus@12033
   829
                xdg_toplevel_destroy(wind->shell_surface.xdg.roleobj.toplevel);
icculus@12033
   830
            }
icculus@12033
   831
            if (wind->shell_surface.zxdg.surface) {
icculus@12033
   832
                xdg_surface_destroy(wind->shell_surface.xdg.surface);
icculus@12033
   833
            }
icculus@12033
   834
        } else if (data->shell.zxdg) {
icculus@11848
   835
            if (wind->shell_surface.zxdg.roleobj.toplevel) {
icculus@11848
   836
                zxdg_toplevel_v6_destroy(wind->shell_surface.zxdg.roleobj.toplevel);
icculus@11848
   837
            }
icculus@11848
   838
            if (wind->shell_surface.zxdg.surface) {
icculus@11848
   839
                zxdg_surface_v6_destroy(wind->shell_surface.zxdg.surface);
icculus@11848
   840
            }
icculus@11848
   841
        } else {
icculus@11848
   842
            if (wind->shell_surface.wl) {
icculus@11848
   843
                wl_shell_surface_destroy(wind->shell_surface.wl);
icculus@11848
   844
            }
icculus@11848
   845
        }
gabomdq@8062
   846
gabomdq@8082
   847
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
m@10614
   848
        if (wind->extended_surface) {
m@10614
   849
            QtExtendedSurface_Unsubscribe(wind->extended_surface, SDL_HINT_QTWAYLAND_CONTENT_ORIENTATION);
m@10614
   850
            QtExtendedSurface_Unsubscribe(wind->extended_surface, SDL_HINT_QTWAYLAND_WINDOW_FLAGS);
gabomdq@8082
   851
            qt_extended_surface_destroy(wind->extended_surface);
m@10614
   852
        }
gabomdq@8082
   853
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
gabomdq@8062
   854
        wl_surface_destroy(wind->surface);
gabomdq@8062
   855
gabomdq@8062
   856
        SDL_free(wind);
gabomdq@8104
   857
        WAYLAND_wl_display_flush(data->display);
gabomdq@8062
   858
    }
slouken@8978
   859
    window->driverdata = NULL;
gabomdq@8062
   860
}
gabomdq@8062
   861
icculus@8116
   862
#endif /* SDL_VIDEO_DRIVER_WAYLAND && SDL_VIDEO_OPENGL_EGL */
icculus@8116
   863
gabomdq@8062
   864
/* vi: set ts=4 sw=4 expandtab: */