wl_window.c 57.5 KB
Newer Older
1
//========================================================================
Camilla Berglund's avatar
Camilla Berglund committed
2
// GLFW 3.3 Wayland - www.glfw.org
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//------------------------------------------------------------------------
// Copyright (c) 2014 Jonas Ådahl <jadahl@gmail.com>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
//    claim that you wrote the original software. If you use this software
//    in a product, an acknowledgment in the product documentation would
//    be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
//    be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
//    distribution.
//
//========================================================================
26
27
// It is fine to use C99 in this file because it will not be built with VS
//========================================================================
28

29
30
#define _GNU_SOURCE

31
32
33
#include "internal.h"

#include <stdio.h>
34
35
36
37
38
39
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <sys/mman.h>
40
#include <sys/timerfd.h>
41
#include <poll.h>
42

43

44
45
46
static void shellSurfaceHandlePing(void* data,
                                   struct wl_shell_surface* shellSurface,
                                   uint32_t serial)
47
48
49
50
{
    wl_shell_surface_pong(shellSurface, serial);
}

51
52
53
54
55
static void shellSurfaceHandleConfigure(void* data,
                                        struct wl_shell_surface* shellSurface,
                                        uint32_t edges,
                                        int32_t width,
                                        int32_t height)
56
{
57
    _GLFWwindow* window = data;
58
59
60
61
62
    float aspectRatio;
    float targetRatio;

    if (!window->monitor)
    {
63
        if (_glfw.wl.viewporter && window->decorated)
64
        {
65
66
            width -= _GLFW_DECORATION_HORIZONTAL;
            height -= _GLFW_DECORATION_VERTICAL;
67
        }
68
69
70
71
        if (width < 1)
            width = 1;
        if (height < 1)
            height = 1;
72

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
        if (window->numer != GLFW_DONT_CARE && window->denom != GLFW_DONT_CARE)
        {
            aspectRatio = (float)width / (float)height;
            targetRatio = (float)window->numer / (float)window->denom;
            if (aspectRatio < targetRatio)
                height = width / targetRatio;
            else if (aspectRatio > targetRatio)
                width = height * targetRatio;
        }

        if (window->minwidth != GLFW_DONT_CARE && width < window->minwidth)
            width = window->minwidth;
        else if (window->maxwidth != GLFW_DONT_CARE && width > window->maxwidth)
            width = window->maxwidth;

        if (window->minheight != GLFW_DONT_CARE && height < window->minheight)
            height = window->minheight;
        else if (window->maxheight != GLFW_DONT_CARE && height > window->maxheight)
            height = window->maxheight;
    }

94
95
96
    _glfwInputWindowSize(window, width, height);
    _glfwPlatformSetWindowSize(window, width, height);
    _glfwInputWindowDamage(window);
97
98
}

99
100
static void shellSurfaceHandlePopupDone(void* data,
                                        struct wl_shell_surface* shellSurface)
101
102
103
104
{
}

static const struct wl_shell_surface_listener shellSurfaceListener = {
105
106
107
    shellSurfaceHandlePing,
    shellSurfaceHandleConfigure,
    shellSurfaceHandlePopupDone
108
109
};

110
static int createTmpfileCloexec(char* tmpname)
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
{
    int fd;

    fd = mkostemp(tmpname, O_CLOEXEC);
    if (fd >= 0)
        unlink(tmpname);

    return fd;
}

/*
 * Create a new, unique, anonymous file of the given size, and
 * return the file descriptor for it. The file descriptor is set
 * CLOEXEC. The file is immediately suitable for mmap()'ing
 * the given size at offset zero.
 *
 * The file should not have a permanent backing store like a disk,
 * but may have if XDG_RUNTIME_DIR is not properly implemented in OS.
 *
 * The file name is deleted from the file system.
 *
 * The file is suitable for buffer sharing between processes by
 * transmitting the file descriptor over Unix sockets using the
 * SCM_RIGHTS methods.
 *
 * posix_fallocate() is used to guarantee that disk space is available
luz.paz's avatar
luz.paz committed
137
 * for the file at the given size. If disk space is insufficient, errno
138
139
140
 * is set to ENOSPC. If posix_fallocate() is not supported, program may
 * receive SIGBUS on accessing mmap()'ed file contents instead.
 */
141
static int createAnonymousFile(off_t size)
142
143
144
145
146
147
148
{
    static const char template[] = "/glfw-shared-XXXXXX";
    const char* path;
    char* name;
    int fd;
    int ret;

149
150
151
#ifdef HAVE_MEMFD_CREATE
    fd = memfd_create("glfw-shared", MFD_CLOEXEC | MFD_ALLOW_SEALING);
    if (fd >= 0)
152
    {
153
154
155
156
157
158
        // We can add this seal before calling posix_fallocate(), as the file
        // is currently zero-sized anyway.
        //
        // There is also no need to check for the return value, we couldn’t do
        // anything with it anyway.
        fcntl(fd, F_ADD_SEALS, F_SEAL_SHRINK | F_SEAL_SEAL);
159
    }
160
    else
Greg V's avatar
Greg V committed
161
162
163
#elif defined(SHM_ANON)
    fd = shm_open(SHM_ANON, O_RDWR | O_CLOEXEC, 0600);
    if (fd < 0)
164
165
166
167
168
169
170
171
#endif
    {
        path = getenv("XDG_RUNTIME_DIR");
        if (!path)
        {
            errno = ENOENT;
            return -1;
        }
172

173
174
175
        name = calloc(strlen(path) + sizeof(template), 1);
        strcpy(name, path);
        strcat(name, template);
176

177
178
179
180
181
        fd = createTmpfileCloexec(name);
        free(name);
        if (fd < 0)
            return -1;
    }
182

Greg V's avatar
Greg V committed
183
184
185
186
#if defined(SHM_ANON)
    // posix_fallocate does not work on SHM descriptors
    ret = ftruncate(fd, size);
#else
187
    ret = posix_fallocate(fd, 0, size);
Greg V's avatar
Greg V committed
188
#endif
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
    if (ret != 0)
    {
        close(fd);
        errno = ret;
        return -1;
    }
    return fd;
}

