JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Fixing the selection handling to allow one char selection.
[st.git] / st.c
diff --git a/st.c b/st.c
index f593302..8d27c94 100644 (file)
--- a/st.c
+++ b/st.c
@@ -36,6 +36,7 @@ char *argv0;
 #define Draw XftDraw *
 #define Colour XftColor
 #define Colourmap Colormap
+#define Rectangle XRectangle
 
 #if   defined(__linux)
  #include <pty.h>
@@ -784,11 +785,8 @@ bpress(XEvent *e) {
                sel.ey = sel.by = y2row(e->xbutton.y);
 
                /*
-                * Snap handling.
-                * If user clicks are fasst enough (e.g. below timeouts),
-                * we ignore if his hand slipped left or down and accidentally
-                * selected more; we are just snapping to whatever we're
-                * snapping.
+                * If the user clicks below predefined timeouts specific
+                * snapping behaviour is exposed.
                 */
                if(TIMEDIFF(now, sel.tclick2) <= tripleclicktimeout) {
                        sel.snap = SNAP_LINE;
@@ -808,7 +806,8 @@ bpress(XEvent *e) {
                 * Draw selection, unless it's regular and we don't want to
                 * make clicks visible
                 */
-               if (sel.snap != 0) {
+               if(sel.snap != 0) {
+                       sel.mode++;
                        tsetdirt(sel.b.y, sel.e.y);
                        draw();
                }
@@ -986,14 +985,14 @@ brelease(XEvent *e) {
        if(e->xbutton.button == Button2) {
                selpaste(NULL);
        } else if(e->xbutton.button == Button1) {
-               sel.mode = 0;
-               getbuttoninfo(e);
-               term.dirty[sel.ey] = 1;
-               if(sel.bx == sel.ex && sel.by == sel.ey) {
+               if(sel.mode < 2) {
                        sel.bx = -1;
                } else {
+                       getbuttoninfo(e);
                        selcopy();
                }
+               sel.mode = 0;
+               term.dirty[sel.ey] = 1;
        }
 }
 
@@ -1009,6 +1008,7 @@ bmotion(XEvent *e) {
        if(!sel.mode)
                return;
 
+       sel.mode++;
        oldey = sel.ey;
        oldex = sel.ex;
        oldsby = sel.b.y;
@@ -1424,6 +1424,8 @@ tclearregion(int x1, int y1, int x2, int y2) {
        for(y = y1; y <= y2; y++) {
                term.dirty[y] = 1;
                for(x = x1; x <= x2; x++) {
+                       if(selected(x, y))
+                               selclear(NULL);
                        term.line[y][x] = term.c.attr;
                        memcpy(term.line[y][x].c, " ", 2);
                }
@@ -2764,6 +2766,7 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
        FcCharSet *fccharset;
        Colour *fg, *bg, *temp, revfg, revbg;
        XRenderColor colfg, colbg;
+       Rectangle r;
 
        frcflags = FRC_NORMAL;
 
@@ -2852,6 +2855,13 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
        /* Clean up the region we want to draw to. */
        XftDrawRect(xw.draw, bg, winx, winy, width, xw.ch);
 
+       /* Set the clip region because Xft is sometimes dirty. */
+       r.x = 0;
+       r.y = 0;
+       r.height = xw.ch;
+       r.width = width;
+       XftDrawSetClipRectangles(xw.draw, winx, winy, &r, 1);
+
        fcsets[0] = font->set;
        for(xp = winx; bytelen > 0;) {
                /*
@@ -2885,6 +2895,7 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
                                                        (FcChar8 *)u8fs,
                                                        u8fblen);
                                        xp += font->width * u8fl;
+
                                }
                                break;
                        }
@@ -2969,6 +2980,9 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
                XftDrawRect(xw.draw, fg, winx, winy + font->ascent + 1,
                                width, 1);
        }
+
+       /* Reset clip to none. */
+       XftDrawSetClip(xw.draw, 0);
 }
 
 void
@@ -3081,7 +3095,7 @@ drawregion(int x1, int y1, int x2, int y2) {
                ic = ib = ox = 0;
                for(x = x1; x < x2; x++) {
                        new = term.line[y][x];
-                       if(ena_sel && *(new.c) && selected(x, y))
+                       if(ena_sel && selected(x, y))
                                new.mode ^= ATTR_REVERSE;
                        if(ib > 0 && (ATTRCMP(base, new)
                                        || ib >= DRAW_BUF_SIZ-UTF_SIZ)) {