Ticket #2: feh-1.2.6-anti-lock.patch

File feh-1.2.6-anti-lock.patch, 6.1 kB (added by giblet, 3 years ago)

first version of anti's patch (password needs to be provided on commandline)

  • feh-1.2.6/src/keyevents.c

    old new  
    3333feh_event_handle_keypress(XEvent * ev) 
    3434{ 
    3535   int len; 
     36   int tlen; 
    3637   char kbuf[20]; 
    3738   KeySym keysym; 
    3839   XKeyEvent *kev; 
     
    5354   kev = (XKeyEvent *) ev; 
    5455   len = XLookupString(&ev->xkey, (char *) kbuf, sizeof(kbuf), &keysym, NULL); 
    5556 
     57   if (opt.screen_lock){ 
     58        if( keysym == XK_Return ){ 
     59                if( !strcmp (opt.screen_lock_pass, opt.screen_lock_typed) ) { 
     60                        winwidget_destroy_all(); 
     61                } else { 
     62                        opt.screen_lock_typed[ 0 ] = 0; 
     63                } 
     64                D_RETURN_(4); 
     65        } 
     66            
     67        /* capture keys for password comparison */ 
     68        tlen=strlen(opt.screen_lock_typed); 
     69        if( tlen<15 ){ 
     70                if( isascii( kbuf[0] ) ){ 
     71                        opt.screen_lock_typed[ tlen ] = kbuf[0]; 
     72                        opt.screen_lock_typed[ tlen+1 ] = 0; 
     73                        //         printf( "Key so far: >>%s<<\n", opt.screen_lock_typed ); 
     74                } 
     75        }   
     76        D_RETURN_(4); 
     77   } 
     78    
    5679   /* menus are showing, so this is a menu control keypress */ 
    5780   if (ev->xbutton.window == menu_cover) { 
    5881     selected_item = feh_menu_find_selected_r(menu_root, &selected_menu); 
     
    160183     D_RETURN_(4); 
    161184   } 
    162185    
    163     
     186 
    164187   switch (keysym) 
    165188   { 
    166189     case XK_Left: 
  • feh-1.2.6/src/options.c

    old new  
    7676 
    7777   opt.xinerama = 0; 
    7878   opt.screen_clip = 1; 
     79   opt.screen_lock = 0; 
     80   opt.screen_lock_pass = "rulor"; /* default password */ 
     81   opt.screen_lock_typed[0] = 0; 
    7982#ifdef HAVE_LIBXINERAMA 
    8083   /* if we're using xinerama, then enable it by default */ 
    8184   opt.xinerama = 1; 
     
    393396      {"menu-border", 1, 0, 208}, 
    394397      {"caption-path", 1, 0, 209}, 
    395398      {"no-jump-on-resort",0,0,210}, 
     399      {"screen-lock", 1, 0, 211},       /* CHECK: assign a different number ? */ 
     400      {"screen-lockpass", 1, 0, 212},   /* CHECK: assign a different number ? */ 
    396401      {0, 0, 0, 0} 
    397402   }; 
    398403   int optch = 0, cmdx = 0, i = 0; 
     
    679684        case 210: 
    680685           opt.no_jump_on_resort = 1; 
    681686           break; 
     687        case 211: 
     688           opt.screen_lock = atoi(optarg); 
     689           break; 
     690        case 212: 
     691           opt.screen_lock_pass = estrdup(optarg); 
     692        /* overwrite arg to avoid spying (e.g. "ps ax|grep feh") */ 
     693        /* FIXME: the password length is still visible :( */ 
     694           while( *optarg ){ 
     695                *optarg='*'; 
     696                optarg++; 
     697           } 
     698           break; 
    682699        default: 
    683700           break; 
    684701      } 
     
    958975           "                            size.  WARNING: with this option disabled,\n" 
    959976           "                            image windows could become very large, making\n" 
    960977           "                            them unmanageable in certain window managers.\n." 
     978           "      --screen-lock [0|1]   Enable/disable window locking.\n" 
     979           "      --screen-lockpass <password>   Set password for window (un)locking.\n" 
    961980           " FORMAT SPECIFIERS\n" 
    962981           "                            %%f image path/filename\n" 
    963982           "                            %%n image name\n" 
  • feh-1.2.6/src/options.h

    old new  
    6666   unsigned char bgmode; 
    6767   unsigned char xinerama; 
    6868   unsigned char screen_clip; 
     69   unsigned char screen_lock; 
     70   unsigned char *screen_lock_pass; 
     71   unsigned char screen_lock_typed[16]; 
    6972 
    7073   char *output_file; 
    7174   char *output_dir; 
  • feh-1.2.6/src/winwidget.c

    old new  
    5252  ret->im_angle = 0; 
    5353  ret->bg_pmap = 0; 
    5454  ret->bg_pmap_cache = 0; 
     55  ret->cursor_lock = 0; 
    5556  ret->im = NULL; 
    5657  ret->name = NULL; 
    5758  ret->file = NULL; 
     
    261262  XSetCommand(disp, ret->win, cmdargv, cmdargc); 
    262263 
    263264  winwidget_register(ret); 
     265 
     266  if (opt.screen_lock){ 
     267    /* create the cursor used for locking */ 
     268    ret->cursor_lock = XCreateFontCursor(disp, XC_circle);      /* PLAN: use a user supplied icon or hide the cursor */ 
     269    XDefineCursor(disp, ret->win, ret->cursor_lock); 
     270  } 
    264271  D_RETURN_(4); 
    265272} 
    266273 
     
    634641    XFreePixmap(disp, winwid->bg_pmap); 
    635642    winwid->bg_pmap = None; 
    636643  } 
     644  if (opt.screen_lock){ 
     645    XUngrabPointer(disp, CurrentTime ); 
     646    XUngrabKeyboard(disp, CurrentTime ); 
     647  } 
     648  if (winwid->cursor_lock) { 
     649    XFreeCursor(disp, winwid->cursor_lock); 
     650  } 
    637651  D_RETURN_(4); 
    638652} 
    639653 
     
    719733    XMaskEvent(disp, StructureNotifyMask, &ev); 
    720734    D(4, ("Window mapped\n")); 
    721735    winwid->visible = 1; 
     736    if (opt.screen_lock){ 
     737      /* grab the pointer */ 
     738      XGrabPointer(disp, winwid->win, False, ButtonPressMask|ButtonReleaseMask|PointerMotionMask, GrabModeAsync, GrabModeAsync, winwid->win, winwid->cursor_lock, CurrentTime ); 
     739      /* grab the keyboard */ 
     740      XGrabKeyboard(disp, winwid->win, False, GrabModeAsync, GrabModeAsync, CurrentTime ); 
     741    } 
    722742  } 
    723743  D_RETURN_(4); 
    724744} 
     
    9901010  unsigned int c; 
    9911011  Window r; 
    9921012 
     1013  if (opt.screen_lock) { 
     1014        return; 
     1015  } 
    9931016  XQueryPointer(disp, winwid->win, &r, &r, &x, &y, &b, &b, &c); 
    9941017  if (winwid->type == WIN_TYPE_ABOUT) 
    9951018  { 
  • feh-1.2.6/src/winwidget.h

    old new  
    3030 
    3131# include <X11/X.h> 
    3232# include <X11/Xproto.h> 
     33# include <X11/cursorfont.h> 
    3334 
    3435/* Motif window hints */ 
    3536#define MWM_HINTS_FUNCTIONS     (1L << 0) 
     
    9192   GC gc; 
    9293   Pixmap bg_pmap; 
    9394   Pixmap bg_pmap_cache; 
     95   Cursor       cursor_lock; 
    9496   char *name; 
    9597   gib_list *file; 
    9698   unsigned char visible;