static struct wl_buffer* createShmBuffer(const GLFWimage* image)
{
    struct wl_shm_pool* pool;
    struct wl_buffer* buffer;
    int stride = image->width * 4;
    int length = image->width * image->height * 4;
    void* data;
    int fd, i;

    fd = createAnonymousFile(length);
    if (fd < 0)
    {
        _glfwInputError(GLFW_PLATFORM_ERROR,
                        "Wayland: Creating a buffer file for %d B failed: %m",
                        length);
213
        return NULL;
214
215
216
217
218
219
220
221
    }

    data = mmap(NULL, length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    if (data == MAP_FAILED)
    {
        _glfwInputError(GLFW_PLATFORM_ERROR,
                        "Wayland: mmap failed: %m");
        close(fd);
222
        return NULL;
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
    }

    pool = wl_shm_create_pool(_glfw.wl.shm, fd, length);

    close(fd);
    unsigned char* source = (unsigned char*) image->pixels;
    unsigned char* target = data;
    for (i = 0;  i < image->width * image->height;  i++, source += 4)
    {
        unsigned int alpha = source[3];

        *target++ = (unsigned char) ((source[2] * alpha) / 255);
        *target++ = (unsigned char) ((source[1] * alpha) / 255);
        *target++ = (unsigned char) ((source[0] * alpha) / 255);
        *target++ = (unsigned char) alpha;
    }

    buffer =
        wl_shm_pool_create_buffer(pool, 0,
                                  image->width,
                                  image->height,
                                  stride, WL_SHM_FORMAT_ARGB8888);
    munmap(data, length);
    wl_shm_pool_destroy(pool);

    return buffer;
}

static void createDecoration(_GLFWdecorationWayland* decoration,
                             struct wl_surface* parent,
253
254
                             struct wl_buffer* buffer, GLFWbool opaque,
                             int x, int y,
255
256
                             int width, int height)
{
257
258
    struct wl_region* region;

259
260
261
262
263
264
265
266
267
    decoration->surface = wl_compositor_create_surface(_glfw.wl.compositor);
    decoration->subsurface =
        wl_subcompositor_get_subsurface(_glfw.wl.subcompositor,
                                        decoration->surface, parent);
    wl_subsurface_set_position(decoration->subsurface, x, y);
    decoration->viewport = wp_viewporter_get_viewport(_glfw.wl.viewporter,
                                                      decoration->surface);
    wp_viewport_set_destination(decoration->viewport, width, height);
    wl_surface_attach(decoration->surface, buffer, 0, 0);
268
269
270
271
272
273
274
275
276
277
278

    if (opaque)
    {
        region = wl_compositor_create_region(_glfw.wl.compositor);
        wl_region_add(region, 0, 0, width, height);
        wl_surface_set_opaque_region(decoration->surface, region);
        wl_surface_commit(decoration->surface);
        wl_region_destroy(region);
    }
    else
        wl_surface_commit(decoration->surface);
279
280
281
282
283
284
}

static void createDecorations(_GLFWwindow* window)
{
    unsigned char data[] = { 224, 224, 224, 255 };
    const GLFWimage image = { 1, 1, data };
285
    GLFWbool opaque = (data[3] == 255);
286

287
    if (!_glfw.wl.viewporter || !window->decorated || window->wl.decorations.serverSide)
288
289
        return;

290
291
    if (!window->wl.decorations.buffer)
        window->wl.decorations.buffer = createShmBuffer(&image);
292
293
    if (!window->wl.decorations.buffer)
        return;
294

295
    createDecoration(&window->wl.decorations.top, window->wl.surface,
296
                     window->wl.decorations.buffer, opaque,
297
298
                     0, -_GLFW_DECORATION_TOP,
                     window->wl.width, _GLFW_DECORATION_TOP);
299
    createDecoration(&window->wl.decorations.left, window->wl.surface,
300
                     window->wl.decorations.buffer, opaque,
301
302
                     -_GLFW_DECORATION_WIDTH, -_GLFW_DECORATION_TOP,
                     _GLFW_DECORATION_WIDTH, window->wl.height + _GLFW_DECORATION_TOP);
303
    createDecoration(&window->wl.decorations.right, window->wl.surface,
304
                     window->wl.decorations.buffer, opaque,
305
306
                     window->wl.width, -_GLFW_DECORATION_TOP,
                     _GLFW_DECORATION_WIDTH, window->wl.height + _GLFW_DECORATION_TOP);
307
    createDecoration(&window->wl.decorations.bottom, window->wl.surface,
308
                     window->wl.decorations.buffer, opaque,
309
                     -_GLFW_DECORATION_WIDTH, window->wl.height,
310
                     window->wl.width + _GLFW_DECORATION_HORIZONTAL, _GLFW_DECORATION_WIDTH);
311
312
}

313
314
315
316
317
318
319
320
static void destroyDecoration(_GLFWdecorationWayland* decoration)
{
    if (decoration->surface)
        wl_surface_destroy(decoration->surface);
    if (decoration->subsurface)
        wl_subsurface_destroy(decoration->subsurface);
    if (decoration->viewport)
        wp_viewport_destroy(decoration->viewport);
321
322
323
    decoration->surface = NULL;
    decoration->subsurface = NULL;
    decoration->viewport = NULL;
324
325
326
327
328
329
330
331
332
333
}

static void destroyDecorations(_GLFWwindow* window)
{
    destroyDecoration(&window->wl.decorations.top);
    destroyDecoration(&window->wl.decorations.left);
    destroyDecoration(&window->wl.decorations.right);
    destroyDecoration(&window->wl.decorations.bottom);
}

334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
static void xdgDecorationHandleConfigure(void* data,
                                         struct zxdg_toplevel_decoration_v1* decoration,
                                         uint32_t mode)
{
    _GLFWwindow* window = data;

    window->wl.decorations.serverSide = (mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);

    if (!window->wl.decorations.serverSide)
        createDecorations(window);
}

static const struct zxdg_toplevel_decoration_v1_listener xdgDecorationListener = {
    xdgDecorationHandleConfigure,
};

350
351
// Makes the surface considered as XRGB instead of ARGB.
static void setOpaqueRegion(_GLFWwindow* window)
352
{
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
    struct wl_region* region;

    region = wl_compositor_create_region(_glfw.wl.compositor);
    if (!region)
        return;

    wl_region_add(region, 0, 0, window->wl.width, window->wl.height);
    wl_surface_set_opaque_region(window->wl.surface, region);
    wl_surface_commit(window->wl.surface);
    wl_region_destroy(region);
}


static void resizeWindow(_GLFWwindow* window)
{
    int scale = window->wl.scale;
    int scaledWidth = window->wl.width * scale;
    int scaledHeight = window->wl.height * scale;
    wl_egl_window_resize(window->wl.native, scaledWidth, scaledHeight, 0, 0);
    if (!window->wl.transparent)
        setOpaqueRegion(window);
    _glfwInputFramebufferSize(window, scaledWidth, scaledHeight);
    _glfwInputWindowContentScale(window, scale, scale);
376

377
    if (!window->wl.decorations.top.surface)
378
379
        return;

380
    // Top decoration.
381
382
    wp_viewport_set_destination(window->wl.decorations.top.viewport,
                                window->wl.width, _GLFW_DECORATION_TOP);
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
    wl_surface_commit(window->wl.decorations.top.surface);

    // Left decoration.
    wp_viewport_set_destination(window->wl.decorations.left.viewport,
                                _GLFW_DECORATION_WIDTH, window->wl.height + _GLFW_DECORATION_TOP);
    wl_surface_commit(window->wl.decorations.left.surface);

    // Right decoration.
    wl_subsurface_set_position(window->wl.decorations.right.subsurface,
                               window->wl.width, -_GLFW_DECORATION_TOP);
    wp_viewport_set_destination(window->wl.decorations.right.viewport,
                                _GLFW_DECORATION_WIDTH, window->wl.height + _GLFW_DECORATION_TOP);
    wl_surface_commit(window->wl.decorations.right.surface);

    // Bottom decoration.
    wl_subsurface_set_position(window->wl.decorations.bottom.subsurface,
                               -_GLFW_DECORATION_WIDTH, window->wl.height);
    wp_viewport_set_destination(window->wl.decorations.bottom.viewport,
401
                                window->wl.width + _GLFW_DECORATION_HORIZONTAL, _GLFW_DECORATION_WIDTH);
402
403
404
    wl_surface_commit(window->wl.decorations.bottom.surface);
}

405
406
407
408
409
410
static void checkScaleChange(_GLFWwindow* window)
{
    int scale = 1;
    int i;
    int monitorScale;

411
    // Check if we will be able to set the buffer scale or not.
412
    if (_glfw.wl.compositorVersion < 3)
413
414
        return;

415
416
417
418
419
420
421
422
423
424
425
426
427
    // Get the scale factor from the highest scale monitor.
    for (i = 0; i < window->wl.monitorsCount; ++i)
    {
        monitorScale = window->wl.monitors[i]->wl.scale;
        if (scale < monitorScale)
            scale = monitorScale;
    }

    // Only change the framebuffer size if the scale changed.
    if (scale != window->wl.scale)
    {
        window->wl.scale = scale;
        wl_surface_set_buffer_scale(window->wl.surface, scale);
428
        resizeWindow(window);
429
430
431
    }
}

432
433
434
static void surfaceHandleEnter(void *data,
                               struct wl_surface *surface,
                               struct wl_output *output)
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
{
    _GLFWwindow* window = data;
    _GLFWmonitor* monitor = wl_output_get_user_data(output);

    if (window->wl.monitorsCount + 1 > window->wl.monitorsSize)
    {
        ++window->wl.monitorsSize;
        window->wl.monitors =
            realloc(window->wl.monitors,
                    window->wl.monitorsSize * sizeof(_GLFWmonitor*));
    }

    window->wl.monitors[window->wl.monitorsCount++] = monitor;

    checkScaleChange(window);
}

452
453
454
static void surfaceHandleLeave(void *data,
                               struct wl_surface *surface,
                               struct wl_output *output)
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
{
    _GLFWwindow* window = data;
    _GLFWmonitor* monitor = wl_output_get_user_data(output);
    GLFWbool found;
    int i;

    for (i = 0, found = GLFW_FALSE; i < window->wl.monitorsCount - 1; ++i)
    {
        if (monitor == window->wl.monitors[i])
            found = GLFW_TRUE;
        if (found)
            window->wl.monitors[i] = window->wl.monitors[i + 1];
    }
    window->wl.monitors[--window->wl.monitorsCount] = NULL;

    checkScaleChange(window);
}

static const struct wl_surface_listener surfaceListener = {
474
475
    surfaceHandleEnter,
    surfaceHandleLeave
476
477
};

478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
static void setIdleInhibitor(_GLFWwindow* window, GLFWbool enable)
{
    if (enable && !window->wl.idleInhibitor && _glfw.wl.idleInhibitManager)
    {
        window->wl.idleInhibitor =
            zwp_idle_inhibit_manager_v1_create_inhibitor(
                _glfw.wl.idleInhibitManager, window->wl.surface);
        if (!window->wl.idleInhibitor)
            _glfwInputError(GLFW_PLATFORM_ERROR,
                            "Wayland: Idle inhibitor creation failed");
    }
    else if (!enable && window->wl.idleInhibitor)
    {
        zwp_idle_inhibitor_v1_destroy(window->wl.idleInhibitor);
        window->wl.idleInhibitor = NULL;
    }
}

496
497
static GLFWbool createSurface(_GLFWwindow* window,
                              const _GLFWwndconfig* wndconfig)
498
{
499
500
    window->wl.surface = wl_compositor_create_surface(_glfw.wl.compositor);
    if (!window->wl.surface)
501
        return GLFW_FALSE;
502

503
504
505
506
    wl_surface_add_listener(window->wl.surface,
                            &surfaceListener,
                            window);

507
508
    wl_surface_set_user_data(window->wl.surface, window);

509
510
511
512
    window->wl.native = wl_egl_window_create(window->wl.surface,
                                             wndconfig->width,
                                             wndconfig->height);
    if (!window->wl.native)
513
        return GLFW_FALSE;
514

515
516
517
518
    window->wl.width = wndconfig->width;
    window->wl.height = wndconfig->height;
    window->wl.scale = 1;

519
520
    if (!window->wl.transparent)
        setOpaqueRegion(window);
521

522
523
524
    return GLFW_TRUE;
}

525
526
static void setFullscreen(_GLFWwindow* window, _GLFWmonitor* monitor,
                          int refreshRate)
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
{
    if (window->wl.xdg.toplevel)
    {
        xdg_toplevel_set_fullscreen(
            window->wl.xdg.toplevel,
            monitor->wl.output);
    }
    else if (window->wl.shellSurface)
    {
        wl_shell_surface_set_fullscreen(
            window->wl.shellSurface,
            WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
            refreshRate * 1000, // Convert Hz to mHz.
            monitor->wl.output);
    }
    setIdleInhibitor(window, GLFW_TRUE);
543
544
    if (!window->wl.decorations.serverSide)
        destroyDecorations(window);
545
546
}

547
548
static GLFWbool createShellSurface(_GLFWwindow* window)
{
549
550
551
552
553
554
555
    if (!_glfw.wl.shell)
    {
        _glfwInputError(GLFW_PLATFORM_ERROR,
                        "Wayland: wl_shell protocol not available");
        return GLFW_FALSE;
    }

556
557
558
    window->wl.shellSurface = wl_shell_get_shell_surface(_glfw.wl.shell,
                                                         window->wl.surface);
    if (!window->wl.shellSurface)
559
560
561
    {
        _glfwInputError(GLFW_PLATFORM_ERROR,
                        "Wayland: Shell surface creation failed");
562
        return GLFW_FALSE;
563
    }
564

565
    wl_shell_surface_add_listener(window->wl.shellSurface,
566
567
568
                                  &shellSurfaceListener,
                                  window);

569
    if (window->wl.title)
570
        wl_shell_surface_set_title(window->wl.shellSurface, window->wl.title);
571
572
573

    if (window->monitor)
    {
574
        setFullscreen(window, window->monitor, 0);
575
    }
576
577
    else if (window->wl.maximized)
    {
578
        wl_shell_surface_set_maximized(window->wl.shellSurface, NULL);
579
        setIdleInhibitor(window, GLFW_FALSE);
580
        createDecorations(window);
581
    }
582
583
    else
    {
584
        wl_shell_surface_set_toplevel(window->wl.shellSurface);
585
        setIdleInhibitor(window, GLFW_FALSE);
586
        createDecorations(window);
587
    }
588

589
590
    wl_surface_commit(window->wl.surface);

591
    return GLFW_TRUE;
592
593
}

594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
static void xdgToplevelHandleConfigure(void* data,
                                       struct xdg_toplevel* toplevel,
                                       int32_t width,
                                       int32_t height,
                                       struct wl_array* states)
{
    _GLFWwindow* window = data;
    float aspectRatio;
    float targetRatio;
    uint32_t* state;
    GLFWbool maximized = GLFW_FALSE;
    GLFWbool fullscreen = GLFW_FALSE;
    GLFWbool activated = GLFW_FALSE;

