implemented clipboard paste and free handlers

This commit is contained in:
James Muehlner 2011-12-30 14:34:04 -08:00
parent 4b0bbd8f4d
commit e6a6780591
5 changed files with 78 additions and 1 deletions

View File

@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* James Muehlner <dagger10k@users.sourceforge.net>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -52,11 +53,14 @@ typedef struct ssh_guac_client_data {
ssh_channel term_channel;
ssh_guac_terminal* term;
char * clipboard_data;
char password[1024];
int password_length;
int mod_ctrl;
int mouse_mask;
} ssh_guac_client_data;

View File

@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* James Muehlner <dagger10k@users.sourceforge.net>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -42,6 +43,9 @@
int ssh_guac_client_handle_messages(guac_client* client);
int ssh_guac_client_key_handler(guac_client* client, int keysym, int pressed);
int ssh_guac_client_mouse_handler(guac_client* client, int x, int y, int mask);
int ssh_guac_client_clipboard_handler(guac_client* client, char* data);
int ssh_guac_client_free_handler(guac_client* client);
#endif

View File

@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* James Muehlner <dagger10k@users.sourceforge.net>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -114,6 +115,7 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
client->data = client_data;
client_data->term = term;
client_data->mod_ctrl = 0;
client_data->clipboard_data = NULL;
/* Send name and dimensions */
guac_protocol_send_name(socket, "SSH TEST");
@ -216,7 +218,11 @@ int ssh_guac_client_auth(guac_client* client, const char* password) {
/* Set handlers */
client->handle_messages = ssh_guac_client_handle_messages;
client->free_handler = ssh_guac_client_free_handler;
client->mouse_handler = ssh_guac_client_mouse_handler;
client->key_handler = ssh_guac_client_key_handler;
client->clipboard_handler = ssh_guac_client_clipboard_handler;
/* Success */
return 0;

View File

@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* James Muehlner <dagger10k@users.sourceforge.net>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -108,6 +109,46 @@ int ssh_guac_client_handle_messages(guac_client* client) {
}
int ssh_guac_client_clipboard_handler(guac_client* client, char* data) {
ssh_guac_client_data* client_data = (ssh_guac_client_data*) client->data;
free(client_data->clipboard_data);
client_data->clipboard_data = strdup(data);
guac_client_log_info(client, "Clipboard data recieved: %s", data);
return 0;
}
int ssh_guac_client_mouse_handler(guac_client* client, int x, int y, int mask) {
ssh_guac_client_data* client_data = (ssh_guac_client_data*) client->data;
/* Mouse just changed from down to up */
int mouse_up =
(client_data->mouse_mask & GUAC_CLIENT_MOUSE_RIGHT)
&& !(mask & GUAC_CLIENT_MOUSE_RIGHT);
guac_client_log_info(client, "CLICK? x=%i, y=%i, mask=%i, mouse_up=%i", x, y, mask, mouse_up);
client_data->mouse_mask = mask;
/* Paste contents of clipboard on right mouse button up */
if(mouse_up && client_data->clipboard_data != NULL) {
int length = strlen(client_data->clipboard_data);
if(length)
return channel_write(client_data->term_channel, client_data->clipboard_data, length);
}
return 0;
}
int ssh_guac_client_key_handler(guac_client* client, int keysym, int pressed) {
ssh_guac_client_data* client_data = (ssh_guac_client_data*) client->data;
@ -161,3 +202,19 @@ int ssh_guac_client_key_handler(guac_client* client, int keysym, int pressed) {
}
int ssh_guac_client_free_handler(guac_client* client) {
ssh_guac_client_data* guac_client_data = (ssh_guac_client_data*) client->data;
/* Free terminal */
ssh_guac_terminal_free(guac_client_data->term);
/* Free clipboard data */
free(guac_client_data->clipboard_data);
/* Free generic data struct */
free(client->data);
return 0;
}

View File

@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* James Muehlner <dagger10k@users.sourceforge.net>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -165,7 +166,12 @@ ssh_guac_terminal* ssh_guac_terminal_create(guac_client* client) {
}
void ssh_guac_terminal_free(ssh_guac_terminal* term) {
/* STUB */
/* Free scrollback buffer */
for (int row = 0; row < term->term_height; row++)
free(term->scrollback[row]);
free(term->scrollback);
}
int __ssh_guac_terminal_get_glyph(ssh_guac_terminal* term, char c) {