| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include "frdp-channel-display-control.h" |
| 20 |
|
| 21 |
#include <freerdp/freerdp.h> |
| 22 |
#include <freerdp/client/disp.h> |
| 23 |
|
| 24 |
typedef struct |
| 25 |
{ |
| 26 |
DispClientContext *display_client_context; |
| 27 |
|
| 28 |
guint32 max_num_monitors; |
| 29 |
guint32 max_monitor_area_factor_a; |
| 30 |
guint32 max_monitor_area_factor_b; |
| 31 |
|
| 32 |
gboolean caps_set; |
| 33 |
} FrdpChannelDisplayControlPrivate; |
| 34 |
|
| 35 |
G_DEFINE_TYPE_WITH_PRIVATE (FrdpChannelDisplayControl, frdp_channel_display_control, FRDP_TYPE_CHANNEL) |
| 36 |
|
| 37 |
enum |
| 38 |
{ |
| 39 |
PROP_0 = 0, |
| 40 |
PROP_DISPLAY_CLIENT_CONTEXT, |
| 41 |
PROP_MAX_NUM_MONITORS, |
| 42 |
PROP_MAX_MONITOR_AREA_FACTOR_A, |
| 43 |
PROP_MAX_MONITOR_AREA_FACTOR_B, |
| 44 |
LAST_PROP |
| 45 |
}; |
| 46 |
|
| 47 |
enum |
| 48 |
{ |
| 49 |
CAPS_SET, |
| 50 |
LAST_SIGNAL |
| 51 |
}; |
| 52 |
|
| 53 |
static guint signals[LAST_SIGNAL]; |
| 54 |
|
| 55 |
static void frdp_channel_display_control_set_client_context (FrdpChannelDisplayControl *self, |
| 56 |
DispClientContext *context); |
| 57 |
|
| 58 |
static void |
| 59 |
frdp_channel_display_control_get_property (GObject *object, |
| 60 |
guint property_id, |
| 61 |
GValue *value, |
| 62 |
GParamSpec *pspec) |
| 63 |
{ |
| 64 |
FrdpChannelDisplayControl *self = FRDP_CHANNEL_DISPLAY_CONTROL (object); |
| 65 |
FrdpChannelDisplayControlPrivate *priv = frdp_channel_display_control_get_instance_private (self); |
| 66 |
|
| 67 |
switch (property_id) |
| 68 |
{ |
| 69 |
case PROP_DISPLAY_CLIENT_CONTEXT: |
| 70 |
g_value_set_pointer (value, priv->display_client_context); |
| 71 |
break; |
| 72 |
case PROP_MAX_NUM_MONITORS: |
| 73 |
g_value_set_uint (value, priv->max_num_monitors); |
| 74 |
break; |
| 75 |
case PROP_MAX_MONITOR_AREA_FACTOR_A: |
| 76 |
g_value_set_uint (value, priv->max_monitor_area_factor_a); |
| 77 |
break; |
| 78 |
case PROP_MAX_MONITOR_AREA_FACTOR_B: |
| 79 |
g_value_set_uint (value, priv->max_monitor_area_factor_b); |
| 80 |
break; |
| 81 |
default: |
| 82 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); |
| 83 |
break; |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
static void |
| 88 |
frdp_channel_display_control_set_property (GObject *object, |
| 89 |
guint property_id, |
| 90 |
const GValue *value, |
| 91 |
GParamSpec *pspec) |
| 92 |
{ |
| 93 |
FrdpChannelDisplayControl *self = FRDP_CHANNEL_DISPLAY_CONTROL (object); |
| 94 |
FrdpChannelDisplayControlPrivate *priv = frdp_channel_display_control_get_instance_private (self); |
| 95 |
|
| 96 |
switch (property_id) |
| 97 |
{ |
| 98 |
case PROP_DISPLAY_CLIENT_CONTEXT: |
| 99 |
frdp_channel_display_control_set_client_context (self, g_value_get_pointer (value)); |
| 100 |
break; |
| 101 |
case PROP_MAX_NUM_MONITORS: |
| 102 |
priv->max_num_monitors = g_value_get_uint (value); |
| 103 |
break; |
| 104 |
case PROP_MAX_MONITOR_AREA_FACTOR_A: |
| 105 |
priv->max_monitor_area_factor_a = g_value_get_uint (value); |
| 106 |
break; |
| 107 |
case PROP_MAX_MONITOR_AREA_FACTOR_B: |
| 108 |
priv->max_monitor_area_factor_b = g_value_get_uint (value); |
| 109 |
break; |
| 110 |
default: |
| 111 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); |
| 112 |
break; |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
static void |
| 117 |
frdp_channel_display_control_class_init (FrdpChannelDisplayControlClass *klass) |
| 118 |
{ |
| 119 |
GObjectClass *gobject_class = G_OBJECT_CLASS (klass); |
| 120 |
|
| 121 |
gobject_class->get_property = frdp_channel_display_control_get_property; |
| 122 |
gobject_class->set_property = frdp_channel_display_control_set_property; |
| 123 |
|
| 124 |
g_object_class_install_property (gobject_class, |
| 125 |
PROP_DISPLAY_CLIENT_CONTEXT, |
| 126 |
g_param_spec_pointer ("display-client-context", |
| 127 |
"display-client-context", |
| 128 |
"Context for display client", |
| 129 |
G_PARAM_READWRITE)); |
| 130 |
|
| 131 |
g_object_class_install_property (gobject_class, |
| 132 |
PROP_MAX_NUM_MONITORS, |
| 133 |
g_param_spec_uint ("max-num-monitors", |
| 134 |
"max-num-monitors", |
| 135 |
"Maximum number of monitors supported by the server", |
| 136 |
0, |
| 137 |
UINT_MAX, |
| 138 |
16, |
| 139 |
G_PARAM_READWRITE)); |
| 140 |
|
| 141 |
g_object_class_install_property (gobject_class, |
| 142 |
PROP_MAX_MONITOR_AREA_FACTOR_A, |
| 143 |
g_param_spec_uint ("max-monitor-area-factor-a", |
| 144 |
"max-monitor-area-factor-a", |
| 145 |
"Maximum monitor area factor A", |
| 146 |
0, |
| 147 |
UINT_MAX, |
| 148 |
8192, |
| 149 |
G_PARAM_READWRITE)); |
| 150 |
|
| 151 |
g_object_class_install_property (gobject_class, |
| 152 |
PROP_MAX_MONITOR_AREA_FACTOR_B, |
| 153 |
g_param_spec_uint ("max-monitor-area-factor-b", |
| 154 |
"max-monitor-area-factor-b", |
| 155 |
"Maximum monitor area factor B", |
| 156 |
0, |
| 157 |
UINT_MAX, |
| 158 |
8192, |
| 159 |
G_PARAM_READWRITE)); |
| 160 |
|
| 161 |
signals[CAPS_SET] = g_signal_new ("caps-set", |
| 162 |
G_TYPE_FROM_CLASS (klass), |
| 163 |
G_SIGNAL_RUN_LAST, |
| 164 |
0, NULL, NULL, NULL, |
| 165 |
G_TYPE_NONE, 0); |
| 166 |
} |
| 167 |
|
| 168 |
static void |
| 169 |
frdp_channel_display_control_init (FrdpChannelDisplayControl *self) |
| 170 |
{ |
| 171 |
} |
| 172 |
|
| 173 |
static guint |
| 174 |
display_control_caps (DispClientContext *context, |
| 175 |
guint32 max_num_monitors, |
| 176 |
guint32 max_monitor_area_factor_a, |
| 177 |
guint32 max_monitor_area_factor_b) |
| 178 |
{ |
| 179 |
FrdpChannelDisplayControlPrivate *priv; |
| 180 |
FrdpChannelDisplayControl *channel; |
| 181 |
|
| 182 |
if (context != NULL) { |
| 183 |
channel = (FrdpChannelDisplayControl *) context->custom; |
| 184 |
priv = frdp_channel_display_control_get_instance_private (channel); |
| 185 |
|
| 186 |
g_object_set (G_OBJECT (channel), |
| 187 |
"max-num-monitors", max_num_monitors, |
| 188 |
"max-monitor-area-factor-a", max_monitor_area_factor_a, |
| 189 |
"max-monitor-area-factor-b", max_monitor_area_factor_b, |
| 190 |
NULL); |
| 191 |
|
| 192 |
priv->caps_set = TRUE; |
| 193 |
g_signal_emit (channel, signals[CAPS_SET], 0); |
| 194 |
} |
| 195 |
|
| 196 |
return CHANNEL_RC_OK; |
| 197 |
} |
| 198 |
|
| 199 |
static void |
| 200 |
frdp_channel_display_control_set_client_context (FrdpChannelDisplayControl *self, |
| 201 |
DispClientContext *context) |
| 202 |
{ |
| 203 |
FrdpChannelDisplayControlPrivate *priv = frdp_channel_display_control_get_instance_private (self); |
| 204 |
|
| 205 |
priv->display_client_context = context; |
| 206 |
context->custom = self; |
| 207 |
context->DisplayControlCaps = display_control_caps; |
| 208 |
} |
| 209 |
|
| 210 |
void |
| 211 |
frdp_channel_display_control_resize_display (FrdpChannelDisplayControl *self, |
| 212 |
guint width, |
| 213 |
guint height) |
| 214 |
{ |
| 215 |
FrdpChannelDisplayControlPrivate *priv = frdp_channel_display_control_get_instance_private (self); |
| 216 |
DISPLAY_CONTROL_MONITOR_LAYOUT monitor_layout = {}; |
| 217 |
guint32 request_width, request_height; |
| 218 |
guint ret_value; |
| 219 |
|
| 220 |
request_width = CLAMP (width, |
| 221 |
DISPLAY_CONTROL_MIN_MONITOR_WIDTH, |
| 222 |
DISPLAY_CONTROL_MAX_MONITOR_WIDTH); |
| 223 |
|
| 224 |
request_height = CLAMP (height, |
| 225 |
DISPLAY_CONTROL_MIN_MONITOR_WIDTH, |
| 226 |
DISPLAY_CONTROL_MAX_MONITOR_WIDTH); |
| 227 |
|
| 228 |
if (request_width % 2 == 1) |
| 229 |
request_width--; |
| 230 |
|
| 231 |
if (priv->display_client_context != NULL && |
| 232 |
priv->caps_set && |
| 233 |
(request_width * request_height) <= (priv->max_num_monitors * priv->max_monitor_area_factor_a * priv->max_monitor_area_factor_b)) { |
| 234 |
|
| 235 |
monitor_layout.Flags = DISPLAY_CONTROL_MONITOR_PRIMARY; |
| 236 |
monitor_layout.Width = request_width; |
| 237 |
monitor_layout.Height = request_height; |
| 238 |
monitor_layout.Orientation = ORIENTATION_LANDSCAPE; |
| 239 |
monitor_layout.DesktopScaleFactor = 100; |
| 240 |
monitor_layout.DeviceScaleFactor = 100; |
| 241 |
|
| 242 |
ret_value = priv->display_client_context->SendMonitorLayout (priv->display_client_context, 1, &monitor_layout); |
| 243 |
if (ret_value != CHANNEL_RC_OK) |
| 244 |
g_warning ("Changing of monitor layout failed with Win32 error code 0x%X", ret_value); |
| 245 |
} else { |
| 246 |
if (priv->display_client_context == NULL) |
| 247 |
g_warning ("DispClientContext has not been set yet!"); |
| 248 |
|
| 249 |
if (!priv->caps_set) |
| 250 |
g_warning ("DisplayControlCaps() has not been called yet!"); |
| 251 |
|
| 252 |
if ((request_width * request_height) > (priv->max_num_monitors * priv->max_monitor_area_factor_a * priv->max_monitor_area_factor_b)) |
| 253 |
g_warning ("Requested display area is larger than allowed maximum area!"); |
| 254 |
} |
| 255 |
} |