2014-11-21 21:30:24 +00:00
|
|
|
/*
|
2016-03-25 19:59:40 +00:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at
|
2014-11-21 21:30:24 +00:00
|
|
|
*
|
2016-03-25 19:59:40 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2014-11-21 21:30:24 +00:00
|
|
|
*
|
2016-03-25 19:59:40 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2014-11-21 21:30:24 +00:00
|
|
|
*/
|
|
|
|
|
2014-11-21 21:51:01 +00:00
|
|
|
#include "config.h"
|
2014-11-21 21:30:24 +00:00
|
|
|
#include "client.h"
|
2016-03-01 05:50:00 +00:00
|
|
|
#include "rdp.h"
|
|
|
|
#include "rdp_disp.h"
|
2016-03-16 04:23:19 +00:00
|
|
|
#include "rdp_settings.h"
|
2014-11-21 21:30:24 +00:00
|
|
|
|
|
|
|
#include <freerdp/freerdp.h>
|
|
|
|
#include <guacamole/client.h>
|
2014-11-25 10:20:54 +00:00
|
|
|
#include <guacamole/timestamp.h>
|
2014-11-21 21:30:24 +00:00
|
|
|
|
2016-03-16 04:59:28 +00:00
|
|
|
#ifdef HAVE_FREERDP_CLIENT_DISP_H
|
|
|
|
#include <freerdp/client/disp.h>
|
|
|
|
#endif
|
|
|
|
|
2014-11-25 10:20:54 +00:00
|
|
|
guac_rdp_disp* guac_rdp_disp_alloc() {
|
2014-11-21 21:30:24 +00:00
|
|
|
|
2014-11-25 10:20:54 +00:00
|
|
|
guac_rdp_disp* disp = malloc(sizeof(guac_rdp_disp));
|
2014-11-21 21:30:24 +00:00
|
|
|
|
2016-03-16 05:11:06 +00:00
|
|
|
#ifdef HAVE_FREERDP_DISPLAY_UPDATE_SUPPORT
|
2014-11-25 10:20:54 +00:00
|
|
|
/* Not yet connected */
|
|
|
|
disp->disp = NULL;
|
2016-03-16 05:11:06 +00:00
|
|
|
#endif
|
2014-11-21 21:30:24 +00:00
|
|
|
|
2014-11-25 10:20:54 +00:00
|
|
|
/* No requests have been made */
|
2016-03-16 22:27:24 +00:00
|
|
|
disp->last_request = guac_timestamp_current();
|
2014-11-25 10:20:54 +00:00
|
|
|
disp->requested_width = 0;
|
|
|
|
disp->requested_height = 0;
|
2016-03-16 04:23:19 +00:00
|
|
|
disp->reconnect_needed = 0;
|
2014-11-21 21:30:24 +00:00
|
|
|
|
2014-11-25 10:20:54 +00:00
|
|
|
return disp;
|
2014-11-21 21:30:24 +00:00
|
|
|
|
2014-11-25 10:20:54 +00:00
|
|
|
}
|
2014-11-21 21:30:24 +00:00
|
|
|
|
2014-11-25 10:20:54 +00:00
|
|
|
void guac_rdp_disp_free(guac_rdp_disp* disp) {
|
|
|
|
free(disp);
|
2014-11-21 21:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void guac_rdp_disp_load_plugin(rdpContext* context) {
|
|
|
|
|
2016-03-16 04:23:19 +00:00
|
|
|
#ifdef HAVE_FREERDP_DISPLAY_UPDATE_SUPPORT
|
2014-11-21 21:51:01 +00:00
|
|
|
#ifdef HAVE_RDPSETTINGS_SUPPORTDISPLAYCONTROL
|
2014-11-21 21:30:24 +00:00
|
|
|
context->settings->SupportDisplayControl = TRUE;
|
2014-11-21 21:51:01 +00:00
|
|
|
#endif
|
2014-11-21 21:30:24 +00:00
|
|
|
|
|
|
|
/* Add "disp" channel */
|
|
|
|
ADDIN_ARGV* args = malloc(sizeof(ADDIN_ARGV));
|
|
|
|
args->argc = 1;
|
|
|
|
args->argv = malloc(sizeof(char**) * 1);
|
|
|
|
args->argv[0] = strdup("disp");
|
|
|
|
freerdp_dynamic_channel_collection_add(context->settings, args);
|
2016-03-16 04:23:19 +00:00
|
|
|
#endif
|
2014-11-21 21:30:24 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-03-16 05:07:38 +00:00
|
|
|
#ifdef HAVE_FREERDP_DISPLAY_UPDATE_SUPPORT
|
2014-11-25 10:20:54 +00:00
|
|
|
void guac_rdp_disp_connect(guac_rdp_disp* guac_disp, DispClientContext* disp) {
|
|
|
|
guac_disp->disp = disp;
|
|
|
|
}
|
2016-03-16 05:07:38 +00:00
|
|
|
#endif
|
2014-11-21 21:30:24 +00:00
|
|
|
|
2014-12-05 23:30:51 +00:00
|
|
|
/**
|
|
|
|
* Fits a given dimension within the allowed bounds for Display Update
|
|
|
|
* messages, adjusting the other dimension such that aspect ratio is
|
|
|
|
* maintained.
|
|
|
|
*
|
|
|
|
* @param a The dimension to fit within allowed bounds.
|
|
|
|
*
|
|
|
|
* @param b
|
|
|
|
* The other dimension to adjust if and only if necessary to preserve
|
|
|
|
* aspect ratio.
|
|
|
|
*/
|
|
|
|
static void guac_rdp_disp_fit(int* a, int* b) {
|
|
|
|
|
|
|
|
int a_value = *a;
|
|
|
|
int b_value = *b;
|
|
|
|
|
|
|
|
/* Ensure first dimension is within allowed range */
|
|
|
|
if (a_value < GUAC_RDP_DISP_MIN_SIZE) {
|
|
|
|
|
|
|
|
/* Adjust other dimension to maintain aspect ratio */
|
|
|
|
int adjusted_b = b_value * GUAC_RDP_DISP_MIN_SIZE / a_value;
|
|
|
|
if (adjusted_b > GUAC_RDP_DISP_MAX_SIZE)
|
|
|
|
adjusted_b = GUAC_RDP_DISP_MAX_SIZE;
|
|
|
|
|
|
|
|
*a = GUAC_RDP_DISP_MIN_SIZE;
|
|
|
|
*b = adjusted_b;
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (a_value > GUAC_RDP_DISP_MAX_SIZE) {
|
|
|
|
|
|
|
|
/* Adjust other dimension to maintain aspect ratio */
|
|
|
|
int adjusted_b = b_value * GUAC_RDP_DISP_MAX_SIZE / a_value;
|
|
|
|
if (adjusted_b < GUAC_RDP_DISP_MIN_SIZE)
|
|
|
|
adjusted_b = GUAC_RDP_DISP_MIN_SIZE;
|
|
|
|
|
|
|
|
*a = GUAC_RDP_DISP_MAX_SIZE;
|
|
|
|
*b = adjusted_b;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-03-16 04:23:19 +00:00
|
|
|
void guac_rdp_disp_set_size(guac_rdp_disp* disp, guac_rdp_settings* settings,
|
|
|
|
freerdp* rdp_inst, int width, int height) {
|
2014-11-25 10:20:54 +00:00
|
|
|
|
2014-12-05 23:30:51 +00:00
|
|
|
/* Fit width within bounds, adjusting height to maintain aspect ratio */
|
|
|
|
guac_rdp_disp_fit(&width, &height);
|
2014-11-25 10:20:54 +00:00
|
|
|
|
2014-12-05 23:30:51 +00:00
|
|
|
/* Fit height within bounds, adjusting width to maintain aspect ratio */
|
|
|
|
guac_rdp_disp_fit(&height, &width);
|
2014-11-25 10:20:54 +00:00
|
|
|
|
|
|
|
/* Width must be even */
|
2014-12-05 23:30:51 +00:00
|
|
|
if (width % 2 == 1)
|
2014-11-25 10:20:54 +00:00
|
|
|
width -= 1;
|
2014-11-21 21:30:24 +00:00
|
|
|
|
2014-11-25 10:20:54 +00:00
|
|
|
/* Store deferred size */
|
|
|
|
disp->requested_width = width;
|
|
|
|
disp->requested_height = height;
|
|
|
|
|
|
|
|
/* Send display update notification if possible */
|
2016-03-16 04:23:19 +00:00
|
|
|
guac_rdp_disp_update_size(disp, settings, rdp_inst);
|
2014-11-25 10:20:54 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-03-16 04:23:19 +00:00
|
|
|
void guac_rdp_disp_update_size(guac_rdp_disp* disp,
|
|
|
|
guac_rdp_settings* settings, freerdp* rdp_inst) {
|
2014-11-25 10:20:54 +00:00
|
|
|
|
2016-03-16 04:23:19 +00:00
|
|
|
int width = disp->requested_width;
|
|
|
|
int height = disp->requested_height;
|
2014-11-21 21:30:24 +00:00
|
|
|
|
2016-03-16 04:23:19 +00:00
|
|
|
/* Do not update size if no requests have been received */
|
|
|
|
if (width == 0 || height == 0)
|
2014-11-25 10:20:54 +00:00
|
|
|
return;
|
|
|
|
|
2016-03-16 04:23:19 +00:00
|
|
|
guac_timestamp now = guac_timestamp_current();
|
|
|
|
|
|
|
|
/* Limit display update frequency */
|
2016-03-16 22:27:24 +00:00
|
|
|
if (now - disp->last_request <= GUAC_RDP_DISP_UPDATE_INTERVAL)
|
2016-03-16 04:23:19 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Do NOT send requests unless the size will change */
|
|
|
|
if (rdp_inst != NULL
|
|
|
|
&& width == guac_rdp_get_width(rdp_inst)
|
|
|
|
&& height == guac_rdp_get_height(rdp_inst))
|
|
|
|
return;
|
|
|
|
|
|
|
|
disp->last_request = now;
|
|
|
|
|
2016-03-16 17:23:21 +00:00
|
|
|
if (settings->resize_method == GUAC_RESIZE_RECONNECT) {
|
|
|
|
|
2016-03-16 04:23:19 +00:00
|
|
|
/* Update settings with new dimensions */
|
|
|
|
settings->width = width;
|
|
|
|
settings->height = height;
|
2014-11-25 10:20:54 +00:00
|
|
|
|
2016-03-16 04:23:19 +00:00
|
|
|
/* Signal reconnect */
|
|
|
|
disp->reconnect_needed = 1;
|
2016-03-16 17:23:21 +00:00
|
|
|
|
2016-03-16 04:23:19 +00:00
|
|
|
}
|
|
|
|
|
2016-03-16 17:23:21 +00:00
|
|
|
else if (settings->resize_method == GUAC_RESIZE_DISPLAY_UPDATE) {
|
2016-03-16 04:23:19 +00:00
|
|
|
#ifdef HAVE_FREERDP_DISPLAY_UPDATE_SUPPORT
|
2016-03-16 17:23:21 +00:00
|
|
|
DISPLAY_CONTROL_MONITOR_LAYOUT monitors[1] = {{
|
|
|
|
.Flags = 0x1, /* DISPLAYCONTROL_MONITOR_PRIMARY */
|
|
|
|
.Left = 0,
|
|
|
|
.Top = 0,
|
|
|
|
.Width = width,
|
|
|
|
.Height = height,
|
|
|
|
.PhysicalWidth = 0,
|
|
|
|
.PhysicalHeight = 0,
|
|
|
|
.Orientation = 0,
|
|
|
|
.DesktopScaleFactor = 0,
|
|
|
|
.DeviceScaleFactor = 0
|
|
|
|
}};
|
|
|
|
|
|
|
|
/* Send display update notification if display channel is connected */
|
|
|
|
if (disp->disp != NULL)
|
|
|
|
disp->disp->SendMonitorLayout(disp->disp, 1, monitors);
|
2016-03-16 04:23:19 +00:00
|
|
|
#endif
|
2016-03-16 17:23:21 +00:00
|
|
|
}
|
2014-11-25 10:20:54 +00:00
|
|
|
|
2016-03-16 04:23:19 +00:00
|
|
|
}
|
2014-11-25 10:20:54 +00:00
|
|
|
|
2016-03-16 04:23:19 +00:00
|
|
|
int guac_rdp_disp_reconnect_needed(guac_rdp_disp* disp) {
|
|
|
|
return disp->reconnect_needed;
|
|
|
|
}
|
2014-11-21 21:30:24 +00:00
|
|
|
|
2016-03-16 04:23:19 +00:00
|
|
|
void guac_rdp_disp_reconnect_complete(guac_rdp_disp* disp) {
|
|
|
|
disp->reconnect_needed = 0;
|
2016-03-16 21:56:14 +00:00
|
|
|
disp->last_request = guac_timestamp_current();
|
2014-11-21 21:30:24 +00:00
|
|
|
}
|
|
|
|
|