2 * FreeRDP: A Remote Desktop Protocol Client
5 * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
24 #include <X11/Xutil.h>
27 #include <X11/extensions/Xinerama.h>
30 #include "xf_monitor.h"
32 /* See MSDN Section on Multiple Display Monitors: http://msdn.microsoft.com/en-us/library/dd145071 */
34 boolean xf_detect_monitors(xfInfo* xfi, rdpSettings* settings)
37 VIRTUAL_SCREEN* vscreen;
40 int ignored, ignored2;
41 XineramaScreenInfo* screen_info = NULL;
44 vscreen = &xfi->vscreen;
46 if (xf_GetWorkArea(xfi) != true)
50 xfi->workArea.width = WidthOfScreen(xfi->screen);
51 xfi->workArea.height = HeightOfScreen(xfi->screen);
54 if (settings->fullscreen)
56 settings->width = WidthOfScreen(xfi->screen);
57 settings->height = HeightOfScreen(xfi->screen);
59 else if (settings->workarea)
61 settings->width = xfi->workArea.width;
62 settings->height = xfi->workArea.height;
64 else if (settings->percent_screen)
66 settings->width = (xfi->workArea.width * settings->percent_screen) / 100;
67 settings->height = (xfi->workArea.height * settings->percent_screen) / 100;
70 if (settings->fullscreen != true && settings->workarea != true)
74 if (XineramaQueryExtension(xfi->display, &ignored, &ignored2))
76 if (XineramaIsActive(xfi->display))
78 screen_info = XineramaQueryScreens(xfi->display, &vscreen->nmonitors);
80 if (vscreen->nmonitors > 16)
81 vscreen->nmonitors = 0;
83 vscreen->monitors = xzalloc(sizeof(MONITOR_INFO) * vscreen->nmonitors);
85 if (vscreen->nmonitors)
87 for (i = 0; i < vscreen->nmonitors; i++)
89 vscreen->monitors[i].area.left = screen_info[i].x_org;
90 vscreen->monitors[i].area.top = screen_info[i].y_org;
91 vscreen->monitors[i].area.right = screen_info[i].x_org + screen_info[i].width - 1;
92 vscreen->monitors[i].area.bottom = screen_info[i].y_org + screen_info[i].height - 1;
94 if ((screen_info[i].x_org == 0) && (screen_info[i].y_org == 0))
95 vscreen->monitors[i].primary = true;
104 settings->num_monitors = vscreen->nmonitors;
106 for (i = 0; i < vscreen->nmonitors; i++)
108 settings->monitors[i].x = vscreen->monitors[i].area.left;
109 settings->monitors[i].y = vscreen->monitors[i].area.top;
110 settings->monitors[i].width = vscreen->monitors[i].area.right - vscreen->monitors[i].area.left + 1;
111 settings->monitors[i].height = vscreen->monitors[i].area.bottom - vscreen->monitors[i].area.top + 1;
112 settings->monitors[i].is_primary = vscreen->monitors[i].primary;
114 vscreen->area.left = MIN(vscreen->monitors[i].area.left, vscreen->area.left);
115 vscreen->area.right = MAX(vscreen->monitors[i].area.right, vscreen->area.right);
116 vscreen->area.top = MIN(vscreen->monitors[i].area.top, vscreen->area.top);
117 vscreen->area.bottom = MAX(vscreen->monitors[i].area.bottom, vscreen->area.bottom);
120 if (settings->num_monitors)
122 settings->width = vscreen->area.right - vscreen->area.left + 1;
123 settings->height = vscreen->area.bottom - vscreen->area.top + 1;