2015-06-21 17:33:46 +02:00
|
|
|
/*
|
|
|
|
Simple DirectMedia Layer
|
2021-01-02 19:25:38 +01:00
|
|
|
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
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"
|
2016-09-01 10:26:56 +02:00
|
|
|
#include "SDL_waylandevents_c.h"
|
2015-06-21 17:33:46 +02:00
|
|
|
#include "SDL_waylandwindow.h"
|
|
|
|
#include "SDL_waylandvideo.h"
|
|
|
|
#include "SDL_waylandtouch.h"
|
|
|
|
#include "SDL_waylanddyn.h"
|
2016-11-13 10:39:04 +01:00
|
|
|
#include "SDL_hints.h"
|
2015-06-21 17:33:46 +02:00
|
|
|
|
2018-06-25 07:42:36 +02:00
|
|
|
#include "xdg-shell-client-protocol.h"
|
2018-02-07 19:13:55 +01:00
|
|
|
#include "xdg-shell-unstable-v6-client-protocol.h"
|
2018-11-04 21:08:40 +01:00
|
|
|
#include "xdg-decoration-unstable-v1-client-protocol.h"
|
2021-01-21 04:17:20 +01:00
|
|
|
#include "idle-inhibit-unstable-v1-client-protocol.h"
|
2018-02-07 19:13:55 +01:00
|
|
|
|
2019-06-12 00:55:05 +02:00
|
|
|
static float get_window_scale_factor(SDL_Window *window) {
|
|
|
|
return ((SDL_WindowData*)window->driverdata)->scale_factor;
|
|
|
|
}
|
|
|
|
|
2021-04-07 00:10:40 +02:00
|
|
|
static void
|
|
|
|
CommitMinMaxDimensions(SDL_Window *window)
|
|
|
|
{
|
|
|
|
SDL_WindowData *wind = window->driverdata;
|
|
|
|
SDL_VideoData *data = wind->waylandData;
|
|
|
|
int min_width, min_height, max_width, max_height;
|
|
|
|
|
|
|
|
if (window->flags & SDL_WINDOW_FULLSCREEN) {
|
|
|
|
min_width = 0;
|
|
|
|
min_height = 0;
|
|
|
|
max_width = 0;
|
|
|
|
max_height = 0;
|
|
|
|
} else if (window->flags & SDL_WINDOW_RESIZABLE) {
|
|
|
|
min_width = window->min_w;
|
|
|
|
min_height = window->min_h;
|
|
|
|
max_width = window->max_w;
|
|
|
|
max_height = window->max_h;
|
|
|
|
} else {
|
|
|
|
min_width = window->w;
|
|
|
|
min_height = window->h;
|
|
|
|
max_width = window->w;
|
|
|
|
max_height = window->h;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data->shell.xdg) {
|
2021-04-20 18:40:40 +02:00
|
|
|
if (wind->shell_surface.xdg.roleobj.toplevel == NULL) {
|
|
|
|
return; /* Can't do anything yet, wait for ShowWindow */
|
|
|
|
}
|
2021-04-07 00:10:40 +02:00
|
|
|
xdg_toplevel_set_min_size(wind->shell_surface.xdg.roleobj.toplevel,
|
|
|
|
min_width,
|
|
|
|
min_height);
|
|
|
|
xdg_toplevel_set_max_size(wind->shell_surface.xdg.roleobj.toplevel,
|
|
|
|
max_width,
|
|
|
|
max_height);
|
|
|
|
} else if (data->shell.zxdg) {
|
2021-04-20 18:40:40 +02:00
|
|
|
if (wind->shell_surface.zxdg.roleobj.toplevel == NULL) {
|
|
|
|
return; /* Can't do anything yet, wait for ShowWindow */
|
|
|
|
}
|
2021-04-07 00:10:40 +02:00
|
|
|
zxdg_toplevel_v6_set_min_size(wind->shell_surface.zxdg.roleobj.toplevel,
|
|
|
|
min_width,
|
|
|
|
min_height);
|
|
|
|
zxdg_toplevel_v6_set_max_size(wind->shell_surface.zxdg.roleobj.toplevel,
|
|
|
|
max_width,
|
|
|
|
max_height);
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_surface_commit(wind->surface);
|
|
|
|
}
|
|
|
|
|
2021-01-22 04:49:13 +01:00
|
|
|
static void
|
|
|
|
SetFullscreen(SDL_Window *window, struct wl_output *output)
|
|
|
|
{
|
|
|
|
SDL_WindowData *wind = window->driverdata;
|
|
|
|
SDL_VideoData *viddata = wind->waylandData;
|
|
|
|
|
2021-04-07 00:10:40 +02:00
|
|
|
/* The desktop may try to enforce min/max sizes here, so turn them off for
|
|
|
|
* fullscreen and on (if applicable) for windowed
|
|
|
|
*/
|
|
|
|
CommitMinMaxDimensions(window);
|
|
|
|
|
2021-01-22 04:49:13 +01:00
|
|
|
if (viddata->shell.xdg) {
|
2021-04-20 18:40:40 +02:00
|
|
|
if (wind->shell_surface.xdg.roleobj.toplevel == NULL) {
|
|
|
|
return; /* Can't do anything yet, wait for ShowWindow */
|
|
|
|
}
|
2021-01-22 04:49:13 +01:00
|
|
|
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) {
|
2021-04-20 18:40:40 +02:00
|
|
|
if (wind->shell_surface.zxdg.roleobj.toplevel == NULL) {
|
|
|
|
return; /* Can't do anything yet, wait for ShowWindow */
|
|
|
|
}
|
2021-01-22 04:49:13 +01:00
|
|
|
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 {
|
2021-04-20 18:40:40 +02:00
|
|
|
if (wind->shell_surface.wl == NULL) {
|
|
|
|
return; /* Can't do anything yet, wait for ShowWindow */
|
|
|
|
}
|
2021-01-22 04:49:13 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WAYLAND_wl_display_flush(viddata->display);
|
|
|
|
}
|
|
|
|
|
2018-02-07 19:13:55 +01:00
|
|
|
/* 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. */
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
static void
|
2018-02-07 19:13:55 +01:00
|
|
|
handle_ping_wl_shell_surface(void *data, struct wl_shell_surface *shell_surface,
|
2015-06-21 17:33:46 +02:00
|
|
|
uint32_t serial)
|
|
|
|
{
|
|
|
|
wl_shell_surface_pong(shell_surface, serial);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-02-07 19:13:55 +01:00
|
|
|
handle_configure_wl_shell_surface(void *data, struct wl_shell_surface *shell_surface,
|
2015-06-21 17:33:46 +02:00
|
|
|
uint32_t edges, int32_t width, int32_t height)
|
|
|
|
{
|
|
|
|
SDL_WindowData *wind = (SDL_WindowData *)data;
|
|
|
|
SDL_Window *window = wind->sdlwindow;
|
|
|
|
|
2016-10-08 03:11:03 +02:00
|
|
|
/* 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);
|
2018-11-07 01:08:35 +01:00
|
|
|
}
|
2016-10-08 03:11:03 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-07 01:08:35 +01:00
|
|
|
wind->resize.width = width;
|
|
|
|
wind->resize.height = height;
|
|
|
|
wind->resize.pending = SDL_TRUE;
|
2020-02-14 06:58:36 +01:00
|
|
|
|
|
|
|
if (!(window->flags & SDL_WINDOW_OPENGL)) {
|
|
|
|
Wayland_HandlePendingResize(window); /* OpenGL windows handle this in SwapWindow */
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-02-07 19:13:55 +01:00
|
|
|
handle_popup_done_wl_shell_surface(void *data, struct wl_shell_surface *shell_surface)
|
2015-06-21 17:33:46 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-02-07 19:13:55 +01:00
|
|
|
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
|
2015-06-21 17:33:46 +02:00
|
|
|
};
|
|
|
|
|
2018-02-07 19:13:55 +01:00
|
|
|
|
2021-04-30 19:19:36 +02:00
|
|
|
static const struct wl_callback_listener surface_frame_listener;
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_surface_frame_done(void *data, struct wl_callback *cb, uint32_t time)
|
|
|
|
{
|
|
|
|
SDL_WindowData *wind = (SDL_WindowData *) data;
|
|
|
|
SDL_AtomicSet(&wind->swap_interval_ready, 1); /* mark window as ready to present again. */
|
|
|
|
|
|
|
|
/* reset this callback to fire again once a new frame was presented and compositor wants the next one. */
|
|
|
|
wl_callback_destroy(cb);
|
|
|
|
wl_callback_add_listener(wl_surface_frame(wind->surface), &surface_frame_listener, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_callback_listener surface_frame_listener = {
|
|
|
|
handle_surface_frame_done
|
|
|
|
};
|
2018-02-07 19:13:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
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;
|
2018-04-15 23:42:09 +02:00
|
|
|
|
2018-11-07 01:08:35 +01:00
|
|
|
if (!wind->shell_surface.zxdg.initial_configure_seen) {
|
2019-06-12 00:55:05 +02:00
|
|
|
window->w = 0;
|
|
|
|
window->h = 0;
|
2018-11-07 01:08:35 +01:00
|
|
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, wind->resize.width, wind->resize.height);
|
|
|
|
window->w = wind->resize.width;
|
|
|
|
window->h = wind->resize.height;
|
|
|
|
|
2019-06-12 00:55:05 +02:00
|
|
|
wl_surface_set_buffer_scale(wind->surface, get_window_scale_factor(window));
|
2020-02-14 07:08:21 +01:00
|
|
|
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);
|
|
|
|
}
|
2018-11-07 01:08:35 +01:00
|
|
|
|
|
|
|
zxdg_surface_v6_ack_configure(zxdg, serial);
|
2018-04-15 23:42:09 +02:00
|
|
|
|
2018-11-07 01:08:35 +01:00
|
|
|
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);
|
2018-02-07 19:13:55 +01:00
|
|
|
|
2018-11-07 01:08:35 +01:00
|
|
|
wind->shell_surface.zxdg.initial_configure_seen = SDL_TRUE;
|
|
|
|
} else {
|
|
|
|
wind->resize.pending = SDL_TRUE;
|
2019-06-12 00:55:05 +02:00
|
|
|
wind->resize.configure = SDL_TRUE;
|
2018-11-07 01:08:35 +01:00
|
|
|
wind->resize.serial = serial;
|
2020-02-14 06:58:36 +01:00
|
|
|
if (!(window->flags & SDL_WINDOW_OPENGL)) {
|
|
|
|
Wayland_HandlePendingResize(window); /* OpenGL windows handle this in SwapWindow */
|
|
|
|
}
|
2018-11-07 01:08:35 +01:00
|
|
|
}
|
2018-02-07 19:13:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct zxdg_surface_v6_listener shell_surface_listener_zxdg = {
|
|
|
|
handle_configure_zxdg_shell_surface
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_configure_zxdg_toplevel(void *data,
|
2018-09-24 20:49:25 +02:00
|
|
|
struct zxdg_toplevel_v6 *zxdg_toplevel_v6,
|
|
|
|
int32_t width,
|
|
|
|
int32_t height,
|
|
|
|
struct wl_array *states)
|
2018-02-07 19:13:55 +01:00
|
|
|
{
|
|
|
|
SDL_WindowData *wind = (SDL_WindowData *)data;
|
|
|
|
SDL_Window *window = wind->sdlwindow;
|
|
|
|
|
2018-11-07 01:08:35 +01:00
|
|
|
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;
|
|
|
|
}
|
2018-02-07 19:13:55 +01:00
|
|
|
}
|
|
|
|
|
2018-11-07 01:08:35 +01:00
|
|
|
if (!fullscreen) {
|
2021-01-22 04:49:13 +01:00
|
|
|
if (window->flags & SDL_WINDOW_FULLSCREEN) {
|
|
|
|
/* We might need to re-enter fullscreen after being restored from minimized */
|
2021-04-07 22:44:10 +02:00
|
|
|
SDL_WaylandOutputData *driverdata = (SDL_WaylandOutputData *) SDL_GetDisplayForWindow(window)->driverdata;
|
|
|
|
SetFullscreen(window, driverdata->output);
|
2021-01-22 04:49:13 +01:00
|
|
|
}
|
|
|
|
|
2018-11-07 01:08:35 +01:00
|
|
|
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. */
|
|
|
|
|
2018-02-07 19:13:55 +01:00
|
|
|
if ((window->flags & SDL_WINDOW_RESIZABLE)) {
|
|
|
|
if (window->max_w > 0) {
|
|
|
|
width = SDL_min(width, window->max_w);
|
2018-11-07 01:08:35 +01:00
|
|
|
}
|
2018-02-07 19:13:55 +01:00
|
|
|
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 {
|
2018-11-07 01:08:35 +01:00
|
|
|
wind->resize.width = window->w;
|
|
|
|
wind->resize.height = window->h;
|
2018-02-07 19:13:55 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-07 01:08:35 +01:00
|
|
|
if (width == 0 || height == 0) {
|
|
|
|
wind->resize.width = window->w;
|
|
|
|
wind->resize.height = window->h;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wind->resize.width = width;
|
|
|
|
wind->resize.height = height;
|
2018-02-07 19:13:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-06-25 07:42:36 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2018-11-07 01:08:35 +01:00
|
|
|
if (!wind->shell_surface.xdg.initial_configure_seen) {
|
2019-06-12 00:55:05 +02:00
|
|
|
window->w = 0;
|
|
|
|
window->h = 0;
|
2018-11-07 01:08:35 +01:00
|
|
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, wind->resize.width, wind->resize.height);
|
|
|
|
window->w = wind->resize.width;
|
|
|
|
window->h = wind->resize.height;
|
|
|
|
|
2019-06-12 00:55:05 +02:00
|
|
|
wl_surface_set_buffer_scale(wind->surface, get_window_scale_factor(window));
|
2020-02-14 07:08:21 +01:00
|
|
|
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);
|
|
|
|
}
|
2018-11-07 01:08:35 +01:00
|
|
|
|
|
|
|
xdg_surface_ack_configure(xdg, serial);
|
2018-06-25 07:42:36 +02:00
|
|
|
|
2018-11-07 01:08:35 +01:00
|
|
|
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);
|
2018-06-25 07:42:36 +02:00
|
|
|
|
2018-11-07 01:08:35 +01:00
|
|
|
wind->shell_surface.xdg.initial_configure_seen = SDL_TRUE;
|
|
|
|
} else {
|
|
|
|
wind->resize.pending = SDL_TRUE;
|
2019-06-12 00:55:05 +02:00
|
|
|
wind->resize.configure = SDL_TRUE;
|
2018-11-07 01:08:35 +01:00
|
|
|
wind->resize.serial = serial;
|
2020-02-14 06:58:36 +01:00
|
|
|
if (!(window->flags & SDL_WINDOW_OPENGL)) {
|
|
|
|
Wayland_HandlePendingResize(window); /* OpenGL windows handle this in SwapWindow */
|
|
|
|
}
|
2018-11-07 01:08:35 +01:00
|
|
|
}
|
2018-06-25 07:42:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct xdg_surface_listener shell_surface_listener_xdg = {
|
|
|
|
handle_configure_xdg_shell_surface
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_configure_xdg_toplevel(void *data,
|
2018-09-24 20:49:25 +02:00
|
|
|
struct xdg_toplevel *xdg_toplevel,
|
|
|
|
int32_t width,
|
|
|
|
int32_t height,
|
|
|
|
struct wl_array *states)
|
2018-06-25 07:42:36 +02:00
|
|
|
{
|
|
|
|
SDL_WindowData *wind = (SDL_WindowData *)data;
|
|
|
|
SDL_Window *window = wind->sdlwindow;
|
|
|
|
|
2018-11-07 01:08:35 +01:00
|
|
|
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;
|
|
|
|
}
|
2021-04-07 00:10:40 +02:00
|
|
|
}
|
2018-06-25 07:42:36 +02:00
|
|
|
|
2018-11-07 01:08:35 +01:00
|
|
|
if (!fullscreen) {
|
2021-01-22 04:49:13 +01:00
|
|
|
if (window->flags & SDL_WINDOW_FULLSCREEN) {
|
|
|
|
/* We might need to re-enter fullscreen after being restored from minimized */
|
2021-04-07 22:44:10 +02:00
|
|
|
SDL_WaylandOutputData *driverdata = (SDL_WaylandOutputData *) SDL_GetDisplayForWindow(window)->driverdata;
|
|
|
|
SetFullscreen(window, driverdata->output);
|
2021-01-22 04:49:13 +01:00
|
|
|
}
|
|
|
|
|
2018-11-07 01:08:35 +01:00
|
|
|
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. */
|
2018-06-25 07:42:36 +02:00
|
|
|
|
|
|
|
if ((window->flags & SDL_WINDOW_RESIZABLE)) {
|
|
|
|
if (window->max_w > 0) {
|
|
|
|
width = SDL_min(width, window->max_w);
|
2018-11-07 01:08:35 +01:00
|
|
|
}
|
2018-06-25 07:42:36 +02:00
|
|
|
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 {
|
2018-11-07 01:08:35 +01:00
|
|
|
wind->resize.width = window->w;
|
|
|
|
wind->resize.height = window->h;
|
2018-06-25 07:42:36 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-07 01:08:35 +01:00
|
|
|
if (width == 0 || height == 0) {
|
|
|
|
wind->resize.width = window->w;
|
|
|
|
wind->resize.height = window->h;
|
2018-06-25 07:42:36 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-07 01:08:35 +01:00
|
|
|
wind->resize.width = width;
|
|
|
|
wind->resize.height = height;
|
2018-06-25 07:42:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
#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 */
|
|
|
|
|
2019-06-12 00:55:05 +02:00
|
|
|
static void
|
|
|
|
update_scale_factor(SDL_WindowData *window) {
|
|
|
|
float old_factor = window->scale_factor, new_factor = 0.0;
|
2019-06-19 06:52:34 +02:00
|
|
|
int i;
|
2019-06-12 00:55:05 +02:00
|
|
|
|
|
|
|
if (!(window->sdlwindow->flags & SDL_WINDOW_ALLOW_HIGHDPI)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!window->num_outputs) {
|
|
|
|
new_factor = old_factor;
|
|
|
|
}
|
|
|
|
|
2021-04-07 22:44:10 +02:00
|
|
|
if (FULLSCREEN_VISIBLE(window->sdlwindow)) {
|
|
|
|
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window->sdlwindow);
|
2021-02-01 17:57:39 +01:00
|
|
|
SDL_WaylandOutputData* driverdata = display->driverdata;
|
|
|
|
new_factor = driverdata->scale_factor;
|
2019-06-12 00:55:05 +02:00
|
|
|
}
|
|
|
|
|
2019-06-19 06:52:34 +02:00
|
|
|
for (i = 0; i < window->num_outputs; i++) {
|
wayland: Implement basic window move events via wl_surface_listener.
This unearthed an unspeakably large amount of bugs in the wl_output enumerator,
notably the fact that the wl_output user pointer was to temporary memory!
This was "fixed" in e862856, and was then pointed out as a leak in 4183211,
which was undone in d9ba204. The busted fix was correct that the malloc was an
issue, but wrong about _why_; SDL_AddVideoDisplay copies by value and does not
reuse the pointer, so generally you want your VideoDisplay to be on the stack,
but of course the callbacks don't allow that, so a malloc was a workaround. But
we can do better and just host our temporary display inside WaylandOutputData
because that will be persistent while also not leaking.
Wait, wasn't I talking about move events? Right, that: wl_surface_listener does
at least give us the ability to know what monitor we're on, even though we have
no idea where we are on the monitor. All we need to do is check the wl_output
against the display list and then push a move event that both indicates the
correct display while also not being _too_ much of a lie (but enough of a lie
to where our event doesn't get discarded as "undefined" or whatever). The index
check for the video display is what spawned the great nightmare you see before
you; aside from the bugfix this is actually a really basic patch.
2021-04-17 03:35:50 +02:00
|
|
|
SDL_WaylandOutputData* driverdata = wl_output_get_user_data(window->outputs[i]);
|
2021-02-01 17:57:39 +01:00
|
|
|
float factor = driverdata->scale_factor;
|
2019-06-12 00:55:05 +02:00
|
|
|
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;
|
2020-02-14 06:58:36 +01:00
|
|
|
if (!(window->sdlwindow->flags & SDL_WINDOW_OPENGL)) {
|
|
|
|
Wayland_HandlePendingResize(window->sdlwindow); /* OpenGL windows handle this in SwapWindow */
|
|
|
|
}
|
2019-06-12 00:55:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
wayland: Implement basic window move events via wl_surface_listener.
This unearthed an unspeakably large amount of bugs in the wl_output enumerator,
notably the fact that the wl_output user pointer was to temporary memory!
This was "fixed" in e862856, and was then pointed out as a leak in 4183211,
which was undone in d9ba204. The busted fix was correct that the malloc was an
issue, but wrong about _why_; SDL_AddVideoDisplay copies by value and does not
reuse the pointer, so generally you want your VideoDisplay to be on the stack,
but of course the callbacks don't allow that, so a malloc was a workaround. But
we can do better and just host our temporary display inside WaylandOutputData
because that will be persistent while also not leaking.
Wait, wasn't I talking about move events? Right, that: wl_surface_listener does
at least give us the ability to know what monitor we're on, even though we have
no idea where we are on the monitor. All we need to do is check the wl_output
against the display list and then push a move event that both indicates the
correct display while also not being _too_ much of a lie (but enough of a lie
to where our event doesn't get discarded as "undefined" or whatever). The index
check for the video display is what spawned the great nightmare you see before
you; aside from the bugfix this is actually a really basic patch.
2021-04-17 03:35:50 +02:00
|
|
|
/* While we can't get window position from the compositor, we do at least know
|
|
|
|
* what monitor we're on, so let's send move events that put the window at the
|
|
|
|
* center of the whatever display the wl_surface_listener events give us.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
Wayland_move_window(SDL_Window *window,
|
|
|
|
SDL_WaylandOutputData *driverdata)
|
|
|
|
{
|
|
|
|
int i, numdisplays = SDL_GetNumVideoDisplays();
|
|
|
|
for (i = 0; i < numdisplays; i += 1) {
|
|
|
|
if (SDL_GetDisplay(i)->driverdata == driverdata) {
|
|
|
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED,
|
|
|
|
SDL_WINDOWPOS_CENTERED_DISPLAY(i),
|
|
|
|
SDL_WINDOWPOS_CENTERED_DISPLAY(i));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-12 00:55:05 +02:00
|
|
|
static void
|
|
|
|
handle_surface_enter(void *data, struct wl_surface *surface,
|
wayland: Implement basic window move events via wl_surface_listener.
This unearthed an unspeakably large amount of bugs in the wl_output enumerator,
notably the fact that the wl_output user pointer was to temporary memory!
This was "fixed" in e862856, and was then pointed out as a leak in 4183211,
which was undone in d9ba204. The busted fix was correct that the malloc was an
issue, but wrong about _why_; SDL_AddVideoDisplay copies by value and does not
reuse the pointer, so generally you want your VideoDisplay to be on the stack,
but of course the callbacks don't allow that, so a malloc was a workaround. But
we can do better and just host our temporary display inside WaylandOutputData
because that will be persistent while also not leaking.
Wait, wasn't I talking about move events? Right, that: wl_surface_listener does
at least give us the ability to know what monitor we're on, even though we have
no idea where we are on the monitor. All we need to do is check the wl_output
against the display list and then push a move event that both indicates the
correct display while also not being _too_ much of a lie (but enough of a lie
to where our event doesn't get discarded as "undefined" or whatever). The index
check for the video display is what spawned the great nightmare you see before
you; aside from the bugfix this is actually a really basic patch.
2021-04-17 03:35:50 +02:00
|
|
|
struct wl_output *output)
|
|
|
|
{
|
2019-06-12 00:55:05 +02:00
|
|
|
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);
|
wayland: Implement basic window move events via wl_surface_listener.
This unearthed an unspeakably large amount of bugs in the wl_output enumerator,
notably the fact that the wl_output user pointer was to temporary memory!
This was "fixed" in e862856, and was then pointed out as a leak in 4183211,
which was undone in d9ba204. The busted fix was correct that the malloc was an
issue, but wrong about _why_; SDL_AddVideoDisplay copies by value and does not
reuse the pointer, so generally you want your VideoDisplay to be on the stack,
but of course the callbacks don't allow that, so a malloc was a workaround. But
we can do better and just host our temporary display inside WaylandOutputData
because that will be persistent while also not leaking.
Wait, wasn't I talking about move events? Right, that: wl_surface_listener does
at least give us the ability to know what monitor we're on, even though we have
no idea where we are on the monitor. All we need to do is check the wl_output
against the display list and then push a move event that both indicates the
correct display while also not being _too_ much of a lie (but enough of a lie
to where our event doesn't get discarded as "undefined" or whatever). The index
check for the video display is what spawned the great nightmare you see before
you; aside from the bugfix this is actually a really basic patch.
2021-04-17 03:35:50 +02:00
|
|
|
|
|
|
|
Wayland_move_window(window->sdlwindow, wl_output_get_user_data(output));
|
2019-06-12 00:55:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_surface_leave(void *data, struct wl_surface *surface,
|
wayland: Implement basic window move events via wl_surface_listener.
This unearthed an unspeakably large amount of bugs in the wl_output enumerator,
notably the fact that the wl_output user pointer was to temporary memory!
This was "fixed" in e862856, and was then pointed out as a leak in 4183211,
which was undone in d9ba204. The busted fix was correct that the malloc was an
issue, but wrong about _why_; SDL_AddVideoDisplay copies by value and does not
reuse the pointer, so generally you want your VideoDisplay to be on the stack,
but of course the callbacks don't allow that, so a malloc was a workaround. But
we can do better and just host our temporary display inside WaylandOutputData
because that will be persistent while also not leaking.
Wait, wasn't I talking about move events? Right, that: wl_surface_listener does
at least give us the ability to know what monitor we're on, even though we have
no idea where we are on the monitor. All we need to do is check the wl_output
against the display list and then push a move event that both indicates the
correct display while also not being _too_ much of a lie (but enough of a lie
to where our event doesn't get discarded as "undefined" or whatever). The index
check for the video display is what spawned the great nightmare you see before
you; aside from the bugfix this is actually a really basic patch.
2021-04-17 03:35:50 +02:00
|
|
|
struct wl_output *output)
|
|
|
|
{
|
2019-06-12 00:55:05 +02:00
|
|
|
SDL_WindowData *window = data;
|
wayland: Implement basic window move events via wl_surface_listener.
This unearthed an unspeakably large amount of bugs in the wl_output enumerator,
notably the fact that the wl_output user pointer was to temporary memory!
This was "fixed" in e862856, and was then pointed out as a leak in 4183211,
which was undone in d9ba204. The busted fix was correct that the malloc was an
issue, but wrong about _why_; SDL_AddVideoDisplay copies by value and does not
reuse the pointer, so generally you want your VideoDisplay to be on the stack,
but of course the callbacks don't allow that, so a malloc was a workaround. But
we can do better and just host our temporary display inside WaylandOutputData
because that will be persistent while also not leaking.
Wait, wasn't I talking about move events? Right, that: wl_surface_listener does
at least give us the ability to know what monitor we're on, even though we have
no idea where we are on the monitor. All we need to do is check the wl_output
against the display list and then push a move event that both indicates the
correct display while also not being _too_ much of a lie (but enough of a lie
to where our event doesn't get discarded as "undefined" or whatever). The index
check for the video display is what spawned the great nightmare you see before
you; aside from the bugfix this is actually a really basic patch.
2021-04-17 03:35:50 +02:00
|
|
|
int i, send_move_event = 0;
|
2019-06-12 00:55:05 +02:00
|
|
|
|
2020-05-28 21:18:41 +02:00
|
|
|
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;
|
wayland: Implement basic window move events via wl_surface_listener.
This unearthed an unspeakably large amount of bugs in the wl_output enumerator,
notably the fact that the wl_output user pointer was to temporary memory!
This was "fixed" in e862856, and was then pointed out as a leak in 4183211,
which was undone in d9ba204. The busted fix was correct that the malloc was an
issue, but wrong about _why_; SDL_AddVideoDisplay copies by value and does not
reuse the pointer, so generally you want your VideoDisplay to be on the stack,
but of course the callbacks don't allow that, so a malloc was a workaround. But
we can do better and just host our temporary display inside WaylandOutputData
because that will be persistent while also not leaking.
Wait, wasn't I talking about move events? Right, that: wl_surface_listener does
at least give us the ability to know what monitor we're on, even though we have
no idea where we are on the monitor. All we need to do is check the wl_output
against the display list and then push a move event that both indicates the
correct display while also not being _too_ much of a lie (but enough of a lie
to where our event doesn't get discarded as "undefined" or whatever). The index
check for the video display is what spawned the great nightmare you see before
you; aside from the bugfix this is actually a really basic patch.
2021-04-17 03:35:50 +02:00
|
|
|
send_move_event = 1;
|
2020-05-28 21:18:41 +02:00
|
|
|
} 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) {
|
2019-06-12 00:55:05 +02:00
|
|
|
SDL_free(window->outputs);
|
|
|
|
window->outputs = NULL;
|
wayland: Implement basic window move events via wl_surface_listener.
This unearthed an unspeakably large amount of bugs in the wl_output enumerator,
notably the fact that the wl_output user pointer was to temporary memory!
This was "fixed" in e862856, and was then pointed out as a leak in 4183211,
which was undone in d9ba204. The busted fix was correct that the malloc was an
issue, but wrong about _why_; SDL_AddVideoDisplay copies by value and does not
reuse the pointer, so generally you want your VideoDisplay to be on the stack,
but of course the callbacks don't allow that, so a malloc was a workaround. But
we can do better and just host our temporary display inside WaylandOutputData
because that will be persistent while also not leaking.
Wait, wasn't I talking about move events? Right, that: wl_surface_listener does
at least give us the ability to know what monitor we're on, even though we have
no idea where we are on the monitor. All we need to do is check the wl_output
against the display list and then push a move event that both indicates the
correct display while also not being _too_ much of a lie (but enough of a lie
to where our event doesn't get discarded as "undefined" or whatever). The index
check for the video display is what spawned the great nightmare you see before
you; aside from the bugfix this is actually a really basic patch.
2021-04-17 03:35:50 +02:00
|
|
|
} else if (send_move_event) {
|
|
|
|
Wayland_move_window(window->sdlwindow,
|
|
|
|
wl_output_get_user_data(window->outputs[window->num_outputs - 1]));
|
2019-06-12 00:55:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
update_scale_factor(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_surface_listener surface_listener = {
|
|
|
|
handle_surface_enter,
|
|
|
|
handle_surface_leave
|
|
|
|
};
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
SDL_bool
|
|
|
|
Wayland_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
|
|
|
|
{
|
|
|
|
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
2021-01-14 23:42:53 +01:00
|
|
|
const Uint32 version = SDL_VERSIONNUM((Uint32)info->version.major,
|
|
|
|
(Uint32)info->version.minor,
|
|
|
|
(Uint32)info->version.patch);
|
2017-06-11 06:50:26 +02:00
|
|
|
|
|
|
|
/* 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. */
|
2021-01-14 23:42:53 +01:00
|
|
|
if (version < SDL_VERSIONNUM(2, 0, 6)) {
|
2017-06-11 06:50:26 +02:00
|
|
|
info->subsystem = SDL_SYSWM_UNKNOWN;
|
2017-06-11 22:30:39 +02:00
|
|
|
SDL_SetError("Version must be 2.0.6 or newer");
|
2017-06-11 06:50:26 +02:00
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
info->info.wl.display = data->waylandData->display;
|
|
|
|
info->info.wl.surface = data->surface;
|
2018-02-07 19:13:55 +01:00
|
|
|
info->info.wl.shell_surface = data->shell_surface.wl;
|
2021-01-14 23:42:53 +01:00
|
|
|
if (version >= SDL_VERSIONNUM(2, 0, 15)) {
|
|
|
|
info->info.wl.egl_window = data->egl_window;
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
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. */
|
|
|
|
}
|
|
|
|
|
2021-04-18 15:45:22 +02:00
|
|
|
int
|
|
|
|
Wayland_SetWindowModalFor(_THIS, SDL_Window *modal_window, SDL_Window *parent_window)
|
|
|
|
{
|
|
|
|
const SDL_VideoData *viddata = (const SDL_VideoData *) _this->driverdata;
|
|
|
|
SDL_WindowData *modal_data = modal_window->driverdata;
|
|
|
|
SDL_WindowData *parent_data = parent_window->driverdata;
|
|
|
|
|
|
|
|
if (viddata->shell.xdg) {
|
2021-04-20 18:40:40 +02:00
|
|
|
if (modal_data->shell_surface.xdg.roleobj.toplevel == NULL) {
|
|
|
|
return SDL_SetError("Modal window was hidden");
|
|
|
|
}
|
|
|
|
if (parent_data->shell_surface.xdg.roleobj.toplevel == NULL) {
|
|
|
|
return SDL_SetError("Parent window was hidden");
|
|
|
|
}
|
2021-04-18 15:45:22 +02:00
|
|
|
xdg_toplevel_set_parent(modal_data->shell_surface.xdg.roleobj.toplevel,
|
|
|
|
parent_data->shell_surface.xdg.roleobj.toplevel);
|
|
|
|
} else if (viddata->shell.zxdg) {
|
2021-04-20 18:40:40 +02:00
|
|
|
if (modal_data->shell_surface.zxdg.roleobj.toplevel == NULL) {
|
|
|
|
return SDL_SetError("Modal window was hidden");
|
|
|
|
}
|
|
|
|
if (parent_data->shell_surface.zxdg.roleobj.toplevel == NULL) {
|
|
|
|
return SDL_SetError("Parent window was hidden");
|
|
|
|
}
|
2021-04-18 15:45:22 +02:00
|
|
|
zxdg_toplevel_v6_set_parent(modal_data->shell_surface.zxdg.roleobj.toplevel,
|
|
|
|
parent_data->shell_surface.zxdg.roleobj.toplevel);
|
|
|
|
} else {
|
|
|
|
return SDL_Unsupported();
|
|
|
|
}
|
|
|
|
|
|
|
|
WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-07 19:13:55 +01:00
|
|
|
void Wayland_ShowWindow(_THIS, SDL_Window *window)
|
|
|
|
{
|
2021-04-20 18:40:40 +02:00
|
|
|
SDL_VideoData *c = _this->driverdata;
|
|
|
|
SDL_WindowData *data = window->driverdata;
|
|
|
|
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
|
|
|
|
|
|
|
/* Detach any previous buffers before resetting everything, otherwise when
|
|
|
|
* calling this a second time you'll get an annoying protocol error
|
|
|
|
*/
|
|
|
|
wl_surface_attach(data->surface, NULL, 0, 0);
|
|
|
|
wl_surface_commit(data->surface);
|
|
|
|
|
|
|
|
/* Create the shell surface and map the toplevel */
|
|
|
|
if (c->shell.xdg) {
|
|
|
|
data->shell_surface.xdg.surface = xdg_wm_base_get_xdg_surface(c->shell.xdg, data->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);
|
|
|
|
|
|
|
|
/* !!! FIXME: add popup role */
|
|
|
|
data->shell_surface.xdg.roleobj.toplevel = xdg_surface_get_toplevel(data->shell_surface.xdg.surface);
|
|
|
|
xdg_toplevel_set_app_id(data->shell_surface.xdg.roleobj.toplevel, c->classname);
|
|
|
|
xdg_toplevel_add_listener(data->shell_surface.xdg.roleobj.toplevel, &toplevel_listener_xdg, data);
|
|
|
|
|
|
|
|
/* Create the window decorations */
|
|
|
|
if (c->decoration_manager) {
|
|
|
|
data->server_decoration = zxdg_decoration_manager_v1_get_toplevel_decoration(c->decoration_manager, data->shell_surface.xdg.roleobj.toplevel);
|
|
|
|
}
|
|
|
|
} else if (c->shell.zxdg) {
|
|
|
|
data->shell_surface.zxdg.surface = zxdg_shell_v6_get_xdg_surface(c->shell.zxdg, data->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);
|
|
|
|
|
|
|
|
/* !!! 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);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Restore state that was set prior to this call */
|
|
|
|
Wayland_SetWindowTitle(_this, window);
|
|
|
|
Wayland_SetWindowBordered(_this, window, (window->flags & SDL_WINDOW_BORDERLESS) == 0);
|
|
|
|
if (window->flags & SDL_WINDOW_MAXIMIZED) {
|
|
|
|
Wayland_MaximizeWindow(_this, window);
|
|
|
|
}
|
|
|
|
if (window->flags & SDL_WINDOW_MINIMIZED) {
|
|
|
|
Wayland_MinimizeWindow(_this, window);
|
|
|
|
}
|
|
|
|
Wayland_SetWindowFullscreen(_this, window, display, (window->flags & SDL_WINDOW_FULLSCREEN) != 0);
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
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) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Wayland_HideWindow(_THIS, SDL_Window *window)
|
|
|
|
{
|
|
|
|
SDL_VideoData *data = _this->driverdata;
|
|
|
|
SDL_WindowData *wind = window->driverdata;
|
|
|
|
|
|
|
|
if (wind->server_decoration) {
|
|
|
|
zxdg_toplevel_decoration_v1_destroy(wind->server_decoration);
|
|
|
|
wind->server_decoration = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data->shell.xdg) {
|
|
|
|
if (wind->shell_surface.xdg.roleobj.toplevel) {
|
|
|
|
xdg_toplevel_destroy(wind->shell_surface.xdg.roleobj.toplevel);
|
|
|
|
wind->shell_surface.xdg.roleobj.toplevel = NULL;
|
|
|
|
}
|
|
|
|
if (wind->shell_surface.xdg.surface) {
|
|
|
|
xdg_surface_destroy(wind->shell_surface.xdg.surface);
|
|
|
|
wind->shell_surface.xdg.surface = NULL;
|
|
|
|
}
|
|
|
|
} else if (data->shell.zxdg) {
|
|
|
|
if (wind->shell_surface.zxdg.roleobj.toplevel) {
|
|
|
|
zxdg_toplevel_v6_destroy(wind->shell_surface.zxdg.roleobj.toplevel);
|
|
|
|
wind->shell_surface.zxdg.roleobj.toplevel = NULL;
|
|
|
|
}
|
|
|
|
if (wind->shell_surface.zxdg.surface) {
|
|
|
|
zxdg_surface_v6_destroy(wind->shell_surface.zxdg.surface);
|
|
|
|
wind->shell_surface.zxdg.surface = NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (wind->shell_surface.wl) {
|
|
|
|
wl_shell_surface_destroy(wind->shell_surface.wl);
|
|
|
|
wind->shell_surface.wl = NULL;
|
|
|
|
}
|
|
|
|
}
|
2018-02-07 19:13:55 +01:00
|
|
|
}
|
|
|
|
|
2016-11-13 10:39:04 +01:00
|
|
|
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
|
2017-08-14 15:28:21 +02:00
|
|
|
static void SDLCALL
|
|
|
|
QtExtendedSurface_OnHintChanged(void *userdata, const char *name,
|
2016-11-13 10:39:04 +01:00
|
|
|
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 */
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
void
|
|
|
|
Wayland_SetWindowFullscreen(_THIS, SDL_Window * window,
|
|
|
|
SDL_VideoDisplay * _display, SDL_bool fullscreen)
|
|
|
|
{
|
2019-06-12 00:55:05 +02:00
|
|
|
struct wl_output *output = ((SDL_WaylandOutputData*) _display->driverdata)->output;
|
2021-01-22 04:49:13 +01:00
|
|
|
SetFullscreen(window, fullscreen ? output : NULL);
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
|
|
|
|
2016-10-08 03:11:03 +02:00
|
|
|
void
|
|
|
|
Wayland_RestoreWindow(_THIS, SDL_Window * window)
|
|
|
|
{
|
|
|
|
SDL_WindowData *wind = window->driverdata;
|
2018-02-07 19:13:55 +01:00
|
|
|
const SDL_VideoData *viddata = (const SDL_VideoData *) _this->driverdata;
|
2016-10-08 03:11:03 +02:00
|
|
|
|
2021-04-18 15:36:54 +02:00
|
|
|
/* Note that xdg-shell does NOT provide a way to unset minimize! */
|
2018-06-25 07:42:36 +02:00
|
|
|
if (viddata->shell.xdg) {
|
2021-04-20 18:40:40 +02:00
|
|
|
if (wind->shell_surface.xdg.roleobj.toplevel == NULL) {
|
|
|
|
return; /* Can't do anything yet, wait for ShowWindow */
|
|
|
|
}
|
2021-04-18 15:36:54 +02:00
|
|
|
xdg_toplevel_unset_maximized(wind->shell_surface.xdg.roleobj.toplevel);
|
2018-06-25 07:42:36 +02:00
|
|
|
} else if (viddata->shell.zxdg) {
|
2021-04-20 18:40:40 +02:00
|
|
|
if (wind->shell_surface.zxdg.roleobj.toplevel == NULL) {
|
|
|
|
return; /* Can't do anything yet, wait for ShowWindow */
|
|
|
|
}
|
2021-04-18 15:36:54 +02:00
|
|
|
zxdg_toplevel_v6_unset_maximized(wind->shell_surface.zxdg.roleobj.toplevel);
|
2018-02-07 19:13:55 +01:00
|
|
|
} else {
|
2021-04-20 18:40:40 +02:00
|
|
|
if (wind->shell_surface.wl == NULL) {
|
|
|
|
return; /* Can't do anything yet, wait for ShowWindow */
|
|
|
|
}
|
2018-02-07 19:13:55 +01:00
|
|
|
wl_shell_surface_set_toplevel(wind->shell_surface.wl);
|
|
|
|
}
|
2016-10-08 03:11:03 +02:00
|
|
|
|
|
|
|
WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
|
|
|
|
}
|
|
|
|
|
2018-10-29 15:14:59 +01:00
|
|
|
void
|
|
|
|
Wayland_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
|
|
|
|
{
|
|
|
|
SDL_WindowData *wind = window->driverdata;
|
|
|
|
const SDL_VideoData *viddata = (const SDL_VideoData *) _this->driverdata;
|
2018-11-04 21:08:40 +01:00
|
|
|
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);
|
2018-10-29 15:14:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-23 21:40:22 +01:00
|
|
|
void
|
|
|
|
Wayland_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable)
|
|
|
|
{
|
2021-04-07 00:10:40 +02:00
|
|
|
CommitMinMaxDimensions(window);
|
2021-01-23 21:40:22 +01:00
|
|
|
}
|
|
|
|
|
2016-10-08 03:11:03 +02:00
|
|
|
void
|
|
|
|
Wayland_MaximizeWindow(_THIS, SDL_Window * window)
|
|
|
|
{
|
|
|
|
SDL_WindowData *wind = window->driverdata;
|
2018-02-07 19:13:55 +01:00
|
|
|
SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
|
2016-10-08 03:11:03 +02:00
|
|
|
|
2018-06-25 07:42:36 +02:00
|
|
|
if (viddata->shell.xdg) {
|
2021-04-20 18:40:40 +02:00
|
|
|
if (wind->shell_surface.xdg.roleobj.toplevel == NULL) {
|
|
|
|
return; /* Can't do anything yet, wait for ShowWindow */
|
|
|
|
}
|
2018-06-25 07:42:36 +02:00
|
|
|
xdg_toplevel_set_maximized(wind->shell_surface.xdg.roleobj.toplevel);
|
|
|
|
} else if (viddata->shell.zxdg) {
|
2021-04-20 18:40:40 +02:00
|
|
|
if (wind->shell_surface.zxdg.roleobj.toplevel == NULL) {
|
|
|
|
return; /* Can't do anything yet, wait for ShowWindow */
|
|
|
|
}
|
2018-02-07 19:13:55 +01:00
|
|
|
zxdg_toplevel_v6_set_maximized(wind->shell_surface.zxdg.roleobj.toplevel);
|
|
|
|
} else {
|
2021-04-20 18:40:40 +02:00
|
|
|
if (wind->shell_surface.wl == NULL) {
|
|
|
|
return; /* Can't do anything yet, wait for ShowWindow */
|
|
|
|
}
|
2018-02-07 19:13:55 +01:00
|
|
|
wl_shell_surface_set_maximized(wind->shell_surface.wl, NULL);
|
|
|
|
}
|
2016-10-08 03:11:03 +02:00
|
|
|
|
2018-02-07 19:13:55 +01:00
|
|
|
WAYLAND_wl_display_flush( viddata->display );
|
2016-10-08 03:11:03 +02:00
|
|
|
}
|
|
|
|
|
2021-01-22 04:49:13 +01:00
|
|
|
void
|
|
|
|
Wayland_MinimizeWindow(_THIS, SDL_Window * window)
|
|
|
|
{
|
|
|
|
SDL_WindowData *wind = window->driverdata;
|
|
|
|
SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
|
|
|
|
|
|
|
|
if (viddata->shell.xdg) {
|
2021-04-20 18:40:40 +02:00
|
|
|
if (wind->shell_surface.xdg.roleobj.toplevel == NULL) {
|
|
|
|
return; /* Can't do anything yet, wait for ShowWindow */
|
|
|
|
}
|
2021-01-22 04:49:13 +01:00
|
|
|
xdg_toplevel_set_minimized(wind->shell_surface.xdg.roleobj.toplevel);
|
|
|
|
} else if (viddata->shell.zxdg) {
|
2021-04-20 18:40:40 +02:00
|
|
|
if (wind->shell_surface.zxdg.roleobj.toplevel == NULL) {
|
|
|
|
return; /* Can't do anything yet, wait for ShowWindow */
|
|
|
|
}
|
2021-01-22 04:49:13 +01:00
|
|
|
zxdg_toplevel_v6_set_minimized(wind->shell_surface.zxdg.roleobj.toplevel);
|
|
|
|
}
|
|
|
|
|
|
|
|
WAYLAND_wl_display_flush(viddata->display);
|
|
|
|
}
|
|
|
|
|
2020-04-17 19:55:44 +02:00
|
|
|
void
|
2021-01-26 04:42:14 +01:00
|
|
|
Wayland_SetWindowMouseGrab(_THIS, SDL_Window *window, SDL_bool grabbed)
|
2020-04-17 19:55:44 +02:00
|
|
|
{
|
|
|
|
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
|
|
|
|
|
2021-01-20 01:20:07 +01:00
|
|
|
if (grabbed) {
|
2020-04-17 19:55:44 +02:00
|
|
|
Wayland_input_confine_pointer(window, data->input);
|
2021-01-23 23:22:44 +01:00
|
|
|
} else {
|
|
|
|
Wayland_input_unconfine_pointer(data->input);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Wayland_SetWindowKeyboardGrab(_THIS, SDL_Window *window, SDL_bool grabbed)
|
|
|
|
{
|
|
|
|
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
|
2021-01-20 01:20:07 +01:00
|
|
|
|
2021-01-23 23:22:44 +01:00
|
|
|
if (grabbed) {
|
|
|
|
Wayland_input_grab_keyboard(window, data->input);
|
2021-01-20 01:20:07 +01:00
|
|
|
} else {
|
|
|
|
Wayland_input_ungrab_keyboard(window);
|
|
|
|
}
|
2020-04-17 19:55:44 +02:00
|
|
|
}
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
int Wayland_CreateWindow(_THIS, SDL_Window *window)
|
|
|
|
{
|
|
|
|
SDL_WindowData *data;
|
|
|
|
SDL_VideoData *c;
|
|
|
|
struct wl_region *region;
|
|
|
|
|
2020-05-04 22:19:26 +02:00
|
|
|
data = SDL_calloc(1, sizeof *data);
|
2015-06-21 17:33:46 +02:00
|
|
|
if (data == NULL)
|
|
|
|
return SDL_OutOfMemory();
|
|
|
|
|
|
|
|
c = _this->driverdata;
|
|
|
|
window->driverdata = data;
|
|
|
|
|
2020-02-14 07:08:21 +01:00
|
|
|
if (!(window->flags & SDL_WINDOW_VULKAN)) {
|
|
|
|
if (!(window->flags & SDL_WINDOW_OPENGL)) {
|
|
|
|
SDL_GL_LoadLibrary(NULL);
|
|
|
|
window->flags |= SDL_WINDOW_OPENGL;
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (window->x == SDL_WINDOWPOS_UNDEFINED) {
|
|
|
|
window->x = 0;
|
|
|
|
}
|
|
|
|
if (window->y == SDL_WINDOWPOS_UNDEFINED) {
|
|
|
|
window->y = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->waylandData = c;
|
|
|
|
data->sdlwindow = window;
|
|
|
|
|
2019-06-12 00:55:05 +02:00
|
|
|
data->scale_factor = 1.0;
|
|
|
|
|
|
|
|
if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
|
2019-06-19 06:52:34 +02:00
|
|
|
int i;
|
|
|
|
for (i=0; i < SDL_GetVideoDevice()->num_displays; i++) {
|
2019-06-12 00:55:05 +02:00
|
|
|
float scale = ((SDL_WaylandOutputData*)SDL_GetVideoDevice()->displays[i].driverdata)->scale_factor;
|
|
|
|
if (scale > data->scale_factor) {
|
|
|
|
data->scale_factor = scale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-07 01:08:35 +01:00
|
|
|
data->resize.pending = SDL_FALSE;
|
2019-06-12 00:55:05 +02:00
|
|
|
data->resize.width = window->w;
|
|
|
|
data->resize.height = window->h;
|
|
|
|
data->resize.scale_factor = data->scale_factor;
|
|
|
|
|
|
|
|
data->outputs = NULL;
|
|
|
|
data->num_outputs = 0;
|
2018-11-07 01:08:35 +01:00
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
data->surface =
|
|
|
|
wl_compositor_create_surface(c->compositor);
|
2019-06-12 00:55:05 +02:00
|
|
|
wl_surface_add_listener(data->surface, &surface_listener, data);
|
2018-02-07 19:13:55 +01:00
|
|
|
|
2021-05-01 15:00:24 +02:00
|
|
|
/* Fire a callback when the compositor wants a new frame rendered.
|
|
|
|
* Right now this only matters for OpenGL; we use this callback to add a
|
|
|
|
* wait timeout that avoids getting deadlocked by the compositor when the
|
|
|
|
* window isn't visible.
|
|
|
|
*/
|
|
|
|
if (window->flags & SDL_WINDOW_OPENGL) {
|
|
|
|
wl_callback_add_listener(wl_surface_frame(data->surface), &surface_frame_listener, data);
|
|
|
|
}
|
2021-04-30 19:19:36 +02:00
|
|
|
|
2016-11-13 10:39:04 +01:00
|
|
|
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
|
2015-06-21 17:33:46 +02:00
|
|
|
if (c->surface_extension) {
|
|
|
|
data->extended_surface = qt_surface_extension_get_extended_surface(
|
|
|
|
c->surface_extension, data->surface);
|
2016-11-13 10:39:04 +01:00
|
|
|
|
|
|
|
QtExtendedSurface_Subscribe(data->extended_surface, SDL_HINT_QTWAYLAND_CONTENT_ORIENTATION);
|
|
|
|
QtExtendedSurface_Subscribe(data->extended_surface, SDL_HINT_QTWAYLAND_WINDOW_FLAGS);
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
|
|
|
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
|
|
|
|
|
2020-02-14 07:08:21 +01:00
|
|
|
if (window->flags & SDL_WINDOW_OPENGL) {
|
|
|
|
data->egl_window = WAYLAND_wl_egl_window_create(data->surface,
|
2019-06-12 00:55:05 +02:00
|
|
|
window->w * data->scale_factor, window->h * data->scale_factor);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
2020-02-14 07:08:21 +01:00
|
|
|
/* Create the GLES window surface */
|
|
|
|
data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->egl_window);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
2020-02-14 07:08:21 +01:00
|
|
|
if (data->egl_surface == EGL_NO_SURFACE) {
|
|
|
|
return SDL_SetError("failed to create an EGL window surface");
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#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 */
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2016-09-01 10:26:56 +02:00
|
|
|
if (c->relative_mouse_mode) {
|
|
|
|
Wayland_input_lock_pointer(c->input);
|
|
|
|
}
|
|
|
|
|
2021-04-20 18:40:40 +02:00
|
|
|
wl_surface_commit(data->surface);
|
2015-06-21 17:33:46 +02:00
|
|
|
WAYLAND_wl_display_flush(c->display);
|
|
|
|
|
2021-01-21 04:17:20 +01:00
|
|
|
/* We may need to create an idle inhibitor for this new window */
|
|
|
|
Wayland_SuspendScreenSaver(_this);
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-14 06:58:36 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-12 20:27:58 +01:00
|
|
|
void
|
|
|
|
Wayland_SetWindowMinimumSize(_THIS, SDL_Window * window)
|
|
|
|
{
|
2021-04-07 00:10:40 +02:00
|
|
|
CommitMinMaxDimensions(window);
|
2021-02-12 20:27:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Wayland_SetWindowMaximumSize(_THIS, SDL_Window * window)
|
|
|
|
{
|
2021-04-07 00:10:40 +02:00
|
|
|
CommitMinMaxDimensions(window);
|
2021-02-12 20:27:58 +01:00
|
|
|
}
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
void Wayland_SetWindowSize(_THIS, SDL_Window * window)
|
|
|
|
{
|
|
|
|
SDL_VideoData *data = _this->driverdata;
|
|
|
|
SDL_WindowData *wind = window->driverdata;
|
|
|
|
struct wl_region *region;
|
|
|
|
|
2019-06-12 00:55:05 +02:00
|
|
|
wl_surface_set_buffer_scale(wind->surface, get_window_scale_factor(window));
|
2020-02-14 07:08:21 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
2019-06-12 00:55:05 +02:00
|
|
|
region = wl_compositor_create_region(data->compositor);
|
2015-06-21 17:33:46 +02:00
|
|
|
wl_region_add(region, 0, 0, window->w, window->h);
|
|
|
|
wl_surface_set_opaque_region(wind->surface, region);
|
|
|
|
wl_region_destroy(region);
|
|
|
|
}
|
|
|
|
|
2016-10-08 03:11:03 +02:00
|
|
|
void Wayland_SetWindowTitle(_THIS, SDL_Window * window)
|
|
|
|
{
|
|
|
|
SDL_WindowData *wind = window->driverdata;
|
2018-02-07 19:13:55 +01:00
|
|
|
SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
|
2021-02-12 20:31:43 +01:00
|
|
|
|
2016-10-08 03:11:03 +02:00
|
|
|
if (window->title != NULL) {
|
2018-06-25 07:42:36 +02:00
|
|
|
if (viddata->shell.xdg) {
|
2021-04-20 18:40:40 +02:00
|
|
|
if (wind->shell_surface.xdg.roleobj.toplevel == NULL) {
|
|
|
|
return; /* Can't do anything yet, wait for ShowWindow */
|
|
|
|
}
|
2018-06-25 07:42:36 +02:00
|
|
|
xdg_toplevel_set_title(wind->shell_surface.xdg.roleobj.toplevel, window->title);
|
|
|
|
} else if (viddata->shell.zxdg) {
|
2021-04-20 18:40:40 +02:00
|
|
|
if (wind->shell_surface.zxdg.roleobj.toplevel == NULL) {
|
|
|
|
return; /* Can't do anything yet, wait for ShowWindow */
|
|
|
|
}
|
2018-02-07 19:13:55 +01:00
|
|
|
zxdg_toplevel_v6_set_title(wind->shell_surface.zxdg.roleobj.toplevel, window->title);
|
|
|
|
} else {
|
2021-04-20 18:40:40 +02:00
|
|
|
if (wind->shell_surface.wl == NULL) {
|
|
|
|
return; /* Can'd do anything yet, wait for ShowWindow */
|
|
|
|
}
|
2018-02-07 19:13:55 +01:00
|
|
|
wl_shell_surface_set_title(wind->shell_surface.wl, window->title);
|
|
|
|
}
|
2016-10-08 03:11:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
|
|
|
|
}
|
|
|
|
|
2021-01-21 04:17:20 +01:00
|
|
|
void
|
|
|
|
Wayland_SuspendScreenSaver(_THIS)
|
|
|
|
{
|
|
|
|
SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
|
|
|
|
|
|
|
|
#if SDL_USE_LIBDBUS
|
|
|
|
if (SDL_DBus_ScreensaverInhibit(_this->suspend_screensaver)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* The idle_inhibit_unstable_v1 protocol suspends the screensaver
|
|
|
|
on a per wl_surface basis, but SDL assumes that suspending
|
|
|
|
the screensaver can be done independently of any window.
|
|
|
|
|
|
|
|
To reconcile these differences, we propagate the idle inhibit
|
|
|
|
state to each window. If there is no window active, we will
|
|
|
|
be able to inhibit idle once the first window is created.
|
|
|
|
*/
|
|
|
|
if (data->idle_inhibit_manager) {
|
|
|
|
SDL_Window *window = _this->windows;
|
|
|
|
while (window) {
|
|
|
|
SDL_WindowData *win_data = window->driverdata;
|
|
|
|
|
|
|
|
if (_this->suspend_screensaver && !win_data->idle_inhibitor) {
|
|
|
|
win_data->idle_inhibitor =
|
|
|
|
zwp_idle_inhibit_manager_v1_create_inhibitor(data->idle_inhibit_manager,
|
|
|
|
win_data->surface);
|
|
|
|
} else if (!_this->suspend_screensaver && win_data->idle_inhibitor) {
|
|
|
|
zwp_idle_inhibitor_v1_destroy(win_data->idle_inhibitor);
|
|
|
|
win_data->idle_inhibitor = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
window = window->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
void Wayland_DestroyWindow(_THIS, SDL_Window *window)
|
|
|
|
{
|
|
|
|
SDL_VideoData *data = _this->driverdata;
|
|
|
|
SDL_WindowData *wind = window->driverdata;
|
|
|
|
|
|
|
|
if (data) {
|
2020-02-14 07:08:21 +01:00
|
|
|
if (wind->egl_surface) {
|
|
|
|
SDL_EGL_DestroySurface(_this, wind->egl_surface);
|
|
|
|
}
|
|
|
|
if (wind->egl_window) {
|
|
|
|
WAYLAND_wl_egl_window_destroy(wind->egl_window);
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
2021-01-21 04:17:20 +01:00
|
|
|
if (wind->idle_inhibitor) {
|
|
|
|
zwp_idle_inhibitor_v1_destroy(wind->idle_inhibitor);
|
|
|
|
}
|
|
|
|
|
2021-02-01 04:10:02 +01:00
|
|
|
SDL_free(wind->outputs);
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
|
2016-11-13 10:39:04 +01:00
|
|
|
if (wind->extended_surface) {
|
|
|
|
QtExtendedSurface_Unsubscribe(wind->extended_surface, SDL_HINT_QTWAYLAND_CONTENT_ORIENTATION);
|
|
|
|
QtExtendedSurface_Unsubscribe(wind->extended_surface, SDL_HINT_QTWAYLAND_WINDOW_FLAGS);
|
2015-06-21 17:33:46 +02:00
|
|
|
qt_extended_surface_destroy(wind->extended_surface);
|
2016-11-13 10:39:04 +01:00
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
#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: */
|