aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.def.h2
-rw-r--r--st.c31
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 */
4static char font[] = "Liberation Mono:pixelsize=12:antialias=false:autohint=false"; 4static char font[] = "Liberation Mono:pixelsize=12:antialias=false:autohint=false";
5static unsigned int borderpx = 2; 5static int borderpx = 2;
6static char shell[] = "/bin/sh"; 6static 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 */
diff --git a/st.c b/st.c
index 8ef1346..d7a0fed 100644
--- a/st.c
+++ b/st.c
@@ -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
583static int
584x2col(int x) {
585 x -= borderpx;
586 x /= xw.cw;
587
588 return LIMIT(x, 0, term.col-1);
589}
590
591static int
592y2row(int y) {
593 y -= borderpx;
594 y /= xw.ch;
595
596 return LIMIT(y, 0, term.row-1);
597}
598
585static inline bool 599static inline bool
586selected(int x, int y) { 600selected(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
614void 629void
615mousereport(XEvent *e) { 630mousereport(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