FreeRDP
display.c
1 
20 #include "display.h"
21 
22 static BOOL display_write_monitor_layout_pdu(wStream* s, UINT32 monitorCount,
23  const MONITOR_DEF* monitorDefArray)
24 {
25  if (!Stream_EnsureRemainingCapacity(s, 4 + (monitorCount * 20)))
26  return FALSE;
27 
28  Stream_Write_UINT32(s, monitorCount); /* monitorCount (4 bytes) */
29 
30  for (UINT32 index = 0; index < monitorCount; index++)
31  {
32  const MONITOR_DEF* monitor = &monitorDefArray[index];
33 
34  Stream_Write_INT32(s, monitor->left); /* left (4 bytes) */
35  Stream_Write_INT32(s, monitor->top); /* top (4 bytes) */
36  Stream_Write_INT32(s, monitor->right); /* right (4 bytes) */
37  Stream_Write_INT32(s, monitor->bottom); /* bottom (4 bytes) */
38  Stream_Write_UINT32(s, monitor->flags); /* flags (4 bytes) */
39  }
40 
41  return TRUE;
42 }
43 
44 BOOL display_convert_rdp_monitor_to_monitor_def(UINT32 monitorCount,
45  const rdpMonitor* monitorDefArray,
46  MONITOR_DEF** result)
47 {
48  MONITOR_DEF* mdef = NULL;
49 
50  if (!monitorDefArray || !result || (*result))
51  return FALSE;
52 
53  mdef = (MONITOR_DEF*)calloc(monitorCount, sizeof(MONITOR_DEF));
54 
55  if (!mdef)
56  return FALSE;
57 
58  for (UINT32 index = 0; index < monitorCount; index++)
59  {
60  const rdpMonitor* monitor = &monitorDefArray[index];
61  MONITOR_DEF* current = &mdef[index];
62 
63  current->left = monitor->x; /* left (4 bytes) */
64  current->top = monitor->y; /* top (4 bytes) */
65  current->right = monitor->x + monitor->width - 1; /* right (4 bytes) */
66  current->bottom = monitor->y + monitor->height - 1; /* bottom (4 bytes) */
67  current->flags = monitor->is_primary ? MONITOR_PRIMARY : 0x0; /* flags (4 bytes) */
68  }
69 
70  *result = mdef;
71  return TRUE;
72 }
73 
74 BOOL freerdp_display_send_monitor_layout(rdpContext* context, UINT32 monitorCount,
75  const MONITOR_DEF* monitorDefArray)
76 {
77  rdpRdp* rdp = context->rdp;
78  wStream* st = rdp_data_pdu_init(rdp);
79 
80  if (!st)
81  return FALSE;
82 
83  if (!display_write_monitor_layout_pdu(st, monitorCount, monitorDefArray))
84  {
85  Stream_Release(st);
86  return FALSE;
87  }
88 
89  return rdp_send_data_pdu(rdp, st, DATA_PDU_TYPE_MONITOR_LAYOUT, 0);
90 }