Skip to content

Commit

Permalink
GUACAMOLE-1196: Remove unnecessary display size checking for VNC.
Browse files Browse the repository at this point in the history
  • Loading branch information
necouchman committed May 29, 2024
1 parent 12c98e3 commit 4177d22
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 145 deletions.
5 changes: 0 additions & 5 deletions src/protocols/vnc/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ int guac_client_init(guac_client* client) {

#ifdef ENABLE_VNC_DESKTOP_SIZE
guac_client_log(client, GUAC_LOG_DEBUG, "Support for desktop sizing enabled.");
vnc_client->vnc_display = guac_vnc_display_update_alloc(client);
#else
guac_client_log(client, GUAC_LOG_WARNING, "VNC client does not support desktop sizing.");
#endif
Expand Down Expand Up @@ -222,10 +221,6 @@ int guac_vnc_client_free_handler(guac_client* client) {
/* Clean up the message lock. */
pthread_mutex_destroy(&(vnc_client->message_lock));

#ifdef ENABLE_VNC_DESKTOP_SIZE
guac_vnc_display_update_free(vnc_client->vnc_display);
#endif

/* Free generic data struct */
guac_mem_free(client->data);

Expand Down
81 changes: 9 additions & 72 deletions src/protocols/vnc/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,89 +157,26 @@ void guac_vnc_copyrect(rfbClient* client, int src_x, int src_y, int w, int h, in

#ifdef ENABLE_VNC_DESKTOP_SIZE

guac_vnc_display* guac_vnc_display_update_alloc(guac_client* client) {
void guac_vnc_display_set_size(rfbClient* client, int width, int height) {

guac_vnc_display* display = guac_mem_alloc(sizeof(guac_vnc_display));
display->client = client;

/* No requests have been made */
display->last_request = guac_timestamp_current();
display->requested_width = 0;
display->requested_height = 0;

return display;

}

void guac_vnc_display_update_free(guac_vnc_display* display) {
guac_mem_free(display);
}

/**
* This function does the actual work of updating the display size if adequate
* time has passed since the last update and the size is actually different.
*
* @param display
* The data structure that contains information used for determing if and
* when display updates should be allowed.
*
* @param rfb_client
* A pointer to the VNC (RFB) client.
*/
static void guac_vnc_display_update_size(guac_vnc_display* display,
rfbClient* rfb_client) {

int width = display->requested_width;
int height = display->requested_height;

/* Do not update size if no requests have been received */
if (width == 0 || height == 0)
return;

guac_timestamp now = guac_timestamp_current();

/* Limit display update frequency */
if (now - display->last_request <= GUAC_COMMON_DISPLAY_UPDATE_INTERVAL)
return;

/* Do NOT send requests unless the size will change */
if (rfb_client != NULL
&& width == rfb_client->screen.width
&& height == rfb_client->screen.height)
return;

/* Send the display size update. */
guac_vnc_client* vnc_client = (guac_vnc_client*) display->client->data;
pthread_mutex_lock(&(vnc_client->message_lock));
SendExtDesktopSize(rfb_client, width, height);
display->last_request = now;
pthread_mutex_unlock(&(vnc_client->message_lock));

}

void guac_vnc_display_set_size(guac_vnc_display* display,
rfbClient* rfb_client, int width, int height) {
/* Get the VNC client */
guac_client* gc = rfbClientGetClientData(client, GUAC_VNC_CLIENT_KEY);
guac_vnc_client* vnc_client = (guac_vnc_client*) gc->data;

/* Fit width within bounds, adjusting height to maintain aspect ratio */
guac_common_display_fit(&width, &height);

/* Fit height within bounds, adjusting width to maintain aspect ratio */
guac_common_display_fit(&height, &width);

/* Width must be even */
if (width % 2 == 1)
width -= 1;

/* Store deferred size */
display->requested_width = width;
display->requested_height = height;

/* Send display update notification if possible */
guac_vnc_display_update_size(display, rfb_client);
/* Send the display size update. */
pthread_mutex_lock(&(vnc_client->message_lock));
SendExtDesktopSize(client, width, height);
pthread_mutex_unlock(&(vnc_client->message_lock));

}

#endif
#endif // ENABLE_VNC_DESKTOP_SIZE

void guac_vnc_set_pixel_format(rfbClient* client, int color_depth) {
client->format.trueColour = 1;
Expand Down
64 changes: 3 additions & 61 deletions src/protocols/vnc/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,6 @@
#include <rfb/rfbclient.h>
#include <rfb/rfbproto.h>

/**
* Display size update module for VNC.
*/
typedef struct guac_vnc_display {

/**
* The guac_client instance handling the relevant VNC connection.
*/
guac_client* client;

/**
* The timestamp of the last display update request, or 0 if no request
* has been sent yet.
*/
guac_timestamp last_request;

/**
* The last requested screen width, in pixels.
*/
int requested_width;

/**
* The last requested screen height, in pixels.
*/
int requested_height;

} guac_vnc_display;

/**
* Callback invoked by libVNCServer when it receives a new binary image data
* from the VNC server. The image itself will be stored in the designated sub-
Expand Down Expand Up @@ -114,53 +86,23 @@ void guac_vnc_copyrect(rfbClient* client, int src_x, int src_y, int w, int h,

#ifdef ENABLE_VNC_DESKTOP_SIZE

/**
* Allocates a new VNC display update module, which will keep track of the data
* needed to handle display updates.
*
* @param client
* The guac_client instance handling the relevant VNC connection.
*
* @return
* A newly-allocated VNC display update module.
*/
guac_vnc_display* guac_vnc_display_update_alloc(guac_client* client);

/**
* Frees the resources associated with the data structure that keeps track of
* items related to VNC display updates. Only resources specific to Guacamole
* are freed. Resources that are part of the rfbClient will be freed separately.
* If no resources are currently allocated for Display Update support, this
* function has no effect.
*
* @param display
* The display update module to free.
*/
void guac_vnc_display_update_free(guac_vnc_display* display);

/**
* Attempts to set the display size of the remote server to the size requested
* by the client, usually as part of a client (browser) resize, if supported by
* both the VNC client and the remote server.
*
* @param display
* The VNC display update object that tracks information related to display
* update requests.
*
* @param rfb_client
* The data structure containing the VNC client that is used by this
* connection.
* The VNC client to which the display size update should be sent.
*
* @param width
* The width that is being requested, in pixels.
*
* @param height
* The height that is being requested, in pixels.
*/
void guac_vnc_display_set_size(guac_vnc_display* display, rfbClient* rfb_client,
int width, int height);
void guac_vnc_display_set_size(rfbClient* client, int width, int height);

#endif
#endif // ENABLE_VNC_DESKTOP_SIZE

/**
* Sets the pixel format to request of the VNC server. The request will be made
Expand Down
4 changes: 2 additions & 2 deletions src/protocols/vnc/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ int guac_vnc_user_key_handler(guac_user* user, int keysym, int pressed) {

int guac_vnc_user_size_handler(guac_user* user, int width, int height) {

/* Get the Guacamole VNC client */
guac_vnc_client* vnc_client = (guac_vnc_client*) user->client->data;
rfbClient* rfb_client = vnc_client->rfb_client;

/* Send display update */
guac_vnc_display_set_size(vnc_client->vnc_display, rfb_client, width, height);
guac_vnc_display_set_size(vnc_client->rfb_client, width, height);

return 0;

Expand Down
5 changes: 0 additions & 5 deletions src/protocols/vnc/vnc.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,6 @@ typedef struct guac_vnc_client {
*/
guac_iconv_write* clipboard_writer;

/**
* VNC display update module.
*/
guac_vnc_display* vnc_display;

} guac_vnc_client;

/**
Expand Down

0 comments on commit 4177d22

Please sign in to comment.