    wl_array_for_each(state, states)
    {
        switch (*state)
        {
            case XDG_TOPLEVEL_STATE_MAXIMIZED:
                maximized = GLFW_TRUE;
                break;
            case XDG_TOPLEVEL_STATE_FULLSCREEN:
                fullscreen = GLFW_TRUE;
                break;
            case XDG_TOPLEVEL_STATE_RESIZING:
                break;
            case XDG_TOPLEVEL_STATE_ACTIVATED:
                activated = GLFW_TRUE;
                break;
        }
    }

626
    if (width != 0 && height != 0)
627
    {
628
        if (!maximized && !fullscreen)
629
        {
630
631
632
633
634
635
636
637
638
            if (window->numer != GLFW_DONT_CARE && window->denom != GLFW_DONT_CARE)
            {
                aspectRatio = (float)width / (float)height;
                targetRatio = (float)window->numer / (float)window->denom;
                if (aspectRatio < targetRatio)
                    height = width / targetRatio;
                else if (aspectRatio > targetRatio)
                    width = height * targetRatio;
            }
639
640
        }

641
642
643
644
        _glfwInputWindowSize(window, width, height);
        _glfwPlatformSetWindowSize(window, width, height);
        _glfwInputWindowDamage(window);
    }
645

646
647
648
649
650
651
652
653
654
655
    if (window->wl.wasFullscreen && window->autoIconify)
    {
        if (!activated || !fullscreen)
        {
            _glfwPlatformIconifyWindow(window);
            window->wl.wasFullscreen = GLFW_FALSE;
        }
    }
    if (fullscreen && activated)
        window->wl.wasFullscreen = GLFW_TRUE;
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
    _glfwInputWindowFocus(window, activated);
}

static void xdgToplevelHandleClose(void* data,
                                   struct xdg_toplevel* toplevel)
{
    _GLFWwindow* window = data;
    _glfwInputWindowCloseRequest(window);
}

static const struct xdg_toplevel_listener xdgToplevelListener = {
    xdgToplevelHandleConfigure,
    xdgToplevelHandleClose
};

static void xdgSurfaceHandleConfigure(void* data,
                                      struct xdg_surface* surface,
                                      uint32_t serial)
{
    xdg_surface_ack_configure(surface, serial);
}

static const struct xdg_surface_listener xdgSurfaceListener = {
    xdgSurfaceHandleConfigure
};

682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
static void setXdgDecorations(_GLFWwindow* window)
{
    if (_glfw.wl.decorationManager)
    {
        window->wl.xdg.decoration =
            zxdg_decoration_manager_v1_get_toplevel_decoration(
                _glfw.wl.decorationManager, window->wl.xdg.toplevel);
        zxdg_toplevel_decoration_v1_add_listener(window->wl.xdg.decoration,
                                                 &xdgDecorationListener,
                                                 window);
        zxdg_toplevel_decoration_v1_set_mode(
            window->wl.xdg.decoration,
            ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
    }
    else
    {
        window->wl.decorations.serverSide = GLFW_FALSE;
        createDecorations(window);
    }
}

703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
static GLFWbool createXdgSurface(_GLFWwindow* window)
{
    window->wl.xdg.surface = xdg_wm_base_get_xdg_surface(_glfw.wl.wmBase,
                                                         window->wl.surface);
    if (!window->wl.xdg.surface)
    {
        _glfwInputError(GLFW_PLATFORM_ERROR,
                        "Wayland: xdg-surface creation failed");
        return GLFW_FALSE;
    }

    xdg_surface_add_listener(window->wl.xdg.surface,
                             &xdgSurfaceListener,
                             window);

    window->wl.xdg.toplevel = xdg_surface_get_toplevel(window->wl.xdg.surface);
    if (!window->wl.xdg.toplevel)
    {
        _glfwInputError(GLFW_PLATFORM_ERROR,
                        "Wayland: xdg-toplevel creation failed");
        return GLFW_FALSE;
    }

    xdg_toplevel_add_listener(window->wl.xdg.toplevel,
                              &xdgToplevelListener,
                              window);

    if (window->wl.title)
        xdg_toplevel_set_title(window->wl.xdg.toplevel, window->wl.title);

733
734
735
736
737
738
    if (window->minwidth != GLFW_DONT_CARE && window->minheight != GLFW_DONT_CARE)
        xdg_toplevel_set_min_size(window->wl.xdg.toplevel,
                                  window->minwidth, window->minheight);
    if (window->maxwidth != GLFW_DONT_CARE && window->maxheight != GLFW_DONT_CARE)
        xdg_toplevel_set_max_size(window->wl.xdg.toplevel,
                                  window->maxwidth, window->maxheight);
739
740
741
742
743
744
745
746
747
748
749

    if (window->monitor)
    {
        xdg_toplevel_set_fullscreen(window->wl.xdg.toplevel,
                                    window->monitor->wl.output);
        setIdleInhibitor(window, GLFW_TRUE);
    }
    else if (window->wl.maximized)
    {
        xdg_toplevel_set_maximized(window->wl.xdg.toplevel);
        setIdleInhibitor(window, GLFW_FALSE);
750
        setXdgDecorations(window);
751
752
753
754
    }
    else
    {
        setIdleInhibitor(window, GLFW_FALSE);
755
        setXdgDecorations(window);
756
757
758
    }

    wl_surface_commit(window->wl.surface);
759
    wl_display_roundtrip(_glfw.wl.display);
760
761
762
763

    return GLFW_TRUE;
}

764
765
static void setCursorImage(_GLFWwindow* window,
                           _GLFWcursorWayland* cursorWayland)
766
767
{
    struct itimerspec timer = {};
768
    struct wl_cursor* wlCursor = cursorWayland->cursor;
769
770
771
    struct wl_cursor_image* image;
    struct wl_buffer* buffer;
    struct wl_surface* surface = _glfw.wl.cursorSurface;
772
    int scale = 1;
773

774
    if (!wlCursor)
775
776
777
        buffer = cursorWayland->buffer;
    else
    {
778
779
780
781
782
783
784
        if (window->wl.scale > 1 && cursorWayland->cursorHiDPI)
        {
            wlCursor = cursorWayland->cursorHiDPI;
            scale = 2;
        }

        image = wlCursor->images[cursorWayland->currentImage];
785
786
787
788
789
790
791
792
793
794
795
796
797
798
        buffer = wl_cursor_image_get_buffer(image);
        if (!buffer)
            return;

        timer.it_value.tv_sec = image->delay / 1000;
        timer.it_value.tv_nsec = (image->delay % 1000) * 1000000;
        timerfd_settime(_glfw.wl.cursorTimerfd, 0, &timer, NULL);

        cursorWayland->width = image->width;
        cursorWayland->height = image->height;
        cursorWayland->xhot = image->hotspot_x;
        cursorWayland->yhot = image->hotspot_y;
    }

799
    wl_pointer_set_cursor(_glfw.wl.pointer, _glfw.wl.serial,
800
                          surface,
801
802
803
                          cursorWayland->xhot / scale,
                          cursorWayland->yhot / scale);
    wl_surface_set_buffer_scale(surface, scale);
804
805
806
807
808
809
    wl_surface_attach(surface, buffer, 0, 0);
    wl_surface_damage(surface, 0, 0,
                      cursorWayland->width, cursorWayland->height);
    wl_surface_commit(surface);
}

810
static void incrementCursorImage(_GLFWwindow* window)
811
812
813
814
815
816
817
818
819
820
821
{
    _GLFWcursor* cursor;

    if (!window || window->wl.decorations.focus != mainWindow)
        return;

    cursor = window->wl.currentCursor;
    if (cursor && cursor->wl.cursor)
    {
        cursor->wl.currentImage += 1;
        cursor->wl.currentImage %= cursor->wl.cursor->image_count;
822
        setCursorImage(window, &cursor->wl);
823
824
825
    }
}

826
static void handleEvents(int timeout)
827
828
829
830
{
    struct wl_display* display = _glfw.wl.display;
    struct pollfd fds[] = {
        { wl_display_get_fd(display), POLLIN },
831
        { _glfw.wl.timerfd, POLLIN },
832
        { _glfw.wl.cursorTimerfd, POLLIN },
833
    };
834
835
    ssize_t read_ret;
    uint64_t repeats, i;
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854

    while (wl_display_prepare_read(display) != 0)
        wl_display_dispatch_pending(display);

    // If an error different from EAGAIN happens, we have likely been
    // disconnected from the Wayland session, try to handle that the best we
    // can.
    if (wl_display_flush(display) < 0 && errno != EAGAIN)
    {
        _GLFWwindow* window = _glfw.windowListHead;
        while (window)
        {
            _glfwInputWindowCloseRequest(window);
            window = window->next;
        }
        wl_display_cancel_read(display);
        return;
    }

855
    if (poll(fds, 3, timeout) > 0)
856
    {
857
858
859
860
861
862
863
864
865
866
867
868
        if (fds[0].revents & POLLIN)
        {
            wl_display_read_events(display);
            wl_display_dispatch_pending(display);
        }
        else
        {
            wl_display_cancel_read(display);
        }

        if (fds[1].revents & POLLIN)
        {
869
870
871
872
873
874
875
876
            read_ret = read(_glfw.wl.timerfd, &repeats, sizeof(repeats));
            if (read_ret != 8)
                return;

            for (i = 0; i < repeats; ++i)
                _glfwInputKey(_glfw.wl.keyboardFocus, _glfw.wl.keyboardLastKey,
                              _glfw.wl.keyboardLastScancode, GLFW_REPEAT,
                              _glfw.wl.xkb.modifiers);
877
        }
878
879
880
881
882
883
884

        if (fds[2].revents & POLLIN)
        {
            read_ret = read(_glfw.wl.cursorTimerfd, &repeats, sizeof(repeats));
            if (read_ret != 8)
                return;

885
            incrementCursorImage(_glfw.wl.pointerFocus);
886
        }
887
888
889
890
891
892
893
    }
    else
    {
        wl_display_cancel_read(display);
    }
}

894
895
896
897
898
899
900
901
902
903
904
905
906
// Translates a GLFW standard cursor to a theme cursor name
//
static char *translateCursorShape(int shape)
{
    switch (shape)
    {
        case GLFW_ARROW_CURSOR:
            return "left_ptr";
        case GLFW_IBEAM_CURSOR:
            return "xterm";
        case GLFW_CROSSHAIR_CURSOR:
            return "crosshair";
        case GLFW_HAND_CURSOR:
907
            return "hand2";
908
909
910
911
912
913
914
915
        case GLFW_HRESIZE_CURSOR:
            return "sb_h_double_arrow";
        case GLFW_VRESIZE_CURSOR:
            return "sb_v_double_arrow";
    }
    return NULL;
}

916
917
918
919
920
921
922
923
924
//////////////////////////////////////////////////////////////////////////
//////                       GLFW platform API                      //////
//////////////////////////////////////////////////////////////////////////

int _glfwPlatformCreateWindow(_GLFWwindow* window,
                              const _GLFWwndconfig* wndconfig,
                              const _GLFWctxconfig* ctxconfig,
                              const _GLFWfbconfig* fbconfig)
{
925
926
    window->wl.transparent = fbconfig->transparent;

927
928
929
    if (!createSurface(window, wndconfig))
        return GLFW_FALSE;

930
    if (ctxconfig->client != GLFW_NO_API)
931
    {
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
        if (ctxconfig->source == GLFW_EGL_CONTEXT_API ||
            ctxconfig->source == GLFW_NATIVE_CONTEXT_API)
        {
            if (!_glfwInitEGL())
                return GLFW_FALSE;
            if (!_glfwCreateContextEGL(window, ctxconfig, fbconfig))
                return GLFW_FALSE;
        }
        else if (ctxconfig->source == GLFW_OSMESA_CONTEXT_API)
        {
            if (!_glfwInitOSMesa())
                return GLFW_FALSE;
            if (!_glfwCreateContextOSMesa(window, ctxconfig, fbconfig))
                return GLFW_FALSE;
        }
947
    }
948

949
    if (wndconfig->title)
950
        window->wl.title = _glfw_strdup(wndconfig->title);
951
952

    if (wndconfig->visible)
953
    {
954
955
956
957
958
959
960
961
962
963
        if (_glfw.wl.wmBase)
        {
            if (!createXdgSurface(window))
                return GLFW_FALSE;
        }
        else
        {
            if (!createShellSurface(window))
                return GLFW_FALSE;
        }
964
965

        window->wl.visible = GLFW_TRUE;
966
967
968
    }
    else
    {
969
970
        window->wl.xdg.surface = NULL;
        window->wl.xdg.toplevel = NULL;
971
        window->wl.shellSurface = NULL;
972
        window->wl.visible = GLFW_FALSE;
973
974
    }

975
976
    window->wl.currentCursor = NULL;

977
978
979
980
    window->wl.monitors = calloc(1, sizeof(_GLFWmonitor*));
    window->wl.monitorsCount = 0;
    window->wl.monitorsSize = 1;

981
    return GLFW_TRUE;
982
983
984
985
}

void _glfwPlatformDestroyWindow(_GLFWwindow* window)
{
986
987
988
    if (window == _glfw.wl.pointerFocus)
    {
        _glfw.wl.pointerFocus = NULL;
989
        _glfwInputCursorEnter(window, GLFW_FALSE);
990
991
992
993
    }
    if (window == _glfw.wl.keyboardFocus)
    {
        _glfw.wl.keyboardFocus = NULL;
994
        _glfwInputWindowFocus(window, GLFW_FALSE);
995
996
    }

997
998
999
    if (window->wl.idleInhibitor)
        zwp_idle_inhibitor_v1_destroy(window->wl.idleInhibitor);

1000
    if (window->context.destroy)
Camilla Berglund's avatar
Cleanup    
Camilla Berglund committed
1001
        window->context.destroy(window);
1002

1003
    destroyDecorations(window);
1004
1005
1006
    if (window->wl.xdg.decoration)
        zxdg_toplevel_decoration_v1_destroy(window->wl.xdg.decoration);

1007
1008
    if (window->wl.decorations.buffer)
        wl_buffer_destroy(window->wl.decorations.buffer);
1009

1010
1011
    if (window->wl.native)
        wl_egl_window_destroy(window->wl.native);
1012

1013
1014
    if (window->wl.shellSurface)
        wl_shell_surface_destroy(window->wl.shellSurface);
1015

1016
1017
1018
1019
1020
1021
    if (window->wl.xdg.toplevel)
        xdg_toplevel_destroy(window->wl.xdg.toplevel);

    if (window->wl.xdg.surface)
        xdg_surface_destroy(window->wl.xdg.surface);

1022
1023
    if (window->wl.surface)
        wl_surface_destroy(window->wl.surface);
1024

1025
    free(window->wl.title);
1026
    free(window->wl.monitors);
1027
1028
1029
1030
}

void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
{
1031
1032
    if (window->wl.title)
        free(window->wl.title);
1033
    window->wl.title = _glfw_strdup(title);
1034
1035
1036
    if (window->wl.xdg.toplevel)
        xdg_toplevel_set_title(window->wl.xdg.toplevel, title);
    else if (window->wl.shellSurface)
1037
        wl_shell_surface_set_title(window->wl.shellSurface, title);
1038
1039
}

Camilla Berglund's avatar
Camilla Berglund committed
1040
1041
1042
void _glfwPlatformSetWindowIcon(_GLFWwindow* window,
                                int count, const GLFWimage* images)
{
1043
1044
    _glfwInputError(GLFW_PLATFORM_ERROR,
                    "Wayland: Setting window icon not supported");
Camilla Berglund's avatar
Camilla Berglund committed
1045
1046
}

1047
1048
void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos)
{
1049
1050
    // A Wayland client is not aware of its position, so just warn and leave it
    // as (0, 0)
1051
1052

    _glfwInputError(GLFW_PLATFORM_ERROR,
1053
                    "Wayland: Window position retrieval not supported");
1054
1055
1056
1057
}

void _glfwPlatformSetWindowPos(_GLFWwindow* window, int xpos, int ypos)
{
Camilla Berglund's avatar
Camilla Berglund committed
1058
    // A Wayland client can not set its position, so just warn
1059
1060

    _glfwInputError(GLFW_PLATFORM_ERROR,
1061
                    "Wayland: Window position setting not supported");
1062
1063
1064
1065
1066
}

void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height)
{
    if (width)
1067
        *width = window->wl.width;
1068
    if (height)
1069
        *height = window->wl.height;
1070
1071
1072
1073
}

