/** * Moves the handle layer of the scrollbar to the position indicated within the * given scrollbar render state, sending any necessary Guacamole instructions * over the given socket. The handle is the portion of the scrollbar that * indicates the current scroll value and which the user can click and drag to * change the value. * * @param scrollbar * The scrollbar associated with the handle being repositioned. * * @param state * The guac_terminal_scrollbar_render_state describing the new scrollbar * handle position. * * @param socket * The guac_socket over which any instructions necessary to perform the * render operation should be sent. */ static void guac_terminal_scrollbar_move_handle( guac_terminal_scrollbar* scrollbar, guac_terminal_scrollbar_render_state* state, guac_socket* socket) { /* Send handle position */ guac_protocol_send_move(socket, scrollbar->handle, scrollbar->container, state->handle_x, state->handle_y, 0); }
/** * Moves the main scrollbar layer to the position indicated within the given * scrollbar render state, sending any necessary Guacamole instructions over * the given socket. * * @param scrollbar * The scrollbar to reposition. * * @param state * The guac_terminal_scrollbar_render_state describing the new scrollbar * position. * * @param socket * The guac_socket over which any instructions necessary to perform the * render operation should be sent. */ static void guac_terminal_scrollbar_move_container( guac_terminal_scrollbar* scrollbar, guac_terminal_scrollbar_render_state* state, guac_socket* socket) { /* Send scrollbar position */ guac_protocol_send_move(socket, scrollbar->container, scrollbar->parent, state->container_x, state->container_y, 0); }
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); /* Send select layer size */ guac_protocol_send_size(socket, display->select_layer, display->char_width * display->width, display->char_height * display->height); }
void guac_terminal_scrollbar_flush(guac_terminal_scrollbar* scrollbar) { guac_socket* socket = scrollbar->client->socket; /* Get old state */ int old_value = scrollbar->value; guac_terminal_scrollbar_render_state* old_state = &scrollbar->render_state; /* Calculate new state */ int new_value; guac_terminal_scrollbar_render_state new_state; calculate_state(scrollbar, &new_state, &new_value); /* Notify of scroll if value is changing */ if (new_value != old_value && scrollbar->scroll_handler) scrollbar->scroll_handler(scrollbar, new_value); /* Reposition container if moved */ if (old_state->container_x != new_state.container_x || old_state->container_y != new_state.container_y) { guac_protocol_send_move(socket, scrollbar->container, scrollbar->parent, new_state.container_x, new_state.container_y, 0); } /* Resize and redraw container if size changed */ if (old_state->container_width != new_state.container_width || old_state->container_height != new_state.container_height) { /* Set new size */ guac_protocol_send_size(socket, scrollbar->container, new_state.container_width, new_state.container_height); /* Fill container with solid color */ guac_protocol_send_rect(socket, scrollbar->container, 0, 0, new_state.container_width, new_state.container_height); guac_protocol_send_cfill(socket, GUAC_COMP_SRC, scrollbar->container, 0x40, 0x40, 0x40, 0xFF); } /* Reposition handle if moved */ if (old_state->handle_x != new_state.handle_x || old_state->handle_y != new_state.handle_y) { guac_protocol_send_move(socket, scrollbar->handle, scrollbar->container, new_state.handle_x, new_state.handle_y, 0); } /* Resize and redraw handle if size changed */ if (old_state->handle_width != new_state.handle_width || old_state->handle_height != new_state.handle_height) { /* Send new size */ guac_protocol_send_size(socket, scrollbar->handle, new_state.handle_width, new_state.handle_height); /* Fill and stroke handle with solid color */ guac_protocol_send_rect(socket, scrollbar->handle, 0, 0, new_state.handle_width, new_state.handle_height); guac_protocol_send_cfill(socket, GUAC_COMP_SRC, scrollbar->handle, 0x80, 0x80, 0x80, 0xFF); guac_protocol_send_cstroke(socket, GUAC_COMP_OVER, scrollbar->handle, GUAC_LINE_CAP_SQUARE, GUAC_LINE_JOIN_MITER, 2, 0xA0, 0xA0, 0xA0, 0xFF); } /* Store current render state */ scrollbar->render_state = new_state; }
guac_terminal_display* guac_terminal_display_alloc(guac_client* client, const char* font_name, int font_size, int dpi, int foreground, int background) { PangoFontMap* font_map; PangoFont* font; PangoFontMetrics* metrics; PangoContext* context; /* Allocate display */ guac_terminal_display* display = malloc(sizeof(guac_terminal_display)); display->client = client; /* Create default surface */ display->display_layer = guac_client_alloc_layer(client); display->select_layer = guac_client_alloc_layer(client); display->display_surface = guac_common_surface_alloc(client, client->socket, display->display_layer, 0, 0); /* Select layer is a child of the display layer */ guac_protocol_send_move(client->socket, display->select_layer, display->display_layer, 0, 0, 0); /* Get font */ display->font_desc = pango_font_description_new(); pango_font_description_set_family(display->font_desc, font_name); pango_font_description_set_weight(display->font_desc, PANGO_WEIGHT_NORMAL); pango_font_description_set_size(display->font_desc, font_size * PANGO_SCALE * dpi / 96); font_map = pango_cairo_font_map_get_default(); context = pango_font_map_create_context(font_map); font = pango_font_map_load_font(font_map, context, display->font_desc); if (font == NULL) { guac_client_abort(display->client, GUAC_PROTOCOL_STATUS_SERVER_ERROR, "Unable to get font \"%s\"", font_name); return NULL; } metrics = pango_font_get_metrics(font, NULL); if (metrics == NULL) { guac_client_abort(display->client, GUAC_PROTOCOL_STATUS_SERVER_ERROR, "Unable to get font metrics for font \"%s\"", font_name); return NULL; } display->default_foreground = display->glyph_foreground = foreground; display->default_background = display->glyph_background = background; /* Calculate character dimensions */ display->char_width = pango_font_metrics_get_approximate_digit_width(metrics) / PANGO_SCALE; display->char_height = (pango_font_metrics_get_descent(metrics) + pango_font_metrics_get_ascent(metrics)) / PANGO_SCALE; /* Initially empty */ display->width = 0; display->height = 0; display->operations = NULL; /* Initially nothing selected */ display->text_selected = display->selection_committed = false; return display; }