X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=driver%2Fdemo-Xm.c;h=b1b08f867326077fb918d994be2af41dd7ddf2dd;hb=4cecfc89e5e889c7232693897c06168fb378bd5c;hp=aadbd0b9658e242f6ea61e145b3879a386876b36;hpb=14463b6ad1ab1ccf81f9c33350b048e410ba94cb;p=xscreensaver diff --git a/driver/demo-Xm.c b/driver/demo-Xm.c index aadbd0b9..b1b08f86 100644 --- a/driver/demo-Xm.c +++ b/driver/demo-Xm.c @@ -1,5 +1,5 @@ /* demo-Xm.c --- implements the interactive demo-mode and options dialogs. - * xscreensaver, Copyright (c) 1993-1999 Jamie Zawinski + * xscreensaver, Copyright (c) 1993-2001 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 @@ -67,6 +67,16 @@ #include #include +#ifdef HAVE_XMCOMBOBOX /* a Motif 2.0 widget */ +# include +# ifndef XmNtextField /* Lesstif 0.89.4 bug */ +# undef HAVE_XMCOMBOBOX +# endif +# if (XmVersion < 2001) /* Lesstif has two personalities these days */ +# undef HAVE_XMCOMBOBOX +# endif +#endif /* HAVE_XMCOMBOBOX */ + #include "version.h" #include "prefs.h" #include "resources.h" /* for parse_time() */ @@ -111,6 +121,7 @@ static void populate_demo_window (Widget toplevel, static void populate_prefs_page (Widget top, prefs_pair *pair); static int apply_changes_and_save (Widget widget); static int maybe_reload_init_file (Widget widget, prefs_pair *pair); +static void await_xscreensaver (Widget widget); /* Some random utility functions @@ -343,8 +354,13 @@ about_menu_cb (Widget button, XtPointer client_data, XtPointer ignored) *s2 = 0; s2 += 2; - sprintf (buf, "%s\n%s\n\n" - "For updates, check http://www.jwz.org/xscreensaver/", + sprintf (buf, "%s\n%s\n" + "\n" + "This is the Motif version of \"xscreensaver-demo\". The Motif\n" + "version is no longer maintained. Please use the GTK version\n" + "instead, which has many more features.\n" + "\n" + "For xscreensaver updates, check http://www.jwz.org/xscreensaver/", s, s2); free (s); @@ -412,6 +428,66 @@ restart_menu_cb (Widget button, XtPointer client_data, XtPointer ignored) sleep (1); system ("xscreensaver -nosplash &"); #endif + + await_xscreensaver (button); +} + +static void +await_xscreensaver (Widget widget) +{ + int countdown = 5; + + Display *dpy = XtDisplay (widget); + char *rversion = 0; + + while (!rversion && (--countdown > 0)) + { + /* Check for the version of the running xscreensaver... */ + server_xscreensaver_version (dpy, &rversion, 0, 0); + + /* If it's not there yet, wait a second... */ + sleep (1); + } + + if (rversion) + { + /* Got it. */ + free (rversion); + } + else + { + /* Timed out, no screensaver running. */ + + char buf [1024]; + Bool root_p = (geteuid () == 0); + + strcpy (buf, + "Error:\n\n" + "The xscreensaver daemon did not start up properly.\n" + "\n"); + + if (root_p) + strcat (buf, + "You are running as root. This usually means that xscreensaver\n" + "was unable to contact your X server because access control is\n" + "turned on. Try running this command:\n" + "\n" + " xhost +localhost\n" + "\n" + "and then selecting `File / Restart Daemon'.\n" + "\n" + "Note that turning off access control will allow anyone logged\n" + "on to this machine to access your screen, which might be\n" + "considered a security problem. Please read the xscreensaver\n" + "manual and FAQ for more information.\n" + "\n" + "You shouldn't run X as root. Instead, you should log in as a\n" + "normal user, and `su' as necessary."); + else + strcat (buf, "Please check your $PATH and permissions."); + + warning_dialog (XtParent (widget), buf, 1); + } } @@ -461,10 +537,10 @@ apply_changes_and_save (Widget widget) Widget vis = name_to_widget (widget, "combo"); # ifdef HAVE_XMCOMBOBOX - Widget text; + Widget text = 0; # else /* !HAVE_XMCOMBOBOX */ Widget menu = 0, *kids = 0, selected_item = 0; - Cardinal nkids; + Cardinal nkids = 0; int i = 0; # endif /* !HAVE_XMCOMBOBOX */ @@ -479,6 +555,9 @@ apply_changes_and_save (Widget widget) # ifdef HAVE_XMCOMBOBOX XtVaGetValues (vis, XmNtextField, &text, 0); + if (!text) + /* If we can't get at the text field of this combo box, we're screwed. */ + abort(); XtVaGetValues (text, XmNvalue, &visual, 0); # else /* !HAVE_XMCOMBOBOX */ @@ -674,7 +753,7 @@ run_prev_cb (Widget button, XtPointer client_data, XtPointer ignored) this parses the text, and does error checking. */ static void -hack_time_text (const char *line, Time *store, Bool sec_p) +hack_time_text (Widget button, const char *line, Time *store, Bool sec_p) { if (*line) { @@ -682,7 +761,14 @@ hack_time_text (const char *line, Time *store, Bool sec_p) value = parse_time ((char *) line, sec_p, True); value *= 1000; /* Time measures in microseconds */ if (value < 0) - /* gdk_beep () */; + { + char b[255]; + sprintf (b, + "Error:\n\n" + "Unparsable time format: \"%s\"\n", + line); + warning_dialog (XtParent (button), b, 100); + } else *store = value; } @@ -704,12 +790,12 @@ prefs_ok_cb (Widget button, XtPointer client_data, XtPointer ignored) # define SECONDS(field, name) \ v = 0; \ XtVaGetValues (name_to_widget (button, (name)), XtNvalue, &v, 0); \ - hack_time_text (v, (field), True) + hack_time_text (button, v, (field), True) # define MINUTES(field, name) \ v = 0; \ XtVaGetValues (name_to_widget (button, (name)), XtNvalue, &v, 0); \ - hack_time_text (v, (field), False) + hack_time_text (button, v, (field), False) # define INTEGER(field, name) do { \ unsigned int value; \ @@ -718,7 +804,11 @@ prefs_ok_cb (Widget button, XtPointer client_data, XtPointer ignored) if (! *v) \ ; \ else if (sscanf (v, "%u%c", &value, &c) != 1) \ - XBell(XtDisplay(button), 0); \ + { \ + char b[255]; \ + sprintf (b, "Error:\n\n" "Not an integer: \"%s\"\n", v); \ + warning_dialog (XtParent (button), b, 100); \ + } \ else \ *(field) = value; \ } while(0) @@ -818,48 +908,6 @@ format_time (char *buf, Time time) } -static char * -make_pretty_name (const char *shell_command) -{ - char *s = strdup (shell_command); - char *s2; - char res_name[255]; - - for (s2 = s; *s2; s2++) /* truncate at first whitespace */ - if (isspace (*s2)) - { - *s2 = 0; - break; - } - - s2 = strrchr (s, '/'); /* if pathname, take last component */ - if (s2) - { - s2 = strdup (s2+1); - free (s); - s = s2; - } - - if (strlen (s) > 50) /* 51 is hereby defined as "unreasonable" */ - s[50] = 0; - - sprintf (res_name, "hacks.%s.name", s); /* resource? */ - s2 = get_string_resource (res_name, res_name); - if (s2) - return s2; - - for (s2 = s; *s2; s2++) /* if it has any capitals, return it */ - if (*s2 >= 'A' && *s2 <= 'Z') - return s; - - if (s[0] >= 'a' && s[0] <= 'z') /* else cap it */ - s[0] -= 'a'-'A'; - if (s[0] == 'X' && s[1] >= 'a' && s[1] <= 'z') /* (magic leading X) */ - s[1] -= 'a'-'A'; - return s; -} - - /* Finds the number of the last hack to run, and makes that item be selected by default. */ @@ -914,7 +962,7 @@ populate_hack_list (Widget toplevel, prefs_pair *pair) { char *pretty_name = (h[0]->name ? strdup (h[0]->name) - : make_pretty_name (h[0]->command)); + : make_hack_name (h[0]->command)); XmString xmstr = XmStringCreate (pretty_name, XmSTRING_DEFAULT_CHARSET); XmListAddItem (list, xmstr, 0); @@ -972,6 +1020,10 @@ populate_prefs_page (Widget top, prefs_pair *pair) } } +#ifdef HAVE_XF86VMODE_GAMMA + found_any_writable_cells = True; /* if we can gamma fade, go for it */ +#endif + XtVaSetValues (name_to_widget (top, "fadeSecondsLabel"), XtNsensitive, found_any_writable_cells, 0); XtVaSetValues (name_to_widget (top, "fadeTicksLabel"), XtNsensitive, @@ -1157,7 +1209,7 @@ get_hack_blurb (screenhack *hack) char *prog_name = strdup (hack->command); char *pretty_name = (hack->name ? strdup (hack->name) - : make_pretty_name (hack->command)); + : make_hack_name (hack->command)); char doc_name[255], doc_class[255]; char *s, *s2; @@ -1219,6 +1271,7 @@ get_hack_blurb (screenhack *hack) } else { +# if 0 static int doc_installed = 0; if (doc_installed == 0) { @@ -1239,7 +1292,16 @@ get_hack_blurb (screenhack *hack) "To fix this problem, delete that file, or " "install a current version (either will work.)"); else - doc_string = strdup (""); +# endif /* 0 */ + doc_string = strdup ( + "\n" + "This is the Motif version of \"xscreensaver-demo\". The Motif " + "version is no longer maintained. Please use the GTK version " + "instead, which has many more features." + "\n\n" + "If you were running the GTK version, there would be a preview " + "of this screen saver mode displayed here, along with graphical " + "configuration options."); } return doc_string; @@ -1261,7 +1323,7 @@ populate_demo_window (Widget toplevel, int which, prefs_pair *pair) char *pretty_name = (hack ? (hack->name ? strdup (hack->name) - : make_pretty_name (hack->command)) + : make_hack_name (hack->command)) : 0); char *doc_string = hack ? get_hack_blurb (hack) : 0; @@ -1608,10 +1670,8 @@ static int demo_ehandler (Display *dpy, XErrorEvent *error) { fprintf (stderr, "\nX error in %s:\n", progname); - if (XmuPrintDefaultErrorMessage (dpy, error, stderr)) - exit (-1); - else - fprintf (stderr, " (nonfatal.)\n"); + XmuPrintDefaultErrorMessage (dpy, error, stderr); + exit (-1); return 0; }