diff options
| author | Christoph Lohmann <20h@r-36.net> | 2012-11-03 03:24:22 +0100 |
|---|---|---|
| committer | Christoph Lohmann <20h@r-36.net> | 2012-11-03 03:24:22 +0100 |
| commit | abe85c0e997ed1882c69bde511f7e2746f68d9ab (patch) | |
| tree | b141915eea47f0fbdbe38ea2f81b454ea75c4576 /st.c | |
| parent | Fixing the italic-bold font check. Thanks nsz. (diff) | |
| download | st-abe85c0e997ed1882c69bde511f7e2746f68d9ab.tar.gz st-abe85c0e997ed1882c69bde511f7e2746f68d9ab.zip | |
Fixing an out-of-bound bug in the selection code. Thanks Szabolczs Nagy!
Diffstat (limited to 'st.c')
| -rw-r--r-- | st.c | 31 |
1 files changed, 23 insertions, 8 deletions
| @@ -72,8 +72,6 @@ | |||
| 72 | #define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg) | 72 | #define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg) |
| 73 | #define IS_SET(flag) (term.mode & (flag)) | 73 | #define IS_SET(flag) (term.mode & (flag)) |
| 74 | #define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + (t1.tv_usec-t2.tv_usec)/1000) | 74 | #define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + (t1.tv_usec-t2.tv_usec)/1000) |
| 75 | #define X2COL(x) (((x) - borderpx)/xw.cw) | ||
| 76 | #define Y2ROW(y) (((y) - borderpx)/xw.ch) | ||
| 77 | 75 | ||
| 78 | #define VT102ID "\033[?6c" | 76 | #define VT102ID "\033[?6c" |
| 79 | 77 | ||
| @@ -582,6 +580,22 @@ selinit(void) { | |||
| 582 | sel.xtarget = XA_STRING; | 580 | sel.xtarget = XA_STRING; |
| 583 | } | 581 | } |
| 584 | 582 | ||
| 583 | static int | ||
| 584 | x2col(int x) { | ||
| 585 | x -= borderpx; | ||
| 586 | x /= xw.cw; | ||
| 587 | |||
| 588 | return LIMIT(x, 0, term.col-1); | ||
| 589 | } | ||
| 590 | |||
| 591 | static int | ||
| 592 | y2row(int y) { | ||
| 593 | y -= borderpx; | ||
| 594 | y /= xw.ch; | ||
| 595 | |||
| 596 | return LIMIT(y, 0, term.row-1); | ||
| 597 | } | ||
| 598 | |||
| 585 | static inline bool | 599 | static inline bool |
| 586 | selected(int x, int y) { | 600 | selected(int x, int y) { |
| 587 | int bx, ex; | 601 | int bx, ex; |
| @@ -603,8 +617,9 @@ getbuttoninfo(XEvent *e, int *b, int *x, int *y) { | |||
| 603 | if(b) | 617 | if(b) |
| 604 | *b = e->xbutton.button; | 618 | *b = e->xbutton.button; |
| 605 | 619 | ||
| 606 | *x = X2COL(e->xbutton.x); | 620 | *x = x2col(e->xbutton.x); |
| 607 | *y = Y2ROW(e->xbutton.y); | 621 | *y = y2row(e->xbutton.y); |
| 622 | |||
| 608 | sel.b.x = sel.by < sel.ey ? sel.bx : sel.ex; | 623 | sel.b.x = sel.by < sel.ey ? sel.bx : sel.ex; |
| 609 | sel.b.y = MIN(sel.by, sel.ey); | 624 | sel.b.y = MIN(sel.by, sel.ey); |
| 610 | sel.e.x = sel.by < sel.ey ? sel.ex : sel.bx; | 625 | sel.e.x = sel.by < sel.ey ? sel.ex : sel.bx; |
| @@ -613,8 +628,8 @@ getbuttoninfo(XEvent *e, int *b, int *x, int *y) { | |||
| 613 | 628 | ||
| 614 | void | 629 | void |
| 615 | mousereport(XEvent *e) { | 630 | mousereport(XEvent *e) { |
| 616 | int x = X2COL(e->xbutton.x); | 631 | int x = x2col(e->xbutton.x); |
| 617 | int y = Y2ROW(e->xbutton.y); | 632 | int y = y2row(e->xbutton.y); |
| 618 | int button = e->xbutton.button; | 633 | int button = e->xbutton.button; |
| 619 | int state = e->xbutton.state; | 634 | int state = e->xbutton.state; |
| 620 | char buf[] = { '\033', '[', 'M', 0, 32+x+1, 32+y+1 }; | 635 | char buf[] = { '\033', '[', 'M', 0, 32+x+1, 32+y+1 }; |
| @@ -656,8 +671,8 @@ bpress(XEvent *e) { | |||
| 656 | draw(); | 671 | draw(); |
| 657 | } | 672 | } |
| 658 | sel.mode = 1; | 673 | sel.mode = 1; |
| 659 | sel.ex = sel.bx = X2COL(e->xbutton.x); | 674 | sel.ex = sel.bx = x2col(e->xbutton.x); |
| 660 | sel.ey = sel.by = Y2ROW(e->xbutton.y); | 675 | sel.ey = sel.by = y2row(e->xbutton.y); |
| 661 | } | 676 | } |
| 662 | } | 677 | } |
| 663 | 678 | ||
