http://ftp.x.org/contrib/applications/xscreensaver-2.34.tar.gz
[xscreensaver] / driver / splash.c
1 /* xscreensaver, Copyright (c) 1991-1998 Jamie Zawinski <jwz@netscape.com>
2  *
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 
9  * implied warranty.
10  */
11
12 #ifdef HAVE_CONFIG_H
13 # include "config.h"
14 #endif
15
16 #include <X11/Intrinsic.h>
17
18 #include "xscreensaver.h"
19 #include "resources.h"
20
21 #undef MAX
22 #define MAX(a,b) ((a)>(b)?(a):(b))
23
24 void
25 draw_shaded_rectangle (Display *dpy, Window window,
26                        int x, int y,
27                        int width, int height,
28                        int thickness,
29                        unsigned long top_color,
30                        unsigned long bottom_color)
31 {
32   XPoint points[4];
33   XGCValues gcv;
34   GC gc1, gc2;
35   if (thickness == 0) return;
36
37   gcv.foreground = top_color;
38   gc1 = XCreateGC (dpy, window, GCForeground, &gcv);
39   gcv.foreground = bottom_color;
40   gc2 = XCreateGC (dpy, window, GCForeground, &gcv);
41
42   points [0].x = x;
43   points [0].y = y;
44   points [1].x = x + width;
45   points [1].y = y;
46   points [2].x = x + width - thickness;
47   points [2].y = y + thickness;
48   points [3].x = x;
49   points [3].y = y + thickness;
50   XFillPolygon (dpy, window, gc1, points, 4, Convex, CoordModeOrigin);
51
52   points [0].x = x;
53   points [0].y = y + thickness;
54   points [1].x = x;
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);
61
62   points [0].x = x + width;
63   points [0].y = y;
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);
71
72   points [0].x = x;
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);
81
82   XFreeGC (dpy, gc1);
83   XFreeGC (dpy, gc2);
84 }
85
86
87 int
88 string_width (XFontStruct *font, char *s)
89 {
90   int direction, ascent, descent;
91   XCharStruct overall;
92   XTextExtents (font, s, strlen(s), &direction, &ascent, &descent, &overall);
93   return overall.width;
94 }
95
96
97 static void
98 send_self_clientmessage (saver_info *si, Atom command)
99 {
100   Display *dpy = si->dpy;
101   Window window = si->default_screen->screensaver_window;
102   XEvent event;
103   event.xany.type = ClientMessage;
104   event.xclient.display = si->dpy;
105   event.xclient.window = window;
106   event.xclient.message_type = XA_SCREENSAVER;
107   event.xclient.format = 32;
108   memset (&event.xclient.data, 0, sizeof(event.xclient.data));
109   event.xclient.data.l[0] = (long) command;
110   if (! XSendEvent (dpy, window, False, 0L, &event))
111     fprintf (stderr, "%s: XSendEvent(dpy, 0x%x ...) failed.\n",
112              progname, (unsigned int) window);
113 }
114
115
116 static void
117 get_help (saver_info *si)
118 {
119   saver_preferences *p = &si->prefs;
120
121   if (!p->help_url || !*p->help_url)
122     fprintf (stderr, "%s: no Help URL has been specified.\n", blurb());
123   else if (!p->load_url_command || !*p->load_url_command)
124     fprintf (stderr, "%s: no URL-loading command has been specified.\n",
125              blurb());
126   else
127     {
128       char *buf = (char *) malloc (strlen(p->load_url_command) +
129                                    (strlen(p->help_url) * 2) + 10);
130       sprintf (buf, p->load_url_command, p->help_url, p->help_url);
131       system (buf);
132     }
133 }
134
135 static void update_splash_window (saver_info *si);
136 static void draw_splash_window (saver_info *si);
137 static void destroy_splash_window (saver_info *si);
138 static void unsplash_timer (XtPointer closure, XtIntervalId *id);
139
140
141 struct splash_dialog_data {
142   XtIntervalId timer;
143
144   Dimension width;
145   Dimension height;
146
147   char *heading_label;
148   char *body_label;
149   char *body2_label;
150   char *demo_label;
151   char *prefs_label;
152   char *help_label;
153
154   XFontStruct *heading_font;
155   XFontStruct *body_font;
156   XFontStruct *button_font;
157
158   Pixel foreground;
159   Pixel background;
160   Pixel button_foreground;
161   Pixel button_background;
162   Pixel logo_foreground;
163   Pixel logo_background;
164   Pixel shadow_top;
165   Pixel shadow_bottom;
166
167   Dimension logo_width;
168   Dimension logo_height;
169   Dimension internal_border;
170   Dimension shadow_width;
171
172   Dimension button_width, button_height;
173   Dimension demo_button_x, demo_button_y;
174   Dimension prefs_button_x, prefs_button_y;
175   Dimension help_button_x, help_button_y;
176
177   int pressed;
178 };
179
180
181 void
182 make_splash_dialog (saver_info *si)
183 {
184   int x, y, bw;
185   XSetWindowAttributes attrs;
186   unsigned long attrmask = 0;
187   splash_dialog_data *sp;
188   Screen *screen = si->default_screen->screen;
189   Colormap cmap = DefaultColormapOfScreen (screen);
190   char *f;
191
192   if (si->sp_data)
193     return;
194   if (si->prefs.splash_duration <= 0)
195     return;
196
197   sp = (splash_dialog_data *) calloc (1, sizeof(*sp));
198
199   sp->heading_label = get_string_resource ("splash.heading.label",
200                                            "Dialog.Label.Label");
201   sp->body_label = get_string_resource ("splash.body.label",
202                                         "Dialog.Label.Label");
203   sp->body2_label = get_string_resource ("splash.body2.label",
204                                          "Dialog.Label.Label");
205   sp->demo_label = get_string_resource ("splash.demo.label",
206                                         "Dialog.Button.Label");
207   sp->prefs_label = get_string_resource ("splash.prefs.label",
208                                         "Dialog.Button.Label");
209   sp->help_label = get_string_resource ("splash.help.label",
210                                         "Dialog.Button.Label");
211
212   if (!sp->heading_label)
213     sp->heading_label = strdup("ERROR: REESOURCES NOT INSTALLED CORRECTLY");
214   if (!sp->body_label)
215     sp->body_label = strdup("ERROR: REESOURCES NOT INSTALLED CORRECTLY");
216   if (!sp->body2_label)
217     sp->body2_label = strdup("ERROR: REESOURCES NOT INSTALLED CORRECTLY");
218   if (!sp->demo_label) sp->demo_label = strdup("ERROR");
219   if (!sp->prefs_label) sp->prefs_label = strdup("ERROR");
220   if (!sp->help_label) sp->help_label = strdup("ERROR");
221
222   /* Put the version number in the label. */
223   {
224     char *s = (char *) malloc (strlen(sp->heading_label) + 20);
225     sprintf(s, sp->heading_label, si->version);
226     free (sp->heading_label);
227     sp->heading_label = s;
228   }
229
230   f = get_string_resource ("splash.headingFont", "Dialog.Font");
231   sp->heading_font = XLoadQueryFont (si->dpy, (f ? f : "fixed"));
232   if (!sp->heading_font) sp->heading_font = XLoadQueryFont (si->dpy, "fixed");
233   if (f) free (f);
234
235   f = get_string_resource("splash.bodyFont", "Dialog.Font");
236   sp->body_font = XLoadQueryFont (si->dpy, (f ? f : "fixed"));
237   if (!sp->body_font) sp->body_font = XLoadQueryFont (si->dpy, "fixed");
238   if (f) free (f);
239
240   f = get_string_resource("splash.buttonFont", "Dialog.Font");
241   sp->button_font = XLoadQueryFont (si->dpy, (f ? f : "fixed"));
242   if (!sp->button_font) sp->button_font = XLoadQueryFont (si->dpy, "fixed");
243   if (f) free (f);
244
245   sp->foreground = get_pixel_resource ("splash.foreground",
246                                        "Dialog.Foreground",
247                                        si->dpy, cmap);
248   sp->background = get_pixel_resource ("splash.background",
249                                        "Dialog.Background",
250                                        si->dpy, cmap);
251
252   if (sp->foreground == sp->background)
253     {
254       /* Make sure the error messages show up. */
255       sp->foreground = BlackPixelOfScreen (screen);
256       sp->background = WhitePixelOfScreen (screen);
257     }
258
259   sp->button_foreground = get_pixel_resource ("splash.Button.foreground",
260                                               "Dialog.Button.Foreground",
261                                               si->dpy, cmap);
262   sp->button_background = get_pixel_resource ("splash.Button.background",
263                                               "Dialog.Button.Background",
264                                               si->dpy, cmap);
265   sp->logo_foreground = get_pixel_resource ("splash.logo.foreground",
266                                             "Dialog.Logo.Foreground",
267                                             si->dpy, cmap);
268   sp->logo_background = get_pixel_resource ("splash.logo.background",
269                                             "Dialog.Logo.Background",
270                                             si->dpy, cmap);
271   sp->shadow_top = get_pixel_resource ("splash.topShadowColor",
272                                        "Dialog.Foreground",
273                                        si->dpy, cmap);
274   sp->shadow_bottom = get_pixel_resource ("splash.bottomShadowColor",
275                                           "Dialog.Background",
276                                           si->dpy, cmap);
277
278   sp->logo_width = get_integer_resource ("splash.logo.width",
279                                          "Dialog.Logo.Width");
280   sp->logo_height = get_integer_resource ("splash.logo.height",
281                                           "Dialog.Logo.Height");
282   sp->internal_border = get_integer_resource ("splash.internalBorderWidth",
283                                               "Dialog.InternalBorderWidth");
284   sp->shadow_width = get_integer_resource ("splash.shadowThickness",
285                                            "Dialog.ShadowThickness");
286
287   if (sp->logo_width == 0)  sp->logo_width = 150;
288   if (sp->logo_height == 0) sp->logo_height = 150;
289   if (sp->internal_border == 0) sp->internal_border = 15;
290   if (sp->shadow_width == 0) sp->shadow_width = 4;
291
292   {
293     int direction, ascent, descent;
294     XCharStruct overall;
295
296     sp->width = 0;
297     sp->height = 0;
298
299     /* Measure the heading_label. */
300     XTextExtents (sp->heading_font,
301                   sp->heading_label, strlen(sp->heading_label),
302                   &direction, &ascent, &descent, &overall);
303     if (overall.width > sp->width) sp->width = overall.width;
304     sp->height += ascent + descent;
305
306     /* Measure the body_label. */
307     XTextExtents (sp->body_font,
308                   sp->body_label, strlen(sp->body_label),
309                   &direction, &ascent, &descent, &overall);
310     if (overall.width > sp->width) sp->width = overall.width;
311     sp->height += ascent + descent;
312
313     /* Measure the body2_label. */
314     XTextExtents (sp->body_font,
315                   sp->body2_label, strlen(sp->body2_label),
316                   &direction, &ascent, &descent, &overall);
317     if (overall.width > sp->width) sp->width = overall.width;
318     sp->height += ascent + descent;
319
320     {
321       Dimension w2 = 0, w3 = 0, w4 = 0;
322       Dimension h2 = 0, h3 = 0, h4 = 0;
323
324       /* Measure the Demo button. */
325       XTextExtents (sp->button_font,
326                     sp->demo_label, strlen(sp->demo_label),
327                     &direction, &ascent, &descent, &overall);
328       w2 = overall.width;
329       h2 = ascent + descent;
330
331       /* Measure the Prefs button. */
332       XTextExtents (sp->button_font,
333                     sp->prefs_label, strlen(sp->prefs_label),
334                     &direction, &ascent, &descent, &overall);
335       w3 = overall.width;
336       h3 = ascent + descent;
337
338       /* Measure the Help button. */
339       XTextExtents (sp->button_font,
340                     sp->help_label, strlen(sp->help_label),
341                     &direction, &ascent, &descent, &overall);
342       w4 = overall.width;
343       h4 = ascent + descent;
344
345       w2 = MAX(w2, w3); w2 = MAX(w2, w4);
346       h2 = MAX(h2, h3); h2 = MAX(h2, h4);
347
348       w2 += ((ascent + descent) / 2) + (sp->shadow_width * 2);
349       h2 += ((ascent + descent) / 2) + (sp->shadow_width * 2);
350
351       sp->button_width = w2;
352       sp->button_height = h2;
353
354       w2 *= 3;
355
356       w2 += ((ascent + descent) * 2);  /* for space between buttons */
357
358       if (w2 > sp->width) sp->width = w2;
359       sp->height += h2;
360     }
361
362     sp->width  += (sp->internal_border * 2);
363     sp->height += (sp->internal_border * 3);
364
365     if (sp->logo_height > sp->height)
366       sp->height = sp->logo_height;
367     else if (sp->height > sp->logo_height)
368       sp->logo_height = sp->height;
369
370     sp->logo_width = sp->logo_height;
371
372     sp->width += sp->logo_width;
373   }
374
375   attrmask |= CWOverrideRedirect; attrs.override_redirect = True;
376   attrmask |= CWEventMask;
377   attrs.event_mask = (ExposureMask | ButtonPressMask | ButtonReleaseMask);
378
379   {
380     Dimension w = WidthOfScreen(screen);
381     Dimension h = HeightOfScreen(screen);
382     if (si->prefs.debug_p) w /= 2;
383     x = ((w + sp->width) / 2) - sp->width;
384     y = ((h + sp->height) / 2) - sp->height;
385     if (x < 0) x = 0;
386     if (y < 0) y = 0;
387   }
388
389   bw = get_integer_resource ("splash.borderWidth", "Dialog.BorderWidth");
390
391   si->splash_dialog =
392     XCreateWindow (si->dpy,
393                    RootWindowOfScreen(screen),
394                    x, y, sp->width, sp->height, bw,
395                    DefaultDepthOfScreen (screen), InputOutput,
396                    DefaultVisualOfScreen(screen),
397                    attrmask, &attrs);
398   XSetWindowBackground (si->dpy, si->splash_dialog, sp->background);
399
400   XMapRaised (si->dpy, si->splash_dialog);
401   XSync (si->dpy, False);
402
403   si->sp_data = sp;
404
405   sp->timer = XtAppAddTimeOut (si->app, si->prefs.splash_duration,
406                                unsplash_timer, (XtPointer) si);
407
408   draw_splash_window (si);
409   XSync (si->dpy, False);
410 }
411
412 static void
413 draw_splash_window (saver_info *si)
414 {
415   splash_dialog_data *sp = si->sp_data;
416   XGCValues gcv;
417   GC gc1, gc2;
418   int hspacing, vspacing, height;
419   int x1, x2, x3, y1, y2;
420   int sw;
421
422   height = (sp->heading_font->ascent + sp->heading_font->descent +
423             sp->body_font->ascent + sp->body_font->descent +
424             sp->body_font->ascent + sp->body_font->descent +
425             sp->button_font->ascent + sp->button_font->descent);
426   vspacing = ((sp->height
427                - (4 * sp->shadow_width)
428                - (2 * sp->internal_border)
429                - height) / 5);
430   if (vspacing < 0) vspacing = 0;
431   if (vspacing > (sp->heading_font->ascent * 2))
432     vspacing = (sp->heading_font->ascent * 2);
433             
434   gcv.foreground = sp->foreground;
435   gc1 = XCreateGC (si->dpy, si->splash_dialog, GCForeground, &gcv);
436   gc2 = XCreateGC (si->dpy, si->splash_dialog, GCForeground, &gcv);
437   x1 = sp->logo_width;
438   x3 = sp->width - (sp->shadow_width * 2);
439   y1 = sp->internal_border;
440
441   /* top heading
442    */
443   XSetFont (si->dpy, gc1, sp->heading_font->fid);
444   sw = string_width (sp->heading_font, sp->heading_label);
445   x2 = (x1 + ((x3 - x1 - sw) / 2));
446   y1 += sp->heading_font->ascent;
447   XDrawString (si->dpy, si->splash_dialog, gc1, x2, y1,
448                sp->heading_label, strlen(sp->heading_label));
449   y1 += sp->heading_font->descent;
450
451   /* text below top heading
452    */
453   XSetFont (si->dpy, gc1, sp->body_font->fid);
454   y1 += vspacing + sp->body_font->ascent;
455   sw = string_width (sp->body_font, sp->body_label);
456   x2 = (x1 + ((x3 - x1 - sw) / 2));
457   XDrawString (si->dpy, si->splash_dialog, gc1, x2, y1,
458                sp->body_label, strlen(sp->body_label));
459   y1 += sp->body_font->descent;
460
461   y1 += sp->body_font->ascent;
462   sw = string_width (sp->body_font, sp->body2_label);
463   x2 = (x1 + ((x3 - x1 - sw) / 2));
464   XDrawString (si->dpy, si->splash_dialog, gc1, x2, y1,
465                sp->body2_label, strlen(sp->body2_label));
466   y1 += sp->body_font->descent;
467
468   /* The buttons
469    */
470   XSetForeground (si->dpy, gc1, sp->button_foreground);
471   XSetForeground (si->dpy, gc2, sp->button_background);
472
473 /*  y1 += (vspacing * 2);*/
474   y1 = sp->height - sp->internal_border - sp->button_height;
475
476   x1 += sp->internal_border;
477   y2 = (y1 + ((sp->button_height -
478                (sp->button_font->ascent + sp->button_font->descent))
479               / 2)
480         + sp->button_font->ascent);
481   hspacing = ((sp->width - x1 - (sp->shadow_width * 2) -
482                sp->internal_border - (sp->button_width * 3))
483               / 2);
484
485   x2 = x1 + ((sp->button_width - string_width(sp->button_font, sp->demo_label))
486              / 2);
487   XFillRectangle (si->dpy, si->splash_dialog, gc2, x1, y1,
488                   sp->button_width, sp->button_height);
489   XDrawString (si->dpy, si->splash_dialog, gc1, x2, y2,
490                sp->demo_label, strlen(sp->demo_label));
491   sp->demo_button_x = x1;
492   sp->demo_button_y = y1;
493   
494   x1 += hspacing + sp->button_width;
495   x2 = x1 + ((sp->button_width - string_width(sp->button_font,sp->prefs_label))
496              / 2);
497   XFillRectangle (si->dpy, si->splash_dialog, gc2, x1, y1,
498                   sp->button_width, sp->button_height);
499   XDrawString (si->dpy, si->splash_dialog, gc1, x2, y2,
500                sp->prefs_label, strlen(sp->prefs_label));
501   sp->prefs_button_x = x1;
502   sp->prefs_button_y = y1;
503
504   x1 += hspacing + sp->button_width;
505   x2 = x1 + ((sp->button_width - string_width(sp->button_font,sp->help_label))
506              / 2);
507   XFillRectangle (si->dpy, si->splash_dialog, gc2, x1, y1,
508                   sp->button_width, sp->button_height);
509   XDrawString (si->dpy, si->splash_dialog, gc1, x2, y2,
510                sp->help_label, strlen(sp->help_label));
511   sp->help_button_x = x1;
512   sp->help_button_y = y1;
513
514
515   /* the logo
516    */
517   XSetForeground (si->dpy, gc1, sp->logo_foreground);
518   XSetForeground (si->dpy, gc2, sp->logo_background);
519
520   x1 = sp->shadow_width * 3;
521   y1 = sp->shadow_width * 3;
522   x2 = sp->logo_width - (sp->shadow_width * 6);
523   y2 = sp->logo_height - (sp->shadow_width * 6);
524
525   XFillRectangle (si->dpy, si->splash_dialog, gc2, x1, y1, x2, y2);
526   skull (si->dpy, si->splash_dialog, gc1, gc2,
527          x1 + sp->shadow_width, y1 + sp->shadow_width,
528          x2 - (sp->shadow_width * 2), y2 - (sp->shadow_width * 2));
529
530
531   /* The shadow around the logo
532    */
533   draw_shaded_rectangle (si->dpy, si->splash_dialog,
534                          sp->shadow_width * 2,
535                          sp->shadow_width * 2,
536                          sp->logo_width - (sp->shadow_width * 4),
537                          sp->logo_height - (sp->shadow_width * 4),
538                          sp->shadow_width,
539                          sp->shadow_bottom, sp->shadow_top);
540
541   /* The shadow around the whole window
542    */
543   draw_shaded_rectangle (si->dpy, si->splash_dialog,
544                          0, 0, sp->width, sp->height, sp->shadow_width,
545                          sp->shadow_top, sp->shadow_bottom);
546
547   XFreeGC (si->dpy, gc1);
548   XFreeGC (si->dpy, gc2);
549
550   update_splash_window (si);
551 }
552
553
554 static void
555 update_splash_window (saver_info *si)
556 {
557   splash_dialog_data *sp = si->sp_data;
558   int pressed;
559   if (!sp) return;
560   pressed = sp->pressed;
561
562   /* The shadows around the buttons
563    */
564   draw_shaded_rectangle (si->dpy, si->splash_dialog,
565                          sp->demo_button_x, sp->demo_button_y,
566                          sp->button_width, sp->button_height, sp->shadow_width,
567                          (pressed == 1 ? sp->shadow_bottom : sp->shadow_top),
568                          (pressed == 1 ? sp->shadow_top : sp->shadow_bottom));
569   draw_shaded_rectangle (si->dpy, si->splash_dialog,
570                          sp->prefs_button_x, sp->prefs_button_y,
571                          sp->button_width, sp->button_height, sp->shadow_width,
572                          (pressed == 2 ? sp->shadow_bottom : sp->shadow_top),
573                          (pressed == 2 ? sp->shadow_top : sp->shadow_bottom));
574   draw_shaded_rectangle (si->dpy, si->splash_dialog,
575                          sp->help_button_x, sp->help_button_y,
576                          sp->button_width, sp->button_height, sp->shadow_width,
577                          (pressed == 3 ? sp->shadow_bottom : sp->shadow_top),
578                          (pressed == 3 ? sp->shadow_top : sp->shadow_bottom));
579 }
580
581 static void
582 destroy_splash_window (saver_info *si)
583 {
584   splash_dialog_data *sp = si->sp_data;
585   Screen *screen = si->default_screen->screen;
586   Colormap cmap = DefaultColormapOfScreen (screen);
587   Pixel black = BlackPixelOfScreen (screen);
588   Pixel white = WhitePixelOfScreen (screen);
589
590   if (sp->timer)
591     XtRemoveTimeOut (sp->timer);
592
593   if (si->splash_dialog)
594     {
595       XDestroyWindow (si->dpy, si->splash_dialog);
596       si->splash_dialog = 0;
597     }
598   
599   if (sp->heading_label) free (sp->heading_label);
600   if (sp->body_label)    free (sp->body_label);
601   if (sp->demo_label)    free (sp->demo_label);
602   if (sp->prefs_label)   free (sp->prefs_label);
603   if (sp->help_label)    free (sp->help_label);
604
605   if (sp->heading_font) XFreeFont (si->dpy, sp->heading_font);
606   if (sp->body_font)    XFreeFont (si->dpy, sp->body_font);
607   if (sp->button_font)  XFreeFont (si->dpy, sp->button_font);
608
609   if (sp->foreground != black && sp->foreground != white)
610     XFreeColors (si->dpy, cmap, &sp->foreground, 1, 0L);
611   if (sp->background != black && sp->background != white)
612     XFreeColors (si->dpy, cmap, &sp->background, 1, 0L);
613   if (sp->button_foreground != black && sp->button_foreground != white)
614     XFreeColors (si->dpy, cmap, &sp->button_foreground, 1, 0L);
615   if (sp->button_background != black && sp->button_background != white)
616     XFreeColors (si->dpy, cmap, &sp->button_background, 1, 0L);
617   if (sp->logo_foreground != black && sp->logo_foreground != white)
618     XFreeColors (si->dpy, cmap, &sp->logo_foreground, 1, 0L);
619   if (sp->logo_background != black && sp->logo_background != white)
620     XFreeColors (si->dpy, cmap, &sp->logo_background, 1, 0L);
621   if (sp->shadow_top != black && sp->shadow_top != white)
622     XFreeColors (si->dpy, cmap, &sp->shadow_top, 1, 0L);
623   if (sp->shadow_bottom != black && sp->shadow_bottom != white)
624     XFreeColors (si->dpy, cmap, &sp->shadow_bottom, 1, 0L);
625
626   memset (sp, 0, sizeof(*sp));
627   free (sp);
628
629   si->sp_data = 0;
630 }
631
632 void
633 handle_splash_event (saver_info *si, XEvent *event)
634 {
635   splash_dialog_data *sp = si->sp_data;
636   int which = 0;
637   if (!sp) return;
638
639   switch (event->xany.type)
640     {
641     case Expose:
642       draw_splash_window (si);
643       break;
644
645     case ButtonPress: case ButtonRelease:
646
647       if (event->xbutton.x >= sp->demo_button_x &&
648           event->xbutton.x < sp->demo_button_x + sp->button_width &&
649           event->xbutton.y >= sp->demo_button_y &&
650           event->xbutton.y < sp->demo_button_y + sp->button_height)
651         which = 1;
652
653       else if (event->xbutton.x >= sp->prefs_button_x &&
654                event->xbutton.x < sp->prefs_button_x + sp->button_width &&
655                event->xbutton.y >= sp->prefs_button_y &&
656                event->xbutton.y < sp->prefs_button_y + sp->button_height)
657         which = 2;
658
659       else if (event->xbutton.x >= sp->help_button_x &&
660                event->xbutton.x < sp->help_button_x + sp->button_width &&
661                event->xbutton.y >= sp->help_button_y &&
662                event->xbutton.y < sp->help_button_y + sp->button_height)
663         which = 3;
664
665       if (event->xany.type == ButtonPress)
666         {
667           sp->pressed = which;
668           update_splash_window (si);
669           if (which == 0)
670             XBell (si->dpy, False);
671         }
672       else if (event->xany.type == ButtonRelease)
673         {
674           if (which && sp->pressed == which)
675             {
676               destroy_splash_window (si);
677               switch (which)
678                 {
679                 case 1: send_self_clientmessage (si, XA_DEMO); break;
680                 case 2: send_self_clientmessage (si, XA_PREFS); break;
681                 case 3: get_help (si); break;
682                 default: abort();
683                 }
684             }
685           sp->pressed = 0;
686           update_splash_window (si);
687         }
688       break;
689
690     default:
691       break;
692     }
693 }
694
695 static void
696 unsplash_timer (XtPointer closure, XtIntervalId *id)
697 {
698   saver_info *si = (saver_info *) closure;
699   if (si && si->sp_data)
700     destroy_splash_window (si);
701 }