Beispiel #1
0
tbool xf_detect_monitors(xfInfo* xfi, rdpSettings* settings)
{
	int i;
	VIRTUAL_SCREEN* vscreen;

#ifdef WITH_XINERAMA
	int ignored, ignored2;
	XineramaScreenInfo* screen_info = NULL;
#endif

	vscreen = &xfi->vscreen;

	if (xf_GetWorkArea(xfi) != true)
	{
		xfi->workArea.x = 0;
		xfi->workArea.y = 0;
		xfi->workArea.width = WidthOfScreen(xfi->screen);
		xfi->workArea.height = HeightOfScreen(xfi->screen);
	}

	if (settings->fullscreen)
	{
		settings->width = WidthOfScreen(xfi->screen);
		settings->height = HeightOfScreen(xfi->screen);
	}
	else if (settings->workarea)
	{
		settings->width = xfi->workArea.width;
		settings->height = xfi->workArea.height;
	}
	else if (settings->percent_screen)
	{
		settings->width = (xfi->workArea.width * settings->percent_screen) / 100;
		settings->height = (xfi->workArea.height * settings->percent_screen) / 100;
	}

	if (settings->fullscreen != true && settings->workarea != true)
		return true;

#ifdef WITH_XINERAMA
	if (XineramaQueryExtension(xfi->display, &ignored, &ignored2))
	{
		if (XineramaIsActive(xfi->display))
		{
			screen_info = XineramaQueryScreens(xfi->display, &vscreen->nmonitors);

			if (vscreen->nmonitors > 16)
				vscreen->nmonitors = 0;

			vscreen->monitors = xzalloc(sizeof(MONITOR_INFO) * vscreen->nmonitors);

			if (vscreen->nmonitors)
			{
				for (i = 0; i < vscreen->nmonitors; i++)
				{
					vscreen->monitors[i].area.left = screen_info[i].x_org;
					vscreen->monitors[i].area.top = screen_info[i].y_org;
					vscreen->monitors[i].area.right = screen_info[i].x_org + screen_info[i].width - 1;
					vscreen->monitors[i].area.bottom = screen_info[i].y_org + screen_info[i].height - 1;

					if ((screen_info[i].x_org == 0) && (screen_info[i].y_org == 0))
						vscreen->monitors[i].primary = true;
				}
			}

			XFree(screen_info);
		}
	}
#endif

	settings->num_monitors = vscreen->nmonitors;

	for (i = 0; i < vscreen->nmonitors; i++)
	{
		settings->monitors[i].x = vscreen->monitors[i].area.left;
		settings->monitors[i].y = vscreen->monitors[i].area.top;
		settings->monitors[i].width = vscreen->monitors[i].area.right - vscreen->monitors[i].area.left + 1;
		settings->monitors[i].height = vscreen->monitors[i].area.bottom - vscreen->monitors[i].area.top + 1;
		settings->monitors[i].is_primary = vscreen->monitors[i].primary;

		vscreen->area.left = MIN(vscreen->monitors[i].area.left, vscreen->area.left);
		vscreen->area.right = MAX(vscreen->monitors[i].area.right, vscreen->area.right);
		vscreen->area.top = MIN(vscreen->monitors[i].area.top, vscreen->area.top);
		vscreen->area.bottom = MAX(vscreen->monitors[i].area.bottom, vscreen->area.bottom);
	}

	if (settings->num_monitors)
	{
		settings->width = vscreen->area.right - vscreen->area.left + 1;
		settings->height = vscreen->area.bottom - vscreen->area.top + 1;
	}

	return true;
}
Beispiel #2
0
BOOL xf_detect_monitors(xfContext* xfc, rdpSettings* settings)
{
	int i, j;
	int nmonitors;
	int primaryMonitor;
	int vWidth, vHeight;
	int maxWidth, maxHeight;
	VIRTUAL_SCREEN* vscreen;

#ifdef WITH_XINERAMA
	int ignored, ignored2;
	XineramaScreenInfo* screen_info = NULL;
#endif

	vscreen = &xfc->vscreen;

#ifdef WITH_XINERAMA
	if (XineramaQueryExtension(xfc->display, &ignored, &ignored2))
	{
		if (XineramaIsActive(xfc->display))
		{
			screen_info = XineramaQueryScreens(xfc->display, &vscreen->nmonitors);

			if (vscreen->nmonitors > 16)
				vscreen->nmonitors = 0;

			vscreen->monitors = malloc(sizeof(MONITOR_INFO) * vscreen->nmonitors);
			ZeroMemory(vscreen->monitors, sizeof(MONITOR_INFO) * vscreen->nmonitors);

			if (vscreen->nmonitors)
			{
				for (i = 0; i < vscreen->nmonitors; i++)
				{
					vscreen->monitors[i].area.left = screen_info[i].x_org;
					vscreen->monitors[i].area.top = screen_info[i].y_org;
					vscreen->monitors[i].area.right = screen_info[i].x_org + screen_info[i].width - 1;
					vscreen->monitors[i].area.bottom = screen_info[i].y_org + screen_info[i].height - 1;

					if ((screen_info[i].x_org == 0) && (screen_info[i].y_org == 0))
						vscreen->monitors[i].primary = TRUE;
				}
			}

			XFree(screen_info);
		}
	}
#endif

	if (!xf_GetWorkArea(xfc))
	{
		xfc->workArea.x = 0;
		xfc->workArea.y = 0;
		xfc->workArea.width = WidthOfScreen(xfc->screen);
		xfc->workArea.height = HeightOfScreen(xfc->screen);
	}

	if (settings->Fullscreen)
	{
		settings->DesktopWidth = WidthOfScreen(xfc->screen);
		settings->DesktopHeight = HeightOfScreen(xfc->screen);
		maxWidth = settings->DesktopWidth;
		maxHeight = settings->DesktopHeight;
	}
	else if (settings->Workarea)
	{
		settings->DesktopWidth = xfc->workArea.width;
		settings->DesktopHeight = xfc->workArea.height;
		maxWidth = settings->DesktopWidth;
		maxHeight = settings->DesktopHeight;
	}
	else if (settings->PercentScreen)
	{
		settings->DesktopWidth = (xfc->workArea.width * settings->PercentScreen) / 100;
		settings->DesktopHeight = (xfc->workArea.height * settings->PercentScreen) / 100;
		maxWidth = settings->DesktopWidth;
		maxHeight = settings->DesktopHeight;
	}
	else
	{
		maxWidth = WidthOfScreen(xfc->screen);
		maxHeight = HeightOfScreen(xfc->screen);
	}

	if (!settings->Fullscreen && !settings->Workarea && !settings->UseMultimon)
		return TRUE;

	if ((settings->Fullscreen && !settings->UseMultimon && !settings->SpanMonitors) ||
			(settings->Workarea && !settings->RemoteApplicationMode))
	{
		/* Select a single monitor */

		if (settings->NumMonitorIds != 1)
		{
			settings->NumMonitorIds = 1;
			settings->MonitorIds = (UINT32*) malloc(sizeof(UINT32) * settings->NumMonitorIds);
			settings->MonitorIds[0] = 0;

			for (i = 0; i < vscreen->nmonitors; i++)
			{
				if (vscreen->monitors[i].primary)
				{
					settings->MonitorIds[0] = i;
					break;
				}
			}
		}
	}

	nmonitors = 0;
	primaryMonitor = 0;

	for (i = 0; i < vscreen->nmonitors; i++)
	{
		if (settings->NumMonitorIds)
		{
			BOOL found = FALSE;

			for (j = 0; j < settings->NumMonitorIds; j++)
			{
				if (settings->MonitorIds[j] == i)
					found = TRUE;
			}

			if (!found)
				continue;
		}

		settings->MonitorDefArray[nmonitors].x = vscreen->monitors[i].area.left;
		settings->MonitorDefArray[nmonitors].y = vscreen->monitors[i].area.top;
		settings->MonitorDefArray[nmonitors].width = MIN(vscreen->monitors[i].area.right - vscreen->monitors[i].area.left + 1, settings->DesktopWidth);
		settings->MonitorDefArray[nmonitors].height = MIN(vscreen->monitors[i].area.bottom - vscreen->monitors[i].area.top + 1, settings->DesktopHeight);
		settings->MonitorDefArray[nmonitors].is_primary = vscreen->monitors[i].primary;

		primaryMonitor |= vscreen->monitors[i].primary;
		nmonitors++;
	}

	settings->MonitorCount = nmonitors;

	vWidth = vHeight = 0;
	settings->DesktopPosX = maxWidth - 1;
	settings->DesktopPosY = maxHeight - 1;

	for (i = 0; i < settings->MonitorCount; i++)
	{
		settings->DesktopPosX = MIN(settings->DesktopPosX, settings->MonitorDefArray[i].x);
		settings->DesktopPosY = MIN(settings->DesktopPosY, settings->MonitorDefArray[i].y);

		vWidth += settings->MonitorDefArray[i].width;
		vHeight = MAX(vHeight, settings->MonitorDefArray[i].height);
	}

	vscreen->area.left = 0;
	vscreen->area.right = vWidth - 1;
	vscreen->area.top = 0;
	vscreen->area.bottom = vHeight - 1;

	if (settings->Workarea)
	{
		vscreen->area.top = xfc->workArea.y;
		vscreen->area.bottom = (vHeight - (vHeight - (xfc->workArea.height + xfc->workArea.y))) - 1;
	}

	if (nmonitors && !primaryMonitor)
		settings->MonitorDefArray[0].is_primary = TRUE;
	
	if (settings->MonitorCount)
	{
		settings->DesktopWidth = vscreen->area.right - vscreen->area.left + 1;
		settings->DesktopHeight = vscreen->area.bottom - vscreen->area.top + 1;
	}

	return TRUE;
}