void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
{
1074
1075
    window->wl.width = width;
    window->wl.height = height;
1076
    resizeWindow(window);
1077
1078
}

1079
1080
1081
1082
void _glfwPlatformSetWindowSizeLimits(_GLFWwindow* window,
                                      int minwidth, int minheight,
                                      int maxwidth, int maxheight)
{
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
    if (_glfw.wl.wmBase)
    {
        if (window->wl.xdg.toplevel)
        {
            if (minwidth == GLFW_DONT_CARE || minheight == GLFW_DONT_CARE)
                minwidth = minheight = 0;
            if (maxwidth == GLFW_DONT_CARE || maxheight == GLFW_DONT_CARE)
                maxwidth = maxheight = 0;
            xdg_toplevel_set_min_size(window->wl.xdg.toplevel, minwidth, minheight);
            xdg_toplevel_set_max_size(window->wl.xdg.toplevel, maxwidth, maxheight);
            wl_surface_commit(window->wl.surface);
        }
    }
    else
    {
        // TODO: find out how to trigger a resize.
        // The actual limits are checked in the wl_shell_surface::configure handler.
    }
1101
1102
}

1103
1104
void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window,
                                       int numer, int denom)
1105
{
1106
1107
    // TODO: find out how to trigger a resize.
    // The actual limits are checked in the wl_shell_surface::configure handler.
1108
1109
}

