aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2016-05-06 03:35:29 -0400
committerJesse Luehrs <doy@tozt.net>2016-05-06 03:42:05 -0400
commit44bfe4da5dead378e32bdbd6be11f591a2283d38 (patch)
tree95a1b99ab2c905f4b6b3cb09ff7d0153d2eeb65d
parentb1ae3f18ef5515433fa64ee00cbd269090b3bfc4 (diff)
downloadrunes-44bfe4da5dead378e32bdbd6be11f591a2283d38.tar.gz
runes-44bfe4da5dead378e32bdbd6be11f591a2283d38.zip
retain selection contents after it is removed
this way, clicking in a terminal doesn't make you stop being able to paste things
-rw-r--r--src/window-xlib.c39
-rw-r--r--src/window-xlib.h2
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;