Bug 1215078 - [Wayland] Configure display for Wayland session. r=karlt

This commit is contained in:
Martin Stransky 2016-01-08 01:25:00 -05:00
parent 40e0ffdd03
commit cd1f126100

View File

@ -2958,7 +2958,42 @@ static void MOZ_gdk_display_close(GdkDisplay *display)
(void) display;
#endif
}
#endif // MOZ_WIDGET_GTK2
static const char* detectDisplay(void)
{
bool tryX11 = false;
bool tryWayland = false;
bool tryBroadway = false;
// Honor user backend selection
const char *backend = PR_GetEnv("GDK_BACKEND");
if (!backend || strstr(backend, "*")) {
// Try all backends
tryX11 = true;
tryWayland = true;
tryBroadway = true;
} else if (backend) {
if (strstr(backend, "x11"))
tryX11 = true;
if (strstr(backend, "wayland"))
tryWayland = true;
if (strstr(backend, "broadway"))
tryBroadway = true;
}
const char *display_name;
if (tryX11 && (display_name = PR_GetEnv("DISPLAY"))) {
return display_name;
} else if (tryWayland && (display_name = PR_GetEnv("WAYLAND_DISPLAY"))) {
return display_name;
} else if (tryBroadway && (display_name = PR_GetEnv("BROADWAY_DISPLAY"))) {
return display_name;
}
PR_fprintf(PR_STDERR, "Error: GDK_BACKEND does not match available displays\n");
return nullptr;
}
#endif // MOZ_WIDGET_GTK
/**
* NSPR will search for the "nspr_use_zone_allocator" symbol throughout
@ -3715,12 +3750,12 @@ XREMain::XRE_mainStartup(bool* aExitFlag)
#if defined(MOZ_WIDGET_GTK)
// display_name is owned by gdk.
const char *display_name = gdk_get_display_arg_name();
bool saveDisplayArg = false;
if (display_name) {
SaveWordToEnv("DISPLAY", nsDependentCString(display_name));
saveDisplayArg = true;
} else {
display_name = PR_GetEnv("DISPLAY");
display_name = detectDisplay();
if (!display_name) {
PR_fprintf(PR_STDERR, "Error: no display specified\n");
return 1;
}
}
@ -3731,16 +3766,19 @@ XREMain::XRE_mainStartup(bool* aExitFlag)
XInitThreads();
#endif
#if defined(MOZ_WIDGET_GTK)
{
mGdkDisplay = gdk_display_open(display_name);
if (!mGdkDisplay) {
PR_fprintf(PR_STDERR, "Error: cannot open display: %s\n", display_name);
return 1;
mGdkDisplay = gdk_display_open(display_name);
if (!mGdkDisplay) {
PR_fprintf(PR_STDERR, "Error: cannot open display: %s\n", display_name);
return 1;
}
gdk_display_manager_set_default_display (gdk_display_manager_get(),
mGdkDisplay);
if (GDK_IS_X11_DISPLAY(mGdkDisplay)) {
if (saveDisplayArg) {
SaveWordToEnv("DISPLAY", nsDependentCString(display_name));
}
gdk_display_manager_set_default_display (gdk_display_manager_get(),
mGdkDisplay);
if (!GDK_IS_X11_DISPLAY(mGdkDisplay))
mDisableRemote = true;
} else {
mDisableRemote = true;
}
#endif
#ifdef MOZ_ENABLE_XREMOTE