X11: center parentless message boxes on the primary display if possible.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 14 Jul 2015 23:46:35 -0400
changeset 9801752406828724
parent 9800 978b538d177e
child 9802 387821246318
X11: center parentless message boxes on the primary display if possible.

This relies on a successful SDL_Init(SDL_INIT_VIDEO) to work, since it's
silly to reproduce all the Xinerama/XRandR code in the message box parts. If
X11 is available but SDL hasn't been initialized, the message box will center
in the primary screen, which will be positioned weirdly on multi-head setups,
but this should fix the most significant common case.
src/video/x11/SDL_x11messagebox.c
     1.1 --- a/src/video/x11/SDL_x11messagebox.c	Tue Jul 14 21:28:26 2015 -0400
     1.2 +++ b/src/video/x11/SDL_x11messagebox.c	Tue Jul 14 23:46:35 2015 -0400
     1.3 @@ -439,8 +439,16 @@
     1.4          y = attrib.y + ( attrib.height - data->dialog_height ) / 3 ;
     1.5          X11_XTranslateCoordinates(display, windowdata->xwindow, RootWindow(display, data->screen), x, y, &x, &y, &dummy);
     1.6      } else {
     1.7 -        x = ( DisplayWidth( display, data->screen ) - data->dialog_width ) / 2;
     1.8 -        y = ( DisplayHeight( display, data->screen ) - data->dialog_height ) / 3 ;
     1.9 +        const SDL_VideoDevice *dev = SDL_GetVideoDevice();
    1.10 +        if ((dev) && (dev->displays) && (dev->num_displays > 0)) {
    1.11 +            const SDL_VideoDisplay *dpy = &dev->displays[0];
    1.12 +            const SDL_DisplayData *dpydata = (SDL_DisplayData *) dpy->driverdata;
    1.13 +            x = dpydata->x + (( dpy->current_mode.w - data->dialog_width ) / 2);
    1.14 +            y = dpydata->y + (( dpy->current_mode.h - data->dialog_height ) / 3);
    1.15 +        } else {   /* oh well. This will misposition on a multi-head setup. Init first next time. */
    1.16 +            x = ( DisplayWidth( display, data->screen ) - data->dialog_width ) / 2;
    1.17 +            y = ( DisplayHeight( display, data->screen ) - data->dialog_height ) / 3 ;
    1.18 +        }
    1.19      }
    1.20      X11_XMoveWindow( display, data->window, x, y );
    1.21