23#include <freerdp/config.h>
30#include <winpr/assert.h>
31#include <winpr/synch.h>
32#include <winpr/print.h>
33#include <winpr/thread.h>
34#include <winpr/stream.h>
35#include <winpr/sysinfo.h>
36#include <winpr/cmdline.h>
37#include <winpr/collections.h>
39#include <freerdp/addin.h>
40#include <freerdp/utils/string.h>
41#include <freerdp/client/channels.h>
44#include "../disp_common.h"
50 DispClientContext* context;
51 UINT32 MaxNumMonitors;
52 UINT32 MaxMonitorAreaFactorA;
53 UINT32 MaxMonitorAreaFactorB;
67 DISP_PLUGIN* disp = NULL;
68 UINT32 MonitorLayoutSize = 0;
71 WINPR_ASSERT(callback);
72 WINPR_ASSERT(Monitors || (NumMonitors == 0));
74 disp = (DISP_PLUGIN*)callback->plugin;
77 MonitorLayoutSize = DISPLAY_CONTROL_MONITOR_LAYOUT_SIZE;
78 header.length = 8 + 8 + (NumMonitors * MonitorLayoutSize);
79 header.type = DISPLAY_CONTROL_PDU_TYPE_MONITOR_LAYOUT;
81 s = Stream_New(NULL, header.length);
85 WLog_ERR(TAG,
"Stream_New failed!");
86 return CHANNEL_RC_NO_MEMORY;
89 if ((status = disp_write_header(s, &header)))
91 WLog_ERR(TAG,
"Failed to write header with error %" PRIu32
"!", status);
95 if (NumMonitors > disp->MaxNumMonitors)
96 NumMonitors = disp->MaxNumMonitors;
98 Stream_Write_UINT32(s, MonitorLayoutSize);
99 Stream_Write_UINT32(s, NumMonitors);
100 WLog_DBG(TAG,
"NumMonitors=%" PRIu32
"", NumMonitors);
102 for (UINT32 index = 0; index < NumMonitors; index++)
105 current.Width -= (current.Width % 2);
107 if (current.Width < 200)
110 if (current.Width > 8192)
111 current.Width = 8192;
113 if (current.Width % 2)
116 if (current.Height < 200)
117 current.Height = 200;
119 if (current.Height > 8192)
120 current.Height = 8192;
122 Stream_Write_UINT32(s, current.Flags);
123 Stream_Write_INT32(s, current.Left);
124 Stream_Write_INT32(s, current.Top);
125 Stream_Write_UINT32(s, current.Width);
126 Stream_Write_UINT32(s, current.Height);
127 Stream_Write_UINT32(s, current.PhysicalWidth);
128 Stream_Write_UINT32(s, current.PhysicalHeight);
129 Stream_Write_UINT32(s, current.Orientation);
130 Stream_Write_UINT32(s, current.DesktopScaleFactor);
131 Stream_Write_UINT32(s, current.DeviceScaleFactor);
133 "\t%" PRIu32
" : Flags: 0x%08" PRIX32
" Left/Top: (%" PRId32
",%" PRId32
134 ") W/H=%" PRIu32
"x%" PRIu32
")",
135 index, current.Flags, current.Left, current.Top, current.Width, current.Height);
137 "\t PhysicalWidth: %" PRIu32
" PhysicalHeight: %" PRIu32
138 " Orientation: %s DesktopScaleFactor=%" PRIu32
" DeviceScaleFactor=%" PRIu32
"",
139 current.PhysicalWidth, current.PhysicalHeight,
140 freerdp_desktop_rotation_flags_to_string(current.Orientation),
141 current.DesktopScaleFactor, current.DeviceScaleFactor);
145 Stream_SealLength(s);
146 status = callback->channel->Write(callback->channel, (UINT32)Stream_Length(s), Stream_Buffer(s),
148 Stream_Free(s, TRUE);
159 DISP_PLUGIN* disp = NULL;
160 DispClientContext* context = NULL;
161 UINT ret = CHANNEL_RC_OK;
163 WINPR_ASSERT(callback);
166 disp = (DISP_PLUGIN*)callback->plugin;
169 context = disp->context;
170 WINPR_ASSERT(context);
172 if (!Stream_CheckAndLogRequiredLength(TAG, s, 12))
173 return ERROR_INVALID_DATA;
175 Stream_Read_UINT32(s, disp->MaxNumMonitors);
176 Stream_Read_UINT32(s, disp->MaxMonitorAreaFactorA);
177 Stream_Read_UINT32(s, disp->MaxMonitorAreaFactorB);
179 if (context->DisplayControlCaps)
180 ret = context->DisplayControlCaps(context, disp->MaxNumMonitors,
181 disp->MaxMonitorAreaFactorA, disp->MaxMonitorAreaFactorB);
196 WINPR_ASSERT(callback);
199 if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
200 return ERROR_INVALID_DATA;
202 if ((error = disp_read_header(s, &header)))
204 WLog_ERR(TAG,
"disp_read_header failed with error %" PRIu32
"!", error);
208 if (!Stream_EnsureRemainingCapacity(s, header.length))
210 WLog_ERR(TAG,
"not enough remaining data");
211 return ERROR_INVALID_DATA;
216 case DISPLAY_CONTROL_PDU_TYPE_CAPS:
217 return disp_recv_display_control_caps_pdu(callback, s);
220 WLog_ERR(TAG,
"Type %" PRIu32
" not recognized!", header.type);
221 return ERROR_INTERNAL_ERROR;
230static UINT disp_on_data_received(IWTSVirtualChannelCallback* pChannelCallback,
wStream* data)
233 return disp_recv_pdu(callback, data);
241static UINT disp_on_close(IWTSVirtualChannelCallback* pChannelCallback)
243 free(pChannelCallback);
244 return CHANNEL_RC_OK;
256static UINT disp_send_monitor_layout(DispClientContext* context, UINT32 NumMonitors,
259 DISP_PLUGIN* disp = NULL;
262 WINPR_ASSERT(context);
264 disp = (DISP_PLUGIN*)context->handle;
267 callback = disp->base.listener_callback->channel_callback;
269 return disp_send_display_control_monitor_layout_pdu(callback, NumMonitors, Monitors);
278 WINPR_ATTR_UNUSED rdpContext* rcontext,
279 WINPR_ATTR_UNUSED rdpSettings* settings)
281 DispClientContext* context = NULL;
282 DISP_PLUGIN* disp = (DISP_PLUGIN*)base;
285 disp->MaxNumMonitors = 16;
286 disp->MaxMonitorAreaFactorA = 8192;
287 disp->MaxMonitorAreaFactorB = 8192;
289 context = (DispClientContext*)calloc(1,
sizeof(DispClientContext));
292 WLog_Print(base->log, WLOG_ERROR,
"unable to allocate DispClientContext");
293 return CHANNEL_RC_NO_MEMORY;
296 context->handle = (
void*)disp;
297 context->SendMonitorLayout = disp_send_monitor_layout;
299 disp->base.iface.pInterface = disp->context = context;
301 return CHANNEL_RC_OK;
306 DISP_PLUGIN* disp = (DISP_PLUGIN*)base;
313static const IWTSVirtualChannelCallback disp_callbacks = { disp_on_data_received, NULL,
314 disp_on_close, NULL };
321FREERDP_ENTRY_POINT(UINT VCAPITYPE disp_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints))
323 return freerdp_generic_DVCPluginEntry(pEntryPoints, TAG, DISP_DVC_CHANNEL_NAME,
325 &disp_callbacks, disp_plugin_initialize,
326 disp_plugin_terminated);