Ticket #2: feh-1.2.6-an-screenlock.patch
| File feh-1.2.6-an-screenlock.patch, 8.4 kB (added by giblet, 3 years ago) |
|---|
-
feh-1.2.6/src/Makefile.am
old new 16 16 utils.c utils.h keyevents.c timers.c timers.h list.c collage.c debug.h \ 17 17 events.c events.h support.c support.h \ 18 18 thumbnail.c thumbnail.h ipc.c ipc.h 19 feh_LDADD = -lX11 @IMLIB_LIBS@ @GIBLIB_LIBS@ 19 feh_LDADD = -lX11 @IMLIB_LIBS@ @GIBLIB_LIBS@ -lcrypt 20 20 21 21 images_DATA = about.png menubg_default.png menubg_sky.png \ 22 22 menubg_chrome.png menubg_brushed.png \ -
feh-1.2.6/src/feh.h
old new 57 57 #include <sys/wait.h> 58 58 #include <math.h> 59 59 60 61 #define _XOPEN_SOURCE 62 #include <unistd.h> 63 #include <shadow.h> 64 65 60 66 #include <Imlib2.h> 61 67 #include <giblib/giblib.h> 62 68 -
feh-1.2.6/src/keyevents.c
old new 29 29 #include "winwidget.h" 30 30 #include "options.h" 31 31 32 int 33 feh_check_passwd( char* pass ) 34 { 35 char *cpass = NULL; 36 37 cpass = crypt( pass, opt.screen_lock_pass ); 38 // printf( "DEBUG: Crypted password: %s\n", cpass ); 39 if( !strcmp( opt.screen_lock_pass, cpass ) ){ 40 return( 1 ); 41 } 42 return( 0 ); 43 } 44 32 45 void 33 46 feh_event_handle_keypress(XEvent * ev) 34 47 { 35 48 int len; 49 int tlen; 36 50 char kbuf[20]; 37 51 KeySym keysym; 38 52 XKeyEvent *kev; … … 53 67 kev = (XKeyEvent *) ev; 54 68 len = XLookupString(&ev->xkey, (char *) kbuf, sizeof(kbuf), &keysym, NULL); 55 69 70 if (opt.screen_lock){ 71 /* for testing / 72 if( keysym == XK_Escape ){ 73 winwidget_destroy_all(); 74 } 75 /* end testing */ 76 if( keysym == XK_Return ){ 77 if( feh_check_passwd( opt.screen_lock_typed ) ){ 78 // if( !strcmp (opt.screen_lock_pass, opt.screen_lock_typed) ) { 79 winwidget_destroy_all(); 80 } else { 81 opt.screen_lock_typed[ 0 ] = 0; 82 } 83 D_RETURN_(4); 84 } 85 86 /* capture keys for password comparison */ 87 tlen=strlen(opt.screen_lock_typed); 88 if( tlen<15 ){ 89 if( isascii( kbuf[0] ) ){ 90 opt.screen_lock_typed[ tlen ] = kbuf[0]; 91 opt.screen_lock_typed[ tlen+1 ] = 0; 92 // printf( "Key so far: >>%s<<\n", opt.screen_lock_typed ); 93 } 94 } 95 D_RETURN_(4); 96 } 97 56 98 /* menus are showing, so this is a menu control keypress */ 57 99 if (ev->xbutton.window == menu_cover) { 58 100 selected_item = feh_menu_find_selected_r(menu_root, &selected_menu); … … 160 202 D_RETURN_(4); 161 203 } 162 204 163 205 164 206 switch (keysym) 165 207 { 166 208 case XK_Left: -
feh-1.2.6/src/main.c
old new 43 43 44 44 init_parse_options(argc, argv); 45 45 46 /* drop root privileges */ 47 setuid( getuid( ) ); /* getuid gets the _real_ uid, setuid sets the _effective_ uid */ 46 48 init_x_and_imlib(); 47 49 48 50 feh_event_init(); -
feh-1.2.6/src/options.c
old new 76 76 77 77 opt.xinerama = 0; 78 78 opt.screen_clip = 1; 79 opt.screen_lock = 0; 80 opt.screen_lock_pass = "qPfnQ7bvq2/zg"; 81 opt.screen_lock_typed[0] = 0; 79 82 #ifdef HAVE_LIBXINERAMA 80 83 /* if we're using xinerama, then enable it by default */ 81 84 opt.xinerama = 1; … … 393 396 {"menu-border", 1, 0, 208}, 394 397 {"caption-path", 1, 0, 209}, 395 398 {"no-jump-on-resort",0,0,210}, 399 {"screen-lock", 1, 0, 211}, /* CHECK: assign a different number ? */ 396 400 {0, 0, 0, 0} 397 401 }; 398 402 int optch = 0, cmdx = 0, i = 0; … … 679 683 case 210: 680 684 opt.no_jump_on_resort = 1; 681 685 break; 686 case 211: 687 opt.screen_lock = atoi(optarg); 688 if( opt.screen_lock ){ 689 char *username = NULL; 690 struct passwd *pwd = NULL; 691 struct spwd *pwds = NULL; 692 693 /* get the username */ 694 username = getenv( "LOGNAME" ); 695 /* get the passwd entry */ 696 pwd = getpwnam( username ); 697 if( !strcmp( pwd->pw_passwd, "x" ) ){ 698 /* system uses shadow passwd */ 699 pwds = getspnam( username ); 700 if( !pwds ){ 701 /* can't access shadow passwords :( */ 702 printf( "On systems with shadow passwd, feh needs to be set uid root.\n" ); 703 /* allow exit without passwd check to keep user from locking himself out of the system */ 704 exit( 1 ); 705 } 706 opt.screen_lock_pass = pwds->sp_pwdp; 707 }else{ 708 opt.screen_lock_pass = pwd->pw_passwd; 709 } 710 711 } 712 break; 682 713 default: 683 714 break; 684 715 } … … 958 989 " size. WARNING: with this option disabled,\n" 959 990 " image windows could become very large, making\n" 960 991 " them unmanageable in certain window managers.\n." 992 " --screen-lock [0|1] Enable/disable window locking.\n" 961 993 " FORMAT SPECIFIERS\n" 962 994 " %%f image path/filename\n" 963 995 " %%n image name\n" -
feh-1.2.6/src/options.h
old new 66 66 unsigned char bgmode; 67 67 unsigned char xinerama; 68 68 unsigned char screen_clip; 69 unsigned char screen_lock; 70 unsigned char *screen_lock_pass; 71 unsigned char screen_lock_typed[16]; 69 72 70 73 char *output_file; 71 74 char *output_dir; -
feh-1.2.6/src/winwidget.c
old new 52 52 ret->im_angle = 0; 53 53 ret->bg_pmap = 0; 54 54 ret->bg_pmap_cache = 0; 55 ret->cursor_lock = 0; 55 56 ret->im = NULL; 56 57 ret->name = NULL; 57 58 ret->file = NULL; … … 261 262 XSetCommand(disp, ret->win, cmdargv, cmdargc); 262 263 263 264 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 } 264 271 D_RETURN_(4); 265 272 } 266 273 … … 634 641 XFreePixmap(disp, winwid->bg_pmap); 635 642 winwid->bg_pmap = None; 636 643 } 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 } 637 651 D_RETURN_(4); 638 652 } 639 653 … … 719 733 XMaskEvent(disp, StructureNotifyMask, &ev); 720 734 D(4, ("Window mapped\n")); 721 735 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 } 722 742 } 723 743 D_RETURN_(4); 724 744 } … … 990 1010 unsigned int c; 991 1011 Window r; 992 1012 1013 if (opt.screen_lock) { 1014 return; 1015 } 993 1016 XQueryPointer(disp, winwid->win, &r, &r, &x, &y, &b, &b, &c); 994 1017 if (winwid->type == WIN_TYPE_ABOUT) 995 1018 { -
feh-1.2.6/src/winwidget.h
old new 30 30 31 31 # include <X11/X.h> 32 32 # include <X11/Xproto.h> 33 # include <X11/cursorfont.h> 33 34 34 35 /* Motif window hints */ 35 36 #define MWM_HINTS_FUNCTIONS (1L << 0) … … 91 92 GC gc; 92 93 Pixmap bg_pmap; 93 94 Pixmap bg_pmap_cache; 95 Cursor cursor_lock; 94 96 char *name; 95 97 gib_list *file; 96 98 unsigned char visible;
