aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2016-06-05 05:08:23 -0400
committerJesse Luehrs <doy@tozt.net>2016-06-05 05:08:23 -0400
commitb8196f0244d2a0b7adebe8d35182a071493eddf5 (patch)
treea381825d4e9e4ccd3bdb3bafcf334973c1fb01ff
parent7f59d00de5bb1b329ce6d332056f8c55348740b0 (diff)
downloadrunes-b8196f0244d2a0b7adebe8d35182a071493eddf5.tar.gz
runes-b8196f0244d2a0b7adebe8d35182a071493eddf5.zip
have the display own the entire selection
rather than just the selection location
-rw-r--r--src/display.c29
-rw-r--r--src/display.h4
-rw-r--r--src/window-xlib.c55
-rw-r--r--src/window-xlib.h2
4 files changed, 48 insertions, 42 deletions
diff --git a/src/display.c b/src/display.c
index 92dfab3..19df767 100644
--- a/src/display.c
+++ b/src/display.c
@@ -162,6 +162,35 @@ void runes_display_draw_cursor(RunesTerm *t)
}
}
+void runes_display_set_selection(
+ RunesTerm *t, struct vt100_loc *start, struct vt100_loc *end)
+{
+ RunesDisplay *display = t->display;
+
+ display->has_selection = 1;
+
+ if (end->row < start->row || (end->row == start->row && end->col < start->col)) {
+ struct vt100_loc *tmp;
+
+ tmp = start;
+ start = end;
+ end = tmp;
+ }
+
+ display->selection_start = *start;
+ display->selection_end = *end;
+
+ if (t->display->selection_contents) {
+ free(t->display->selection_contents);
+ t->display->selection_contents = NULL;
+ }
+ vt100_screen_get_string_plaintext(
+ t->scr, start, end,
+ &t->display->selection_contents, &t->display->selection_len);
+
+ t->display->dirty = 1;
+}
+
void runes_display_delete(RunesDisplay *display)
{
cairo_pattern_destroy(display->buffer);
diff --git a/src/display.h b/src/display.h
index 83fd57a..135a71e 100644
--- a/src/display.h
+++ b/src/display.h
@@ -19,6 +19,8 @@ struct runes_display {
struct vt100_loc selection_start;
struct vt100_loc selection_end;
+ char *selection_contents;
+ size_t selection_len;
unsigned int unfocused: 1;
unsigned int has_selection: 1;
@@ -29,6 +31,8 @@ RunesDisplay *runes_display_new(char *font_name);
void runes_display_set_context(RunesTerm *t, cairo_t *cr);
void runes_display_draw_screen(RunesTerm *t);
void runes_display_draw_cursor(RunesTerm *t);
+void runes_display_set_selection(
+ RunesTerm *t, struct vt100_loc *start, struct vt100_loc *end);
void runes_display_delete(RunesDisplay *display);
#endif
diff --git a/src/window-xlib.c b/src/window-xlib.c
index f656e03..be79cbe 100644
--- a/src/window-xlib.c
+++ b/src/window-xlib.c
@@ -97,11 +97,11 @@ static void runes_window_paste(RunesTerm *t, Time time);
static void runes_window_start_selection(
RunesTerm *t, int xpixel, int ypixel, Time time);
static void runes_window_start_selection_loc(
- RunesTerm *t, struct vt100_loc *loc, Time time);
+ RunesTerm *t, struct vt100_loc *start, Time time);
static void runes_window_update_selection(
RunesTerm *t, int xpixel, int ypixel);
static void runes_window_update_selection_loc(
- RunesTerm *t, struct vt100_loc *loc);
+ RunesTerm *t, struct vt100_loc *end);
static void runes_window_clear_selection(RunesTerm *t);
static void runes_window_handle_key_event(RunesTerm *t, XKeyEvent *e);
static void runes_window_handle_button_event(RunesTerm *t, XButtonEvent *e);
@@ -714,14 +714,11 @@ static void runes_window_start_selection(
}
static void runes_window_start_selection_loc(
- RunesTerm *t, struct vt100_loc *loc, Time time)
+ RunesTerm *t, struct vt100_loc *start, Time time)
{
RunesWindow *w = t->w;
- struct vt100_loc *start = &t->display->selection_start;
- struct vt100_loc *end = &t->display->selection_end;
Window old_owner;
-
- *start = *end = *loc;
+ int got_selection;
old_owner = XGetSelectionOwner(w->wb->dpy, XA_PRIMARY);
if (old_owner != w->w) {
@@ -735,10 +732,12 @@ static void runes_window_start_selection_loc(
XSendEvent(w->wb->dpy, old_owner, False, NoEventMask, &e);
}
XSetSelectionOwner(w->wb->dpy, XA_PRIMARY, w->w, time);
- t->display->has_selection = (XGetSelectionOwner(w->wb->dpy, XA_PRIMARY) == w->w);
+ got_selection = (XGetSelectionOwner(w->wb->dpy, XA_PRIMARY) == w->w);
- t->display->dirty = 1;
- runes_window_request_flush(t);
+ if (got_selection) {
+ runes_display_set_selection(t, start, start);
+ runes_window_request_flush(t);
+ }
}
static void runes_window_update_selection(RunesTerm *t, int xpixel, int ypixel)
@@ -750,35 +749,14 @@ static void runes_window_update_selection(RunesTerm *t, int xpixel, int ypixel)
}
static void runes_window_update_selection_loc(
- RunesTerm *t, struct vt100_loc *loc)
+ RunesTerm *t, struct vt100_loc *end)
{
- RunesWindow *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;
-
if (!t->display->has_selection) {
return;
}
- *end = *loc;
-
- 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;
+ if (t->display->selection_end.row != end->row || t->display->selection_end.col != end->col) {
+ runes_display_set_selection(t, &t->display->selection_start, end);
runes_window_request_flush(t);
}
}
@@ -789,10 +767,6 @@ static void runes_window_clear_selection(RunesTerm *t)
XSetSelectionOwner(w->wb->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_handle_key_event(RunesTerm *t, XKeyEvent *e)
@@ -1042,11 +1016,12 @@ static void runes_window_handle_selection_request_event(
}
else if (e->target == XA_STRING
|| e->target == w->wb->atoms[RUNES_ATOM_UTF8_STRING]) {
- if (w->selection_contents) {
+ if (t->display->selection_contents) {
XChangeProperty(
w->wb->dpy, e->requestor, e->property,
e->target, 8, PropModeReplace,
- (unsigned char *)w->selection_contents, w->selection_len);
+ (unsigned char *)t->display->selection_contents,
+ t->display->selection_len);
}
}
else {
diff --git a/src/window-xlib.h b/src/window-xlib.h
index 7819c5b..6518a1c 100644
--- a/src/window-xlib.h
+++ b/src/window-xlib.h
@@ -10,8 +10,6 @@ struct runes_window {
Window w;
Window border_w;
XIC ic;
- char *selection_contents;
- size_t selection_len;
struct timespec last_redraw;
cairo_t *backend_cr;