X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=driver%2Fsplash.c;h=a4f17616e4b46ba0d271bdd7f9d9bbe67f597317;hb=78add6e627ee5f10e1fa6f3852602ea5066eee5a;hp=ead36d7c1c38179eefc5377dc62650bf65b79fb3;hpb=c494fd2e6b3b25582375d62e40f4f5cc984ca424;p=xscreensaver diff --git a/driver/splash.c b/driver/splash.c index ead36d7c..a4f17616 100644 --- a/driver/splash.c +++ b/driver/splash.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1991-2006 Jamie Zawinski +/* xscreensaver, Copyright (c) 1991-2018 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 @@ -17,6 +17,7 @@ #include "xscreensaver.h" #include "resources.h" +#include "font-retry.h" #undef MAX #define MAX(a,b) ((a)>(b)?(a):(b)) @@ -103,6 +104,19 @@ static void do_prefs (saver_screen_info *ssi); static void do_help (saver_screen_info *ssi); +XFontStruct * +splash_load_font (Display *dpy, char *name, char *class) +{ + char *s = get_string_resource (dpy, name, class); + XFontStruct *f; + if (!s || !*s) + s = "-*-helvetica-bold-r-*-*-*-140-*-*-*-*-*-*"; + f = load_font_retry (dpy, s); + if (!f) abort(); + return f; +} + + struct splash_dialog_data { saver_screen_info *prompt_screen; @@ -114,6 +128,8 @@ struct splash_dialog_data { char *heading_label; char *body_label; char *body2_label; + char *body3_label; + char *body4_label; char *demo_label; #ifdef PREFS_BUTTON char *prefs_label; @@ -126,6 +142,7 @@ struct splash_dialog_data { Pixel foreground; Pixel background; + Pixel border; Pixel button_foreground; Pixel button_background; Pixel shadow_top; @@ -155,13 +172,27 @@ struct splash_dialog_data { void make_splash_dialog (saver_info *si) { + saver_preferences *p = &si->prefs; int x, y, bw; XSetWindowAttributes attrs; unsigned long attrmask = 0; splash_dialog_data *sp; saver_screen_info *ssi; Colormap cmap; - char *f; + + Bool whyne = senesculent_p (); + + if (whyne) + { + /* If locking is not enabled, make sure they see the message. */ + if (!p->lock_p) + { + si->prefs.splash_p = True; + if (si->prefs.splash_duration < 5000) + si->prefs.splash_duration = 5000; + } + si->prefs.splash_duration += 3000; + } if (si->sp_data) return; @@ -170,6 +201,10 @@ make_splash_dialog (saver_info *si) return; ssi = &si->screens[mouse_screen (si)]; + + if (!ssi || !ssi->screen) + return; /* WTF? Trying to splash while no screens connected? */ + cmap = DefaultColormapOfScreen (ssi->screen); sp = (splash_dialog_data *) calloc (1, sizeof(*sp)); @@ -196,6 +231,14 @@ make_splash_dialog (saver_info *si) "splash.help.label", "Dialog.Button.Label"); + + + if (whyne) + { + sp->body3_label = strdup("WARNING: This version is very old!"); + sp->body4_label = strdup("Please upgrade!"); + } + if (!sp->heading_label) sp->heading_label = strdup("ERROR: REESOURCES NOT INSTALLED CORRECTLY"); if (!sp->body_label) @@ -216,20 +259,12 @@ make_splash_dialog (saver_info *si) sp->heading_label = s; } - f = get_string_resource (si->dpy, "splash.headingFont", "Dialog.Font"); - sp->heading_font = XLoadQueryFont (si->dpy, (f ? f : "fixed")); - if (!sp->heading_font) sp->heading_font = XLoadQueryFont (si->dpy, "fixed"); - if (f) free (f); - - f = get_string_resource(si->dpy, "splash.bodyFont", "Dialog.Font"); - sp->body_font = XLoadQueryFont (si->dpy, (f ? f : "fixed")); - if (!sp->body_font) sp->body_font = XLoadQueryFont (si->dpy, "fixed"); - if (f) free (f); - - f = get_string_resource(si->dpy, "splash.buttonFont", "Dialog.Font"); - sp->button_font = XLoadQueryFont (si->dpy, (f ? f : "fixed")); - if (!sp->button_font) sp->button_font = XLoadQueryFont (si->dpy, "fixed"); - if (f) free (f); + sp->heading_font = + splash_load_font (si->dpy, "splash.headingFont", "Dialog.Font"); + sp->body_font = + splash_load_font (si->dpy, "splash.bodyFont", "Dialog.Font"); + sp->button_font = + splash_load_font (si->dpy, "splash.buttonFont", "Dialog.Font"); sp->foreground = get_pixel_resource (si->dpy, cmap, "splash.foreground", @@ -237,6 +272,9 @@ make_splash_dialog (saver_info *si) sp->background = get_pixel_resource (si->dpy, cmap, "splash.background", "Dialog.Background"); + sp->border = get_pixel_resource (si->dpy, cmap, + "splash.borderColor", + "Dialog.borderColor"); if (sp->foreground == sp->background) { @@ -304,6 +342,20 @@ make_splash_dialog (saver_info *si) if (overall.width > sp->width) sp->width = overall.width; sp->height += ascent + descent; + /* Measure the optional body3_label. */ + if (sp->body3_label) + { + XTextExtents (sp->heading_font, + sp->body3_label, strlen(sp->body3_label), + &direction, &ascent, &descent, &overall); + if (overall.width > sp->width) sp->width = overall.width; + XTextExtents (sp->heading_font, + sp->body4_label, strlen(sp->body4_label), + &direction, &ascent, &descent, &overall); + if (overall.width > sp->width) sp->width = overall.width; + sp->height += (ascent + descent) * 5; + } + { Dimension w2 = 0, w3 = 0, w4 = 0; Dimension h2 = 0, h3 = 0, h4 = 0; @@ -376,24 +428,12 @@ make_splash_dialog (saver_info *si) attrs.event_mask = (ExposureMask | ButtonPressMask | ButtonReleaseMask); { - int sx, sy, w, h; - int mouse_x = 0, mouse_y = 0; + int sx = 0, sy = 0, w, h; - { - Window pointer_root, pointer_child; - int root_x, root_y, win_x, win_y; - unsigned int mask; - if (XQueryPointer (si->dpy, - RootWindowOfScreen (ssi->screen), - &pointer_root, &pointer_child, - &root_x, &root_y, &win_x, &win_y, &mask)) - { - mouse_x = root_x; - mouse_y = root_y; - } - } - - get_screen_viewport (ssi, &sx, &sy, &w, &h, mouse_x, mouse_y, False); + x = ssi->x; + y = ssi->y; + w = ssi->width; + h = ssi->height; if (si->prefs.debug_p) w /= 2; x = sx + (((w + sp->width) / 2) - sp->width); y = sy + (((h + sp->height) / 2) - sp->height); @@ -413,8 +453,12 @@ make_splash_dialog (saver_info *si) DefaultVisualOfScreen(ssi->screen), attrmask, &attrs); XSetWindowBackground (si->dpy, si->splash_dialog, sp->background); + XSetWindowBorder (si->dpy, si->splash_dialog, sp->border); + - sp->logo_pixmap = xscreensaver_logo (ssi->screen, ssi->current_visual, + sp->logo_pixmap = xscreensaver_logo (ssi->screen, + /* same visual as si->splash_dialog */ + DefaultVisualOfScreen (ssi->screen), si->splash_dialog, cmap, sp->background, &sp->logo_pixels, &sp->logo_npixels, @@ -439,14 +483,13 @@ draw_splash_window (saver_info *si) splash_dialog_data *sp = si->sp_data; XGCValues gcv; GC gc1, gc2; - int hspacing, vspacing, height; + int vspacing, height; int x1, x2, x3, y1, y2; int sw; #ifdef PREFS_BUTTON + int hspacing; int nbuttons = 3; -#else /* !PREFS_BUTTON */ - int nbuttons = 2; #endif /* !PREFS_BUTTON */ height = (sp->heading_font->ascent + sp->heading_font->descent + @@ -495,6 +538,24 @@ draw_splash_window (saver_info *si) sp->body2_label, strlen(sp->body2_label)); y1 += sp->body_font->descent; + if (sp->body3_label) + { + XSetFont (si->dpy, gc1, sp->heading_font->fid); + y1 += sp->heading_font->ascent + sp->heading_font->descent; + y1 += sp->heading_font->ascent; + sw = string_width (sp->heading_font, sp->body3_label); + x2 = (x1 + ((x3 - x1 - sw) / 2)); + XDrawString (si->dpy, si->splash_dialog, gc1, x2, y1, + sp->body3_label, strlen(sp->body3_label)); + y1 += sp->heading_font->descent + sp->heading_font->ascent; + sw = string_width (sp->heading_font, sp->body4_label); + x2 = (x1 + ((x3 - x1 - sw) / 2)); + XDrawString (si->dpy, si->splash_dialog, gc1, x2, y1, + sp->body4_label, strlen(sp->body4_label)); + y1 += sp->heading_font->descent; + XSetFont (si->dpy, gc1, sp->body_font->fid); + } + /* The buttons */ XSetForeground (si->dpy, gc1, sp->button_foreground); @@ -508,9 +569,11 @@ draw_splash_window (saver_info *si) (sp->button_font->ascent + sp->button_font->descent)) / 2) + sp->button_font->ascent); +#ifdef PREFS_BUTTON hspacing = ((sp->width - x1 - (sp->shadow_width * 2) - sp->internal_border - (sp->button_width * nbuttons)) / 2); +#endif x2 = x1 + ((sp->button_width - string_width(sp->button_font, sp->demo_label)) / 2); @@ -659,6 +722,8 @@ destroy_splash_window (saver_info *si) if (sp->heading_label) free (sp->heading_label); if (sp->body_label) free (sp->body_label); if (sp->body2_label) free (sp->body2_label); + if (sp->body3_label) free (sp->body3_label); + if (sp->body4_label) free (sp->body4_label); if (sp->demo_label) free (sp->demo_label); #ifdef PREFS_BUTTON if (sp->prefs_label) free (sp->prefs_label); @@ -704,9 +769,10 @@ void handle_splash_event (saver_info *si, XEvent *event) { splash_dialog_data *sp = si->sp_data; - saver_screen_info *ssi = sp->prompt_screen; + saver_screen_info *ssi; int which = 0; if (!sp) return; + ssi = sp->prompt_screen; switch (event->xany.type) {