[Commits] SDL: X11: center parentless message boxes on the primary display...

libsdl.org revision control commits-owner at libsdl.org
Tue Jul 14 20:46:47 PDT 2015


details:   https://hg.libsdl.org/SDL/rev/752406828724
changeset: 9801:752406828724
user:      Ryan C. Gordon <icculus at icculus.org>
date:      Tue Jul 14 23:46:35 2015 -0400
description:
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.

diffstat:

 src/video/x11/SDL_x11messagebox.c |  12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diffs (22 lines):

diff -r 978b538d177e -r 752406828724 src/video/x11/SDL_x11messagebox.c
--- a/src/video/x11/SDL_x11messagebox.c	Tue Jul 14 21:28:26 2015 -0400
+++ b/src/video/x11/SDL_x11messagebox.c	Tue Jul 14 23:46:35 2015 -0400
@@ -439,8 +439,16 @@
         y = attrib.y + ( attrib.height - data->dialog_height ) / 3 ;
         X11_XTranslateCoordinates(display, windowdata->xwindow, RootWindow(display, data->screen), x, y, &x, &y, &dummy);
     } else {
-        x = ( DisplayWidth( display, data->screen ) - data->dialog_width ) / 2;
-        y = ( DisplayHeight( display, data->screen ) - data->dialog_height ) / 3 ;
+        const SDL_VideoDevice *dev = SDL_GetVideoDevice();
+        if ((dev) && (dev->displays) && (dev->num_displays > 0)) {
+            const SDL_VideoDisplay *dpy = &dev->displays[0];
+            const SDL_DisplayData *dpydata = (SDL_DisplayData *) dpy->driverdata;
+            x = dpydata->x + (( dpy->current_mode.w - data->dialog_width ) / 2);
+            y = dpydata->y + (( dpy->current_mode.h - data->dialog_height ) / 3);
+        } else {   /* oh well. This will misposition on a multi-head setup. Init first next time. */
+            x = ( DisplayWidth( display, data->screen ) - data->dialog_width ) / 2;
+            y = ( DisplayHeight( display, data->screen ) - data->dialog_height ) / 3 ;
+        }
     }
     X11_XMoveWindow( display, data->window, x, y );
 


More information about the commits mailing list