1110
1111
void _glfwPlatformGetFramebufferSize(_GLFWwindow* window,
                                     int* width, int* height)
1112
1113
{
    _glfwPlatformGetWindowSize(window, width, height);
1114
1115
    *width *= window->wl.scale;
    *height *= window->wl.scale;
1116
1117
}

1118
1119
1120
1121
void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
                                     int* left, int* top,
                                     int* right, int* bottom)
{
1122
    if (window->decorated && !window->monitor && !window->wl.decorations.serverSide)
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
    {
        if (top)
            *top = _GLFW_DECORATION_TOP;
        if (left)
            *left = _GLFW_DECORATION_WIDTH;
        if (right)
            *right = _GLFW_DECORATION_WIDTH;
        if (bottom)
            *bottom = _GLFW_DECORATION_WIDTH;
    }
1133
1134
}

Camilla Löwy's avatar
Camilla Löwy committed
1135
1136
1137
1138
1139
1140
1141
1142
1143
void _glfwPlatformGetWindowContentScale(_GLFWwindow* window,
                                        float* xscale, float* yscale)
{
    if (xscale)
        *xscale = (float) window->wl.scale;
    if (yscale)
        *yscale = (float) window->wl.scale;
}

1144
1145
void _glfwPlatformIconifyWindow(_GLFWwindow* window)
{
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
    if (_glfw.wl.wmBase)
    {
        if (window->wl.xdg.toplevel)
            xdg_toplevel_set_minimized(window->wl.xdg.toplevel);
    }
    else
    {
        _glfwInputError(GLFW_PLATFORM_ERROR,
                        "Wayland: Iconify window not supported on wl_shell");
    }
1156
1157
1158
1159
}

