X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=st.c;h=a5cca1710cdc17da5fd79d4bd9393f5b5cc43674;hb=cfe897554d4467fdf4c002429370fc7716e419bc;hp=1474c531dcb4ab9086b7bf718019b0d2527b15af;hpb=1132d9e2d65f469dedd9c5b6f356495c7a87b743;p=st.git diff --git a/st.c b/st.c index 1474c53..a5cca17 100644 --- a/st.c +++ b/st.c @@ -125,11 +125,12 @@ typedef struct { GC gc; } DC; +/* TODO: use better name for vars... */ typedef struct { int mode; int bx, by; int ex, ey; - int b[2], e[2]; + struct {int x, y;} b, e; char *clip; } Selection; @@ -218,13 +219,13 @@ selinit(void) { } static inline int selected(int x, int y) { - if ((sel.ey==y && sel.by==y)) { + if(sel.ey == y && sel.by == y) { int bx = MIN(sel.bx, sel.ex); int ex = MAX(sel.bx, sel.ex); - return (x>=bx && x<=ex); + return BETWEEN(x, bx, ex); } - return (((y>sel.b[1] && y=sel.b[0] && (x<=sel.e[0] || sel.b[1]!=sel.e[1]))); + return ((sel.b.y < y&&y < sel.e.y) || (y==sel.e.y && x<=sel.e.x)) + || (y==sel.b.y && x>=sel.b.x && (x<=sel.e.x || sel.b.y!=sel.e.y)); } static void getbuttoninfo(XEvent *e, int *b, int *x, int *y) { @@ -232,10 +233,10 @@ static void getbuttoninfo(XEvent *e, int *b, int *x, int *y) { *b=*b==4096?5:*b==2048?4:*b==1024?3:*b==512?2:*b==256?1:-1; *x = e->xbutton.x/xw.cw; *y = e->xbutton.y/xw.ch; - sel.b[0] = sel.by