GUAC-947: Maintain aspect ratio when size is adjusted to conform with Display Update specs.
This commit is contained in:
parent
cbab9e2efb
commit
37276c081b
@ -67,29 +67,61 @@ void guac_rdp_disp_connect(guac_rdp_disp* guac_disp, DispClientContext* disp) {
|
|||||||
guac_disp->disp = disp;
|
guac_disp->disp = disp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void guac_rdp_disp_set_size(guac_rdp_disp* disp, rdpContext* context,
|
void guac_rdp_disp_set_size(guac_rdp_disp* disp, rdpContext* context,
|
||||||
int width, int height) {
|
int width, int height) {
|
||||||
|
|
||||||
/* Width must be at least 200 pixels */
|
/* Fit width within bounds, adjusting height to maintain aspect ratio */
|
||||||
if (width < 200)
|
guac_rdp_disp_fit(&width, &height);
|
||||||
width = 200;
|
|
||||||
|
|
||||||
/* Width may be no more than 8192 pixels */
|
/* Fit height within bounds, adjusting width to maintain aspect ratio */
|
||||||
else if (width > 8192)
|
guac_rdp_disp_fit(&height, &width);
|
||||||
width = 8192;
|
|
||||||
|
|
||||||
/* Width must be even */
|
/* Width must be even */
|
||||||
else if (width % 2 == 1)
|
if (width % 2 == 1)
|
||||||
width -= 1;
|
width -= 1;
|
||||||
|
|
||||||
/* Height must be at least 200 pixels */
|
|
||||||
if (height < 200)
|
|
||||||
height = 200;
|
|
||||||
|
|
||||||
/* Height may be no more than 8192 pixels */
|
|
||||||
else if (height > 8192)
|
|
||||||
height = 8192;
|
|
||||||
|
|
||||||
/* Store deferred size */
|
/* Store deferred size */
|
||||||
disp->requested_width = width;
|
disp->requested_width = width;
|
||||||
disp->requested_height = height;
|
disp->requested_height = height;
|
||||||
|
@ -26,6 +26,15 @@
|
|||||||
#include <freerdp/client/disp.h>
|
#include <freerdp/client/disp.h>
|
||||||
#include <freerdp/freerdp.h>
|
#include <freerdp/freerdp.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The minimum value for width or height, in pixels.
|
||||||
|
*/
|
||||||
|
#define GUAC_RDP_DISP_MIN_SIZE 200
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The maximum value for width or height, in pixels.
|
||||||
|
*/
|
||||||
|
#define GUAC_RDP_DISP_MAX_SIZE 8192
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The minimum amount of time that must elapse between display size updates,
|
* The minimum amount of time that must elapse between display size updates,
|
||||||
|
Loading…
Reference in New Issue
Block a user