diff options
-rw-r--r-- | config.def.h | 2 | ||||
-rw-r--r-- | st.c | 31 |
2 files changed, 24 insertions, 9 deletions
diff --git a/config.def.h b/config.def.h index 1ba6d8e..ee677a5 100644 --- a/config.def.h +++ b/config.def.h | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | /* appearance */ | 3 | /* appearance */ |
4 | static char font[] = "Liberation Mono:pixelsize=12:antialias=false:autohint=false"; | 4 | static char font[] = "Liberation Mono:pixelsize=12:antialias=false:autohint=false"; |
5 | static unsigned int borderpx = 2; | 5 | static int borderpx = 2; |
6 | static char shell[] = "/bin/sh"; | 6 | static char shell[] = "/bin/sh"; |
7 | 7 | ||
8 | /* double-click timeout (in milliseconds) between clicks for selection */ | 8 | /* double-click timeout (in milliseconds) between clicks for selection */ |
@@ -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 | ||