| @@ -152,7 +152,8 @@ void tns_clean_cache(tns_t *tns) |
| 152 | 152 | | } |
| 153 | 153 | | |
| 154 | 154 | | |
| 155 | | − | void tns_init(tns_t *tns, const fileinfo_t *files, int cnt, int *sel, win_t *win) |
| 155 | + | void tns_init(tns_t *tns, const fileinfo_t *files, const int *cnt, int *sel, |
| 156 | + | win_t *win) |
| 156 | 157 | | { |
| 157 | 158 | | int len; |
| 158 | 159 | | const char *homedir, *dsuffix = ""; |
| @@ -160,9 +161,9 @@ void tns_init(tns_t *tns, const fileinfo_t *files, int cnt, int *sel, win_t *win |
| 160 | 161 | | if (tns == NULL) |
| 161 | 162 | | return; |
| 162 | 163 | | |
| 163 | | − | if (cnt > 0) { |
| 164 | | − | tns->thumbs = (thumb_t*) s_malloc(cnt * sizeof(thumb_t)); |
| 165 | | − | memset(tns->thumbs, 0, cnt * sizeof(thumb_t)); |
| 164 | + | if (*cnt > 0) { |
| 165 | + | tns->thumbs = (thumb_t*) s_malloc(*cnt * sizeof(thumb_t)); |
| 166 | + | memset(tns->thumbs, 0, *cnt * sizeof(thumb_t)); |
| 166 | 167 | | } else { |
| 167 | 168 | | tns->thumbs = NULL; |
| 168 | 169 | | } |
| @@ -198,7 +199,7 @@ void tns_free(tns_t *tns) |
| 198 | 199 | | return; |
| 199 | 200 | | |
| 200 | 201 | | if (tns->thumbs != NULL) { |
| 201 | | − | for (i = 0; i < tns->cnt; i++) { |
| 202 | + | for (i = 0; i < *tns->cnt; i++) { |
| 202 | 203 | | if (tns->thumbs[i].im != NULL) { |
| 203 | 204 | | imlib_context_set_image(tns->thumbs[i].im); |
| 204 | 205 | | imlib_free_image(); |
| @@ -247,7 +248,7 @@ bool tns_load(tns_t *tns, int n, bool force) |
| 247 | 248 | | |
| 248 | 249 | | if (tns == NULL || tns->thumbs == NULL) |
| 249 | 250 | | return false; |
| 250 | | − | if (n < 0 || n >= tns->cnt) |
| 251 | + | if (n < 0 || n >= *tns->cnt) |
| 251 | 252 | | return false; |
| 252 | 253 | | file = &tns->files[n]; |
| 253 | 254 | | if (file->name == NULL || file->path == NULL) |
| @@ -351,7 +352,7 @@ void tns_unload(tns_t *tns, int n) |
| 351 | 352 | | |
| 352 | 353 | | if (tns == NULL || tns->thumbs == NULL) |
| 353 | 354 | | return; |
| 354 | | − | if (n < 0 || n >= tns->cnt) |
| 355 | + | if (n < 0 || n >= *tns->cnt) |
| 355 | 356 | | return; |
| 356 | 357 | | |
| 357 | 358 | | t = &tns->thumbs[n]; |
| @@ -409,13 +410,13 @@ void tns_render(tns_t *tns) |
| 409 | 410 | | tns->cols = MAX(1, win->w / tns->dim); |
| 410 | 411 | | tns->rows = MAX(1, win->h / tns->dim); |
| 411 | 412 | | |
| 412 | | − | if (tns->cnt < tns->cols * tns->rows) { |
| 413 | + | if (*tns->cnt < tns->cols * tns->rows) { |
| 413 | 414 | | tns->first = 0; |
| 414 | | − | cnt = tns->cnt; |
| 415 | + | cnt = *tns->cnt; |
| 415 | 416 | | } else { |
| 416 | 417 | | tns_check_view(tns, false); |
| 417 | 418 | | cnt = tns->cols * tns->rows; |
| 418 | | − | if ((r = tns->first + cnt - tns->cnt) >= tns->cols) |
| 419 | + | if ((r = tns->first + cnt - *tns->cnt) >= tns->cols) |
| 419 | 420 | | tns->first -= r - r % tns->cols; |
| 420 | 421 | | if (r > 0) |
| 421 | 422 | | cnt -= r % tns->cols; |
| @@ -423,7 +424,7 @@ void tns_render(tns_t *tns) |
| 423 | 424 | | r = cnt % tns->cols ? 1 : 0; |
| 424 | 425 | | tns->x = x = (win->w - MIN(cnt, tns->cols) * tns->dim) / 2 + tns->bw + 3; |
| 425 | 426 | | tns->y = y = (win->h - (cnt / tns->cols + r) * tns->dim) / 2 + tns->bw + 3; |
| 426 | | − | tns->loadnext = tns->cnt; |
| 427 | + | tns->loadnext = *tns->cnt; |
| 427 | 428 | | tns->end = tns->first + cnt; |
| 428 | 429 | | |
| 429 | 430 | | for (i = tns->r_first; i < tns->r_end; i++) { |
| @@ -461,7 +462,7 @@ void tns_mark(tns_t *tns, int n, bool mark) |
| 461 | 462 | | if (tns == NULL || tns->thumbs == NULL || tns->win == NULL) |
| 462 | 463 | | return; |
| 463 | 464 | | |
| 464 | | − | if (n >= 0 && n < tns->cnt && tns->thumbs[n].im != NULL) { |
| 465 | + | if (n >= 0 && n < *tns->cnt && tns->thumbs[n].im != NULL) { |
| 465 | 466 | | win_t *win = tns->win; |
| 466 | 467 | | thumb_t *t = &tns->thumbs[n]; |
| 467 | 468 | | unsigned long col = win->fullscreen ? win->fscol : win->bgcol; |
| @@ -485,7 +486,7 @@ void tns_highlight(tns_t *tns, int n, bool hl) |
| 485 | 486 | | if (tns == NULL || tns->thumbs == NULL || tns->win == NULL) |
| 486 | 487 | | return; |
| 487 | 488 | | |
| 488 | | − | if (n >= 0 && n < tns->cnt && tns->thumbs[n].im != NULL) { |
| 489 | + | if (n >= 0 && n < *tns->cnt && tns->thumbs[n].im != NULL) { |
| 489 | 490 | | win_t *win = tns->win; |
| 490 | 491 | | thumb_t *t = &tns->thumbs[n]; |
| 491 | 492 | | unsigned long col; |
| @@ -519,15 +520,15 @@ bool tns_move_selection(tns_t *tns, direction_t dir, int cnt) |
| 519 | 520 | | *tns->sel = MAX(*tns->sel - cnt * tns->cols, *tns->sel % tns->cols); |
| 520 | 521 | | break; |
| 521 | 522 | | case DIR_DOWN: |
| 522 | | − | max = tns->cols * ((tns->cnt - 1) / tns->cols) + |
| 523 | | − | MIN((tns->cnt - 1) % tns->cols, *tns->sel % tns->cols); |
| 523 | + | max = tns->cols * ((*tns->cnt - 1) / tns->cols) + |
| 524 | + | MIN((*tns->cnt - 1) % tns->cols, *tns->sel % tns->cols); |
| 524 | 525 | | *tns->sel = MIN(*tns->sel + cnt * tns->cols, max); |
| 525 | 526 | | break; |
| 526 | 527 | | case DIR_LEFT: |
| 527 | 528 | | *tns->sel = MAX(*tns->sel - cnt, 0); |
| 528 | 529 | | break; |
| 529 | 530 | | case DIR_RIGHT: |
| 530 | | − | *tns->sel = MIN(*tns->sel + cnt, tns->cnt - 1); |
| 531 | + | *tns->sel = MIN(*tns->sel + cnt, *tns->cnt - 1); |
| 531 | 532 | | break; |
| 532 | 533 | | } |
| 533 | 534 | | |
| @@ -551,9 +552,9 @@ bool tns_scroll(tns_t *tns, direction_t dir, bool screen) |
| 551 | 552 | | d = tns->cols * (screen ? tns->rows : 1); |
| 552 | 553 | | |
| 553 | 554 | | if (dir == DIR_DOWN) { |
| 554 | | − | max = tns->cnt - tns->cols * tns->rows; |
| 555 | | − | if (tns->cnt % tns->cols != 0) |
| 556 | | − | max += tns->cols - tns->cnt % tns->cols; |
| 555 | + | max = *tns->cnt - tns->cols * tns->rows; |
| 556 | + | if (*tns->cnt % tns->cols != 0) |
| 557 | + | max += tns->cols - *tns->cnt % tns->cols; |
| 557 | 558 | | tns->first = MIN(tns->first + d, max); |
| 558 | 559 | | } else if (dir == DIR_UP) { |
| 559 | 560 | | tns->first = MAX(tns->first - d, 0); |
| @@ -582,7 +583,7 @@ bool tns_zoom(tns_t *tns, int d) |
| 582 | 583 | | tns->dim = thumb_sizes[tns->zl] + 2 * tns->bw + 6; |
| 583 | 584 | | |
| 584 | 585 | | if (tns->zl != oldzl) { |
| 585 | | − | for (i = 0; i < tns->cnt; i++) |
| 586 | + | for (i = 0; i < *tns->cnt; i++) |
| 586 | 587 | | tns_unload(tns, i); |
| 587 | 588 | | tns->dirty = true; |
| 588 | 589 | | } |
| @@ -600,7 +601,7 @@ int tns_translate(tns_t *tns, int x, int y) |
| 600 | 601 | | |
| 601 | 602 | | n = tns->first + (y - tns->y) / tns->dim * tns->cols + |
| 602 | 603 | | (x - tns->x) / tns->dim; |
| 603 | | − | if (n >= tns->cnt) |
| 604 | + | if (n >= *tns->cnt) |
| 604 | 605 | | n = -1; |
| 605 | 606 | | |
| 606 | 607 | | return n; |