Store large clipboard selections in a file

This commit is contained in:
K. Lange 2018-05-15 14:54:22 +09:00
parent ee1aeb89b2
commit 4ff96e4bdf
3 changed files with 37 additions and 6 deletions

View File

@ -1613,9 +1613,18 @@ void * handle_incoming(void) {
if (selection_text) {
free(selection_text);
}
selection_text = malloc(cb->size+1);
memcpy(selection_text, cb->content, cb->size);
selection_text[cb->size] = '\0';
if (*cb->content == '\002') {
int size = atoi(&cb->content[2]);
FILE * clipboard = yutani_open_clipboard(yctx);
selection_text = malloc(size + 1);
fread(selection_text, 1, size, clipboard);
selection_text[size] = '\0';
fclose(clipboard);
} else {
selection_text = malloc(cb->size+1);
memcpy(selection_text, cb->content, cb->size);
selection_text[cb->size] = '\0';
}
handle_input_s(selection_text);
}
break;

View File

@ -520,6 +520,7 @@ extern void yutani_window_resize_start(yutani_t * yctx, yutani_window_t * window
extern void yutani_special_request(yutani_t * yctx, yutani_window_t * window, uint32_t request);
extern void yutani_special_request_wid(yutani_t * yctx, yutani_wid_t wid, uint32_t request);
extern void yutani_set_clipboard(yutani_t * yctx, char * content);
extern FILE * yutani_open_clipboard(yutani_t * yctx);
extern gfx_context_t * init_graphics_yutani(yutani_window_t * window);
extern gfx_context_t * init_graphics_yutani_double_buffer(yutani_window_t * window);

View File

@ -761,9 +761,30 @@ void yutani_special_request_wid(yutani_t * yctx, yutani_wid_t wid, uint32_t requ
void yutani_set_clipboard(yutani_t * yctx, char * content) {
/* Set clipboard contents */
yutani_msg_buildx_clipboard_alloc(m, strlen(content));
yutani_msg_buildx_clipboard(m, content);
yutani_msg_send(yctx, m);
int len = strlen(content);
if (len > 511) {
char tmp_file[100];
sprintf(tmp_file, "/tmp/.clipboard.%s", yctx->server_ident);
FILE * tmp = fopen(tmp_file, "w+");
fwrite(content, len, 1, tmp);
fclose(tmp);
char tmp_data[100];
sprintf(tmp_data, "\002 %d", len);
yutani_msg_buildx_clipboard_alloc(m, strlen(tmp_data));
yutani_msg_buildx_clipboard(m, tmp_data);
yutani_msg_send(yctx, m);
} else {
yutani_msg_buildx_clipboard_alloc(m, len);
yutani_msg_buildx_clipboard(m, content);
yutani_msg_send(yctx, m);
}
}
FILE * yutani_open_clipboard(yutani_t * yctx) {
char tmp_file[100];
sprintf(tmp_file, "/tmp/.clipboard.%s", yctx->server_ident);
return fopen(tmp_file, "r");
}
gfx_context_t * init_graphics_yutani(yutani_window_t * window) {