src/video/x11/SDL_x11messagebox.c
changeset 6835 c259f0817583
parent 6817 93103b719488
child 6885 700f1b25f77f
equal deleted inserted replaced
6834:dce4e1d1eca3 6835:c259f0817583
    29 #include "SDL_assert.h"
    29 #include "SDL_assert.h"
    30 
    30 
    31 #include <locale.h>
    31 #include <locale.h>
    32 
    32 
    33 
    33 
    34 #define SDL_FORK_MESSAGEBOX 1
    34 #define SDL_FORK_MESSAGEBOX 0
       
    35 #define SDL_SET_LOCALE      0
    35 
    36 
    36 #if SDL_FORK_MESSAGEBOX
    37 #if SDL_FORK_MESSAGEBOX
    37 #include <sys/types.h>
    38 #include <sys/types.h>
    38 #include <sys/wait.h>
    39 #include <sys/wait.h>
    39 #include <unistd.h>
    40 #include <unistd.h>
   643 static int
   644 static int
   644 X11_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonid)
   645 X11_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonid)
   645 {
   646 {
   646     int ret;
   647     int ret;
   647     SDL_MessageBoxDataX11 data;
   648     SDL_MessageBoxDataX11 data;
       
   649 #if SDL_SET_LOCALE
   648     char *origlocale;
   650     char *origlocale;
       
   651 #endif
   649 
   652 
   650     SDL_zero(data);
   653     SDL_zero(data);
   651 
   654 
   652     if ( !SDL_X11_LoadSymbols() )
   655     if ( !SDL_X11_LoadSymbols() )
   653         return -1;
   656         return -1;
   654 
   657 
       
   658 #if SDL_SET_LOCALE
   655     origlocale = setlocale(LC_ALL, NULL);
   659     origlocale = setlocale(LC_ALL, NULL);
   656     if (origlocale != NULL) {
   660     if (origlocale != NULL) {
   657         origlocale = SDL_strdup(origlocale);
   661         origlocale = SDL_strdup(origlocale);
   658         if (origlocale == NULL) {
   662         if (origlocale == NULL) {
   659             SDL_OutOfMemory();
   663             SDL_OutOfMemory();
   660             return -1;
   664             return -1;
   661         }
   665         }
   662         setlocale(LC_ALL, "");
   666         setlocale(LC_ALL, "");
   663     }
   667     }
       
   668 #endif
   664 
   669 
   665     /* This code could get called from multiple threads maybe? */
   670     /* This code could get called from multiple threads maybe? */
   666     XInitThreads();
   671     XInitThreads();
   667 
   672 
   668     /* Initialize the return buttonid value to -1 (for error or dialogbox closed). */
   673     /* Initialize the return buttonid value to -1 (for error or dialogbox closed). */
   680         }
   685         }
   681     }
   686     }
   682 
   687 
   683     X11_MessageBoxShutdown( &data );
   688     X11_MessageBoxShutdown( &data );
   684 
   689 
       
   690 #if SDL_SET_LOCALE
   685     if (origlocale) {
   691     if (origlocale) {
   686         setlocale(LC_ALL, origlocale);
   692         setlocale(LC_ALL, origlocale);
   687         SDL_free(origlocale);
   693         SDL_free(origlocale);
   688     }
   694     }
       
   695 #endif
   689 
   696 
   690     return ret;
   697     return ret;
   691 }
   698 }
   692 
   699 
   693 /* Display an x11 message box. */
   700 /* Display an x11 message box. */
   697 #if SDL_FORK_MESSAGEBOX
   704 #if SDL_FORK_MESSAGEBOX
   698     /* Use a child process to protect against setlocale(). Annoying. */
   705     /* Use a child process to protect against setlocale(). Annoying. */
   699     pid_t pid;
   706     pid_t pid;
   700     int fds[2];
   707     int fds[2];
   701     int status = 0;
   708     int status = 0;
       
   709 
       
   710 	/* Need to flush here in case someone has turned grab off and it hasn't gone through yet, etc. */
       
   711 	XFlush(data->display);
   702 
   712 
   703     if (pipe(fds) == -1) {
   713     if (pipe(fds) == -1) {
   704         return X11_ShowMessageBoxImpl(messageboxdata, buttonid); /* oh well. */
   714         return X11_ShowMessageBoxImpl(messageboxdata, buttonid); /* oh well. */
   705     }
   715     }
   706 
   716