SDL: Add patches suggested by @slouken in round 1 review

From 367684b0c282eaa59f831fece112b2bb82a2a7ad Mon Sep 17 00:00:00 2001
From: Fredrick Brennan <[EMAIL REDACTED]>
Date: Sun, 28 Nov 2021 22:56:24 -0500
Subject: [PATCH] Add patches suggested by @slouken in round 1 review

---
 src/video/x11/SDL_x11sym.h    |  1 -
 src/video/x11/SDL_x11video.c  |  6 +-----
 src/video/x11/SDL_x11window.c | 31 +++++++++++++++++--------------
 src/video/x11/SDL_x11window.h |  2 +-
 4 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/src/video/x11/SDL_x11sym.h b/src/video/x11/SDL_x11sym.h
index ba08ea9db4..673b7f101e 100644
--- a/src/video/x11/SDL_x11sym.h
+++ b/src/video/x11/SDL_x11sym.h
@@ -157,7 +157,6 @@ SDL_X11_SYM(SDL_X11_XESetEventToWireRetType,XESetEventToWire,(Display* a,int b,S
 SDL_X11_SYM(void,XRefreshKeyboardMapping,(XMappingEvent *a),(a),)
 SDL_X11_SYM(int,XQueryTree,(Display* a,Window b,Window* c,Window* d,Window** e,unsigned int* f),(a,b,c,d,e,f),return)
 SDL_X11_SYM(Bool,XSupportsLocale,(void),(),return)
-SDL_X11_SYM(void,XSetWMName,(Display* a,Window b,XTextProperty* c),(a,b,c),return)
 SDL_X11_SYM(Status,XmbTextListToTextProperty,(Display* a,char** b,int c,XICCEncodingStyle d,XTextProperty* e),(a,b,c,d,e),return)
 
 #if SDL_VIDEO_DRIVER_X11_XFIXES
diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c
index 6d2cd0713d..1bf40320bc 100644
--- a/src/video/x11/SDL_x11video.c
+++ b/src/video/x11/SDL_x11video.c
@@ -461,13 +461,9 @@ X11_VideoInit(_THIS)
 #endif /* SDL_VIDEO_DRIVER_X11_XFIXES */
 
 #ifndef X_HAVE_UTF8_STRING
-    SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "X server doesn't support UTF8_STRING, a feature introduced in 2000! This is likely to become a hard error in a future libSDL2.");
+#warning X server does not support UTF8_STRING, a feature introduced in 2000! This is likely to become a hard error in a future libSDL2.
 #endif
 
-    if (X11_XSupportsLocale() != True) {
-        return SDL_SetError("Current locale not supported by X server, cannot continue.");
-    }
-
     if (X11_InitKeyboard(_this) != 0) {
         return -1;
     }
diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c
index 48f0cc60e7..51869a6a0b 100644
--- a/src/video/x11/SDL_x11window.c
+++ b/src/video/x11/SDL_x11window.c
@@ -262,6 +262,7 @@ SetupWindowData(_THIS, SDL_Window * window, Window w, BOOL created)
     }
     data->window = window;
     data->xwindow = w;
+
 #ifdef X_HAVE_UTF8_STRING
     if (SDL_X11_HAVE_UTF8 && videodata->im) {
         data->ic =
@@ -716,11 +717,11 @@ X11_GetWindowTitle(_THIS, Window xwindow)
                     0L, 8192L, False, XA_STRING, &real_type, &real_format,
                     &items_read, &items_left, &propdata);
         if (status == Success && propdata) {
-            SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Failed to convert _WM_NAME title expecting UTF8! Title: %s", title);
+            SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Failed to convert WM_NAME title expecting UTF8! Title: %s", title);
             title = SDL_iconv_string("UTF-8", "", SDL_static_cast(char*, propdata), items_read+1);
             X11_XFree(propdata);
         } else {
-            SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not get any window title response from Xorg, returning empty string!");
+            SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Could not get any window title response from Xorg, returning empty string!");
             title = SDL_strdup("");
         }
     }
@@ -1871,22 +1872,25 @@ X11_FlashWindow(_THIS, SDL_Window * window, SDL_FlashOperation operation)
     return 0;
 }
 
-bool SDL_X11_SetWindowTitle(Display* display, Window xwindow, char* title) {
+int SDL_X11_SetWindowTitle(Display* display, Window xwindow, char* title) {
     Atom _NET_WM_NAME = X11_XInternAtom(display, "_NET_WM_NAME", False);
     XTextProperty titleprop;
-    int conv = X11_XmbTextListToTextProperty(display, (char**) &title, 1, XStdICCTextStyle, &titleprop);
+    int conv = X11_XmbTextListToTextProperty(display, (char**) &title, 1, XTextStyle, &titleprop);
     Status status;
 
+    if (X11_XSupportsLocale() != True) {
+        return SDL_SetError("Current locale not supported by X server, cannot continue.");
+    }
+
     if (conv == 0) {
         X11_XSetTextProperty(display, xwindow, &titleprop, XA_WM_NAME);
         X11_XFree(titleprop.value);
-    // we know this can't be a locale error as we checked X locale validity in X11_VideoInit
-    } else if (conv <= 0) {
-        SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "X11 reporting it's out of memory");
-        return EXIT_FAILURE;
-    } else { // conv >= 0
-        SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO, "%d characters were not convertable to the current locale!", conv);
-        return EXIT_FAILURE;
+    // we know this can't be a locale error as we checked X locale validity
+    } else if (conv < 0) {
+        return SDL_OutOfMemory();
+    } else { // conv > 0
+        SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "%d characters were not convertable to the current locale!", conv);
+        return 0;
     }
 
 #ifdef X_HAVE_UTF8_STRING
@@ -1895,13 +1899,12 @@ bool SDL_X11_SetWindowTitle(Display* display, Window xwindow, char* title) {
         X11_XSetTextProperty(display, xwindow, &titleprop, _NET_WM_NAME);
         X11_XFree(titleprop.value);
     } else {
-        SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Failed to convert title to UTF8! Bad encoding, or bad Xorg encoding? Window title: «%s»", title);
-        return EXIT_FAILURE;
+        return SDL_SetError("Failed to convert title to UTF8! Bad encoding, or bad Xorg encoding? Window title: «%s»", title);
     }
 #endif
 
     X11_XFlush(display);
-    return EXIT_SUCCESS;
+    return 0;
 }
 
 #endif /* SDL_VIDEO_DRIVER_X11 */
diff --git a/src/video/x11/SDL_x11window.h b/src/video/x11/SDL_x11window.h
index dd66af7953..11bd9feb2e 100644
--- a/src/video/x11/SDL_x11window.h
+++ b/src/video/x11/SDL_x11window.h
@@ -117,7 +117,7 @@ extern int X11_SetWindowHitTest(SDL_Window *window, SDL_bool enabled);
 extern void X11_AcceptDragAndDrop(SDL_Window * window, SDL_bool accept);
 extern int X11_FlashWindow(_THIS, SDL_Window * window, SDL_FlashOperation operation);
 
-bool SDL_X11_SetWindowTitle(Display* display, Window xwindow, char* string);
+int SDL_X11_SetWindowTitle(Display* display, Window xwindow, char* string);
 
 #endif /* SDL_x11window_h_ */