forked from rdesktop/rdesktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rdpedisp.c
157 lines (123 loc) · 4.39 KB
/
rdpedisp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* -*- c-basic-offset: 8 -*-
rdesktop: A Remote Desktop Protocol client.
Display Update Virtual Channel Extension.
Copyright 2017 Henrik Andersson <[email protected]> for Cendio AB
Copyright 2017 Karl Mikaelsson <[email protected]> for Cendio AB
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "rdesktop.h"
#define DISPLAYCONTROL_PDU_TYPE_CAPS 0x5
#define DISPLAYCONTROL_PDU_TYPE_MONITOR_LAYOUT 0x2
#define DISPLAYCONTROL_MONITOR_PRIMARY 0x1
#define RDPEDISP_CHANNEL_NAME "Microsoft::Windows::RDS::DisplayControl"
extern int g_dpi;
extern RD_BOOL g_pending_resize_defer;
extern struct timeval g_pending_resize_defer_timer;
static void rdpedisp_send(STREAM s);
static void rdpedisp_init_packet(STREAM s, uint32 type, uint32 length);
static void
rdpedisp_process_caps_pdu(STREAM s)
{
uint32 tmp[3];
in_uint32_le(s, tmp[0]); /* MaxNumMonitors */
in_uint32_le(s, tmp[1]); /* MaxMonitorAreaFactorA */
in_uint32_le(s, tmp[2]); /* MaxMonitorAreaFactorB */
logger(Protocol, Debug,
"rdpedisp_process_caps_pdu(), Max supported monitor area (square pixels) is %d",
tmp[0] * tmp[1] * tmp[2]);
/* When the RDPEDISP channel is established, we allow dynamic
session resize straight away by clearing the defer flag and
the defer timer. This lets process_pending_resize() start
processing pending resizes immediately. We expect that
process_pending_resize will prefer RDPEDISP resizes over
disconnect/reconnect resizes. */
g_pending_resize_defer = False;
g_pending_resize_defer_timer.tv_sec = 0;
g_pending_resize_defer_timer.tv_usec = 0;
}
static void
rdpedisp_process_pdu(STREAM s)
{
uint32 type;
/* Read DISPLAYCONTROL_HEADER */
in_uint32_le(s, type); /* type */
in_uint8s(s, 4); /* length */
logger(Protocol, Debug, "rdpedisp_process_pdu(), Got PDU type %d", type);
switch (type)
{
case DISPLAYCONTROL_PDU_TYPE_CAPS:
rdpedisp_process_caps_pdu(s);
break;
default:
logger(Protocol, Warning, "rdpedisp_process_pdu(), Unhandled PDU type %d",
type);
break;
}
}
static void
rdpedisp_send_monitor_layout_pdu(uint32 width, uint32 height)
{
struct stream s;
uint32 physwidth, physheight, desktopscale, devicescale;
memset(&s, 0, sizeof(s));
logger(Protocol, Debug, "rdpedisp_send_monitor_layout_pdu(), width = %d, height = %d",
width, height);
rdpedisp_init_packet(&s, DISPLAYCONTROL_PDU_TYPE_MONITOR_LAYOUT, 16 + 1 * 40);
out_uint32_le(&s, 40); /* MonitorLayoutSize - spec mandates 40 */
out_uint32_le(&s, 1); /* NumMonitors */
out_uint32_le(&s, DISPLAYCONTROL_MONITOR_PRIMARY); /* flags */
out_uint32_le(&s, 0); /* left */
out_uint32_le(&s, 0); /* top */
out_uint32_le(&s, width); /* width */
out_uint32_le(&s, height); /* height */
utils_calculate_dpi_scale_factors(width, height, g_dpi,
&physwidth, &physheight, &desktopscale, &devicescale);
out_uint32_le(&s, physwidth); /* physicalwidth */
out_uint32_le(&s, physheight); /* physicalheight */
out_uint32_le(&s, ORIENTATION_LANDSCAPE); /* Orientation */
out_uint32_le(&s, desktopscale); /* DesktopScaleFactor */
out_uint32_le(&s, devicescale); /* DeviceScaleFactor */
s_mark_end(&s);
rdpedisp_send(&s);
}
static void
rdpedisp_init_packet(STREAM s, uint32 type, uint32 length)
{
s_realloc(s, length);
s_reset(s);
out_uint32_le(s, type);
out_uint32_le(s, length);
}
static void
rdpedisp_send(STREAM s)
{
dvc_send(RDPEDISP_CHANNEL_NAME, s);
}
RD_BOOL
rdpedisp_is_available()
{
return dvc_channels_is_available(RDPEDISP_CHANNEL_NAME);
}
void
rdpedisp_set_session_size(uint32 width, uint32 height)
{
if (rdpedisp_is_available() == False)
return;
/* monitor width MUST be even number */
utils_apply_session_size_limitations(&width, &height);
rdpedisp_send_monitor_layout_pdu(width, height);
}
void
rdpedisp_init(void)
{
dvc_channels_register(RDPEDISP_CHANNEL_NAME, rdpedisp_process_pdu);
}