Fix changelog email address
[freerdp-ubuntu-pcb-backport.git] / client / X11 / xf_monitor.c
1 /**
2  * FreeRDP: A Remote Desktop Protocol Client
3  * X11 Monitor Handling
4  *
5  * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6  *
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
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <X11/Xlib.h>
24 #include <X11/Xutil.h>
25
26 #ifdef WITH_XINERAMA
27 #include <X11/extensions/Xinerama.h>
28 #endif
29
30 #include "xf_monitor.h"
31
32 /* See MSDN Section on Multiple Display Monitors: http://msdn.microsoft.com/en-us/library/dd145071 */
33
34 boolean xf_detect_monitors(xfInfo* xfi, rdpSettings* settings)
35 {
36         int i;
37         VIRTUAL_SCREEN* vscreen;
38
39 #ifdef WITH_XINERAMA
40         int ignored, ignored2;
41         XineramaScreenInfo* screen_info = NULL;
42 #endif
43
44         vscreen = &xfi->vscreen;
45
46         if (xf_GetWorkArea(xfi) != true)
47         {
48                 xfi->workArea.x = 0;
49                 xfi->workArea.y = 0;
50                 xfi->workArea.width = WidthOfScreen(xfi->screen);
51                 xfi->workArea.height = HeightOfScreen(xfi->screen);
52         }
53
54         if (settings->fullscreen)
55         {
56                 settings->width = WidthOfScreen(xfi->screen);
57                 settings->height = HeightOfScreen(xfi->screen); 
58         }
59         else if (settings->workarea)
60         {
61                 settings->width = xfi->workArea.width;
62                 settings->height = xfi->workArea.height;
63         }
64         else if (settings->percent_screen)
65         {
66                 settings->width = (xfi->workArea.width * settings->percent_screen) / 100;
67                 settings->height = (xfi->workArea.height * settings->percent_screen) / 100;
68         }
69
70         if (settings->fullscreen != true && settings->workarea != true)
71                 return true;
72
73 #ifdef WITH_XINERAMA
74         if (XineramaQueryExtension(xfi->display, &ignored, &ignored2))
75         {
76                 if (XineramaIsActive(xfi->display))
77                 {
78                         screen_info = XineramaQueryScreens(xfi->display, &vscreen->nmonitors);
79
80                         if (vscreen->nmonitors > 16)
81                                 vscreen->nmonitors = 0;
82
83                         vscreen->monitors = xzalloc(sizeof(MONITOR_INFO) * vscreen->nmonitors);
84
85                         if (vscreen->nmonitors)
86                         {
87                                 for (i = 0; i < vscreen->nmonitors; i++)
88                                 {
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;
93
94                                         if ((screen_info[i].x_org == 0) && (screen_info[i].y_org == 0))
95                                                 vscreen->monitors[i].primary = true;
96                                 }
97                         }
98
99                         XFree(screen_info);
100                 }
101         }
102 #endif
103
104         settings->num_monitors = vscreen->nmonitors;
105
106         for (i = 0; i < vscreen->nmonitors; i++)
107         {
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;
113
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);
118         }
119
120         if (settings->num_monitors)
121         {
122                 settings->width = vscreen->area.right - vscreen->area.left + 1;
123                 settings->height = vscreen->area.bottom - vscreen->area.top + 1;
124         }
125
126         return true;
127 }