From a14e0fa3fb62ed66e3799f542de54b7c8f0d932f Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 14 Mar 2016 15:15:32 -0700 Subject: [PATCH] GUAC-1389: Redraw / resync terminal contents. --- src/terminal/display.c | 12 ++++++++++++ src/terminal/display.h | 17 +++++++++++++++++ src/terminal/terminal.c | 18 +++++++++++++----- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/terminal/display.c b/src/terminal/display.c index ebb69f73..52561c6c 100644 --- a/src/terminal/display.c +++ b/src/terminal/display.c @@ -845,6 +845,18 @@ void guac_terminal_display_flush(guac_terminal_display* display) { } +void guac_terminal_display_dup(guac_terminal_display* display, guac_user* user, + guac_socket* socket) { + + /* Create default surface */ + guac_common_surface_dup(display->display_surface, user, socket); + + /* Select layer is a child of the display layer */ + guac_protocol_send_move(socket, display->select_layer, + display->display_layer, 0, 0, 0); + +} + void guac_terminal_display_commit_select(guac_terminal_display* display) { display->selection_committed = true; } diff --git a/src/terminal/display.h b/src/terminal/display.h index d42d99bd..b11c0509 100644 --- a/src/terminal/display.h +++ b/src/terminal/display.h @@ -333,6 +333,23 @@ void guac_terminal_display_resize(guac_terminal_display* display, int width, int */ void guac_terminal_display_flush(guac_terminal_display* display); +/** + * Initializes and syncs the current terminal display state for the given user + * that has just joined the connection, sending the necessary instructions to + * completely recreate and redraw the terminal rendering over the given socket. + * + * @param display + * The terminal display to sync to the given user. + * + * @param user + * The user that has just joined the connection. + * + * @param socket + * The socket over which any necessary instructions should be sent. + */ +void guac_terminal_display_dup(guac_terminal_display* display, guac_user* user, + guac_socket* socket); + /** * Draws the text selection rectangle from the given coordinates to the given end coordinates. */ diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index 1a2fb43a..63df4aec 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -200,6 +200,10 @@ void guac_terminal_reset(guac_terminal* term) { * @param terminal * The terminal whose background should be painted or repainted. * + * @param socket + * The socket over which instructions required to paint / repaint the + * terminal background should be send. + * * @param width * The width of the background to draw, in pixels. * @@ -207,11 +211,9 @@ void guac_terminal_reset(guac_terminal* term) { * The height of the background to draw, in pixels. */ static void guac_terminal_paint_background(guac_terminal* terminal, - int width, int height) { + guac_socket* socket, int width, int height) { guac_terminal_display* display = terminal->term_display; - guac_client* client = display->client; - guac_socket* socket = client->socket; /* Get background color */ const guac_terminal_color* color = @@ -371,7 +373,7 @@ guac_terminal* guac_terminal_create(guac_client* client, pthread_mutex_init(&(term->lock), NULL); /* Size display */ - guac_terminal_paint_background(term, width, height); + guac_terminal_paint_background(term, client->socket, width, height); guac_terminal_display_resize(term->term_display, term->term_width, term->term_height); @@ -1369,7 +1371,7 @@ int guac_terminal_resize(guac_terminal* terminal, int width, int height) { /* Resize default layer to given pixel dimensions */ guac_common_surface_resize(terminal->display->default_surface, width, height); - guac_terminal_paint_background(terminal, width, height); + guac_terminal_paint_background(terminal, client->socket, width, height); /* Notify scrollbar of resize */ guac_terminal_scrollbar_parent_resized(terminal->scrollbar, width, height, rows); @@ -1910,7 +1912,13 @@ void guac_terminal_add_user(guac_terminal* term, guac_user* user, /* Synchronize display state with new user */ guac_common_display_dup(term->display, user, socket); + guac_terminal_display_dup(term->term_display, user, socket); guac_terminal_scrollbar_dup(term->scrollbar, user, socket); + /* Paint background for joining user */ + guac_common_surface* default_surface = term->display->default_surface; + guac_terminal_paint_background(term, socket, default_surface->width, + default_surface->height); + }