Skip to content

Commit 4ef8b6c

Browse files
authored
X11: Center Message Box on Multi Monitor Displays (#12819)
Use XRandr to find the position of the current screen to center the message box on that window
1 parent c5d5967 commit 4ef8b6c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/video/x11/SDL_x11messagebox.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,11 @@ static bool X11_MessageBoxCreateWindow(SDL_MessageBoxDataX11 *data)
425425
Display *display = data->display;
426426
SDL_WindowData *windowdata = NULL;
427427
const SDL_MessageBoxData *messageboxdata = data->messageboxdata;
428+
#ifdef XRANDR_DISABLED_BY_DEFAULT
429+
const bool use_xrandr_by_default = false;
430+
#else
431+
const bool use_xrandr_by_default = true;
432+
#endif
428433

429434
if (messageboxdata->window) {
430435
SDL_DisplayData *displaydata = SDL_GetDisplayDriverDataForWindow(messageboxdata->window);
@@ -497,7 +502,13 @@ static bool X11_MessageBoxCreateWindow(SDL_MessageBoxDataX11 *data)
497502
const SDL_DisplayData *dpydata = dpy->internal;
498503
x = dpydata->x + ((dpy->current_mode->w - data->dialog_width) / 2);
499504
y = dpydata->y + ((dpy->current_mode->h - data->dialog_height) / 3);
500-
} else { // oh well. This will misposition on a multi-head setup. Init first next time.
505+
} else if (SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_XRANDR, use_xrandr_by_default)) {
506+
XRRScreenResources *screen = X11_XRRGetScreenResourcesCurrent(display, DefaultRootWindow(display));
507+
XRRCrtcInfo *crtc_info = X11_XRRGetCrtcInfo(display, screen, screen->crtcs[0]);
508+
x = (crtc_info->width - data->dialog_width) / 2;
509+
y = (crtc_info->height - data->dialog_height) / 3;
510+
} else {
511+
// oh well. This will misposition on a multi-head setup. Init first next time.
501512
x = (DisplayWidth(display, data->screen) - data->dialog_width) / 2;
502513
y = (DisplayHeight(display, data->screen) - data->dialog_height) / 3;
503514
}

0 commit comments

Comments
 (0)