--- pv.old/src/init_video.c +++ pv/src/init_video.c @@ -24,6 +24,11 @@ #include "pv.h" +void grabfocus (void) +{ // Local change + SDL_WM_GrabInput (SDL_GRAB_ON); +} + void init_video_lib(t_pv *p) { if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTTHREAD) < 0 ) @@ -31,11 +36,17 @@ fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); exit(1); } + // Local change + SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY , + SDL_DEFAULT_REPEAT_INTERVAL); + // grabfocus(); // @@@ + atexit(SDL_Quit); } void init_video(t_pv *p, int w, int h, int bits) { + putenv ("SDL_VIDEO_CENTERED=1"); // Local change p->screen = SDL_SetVideoMode(w, h, bits, --- pv.old/src/keyboard.c +++ pv/src/keyboard.c @@ -41,7 +41,13 @@ mask = (SDL_KEYDOWNMASK | SDL_KEYUPMASK | SDL_VIDEORESIZEMASK | SDL_QUITMASK); while (!p->done) { - found = SDL_PeepEvents(events, EVENTS_NUM, SDL_GETEVENT, mask); + do + { // Local change + found = SDL_PeepEvents (events, + EVENTS_NUM, SDL_GETEVENT, mask); + } + while (found == 0); + for (i = 0; i < found; ++i) { p->event = &events[i]; --- pv.old/src/main_loop.c +++ pv/src/main_loop.c @@ -84,27 +84,43 @@ { int i; - if (p->event->type == SDL_KEYUP) - { - for (i = 0; gl_general_keys_up[i].key; i++) - if (gl_general_keys_up[i].key == p->event->key.keysym.sym) - return (gl_general_keys_up[i].f(p)); + if (p->event->type == SDL_KEYUP) + { // Local keyboard fix + for (i = 0; gl_general_keys_up [i].key; i++) + { + if (gl_general_keys_up [i].key == + p->event->key.keysym.sym) + { + return (gl_general_keys_up[i].f(p)); + } + } + + return (0); } + if (p->event->type == SDL_KEYDOWN) { if (p->event->key.keysym.sym == SDLK_ESCAPE || (p->event->key.keysym.sym == SDLK_q)) return (-1); /* Exit program */ - for (i = 0; gl_general_keys[i].key; i++) - if (gl_general_keys[i].key == p->event->key.keysym.sym) - return (gl_general_keys[i].f(p)); + if (p->multiple_files) { for (i = 0; gl_multi_files_keys[i].key; i++) + { if (gl_multi_files_keys[i].key == p->event->key.keysym.sym) + { return (gl_multi_files_keys[i].f(p)); } } + } + // Local keyboard fix + for (i = 0; gl_general_keys [i].key; i++) + if (gl_general_keys[i].key == + p->event->key.keysym.sym) + return (gl_general_keys [i].f(p)); + } + if (p->event->type == SDL_QUIT) return (-1); if (p->event->type == SDL_VIDEORESIZE) --- pv.old/src/multiple_files.c +++ pv/src/multiple_files.c @@ -175,15 +175,18 @@ { if (p->next_image != 0) /* only if a next image key is pressed, proceed. */ { +#ifdef NOTDEF /* Disable buggy code */ if (p->wait_first_cyl && p->wait_first_img) p->wait_first_cyl--; else +#endif /* Endif NOTDEF */ { if (p->next_image == -1) aff_previous_file(p); if (p->next_image == 1) aff_next_file(p); p->wait_first_img = 1; + p->next_image = 0; /* Work-around for problem */ } } return (0); --- pv.old/src/multiple_files.c +++ pv/src/multiple_files.c @@ -38,7 +38,7 @@ else { if (p->best_file_id == -1) - err_msg("\npv: Can't read any files in paramter."); + err_msg("\npv: Can't read any of the specified files"); else { p->current_file_id = p->best_file_id; --- pv.old/src/Makefile.in +++ pv/src/Makefile.in @@ -117,7 +117,7 @@ DEFS = @DEFS@ -I. -I$(srcdir) -LIBS = @LIBS@ +LIBS = @LIBS@ -L/usr/X11R6/lib -lX11 pv_OBJECTS = main.o add.o aff_fileinfotext.o aff_image.o benchmark.o \ check_arguments.o err_msg.o fullscreen.o get_wm_property.o help.o \ init_caption.o init_video.o keyboard.o load_directory_files.o \ --- pv.old/src/load_image.c +++ pv/src/load_image.c @@ -60,12 +60,43 @@ if (p->img_file) SDL_FreeSurface(p->img_file); p->img_file = new_file; - if (p->img_file->format->palette && p->screen->format->palette) - { - SDL_SetColors(p->screen, p->img_file->format->palette->colors, 0, - p->img_file->format->palette->ncolors); - } - return (0); + +// This code includes two bug fixes: (1) The initial "p->screen" test +// prevents a segmentation fault that occurred in the original ver- +// sion of "pv". (2) If the current screen has a palette, but the cur- +// rent image doesn't, this code resets the screen palette. + + if (p->screen && + p->screen->format && + p->screen->format->palette) + { + if (p->img_file->format->palette) + { + SDL_SetColors + ( + p->screen , + p->img_file->format->palette->colors , + 0 , + p->img_file->format->palette->ncolors + ); + } + else if (0) + { + SDL_PixelFormat *vf = p->screen->format; + SDL_DitherColors + (vf->palette->colors, vf->BitsPerPixel); + + SDL_SetColors + ( + p->screen , + vf->palette->colors , + 0 , + vf->palette->ncolors + ); + } + } + + return (0); } return (0); /* didn't reload pic and don't return other val than 0, or program will segfault */ } --- pv.old/src/pv.c +++ pv/src/pv.c @@ -40,13 +40,34 @@ /* Load image file */ next_file(p); -/* Create SDL X11 Window */ -/* If XFE mode we open a window already resized for the current window manager. */ - if (p->xfe_mode) - init_video(p, p->wm_w - 100, p->wm_h - 100, 0); - else - init_video(p, p->img_file->w, p->img_file->h, p->img_file->format->BitsPerPixel); +/* Create SDL X11 Window */ +/* In XFE mode, we open a window already resized for the current window manager. */ + + if (p->xfe_mode) + { + init_video (p, p->wm_w - 100, p->wm_h - 100, 0); + } + else + { + int w, h; + int pw, ph; + pw = p->win_w; + ph = p->win_h; + + if (pw < (w = p->img_file->w)) pw = w; + if (ph < (h = p->img_file->h)) ph = h; + + if (((w = p->wm_w) > 0) && ((h = p->wm_h) > 0)) + { + w -= 25; + h -= 25; + if (pw > w) pw = w; + if (ph > h) ph = h; + } + + init_video (p, pw, ph, p->img_file->format->BitsPerPixel); + } if (p->auto_resize) autoresize(p, p->win_w, p->win_h, p->img_file->w, p->img_file->h);