commit d832e4524b6400ee981a179b281ab0389add41b6
parent cef88c8da511cdb97cdd37250514bf63bdc8c942
Author: Tomas Hlavaty <tom@logand.com>
Date: Fri, 13 Sep 2019 02:16:39 +0200
more responsive navigation
Diffstat:
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/osmtile.c b/osmtile.c
@@ -106,7 +106,7 @@ static int probe(char *path) {
return 0;
}
-static int cached_file(int z, int x, int y, char *dir, char file[4096]) {
+static int cached_file(int z, int x, int y, char *dir, char file[4096], int draw) {
int max = (1 << z) - 1;
if(x < 0) x = max;
if(y < 0) y = max;
@@ -118,16 +118,16 @@ static int cached_file(int z, int x, int y, char *dir, char file[4096]) {
n = snprintf(file, 4096, "%s/%s.png", dir, zxy);
if(n < 0 || 4096 < n) fail(1, "file path error\n");
if(probe(file)) return 1;
+ if(draw) return 0;
/* download tile in background */
+ char *args[] = {"osmtile-download", zxy, dir, NULL};
int pid = fork();
if(pid < 0) fail(1, "fork failed\n");
- if(pid) { /* parent */
- return 0;
+ if(!pid) { /* child */
+ execvp(*args, args);
+ fail(1, "exec %s failed\n", *args);
}
- /* child */
- char *args[] = {"osmtile-download", zxy, dir, NULL};
- execvp(*args, args);
- fail(1, "exec %s failed\n", *args);
+ return 0;
}
static void screen_size(int *w, int *h) {
@@ -179,21 +179,24 @@ static int main_tty(int argc, char *argv[]) {
for(;;) {
FILE *p = popen("w3mimgdisplay", "w");
if(!p) fail(1, "popen w3mimgdisplay failed\n");
- int full = 1;
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
char file[4096];
- if(cached_file(z, x + i - 1, y + j - 1, dir, file)) {
+ if(cached_file(z, x + i - 1, y + j - 1, dir, file, 1)) {
int w = min(width, height) / 3;
int h = w;
fprintf(p, "0;1;%d;%d;%d;%d;;;;;%s\n", w * i, h * j, w, h, file);
- } else {
- full = 0;
}
}
}
pclose(p);
- unsigned char c = key(full ? 0 : 1);
+ for(int i = 0; i < 3; i++) {
+ for(int j = 0; j < 3; j++) {
+ char file[4096];
+ cached_file(z, x + i - 1, y + j - 1, dir, file, 0);
+ }
+ }
+ unsigned char c = key(1);
switch(c) {
case 27: /* esc */
c = key(0);