diff options
| author | Aurélien Aptel <aurelien.aptel@gmail.com> | 2010-08-31 18:30:18 +0200 |
|---|---|---|
| committer | Aurélien Aptel <aurelien.aptel@gmail.com> | 2010-08-31 18:30:18 +0200 |
| commit | cfe897554d4467fdf4c002429370fc7716e419bc (patch) | |
| tree | a1982471fcc74e5bc0455a38ed800cb48cb1fb8d | |
| parent | 9703859e6c1e2280036dc7992cb4c54688f719f5 (diff) | |
| download | st-cfe897554d4467fdf4c002429370fc7716e419bc.tar.gz st-cfe897554d4467fdf4c002429370fc7716e419bc.zip | |
use struct instead of array.
| -rw-r--r-- | st.c | 17 |
1 files changed, 9 insertions, 8 deletions
| @@ -125,11 +125,12 @@ typedef struct { | |||
| 125 | GC gc; | 125 | GC gc; |
| 126 | } DC; | 126 | } DC; |
| 127 | 127 | ||
| 128 | /* TODO: use better name for vars... */ | ||
| 128 | typedef struct { | 129 | typedef struct { |
| 129 | int mode; | 130 | int mode; |
| 130 | int bx, by; | 131 | int bx, by; |
| 131 | int ex, ey; | 132 | int ex, ey; |
| 132 | int b[2], e[2]; | 133 | struct {int x, y;} b, e; |
| 133 | char *clip; | 134 | char *clip; |
| 134 | } Selection; | 135 | } Selection; |
| 135 | 136 | ||
| @@ -223,8 +224,8 @@ static inline int selected(int x, int y) { | |||
| 223 | int ex = MAX(sel.bx, sel.ex); | 224 | int ex = MAX(sel.bx, sel.ex); |
| 224 | return BETWEEN(x, bx, ex); | 225 | return BETWEEN(x, bx, ex); |
| 225 | } | 226 | } |
| 226 | return ((sel.b[1] < y&&y < sel.e[1]) || (y==sel.e[1] && x<=sel.e[0])) | 227 | return ((sel.b.y < y&&y < sel.e.y) || (y==sel.e.y && x<=sel.e.x)) |
| 227 | || (y==sel.b[1] && x>=sel.b[0] && (x<=sel.e[0] || sel.b[1]!=sel.e[1])); | 228 | || (y==sel.b.y && x>=sel.b.x && (x<=sel.e.x || sel.b.y!=sel.e.y)); |
| 228 | } | 229 | } |
| 229 | 230 | ||
| 230 | static void getbuttoninfo(XEvent *e, int *b, int *x, int *y) { | 231 | static void getbuttoninfo(XEvent *e, int *b, int *x, int *y) { |
| @@ -232,10 +233,10 @@ static void getbuttoninfo(XEvent *e, int *b, int *x, int *y) { | |||
| 232 | *b=*b==4096?5:*b==2048?4:*b==1024?3:*b==512?2:*b==256?1:-1; | 233 | *b=*b==4096?5:*b==2048?4:*b==1024?3:*b==512?2:*b==256?1:-1; |
| 233 | *x = e->xbutton.x/xw.cw; | 234 | *x = e->xbutton.x/xw.cw; |
| 234 | *y = e->xbutton.y/xw.ch; | 235 | *y = e->xbutton.y/xw.ch; |
| 235 | sel.b[0] = sel.by < sel.ey ? sel.bx : sel.ex; | 236 | sel.b.x = sel.by < sel.ey ? sel.bx : sel.ex; |
| 236 | sel.b[1] = MIN(sel.by, sel.ey); | 237 | sel.b.y = MIN(sel.by, sel.ey); |
| 237 | sel.e[0] = sel.by < sel.ey ? sel.ex : sel.bx; | 238 | sel.e.x = sel.by < sel.ey ? sel.ex : sel.bx; |
| 238 | sel.e[1] = MAX(sel.by, sel.ey); | 239 | sel.e.y = MAX(sel.by, sel.ey); |
| 239 | } | 240 | } |
| 240 | 241 | ||
| 241 | static void bpress(XEvent *e) { | 242 | static void bpress(XEvent *e) { |
| @@ -249,7 +250,7 @@ static char *getseltext() { | |||
| 249 | int ls, x, y, sz; | 250 | int ls, x, y, sz; |
| 250 | if(sel.bx == -1) | 251 | if(sel.bx == -1) |
| 251 | return NULL; | 252 | return NULL; |
| 252 | sz = (term.col+1) * (sel.e[1]-sel.b[1]+1); | 253 | sz = (term.col+1) * (sel.e.y-sel.b.y+1); |
| 253 | ptr = str = malloc(sz); | 254 | ptr = str = malloc(sz); |
| 254 | for(y = 0; y < term.row; y++) { | 255 | for(y = 0; y < term.row; y++) { |
| 255 | for(x = 0; x < term.col; x++) | 256 | for(x = 0; x < term.col; x++) |
