X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=xscreensaver;a=blobdiff_plain;f=driver%2Flock.c;h=2aa61f637daa8f9178ee7b31521651f7c9c7d57e;hp=aad2cc6f58530d849f3d0b35849005a197697558;hb=ffd8c0873576a9e3065696a624dce6b766b77062;hpb=8eb2873d7054e705c4e83f22d18c40946a9e2529 diff --git a/driver/lock.c b/driver/lock.c index aad2cc6f..2aa61f63 100644 --- a/driver/lock.c +++ b/driver/lock.c @@ -1,5 +1,5 @@ /* lock.c --- handling the password dialog for locking-mode. - * xscreensaver, Copyright (c) 1993-1998 Jamie Zawinski + * xscreensaver, Copyright (c) 1993-2004 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -19,6 +19,8 @@ #include #include /* for time() */ +#include +#include #include "xscreensaver.h" #include "resources.h" @@ -45,6 +47,11 @@ static void xfree_lock_mode_switch (saver_info *si, Bool lock_p); #endif /* HAVE_XF86VMODE */ +#ifdef HAVE_XF86MISCSETGRABKEYSSTATE +# include + static void xfree_lock_grab_smasher (saver_info *si, Bool lock_p); +#endif /* HAVE_XF86MISCSETGRABKEYSSTATE */ + #ifdef _VROOT_H_ ERROR! You must not include vroot.h in this file. @@ -148,8 +155,9 @@ make_passwd_window (saver_info *si) Screen *screen; Colormap cmap; char *f; + saver_screen_info *ssi = &si->screens [mouse_screen (si)]; - pw->prompt_screen = &si->screens [mouse_screen (si)]; + pw->prompt_screen = ssi; if (si->prefs.verbose_p) fprintf (stderr, "%s: %d: creating password dialog.\n", blurb(), pw->prompt_screen->number); @@ -185,7 +193,7 @@ make_passwd_window (saver_info *si) pw->heading_label = s; } - pw->user_string = (p && p->pw_name ? p->pw_name : "???"); + pw->user_string = strdup (p && p->pw_name ? p->pw_name : "???"); pw->passwd_string = strdup(""); f = get_string_resource ("passwd.headingFont", "Dialog.Font"); @@ -399,7 +407,12 @@ make_passwd_window (saver_info *si) attrmask, &attrs); XSetWindowBackground (si->dpy, si->passwd_dialog, pw->background); - pw->logo_pixmap = xscreensaver_logo (si->dpy, si->passwd_dialog, cmap, + /* We use the default visual, not ssi->visual, so that the logo pixmap's + visual matches that of the si->passwd_dialog window. */ + pw->logo_pixmap = xscreensaver_logo (ssi->screen, + /* ssi->current_visual, */ + DefaultVisualOfScreen(screen), + si->passwd_dialog, cmap, pw->background, &pw->logo_pixels, &pw->logo_npixels, 0, True); @@ -769,6 +782,9 @@ destroy_passwd_window (saver_info *si) Pixel white = WhitePixelOfScreen (ssi->screen); XEvent event; + memset (pw->typed_passwd, 0, sizeof(pw->typed_passwd)); + memset (pw->passwd_string, 0, strlen(pw->passwd_string)); + if (pw->timer) XtRemoveTimeOut (pw->timer); @@ -816,11 +832,15 @@ destroy_passwd_window (saver_info *si) if (pw->body_label) free (pw->body_label); if (pw->user_label) free (pw->user_label); if (pw->passwd_label) free (pw->passwd_label); + if (pw->date_label) free (pw->date_label); + if (pw->user_string) free (pw->user_string); + if (pw->passwd_string) free (pw->passwd_string); if (pw->heading_font) XFreeFont (si->dpy, pw->heading_font); if (pw->body_font) XFreeFont (si->dpy, pw->body_font); if (pw->label_font) XFreeFont (si->dpy, pw->label_font); if (pw->passwd_font) XFreeFont (si->dpy, pw->passwd_font); + if (pw->date_font) XFreeFont (si->dpy, pw->date_font); if (pw->foreground != black && pw->foreground != white) XFreeColors (si->dpy, cmap, &pw->foreground, 1, 0L); @@ -841,21 +861,37 @@ destroy_passwd_window (saver_info *si) if (pw->logo_pixmap) XFreePixmap (si->dpy, pw->logo_pixmap); - if (pw->logo_npixels && pw->logo_pixels) - XFreeColors (si->dpy, cmap, pw->logo_pixels, pw->logo_npixels, 0L); if (pw->logo_pixels) - free (pw->logo_pixels); + { + if (pw->logo_npixels) + XFreeColors (si->dpy, cmap, pw->logo_pixels, pw->logo_npixels, 0L); + free (pw->logo_pixels); + pw->logo_pixels = 0; + pw->logo_npixels = 0; + } - memset (pw, 0, sizeof(*pw)); - free (pw); + if (pw->save_under) + XFreePixmap (si->dpy, pw->save_under); if (cmap) XInstallColormap (si->dpy, cmap); + memset (pw, 0, sizeof(*pw)); + free (pw); si->pw_data = 0; } +static Bool error_handler_hit_p = False; + +static int +ignore_all_errors_ehandler (Display *dpy, XErrorEvent *error) +{ + error_handler_hit_p = True; + return 0; +} + + #ifdef HAVE_XHPDISABLERESET /* This function enables and disables the C-Sh-Reset hot-key, which normally resets the X server (logging out the logged-in user.) @@ -882,6 +918,55 @@ hp_lock_reset (saver_info *si, Bool lock_p) } #endif /* HAVE_XHPDISABLERESET */ + +#ifdef HAVE_XF86MISCSETGRABKEYSSTATE + +/* This function enables and disables the Ctrl-Alt-KP_star and + Ctrl-Alt-KP_slash hot-keys, which (in XFree86 4.2) break any + grabs and/or kill the grabbing client. That would effectively + unlock the screen, so we don't like that. + + The Ctrl-Alt-KP_star and Ctrl-Alt-KP_slash hot-keys only exist + if AllowDeactivateGrabs and/or AllowClosedownGrabs are turned on + in XF86Config. I believe they are disabled by default. + + This does not affect any other keys (specifically Ctrl-Alt-BS or + Ctrl-Alt-F1) but I wish it did. Maybe it will someday. + */ +static void +xfree_lock_grab_smasher (saver_info *si, Bool lock_p) +{ + saver_preferences *p = &si->prefs; + int status; + + XErrorHandler old_handler; + XSync (si->dpy, False); + error_handler_hit_p = False; + old_handler = XSetErrorHandler (ignore_all_errors_ehandler); + XSync (si->dpy, False); + status = XF86MiscSetGrabKeysState (si->dpy, !lock_p); + XSync (si->dpy, False); + if (error_handler_hit_p) status = 666; + + if (!lock_p && status == MiscExtGrabStateAlready) + status = MiscExtGrabStateSuccess; /* shut up, consider this success */ + + if (p->verbose_p && status != MiscExtGrabStateSuccess) + fprintf (stderr, "%s: error: XF86MiscSetGrabKeysState(%d) returned %s\n", + blurb(), !lock_p, + (status == MiscExtGrabStateSuccess ? "MiscExtGrabStateSuccess" : + status == MiscExtGrabStateLocked ? "MiscExtGrabStateLocked" : + status == MiscExtGrabStateAlready ? "MiscExtGrabStateAlready" : + status == 666 ? "an X error" : + "unknown value")); + + XSync (si->dpy, False); + XSetErrorHandler (old_handler); + XSync (si->dpy, False); +} +#endif /* HAVE_XF86MISCSETGRABKEYSSTATE */ + + /* This function enables and disables the C-Sh-F1 ... F12 hot-keys, @@ -953,9 +1038,6 @@ linux_lock_vt_switch (saver_info *si, Bool lock_p) */ #ifdef HAVE_XF86VMODE -static int ignore_all_errors_ehandler (Display *dpy, XErrorEvent *error); -static Bool vp_got_error = False; - static void xfree_lock_mode_switch (saver_info *si, Bool lock_p) { @@ -971,14 +1053,15 @@ xfree_lock_mode_switch (saver_info *si, Bool lock_p) if (!XF86VidModeQueryExtension (si->dpy, &event, &error)) return; - for (screen = 0; screen < si->nscreens; screen++) + for (screen = 0; screen < (si->xinerama_p ? 1 : si->nscreens); screen++) { XSync (si->dpy, False); old_handler = XSetErrorHandler (ignore_all_errors_ehandler); + error_handler_hit_p = False; status = XF86VidModeLockModeSwitch (si->dpy, screen, lock_p); XSync (si->dpy, False); XSetErrorHandler (old_handler); - if (vp_got_error) status = False; + if (error_handler_hit_p) status = False; if (status) any_mode_locked_p = lock_p; @@ -994,14 +1077,6 @@ xfree_lock_mode_switch (saver_info *si, Bool lock_p) blurb(), screen, (lock_p ? "locked" : "unlocked")); } } - -static int -ignore_all_errors_ehandler (Display *dpy, XErrorEvent *error) -{ - vp_got_error = True; - return 0; -} - #endif /* HAVE_XF86VMODE */ @@ -1088,7 +1163,7 @@ passwd_animate_timer (XtPointer closure, XtIntervalId *id) else pw->timer = 0; - idle_timer ((XtPointer) si, id); + idle_timer ((XtPointer) si, 0); } @@ -1342,6 +1417,9 @@ set_locked_p (saver_info *si, Bool locked_p) #ifdef HAVE_XF86VMODE xfree_lock_mode_switch (si, locked_p); /* turn off/on C-Alt-Plus */ #endif +#ifdef HAVE_XF86MISCSETGRABKEYSSTATE + xfree_lock_grab_smasher (si, locked_p); /* turn off/on C-Alt-KP-*,/ */ +#endif store_saver_status (si); /* store locked-p */ }