1 /* xscreensaver, Copyright (c) 1991-2014 Jamie Zawinski <jwz@netscape.com>
3 * Permission to use, copy, modify, distribute, and sell this software and its
4 * documentation for any purpose is hereby granted without fee, provided that
5 * the above copyright notice appear in all copies and that both that
6 * copyright notice and this permission notice appear in supporting
7 * documentation. No representations are made about the suitability of this
8 * software for any purpose. It is provided "as is" without express or
16 #include <X11/Intrinsic.h>
18 #include "xscreensaver.h"
19 #include "resources.h"
22 #define MAX(a,b) ((a)>(b)?(a):(b))
25 draw_shaded_rectangle (Display *dpy, Window window,
27 int width, int height,
29 unsigned long top_color,
30 unsigned long bottom_color)
35 if (thickness == 0) return;
37 gcv.foreground = top_color;
38 gc1 = XCreateGC (dpy, window, GCForeground, &gcv);
39 gcv.foreground = bottom_color;
40 gc2 = XCreateGC (dpy, window, GCForeground, &gcv);
44 points [1].x = x + width;
46 points [2].x = x + width - thickness;
47 points [2].y = y + thickness;
49 points [3].y = y + thickness;
50 XFillPolygon (dpy, window, gc1, points, 4, Convex, CoordModeOrigin);
53 points [0].y = y + thickness;
55 points [1].y = y + height;
56 points [2].x = x + thickness;
57 points [2].y = y + height - thickness;
58 points [3].x = x + thickness;
59 points [3].y = y + thickness;
60 XFillPolygon (dpy, window, gc1, points, 4, Convex, CoordModeOrigin);
62 points [0].x = x + width;
64 points [1].x = x + width - thickness;
65 points [1].y = y + thickness;
66 points [2].x = x + width - thickness;
67 points [2].y = y + height - thickness;
68 points [3].x = x + width;
69 points [3].y = y + height - thickness;
70 XFillPolygon (dpy, window, gc2, points, 4, Convex, CoordModeOrigin);
73 points [0].y = y + height;
74 points [1].x = x + width;
75 points [1].y = y + height;
76 points [2].x = x + width;
77 points [2].y = y + height - thickness;
78 points [3].x = x + thickness;
79 points [3].y = y + height - thickness;
80 XFillPolygon (dpy, window, gc2, points, 4, Convex, CoordModeOrigin);
88 string_width (XFontStruct *font, char *s)
90 return XTextWidth(font, s, strlen(s));
94 static void update_splash_window (saver_info *si);
95 static void draw_splash_window (saver_info *si);
96 static void destroy_splash_window (saver_info *si);
97 static void unsplash_timer (XtPointer closure, XtIntervalId *id);
99 static void do_demo (saver_screen_info *ssi);
101 static void do_prefs (saver_screen_info *ssi);
102 #endif /* PREFS_BUTTON */
103 static void do_help (saver_screen_info *ssi);
106 struct splash_dialog_data {
108 saver_screen_info *prompt_screen;
122 #endif /* PREFS_BUTTON */
125 XFontStruct *heading_font;
126 XFontStruct *body_font;
127 XFontStruct *button_font;
132 Pixel button_foreground;
133 Pixel button_background;
137 Dimension logo_width;
138 Dimension logo_height;
139 Dimension internal_border;
140 Dimension shadow_width;
142 Dimension button_width, button_height;
143 Dimension demo_button_x, demo_button_y;
145 Dimension prefs_button_x, prefs_button_y;
146 #endif /* PREFS_BUTTON */
147 Dimension help_button_x, help_button_y;
150 Pixmap logo_clipmask;
152 unsigned long *logo_pixels;
159 make_splash_dialog (saver_info *si)
161 saver_preferences *p = &si->prefs;
163 XSetWindowAttributes attrs;
164 unsigned long attrmask = 0;
165 splash_dialog_data *sp;
166 saver_screen_info *ssi;
170 Bool whine = senescent_p ();
174 /* If locking is not enabled, make sure they see the message. */
177 si->prefs.splash_p = True;
178 if (si->prefs.splash_duration < 5000)
179 si->prefs.splash_duration = 5000;
181 si->prefs.splash_duration += 3000;
186 if (!si->prefs.splash_p ||
187 si->prefs.splash_duration <= 0)
190 ssi = &si->screens[mouse_screen (si)];
192 if (!ssi || !ssi->screen)
193 return; /* WTF? Trying to splash while no screens connected? */
195 cmap = DefaultColormapOfScreen (ssi->screen);
197 sp = (splash_dialog_data *) calloc (1, sizeof(*sp));
198 sp->prompt_screen = ssi;
200 sp->heading_label = get_string_resource (si->dpy,
201 "splash.heading.label",
202 "Dialog.Label.Label");
203 sp->body_label = get_string_resource (si->dpy,
205 "Dialog.Label.Label");
206 sp->body2_label = get_string_resource (si->dpy,
207 "splash.body2.label",
208 "Dialog.Label.Label");
209 sp->demo_label = get_string_resource (si->dpy,
211 "Dialog.Button.Label");
213 sp->prefs_label = get_string_resource (si->dpy,
214 "splash.prefs.label",
215 "Dialog.Button.Label");
216 #endif /* PREFS_BUTTON */
217 sp->help_label = get_string_resource (si->dpy,
219 "Dialog.Button.Label");
225 sp->body3_label = strdup("WARNING: This version is very old!");
226 sp->body4_label = strdup("Please upgrade!");
229 if (!sp->heading_label)
230 sp->heading_label = strdup("ERROR: REESOURCES NOT INSTALLED CORRECTLY");
232 sp->body_label = strdup("ERROR: REESOURCES NOT INSTALLED CORRECTLY");
233 if (!sp->body2_label)
234 sp->body2_label = strdup("ERROR: REESOURCES NOT INSTALLED CORRECTLY");
235 if (!sp->demo_label) sp->demo_label = strdup("ERROR");
237 if (!sp->prefs_label) sp->prefs_label = strdup("ERROR");
238 #endif /* PREFS_BUTTON */
239 if (!sp->help_label) sp->help_label = strdup("ERROR");
241 /* Put the version number in the label. */
243 char *s = (char *) malloc (strlen(sp->heading_label) + 20);
244 sprintf(s, sp->heading_label, si->version);
245 free (sp->heading_label);
246 sp->heading_label = s;
249 f = get_string_resource (si->dpy, "splash.headingFont", "Dialog.Font");
250 sp->heading_font = XLoadQueryFont (si->dpy, (f ? f : "fixed"));
251 if (!sp->heading_font) sp->heading_font = XLoadQueryFont (si->dpy, "fixed");
254 f = get_string_resource(si->dpy, "splash.bodyFont", "Dialog.Font");
255 sp->body_font = XLoadQueryFont (si->dpy, (f ? f : "fixed"));
256 if (!sp->body_font) sp->body_font = XLoadQueryFont (si->dpy, "fixed");
259 f = get_string_resource(si->dpy, "splash.buttonFont", "Dialog.Font");
260 sp->button_font = XLoadQueryFont (si->dpy, (f ? f : "fixed"));
261 if (!sp->button_font) sp->button_font = XLoadQueryFont (si->dpy, "fixed");
264 sp->foreground = get_pixel_resource (si->dpy, cmap,
266 "Dialog.Foreground");
267 sp->background = get_pixel_resource (si->dpy, cmap,
269 "Dialog.Background");
270 sp->border = get_pixel_resource (si->dpy, cmap,
271 "splash.borderColor",
272 "Dialog.borderColor");
274 if (sp->foreground == sp->background)
276 /* Make sure the error messages show up. */
277 sp->foreground = BlackPixelOfScreen (ssi->screen);
278 sp->background = WhitePixelOfScreen (ssi->screen);
281 sp->button_foreground = get_pixel_resource (si->dpy, cmap,
282 "splash.Button.foreground",
283 "Dialog.Button.Foreground");
284 sp->button_background = get_pixel_resource (si->dpy, cmap,
285 "splash.Button.background",
286 "Dialog.Button.Background");
287 sp->shadow_top = get_pixel_resource (si->dpy, cmap,
288 "splash.topShadowColor",
289 "Dialog.Foreground");
290 sp->shadow_bottom = get_pixel_resource (si->dpy, cmap,
291 "splash.bottomShadowColor",
292 "Dialog.Background");
294 sp->logo_width = get_integer_resource (si->dpy,
296 "Dialog.Logo.Width");
297 sp->logo_height = get_integer_resource (si->dpy,
298 "splash.logo.height",
299 "Dialog.Logo.Height");
300 sp->internal_border = get_integer_resource (si->dpy,
301 "splash.internalBorderWidth",
302 "Dialog.InternalBorderWidth");
303 sp->shadow_width = get_integer_resource (si->dpy,
304 "splash.shadowThickness",
305 "Dialog.ShadowThickness");
307 if (sp->logo_width == 0) sp->logo_width = 150;
308 if (sp->logo_height == 0) sp->logo_height = 150;
309 if (sp->internal_border == 0) sp->internal_border = 15;
310 if (sp->shadow_width == 0) sp->shadow_width = 4;
313 int direction, ascent, descent;
319 /* Measure the heading_label. */
320 XTextExtents (sp->heading_font,
321 sp->heading_label, strlen(sp->heading_label),
322 &direction, &ascent, &descent, &overall);
323 if (overall.width > sp->width) sp->width = overall.width;
324 sp->height += ascent + descent;
326 /* Measure the body_label. */
327 XTextExtents (sp->body_font,
328 sp->body_label, strlen(sp->body_label),
329 &direction, &ascent, &descent, &overall);
330 if (overall.width > sp->width) sp->width = overall.width;
331 sp->height += ascent + descent;
333 /* Measure the body2_label. */
334 XTextExtents (sp->body_font,
335 sp->body2_label, strlen(sp->body2_label),
336 &direction, &ascent, &descent, &overall);
337 if (overall.width > sp->width) sp->width = overall.width;
338 sp->height += ascent + descent;
340 /* Measure the optional body3_label. */
343 XTextExtents (sp->heading_font,
344 sp->body3_label, strlen(sp->body3_label),
345 &direction, &ascent, &descent, &overall);
346 if (overall.width > sp->width) sp->width = overall.width;
347 XTextExtents (sp->heading_font,
348 sp->body4_label, strlen(sp->body4_label),
349 &direction, &ascent, &descent, &overall);
350 if (overall.width > sp->width) sp->width = overall.width;
351 sp->height += (ascent + descent) * 5;
355 Dimension w2 = 0, w3 = 0, w4 = 0;
356 Dimension h2 = 0, h3 = 0, h4 = 0;
358 /* Measure the Demo button. */
359 XTextExtents (sp->button_font,
360 sp->demo_label, strlen(sp->demo_label),
361 &direction, &ascent, &descent, &overall);
363 h2 = ascent + descent;
366 /* Measure the Prefs button. */
367 XTextExtents (sp->button_font,
368 sp->prefs_label, strlen(sp->prefs_label),
369 &direction, &ascent, &descent, &overall);
371 h3 = ascent + descent;
372 #else /* !PREFS_BUTTON */
375 #endif /* !PREFS_BUTTON */
377 /* Measure the Help button. */
378 XTextExtents (sp->button_font,
379 sp->help_label, strlen(sp->help_label),
380 &direction, &ascent, &descent, &overall);
382 h4 = ascent + descent;
384 w2 = MAX(w2, w3); w2 = MAX(w2, w4);
385 h2 = MAX(h2, h3); h2 = MAX(h2, h4);
387 /* Add some horizontal padding inside the buttons. */
390 w2 += ((ascent + descent) / 2) + (sp->shadow_width * 2);
391 h2 += ((ascent + descent) / 2) + (sp->shadow_width * 2);
393 sp->button_width = w2;
394 sp->button_height = h2;
398 #else /* !PREFS_BUTTON */
400 #endif /* !PREFS_BUTTON */
402 w2 += ((ascent + descent) * 2); /* for space between buttons */
404 if (w2 > sp->width) sp->width = w2;
408 sp->width += (sp->internal_border * 2);
409 sp->height += (sp->internal_border * 3);
411 if (sp->logo_height > sp->height)
412 sp->height = sp->logo_height;
413 else if (sp->height > sp->logo_height)
414 sp->logo_height = sp->height;
416 sp->logo_width = sp->logo_height;
418 sp->width += sp->logo_width;
421 attrmask |= CWOverrideRedirect; attrs.override_redirect = True;
422 attrmask |= CWEventMask;
423 attrs.event_mask = (ExposureMask | ButtonPressMask | ButtonReleaseMask);
426 int sx = 0, sy = 0, w, h;
427 int mouse_x = 0, mouse_y = 0;
430 Window pointer_root, pointer_child;
431 int root_x, root_y, win_x, win_y;
433 if (XQueryPointer (si->dpy,
434 RootWindowOfScreen (ssi->screen),
435 &pointer_root, &pointer_child,
436 &root_x, &root_y, &win_x, &win_y, &mask))
447 if (si->prefs.debug_p) w /= 2;
448 x = sx + (((w + sp->width) / 2) - sp->width);
449 y = sy + (((h + sp->height) / 2) - sp->height);
454 bw = get_integer_resource (si->dpy,
455 "splash.borderWidth",
456 "Dialog.BorderWidth");
459 XCreateWindow (si->dpy,
460 RootWindowOfScreen(ssi->screen),
461 x, y, sp->width, sp->height, bw,
462 DefaultDepthOfScreen (ssi->screen), InputOutput,
463 DefaultVisualOfScreen(ssi->screen),
465 XSetWindowBackground (si->dpy, si->splash_dialog, sp->background);
466 XSetWindowBorder (si->dpy, si->splash_dialog, sp->border);
469 sp->logo_pixmap = xscreensaver_logo (ssi->screen,
470 /* same visual as si->splash_dialog */
471 DefaultVisualOfScreen (ssi->screen),
472 si->splash_dialog, cmap,
474 &sp->logo_pixels, &sp->logo_npixels,
475 &sp->logo_clipmask, True);
477 XMapRaised (si->dpy, si->splash_dialog);
478 XSync (si->dpy, False);
482 sp->timer = XtAppAddTimeOut (si->app, si->prefs.splash_duration,
483 unsplash_timer, (XtPointer) si);
485 draw_splash_window (si);
486 XSync (si->dpy, False);
491 draw_splash_window (saver_info *si)
493 splash_dialog_data *sp = si->sp_data;
496 int hspacing, vspacing, height;
497 int x1, x2, x3, y1, y2;
502 #else /* !PREFS_BUTTON */
504 #endif /* !PREFS_BUTTON */
506 height = (sp->heading_font->ascent + sp->heading_font->descent +
507 sp->body_font->ascent + sp->body_font->descent +
508 sp->body_font->ascent + sp->body_font->descent +
509 sp->button_font->ascent + sp->button_font->descent);
510 vspacing = ((sp->height
511 - (4 * sp->shadow_width)
512 - (2 * sp->internal_border)
514 if (vspacing < 0) vspacing = 0;
515 if (vspacing > (sp->heading_font->ascent * 2))
516 vspacing = (sp->heading_font->ascent * 2);
518 gcv.foreground = sp->foreground;
519 gc1 = XCreateGC (si->dpy, si->splash_dialog, GCForeground, &gcv);
520 gc2 = XCreateGC (si->dpy, si->splash_dialog, GCForeground, &gcv);
522 x3 = sp->width - (sp->shadow_width * 2);
523 y1 = sp->internal_border;
527 XSetFont (si->dpy, gc1, sp->heading_font->fid);
528 sw = string_width (sp->heading_font, sp->heading_label);
529 x2 = (x1 + ((x3 - x1 - sw) / 2));
530 y1 += sp->heading_font->ascent;
531 XDrawString (si->dpy, si->splash_dialog, gc1, x2, y1,
532 sp->heading_label, strlen(sp->heading_label));
533 y1 += sp->heading_font->descent;
535 /* text below top heading
537 XSetFont (si->dpy, gc1, sp->body_font->fid);
538 y1 += vspacing + sp->body_font->ascent;
539 sw = string_width (sp->body_font, sp->body_label);
540 x2 = (x1 + ((x3 - x1 - sw) / 2));
541 XDrawString (si->dpy, si->splash_dialog, gc1, x2, y1,
542 sp->body_label, strlen(sp->body_label));
543 y1 += sp->body_font->descent;
545 y1 += sp->body_font->ascent;
546 sw = string_width (sp->body_font, sp->body2_label);
547 x2 = (x1 + ((x3 - x1 - sw) / 2));
548 XDrawString (si->dpy, si->splash_dialog, gc1, x2, y1,
549 sp->body2_label, strlen(sp->body2_label));
550 y1 += sp->body_font->descent;
554 XSetFont (si->dpy, gc1, sp->heading_font->fid);
555 y1 += sp->heading_font->ascent + sp->heading_font->descent;
556 y1 += sp->heading_font->ascent;
557 sw = string_width (sp->heading_font, sp->body3_label);
558 x2 = (x1 + ((x3 - x1 - sw) / 2));
559 XDrawString (si->dpy, si->splash_dialog, gc1, x2, y1,
560 sp->body3_label, strlen(sp->body3_label));
561 y1 += sp->heading_font->descent + sp->heading_font->ascent;
562 sw = string_width (sp->heading_font, sp->body4_label);
563 x2 = (x1 + ((x3 - x1 - sw) / 2));
564 XDrawString (si->dpy, si->splash_dialog, gc1, x2, y1,
565 sp->body4_label, strlen(sp->body4_label));
566 y1 += sp->heading_font->descent;
567 XSetFont (si->dpy, gc1, sp->body_font->fid);
572 XSetForeground (si->dpy, gc1, sp->button_foreground);
573 XSetForeground (si->dpy, gc2, sp->button_background);
575 /* y1 += (vspacing * 2);*/
576 y1 = sp->height - sp->internal_border - sp->button_height;
578 x1 += sp->internal_border;
579 y2 = (y1 + ((sp->button_height -
580 (sp->button_font->ascent + sp->button_font->descent))
582 + sp->button_font->ascent);
583 hspacing = ((sp->width - x1 - (sp->shadow_width * 2) -
584 sp->internal_border - (sp->button_width * nbuttons))
587 x2 = x1 + ((sp->button_width - string_width(sp->button_font, sp->demo_label))
589 XFillRectangle (si->dpy, si->splash_dialog, gc2, x1, y1,
590 sp->button_width, sp->button_height);
591 XDrawString (si->dpy, si->splash_dialog, gc1, x2, y2,
592 sp->demo_label, strlen(sp->demo_label));
593 sp->demo_button_x = x1;
594 sp->demo_button_y = y1;
597 x1 += hspacing + sp->button_width;
598 x2 = x1 + ((sp->button_width - string_width(sp->button_font,sp->prefs_label))
600 XFillRectangle (si->dpy, si->splash_dialog, gc2, x1, y1,
601 sp->button_width, sp->button_height);
602 XDrawString (si->dpy, si->splash_dialog, gc1, x2, y2,
603 sp->prefs_label, strlen(sp->prefs_label));
604 sp->prefs_button_x = x1;
605 sp->prefs_button_y = y1;
606 #endif /* PREFS_BUTTON */
609 x1 += hspacing + sp->button_width;
610 #else /* !PREFS_BUTTON */
611 x1 = (sp->width - sp->button_width -
612 sp->internal_border - (sp->shadow_width * 2));
613 #endif /* !PREFS_BUTTON */
615 x2 = x1 + ((sp->button_width - string_width(sp->button_font,sp->help_label))
617 XFillRectangle (si->dpy, si->splash_dialog, gc2, x1, y1,
618 sp->button_width, sp->button_height);
619 XDrawString (si->dpy, si->splash_dialog, gc1, x2, y2,
620 sp->help_label, strlen(sp->help_label));
621 sp->help_button_x = x1;
622 sp->help_button_y = y1;
627 x1 = sp->shadow_width * 6;
628 y1 = sp->shadow_width * 6;
629 x2 = sp->logo_width - (sp->shadow_width * 12);
630 y2 = sp->logo_height - (sp->shadow_width * 12);
636 unsigned int w, h, bw, d;
637 XGetGeometry (si->dpy, sp->logo_pixmap, &root, &x, &y, &w, &h, &bw, &d);
638 XSetForeground (si->dpy, gc1, sp->foreground);
639 XSetBackground (si->dpy, gc1, sp->background);
640 XSetClipMask (si->dpy, gc1, sp->logo_clipmask);
641 XSetClipOrigin (si->dpy, gc1, x1 + ((x2 - (int)w) /2), y1 + ((y2 - (int)h) / 2));
643 XCopyPlane (si->dpy, sp->logo_pixmap, si->splash_dialog, gc1,
645 x1 + ((x2 - (int)w) / 2),
646 y1 + ((y2 - (int)h) / 2),
649 XCopyArea (si->dpy, sp->logo_pixmap, si->splash_dialog, gc1,
651 x1 + ((x2 - (int)w) / 2),
652 y1 + ((y2 - (int)h) / 2));
655 /* Solid border inside the logo box. */
657 XSetForeground (si->dpy, gc1, sp->foreground);
658 XDrawRectangle (si->dpy, si->splash_dialog, gc1, x1, y1, x2-1, y2-1);
661 /* The shadow around the logo
663 draw_shaded_rectangle (si->dpy, si->splash_dialog,
664 sp->shadow_width * 4,
665 sp->shadow_width * 4,
666 sp->logo_width - (sp->shadow_width * 8),
667 sp->logo_height - (sp->shadow_width * 8),
669 sp->shadow_bottom, sp->shadow_top);
671 /* The shadow around the whole window
673 draw_shaded_rectangle (si->dpy, si->splash_dialog,
674 0, 0, sp->width, sp->height, sp->shadow_width,
675 sp->shadow_top, sp->shadow_bottom);
677 XFreeGC (si->dpy, gc1);
678 XFreeGC (si->dpy, gc2);
680 update_splash_window (si);
685 update_splash_window (saver_info *si)
687 splash_dialog_data *sp = si->sp_data;
690 pressed = sp->pressed;
692 /* The shadows around the buttons
694 draw_shaded_rectangle (si->dpy, si->splash_dialog,
695 sp->demo_button_x, sp->demo_button_y,
696 sp->button_width, sp->button_height, sp->shadow_width,
697 (pressed == 1 ? sp->shadow_bottom : sp->shadow_top),
698 (pressed == 1 ? sp->shadow_top : sp->shadow_bottom));
700 draw_shaded_rectangle (si->dpy, si->splash_dialog,
701 sp->prefs_button_x, sp->prefs_button_y,
702 sp->button_width, sp->button_height, sp->shadow_width,
703 (pressed == 2 ? sp->shadow_bottom : sp->shadow_top),
704 (pressed == 2 ? sp->shadow_top : sp->shadow_bottom));
705 #endif /* PREFS_BUTTON */
706 draw_shaded_rectangle (si->dpy, si->splash_dialog,
707 sp->help_button_x, sp->help_button_y,
708 sp->button_width, sp->button_height, sp->shadow_width,
709 (pressed == 3 ? sp->shadow_bottom : sp->shadow_top),
710 (pressed == 3 ? sp->shadow_top : sp->shadow_bottom));
714 destroy_splash_window (saver_info *si)
716 splash_dialog_data *sp = si->sp_data;
717 saver_screen_info *ssi = sp->prompt_screen;
718 Colormap cmap = DefaultColormapOfScreen (ssi->screen);
719 Pixel black = BlackPixelOfScreen (ssi->screen);
720 Pixel white = WhitePixelOfScreen (ssi->screen);
723 XtRemoveTimeOut (sp->timer);
725 if (si->splash_dialog)
727 XDestroyWindow (si->dpy, si->splash_dialog);
728 si->splash_dialog = 0;
731 if (sp->heading_label) free (sp->heading_label);
732 if (sp->body_label) free (sp->body_label);
733 if (sp->body2_label) free (sp->body2_label);
734 if (sp->body3_label) free (sp->body3_label);
735 if (sp->body4_label) free (sp->body4_label);
736 if (sp->demo_label) free (sp->demo_label);
738 if (sp->prefs_label) free (sp->prefs_label);
739 #endif /* PREFS_BUTTON */
740 if (sp->help_label) free (sp->help_label);
742 if (sp->heading_font) XFreeFont (si->dpy, sp->heading_font);
743 if (sp->body_font) XFreeFont (si->dpy, sp->body_font);
744 if (sp->button_font) XFreeFont (si->dpy, sp->button_font);
746 if (sp->foreground != black && sp->foreground != white)
747 XFreeColors (si->dpy, cmap, &sp->foreground, 1, 0L);
748 if (sp->background != black && sp->background != white)
749 XFreeColors (si->dpy, cmap, &sp->background, 1, 0L);
750 if (sp->button_foreground != black && sp->button_foreground != white)
751 XFreeColors (si->dpy, cmap, &sp->button_foreground, 1, 0L);
752 if (sp->button_background != black && sp->button_background != white)
753 XFreeColors (si->dpy, cmap, &sp->button_background, 1, 0L);
754 if (sp->shadow_top != black && sp->shadow_top != white)
755 XFreeColors (si->dpy, cmap, &sp->shadow_top, 1, 0L);
756 if (sp->shadow_bottom != black && sp->shadow_bottom != white)
757 XFreeColors (si->dpy, cmap, &sp->shadow_bottom, 1, 0L);
760 XFreePixmap (si->dpy, sp->logo_pixmap);
761 if (sp->logo_clipmask)
762 XFreePixmap (si->dpy, sp->logo_clipmask);
765 if (sp->logo_npixels)
766 XFreeColors (si->dpy, cmap, sp->logo_pixels, sp->logo_npixels, 0L);
767 free (sp->logo_pixels);
769 sp->logo_npixels = 0;
772 memset (sp, 0, sizeof(*sp));
778 handle_splash_event (saver_info *si, XEvent *event)
780 splash_dialog_data *sp = si->sp_data;
781 saver_screen_info *ssi;
784 ssi = sp->prompt_screen;
786 switch (event->xany.type)
789 draw_splash_window (si);
792 case ButtonPress: case ButtonRelease:
794 if (event->xbutton.x >= sp->demo_button_x &&
795 event->xbutton.x < sp->demo_button_x + sp->button_width &&
796 event->xbutton.y >= sp->demo_button_y &&
797 event->xbutton.y < sp->demo_button_y + sp->button_height)
801 else if (event->xbutton.x >= sp->prefs_button_x &&
802 event->xbutton.x < sp->prefs_button_x + sp->button_width &&
803 event->xbutton.y >= sp->prefs_button_y &&
804 event->xbutton.y < sp->prefs_button_y + sp->button_height)
806 #endif /* PREFS_BUTTON */
808 else if (event->xbutton.x >= sp->help_button_x &&
809 event->xbutton.x < sp->help_button_x + sp->button_width &&
810 event->xbutton.y >= sp->help_button_y &&
811 event->xbutton.y < sp->help_button_y + sp->button_height)
814 if (event->xany.type == ButtonPress)
817 update_splash_window (si);
819 XBell (si->dpy, False);
821 else if (event->xany.type == ButtonRelease)
823 if (which && sp->pressed == which)
825 destroy_splash_window (si);
829 case 1: do_demo (ssi); break;
831 case 2: do_prefs (ssi); break;
832 #endif /* PREFS_BUTTON */
833 case 3: do_help (ssi); break;
837 else if (which == 0 && sp->pressed == 0)
839 /* click and release on the window but not in a button:
840 treat that as "dismiss the splash dialog." */
841 destroy_splash_window (si);
844 if (sp) sp->pressed = 0;
845 update_splash_window (si);
855 unsplash_timer (XtPointer closure, XtIntervalId *id)
857 saver_info *si = (saver_info *) closure;
858 if (si && si->sp_data)
859 destroy_splash_window (si);
863 /* Button callbacks */
872 do_demo (saver_screen_info *ssi)
874 saver_info *si = ssi->global;
875 saver_preferences *p = &si->prefs;
876 const char *cmd = p->demo_command;
879 fork_and_exec (ssi, cmd);
881 fprintf (stderr, "%s: no demo-mode command has been specified.\n",
887 do_prefs (saver_screen_info *ssi)
889 saver_info *si = ssi->global;
890 saver_preferences *p = &si->prefs;
891 const char *cmd = p->prefs_command;
893 if (command && *command)
894 fork_and_exec (ssi, cmd);
896 fprintf (stderr, "%s: no preferences command has been specified.\n",
899 #endif /* PREFS_BUTTON */
902 do_help (saver_screen_info *ssi)
904 saver_info *si = ssi->global;
905 saver_preferences *p = &si->prefs;
906 char *help_command = 0;
908 if (!p->load_url_command || !*p->load_url_command)
910 fprintf (stderr, "%s: no URL command has been specified.\n", blurb());
913 if (!p->help_url || !*p->help_url)
915 fprintf (stderr, "%s: no Help URL has been specified.\n", blurb());
919 help_command = (char *) malloc (strlen (p->load_url_command) +
920 (strlen (p->help_url) * 4) + 10);
921 sprintf (help_command, p->load_url_command,
922 p->help_url, p->help_url, p->help_url, p->help_url);
924 fork_and_exec (ssi, help_command);