Initial actual support for copying of text.
This commit is contained in:
parent
c29c43e056
commit
3d1ca93b3a
@ -248,5 +248,10 @@ void guac_terminal_display_flush(guac_terminal_display* display);
|
|||||||
void guac_terminal_display_select(guac_terminal_display* display,
|
void guac_terminal_display_select(guac_terminal_display* display,
|
||||||
int start_row, int start_col, int end_row, int end_col);
|
int start_row, int start_col, int end_row, int end_col);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the select rectangle.
|
||||||
|
*/
|
||||||
|
void guac_terminal_display_clear_select(guac_terminal_display* display);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -248,9 +248,10 @@ void guac_terminal_select_start(guac_terminal* terminal, int row, int column);
|
|||||||
void guac_terminal_select_update(guac_terminal* terminal, int row, int column);
|
void guac_terminal_select_update(guac_terminal* terminal, int row, int column);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ends text selection, removing any highlight.
|
* Ends text selection, removing any highlight. Character data is stored in the
|
||||||
|
* string buffer provided.
|
||||||
*/
|
*/
|
||||||
void guac_terminal_select_end(guac_terminal* terminal);
|
void guac_terminal_select_end(guac_terminal* terminal, char* string);
|
||||||
|
|
||||||
/* LOW-LEVEL TERMINAL OPERATIONS */
|
/* LOW-LEVEL TERMINAL OPERATIONS */
|
||||||
|
|
||||||
|
@ -887,14 +887,25 @@ void guac_terminal_display_flush(guac_terminal_display* display) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void guac_terminal_display_clear_select(guac_terminal_display* display) {
|
||||||
|
|
||||||
|
guac_socket* socket = display->client->socket;
|
||||||
|
guac_layer* select_layer = display->select_layer;
|
||||||
|
|
||||||
|
guac_protocol_send_rect(socket, select_layer, 0, 0, 1, 1);
|
||||||
|
guac_protocol_send_cfill(socket, GUAC_COMP_SRC, select_layer,
|
||||||
|
0x00, 0x00, 0x00, 0x00);
|
||||||
|
|
||||||
|
guac_socket_flush(socket);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void guac_terminal_display_select(guac_terminal_display* display,
|
void guac_terminal_display_select(guac_terminal_display* display,
|
||||||
int start_row, int start_col, int end_row, int end_col) {
|
int start_row, int start_col, int end_row, int end_col) {
|
||||||
|
|
||||||
guac_socket* socket = display->client->socket;
|
guac_socket* socket = display->client->socket;
|
||||||
guac_layer* select_layer = display->select_layer;
|
guac_layer* select_layer = display->select_layer;
|
||||||
|
|
||||||
guac_client_log_info(display->client, "START_COL=%i", start_col);
|
|
||||||
|
|
||||||
/* If single row, just need one rectangle */
|
/* If single row, just need one rectangle */
|
||||||
if (start_row == end_row) {
|
if (start_row == end_row) {
|
||||||
|
|
||||||
@ -965,7 +976,7 @@ void guac_terminal_display_select(guac_terminal_display* display,
|
|||||||
|
|
||||||
/* Draw new selection, erasing old */
|
/* Draw new selection, erasing old */
|
||||||
guac_protocol_send_cfill(socket, GUAC_COMP_SRC, select_layer,
|
guac_protocol_send_cfill(socket, GUAC_COMP_SRC, select_layer,
|
||||||
0x00, 0xFF, 0x00, 0x80);
|
0x00, 0x80, 0xFF, 0x60);
|
||||||
|
|
||||||
guac_socket_flush(socket);
|
guac_socket_flush(socket);
|
||||||
|
|
||||||
|
@ -180,8 +180,21 @@ int ssh_guac_client_mouse_handler(guac_client* client, int x, int y, int mask) {
|
|||||||
pthread_mutex_lock(&(term->lock));
|
pthread_mutex_lock(&(term->lock));
|
||||||
|
|
||||||
/* If mouse button released, stop selection */
|
/* If mouse button released, stop selection */
|
||||||
if (released_mask & GUAC_CLIENT_MOUSE_LEFT)
|
if (released_mask & GUAC_CLIENT_MOUSE_LEFT) {
|
||||||
guac_terminal_select_end(term);
|
|
||||||
|
/* End selection and get selected text */
|
||||||
|
char* string = malloc(term->term_width * term->term_height * sizeof(char));
|
||||||
|
guac_terminal_select_end(term, string);
|
||||||
|
|
||||||
|
/* Store new data */
|
||||||
|
free(client_data->clipboard_data);
|
||||||
|
client_data->clipboard_data = string;
|
||||||
|
|
||||||
|
/* Send data */
|
||||||
|
guac_protocol_send_clipboard(client->socket, string);
|
||||||
|
guac_socket_flush(client->socket);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/* Otherwise, just update */
|
/* Otherwise, just update */
|
||||||
else
|
else
|
||||||
|
@ -409,9 +409,81 @@ void guac_terminal_select_update(guac_terminal* terminal, int row, int column) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void guac_terminal_select_end(guac_terminal* terminal) {
|
int __guac_terminal_buffer_string(guac_terminal_buffer_row* row, int start, int end, char* string) {
|
||||||
/* STUB */
|
|
||||||
|
int length = 0;
|
||||||
|
int i;
|
||||||
|
for (i=start; i<=end; i++) {
|
||||||
|
*(string++) = (char) row->characters[i].value;
|
||||||
|
length++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return length;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void guac_terminal_select_end(guac_terminal* terminal, char* string) {
|
||||||
|
|
||||||
|
/* Deselect */
|
||||||
terminal->text_selected = false;
|
terminal->text_selected = false;
|
||||||
|
guac_terminal_display_clear_select(terminal->display);
|
||||||
|
|
||||||
|
guac_terminal_buffer_row* buffer_row;
|
||||||
|
|
||||||
|
int row;
|
||||||
|
|
||||||
|
int start_row, start_col;
|
||||||
|
int end_row, end_col;
|
||||||
|
|
||||||
|
/* Ensure proper ordering of start and end coords */
|
||||||
|
if (terminal->selection_start_row <= terminal->selection_end_row) {
|
||||||
|
start_row = terminal->selection_start_row;
|
||||||
|
start_col = terminal->selection_start_column;
|
||||||
|
end_row = terminal->selection_end_row;
|
||||||
|
end_col = terminal->selection_end_column;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
end_row = terminal->selection_start_row;
|
||||||
|
end_col = terminal->selection_start_column;
|
||||||
|
start_row = terminal->selection_end_row;
|
||||||
|
start_col = terminal->selection_end_column;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If only one row, simply copy */
|
||||||
|
buffer_row = guac_terminal_buffer_get_row(terminal->buffer, start_row, 0);
|
||||||
|
if (end_row == start_row) {
|
||||||
|
if (buffer_row->length - 1 < end_col)
|
||||||
|
end_col = buffer_row->length - 1;
|
||||||
|
string += __guac_terminal_buffer_string(buffer_row, start_col, end_col, string);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Otherwise, copy multiple rows */
|
||||||
|
else {
|
||||||
|
|
||||||
|
/* Store first row */
|
||||||
|
string += __guac_terminal_buffer_string(buffer_row, start_col, buffer_row->length - 1, string);
|
||||||
|
|
||||||
|
/* Store all middle rows */
|
||||||
|
for (row=start_row+1; row<end_row; row++) {
|
||||||
|
|
||||||
|
buffer_row = guac_terminal_buffer_get_row(terminal->buffer, row, 0);
|
||||||
|
|
||||||
|
*(string++) = '\n';
|
||||||
|
string += __guac_terminal_buffer_string(buffer_row, 0, buffer_row->length - 1, string);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Store last row */
|
||||||
|
buffer_row = guac_terminal_buffer_get_row(terminal->buffer, end_row, 0);
|
||||||
|
if (buffer_row->length - 1 < end_col)
|
||||||
|
end_col = buffer_row->length - 1;
|
||||||
|
string += __guac_terminal_buffer_string(buffer_row, 0, end_col, string);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Null terminator */
|
||||||
|
*string = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void guac_terminal_copy_columns(guac_terminal* terminal, int row,
|
void guac_terminal_copy_columns(guac_terminal* terminal, int row,
|
||||||
|
Loading…
Reference in New Issue
Block a user