1 /* xscreensaver, Copyright (c) 1991-2014, 2016
2 * -Jamie Zawinski <jwz@netscape.com>
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation. No representations are made about the suitability of this
9 * software for any purpose. It is provided "as is" without express or
17 #include <X11/Intrinsic.h>
19 #include "xscreensaver.h"
20 #include "resources.h"
23 #define MAX(a,b) ((a)>(b)?(a):(b))
26 draw_shaded_rectangle (Display *dpy, Window window,
28 int width, int height,
30 unsigned long top_color,
31 unsigned long bottom_color)
36 if (thickness == 0) return;
38 gcv.foreground = top_color;
39 gc1 = XCreateGC (dpy, window, GCForeground, &gcv);
40 gcv.foreground = bottom_color;
41 gc2 = XCreateGC (dpy, window, GCForeground, &gcv);
45 points [1].x = x + width;
47 points [2].x = x + width - thickness;
48 points [2].y = y + thickness;
50 points [3].y = y + thickness;
51 XFillPolygon (dpy, window, gc1, points, 4, Convex, CoordModeOrigin);
54 points [0].y = y + thickness;
56 points [1].y = y + height;
57 points [2].x = x + thickness;
58 points [2].y = y + height - thickness;
59 points [3].x = x + thickness;
60 points [3].y = y + thickness;
61 XFillPolygon (dpy, window, gc1, points, 4, Convex, CoordModeOrigin);
63 points [0].x = x + width;
65 points [1].x = x + width - thickness;
66 points [1].y = y + thickness;
67 points [2].x = x + width - thickness;
68 points [2].y = y + height - thickness;
69 points [3].x = x + width;
70 points [3].y = y + height - thickness;
71 XFillPolygon (dpy, window, gc2, points, 4, Convex, CoordModeOrigin);
74 points [0].y = y + height;
75 points [1].x = x + width;
76 points [1].y = y + height;
77 points [2].x = x + width;
78 points [2].y = y + height - thickness;
79 points [3].x = x + thickness;
80 points [3].y = y + height - thickness;
81 XFillPolygon (dpy, window, gc2, points, 4, Convex, CoordModeOrigin);
89 string_width (XFontStruct *font, char *s)
91 return XTextWidth(font, s, strlen(s));
95 static void update_splash_window (saver_info *si);
96 static void draw_splash_window (saver_info *si);
97 static void destroy_splash_window (saver_info *si);
98 static void unsplash_timer (XtPointer closure, XtIntervalId *id);
100 static void do_demo (saver_screen_info *ssi);
102 static void do_prefs (saver_screen_info *ssi);
103 #endif /* PREFS_BUTTON */
104 static void do_help (saver_screen_info *ssi);
107 struct splash_dialog_data {
109 saver_screen_info *prompt_screen;
123 #endif /* PREFS_BUTTON */
126 XFontStruct *heading_font;
127 XFontStruct *body_font;
128 XFontStruct *button_font;
133 Pixel button_foreground;
134 Pixel button_background;
138 Dimension logo_width;
139 Dimension logo_height;
140 Dimension internal_border;
141 Dimension shadow_width;
143 Dimension button_width, button_height;
144 Dimension demo_button_x, demo_button_y;
146 Dimension prefs_button_x, prefs_button_y;
147 #endif /* PREFS_BUTTON */
148 Dimension help_button_x, help_button_y;
151 Pixmap logo_clipmask;
153 unsigned long *logo_pixels;
160 make_splash_dialog (saver_info *si)
162 saver_preferences *p = &si->prefs;
164 XSetWindowAttributes attrs;
165 unsigned long attrmask = 0;
166 splash_dialog_data *sp;
167 saver_screen_info *ssi;
171 Bool whine = decrepit_p ();
175 /* If locking is not enabled, make sure they see the message. */
178 si->prefs.splash_p = True;
179 if (si->prefs.splash_duration < 5000)
180 si->prefs.splash_duration = 5000;
182 si->prefs.splash_duration += 3000;
187 if (!si->prefs.splash_p ||
188 si->prefs.splash_duration <= 0)
191 ssi = &si->screens[mouse_screen (si)];
193 if (!ssi || !ssi->screen)
194 return; /* WTF? Trying to splash while no screens connected? */
196 cmap = DefaultColormapOfScreen (ssi->screen);
198 sp = (splash_dialog_data *) calloc (1, sizeof(*sp));
199 sp->prompt_screen = ssi;
201 sp->heading_label = get_string_resource (si->dpy,
202 "splash.heading.label",
203 "Dialog.Label.Label");
204 sp->body_label = get_string_resource (si->dpy,
206 "Dialog.Label.Label");
207 sp->body2_label = get_string_resource (si->dpy,
208 "splash.body2.label",
209 "Dialog.Label.Label");
210 sp->demo_label = get_string_resource (si->dpy,
212 "Dialog.Button.Label");
214 sp->prefs_label = get_string_resource (si->dpy,
215 "splash.prefs.label",
216 "Dialog.Button.Label");
217 #endif /* PREFS_BUTTON */
218 sp->help_label = get_string_resource (si->dpy,
220 "Dialog.Button.Label");
226 sp->body3_label = strdup("WARNING: This version is very old!");
227 sp->body4_label = strdup("Please upgrade!");
230 if (!sp->heading_label)
231 sp->heading_label = strdup("ERROR: REESOURCES NOT INSTALLED CORRECTLY");
233 sp->body_label = strdup("ERROR: REESOURCES NOT INSTALLED CORRECTLY");
234 if (!sp->body2_label)
235 sp->body2_label = strdup("ERROR: REESOURCES NOT INSTALLED CORRECTLY");
236 if (!sp->demo_label) sp->demo_label = strdup("ERROR");
238 if (!sp->prefs_label) sp->prefs_label = strdup("ERROR");
239 #endif /* PREFS_BUTTON */
240 if (!sp->help_label) sp->help_label = strdup("ERROR");
242 /* Put the version number in the label. */
244 char *s = (char *) malloc (strlen(sp->heading_label) + 20);
245 sprintf(s, sp->heading_label, si->version);
246 free (sp->heading_label);
247 sp->heading_label = s;
250 f = get_string_resource (si->dpy, "splash.headingFont", "Dialog.Font");
251 sp->heading_font = XLoadQueryFont (si->dpy, (f ? f : "fixed"));
252 if (!sp->heading_font) sp->heading_font = XLoadQueryFont (si->dpy, "fixed");
255 f = get_string_resource(si->dpy, "splash.bodyFont", "Dialog.Font");
256 sp->body_font = XLoadQueryFont (si->dpy, (f ? f : "fixed"));
257 if (!sp->body_font) sp->body_font = XLoadQueryFont (si->dpy, "fixed");
260 f = get_string_resource(si->dpy, "splash.buttonFont", "Dialog.Font");
261 sp->button_font = XLoadQueryFont (si->dpy, (f ? f : "fixed"));
262 if (!sp->button_font) sp->button_font = XLoadQueryFont (si->dpy, "fixed");
265 sp->foreground = get_pixel_resource (si->dpy, cmap,
267 "Dialog.Foreground");
268 sp->background = get_pixel_resource (si->dpy, cmap,
270 "Dialog.Background");
271 sp->border = get_pixel_resource (si->dpy, cmap,
272 "splash.borderColor",
273 "Dialog.borderColor");
275 if (sp->foreground == sp->background)
277 /* Make sure the error messages show up. */
278 sp->foreground = BlackPixelOfScreen (ssi->screen);
279 sp->background = WhitePixelOfScreen (ssi->screen);
282 sp->button_foreground = get_pixel_resource (si->dpy, cmap,
283 "splash.Button.foreground",
284 "Dialog.Button.Foreground");
285 sp->button_background = get_pixel_resource (si->dpy, cmap,
286 "splash.Button.background",
287 "Dialog.Button.Background");
288 sp->shadow_top = get_pixel_resource (si->dpy, cmap,
289 "splash.topShadowColor",
290 "Dialog.Foreground");
291 sp->shadow_bottom = get_pixel_resource (si->dpy, cmap,
292 "splash.bottomShadowColor",
293 "Dialog.Background");
295 sp->logo_width = get_integer_resource (si->dpy,
297 "Dialog.Logo.Width");
298 sp->logo_height = get_integer_resource (si->dpy,
299 "splash.logo.height",
300 "Dialog.Logo.Height");
301 sp->internal_border = get_integer_resource (si->dpy,
302 "splash.internalBorderWidth",
303 "Dialog.InternalBorderWidth");
304 sp->shadow_width = get_integer_resource (si->dpy,
305 "splash.shadowThickness",
306 "Dialog.ShadowThickness");
308 if (sp->logo_width == 0) sp->logo_width = 150;
309 if (sp->logo_height == 0) sp->logo_height = 150;
310 if (sp->internal_border == 0) sp->internal_border = 15;
311 if (sp->shadow_width == 0) sp->shadow_width = 4;
314 int direction, ascent, descent;
320 /* Measure the heading_label. */
321 XTextExtents (sp->heading_font,
322 sp->heading_label, strlen(sp->heading_label),
323 &direction, &ascent, &descent, &overall);
324 if (overall.width > sp->width) sp->width = overall.width;
325 sp->height += ascent + descent;
327 /* Measure the body_label. */
328 XTextExtents (sp->body_font,
329 sp->body_label, strlen(sp->body_label),
330 &direction, &ascent, &descent, &overall);
331 if (overall.width > sp->width) sp->width = overall.width;
332 sp->height += ascent + descent;
334 /* Measure the body2_label. */
335 XTextExtents (sp->body_font,
336 sp->body2_label, strlen(sp->body2_label),
337 &direction, &ascent, &descent, &overall);
338 if (overall.width > sp->width) sp->width = overall.width;
339 sp->height += ascent + descent;
341 /* Measure the optional body3_label. */
344 XTextExtents (sp->heading_font,
345 sp->body3_label, strlen(sp->body3_label),
346 &direction, &ascent, &descent, &overall);
347 if (overall.width > sp->width) sp->width = overall.width;
348 XTextExtents (sp->heading_font,
349 sp->body4_label, strlen(sp->body4_label),
350 &direction, &ascent, &descent, &overall);
351 if (overall.width > sp->width) sp->width = overall.width;
352 sp->height += (ascent + descent) * 5;
356 Dimension w2 = 0, w3 = 0, w4 = 0;
357 Dimension h2 = 0, h3 = 0, h4 = 0;
359 /* Measure the Demo button. */
360 XTextExtents (sp->button_font,
361 sp->demo_label, strlen(sp->demo_label),
362 &direction, &ascent, &descent, &overall);
364 h2 = ascent + descent;
367 /* Measure the Prefs button. */
368 XTextExtents (sp->button_font,
369 sp->prefs_label, strlen(sp->prefs_label),
370 &direction, &ascent, &descent, &overall);
372 h3 = ascent + descent;
373 #else /* !PREFS_BUTTON */
376 #endif /* !PREFS_BUTTON */
378 /* Measure the Help button. */
379 XTextExtents (sp->button_font,
380 sp->help_label, strlen(sp->help_label),
381 &direction, &ascent, &descent, &overall);
383 h4 = ascent + descent;
385 w2 = MAX(w2, w3); w2 = MAX(w2, w4);
386 h2 = MAX(h2, h3); h2 = MAX(h2, h4);
388 /* Add some horizontal padding inside the buttons. */
391 w2 += ((ascent + descent) / 2) + (sp->shadow_width * 2);
392 h2 += ((ascent + descent) / 2) + (sp->shadow_width * 2);
394 sp->button_width = w2;
395 sp->button_height = h2;
399 #else /* !PREFS_BUTTON */
401 #endif /* !PREFS_BUTTON */
403 w2 += ((ascent + descent) * 2); /* for space between buttons */
405 if (w2 > sp->width) sp->width = w2;
409 sp->width += (sp->internal_border * 2);
410 sp->height += (sp->internal_border * 3);
412 if (sp->logo_height > sp->height)
413 sp->height = sp->logo_height;
414 else if (sp->height > sp->logo_height)
415 sp->logo_height = sp->height;
417 sp->logo_width = sp->logo_height;
419 sp->width += sp->logo_width;
422 attrmask |= CWOverrideRedirect; attrs.override_redirect = True;
423 attrmask |= CWEventMask;
424 attrs.event_mask = (ExposureMask | ButtonPressMask | ButtonReleaseMask);
427 int sx = 0, sy = 0, w, h;
428 int mouse_x = 0, mouse_y = 0;
431 Window pointer_root, pointer_child;
432 int root_x, root_y, win_x, win_y;
434 if (XQueryPointer (si->dpy,
435 RootWindowOfScreen (ssi->screen),
436 &pointer_root, &pointer_child,
437 &root_x, &root_y, &win_x, &win_y, &mask))
448 if (si->prefs.debug_p) w /= 2;
449 x = sx + (((w + sp->width) / 2) - sp->width);
450 y = sy + (((h + sp->height) / 2) - sp->height);
455 bw = get_integer_resource (si->dpy,
456 "splash.borderWidth",
457 "Dialog.BorderWidth");
460 XCreateWindow (si->dpy,
461 RootWindowOfScreen(ssi->screen),
462 x, y, sp->width, sp->height, bw,
463 DefaultDepthOfScreen (ssi->screen), InputOutput,
464 DefaultVisualOfScreen(ssi->screen),
466 XSetWindowBackground (si->dpy, si->splash_dialog, sp->background);
467 XSetWindowBorder (si->dpy, si->splash_dialog, sp->border);
470 sp->logo_pixmap = xscreensaver_logo (ssi->screen,
471 /* same visual as si->splash_dialog */
472 DefaultVisualOfScreen (ssi->screen),
473 si->splash_dialog, cmap,
475 &sp->logo_pixels, &sp->logo_npixels,
476 &sp->logo_clipmask, True);
478 XMapRaised (si->dpy, si->splash_dialog);
479 XSync (si->dpy, False);
483 sp->timer = XtAppAddTimeOut (si->app, si->prefs.splash_duration,
484 unsplash_timer, (XtPointer) si);
486 draw_splash_window (si);
487 XSync (si->dpy, False);
492 draw_splash_window (saver_info *si)
494 splash_dialog_data *sp = si->sp_data;
497 int hspacing, vspacing, height;
498 int x1, x2, x3, y1, y2;
503 #else /* !PREFS_BUTTON */
505 #endif /* !PREFS_BUTTON */
507 height = (sp->heading_font->ascent + sp->heading_font->descent +
508 sp->body_font->ascent + sp->body_font->descent +
509 sp->body_font->ascent + sp->body_font->descent +
510 sp->button_font->ascent + sp->button_font->descent);
511 vspacing = ((sp->height
512 - (4 * sp->shadow_width)
513 - (2 * sp->internal_border)
515 if (vspacing < 0) vspacing = 0;
516 if (vspacing > (sp->heading_font->ascent * 2))
517 vspacing = (sp->heading_font->ascent * 2);
519 gcv.foreground = sp->foreground;
520 gc1 = XCreateGC (si->dpy, si->splash_dialog, GCForeground, &gcv);
521 gc2 = XCreateGC (si->dpy, si->splash_dialog, GCForeground, &gcv);
523 x3 = sp->width - (sp->shadow_width * 2);
524 y1 = sp->internal_border;
528 XSetFont (si->dpy, gc1, sp->heading_font->fid);
529 sw = string_width (sp->heading_font, sp->heading_label);
530 x2 = (x1 + ((x3 - x1 - sw) / 2));
531 y1 += sp->heading_font->ascent;
532 XDrawString (si->dpy, si->splash_dialog, gc1, x2, y1,
533 sp->heading_label, strlen(sp->heading_label));
534 y1 += sp->heading_font->descent;
536 /* text below top heading
538 XSetFont (si->dpy, gc1, sp->body_font->fid);
539 y1 += vspacing + sp->body_font->ascent;
540 sw = string_width (sp->body_font, sp->body_label);
541 x2 = (x1 + ((x3 - x1 - sw) / 2));
542 XDrawString (si->dpy, si->splash_dialog, gc1, x2, y1,
543 sp->body_label, strlen(sp->body_label));
544 y1 += sp->body_font->descent;
546 y1 += sp->body_font->ascent;
547 sw = string_width (sp->body_font, sp->body2_label);
548 x2 = (x1 + ((x3 - x1 - sw) / 2));
549 XDrawString (si->dpy, si->splash_dialog, gc1, x2, y1,
550 sp->body2_label, strlen(sp->body2_label));
551 y1 += sp->body_font->descent;
555 XSetFont (si->dpy, gc1, sp->heading_font->fid);
556 y1 += sp->heading_font->ascent + sp->heading_font->descent;
557 y1 += sp->heading_font->ascent;
558 sw = string_width (sp->heading_font, sp->body3_label);
559 x2 = (x1 + ((x3 - x1 - sw) / 2));
560 XDrawString (si->dpy, si->splash_dialog, gc1, x2, y1,
561 sp->body3_label, strlen(sp->body3_label));
562 y1 += sp->heading_font->descent + sp->heading_font->ascent;
563 sw = string_width (sp->heading_font, sp->body4_label);
564 x2 = (x1 + ((x3 - x1 - sw) / 2));
565 XDrawString (si->dpy, si->splash_dialog, gc1, x2, y1,
566 sp->body4_label, strlen(sp->body4_label));
567 y1 += sp->heading_font->descent;
568 XSetFont (si->dpy, gc1, sp->body_font->fid);
573 XSetForeground (si->dpy, gc1, sp->button_foreground);
574 XSetForeground (si->dpy, gc2, sp->button_background);
576 /* y1 += (vspacing * 2);*/
577 y1 = sp->height - sp->internal_border - sp->button_height;
579 x1 += sp->internal_border;
580 y2 = (y1 + ((sp->button_height -
581 (sp->button_font->ascent + sp->button_font->descent))
583 + sp->button_font->ascent);
584 hspacing = ((sp->width - x1 - (sp->shadow_width * 2) -
585 sp->internal_border - (sp->button_width * nbuttons))
588 x2 = x1 + ((sp->button_width - string_width(sp->button_font, sp->demo_label))
590 XFillRectangle (si->dpy, si->splash_dialog, gc2, x1, y1,
591 sp->button_width, sp->button_height);
592 XDrawString (si->dpy, si->splash_dialog, gc1, x2, y2,
593 sp->demo_label, strlen(sp->demo_label));
594 sp->demo_button_x = x1;
595 sp->demo_button_y = y1;
598 x1 += hspacing + sp->button_width;
599 x2 = x1 + ((sp->button_width - string_width(sp->button_font,sp->prefs_label))
601 XFillRectangle (si->dpy, si->splash_dialog, gc2, x1, y1,
602 sp->button_width, sp->button_height);
603 XDrawString (si->dpy, si->splash_dialog, gc1, x2, y2,
604 sp->prefs_label, strlen(sp->prefs_label));
605 sp->prefs_button_x = x1;
606 sp->prefs_button_y = y1;
607 #endif /* PREFS_BUTTON */
610 x1 += hspacing + sp->button_width;
611 #else /* !PREFS_BUTTON */
612 x1 = (sp->width - sp->button_width -
613 sp->internal_border - (sp->shadow_width * 2));
614 #endif /* !PREFS_BUTTON */
616 x2 = x1 + ((sp->button_width - string_width(sp->button_font,sp->help_label))
618 XFillRectangle (si->dpy, si->splash_dialog, gc2, x1, y1,
619 sp->button_width, sp->button_height);
620 XDrawString (si->dpy, si->splash_dialog, gc1, x2, y2,
621 sp->help_label, strlen(sp->help_label));
622 sp->help_button_x = x1;
623 sp->help_button_y = y1;
628 x1 = sp->shadow_width * 6;
629 y1 = sp->shadow_width * 6;
630 x2 = sp->logo_width - (sp->shadow_width * 12);
631 y2 = sp->logo_height - (sp->shadow_width * 12);
637 unsigned int w, h, bw, d;
638 XGetGeometry (si->dpy, sp->logo_pixmap, &root, &x, &y, &w, &h, &bw, &d);
639 XSetForeground (si->dpy, gc1, sp->foreground);
640 XSetBackground (si->dpy, gc1, sp->background);
641 XSetClipMask (si->dpy, gc1, sp->logo_clipmask);
642 XSetClipOrigin (si->dpy, gc1, x1 + ((x2 - (int)w) /2), y1 + ((y2 - (int)h) / 2));
644 XCopyPlane (si->dpy, sp->logo_pixmap, si->splash_dialog, gc1,
646 x1 + ((x2 - (int)w) / 2),
647 y1 + ((y2 - (int)h) / 2),
650 XCopyArea (si->dpy, sp->logo_pixmap, si->splash_dialog, gc1,
652 x1 + ((x2 - (int)w) / 2),
653 y1 + ((y2 - (int)h) / 2));
656 /* Solid border inside the logo box. */
658 XSetForeground (si->dpy, gc1, sp->foreground);
659 XDrawRectangle (si->dpy, si->splash_dialog, gc1, x1, y1, x2-1, y2-1);
662 /* The shadow around the logo
664 draw_shaded_rectangle (si->dpy, si->splash_dialog,
665 sp->shadow_width * 4,
666 sp->shadow_width * 4,
667 sp->logo_width - (sp->shadow_width * 8),
668 sp->logo_height - (sp->shadow_width * 8),
670 sp->shadow_bottom, sp->shadow_top);
672 /* The shadow around the whole window
674 draw_shaded_rectangle (si->dpy, si->splash_dialog,
675 0, 0, sp->width, sp->height, sp->shadow_width,
676 sp->shadow_top, sp->shadow_bottom);
678 XFreeGC (si->dpy, gc1);
679 XFreeGC (si->dpy, gc2);
681 update_splash_window (si);
686 update_splash_window (saver_info *si)
688 splash_dialog_data *sp = si->sp_data;
691 pressed = sp->pressed;
693 /* The shadows around the buttons
695 draw_shaded_rectangle (si->dpy, si->splash_dialog,
696 sp->demo_button_x, sp->demo_button_y,
697 sp->button_width, sp->button_height, sp->shadow_width,
698 (pressed == 1 ? sp->shadow_bottom : sp->shadow_top),
699 (pressed == 1 ? sp->shadow_top : sp->shadow_bottom));
701 draw_shaded_rectangle (si->dpy, si->splash_dialog,
702 sp->prefs_button_x, sp->prefs_button_y,
703 sp->button_width, sp->button_height, sp->shadow_width,
704 (pressed == 2 ? sp->shadow_bottom : sp->shadow_top),
705 (pressed == 2 ? sp->shadow_top : sp->shadow_bottom));
706 #endif /* PREFS_BUTTON */
707 draw_shaded_rectangle (si->dpy, si->splash_dialog,
708 sp->help_button_x, sp->help_button_y,
709 sp->button_width, sp->button_height, sp->shadow_width,
710 (pressed == 3 ? sp->shadow_bottom : sp->shadow_top),
711 (pressed == 3 ? sp->shadow_top : sp->shadow_bottom));
715 destroy_splash_window (saver_info *si)
717 splash_dialog_data *sp = si->sp_data;
718 saver_screen_info *ssi = sp->prompt_screen;
719 Colormap cmap = DefaultColormapOfScreen (ssi->screen);
720 Pixel black = BlackPixelOfScreen (ssi->screen);
721 Pixel white = WhitePixelOfScreen (ssi->screen);
724 XtRemoveTimeOut (sp->timer);
726 if (si->splash_dialog)
728 XDestroyWindow (si->dpy, si->splash_dialog);
729 si->splash_dialog = 0;
732 if (sp->heading_label) free (sp->heading_label);
733 if (sp->body_label) free (sp->body_label);
734 if (sp->body2_label) free (sp->body2_label);
735 if (sp->body3_label) free (sp->body3_label);
736 if (sp->body4_label) free (sp->body4_label);
737 if (sp->demo_label) free (sp->demo_label);
739 if (sp->prefs_label) free (sp->prefs_label);
740 #endif /* PREFS_BUTTON */
741 if (sp->help_label) free (sp->help_label);
743 if (sp->heading_font) XFreeFont (si->dpy, sp->heading_font);
744 if (sp->body_font) XFreeFont (si->dpy, sp->body_font);
745 if (sp->button_font) XFreeFont (si->dpy, sp->button_font);
747 if (sp->foreground != black && sp->foreground != white)
748 XFreeColors (si->dpy, cmap, &sp->foreground, 1, 0L);
749 if (sp->background != black && sp->background != white)
750 XFreeColors (si->dpy, cmap, &sp->background, 1, 0L);
751 if (sp->button_foreground != black && sp->button_foreground != white)
752 XFreeColors (si->dpy, cmap, &sp->button_foreground, 1, 0L);
753 if (sp->button_background != black && sp->button_background != white)
754 XFreeColors (si->dpy, cmap, &sp->button_background, 1, 0L);
755 if (sp->shadow_top != black && sp->shadow_top != white)
756 XFreeColors (si->dpy, cmap, &sp->shadow_top, 1, 0L);
757 if (sp->shadow_bottom != black && sp->shadow_bottom != white)
758 XFreeColors (si->dpy, cmap, &sp->shadow_bottom, 1, 0L);
761 XFreePixmap (si->dpy, sp->logo_pixmap);
762 if (sp->logo_clipmask)
763 XFreePixmap (si->dpy, sp->logo_clipmask);
766 if (sp->logo_npixels)
767 XFreeColors (si->dpy, cmap, sp->logo_pixels, sp->logo_npixels, 0L);
768 free (sp->logo_pixels);
770 sp->logo_npixels = 0;
773 memset (sp, 0, sizeof(*sp));
779 handle_splash_event (saver_info *si, XEvent *event)
781 splash_dialog_data *sp = si->sp_data;
782 saver_screen_info *ssi;
785 ssi = sp->prompt_screen;
787 switch (event->xany.type)
790 draw_splash_window (si);
793 case ButtonPress: case ButtonRelease:
795 if (event->xbutton.x >= sp->demo_button_x &&
796 event->xbutton.x < sp->demo_button_x + sp->button_width &&
797 event->xbutton.y >= sp->demo_button_y &&
798 event->xbutton.y < sp->demo_button_y + sp->button_height)
802 else if (event->xbutton.x >= sp->prefs_button_x &&
803 event->xbutton.x < sp->prefs_button_x + sp->button_width &&
804 event->xbutton.y >= sp->prefs_button_y &&
805 event->xbutton.y < sp->prefs_button_y + sp->button_height)
807 #endif /* PREFS_BUTTON */
809 else if (event->xbutton.x >= sp->help_button_x &&
810 event->xbutton.x < sp->help_button_x + sp->button_width &&
811 event->xbutton.y >= sp->help_button_y &&
812 event->xbutton.y < sp->help_button_y + sp->button_height)
815 if (event->xany.type == ButtonPress)
818 update_splash_window (si);
820 XBell (si->dpy, False);
822 else if (event->xany.type == ButtonRelease)
824 if (which && sp->pressed == which)
826 destroy_splash_window (si);
830 case 1: do_demo (ssi); break;
832 case 2: do_prefs (ssi); break;
833 #endif /* PREFS_BUTTON */
834 case 3: do_help (ssi); break;
838 else if (which == 0 && sp->pressed == 0)
840 /* click and release on the window but not in a button:
841 treat that as "dismiss the splash dialog." */
842 destroy_splash_window (si);
845 if (sp) sp->pressed = 0;
846 update_splash_window (si);
856 unsplash_timer (XtPointer closure, XtIntervalId *id)
858 saver_info *si = (saver_info *) closure;
859 if (si && si->sp_data)
860 destroy_splash_window (si);
864 /* Button callbacks */
873 do_demo (saver_screen_info *ssi)
875 saver_info *si = ssi->global;
876 saver_preferences *p = &si->prefs;
877 const char *cmd = p->demo_command;
880 fork_and_exec (ssi, cmd);
882 fprintf (stderr, "%s: no demo-mode command has been specified.\n",
888 do_prefs (saver_screen_info *ssi)
890 saver_info *si = ssi->global;
891 saver_preferences *p = &si->prefs;
892 const char *cmd = p->prefs_command;
894 if (command && *command)
895 fork_and_exec (ssi, cmd);
897 fprintf (stderr, "%s: no preferences command has been specified.\n",
900 #endif /* PREFS_BUTTON */
903 do_help (saver_screen_info *ssi)
905 saver_info *si = ssi->global;
906 saver_preferences *p = &si->prefs;
907 char *help_command = 0;
909 if (!p->load_url_command || !*p->load_url_command)
911 fprintf (stderr, "%s: no URL command has been specified.\n", blurb());
914 if (!p->help_url || !*p->help_url)
916 fprintf (stderr, "%s: no Help URL has been specified.\n", blurb());
920 help_command = (char *) malloc (strlen (p->load_url_command) +
921 (strlen (p->help_url) * 4) + 10);
922 sprintf (help_command, p->load_url_command,
923 p->help_url, p->help_url, p->help_url, p->help_url);
925 fork_and_exec (ssi, help_command);