X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=driver%2Flock.c;h=25dad5546e555e7e0a41387b0ccf7afa31318ccf;hb=481b95e2617b69e6fd4444432747d7e1e0c3dc85;hp=b4246c914847a8351cee8265e1125e0863ee99a3;hpb=f3e0240915ed9f9b3a61781f5c7002d587563fe0;p=xscreensaver diff --git a/driver/lock.c b/driver/lock.c index b4246c91..25dad554 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-1997 Jamie Zawinski + * xscreensaver, Copyright (c) 1993-1998 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 @@ -21,14 +21,15 @@ #include #include +#include /* for XtResizeWidget */ #include "xscreensaver.h" +#include "resources.h" #ifndef VMS # include #else /* VMS */ extern char *getenv(const char *name); extern int validate_user(char *name, char *password); -static char * user_vms; #endif /* VMS */ @@ -40,17 +41,6 @@ static char * user_vms; # include # include -static void passwd_done_cb (Widget, XtPointer, XtPointer); -static XtActionsRec actionsList[] = -{ - {"passwdentered", (XtActionProc) passwd_done_cb}, -}; - -static char Translations[] = -"\ -Return: passwdentered()\ -"; - #else /* HAVE_MOTIF */ # include @@ -77,8 +67,7 @@ static Widget passwd_done = 0; static enum { pw_read, pw_ok, pw_fail, pw_cancel, pw_time } passwd_state; -#define PASSWDLEN 80 -static char typed_passwd [PASSWDLEN]; +static char typed_passwd [80]; #if defined(HAVE_ATHENA) || (XmVersion >= 1002) @@ -93,29 +82,32 @@ passwd_cancel_cb (Widget button, XtPointer client_data, XtPointer call_data) passwd_state = pw_cancel; } + +#ifdef VMS +static Bool +vms_passwd_valid_p(char *pw) +{ + char *u = getenv("USER"); + return (validate_user (i, typed_passwd) == 1); +} +# undef passwd_valid_p +# define passwd_valid_p vms_passwd_valid_p + +#endif /* VMS */ + + static void passwd_done_cb (Widget button, XtPointer client_data, XtPointer call_data) { if (passwd_state != pw_read) return; /* already done */ -#ifndef VMS -# ifdef HAVE_ATHENA - strncpy(typed_passwd, XawDialogGetValueString(passwd_form), PASSWDLEN); -# endif /* HAVE_ATHENA */ if (passwd_valid_p (typed_passwd)) passwd_state = pw_ok; else passwd_state = pw_fail; - -#else /* VMS */ - user_vms = getenv("USER"); - if (validate_user(user_vms,typed_passwd) == 1) - passwd_state = pw_ok; - else - passwd_state = pw_fail; -#endif /* VMS */ } + #if defined(HAVE_MOTIF) && defined(VERIFY_CALLBACK_WORKS) /* It looks to me like adding any modifyVerify callback causes @@ -146,8 +138,11 @@ check_passwd_cb (Widget button, XtPointer client_data, XtPointer call_data) else if (vcb->text->ptr != 0) { int i; - strncat (typed_passwd, vcb->text->ptr, vcb->text->length); - typed_passwd [vcb->endPos + vcb->text->length] = 0; + int L = vcb->text->length; + if (L >= sizeof(typed_passwd)) + L = sizeof(typed_passwd)-1; + strncat (typed_passwd, vcb->text->ptr, L); + typed_passwd [vcb->endPos + L] = 0; for (i = 0; i < vcb->text->length; i++) vcb->text->ptr [i] = '*'; } @@ -166,22 +161,21 @@ static XtActionsRec actions[] = {{"keypress", keypress}, {"done", done} }; -# ifdef HAVE_MOTIF -# if 0 /* oh fuck, why doesn't this work? */ -static char translations[] = "\ -BackSpace: backspace()\n\ -Delete: backspace()\n\ -CtrlH: backspace()\n\ -CtrlU: kill_line()\n\ -CtrlX: kill_line()\n\ -CtrlJ: done()\n\ -CtrlM: done()\n\ -: keypress()\n\ -"; -# else /* !0 */ -static char translations[] = ":keypress()"; -# endif /* !0 */ -# endif /* HAVE_MOTIF */ +# if 0 /* This works for Athena, but not Motif: keypress() gets called + for all keys anyway. So, the implementation of keypress() + has BackSpace, etc, hardcoded into it instead. FMH! + */ +static char translations[] = ("BackSpace: backspace()\n" + "Delete: backspace()\n" + "CtrlH: backspace()\n" + "CtrlU: kill_line()\n" + "CtrlX: kill_line()\n" + "CtrlJ: done()\n" + "CtrlM: done()\n" + ": keypress()\n"); +# else /* !0 */ +static char translations[] = (": keypress()\n"); +# endif /* !0 */ static void @@ -218,8 +212,8 @@ static void keypress (Widget w, XEvent *event, String *argv, Cardinal *argc) { int i, j; - char s [sizeof (typed_passwd)]; - int size = XLookupString ((XKeyEvent *) event, s, sizeof (s), 0, 0); + char s [sizeof(typed_passwd)]; + int size = XLookupString ((XKeyEvent *) event, s, sizeof(s)-1, 0, 0); if (size != 1) return; /* hack because I can't get translations to dance to my tune... */ @@ -231,6 +225,13 @@ keypress (Widget w, XEvent *event, String *argv, Cardinal *argc) if (*s == '\015') { done (w, event, argv, argc); return; } i = j = strlen (typed_passwd); + + if (i >= (sizeof(typed_passwd)-1)) + { + XBell(XtDisplay(w), 0); + return; + } + typed_passwd [i] = *s; s [++i] = 0; while (i--) @@ -242,7 +243,7 @@ keypress (Widget w, XEvent *event, String *argv, Cardinal *argc) static void backspace (Widget w, XEvent *event, String *argv, Cardinal *argc) { - char s [sizeof (typed_passwd)]; + char s [sizeof(typed_passwd)]; int i = strlen (typed_passwd); int j = i; if (i == 0) @@ -258,7 +259,7 @@ backspace (Widget w, XEvent *event, String *argv, Cardinal *argc) static void kill_line (Widget w, XEvent *event, String *argv, Cardinal *argc) { - memset (typed_passwd, 0, sizeof (typed_passwd)); + memset (typed_passwd, 0, sizeof(typed_passwd)); text_field_set_string (passwd_text, "", 0); } @@ -335,7 +336,6 @@ make_passwd_dialog (saver_info *si) create_passwd_dialog (parent, ssi->default_visual, ssi->demo_cmap); #ifdef HAVE_ATHENA - XtVaSetValues(passwd_form, XtNvalue, typed_passwd, 0); XawDialogAddButton(passwd_form,"ok", passwd_done_cb, 0); @@ -343,9 +343,15 @@ make_passwd_dialog (saver_info *si) passwd_done = XtNameToWidget(passwd_form,"ok"); passwd_text = XtNameToWidget(passwd_form,"value"); - XtAppAddActions(XtWidgetToApplicationContext(passwd_text), - actionsList, XtNumber(actionsList)); - XtOverrideTranslations(passwd_text, XtParseTranslationTable(Translations)); + XtAppAddActions(XtWidgetToApplicationContext(passwd_text), + actions, XtNumber(actions)); + XtOverrideTranslations(passwd_text, XtParseTranslationTable(translations)); + + /* Lose the label on the inner dialog. */ + { + Widget w = XtNameToWidget(passwd_form, "label"); + if (w) XtUnmanageChild(w); + } #else /* HAVE_MOTIF */ @@ -356,15 +362,15 @@ make_passwd_dialog (saver_info *si) # ifdef VERIFY_CALLBACK_WORKS XtAddCallback (passwd_text, XmNmodifyVerifyCallback, check_passwd_cb, 0); XtAddCallback (passwd_text, XmNactivateCallback, check_passwd_cb, 0); -# else +# else /* !VERIFY_CALLBACK_WORKS */ XtAddCallback (passwd_text, XmNactivateCallback, passwd_done_cb, 0); XtOverrideTranslations (passwd_text, XtParseTranslationTable (translations)); -# endif +# endif /* !VERIFY_CALLBACK_WORKS */ # if defined(HAVE_MOTIF) && (XmVersion >= 1002) /* The focus stuff changed around; this didn't exist in 1.1.5. */ XtVaSetValues (passwd_form, XmNinitialFocus, passwd_text, 0); -# endif +# endif /* HAVE_MOTIF && XmVersion >= 1002 */ /* Another random thing necessary in 1.2.1 but not 1.1.5... */ XtVaSetValues (roger_label, XmNborderWidth, 2, 0); @@ -385,7 +391,7 @@ make_passwd_dialog (saver_info *si) format_into_label (passwd_label3, (username ? username : "???")); } -static int passwd_idle_timer_tick; +static int passwd_idle_timer_tick = -1; static XtIntervalId passwd_idle_id; static void @@ -410,7 +416,7 @@ passwd_idle_timer (XtPointer closure, XtIntervalId *id) { XGCValues gcv; #ifdef HAVE_MOTIF - unsigned long fg, bg, ts, bs; + unsigned long fg = 0, bg = 0, ts = 0, bs = 0; Dimension w = 0, h = 0; XtVaGetValues(XtParent(passwd_done), XmNwidth, &w, @@ -434,6 +440,17 @@ passwd_idle_timer (XtPointer closure, XtIntervalId *id) x = (w / 2); +# ifdef __sgi /* Kludge -- SGI's Motif hacks place buttons differently. */ + { + static int sgi_mode = -1; + if (sgi_mode == -1) + sgi_mode = get_boolean_resource("sgiMode", "sgiMode") ? 1 : 0; + + if (sgi_mode) + x = d; + } +# endif /* __sgi */ + x -= d/2; y += d/2; @@ -441,7 +458,7 @@ passwd_idle_timer (XtPointer closure, XtIntervalId *id) Arg av [100]; int ac = 0; - unsigned long fg, bg; + unsigned long fg = 0, bg = 0; XtSetArg (av [ac], XtNheight, &d); ac++; XtGetValues (passwd_done, av, ac); ac = 0; @@ -477,77 +494,6 @@ passwd_idle_timer (XtPointer closure, XtIntervalId *id) } } -#ifdef HAVE_ATHENA - -void -pop_up_athena_dialog_box (Widget parent, Widget focus, Widget dialog, - Widget form, int where) -{ - /* modified from demo.c */ - /* I'm sure this is the wrong way to pop up a dialog box, but I can't - figure out how else to do it. - - It's important that the screensaver dialogs not get decorated or - otherwise reparented by the window manager, because they need to be - children of the *real* root window, not the WM's virtual root, in - order for us to guarentee that they are visible above the screensaver - window itself. - */ - Arg av [100]; - int ac = 0; - Dimension sw, sh, x, y, w, h; - - XtRealizeWidget(dialog); - sw = WidthOfScreen (XtScreen (dialog)); - sh = HeightOfScreen (XtScreen (dialog)); - ac = 0; - XtSetArg (av [ac], XtNwidth, &w); ac++; - XtSetArg (av [ac], XtNheight, &h); ac++; - XtGetValues (form, av, ac); - switch (where) - { - case 0: /* center it in the top-right quadrant */ - x = (sw/2 + w) / 2 + (sw/2) - w; - y = (sh/2 + h) / 2 - h; - break; - case 1: /* center it in the bottom-right quadrant */ - x = (sw/2 + w) / 2 + (sw/2) - w; - y = (sh/2 + h) / 2 + (sh/2) - h; - break; - case 2: /* center it on the screen */ - x = (sw + w) / 2 - w; - y = (sh + h) / 2 - h; - break; - default: - abort (); - } - if (x + w > sw) x = sw - w; - if (y + h > sh) y = sh - h; - ac = 0; - XtVaSetValues(dialog, - XtNx, x, - XtNy, y, - NULL); - XtVaSetValues(form, - XtNx, x, - XtNy, y, - NULL); - XtPopup(dialog,XtGrabNone); - steal_focus_and_colormap (focus); -} - -static void -passwd_set_label (char *buf, int len) -{ - Widget label; - if (!passwd_text) - return; - label=XtNameToWidget(XtParent(passwd_text),"*label"); - XtVaSetValues(label, - XtNlabel, buf, - NULL); -} -#endif /* HAVE_ATHENA */ static Bool pop_passwd_dialog (saver_info *si) @@ -578,25 +524,39 @@ pop_passwd_dialog (saver_info *si) */ if (XtWindow (passwd_form)) XMapRaised (dpy, XtWindow (passwd_dialog)); -#endif +#endif /* HAVE_MOTIF && !DESTROY_WORKS */ -#ifdef HAVE_ATHENA - pop_up_athena_dialog_box (parent, passwd_text, passwd_dialog, - passwd_form, 2); -#else + monitor_power_on (si); pop_up_dialog_box (passwd_dialog, passwd_form, -#ifdef DEBUG + /* for debugging -- don't ask */ (si->prefs.debug_p ? 69 : 0) + -#endif 2); XtManageChild (passwd_form); -#endif + +#ifdef HAVE_ATHENA + steal_focus_and_colormap (passwd_text); + + /* For some reason, the passwd_form box is not stretching all the way + to the right edge of the window, despite being XtChainRight. + So... resize it by hand. + */ + { + Dimension x=0, w=0, h=0; + XtVaGetValues(passwd_form, XtNx, &x, XtNwidth, &w, XtNheight, &h, 0); + XtVaGetValues(XtParent(passwd_form), XtNwidth, &w, 0); + w -= x; + w -= 6; + if (w > 0) XtResizeWidget(passwd_form, w, h, 0); + } + +#endif /* HAVE_ATHENA */ + #if defined(HAVE_MOTIF) && (XmVersion < 1002) /* The focus stuff changed around; this causes problems in 1.2.1 but is necessary in 1.1.5. */ XmProcessTraversal (passwd_text, XmTRAVERSE_CURRENT); -#endif +#endif /* HAVE_MOTIF && XmVersion < 1002 */ passwd_idle_timer_tick = p->passwd_timeout / 1000; passwd_idle_id = XtAppAddTimeOut (si->app, 1000, passwd_idle_timer, @@ -607,14 +567,12 @@ pop_passwd_dialog (saver_info *si) roger(roger_label, 0, 0); #endif /* HAVE_ATHENA */ -#ifdef DEBUG if (!si->prefs.debug_p) -#endif - XGrabServer (dpy); /* ############ DANGER! */ + XGrabServer (dpy); /* ############ DANGER! */ /* this call to ungrab used to be in main_loop() - see comment in xscreensaver.c around line 857. */ - ungrab_keyboard_and_mouse (si->dpy); + ungrab_keyboard_and_mouse (si); while (passwd_state == pw_read) { @@ -641,21 +599,17 @@ pop_passwd_dialog (saver_info *si) case pw_cancel: lose = 0; break; default: abort (); } + #ifdef HAVE_MOTIF XmProcessTraversal (passwd_cancel, 0); /* turn off I-beam */ -#endif +#else /* HAVE_ATHENA */ + steal_focus_and_colormap (passwd_done); +#endif /* HAVE_ATHENA */ + if (lose) { -#ifdef HAVE_ATHENA - /* show the message */ - passwd_set_label(lose,strlen(lose)+1); - - /* and clear the password line */ - memset(typed_passwd, 0, PASSWDLEN); - text_field_set_string (passwd_text, "", 0); -#else text_field_set_string (passwd_text, lose, strlen (lose) + 1); -#endif + passwd_idle_timer_tick = 1; passwd_idle_id = XtAppAddTimeOut (si->app, 3000, passwd_idle_timer, (XtPointer) si); @@ -670,16 +624,16 @@ pop_passwd_dialog (saver_info *si) } } } - memset (typed_passwd, 0, sizeof (typed_passwd)); + memset (typed_passwd, 0, sizeof(typed_passwd)); text_field_set_string (passwd_text, "", 0); XtSetKeyboardFocus (parent, None); #ifdef DESTROY_WORKS XtDestroyWidget (passwd_dialog); passwd_dialog = 0; -#else +#else /* !DESTROY_WORKS */ XUnmapWindow (XtDisplay (passwd_dialog), XtWindow (passwd_dialog)); -#endif +#endif /* !DESTROY_WORKS */ { XErrorHandler old_handler = XSetErrorHandler (BadWindow_ehandler); /* I don't understand why this doesn't refocus on the old selected @@ -709,9 +663,11 @@ unlock_p (saver_info *si) static Bool initted = False; if (! initted) { + #ifndef VERIFY_CALLBACK_WORKS XtAppAddActions (si->app, actions, XtNumber (actions)); -#endif +#endif /* !VERIFY_CALLBACK_WORKS */ + passwd_dialog = 0; initted = True; }