aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevin J. Pohly <djpohly@gmail.com>2018-02-21 22:56:02 -0600
committerDevin J. Pohly <djpohly@gmail.com>2018-02-25 21:53:24 -0600
commit5683b1f80c5ac274adf98517ce2217b4d4896243 (patch)
tree83e79c7f53eb44b6a7e76834dfe234408a7b0495
parent138caf294ea4d7968df36ead9d5ff5fc49f6215f (diff)
downloadst-patched-5683b1f80c5ac274adf98517ce2217b4d4896243.tar.bz2
st-patched-5683b1f80c5ac274adf98517ce2217b4d4896243.tar.xz
st-patched-5683b1f80c5ac274adf98517ce2217b4d4896243.zip
Move X-specific selection info into XSelection
Data about PRIMARY/CLIPBOARD and clicks are part of the front-end, not the terminal. Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
-rw-r--r--st.c4
-rw-r--r--st.h5
-rw-r--r--x.c31
3 files changed, 19 insertions, 21 deletions
diff --git a/st.c b/st.c
index d4dfe6e..ea0726c 100644
--- a/st.c
+++ b/st.c
@@ -365,13 +365,9 @@ base64dec(const char *src)
365void 365void
366selinit(void) 366selinit(void)
367{ 367{
368 clock_gettime(CLOCK_MONOTONIC, &sel.tclick1);
369 clock_gettime(CLOCK_MONOTONIC, &sel.tclick2);
370 sel.mode = SEL_IDLE; 368 sel.mode = SEL_IDLE;
371 sel.snap = 0; 369 sel.snap = 0;
372 sel.ob.x = -1; 370 sel.ob.x = -1;
373 sel.primary = NULL;
374 sel.clipboard = NULL;
375} 371}
376 372
377int 373int
diff --git a/st.h b/st.h
index 8637d35..79dd47e 100644
--- a/st.h
+++ b/st.h
@@ -149,12 +149,7 @@ typedef struct {
149 int x, y; 149 int x, y;
150 } nb, ne, ob, oe; 150 } nb, ne, ob, oe;
151 151
152 char *primary, *clipboard;
153 int alt; 152 int alt;
154 struct timespec tclick1;
155 struct timespec tclick2;
156
157 //Atom xtarget;
158} Selection; 153} Selection;
159 154
160typedef union { 155typedef union {
diff --git a/x.c b/x.c
index e3e5451..9f506b1 100644
--- a/x.c
+++ b/x.c
@@ -94,6 +94,9 @@ typedef struct {
94 94
95typedef struct { 95typedef struct {
96 Atom xtarget; 96 Atom xtarget;
97 char *primary, *clipboard;
98 struct timespec tclick1;
99 struct timespec tclick2;
97} XSelection; 100} XSelection;
98 101
99/* Font structure */ 102/* Font structure */
@@ -234,11 +237,11 @@ clipcopy(const Arg *dummy)
234{ 237{
235 Atom clipboard; 238 Atom clipboard;
236 239
237 if (sel.clipboard != NULL) 240 if (xsel.clipboard != NULL)
238 free(sel.clipboard); 241 free(xsel.clipboard);
239 242
240 if (sel.primary != NULL) { 243 if (xsel.primary != NULL) {
241 sel.clipboard = xstrdup(sel.primary); 244 xsel.clipboard = xstrdup(xsel.primary);
242 clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0); 245 clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0);
243 XSetSelectionOwner(xw.dpy, clipboard, xw.win, CurrentTime); 246 XSetSelectionOwner(xw.dpy, clipboard, xw.win, CurrentTime);
244 } 247 }
@@ -427,9 +430,9 @@ bpress(XEvent *e)
427 * If the user clicks below predefined timeouts specific 430 * If the user clicks below predefined timeouts specific
428 * snapping behaviour is exposed. 431 * snapping behaviour is exposed.
429 */ 432 */
430 if (TIMEDIFF(now, sel.tclick2) <= tripleclicktimeout) { 433 if (TIMEDIFF(now, xsel.tclick2) <= tripleclicktimeout) {
431 sel.snap = SNAP_LINE; 434 sel.snap = SNAP_LINE;
432 } else if (TIMEDIFF(now, sel.tclick1) <= doubleclicktimeout) { 435 } else if (TIMEDIFF(now, xsel.tclick1) <= doubleclicktimeout) {
433 sel.snap = SNAP_WORD; 436 sel.snap = SNAP_WORD;
434 } else { 437 } else {
435 sel.snap = 0; 438 sel.snap = 0;
@@ -439,8 +442,8 @@ bpress(XEvent *e)
439 if (sel.snap != 0) 442 if (sel.snap != 0)
440 sel.mode = SEL_READY; 443 sel.mode = SEL_READY;
441 tsetdirt(sel.nb.y, sel.ne.y); 444 tsetdirt(sel.nb.y, sel.ne.y);
442 sel.tclick2 = sel.tclick1; 445 xsel.tclick2 = xsel.tclick1;
443 sel.tclick1 = now; 446 xsel.tclick1 = now;
444 } 447 }
445} 448}
446 449
@@ -594,9 +597,9 @@ selrequest(XEvent *e)
594 */ 597 */
595 clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0); 598 clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0);
596 if (xsre->selection == XA_PRIMARY) { 599 if (xsre->selection == XA_PRIMARY) {
597 seltext = sel.primary; 600 seltext = xsel.primary;
598 } else if (xsre->selection == clipboard) { 601 } else if (xsre->selection == clipboard) {
599 seltext = sel.clipboard; 602 seltext = xsel.clipboard;
600 } else { 603 } else {
601 fprintf(stderr, 604 fprintf(stderr,
602 "Unhandled clipboard selection 0x%lx\n", 605 "Unhandled clipboard selection 0x%lx\n",
@@ -620,8 +623,8 @@ selrequest(XEvent *e)
620void 623void
621setsel(char *str, Time t) 624setsel(char *str, Time t)
622{ 625{
623 free(sel.primary); 626 free(xsel.primary);
624 sel.primary = str; 627 xsel.primary = str;
625 628
626 XSetSelectionOwner(xw.dpy, XA_PRIMARY, xw.win, t); 629 XSetSelectionOwner(xw.dpy, XA_PRIMARY, xw.win, t);
627 if (XGetSelectionOwner(xw.dpy, XA_PRIMARY) != xw.win) 630 if (XGetSelectionOwner(xw.dpy, XA_PRIMARY) != xw.win)
@@ -1127,6 +1130,10 @@ xinit(void)
1127 xhints(); 1130 xhints();
1128 XSync(xw.dpy, False); 1131 XSync(xw.dpy, False);
1129 1132
1133 clock_gettime(CLOCK_MONOTONIC, &xsel.tclick1);
1134 clock_gettime(CLOCK_MONOTONIC, &xsel.tclick2);
1135 xsel.primary = NULL;
1136 xsel.clipboard = NULL;
1130 xsel.xtarget = XInternAtom(xw.dpy, "UTF8_STRING", 0); 1137 xsel.xtarget = XInternAtom(xw.dpy, "UTF8_STRING", 0);
1131 if (xsel.xtarget == None) 1138 if (xsel.xtarget == None)
1132 xsel.xtarget = XA_STRING; 1139 xsel.xtarget = XA_STRING;