void _glfwPlatformRestoreWindow(_GLFWwindow* window)
{
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
    if (window->wl.xdg.toplevel)
    {
        if (window->monitor)
            xdg_toplevel_unset_fullscreen(window->wl.xdg.toplevel);
        if (window->wl.maximized)
            xdg_toplevel_unset_maximized(window->wl.xdg.toplevel);
        // There is no way to unset minimized, or even to know if we are
        // minimized, so there is nothing to do here.
    }
    else if (window->wl.shellSurface)
1170
    {
1171
        if (window->monitor || window->wl.maximized)
1172
            wl_shell_surface_set_toplevel(window->wl.shellSurface);
1173
    }
1174
1175
    _glfwInputWindowMonitor(window, NULL);
    window->wl.maximized = GLFW_FALSE;
1176
1177
}

1178
1179
void _glfwPlatformMaximizeWindow(_GLFWwindow* window)
{
1180
    if (window->wl.xdg.toplevel)
1181
    {
1182
        xdg_toplevel_set_maximized(window->wl.xdg.toplevel);
1183
    }
1184
1185
1186
1187
1188
1189
    else if (window->wl.shellSurface)
    {
        // Let the compositor select the best output.
        wl_shell_surface_set_maximized(window->wl.shellSurface, NULL);
    }
    window->wl.maximized = GLFW_TRUE;
1190
1191
}

