x11: Fix message box titles with Unicode chars on some window managers.
authorRyan C. Gordon <icculus@icculus.org>
Sun, 13 Aug 2017 00:58:23 -0400
changeset 11259931e9d3a452e
parent 11258 9fc2e83124ba
child 11260 f7abcb63e51e
x11: Fix message box titles with Unicode chars on some window managers.

Fixes Bugzilla #2971.
src/video/x11/SDL_x11messagebox.c
     1.1 --- a/src/video/x11/SDL_x11messagebox.c	Sat Aug 12 20:25:49 2017 -0700
     1.2 +++ b/src/video/x11/SDL_x11messagebox.c	Sun Aug 13 00:58:23 2017 -0400
     1.3 @@ -378,10 +378,11 @@
     1.4      int x, y;
     1.5      XSizeHints *sizehints;
     1.6      XSetWindowAttributes wnd_attr;
     1.7 -    Atom _NET_WM_WINDOW_TYPE, _NET_WM_WINDOW_TYPE_DIALOG, _NET_WM_NAME, UTF8_STRING;
     1.8 +    Atom _NET_WM_WINDOW_TYPE, _NET_WM_WINDOW_TYPE_DIALOG, _NET_WM_NAME;
     1.9      Display *display = data->display;
    1.10      SDL_WindowData *windowdata = NULL;
    1.11      const SDL_MessageBoxData *messageboxdata = data->messageboxdata;
    1.12 +    char *title_locale = NULL;
    1.13  
    1.14      if ( messageboxdata->window ) {
    1.15          SDL_DisplayData *displaydata =
    1.16 @@ -414,10 +415,30 @@
    1.17  
    1.18      X11_XStoreName( display, data->window, messageboxdata->title );
    1.19      _NET_WM_NAME = X11_XInternAtom(display, "_NET_WM_NAME", False);
    1.20 -    UTF8_STRING = X11_XInternAtom(display, "UTF8_STRING", False);
    1.21 -    X11_XChangeProperty(display, data->window, _NET_WM_NAME, UTF8_STRING, 8,
    1.22 -                    PropModeReplace, (unsigned char *) messageboxdata->title,
    1.23 -                    strlen(messageboxdata->title) + 1 );
    1.24 +
    1.25 +    title_locale = SDL_iconv_utf8_locale(messageboxdata->title);
    1.26 +    if (title_locale) {
    1.27 +        XTextProperty titleprop;
    1.28 +        Status status = X11_XStringListToTextProperty(&title_locale, 1, &titleprop);
    1.29 +        SDL_free(title_locale);
    1.30 +        if (status) {
    1.31 +            X11_XSetTextProperty(display, data->xwindow, &titleprop, XA_WM_NAME);
    1.32 +            X11_XFree(titleprop.value);
    1.33 +        }
    1.34 +    }
    1.35 +
    1.36 +#ifdef X_HAVE_UTF8_STRING
    1.37 +    if (SDL_X11_HAVE_UTF8) {
    1.38 +        XTextProperty titleprop;
    1.39 +        status = X11_Xutf8TextListToTextProperty(display, (char **) &messageboxdata->title, 1,
    1.40 +                                            XUTF8StringStyle, &titleprop);
    1.41 +        if (status == Success) {
    1.42 +            X11_XSetTextProperty(display, data->window, &titleprop,
    1.43 +                                 _NET_WM_NAME);
    1.44 +            X11_XFree(titleprop.value);
    1.45 +        }
    1.46 +    }
    1.47 +#endif
    1.48  
    1.49      /* Let the window manager know this is a dialog box */
    1.50      _NET_WM_WINDOW_TYPE = X11_XInternAtom(display, "_NET_WM_WINDOW_TYPE", False);