X11: Add Xdbe support to message boxes (thanks, Melker!).
authorRyan C. Gordon <icculus@icculus.org>
Thu, 28 May 2015 00:30:21 -0400
changeset 9657fbc01731d914
parent 9656 8a4bcbdeba1c
child 9658 9753468b5c0e
X11: Add Xdbe support to message boxes (thanks, Melker!).

Without this, message boxes with a lot of text will noticibly flicker as
you mouse over buttons.

Fixes Bugzilla #2343.
configure
configure.in
include/SDL_config.h.cmake
include/SDL_config.h.in
include/SDL_config_macosx.h
premake/Linux/SDL_config_premake.h
premake/Xcode/Xcode3/SDL_config_premake.h
premake/Xcode/Xcode4/SDL_config_premake.h
premake/config/SDL_config_macosx.template.h
premake/projects/SDL2.lua
src/video/x11/SDL_x11dyn.h
src/video/x11/SDL_x11messagebox.c
src/video/x11/SDL_x11sym.h
src/video/x11/SDL_x11video.h
     1.1 --- a/configure	Wed May 27 19:00:56 2015 -0400
     1.2 +++ b/configure	Thu May 28 00:30:21 2015 -0400
     1.3 @@ -826,6 +826,7 @@
     1.4  with_x
     1.5  enable_x11_shared
     1.6  enable_video_x11_xcursor
     1.7 +enable_video_x11_xdbe
     1.8  enable_video_x11_xinerama
     1.9  enable_video_x11_xinput
    1.10  enable_video_x11_xrandr
    1.11 @@ -1551,6 +1552,7 @@
    1.12    --enable-x11-shared     dynamically load X11 support [[default=maybe]]
    1.13    --enable-video-x11-xcursor
    1.14                            enable X11 Xcursor support [[default=yes]]
    1.15 +  --enable-video-x11-xdbe enable X11 Xdbe support [[default=yes]]
    1.16    --enable-video-x11-xinerama
    1.17                            enable X11 Xinerama support [[default=yes]]
    1.18    --enable-video-x11-xinput
    1.19 @@ -20123,6 +20125,31 @@
    1.20  
    1.21                  SUMMARY_video_x11="${SUMMARY_video_x11} xcursor"
    1.22              fi
    1.23 +            # Check whether --enable-video-x11-xdbe was given.
    1.24 +if test "${enable_video_x11_xdbe+set}" = set; then :
    1.25 +  enableval=$enable_video_x11_xdbe;
    1.26 +else
    1.27 +  enable_video_x11_xdbe=yes
    1.28 +fi
    1.29 +
    1.30 +            if test x$enable_video_x11_xdbe = xyes; then
    1.31 +                ac_fn_c_check_header_compile "$LINENO" "X11/extensions/Xdbe.h" "ac_cv_header_X11_extensions_Xdbe_h" "#include <X11/Xlib.h>
    1.32 +
    1.33 +"
    1.34 +if test "x$ac_cv_header_X11_extensions_Xdbe_h" = xyes; then :
    1.35 +  have_dbe_h_hdr=yes
    1.36 +else
    1.37 +  have_dbe_h_hdr=no
    1.38 +fi
    1.39 +
    1.40 +
    1.41 +                if test x$have_dbe_h_hdr = xyes; then
    1.42 +
    1.43 +$as_echo "#define SDL_VIDEO_DRIVER_X11_XDBE 1" >>confdefs.h
    1.44 +
    1.45 +                    SUMMARY_video_x11="${SUMMARY_video_x11} xdbe"
    1.46 +                fi
    1.47 +            fi
    1.48              # Check whether --enable-video-x11-xinerama was given.
    1.49  if test "${enable_video_x11_xinerama+set}" = set; then :
    1.50    enableval=$enable_video_x11_xinerama;
     2.1 --- a/configure.in	Wed May 27 19:00:56 2015 -0400
     2.2 +++ b/configure.in	Thu May 28 00:30:21 2015 -0400
     2.3 @@ -1552,6 +1552,20 @@
     2.4                  AC_DEFINE(SDL_VIDEO_DRIVER_X11_XCURSOR, 1, [ ])
     2.5                  SUMMARY_video_x11="${SUMMARY_video_x11} xcursor"
     2.6              fi
     2.7 +            AC_ARG_ENABLE(video-x11-xdbe,
     2.8 +AC_HELP_STRING([--enable-video-x11-xdbe], [enable X11 Xdbe support [[default=yes]]]),
     2.9 +                            , enable_video_x11_xdbe=yes)
    2.10 +            if test x$enable_video_x11_xdbe = xyes; then
    2.11 +                AC_CHECK_HEADER(X11/extensions/Xdbe.h,
    2.12 +                                have_dbe_h_hdr=yes,
    2.13 +                                have_dbe_h_hdr=no,
    2.14 +                                [#include <X11/Xlib.h>
    2.15 +                                ])
    2.16 +                if test x$have_dbe_h_hdr = xyes; then
    2.17 +                    AC_DEFINE(SDL_VIDEO_DRIVER_X11_XDBE, 1, [ ])
    2.18 +                    SUMMARY_video_x11="${SUMMARY_video_x11} xdbe"
    2.19 +                fi
    2.20 +            fi
    2.21              AC_ARG_ENABLE(video-x11-xinerama,
    2.22  AC_HELP_STRING([--enable-video-x11-xinerama], [enable X11 Xinerama support [[default=yes]]]),
    2.23                              , enable_video_x11_xinerama=yes)
     3.1 --- a/include/SDL_config.h.cmake	Wed May 27 19:00:56 2015 -0400
     3.2 +++ b/include/SDL_config.h.cmake	Thu May 28 00:30:21 2015 -0400
     3.3 @@ -296,6 +296,7 @@
     3.4  #cmakedefine SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS @SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS@
     3.5  #cmakedefine SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE @SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE@
     3.6  #cmakedefine SDL_VIDEO_DRIVER_X11_XCURSOR @SDL_VIDEO_DRIVER_X11_XCURSOR@
     3.7 +#cmakedefine SDL_VIDEO_DRIVER_X11_XDBE @SDL_VIDEO_DRIVER_X11_XDBE@
     3.8  #cmakedefine SDL_VIDEO_DRIVER_X11_XINERAMA @SDL_VIDEO_DRIVER_X11_XINERAMA@
     3.9  #cmakedefine SDL_VIDEO_DRIVER_X11_XINPUT2 @SDL_VIDEO_DRIVER_X11_XINPUT2@
    3.10  #cmakedefine SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH @SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH@
     4.1 --- a/include/SDL_config.h.in	Wed May 27 19:00:56 2015 -0400
     4.2 +++ b/include/SDL_config.h.in	Thu May 28 00:30:21 2015 -0400
     4.3 @@ -299,6 +299,7 @@
     4.4  #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS
     4.5  #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE
     4.6  #undef SDL_VIDEO_DRIVER_X11_XCURSOR
     4.7 +#undef SDL_VIDEO_DRIVER_X11_XDBE
     4.8  #undef SDL_VIDEO_DRIVER_X11_XINERAMA
     4.9  #undef SDL_VIDEO_DRIVER_X11_XINPUT2
    4.10  #undef SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
     5.1 --- a/include/SDL_config_macosx.h	Wed May 27 19:00:56 2015 -0400
     5.2 +++ b/include/SDL_config_macosx.h	Thu May 28 00:30:21 2015 -0400
     5.3 @@ -139,6 +139,7 @@
     5.4  #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "/usr/X11R6/lib/libXrandr.2.dylib"
     5.5  #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "/usr/X11R6/lib/libXss.1.dylib"
     5.6  #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "/usr/X11R6/lib/libXxf86vm.1.dylib"
     5.7 +#define SDL_VIDEO_DRIVER_X11_XDBE 1
     5.8  #define SDL_VIDEO_DRIVER_X11_XINERAMA 1
     5.9  #define SDL_VIDEO_DRIVER_X11_XRANDR 1
    5.10  #define SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1
     6.1 --- a/premake/Linux/SDL_config_premake.h	Wed May 27 19:00:56 2015 -0400
     6.2 +++ b/premake/Linux/SDL_config_premake.h	Thu May 28 00:30:21 2015 -0400
     6.3 @@ -229,6 +229,9 @@
     6.4  #ifndef SDL_VIDEO_DRIVER_X11_XCURSOR
     6.5  #define SDL_VIDEO_DRIVER_X11_XCURSOR 1
     6.6  #endif
     6.7 +#ifndef SDL_VIDEO_DRIVER_X11_XDBE
     6.8 +#define SDL_VIDEO_DRIVER_X11_XDBE 1
     6.9 +#endif
    6.10  #ifndef SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
    6.11  #define SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM 1
    6.12  #endif
     7.1 --- a/premake/Xcode/Xcode3/SDL_config_premake.h	Wed May 27 19:00:56 2015 -0400
     7.2 +++ b/premake/Xcode/Xcode3/SDL_config_premake.h	Thu May 28 00:30:21 2015 -0400
     7.3 @@ -162,6 +162,7 @@
     7.4  #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "/usr/X11R6/lib/libXrandr.2.dylib"
     7.5  #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "/usr/X11R6/lib/libXss.1.dylib"
     7.6  #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "/usr/X11R6/lib/libXxf86vm.1.dylib"
     7.7 +#define SDL_VIDEO_DRIVER_X11_XDBE 1
     7.8  #define SDL_VIDEO_DRIVER_X11_XINERAMA 1
     7.9  #define SDL_VIDEO_DRIVER_X11_XRANDR 1
    7.10  #define SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1
     8.1 --- a/premake/Xcode/Xcode4/SDL_config_premake.h	Wed May 27 19:00:56 2015 -0400
     8.2 +++ b/premake/Xcode/Xcode4/SDL_config_premake.h	Thu May 28 00:30:21 2015 -0400
     8.3 @@ -162,6 +162,7 @@
     8.4  #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "/usr/X11R6/lib/libXrandr.2.dylib"
     8.5  #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "/usr/X11R6/lib/libXss.1.dylib"
     8.6  #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "/usr/X11R6/lib/libXxf86vm.1.dylib"
     8.7 +#define SDL_VIDEO_DRIVER_X11_XDBE 1
     8.8  #define SDL_VIDEO_DRIVER_X11_XINERAMA 1
     8.9  #define SDL_VIDEO_DRIVER_X11_XRANDR 1
    8.10  #define SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1
     9.1 --- a/premake/config/SDL_config_macosx.template.h	Wed May 27 19:00:56 2015 -0400
     9.2 +++ b/premake/config/SDL_config_macosx.template.h	Thu May 28 00:30:21 2015 -0400
     9.3 @@ -118,6 +118,7 @@
     9.4  #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "/usr/X11R6/lib/libXrandr.2.dylib"
     9.5  #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "/usr/X11R6/lib/libXss.1.dylib"
     9.6  #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "/usr/X11R6/lib/libXxf86vm.1.dylib"
     9.7 +#define SDL_VIDEO_DRIVER_X11_XDBE 1
     9.8  #define SDL_VIDEO_DRIVER_X11_XINERAMA 1
     9.9  #define SDL_VIDEO_DRIVER_X11_XRANDR 1
    9.10  #define SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1
    10.1 --- a/premake/projects/SDL2.lua	Wed May 27 19:00:56 2015 -0400
    10.2 +++ b/premake/projects/SDL2.lua	Thu May 28 00:30:21 2015 -0400
    10.3 @@ -293,6 +293,7 @@
    10.4  			["SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS"] = '"libXss.so"',
    10.5  			["SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE"] = '"libXxf86vm.so"',
    10.6  			["SDL_VIDEO_DRIVER_X11_XCURSOR"] = 1,
    10.7 +			["SDL_VIDEO_DRIVER_X11_XDBE"] = 1,
    10.8  			["SDL_VIDEO_DRIVER_X11_XINERAMA"] = 1,
    10.9  			["SDL_VIDEO_DRIVER_X11_XINPUT2"] = 1,
   10.10  			["SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH"] = 1,
    11.1 --- a/src/video/x11/SDL_x11dyn.h	Wed May 27 19:00:56 2015 -0400
    11.2 +++ b/src/video/x11/SDL_x11dyn.h	Thu May 28 00:30:21 2015 -0400
    11.3 @@ -50,6 +50,9 @@
    11.4  #if SDL_VIDEO_DRIVER_X11_XCURSOR
    11.5  #include <X11/Xcursor/Xcursor.h>
    11.6  #endif
    11.7 +#if SDL_VIDEO_DRIVER_X11_XDBE
    11.8 +#include <X11/extensions/Xdbe.h>
    11.9 +#endif
   11.10  #if SDL_VIDEO_DRIVER_X11_XINERAMA
   11.11  #include <X11/extensions/Xinerama.h>
   11.12  #endif
    12.1 --- a/src/video/x11/SDL_x11messagebox.c	Wed May 27 19:00:56 2015 -0400
    12.2 +++ b/src/video/x11/SDL_x11messagebox.c	Thu May 28 00:30:21 2015 -0400
    12.3 @@ -83,6 +83,10 @@
    12.4      Display *display;
    12.5      int screen;
    12.6      Window window;
    12.7 +#if SDL_VIDEO_DRIVER_X11_XDBE
    12.8 +    XdbeBackBuffer buf;
    12.9 +    SDL_bool xdbe;                      /* Whether Xdbe is present or not */
   12.10 +#endif
   12.11      long event_mask;
   12.12      Atom wm_protocols;
   12.13      Atom wm_delete_message;
   12.14 @@ -347,6 +351,12 @@
   12.15          data->font_struct = NULL;
   12.16      }
   12.17  
   12.18 +#if SDL_VIDEO_DRIVER_X11_XDBE
   12.19 +    if ( SDL_X11_HAVE_XDBE && data->xdbe ) {
   12.20 +        X11_XdbeDeallocateBackBufferName(data->display, data->buf);
   12.21 +    }
   12.22 +#endif
   12.23 +
   12.24      if ( data->display ) {
   12.25          if ( data->window != None ) {
   12.26              X11_XWithdrawWindow( data->display, data->window, data->screen );
   12.27 @@ -445,6 +455,20 @@
   12.28      }
   12.29  
   12.30      X11_XMapRaised( display, data->window );
   12.31 +
   12.32 +#if SDL_VIDEO_DRIVER_X11_XDBE
   12.33 +    /* Initialise a back buffer for double buffering */
   12.34 +    if (SDL_X11_HAVE_XDBE) {
   12.35 +        int xdbe_major, xdbe_minor;
   12.36 +        if (X11_XdbeQueryExtension(display, &xdbe_major, &xdbe_minor) != 0) {
   12.37 +            data->xdbe = SDL_TRUE;
   12.38 +            data->buf = X11_XdbeAllocateBackBufferName(display, data->window, XdbeUndefined);
   12.39 +        } else {
   12.40 +            data->xdbe = SDL_FALSE;
   12.41 +        }
   12.42 +    }
   12.43 +#endif
   12.44 +
   12.45      return 0;
   12.46  }
   12.47  
   12.48 @@ -453,9 +477,16 @@
   12.49  X11_MessageBoxDraw( SDL_MessageBoxDataX11 *data, GC ctx )
   12.50  {
   12.51      int i;
   12.52 -    Window window = data->window;
   12.53 +    Drawable window = data->window;
   12.54      Display *display = data->display;
   12.55  
   12.56 +#if SDL_VIDEO_DRIVER_X11_XDBE
   12.57 +    if (SDL_X11_HAVE_XDBE && data->xdbe) {
   12.58 +        window = data->buf;
   12.59 +        X11_XdbeBeginIdiom(data->display);
   12.60 +    }
   12.61 +#endif
   12.62 +
   12.63      X11_XSetForeground( display, ctx, data->color[ SDL_MESSAGEBOX_COLOR_BACKGROUND ] );
   12.64      X11_XFillRectangle( display, window, ctx, 0, 0, data->dialog_width, data->dialog_height );
   12.65  
   12.66 @@ -505,6 +536,16 @@
   12.67                           buttondata->text, buttondatax11->length );
   12.68          }
   12.69      }
   12.70 +
   12.71 +#if SDL_VIDEO_DRIVER_X11_XDBE
   12.72 +    if (SDL_X11_HAVE_XDBE && data->xdbe) {
   12.73 +        XdbeSwapInfo swap_info;
   12.74 +        swap_info.swap_window = data->window;
   12.75 +        swap_info.swap_action = XdbeUndefined;
   12.76 +        X11_XdbeSwapBuffers(data->display, &swap_info, 1);
   12.77 +        X11_XdbeEndIdiom(data->display);
   12.78 +    }
   12.79 +#endif
   12.80  }
   12.81  
   12.82  /* Loop and handle message box event messages until something kills it. */
   12.83 @@ -568,7 +609,7 @@
   12.84          case MotionNotify:
   12.85              if ( has_focus ) {
   12.86                  /* Mouse moved... */
   12.87 -                int previndex = data->mouse_over_index;
   12.88 +                const int previndex = data->mouse_over_index;
   12.89                  data->mouse_over_index = GetHitButtonIndex( data, e.xbutton.x, e.xbutton.y );
   12.90                  if (data->mouse_over_index == previndex) {
   12.91                      draw = SDL_FALSE;
    13.1 --- a/src/video/x11/SDL_x11sym.h	Wed May 27 19:00:56 2015 -0400
    13.2 +++ b/src/video/x11/SDL_x11sym.h	Thu May 28 00:30:21 2015 -0400
    13.3 @@ -230,6 +230,20 @@
    13.4  SDL_X11_SYM(Cursor,XcursorImageLoadCursor,(Display *a,const XcursorImage *b),(a,b),return)
    13.5  #endif
    13.6  
    13.7 +/* Xdbe support */
    13.8 +#if SDL_VIDEO_DRIVER_X11_XDBE
    13.9 +SDL_X11_MODULE(XDBE)
   13.10 +SDL_X11_SYM(Status,XdbeQueryExtension,(Display *dpy,int *major_version_return,int *minor_version_return),(dpy,major_version_return,minor_version_return),return)
   13.11 +SDL_X11_SYM(XdbeBackBuffer,XdbeAllocateBackBufferName,(Display *dpy,Window window,XdbeSwapAction swap_action),(dpy,window,swap_action),return)
   13.12 +SDL_X11_SYM(Status,XdbeDeallocateBackBufferName,(Display *dpy,XdbeBackBuffer buffer),(dpy,buffer),return)
   13.13 +SDL_X11_SYM(Status,XdbeSwapBuffers,(Display *dpy,XdbeSwapInfo *swap_info,int num_windows),(dpy,swap_info,num_windows),return)
   13.14 +SDL_X11_SYM(Status,XdbeBeginIdiom,(Display *dpy),(dpy),return)
   13.15 +SDL_X11_SYM(Status,XdbeEndIdiom,(Display *dpy),(dpy),return)
   13.16 +SDL_X11_SYM(XdbeScreenVisualInfo*,XdbeGetVisualInfo,(Display *dpy,Drawable *screen_specifiers,int *num_screens),(dpy,screen_specifiers,num_screens),return)
   13.17 +SDL_X11_SYM(void,XdbeFreeVisualInfo,(XdbeScreenVisualInfo *visual_info),(visual_info),)
   13.18 +SDL_X11_SYM(XdbeBackBufferAttributes*,XdbeGetBackBufferAttributes,(Display *dpy,XdbeBackBuffer buffer),(dpy,buffer),return)
   13.19 +#endif
   13.20 +
   13.21  /* Xinerama support */
   13.22  #if SDL_VIDEO_DRIVER_X11_XINERAMA
   13.23  SDL_X11_MODULE(XINERAMA)
    14.1 --- a/src/video/x11/SDL_x11video.h	Wed May 27 19:00:56 2015 -0400
    14.2 +++ b/src/video/x11/SDL_x11video.h	Thu May 28 00:30:21 2015 -0400
    14.3 @@ -34,6 +34,9 @@
    14.4  #if SDL_VIDEO_DRIVER_X11_XCURSOR
    14.5  #include <X11/Xcursor/Xcursor.h>
    14.6  #endif
    14.7 +#if SDL_VIDEO_DRIVER_X11_XDBE
    14.8 +#include <X11/extensions/Xdbe.h>
    14.9 +#endif
   14.10  #if SDL_VIDEO_DRIVER_X11_XINERAMA
   14.11  #include <X11/extensions/Xinerama.h>
   14.12  #endif