From e1c8350439d09903d5697d06ab846133d132205c Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Sun, 15 May 2022 10:35:59 -0400
Subject: [PATCH] wayland: Add a hint to disable video mode emulation under
Wayland
Add the hint "SDL_VIDEO_WAYLAND_MODE_EMULATION", which can be used to disable mode emulation under Wayland. When disabled, only the desktop and/or native display resolution is exposed.
---
include/SDL_hints.h | 15 +++++++++++++++
src/video/wayland/SDL_waylandvideo.c | 9 +++++----
2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index 2699b6ae911..b5665b91d9f 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -1508,6 +1508,21 @@ extern "C" {
*/
#define SDL_HINT_VIDEO_WAYLAND_PREFER_LIBDECOR "SDL_VIDEO_WAYLAND_PREFER_LIBDECOR"
+/**
+ * \brief A variable controlling whether video mode emulation is enabled under Wayland.
+ *
+ * When this hint is set, a standard set of emulated CVT video modes will be exposed for use by the application.
+ * If it is disabled, the only modes exposed will be the logical desktop size and, in the case of a scaled
+ * desktop, the native display resolution.
+ *
+ * This variable can be set to the following values:
+ * "0" - Video mode emulation is disabled.
+ * "1" - Video mode emulation is enabled.
+ *
+ * By default video mode emulation is enabled.
+ */
+#define SDL_HINT_VIDEO_WAYLAND_MODE_EMULATION "SDL_VIDEO_WAYLAND_MODE_EMULATION"
+
/**
* \brief A variable that is the address of another SDL_Window* (as a hex string formatted with "%p").
*
diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c
index 6688f139403..4698cc53116 100644
--- a/src/video/wayland/SDL_waylandvideo.c
+++ b/src/video/wayland/SDL_waylandvideo.c
@@ -545,6 +545,7 @@ display_handle_done(void *data,
SDL_VideoData* video = driverdata->videodata;
SDL_DisplayMode native_mode, desktop_mode;
SDL_VideoDisplay *dpy;
+ const SDL_bool mode_emulation_enabled = SDL_GetHintBoolean(SDL_HINT_VIDEO_WAYLAND_MODE_EMULATION, SDL_TRUE);
/*
* When using xdg-output, two wl-output.done events will be emitted:
@@ -597,8 +598,8 @@ display_handle_done(void *data,
desktop_mode.driverdata = driverdata->output;
/*
- * The native display mode is only exposed separately from the desktop size if:
- * the desktop is scaled and the wp_viewporter protocol is supported.
+ * The native display mode is only exposed separately from the desktop size if the
+ * desktop is scaled and the wp_viewporter protocol is supported.
*/
if (driverdata->scale_factor > 1.0f && video->viewporter != NULL) {
if (driverdata->index > -1) {
@@ -643,8 +644,8 @@ display_handle_done(void *data,
SDL_SetCurrentDisplayMode(dpy, &desktop_mode);
SDL_SetDesktopDisplayMode(dpy, &desktop_mode);
- /* Add emulated modes if wp_viewporter is supported. */
- if (video->viewporter) {
+ /* Add emulated modes if wp_viewporter is supported and mode emulation is enabled. */
+ if (video->viewporter && mode_emulation_enabled) {
AddEmulatedModes(dpy, (driverdata->transform & WL_OUTPUT_TRANSFORM_90) != 0);
}