X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=driver%2Fdemo.c;h=c7a12ba3eb4b4c5e458440768e9672a8ff6f287a;hb=2a991a811de4c7b22f812682b267b616a809fd9a;hp=23a42974c6ae88d7015d173d4b6940835efa04ae;hpb=0bd2eabab3e404c6769fe8f59b639275e960c415;p=xscreensaver diff --git a/driver/demo.c b/driver/demo.c index 23a42974..c7a12ba3 100644 --- a/driver/demo.c +++ b/driver/demo.c @@ -1,5 +1,5 @@ /* demo.c --- implements the interactive demo-mode and options dialogs. - * xscreensaver, Copyright (c) 1993-1998 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 @@ -15,6 +15,7 @@ #endif #include +#include /* We don't actually use any widget internals, but these are included so that gdb will have debug info for the widgets... */ @@ -30,7 +31,6 @@ #else /* HAVE_ATHENA */ /* Athena demo code contributed by Jon A. Christopher */ /* Copyright 1997, with the same permissions as above. */ -# include # include # include # include @@ -40,6 +40,7 @@ # include # include # include +# include #endif /* HAVE_ATHENA */ #include "xscreensaver.h" @@ -48,6 +49,10 @@ #include #include +#ifdef _VROOT_H_ +ERROR! You must not include vroot.h in this file. +#endif + static void demo_mode_hack (saver_info *si, char *); static void demo_mode_done (saver_info *si); @@ -104,7 +109,13 @@ get_text_string (Widget text_widget) return XmTextGetString (text_widget); #else /* HAVE_ATHENA */ char *string = 0; - XtVaGetValues (text_widget, XtNvalue, &string, 0); + if (XtIsSubclass(text_widget, textWidgetClass)) + XtVaGetValues (text_widget, XtNstring, &string, 0); + else if (XtIsSubclass(text_widget, dialogWidgetClass)) + XtVaGetValues (text_widget, XtNvalue, &string, 0); + else + string = 0; + return string; #endif /* HAVE_ATHENA */ } @@ -204,18 +215,39 @@ destroy_screenhack_dialogs (saver_info *si) XInstallColormap (si->dpy, ssi->cmap); } -#ifdef HAVE_MOTIF static void text_cb (Widget text_widget, XtPointer client_data, XtPointer call_data) { saver_info *si = (saver_info *) client_data; + saver_preferences *p = &si->prefs; char *line; line = get_text_string (text_widget); + + if (p->verbose_p) + fprintf (stderr, "%s: processing text \"%s\".\n", blurb(), line); + demo_mode_hack (si, line); } -#endif /* HAVE_MOTIF */ + +#ifdef HAVE_ATHENA +/* Bend over backwards to make hitting Return in the text field do the + right thing. + */ +extern saver_info *global_si_kludge; +static void text_enter (Widget w, XEvent *event, String *av, Cardinal *ac) +{ + text_cb (w, global_si_kludge, 0); +} + +static XtActionsRec actions[] = {{"done", text_enter} + }; +static char translations[] = ("Return: done()\n" + "Linefeed: done()\n" + "CtrlM: done()\n" + "CtrlJ: done()\n"); +#endif /* HAVE_ATHENA */ static void @@ -225,6 +257,8 @@ select_cb (Widget button, XtPointer client_data, XtPointer call_data) #ifdef HAVE_ATHENA XawListReturnStruct *item = (XawListReturnStruct*)call_data; + XtVaSetValues(text_line, XtNstring, item->string, 0); + demo_mode_hack (si, item->string); if (item->list_index >= 0) si->default_screen->current_hack = item->list_index; @@ -248,19 +282,6 @@ select_cb (Widget button, XtPointer client_data, XtPointer call_data) } -#if 0 /* configure does this now */ -#ifdef HAVE_ATHENA -# if !defined(_Viewport_h) - /* The R4 Athena libs don't have this function. I don't know the right - way to tell, but I note that the R5 version of Viewport.h defines - _XawViewport_h, while the R4 version defines _Viewport_h. So we'll - try and key off of that... */ -# define HAVE_XawViewportSetCoordinates -# endif -#endif /* HAVE_ATHENA */ -#endif /* 0 */ - - /* Why this behavior isn't automatic in *either* toolkit, I'll never know. */ static void @@ -348,12 +369,17 @@ static void next_cb (Widget button, XtPointer client_data, XtPointer call_data) { saver_info *si = (saver_info *) client_data; + saver_preferences *p = &si->prefs; + + if (p->verbose_p) + fprintf (stderr, "%s: Run Next\n", blurb()); + { #ifdef HAVE_ATHENA int cnt; XawListReturnStruct *current = XawListShowCurrent(demo_list); if (current->list_index == XAW_LIST_NONE) - XawListHighlight(demo_list,1); + XawListHighlight(demo_list, 0); else { XtVaGetValues(demo_list, @@ -368,6 +394,7 @@ next_cb (Widget button, XtPointer client_data, XtPointer call_data) ensure_selected_item_visible (demo_list); current = XawListShowCurrent(demo_list); + XtVaSetValues(text_line, XtNstring, current->string, 0); demo_mode_hack (si, current->string); #else /* HAVE_MOTIF */ @@ -392,6 +419,7 @@ next_cb (Widget button, XtPointer client_data, XtPointer call_data) demo_mode_hack (si, get_text_string (text_line)); #endif /* HAVE_MOTIF */ + } } @@ -399,14 +427,19 @@ static void prev_cb (Widget button, XtPointer client_data, XtPointer call_data) { saver_info *si = (saver_info *) client_data; + saver_preferences *p = &si->prefs; + + if (p->verbose_p) + fprintf (stderr, "%s: Run Previous\n", blurb()); + { #ifdef HAVE_ATHENA XawListReturnStruct *current=XawListShowCurrent(demo_list); if (current->list_index == XAW_LIST_NONE) - XawListHighlight(demo_list,1); + XawListHighlight(demo_list, 0); else { - if (current->list_index>=1) + if (current->list_index >= 1) { current->list_index--; XawListHighlight(demo_list, current->list_index); @@ -415,6 +448,7 @@ prev_cb (Widget button, XtPointer client_data, XtPointer call_data) ensure_selected_item_visible (demo_list); current = XawListShowCurrent(demo_list); + XtVaSetValues(text_line, XtNstring, current->string, 0); demo_mode_hack (si, current->string); #else /* HAVE_MOTIF */ @@ -436,6 +470,7 @@ prev_cb (Widget button, XtPointer client_data, XtPointer call_data) demo_mode_hack (si, get_text_string (text_line)); #endif /* HAVE_MOTIF */ + } } @@ -447,7 +482,12 @@ edit_cb (Widget button, XtPointer client_data, XtPointer call_data) { saver_info *si = (saver_info *) client_data; saver_screen_info *ssi = si->default_screen; + saver_preferences *p = &si->prefs; Widget parent = ssi->toplevel_shell; + + if (p->verbose_p) + fprintf (stderr, "%s: Preferences\n", blurb()); + if (! resources_dialog) make_resources_dialog (si, parent); pop_resources_dialog (si); @@ -465,6 +505,9 @@ static void restart_cb (Widget button, XtPointer client_data, XtPointer call_data) { saver_info *si = (saver_info *) client_data; + saver_preferences *p = &si->prefs; + if (p->verbose_p) + fprintf (stderr, "%s: Restart\n", blurb()); demo_mode_restart_process (si); } @@ -520,6 +563,10 @@ pop_up_dialog_box (Widget dialog, Widget form, int where) x = (sw + w) / 2 - w; y = (sh + h) / 2 - h; break; + case 3: /* center it in the top 2/3rds of the screen */ + x = (sw + w) / 2 - w; + y = (sh*2/3 + h) / 2 - h; + break; default: abort (); } @@ -547,7 +594,7 @@ pop_up_dialog_box (Widget dialog, Widget form, int where) } -static void +void make_screenhack_dialog (saver_info *si) { saver_screen_info *ssi = si->default_screen; @@ -585,12 +632,13 @@ make_screenhack_dialog (saver_info *si) select_cb, (XtPointer) si); XtAddCallback (text_line, XmNactivateCallback, text_cb, (XtPointer) si); - for (; *hacks; hacks++) - { - XmString xmstr = XmStringCreate (*hacks, XmSTRING_DEFAULT_CHARSET); - XmListAddItem (demo_list, xmstr, 0); - XmStringFree (xmstr); - } + if (hacks) + for (; *hacks; hacks++) + { + XmString xmstr = XmStringCreate (*hacks, XmSTRING_DEFAULT_CHARSET); + XmListAddItem (demo_list, xmstr, 0); + XmStringFree (xmstr); + } /* Cause the most-recently-run hack to be selected in the list. Do some voodoo to make it be roughly centered in the list (really, @@ -620,6 +668,18 @@ make_screenhack_dialog (saver_info *si) #else /* HAVE_ATHENA */ + /* Hook up the text line. */ + + XtAppAddActions(XtWidgetToApplicationContext(text_line), + actions, XtNumber(actions)); + XtOverrideTranslations(text_line, XtParseTranslationTable(translations)); + + + /* Must realize the widget before populating the list, or the dialog + will be as wide as the longest string. + */ + XtRealizeWidget (demo_dialog); + XtVaSetValues (demo_list, XtNlist, hacks, XtNnumberStrings, si->prefs.screenhacks_count, @@ -628,6 +688,48 @@ make_screenhack_dialog (saver_info *si) if (ssi->current_hack > 0) XawListHighlight(demo_list, ssi->current_hack); + /* Now that we've populated the list, make sure that the list is as + wide as the dialog itself. + */ + { + Widget viewport = XtParent(demo_list); + Widget subform = XtParent(viewport); + Widget box = XtNameToWidget(demo_dialog, "*box"); + Widget label1 = XtNameToWidget(demo_dialog, "*label1"); + Widget label2 = XtNameToWidget(demo_dialog, "*label2"); + Dimension x=0, y=0, w=0, h=0, bw=0, w2=0; + XtVaGetValues(subform, + XtNwidth, &w, XtNheight, &h, XtNborderWidth, &bw, 0); + XtVaGetValues(box, XtNwidth, &w2, 0); + if (w2 != w) + XtResizeWidget(subform, w2, h, bw); + + /* Why isn't the viewport getting centered? */ + XtVaGetValues(viewport, + XtNx, &x, XtNy, &y, XtNheight, &h, XtNborderWidth, &bw, 0); +/* printf("%d %d %d %d\n", x, y, w, h); */ + XtConfigureWidget(viewport, x, y, w2-x-x, h, bw); + + /* And the text line, too. */ + XtVaGetValues(text_line, + XtNwidth, &w, XtNheight, &h, XtNborderWidth, &bw, 0); + XtVaGetValues(viewport, XtNwidth, &w2, 0); + if (w2 != w) + XtResizeWidget(text_line, w2, h, bw); + + /* And the labels too. */ + XtVaGetValues(label1, + XtNwidth, &w, XtNheight, &h, XtNborderWidth, &bw, 0); + if (w2 != w) + XtResizeWidget(label1, w2, h, bw); + + XtVaGetValues(label2, + XtNwidth, &w, XtNheight, &h, XtNborderWidth, &bw, 0); + if (w2 != w) + XtResizeWidget(label2, w2, h, bw); + + } + #endif /* HAVE_ATHENA */ monitor_power_on (si); @@ -710,9 +812,15 @@ res_bool_cb (Widget button, XtPointer client_data, XtPointer call_data) static void res_cancel_cb (Widget button, XtPointer client_data, XtPointer call_data) { + saver_info *si = (saver_info *) client_data; + saver_preferences *p = &si->prefs; + XtDestroyWidget (resources_dialog); resources_dialog = 0; raise_screenhack_dialog (); + + if (p->verbose_p) + fprintf (stderr, "%s: lowering preferences dialog.\n", blurb()); } @@ -758,7 +866,7 @@ res_done_cb (Widget button, XtPointer client_data, XtPointer call_data) timeout: %d\n\tcycle: %d\n\tlock: %d\n\tpasswd: %d\n\ fade: %d\n\tfade: %d\n\tverbose: %d\n\tinstall: %d\n\ fade: %d\n\tunfade: %d\n\tlock: %d\n", - progname, p->timeout, p->cycle, p->lock_timeout, + blurb(), p->timeout, p->cycle, p->lock_timeout, #ifdef NO_LOCKING 0, #else @@ -782,13 +890,15 @@ res_done_cb (Widget button, XtPointer client_data, XtPointer call_data) if (p->verbose_p) fprintf (stderr, "%s: configuring server for saver timeout of %d seconds.\n", - progname, server_timeout); + blurb(), server_timeout); /* Leave all other parameters the same. */ XSetScreenSaver (si->dpy, server_timeout, server_interval, prefer_blank, allow_exp); } } #endif /* HAVE_MIT_SAVER_EXTENSION || HAVE_SGI_SAVER_EXTENSION */ + + write_init_file (si); } @@ -848,7 +958,7 @@ make_resources_dialog (saver_info *si, Widget parent) disable_widget (lock_time_text); disable_widget (lock_toggle); } - if (CellsOfScreen (XtScreen (parent)) <= 2) + if (!si->fading_possible_p) { disable_widget (fade_text); disable_widget (ticks_text); @@ -892,6 +1002,9 @@ pop_resources_dialog (saver_info *si) saver_preferences *p = &si->prefs; char buf [100]; + if (p->verbose_p) + fprintf (stderr, "%s: raising preferences dialog.\n", blurb()); + res.timeout = p->timeout / 1000; res.cycle = p->cycle / 1000; res.lock_time = p->lock_timeout / 1000; @@ -934,10 +1047,20 @@ void demo_mode (saver_info *si) { saver_preferences *p = &si->prefs; + Bool prefs_p = (si->demo_mode_p == (Bool) 2); /* kludge! */ + + if (p->verbose_p) + fprintf (stderr, "%s: Demo Mode.\n", blurb()); + + si->selection_mode = 0; si->dbox_up_p = True; monitor_power_on (si); raise_window (si, True, False, False); make_screenhack_dialog (si); + + if (prefs_p) + edit_cb (0, si, 0); /* pop up preferences panel */ + while (si->demo_mode_p) { XEvent event; @@ -959,10 +1082,11 @@ demo_mode (saver_info *si) start_notice_events_timer (si, event.xcreatewindow.window); #ifdef DEBUG_TIMERS if (p->verbose_p) - printf ("%s: starting notice_events_timer for 0x%X (%lu)\n", - progname, - (unsigned int) event.xcreatewindow.window, - p->notice_events_timeout); + fprintf (stderr, + "%s: starting notice_events_timer for 0x%X (%lu)\n", + blurb(), + (unsigned int) event.xcreatewindow.window, + p->notice_events_timeout); #endif /* DEBUG_TIMERS */ } break; @@ -995,9 +1119,18 @@ demo_mode (saver_info *si) break; } } + + if (p->verbose_p) + fprintf (stderr, "%s: Demo Mode done.\n", blurb()); + + kill_screenhack (si); + destroy_screenhack_dialogs (si); initialize_screensaver_window (si); + si->dbox_up_p = False; + si->demo_hack = 0; + si->demo_mode_p = True; /* kludge to inhibit unfade... */ unblank_screen (si); si->demo_mode_p = False; @@ -1018,10 +1151,5 @@ demo_mode_hack (saver_info *si, char *hack) static void demo_mode_done (saver_info *si) { - kill_screenhack (si); - if (si->demo_hack) - unblank_screen (si); si->demo_mode_p = False; - si->dbox_up_p = False; - si->demo_hack = 0; }