1192
1193
void _glfwPlatformShowWindow(_GLFWwindow* window)
{
1194
1195
1196
1197
1198
1199
1200
1201
    if (!window->wl.visible)
    {
        if (_glfw.wl.wmBase)
            createXdgSurface(window);
        else if (!window->wl.shellSurface)
            createShellSurface(window);
        window->wl.visible = GLFW_TRUE;
    }
1202
1203
1204
1205
}

void _glfwPlatformHideWindow(_GLFWwindow* window)
{
1206
    if (window->wl.xdg.toplevel)
1207
    {
1208
1209
1210
1211
1212
1213
1214
1215
1216
        xdg_toplevel_destroy(window->wl.xdg.toplevel);
        xdg_surface_destroy(window->wl.xdg.surface);
        window->wl.xdg.toplevel = NULL;
        window->wl.xdg.surface = NULL;
    }
    else if (window->wl.shellSurface)
    {
        wl_shell_surface_destroy(window->wl.shellSurface);
        window->wl.shellSurface = NULL;
1217
    }
1218
    window->wl.visible = GLFW_FALSE;
1219
1220
}

1221
1222
void _glfwPlatformRequestWindowAttention(_GLFWwindow* window)
{
Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
1223
1224
1225
    // TODO
    _glfwInputError(GLFW_PLATFORM_ERROR,
                    "Wayland: Window attention request not implemented yet");
1226
1227
}

