[hackers] [st] Implement most ICCCM rules for selection handling. || Markus Wichmann

From: <git_AT_suckless.org>
Date: Mon, 13 Apr 2015 22:25:50 +0200 (CEST)

commit 42fa1f5ce46593a9d6c2f9196c1aae1a60ca07d1
Author: Markus Wichmann <nullplan_AT_gmx.net>
Date: Sat Apr 11 21:21:34 2015 +0200

    Implement most ICCCM rules for selection handling.
    
    ICCCM mandates the use of real timestamps to interact with the
    selection, to rule out race conditions if the clients are run at
    different speeds. I have implemented the low hanging fruit, putting the
    timestamps into text selection. Also, ICCCM mandates a check for whether
    XSetSelectionOwner() worked. Not sure my version is correct, though.

diff --git a/st.c b/st.c
index f874127..6bfa834 100644
--- a/st.c
+++ b/st.c
_AT_@ -423,7 +423,7 @@ static void xsettitle(char *);
 static void xresettitle(void);
 static void xsetpointermotion(int);
 static void xseturgency(int);
-static void xsetsel(char *);
+static void xsetsel(char *, Time);
 static void xtermclear(int, int, int, int);
 static void xunloadfont(Font *);
 static void xunloadfonts(void);
_AT_@ -449,7 +449,7 @@ static void selinit(void);
 static void selnormalize(void);
 static inline bool selected(int, int);
 static char *getsel(void);
-static void selcopy(void);
+static void selcopy(Time);
 static void selscroll(int, int);
 static void selsnap(int, int *, int *, int);
 static int x2col(int);
_AT_@ -984,8 +984,8 @@ getsel(void) {
 }
 
 void
-selcopy(void) {
- xsetsel(getsel());
+selcopy(Time t) {
+ xsetsel(getsel(), t);
 }
 
 void
_AT_@ -997,7 +997,7 @@ selnotify(XEvent *e) {
         XSelectionEvent *xsev;
 
         ofs = 0;
- xsev = (XSelectionEvent *)e;
+ xsev = &e->xselection;
         if (xsev->property == None)
             return;
         do {
_AT_@ -1083,6 +1083,9 @@ selrequest(XEvent *e) {
         xev.selection = xsre->selection;
         xev.target = xsre->target;
         xev.time = xsre->time;
+ if (xsre->property == None)
+ xsre->property = xsre->target;
+
         /* reject */
         xev.property = None;
 
_AT_@ -1125,11 +1128,13 @@ selrequest(XEvent *e) {
 }
 
 void
-xsetsel(char *str) {
+xsetsel(char *str, Time t) {
         free(sel.primary);
         sel.primary = str;
 
- XSetSelectionOwner(xw.dpy, XA_PRIMARY, xw.win, CurrentTime);
+ XSetSelectionOwner(xw.dpy, XA_PRIMARY, xw.win, t);
+ if (XGetSelectionOwner(xw.dpy, XA_PRIMARY) != xw.win)
+ selclear(0);
 }
 
 void
_AT_@ -1146,7 +1151,7 @@ brelease(XEvent *e) {
                         selclear(NULL);
                 } else {
                         getbuttoninfo(e);
- selcopy();
+ selcopy(e->xbutton.time);
                 }
                 sel.mode = 0;
                 tsetdirt(sel.nb.y, sel.ne.y);
Received on Mon Apr 13 2015 - 22:25:50 CEST

This archive was generated by hypermail 2.3.0 : Mon Apr 13 2015 - 22:36:14 CEST