[X11] Do not fail DisplayServer init if non-essential extensions are missing.

(cherry picked from commit acff87ffda)
This commit is contained in:
bruvzg 2023-08-04 10:58:14 +03:00 committed by Yuri Sizov
parent c339abe1aa
commit 21da3f3847
2 changed files with 22 additions and 25 deletions

View File

@ -744,7 +744,7 @@ int DisplayServerX11::get_screen_count() const {
// Using Xinerama Extension // Using Xinerama Extension
int event_base, error_base; int event_base, error_base;
if (XineramaQueryExtension(x11_display, &event_base, &error_base)) { if (xinerama_ext_ok && XineramaQueryExtension(x11_display, &event_base, &error_base)) {
XineramaScreenInfo *xsi = XineramaQueryScreens(x11_display, &count); XineramaScreenInfo *xsi = XineramaQueryScreens(x11_display, &count);
XFree(xsi); XFree(xsi);
} else { } else {
@ -756,7 +756,7 @@ int DisplayServerX11::get_screen_count() const {
int DisplayServerX11::get_primary_screen() const { int DisplayServerX11::get_primary_screen() const {
int event_base, error_base; int event_base, error_base;
if (XineramaQueryExtension(x11_display, &event_base, &error_base)) { if (xinerama_ext_ok && XineramaQueryExtension(x11_display, &event_base, &error_base)) {
return 0; return 0;
} else { } else {
return XDefaultScreen(x11_display); return XDefaultScreen(x11_display);
@ -809,7 +809,7 @@ Rect2i DisplayServerX11::_screen_get_rect(int p_screen) const {
// Using Xinerama Extension. // Using Xinerama Extension.
int event_base, error_base; int event_base, error_base;
if (XineramaQueryExtension(x11_display, &event_base, &error_base)) { if (xinerama_ext_ok && XineramaQueryExtension(x11_display, &event_base, &error_base)) {
int count; int count;
XineramaScreenInfo *xsi = XineramaQueryScreens(x11_display, &count); XineramaScreenInfo *xsi = XineramaQueryScreens(x11_display, &count);
@ -1244,7 +1244,7 @@ Ref<Image> DisplayServerX11::screen_get_image(int p_screen) const {
XImage *image = nullptr; XImage *image = nullptr;
int event_base, error_base; int event_base, error_base;
if (XineramaQueryExtension(x11_display, &event_base, &error_base)) { if (xinerama_ext_ok && XineramaQueryExtension(x11_display, &event_base, &error_base)) {
int xin_count; int xin_count;
XineramaScreenInfo *xsi = XineramaQueryScreens(x11_display, &xin_count); XineramaScreenInfo *xsi = XineramaQueryScreens(x11_display, &xin_count);
if (p_screen < xin_count) { if (p_screen < xin_count) {
@ -1580,6 +1580,7 @@ void DisplayServerX11::window_set_mouse_passthrough(const Vector<Vector2> &p_reg
void DisplayServerX11::_update_window_mouse_passthrough(WindowID p_window) { void DisplayServerX11::_update_window_mouse_passthrough(WindowID p_window) {
ERR_FAIL_COND(!windows.has(p_window)); ERR_FAIL_COND(!windows.has(p_window));
ERR_FAIL_COND(!xshaped_ext_ok);
const Vector<Vector2> region_path = windows[p_window].mpath; const Vector<Vector2> region_path = windows[p_window].mpath;
@ -5429,13 +5430,11 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode
} }
if (initialize_xinerama(dylibloader_verbose) != 0) { if (initialize_xinerama(dylibloader_verbose) != 0) {
r_error = ERR_UNAVAILABLE; xinerama_ext_ok = false;
ERR_FAIL_MSG("Can't load Xinerama dynamically.");
} }
if (initialize_xrandr(dylibloader_verbose) != 0) { if (initialize_xrandr(dylibloader_verbose) != 0) {
r_error = ERR_UNAVAILABLE; xrandr_ext_ok = false;
ERR_FAIL_MSG("Can't load Xrandr dynamically.");
} }
if (initialize_xrender(dylibloader_verbose) != 0) { if (initialize_xrender(dylibloader_verbose) != 0) {
@ -5505,42 +5504,36 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode
return; return;
} }
{ if (xshaped_ext_ok) {
int version_major = 0; int version_major = 0;
int version_minor = 0; int version_minor = 0;
int rc = XShapeQueryVersion(x11_display, &version_major, &version_minor); int rc = XShapeQueryVersion(x11_display, &version_major, &version_minor);
print_verbose(vformat("Xshape %d.%d detected.", version_major, version_minor)); print_verbose(vformat("Xshape %d.%d detected.", version_major, version_minor));
if (rc != 1 || version_major < 1) { if (rc != 1 || version_major < 1) {
ERR_PRINT("Unsupported Xshape library version."); xshaped_ext_ok = false;
r_error = ERR_UNAVAILABLE; print_verbose("Unsupported Xshape library version.");
XCloseDisplay(x11_display);
return;
} }
} }
{ if (xinerama_ext_ok) {
int version_major = 0; int version_major = 0;
int version_minor = 0; int version_minor = 0;
int rc = XineramaQueryVersion(x11_display, &version_major, &version_minor); int rc = XineramaQueryVersion(x11_display, &version_major, &version_minor);
print_verbose(vformat("Xinerama %d.%d detected.", version_major, version_minor)); print_verbose(vformat("Xinerama %d.%d detected.", version_major, version_minor));
if (rc != 1 || version_major < 1) { if (rc != 1 || version_major < 1) {
ERR_PRINT("Unsupported Xinerama library version."); xinerama_ext_ok = false;
r_error = ERR_UNAVAILABLE; print_verbose("Unsupported Xinerama library version.");
XCloseDisplay(x11_display);
return;
} }
} }
{ if (xrandr_ext_ok) {
int version_major = 0; int version_major = 0;
int version_minor = 0; int version_minor = 0;
int rc = XRRQueryVersion(x11_display, &version_major, &version_minor); int rc = XRRQueryVersion(x11_display, &version_major, &version_minor);
print_verbose(vformat("Xrandr %d.%d detected.", version_major, version_minor)); print_verbose(vformat("Xrandr %d.%d detected.", version_major, version_minor));
if (rc != 1 || (version_major == 1 && version_minor < 3) || (version_major < 1)) { if (rc != 1 || (version_major == 1 && version_minor < 3) || (version_major < 1)) {
ERR_PRINT("Unsupported Xrandr library version."); xrandr_ext_ok = false;
r_error = ERR_UNAVAILABLE; print_verbose("Unsupported Xrandr library version.");
XCloseDisplay(x11_display);
return;
} }
} }
@ -5606,7 +5599,9 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode
if (!xrandr_handle) { if (!xrandr_handle) {
fprintf(stderr, "could not load libXrandr.so.2, Error: %s\n", err); fprintf(stderr, "could not load libXrandr.so.2, Error: %s\n", err);
} }
} else { }
if (xrandr_handle) {
XRRQueryVersion(x11_display, &xrandr_major, &xrandr_minor); XRRQueryVersion(x11_display, &xrandr_major, &xrandr_minor);
if (((xrandr_major << 8) | xrandr_minor) >= 0x0105) { if (((xrandr_major << 8) | xrandr_minor) >= 0x0105) {
xrr_get_monitors = (xrr_get_monitors_t)dlsym(xrandr_handle, "XRRGetMonitors"); xrr_get_monitors = (xrr_get_monitors_t)dlsym(xrandr_handle, "XRRGetMonitors");

View File

@ -322,7 +322,9 @@ class DisplayServerX11 : public DisplayServer {
xrr_get_monitors_t xrr_get_monitors = nullptr; xrr_get_monitors_t xrr_get_monitors = nullptr;
xrr_free_monitors_t xrr_free_monitors = nullptr; xrr_free_monitors_t xrr_free_monitors = nullptr;
void *xrandr_handle = nullptr; void *xrandr_handle = nullptr;
Bool xrandr_ext_ok; bool xrandr_ext_ok = true;
bool xinerama_ext_ok = true;
bool xshaped_ext_ok = true;
struct Property { struct Property {
unsigned char *data; unsigned char *data;