diff options
author | Aurélien Aptel <aurelien.aptel@gmail.com> | 2011-05-10 22:55:35 +0200 |
---|---|---|
committer | Aurélien Aptel <aurelien.aptel@gmail.com> | 2011-05-10 22:55:35 +0200 |
commit | a7f4af0139d6c0890007c7349b59ef94266ccea9 (patch) | |
tree | 9eeeadf0f602c84eba961bd2ded1c856bf1e286a | |
parent | 225fc7cbcfaf15a56210b2ec3ec41588ef864849 (diff) | |
download | st-patched-a7f4af0139d6c0890007c7349b59ef94266ccea9.tar.bz2 st-patched-a7f4af0139d6c0890007c7349b59ef94266ccea9.tar.xz st-patched-a7f4af0139d6c0890007c7349b59ef94266ccea9.zip |
macro cleanup.
-rw-r--r-- | st.c | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -53,7 +53,9 @@ | |||
53 | #define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x) | 53 | #define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x) |
54 | #define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg) | 54 | #define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg) |
55 | #define IS_SET(flag) (term.mode & (flag)) | 55 | #define IS_SET(flag) (term.mode & (flag)) |
56 | #define TIMEDIFFERENCE(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + (t1.tv_usec-t2.tv_usec)/1000) | 56 | #define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + (t1.tv_usec-t2.tv_usec)/1000) |
57 | #define X2COL(x) (((x) - BORDER)/xw.cw) | ||
58 | #define Y2ROW(y) (((y) - BORDER)/xw.ch) | ||
57 | 59 | ||
58 | /* Attribute, Cursor, Character state, Terminal mode, Screen draw mode */ | 60 | /* Attribute, Cursor, Character state, Terminal mode, Screen draw mode */ |
59 | enum { ATTR_NULL=0 , ATTR_REVERSE=1 , ATTR_UNDERLINE=2, ATTR_BOLD=4, ATTR_GFX=8 }; | 61 | enum { ATTR_NULL=0 , ATTR_REVERSE=1 , ATTR_UNDERLINE=2, ATTR_BOLD=4, ATTR_GFX=8 }; |
@@ -401,8 +403,8 @@ getbuttoninfo(XEvent *e, int *b, int *x, int *y) { | |||
401 | if(b) | 403 | if(b) |
402 | *b = e->xbutton.button; | 404 | *b = e->xbutton.button; |
403 | 405 | ||
404 | *x = (e->xbutton.x - BORDER)/xw.cw; | 406 | *x = X2COL(e->xbutton.x); |
405 | *y = (e->xbutton.y - BORDER)/xw.ch; | 407 | *y = Y2ROW(e->xbutton.y); |
406 | sel.b.x = sel.by < sel.ey ? sel.bx : sel.ex; | 408 | sel.b.x = sel.by < sel.ey ? sel.bx : sel.ex; |
407 | sel.b.y = MIN(sel.by, sel.ey); | 409 | sel.b.y = MIN(sel.by, sel.ey); |
408 | sel.e.x = sel.by < sel.ey ? sel.ex : sel.bx; | 410 | sel.e.x = sel.by < sel.ey ? sel.ex : sel.bx; |
@@ -411,8 +413,8 @@ getbuttoninfo(XEvent *e, int *b, int *x, int *y) { | |||
411 | 413 | ||
412 | void | 414 | void |
413 | mousereport(XEvent *e) { | 415 | mousereport(XEvent *e) { |
414 | int x = (e->xbutton.x - BORDER)/xw.cw; | 416 | int x = X2COL(e->xbutton.x); |
415 | int y = (e->xbutton.y - BORDER)/xw.ch; | 417 | int y = Y2ROW(e->xbutton.y); |
416 | int button = e->xbutton.button; | 418 | int button = e->xbutton.button; |
417 | int state = e->xbutton.state; | 419 | int state = e->xbutton.state; |
418 | char buf[] = { '\033', '[', 'M', 0, 32+x+1, 32+y+1 }; | 420 | char buf[] = { '\033', '[', 'M', 0, 32+x+1, 32+y+1 }; |
@@ -440,8 +442,8 @@ void | |||
440 | bpress(XEvent *e) { | 442 | bpress(XEvent *e) { |
441 | mousereport(e); | 443 | mousereport(e); |
442 | sel.mode = 1; | 444 | sel.mode = 1; |
443 | sel.ex = sel.bx = (e->xbutton.x - BORDER)/xw.cw; | 445 | sel.ex = sel.bx = X2COL(e->xbutton.x); |
444 | sel.ey = sel.by = (e->xbutton.y - BORDER)/xw.ch; | 446 | sel.ey = sel.by = Y2ROW(e->xbutton.y); |
445 | } | 447 | } |
446 | 448 | ||
447 | void | 449 | void |
@@ -563,13 +565,13 @@ brelease(XEvent *e) { | |||
563 | struct timeval now; | 565 | struct timeval now; |
564 | gettimeofday(&now, NULL); | 566 | gettimeofday(&now, NULL); |
565 | 567 | ||
566 | if(TIMEDIFFERENCE(now, sel.tclick2) <= TRIPLECLICK_TIMEOUT) { | 568 | if(TIMEDIFF(now, sel.tclick2) <= TRIPLECLICK_TIMEOUT) { |
567 | /* triple click on the line */ | 569 | /* triple click on the line */ |
568 | sel.b.x = sel.bx = 0; | 570 | sel.b.x = sel.bx = 0; |
569 | sel.e.x = sel.ex = term.col; | 571 | sel.e.x = sel.ex = term.col; |
570 | sel.b.y = sel.e.y = sel.ey; | 572 | sel.b.y = sel.e.y = sel.ey; |
571 | selcopy(); | 573 | selcopy(); |
572 | } else if(TIMEDIFFERENCE(now, sel.tclick1) <= DOUBLECLICK_TIMEOUT) { | 574 | } else if(TIMEDIFF(now, sel.tclick1) <= DOUBLECLICK_TIMEOUT) { |
573 | /* double click to select word */ | 575 | /* double click to select word */ |
574 | sel.bx = sel.ex; | 576 | sel.bx = sel.ex; |
575 | while(term.line[sel.ey][sel.bx-1].state & GLYPH_SET && | 577 | while(term.line[sel.ey][sel.bx-1].state & GLYPH_SET && |