Add patches suggested by @slouken in round 1 review

This commit is contained in:
Fredrick Brennan 2021-11-28 22:56:24 -05:00 committed by Sam Lantinga
parent 9c03d25543
commit 367684b0c2
4 changed files with 19 additions and 21 deletions

View File

@ -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(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(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(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) 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 #if SDL_VIDEO_DRIVER_X11_XFIXES

View File

@ -461,13 +461,9 @@ X11_VideoInit(_THIS)
#endif /* SDL_VIDEO_DRIVER_X11_XFIXES */ #endif /* SDL_VIDEO_DRIVER_X11_XFIXES */
#ifndef X_HAVE_UTF8_STRING #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 #endif
if (X11_XSupportsLocale() != True) {
return SDL_SetError("Current locale not supported by X server, cannot continue.");
}
if (X11_InitKeyboard(_this) != 0) { if (X11_InitKeyboard(_this) != 0) {
return -1; return -1;
} }

View File

@ -262,6 +262,7 @@ SetupWindowData(_THIS, SDL_Window * window, Window w, BOOL created)
} }
data->window = window; data->window = window;
data->xwindow = w; data->xwindow = w;
#ifdef X_HAVE_UTF8_STRING #ifdef X_HAVE_UTF8_STRING
if (SDL_X11_HAVE_UTF8 && videodata->im) { if (SDL_X11_HAVE_UTF8 && videodata->im) {
data->ic = data->ic =
@ -716,11 +717,11 @@ X11_GetWindowTitle(_THIS, Window xwindow)
0L, 8192L, False, XA_STRING, &real_type, &real_format, 0L, 8192L, False, XA_STRING, &real_type, &real_format,
&items_read, &items_left, &propdata); &items_read, &items_left, &propdata);
if (status == Success && 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); title = SDL_iconv_string("UTF-8", "", SDL_static_cast(char*, propdata), items_read+1);
X11_XFree(propdata); X11_XFree(propdata);
} else { } 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(""); title = SDL_strdup("");
} }
} }
@ -1871,22 +1872,25 @@ X11_FlashWindow(_THIS, SDL_Window * window, SDL_FlashOperation operation)
return 0; 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); Atom _NET_WM_NAME = X11_XInternAtom(display, "_NET_WM_NAME", False);
XTextProperty titleprop; XTextProperty titleprop;
int conv = X11_XmbTextListToTextProperty(display, (char**) &title, 1, XStdICCTextStyle, &titleprop); int conv = X11_XmbTextListToTextProperty(display, (char**) &title, 1, XTextStyle, &titleprop);
Status status; Status status;
if (X11_XSupportsLocale() != True) {
return SDL_SetError("Current locale not supported by X server, cannot continue.");
}
if (conv == 0) { if (conv == 0) {
X11_XSetTextProperty(display, xwindow, &titleprop, XA_WM_NAME); X11_XSetTextProperty(display, xwindow, &titleprop, XA_WM_NAME);
X11_XFree(titleprop.value); X11_XFree(titleprop.value);
// we know this can't be a locale error as we checked X locale validity in X11_VideoInit // we know this can't be a locale error as we checked X locale validity
} else if (conv <= 0) { } else if (conv < 0) {
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "X11 reporting it's out of memory"); return SDL_OutOfMemory();
return EXIT_FAILURE; } else { // conv > 0
} else { // conv >= 0 SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "%d characters were not convertable to the current locale!", conv);
SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO, "%d characters were not convertable to the current locale!", conv); return 0;
return EXIT_FAILURE;
} }
#ifdef X_HAVE_UTF8_STRING #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_XSetTextProperty(display, xwindow, &titleprop, _NET_WM_NAME);
X11_XFree(titleprop.value); X11_XFree(titleprop.value);
} else { } else {
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Failed to convert title to UTF8! Bad encoding, or bad Xorg encoding? Window title: «%s»", title); return SDL_SetError("Failed to convert title to UTF8! Bad encoding, or bad Xorg encoding? Window title: «%s»", title);
return EXIT_FAILURE;
} }
#endif #endif
X11_XFlush(display); X11_XFlush(display);
return EXIT_SUCCESS; return 0;
} }
#endif /* SDL_VIDEO_DRIVER_X11 */ #endif /* SDL_VIDEO_DRIVER_X11 */

View File

@ -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 void X11_AcceptDragAndDrop(SDL_Window * window, SDL_bool accept);
extern int X11_FlashWindow(_THIS, SDL_Window * window, SDL_FlashOperation operation); 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_ */ #endif /* SDL_x11window_h_ */