Skip to content

Latest commit

 

History

History
943 lines (785 loc) · 33 KB

SDL_waylandwindow.c

File metadata and controls

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