Linked thumbnails to files
This commit is contained in:
		
							parent
							
								
									dc04bdc72f
								
							
						
					
					
						commit
						095217b26f
					
				
							
								
								
									
										16
									
								
								main.c
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								main.c
									
									
									
									
									
								
							| @ -55,8 +55,6 @@ const char **filenames; | |||||||
| int filecnt, fileidx; | int filecnt, fileidx; | ||||||
| size_t filesize; | size_t filesize; | ||||||
| 
 | 
 | ||||||
| int tns_loaded; |  | ||||||
| 
 |  | ||||||
| #define TITLE_LEN 256 | #define TITLE_LEN 256 | ||||||
| char win_title[TITLE_LEN]; | char win_title[TITLE_LEN]; | ||||||
| 
 | 
 | ||||||
| @ -131,10 +129,8 @@ int main(int argc, char **argv) { | |||||||
| 	win_open(&win); | 	win_open(&win); | ||||||
| 	img_init(&img, &win); | 	img_init(&img, &win); | ||||||
| 
 | 
 | ||||||
| 	if (options->thumbnails) { | 	if (options->thumbnails) | ||||||
| 		tns_loaded = 0; |  | ||||||
| 		tns_init(&tns, filecnt); | 		tns_init(&tns, filecnt); | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	if (options->thumbnails == 2) { | 	if (options->thumbnails == 2) { | ||||||
| 		mode = MODE_THUMBS; | 		mode = MODE_THUMBS; | ||||||
| @ -161,7 +157,7 @@ void update_title() { | |||||||
| 	if (mode == MODE_THUMBS) { | 	if (mode == MODE_THUMBS) { | ||||||
| 		n = snprintf(win_title, TITLE_LEN, "sxiv: [%d/%d] %s", | 		n = snprintf(win_title, TITLE_LEN, "sxiv: [%d/%d] %s", | ||||||
| 		             tns.cnt ? tns.sel + 1 : 0, tns.cnt, | 		             tns.cnt ? tns.sel + 1 : 0, tns.cnt, | ||||||
| 								 tns.cnt ? tns.thumbs[tns.sel].filename : ""); | 		             tns.cnt ? filenames[tns.sel] : ""); | ||||||
| 	} else { | 	} else { | ||||||
| 		if (img.valid) { | 		if (img.valid) { | ||||||
| 			size = filesize; | 			size = filesize; | ||||||
| @ -490,17 +486,17 @@ void run() { | |||||||
| 	timeout = 0; | 	timeout = 0; | ||||||
| 
 | 
 | ||||||
| 	while (1) { | 	while (1) { | ||||||
| 		if (mode == MODE_THUMBS && tns_loaded < filecnt) { | 		if (mode == MODE_THUMBS && tns.cnt < filecnt) { | ||||||
| 			win_set_cursor(&win, CURSOR_WATCH); | 			win_set_cursor(&win, CURSOR_WATCH); | ||||||
| 			gettimeofday(&t0, 0); | 			gettimeofday(&t0, 0); | ||||||
| 
 | 
 | ||||||
| 			while (!XPending(win.env.dpy) && tns_loaded < filecnt) { | 			while (!XPending(win.env.dpy) && tns.cnt < filecnt) { | ||||||
| 				tns_load(&tns, &win, filenames[tns_loaded++]); | 				tns_load(&tns, &win, filenames[tns.cnt]); | ||||||
| 				gettimeofday(&t, 0); | 				gettimeofday(&t, 0); | ||||||
| 				if (TV_TO_DOUBLE(t) - TV_TO_DOUBLE(t0) >= 0.25) | 				if (TV_TO_DOUBLE(t) - TV_TO_DOUBLE(t0) >= 0.25) | ||||||
| 					break; | 					break; | ||||||
| 			} | 			} | ||||||
| 			if (tns_loaded == filecnt) | 			if (tns.cnt == filecnt) | ||||||
| 				win_set_cursor(&win, CURSOR_ARROW); | 				win_set_cursor(&win, CURSOR_ARROW); | ||||||
| 			if (!XPending(win.env.dpy)) { | 			if (!XPending(win.env.dpy)) { | ||||||
| 				redraw(); | 				redraw(); | ||||||
|  | |||||||
							
								
								
									
										10
									
								
								thumbs.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								thumbs.c
									
									
									
									
									
								
							| @ -25,6 +25,7 @@ | |||||||
| #include "thumbs.h" | #include "thumbs.h" | ||||||
| #include "util.h" | #include "util.h" | ||||||
| 
 | 
 | ||||||
|  | extern Imlib_Image *im_broken; | ||||||
| const int thumb_dim = THUMB_SIZE + 10; | const int thumb_dim = THUMB_SIZE + 10; | ||||||
| 
 | 
 | ||||||
| void tns_init(tns_t *tns, int cnt) { | void tns_init(tns_t *tns, int cnt) { | ||||||
| @ -57,19 +58,20 @@ void tns_load(tns_t *tns, win_t *win, const char *filename) { | |||||||
| 	if (!tns || !win || !filename) | 	if (!tns || !win || !filename) | ||||||
| 		return; | 		return; | ||||||
| 
 | 
 | ||||||
| 	if (!(im = imlib_load_image(filename))) | 	if ((im = imlib_load_image(filename))) | ||||||
| 		return; |  | ||||||
| 
 |  | ||||||
| 		imlib_context_set_image(im); | 		imlib_context_set_image(im); | ||||||
|  | 	else | ||||||
|  | 		imlib_context_set_image(im_broken); | ||||||
| 
 | 
 | ||||||
| 	w = imlib_image_get_width(); | 	w = imlib_image_get_width(); | ||||||
| 	h = imlib_image_get_height(); | 	h = imlib_image_get_height(); | ||||||
| 	zw = (float) THUMB_SIZE / (float) w; | 	zw = (float) THUMB_SIZE / (float) w; | ||||||
| 	zh = (float) THUMB_SIZE / (float) h; | 	zh = (float) THUMB_SIZE / (float) h; | ||||||
| 	z = MIN(zw, zh); | 	z = MIN(zw, zh); | ||||||
|  | 	if (!im && z > 1.0) | ||||||
|  | 		z = 1.0; | ||||||
| 
 | 
 | ||||||
| 	t = &tns->thumbs[tns->cnt++]; | 	t = &tns->thumbs[tns->cnt++]; | ||||||
| 	t->filename = filename; |  | ||||||
| 	t->w = z * w; | 	t->w = z * w; | ||||||
| 	t->h = z * h; | 	t->h = z * h; | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Bert
						Bert