mirror of
https://github.com/godotengine/godot
synced 2024-09-16 02:17:12 +00:00
[X11] Fallback to root window size, when Xinerama extension is available, but return zero screens.
This commit is contained in:
parent
557f63d037
commit
1f8e69ddec
|
@ -1007,7 +1007,8 @@ int DisplayServerX11::get_screen_count() const {
|
||||||
if (xinerama_ext_ok && 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 {
|
}
|
||||||
|
if (count == 0) {
|
||||||
count = XScreenCount(x11_display);
|
count = XScreenCount(x11_display);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1068,25 +1069,29 @@ Rect2i DisplayServerX11::_screen_get_rect(int p_screen) const {
|
||||||
ERR_FAIL_COND_V(p_screen < 0, rect);
|
ERR_FAIL_COND_V(p_screen < 0, rect);
|
||||||
|
|
||||||
// Using Xinerama Extension.
|
// Using Xinerama Extension.
|
||||||
|
bool found = false;
|
||||||
int event_base, error_base;
|
int event_base, error_base;
|
||||||
if (xinerama_ext_ok && 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);
|
||||||
|
|
||||||
// Check if screen is valid.
|
|
||||||
if (p_screen < count) {
|
|
||||||
rect.position.x = xsi[p_screen].x_org;
|
|
||||||
rect.position.y = xsi[p_screen].y_org;
|
|
||||||
rect.size.width = xsi[p_screen].width;
|
|
||||||
rect.size.height = xsi[p_screen].height;
|
|
||||||
} else {
|
|
||||||
ERR_PRINT("Invalid screen index: " + itos(p_screen) + "(count: " + itos(count) + ").");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (xsi) {
|
if (xsi) {
|
||||||
|
if (count > 0) {
|
||||||
|
// Check if screen is valid.
|
||||||
|
if (p_screen < count) {
|
||||||
|
rect.position.x = xsi[p_screen].x_org;
|
||||||
|
rect.position.y = xsi[p_screen].y_org;
|
||||||
|
rect.size.width = xsi[p_screen].width;
|
||||||
|
rect.size.height = xsi[p_screen].height;
|
||||||
|
found = true;
|
||||||
|
} else {
|
||||||
|
ERR_PRINT(vformat("Invalid screen index: %d (count: %d).", p_screen, count));
|
||||||
|
}
|
||||||
|
}
|
||||||
XFree(xsi);
|
XFree(xsi);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if (!found) {
|
||||||
int count = XScreenCount(x11_display);
|
int count = XScreenCount(x11_display);
|
||||||
if (p_screen < count) {
|
if (p_screen < count) {
|
||||||
Window root = XRootWindow(x11_display, p_screen);
|
Window root = XRootWindow(x11_display, p_screen);
|
||||||
|
@ -1097,7 +1102,7 @@ Rect2i DisplayServerX11::_screen_get_rect(int p_screen) const {
|
||||||
rect.size.width = xwa.width;
|
rect.size.width = xwa.width;
|
||||||
rect.size.height = xwa.height;
|
rect.size.height = xwa.height;
|
||||||
} else {
|
} else {
|
||||||
ERR_PRINT("Invalid screen index: " + itos(p_screen) + "(count: " + itos(count) + ").");
|
ERR_PRINT(vformat("Invalid screen index: %d (count: %d).", p_screen, count));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1503,25 +1508,33 @@ Ref<Image> DisplayServerX11::screen_get_image(int p_screen) const {
|
||||||
|
|
||||||
XImage *image = nullptr;
|
XImage *image = nullptr;
|
||||||
|
|
||||||
|
bool found = false;
|
||||||
int event_base, error_base;
|
int event_base, error_base;
|
||||||
if (xinerama_ext_ok && 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 (xsi) {
|
||||||
int x_count = XScreenCount(x11_display);
|
if (xin_count > 0) {
|
||||||
for (int i = 0; i < x_count; i++) {
|
if (p_screen < xin_count) {
|
||||||
Window root = XRootWindow(x11_display, i);
|
int x_count = XScreenCount(x11_display);
|
||||||
XWindowAttributes root_attrs;
|
for (int i = 0; i < x_count; i++) {
|
||||||
XGetWindowAttributes(x11_display, root, &root_attrs);
|
Window root = XRootWindow(x11_display, i);
|
||||||
if ((xsi[p_screen].x_org >= root_attrs.x) && (xsi[p_screen].x_org <= root_attrs.x + root_attrs.width) && (xsi[p_screen].y_org >= root_attrs.y) && (xsi[p_screen].y_org <= root_attrs.y + root_attrs.height)) {
|
XWindowAttributes root_attrs;
|
||||||
image = XGetImage(x11_display, root, xsi[p_screen].x_org, xsi[p_screen].y_org, xsi[p_screen].width, xsi[p_screen].height, AllPlanes, ZPixmap);
|
XGetWindowAttributes(x11_display, root, &root_attrs);
|
||||||
break;
|
if ((xsi[p_screen].x_org >= root_attrs.x) && (xsi[p_screen].x_org <= root_attrs.x + root_attrs.width) && (xsi[p_screen].y_org >= root_attrs.y) && (xsi[p_screen].y_org <= root_attrs.y + root_attrs.height)) {
|
||||||
|
found = true;
|
||||||
|
image = XGetImage(x11_display, root, xsi[p_screen].x_org, xsi[p_screen].y_org, xsi[p_screen].width, xsi[p_screen].height, AllPlanes, ZPixmap);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ERR_PRINT(vformat("Invalid screen index: %d (count: %d).", p_screen, xin_count));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
XFree(xsi);
|
||||||
ERR_FAIL_V_MSG(Ref<Image>(), "Invalid screen index: " + itos(p_screen) + "(count: " + itos(xin_count) + ").");
|
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
if (!found) {
|
||||||
int x_count = XScreenCount(x11_display);
|
int x_count = XScreenCount(x11_display);
|
||||||
if (p_screen < x_count) {
|
if (p_screen < x_count) {
|
||||||
Window root = XRootWindow(x11_display, p_screen);
|
Window root = XRootWindow(x11_display, p_screen);
|
||||||
|
@ -1531,7 +1544,7 @@ Ref<Image> DisplayServerX11::screen_get_image(int p_screen) const {
|
||||||
|
|
||||||
image = XGetImage(x11_display, root, root_attrs.x, root_attrs.y, root_attrs.width, root_attrs.height, AllPlanes, ZPixmap);
|
image = XGetImage(x11_display, root, root_attrs.x, root_attrs.y, root_attrs.width, root_attrs.height, AllPlanes, ZPixmap);
|
||||||
} else {
|
} else {
|
||||||
ERR_FAIL_V_MSG(Ref<Image>(), "Invalid screen index: " + itos(p_screen) + "(count: " + itos(x_count) + ").");
|
ERR_PRINT(vformat("Invalid screen index: %d (count: %d).", p_screen, x_count));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue