### Godot version

2992ffd25523cb8b3e0ef1b873c40115b8940178

### System information

Windows 10

### Issue description

Godot crashes randomly within a few seconds after project start when moving with the mouse.

![win_err](https://github.com/godotengine/godot/assets/52464204/1da28596-d95b-40f3-b32f-12219ec02c5d)

Started after recent merge of https://github.com/godotengine/godot/pull/67791.
I can confirm that reverting the pr fixes the crashes.

### Steps to reproduce

see desc

### Minimal reproduction project

N/A
ERR_FAIL_INDEX_V(p_screen, get_screen_count(), Ref<Image>());
	switch (p_screen) {
		case SCREEN_PRIMARY: {
			p_screen = get_primary_screen();
		} break;
		case SCREEN_OF_MAIN_WINDOW: {
			p_screen = window_get_current_screen(MAIN_WINDOW_ID);
		} break;
		default:
			break;
	}
	ERR_FAIL_COND_V(p_screen < 0, Ref<Image>());
	XImage *image = nullptr;
	int event_base, error_base;
	if (XineramaQueryExtension(x11_display, &event_base, &error_base)) {
		int xin_count;
		XineramaScreenInfo *xsi = XineramaQueryScreens(x11_display, &xin_count);
		if (p_screen < xin_count) {
			int x_count = XScreenCount(x11_display);
			for (int i = 0; i < x_count; i++) {
				Window root = XRootWindow(x11_display, i);
				XWindowAttributes root_attrs;
				XGetWindowAttributes(x11_display, root, &root_attrs);
				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)) {
					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;
				}