From 44bfe4da5dead378e32bdbd6be11f591a2283d38 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 6 May 2016 03:35:29 -0400 Subject: retain selection contents after it is removed this way, clicking in a terminal doesn't make you stop being able to paste things --- src/window-xlib.c | 39 ++++++++++++++++++++++----------------- src/window-xlib.h | 2 ++ 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/window-xlib.c b/src/window-xlib.c index 2bdfa41..48d8654 100644 --- a/src/window-xlib.c +++ b/src/window-xlib.c @@ -618,6 +618,8 @@ static void runes_window_backend_start_selection( static void runes_window_backend_update_selection( RunesTerm *t, int xpixel, int ypixel) { + RunesWindowBackend *w = &t->w; + struct vt100_loc *start = &t->display.selection_start; struct vt100_loc *end = &t->display.selection_end; struct vt100_loc orig_end = *end; @@ -628,6 +630,20 @@ static void runes_window_backend_update_selection( *end = runes_window_backend_get_mouse_position(t, xpixel, ypixel); if (orig_end.row != end->row || orig_end.col != end->col) { + if (end->row < start->row || (end->row == start->row && end->col < start->col)) { + struct vt100_loc *tmp; + + tmp = start; + start = end; + end = tmp; + } + + if (w->selection_contents) { + free(w->selection_contents); + w->selection_contents = NULL; + } + vt100_screen_get_string_plaintext( + &t->scr, start, end, &w->selection_contents, &w->selection_len); t->display.dirty = 1; runes_window_backend_request_flush(t); } @@ -639,6 +655,10 @@ static void runes_window_backend_clear_selection(RunesTerm *t) XSetSelectionOwner(w->dpy, XA_PRIMARY, None, CurrentTime); t->display.has_selection = 0; + if (w->selection_contents) { + free(w->selection_contents); + w->selection_contents = NULL; + } } static void runes_window_backend_handle_key_event(RunesTerm *t, XKeyEvent *e) @@ -888,26 +908,11 @@ static void runes_window_backend_handle_selection_request_event( (unsigned char *)&targets, 2); } else if (e->target == XA_STRING || e->target == w->atoms[RUNES_ATOM_UTF8_STRING]) { - char *contents; - size_t len; - struct vt100_loc *start = &t->display.selection_start; - struct vt100_loc *end = &t->display.selection_end; - - if (end->row < start->row || (end->row == start->row && end->col < start->col)) { - struct vt100_loc *tmp; - - tmp = start; - start = end; - end = tmp; - } - - vt100_screen_get_string_plaintext(&t->scr, start, end, &contents, &len); - if (contents) { + if (w->selection_contents) { XChangeProperty( w->dpy, e->requestor, e->property, e->target, 8, PropModeReplace, - (unsigned char *)contents, len); - free(contents); + (unsigned char *)w->selection_contents, w->selection_len); } } else { diff --git a/src/window-xlib.h b/src/window-xlib.h index 8bc0fb6..4a49340 100644 --- a/src/window-xlib.h +++ b/src/window-xlib.h @@ -25,6 +25,8 @@ struct runes_window { Window border_w; XIC ic; XEvent event; + char *selection_contents; + size_t selection_len; cairo_t *backend_cr; -- cgit v1.2.3-54-g00ecf