Camilla Berglund's avatar
Camilla Berglund committed
1228
1229
void _glfwPlatformFocusWindow(_GLFWwindow* window)
{
1230
1231
    _glfwInputError(GLFW_PLATFORM_ERROR,
                    "Wayland: Focusing a window requires user interaction");
Camilla Berglund's avatar
Camilla Berglund committed
1232
1233
}

Camilla Berglund's avatar
Camilla Berglund committed
1234
1235
1236
1237
1238
1239
void _glfwPlatformSetWindowMonitor(_GLFWwindow* window,
                                   _GLFWmonitor* monitor,
                                   int xpos, int ypos,
                                   int width, int height,
                                   int refreshRate)
{
1240
    if (monitor)
1241
    {
1242
        setFullscreen(window, monitor, refreshRate);
1243
    }
1244
    else
1245
    {
1246
1247
1248
        if (window->wl.xdg.toplevel)
            xdg_toplevel_unset_fullscreen(window->wl.xdg.toplevel);
        else if (window->wl.shellSurface)
1249
            wl_shell_surface_set_toplevel(window->wl.shellSurface);
1250
        setIdleInhibitor(window, GLFW_FALSE);
1251
        if (!_glfw.wl.decorationManager)
1252
            createDecorations(window);
1253
    }
Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
1254
    _glfwInputWindowMonitor(window, monitor);
Camilla Berglund's avatar
Camilla Berglund committed
1255
1256
}

1257
1258
int _glfwPlatformWindowFocused(_GLFWwindow* window)
{
1259
    return _glfw.wl.keyboardFocus == window;
1260
1261
1262
1263
}

int _glfwPlatformWindowIconified(_GLFWwindow* window)
{
1264
1265
    // wl_shell doesn't have any iconified concept, and xdg-shell doesn’t give
    // any way to request whether a surface is iconified.
1266
    return GLFW_FALSE;
1267
1268
1269
1270
}

int _glfwPlatformWindowVisible(_GLFWwindow* window)
{
1271
    return window->wl.visible;
1272
1273
}

1274
1275
int _glfwPlatformWindowMaximized(_GLFWwindow* window)
{
1276
    return window->wl.maximized;
1277
1278
}

1279
1280
1281
1282
1283
int _glfwPlatformWindowHovered(_GLFWwindow* window)
{
    return window->wl.hovered;
}

1284
1285
int _glfwPlatformFramebufferTransparent(_GLFWwindow* window)
{
1286
    return window->wl.transparent;
1287
1288
}

Camilla Löwy's avatar
Camilla Löwy committed
1289
1290
1291
1292
1293
1294
1295
1296
1297
void _glfwPlatformSetWindowResizable(_GLFWwindow* window, GLFWbool enabled)
{
    // TODO
    _glfwInputError(GLFW_PLATFORM_ERROR,
                    "Wayland: Window attribute setting not implemented yet");
}

void _glfwPlatformSetWindowDecorated(_GLFWwindow* window, GLFWbool enabled)
{
1298
1299
1300
1301
1302
1303
1304
    if (!window->monitor)
    {
        if (enabled)
            createDecorations(window);
        else
            destroyDecorations(window);
    }
Camilla Löwy's avatar
Camilla Löwy committed
1305
1306
1307
1308
1309
1310
1311
1312
1313
}

void _glfwPlatformSetWindowFloating(_GLFWwindow* window, GLFWbool enabled)
{
    // TODO
    _glfwInputError(GLFW_PLATFORM_ERROR,
                    "Wayland: Window attribute setting not implemented yet");
}

1314
1315
1316
1317
1318
1319
1320
1321
1322
float _glfwPlatformGetWindowOpacity(_GLFWwindow* window)
{
    return 1.f;
}

void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity)
{
}

</