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 | 5beae6a62ee15dfe36048e377ebf86df09a0cf82 (patch) | |
| tree | 9eeeadf0f602c84eba961bd2ded1c856bf1e286a | |
| parent | 0107293a446725551ceb756affe50b4853046f05 (diff) | |
| download | st-5beae6a62ee15dfe36048e377ebf86df09a0cf82.tar.gz st-5beae6a62ee15dfe36048e377ebf86df09a0cf82.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 && |
