2011-08-31 04:59:42 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-08-31 04:59:42 +04:00
|
|
|
* X11 Monitor Handling
|
|
|
|
*
|
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:20:53 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-08-31 04:59:42 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
|
2012-11-20 08:49:08 +04:00
|
|
|
#include <winpr/crt.h>
|
|
|
|
|
2014-09-12 19:13:01 +04:00
|
|
|
#include <freerdp/log.h>
|
|
|
|
|
|
|
|
#define TAG CLIENT_TAG("x11")
|
|
|
|
|
2011-08-31 04:59:42 +04:00
|
|
|
#ifdef WITH_XINERAMA
|
|
|
|
#include <X11/extensions/Xinerama.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "xf_monitor.h"
|
|
|
|
|
|
|
|
/* See MSDN Section on Multiple Display Monitors: http://msdn.microsoft.com/en-us/library/dd145071 */
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
int xf_list_monitors(xfContext* xfc)
|
2013-04-29 01:10:43 +04:00
|
|
|
{
|
|
|
|
#ifdef WITH_XINERAMA
|
|
|
|
Display* display;
|
|
|
|
int i, nmonitors = 0;
|
|
|
|
int ignored, ignored2;
|
|
|
|
XineramaScreenInfo* screen = NULL;
|
|
|
|
|
|
|
|
display = XOpenDisplay(NULL);
|
|
|
|
|
|
|
|
if (XineramaQueryExtension(display, &ignored, &ignored2))
|
|
|
|
{
|
|
|
|
if (XineramaIsActive(display))
|
|
|
|
{
|
|
|
|
screen = XineramaQueryScreens(display, &nmonitors);
|
|
|
|
|
|
|
|
for (i = 0; i < nmonitors; i++)
|
|
|
|
{
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_DBG(TAG, " %s [%d] %dx%d\t+%d+%d",
|
|
|
|
(i == 0) ? "*" : " ", i,
|
|
|
|
screen[i].width, screen[i].height,
|
|
|
|
screen[i].x_org, screen[i].y_org);
|
2013-04-29 01:10:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
XFree(screen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
XCloseDisplay(display);
|
|
|
|
#else
|
|
|
|
Screen* screen;
|
|
|
|
Display* display;
|
|
|
|
|
|
|
|
display = XOpenDisplay(NULL);
|
|
|
|
|
|
|
|
screen = ScreenOfDisplay(display, DefaultScreen(display));
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_DBG(TAG, " * [0] %dx%d\t+%d+%d", WidthOfScreen(screen), HeightOfScreen(screen), 0, 0);
|
2013-04-29 01:10:43 +04:00
|
|
|
XCloseDisplay(display);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
BOOL xf_detect_monitors(xfContext* xfc, rdpSettings* settings)
|
2011-08-31 04:59:42 +04:00
|
|
|
{
|
2013-04-29 02:48:27 +04:00
|
|
|
int i, j;
|
2013-04-29 00:27:23 +04:00
|
|
|
int nmonitors;
|
|
|
|
int primaryMonitor;
|
2013-04-29 02:48:27 +04:00
|
|
|
int vWidth, vHeight;
|
2013-04-29 00:27:23 +04:00
|
|
|
int maxWidth, maxHeight;
|
2011-08-31 04:59:42 +04:00
|
|
|
VIRTUAL_SCREEN* vscreen;
|
|
|
|
|
|
|
|
#ifdef WITH_XINERAMA
|
|
|
|
int ignored, ignored2;
|
|
|
|
XineramaScreenInfo* screen_info = NULL;
|
|
|
|
#endif
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
vscreen = &xfc->vscreen;
|
2011-08-31 04:59:42 +04:00
|
|
|
|
|
|
|
#ifdef WITH_XINERAMA
|
2013-06-13 02:57:25 +04:00
|
|
|
if (XineramaQueryExtension(xfc->display, &ignored, &ignored2))
|
2011-08-31 04:59:42 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
if (XineramaIsActive(xfc->display))
|
2011-08-31 04:59:42 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
screen_info = XineramaQueryScreens(xfc->display, &vscreen->nmonitors);
|
2011-08-31 04:59:42 +04:00
|
|
|
|
|
|
|
if (vscreen->nmonitors > 16)
|
|
|
|
vscreen->nmonitors = 0;
|
|
|
|
|
2012-11-20 08:49:08 +04:00
|
|
|
vscreen->monitors = malloc(sizeof(MONITOR_INFO) * vscreen->nmonitors);
|
|
|
|
ZeroMemory(vscreen->monitors, sizeof(MONITOR_INFO) * vscreen->nmonitors);
|
2011-08-31 04:59:42 +04:00
|
|
|
|
|
|
|
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))
|
2012-10-09 10:31:28 +04:00
|
|
|
vscreen->monitors[i].primary = TRUE;
|
2011-08-31 04:59:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
XFree(screen_info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (!xf_GetWorkArea(xfc))
|
2013-04-29 00:27:23 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->workArea.x = 0;
|
|
|
|
xfc->workArea.y = 0;
|
|
|
|
xfc->workArea.width = WidthOfScreen(xfc->screen);
|
|
|
|
xfc->workArea.height = HeightOfScreen(xfc->screen);
|
2013-04-29 00:27:23 +04:00
|
|
|
}
|
2011-08-31 04:59:42 +04:00
|
|
|
|
2013-04-29 00:27:23 +04:00
|
|
|
if (settings->Fullscreen)
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
settings->DesktopWidth = WidthOfScreen(xfc->screen);
|
|
|
|
settings->DesktopHeight = HeightOfScreen(xfc->screen);
|
2013-04-29 00:27:23 +04:00
|
|
|
maxWidth = settings->DesktopWidth;
|
|
|
|
maxHeight = settings->DesktopHeight;
|
|
|
|
}
|
|
|
|
else if (settings->Workarea)
|
2011-08-31 04:59:42 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
settings->DesktopWidth = xfc->workArea.width;
|
|
|
|
settings->DesktopHeight = xfc->workArea.height;
|
2013-04-29 00:27:23 +04:00
|
|
|
maxWidth = settings->DesktopWidth;
|
|
|
|
maxHeight = settings->DesktopHeight;
|
2011-08-31 04:59:42 +04:00
|
|
|
}
|
2013-04-29 00:27:23 +04:00
|
|
|
else if (settings->PercentScreen)
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
settings->DesktopWidth = (xfc->workArea.width * settings->PercentScreen) / 100;
|
|
|
|
settings->DesktopHeight = (xfc->workArea.height * settings->PercentScreen) / 100;
|
2013-04-29 00:27:23 +04:00
|
|
|
maxWidth = settings->DesktopWidth;
|
|
|
|
maxHeight = settings->DesktopHeight;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
maxWidth = WidthOfScreen(xfc->screen);
|
|
|
|
maxHeight = HeightOfScreen(xfc->screen);
|
2013-04-29 00:27:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!settings->Fullscreen && !settings->Workarea && !settings->UseMultimon)
|
|
|
|
return TRUE;
|
2011-08-31 04:59:42 +04:00
|
|
|
|
2013-04-29 03:16:23 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-29 00:27:23 +04:00
|
|
|
nmonitors = 0;
|
|
|
|
primaryMonitor = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < vscreen->nmonitors; i++)
|
2012-08-04 02:35:17 +04:00
|
|
|
{
|
2013-04-29 02:48:27 +04:00
|
|
|
if (settings->NumMonitorIds)
|
|
|
|
{
|
|
|
|
BOOL found = FALSE;
|
|
|
|
|
|
|
|
for (j = 0; j < settings->NumMonitorIds; j++)
|
|
|
|
{
|
|
|
|
if (settings->MonitorIds[j] == i)
|
|
|
|
found = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
2013-04-29 00:27:23 +04:00
|
|
|
continue;
|
2013-04-29 02:48:27 +04:00
|
|
|
}
|
2013-04-29 00:27:23 +04:00
|
|
|
|
2013-04-29 02:48:27 +04:00
|
|
|
settings->MonitorDefArray[nmonitors].x = vscreen->monitors[i].area.left;
|
|
|
|
settings->MonitorDefArray[nmonitors].y = vscreen->monitors[i].area.top;
|
2013-04-29 00:27:23 +04:00
|
|
|
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++;
|
2012-08-04 02:35:17 +04:00
|
|
|
}
|
|
|
|
|
2013-04-29 00:27:23 +04:00
|
|
|
settings->MonitorCount = nmonitors;
|
|
|
|
|
2013-04-29 02:48:27 +04:00
|
|
|
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;
|
|
|
|
|
2013-04-29 03:16:23 +04:00
|
|
|
if (settings->Workarea)
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
vscreen->area.top = xfc->workArea.y;
|
|
|
|
vscreen->area.bottom = (vHeight - (vHeight - (xfc->workArea.height + xfc->workArea.y))) - 1;
|
2013-04-29 03:16:23 +04:00
|
|
|
}
|
|
|
|
|
2013-04-29 00:27:23 +04:00
|
|
|
if (nmonitors && !primaryMonitor)
|
|
|
|
settings->MonitorDefArray[0].is_primary = TRUE;
|
|
|
|
|
2012-11-08 08:29:24 +04:00
|
|
|
if (settings->MonitorCount)
|
2011-12-15 13:45:50 +04:00
|
|
|
{
|
2012-11-07 19:33:06 +04:00
|
|
|
settings->DesktopWidth = vscreen->area.right - vscreen->area.left + 1;
|
|
|
|
settings->DesktopHeight = vscreen->area.bottom - vscreen->area.top + 1;
|
2011-12-15 13:45:50 +04:00
|
|
|
}
|
2011-09-02 21:29:17 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-31 04:59:42 +04:00
|
|
|
}
|
2013-08-19 19:44:52 +04:00
|
|
|
|
|
|
|
/** Clean up all resources allocated by functions in this file.
|
|
|
|
*/
|
|
|
|
void xf_monitors_free(xfContext *xfc, rdpSettings *settings)
|
|
|
|
{
|
|
|
|
#ifdef WITH_XINERAMA
|
2013-11-01 07:35:24 +04:00
|
|
|
if (xfc->vscreen.monitors)
|
|
|
|
{
|
2013-08-19 19:44:52 +04:00
|
|
|
free(xfc->vscreen.monitors);
|
2013-11-01 07:35:24 +04:00
|
|
|
xfc->vscreen.monitors = NULL;
|
|
|
|
}
|
2013-08-19 19:44:52 +04:00
|
|
|
#endif
|
|
|
|
|
2013-11-01 07:35:24 +04:00
|
|
|
if (settings->MonitorIds)
|
|
|
|
{
|
2013-08-19 19:44:52 +04:00
|
|
|
free(settings->MonitorIds);
|
2013-11-01 07:35:24 +04:00
|
|
|
settings->MonitorIds = NULL;
|
|
|
|
}
|
2013-08-19 19:44:52 +04:00
|
|
|
}
|