/** * info_msg and prompt may be NULL. */ static int make_passwd_window (saver_info *si, const char *info_msg, const char *prompt, Bool echo) { passwd_dialog_data *pw; Screen *screen; Colormap cmap; saver_screen_info *ssi = &si->screens [mouse_screen (si)]; cleanup_passwd_window (si); if (! ssi) return -1; /* [email protected] - fix for mirroring with external monitor */ get_current_screen_size(si, ssi); if (!si->pw_data) if (new_passwd_window (si) < 0) return -1; if (!(pw = si->pw_data)) return -1; pw->ratio = 1.0; pw->prompt_screen = ssi; /* [email protected] * Figure out where on the desktop to place the window so that it will * actually be visible and centered with respect to screen */ pw->x = MAX((ssi->width - pw->width) / 2, 0); pw->y = MAX((ssi->height - pw->height) / 2, 0); /* [email protected] - Get the rest of the resources from the config file */ pw->uname_field_x = pw->x + get_integer_resource(si->dpy, "chromeos.username.x", "Integer"); pw->uname_field_y = pw->y + get_integer_resource(si->dpy, "chromeos.username.y", "Integer"); pw->passwd_field_x = pw->x + get_integer_resource(si->dpy, "chromeos.password.x", "Integer"); pw->passwd_field_y = pw->y + get_integer_resource(si->dpy, "chromeos.password.y", "Integer"); if (si->prefs.verbose_p) fprintf (stderr, "%s: %d: creating password dialog (\"%s\")\n", blurb(), pw->prompt_screen->number, info_msg ? info_msg : ""); screen = pw->prompt_screen->screen; cmap = DefaultColormapOfScreen (screen); pw->echo_input = echo; pw->draw_password_prompt = (NULL != prompt); /* Only create the window the first time around */ if (!si->passwd_dialog) { XSetWindowAttributes attrs; unsigned long attrmask = CWOverrideRedirect | CWEventMask; attrs.override_redirect = True; attrs.event_mask = (ExposureMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask); si->passwd_dialog = XCreateWindow (si->dpy, RootWindowOfScreen(screen), ssi->x, ssi->y, ssi->width, ssi->height, 0, DefaultDepthOfScreen (screen), InputOutput, DefaultVisualOfScreen(screen), attrmask, &attrs); XSetWindowBackground (si->dpy, si->passwd_dialog, pw->background); /* We use the default visual, not ssi->visual, so that the logo pixmap's visual matches that of the si->passwd_dialog window. */ pw->logo_pixmap = xscreensaver_logo (ssi->screen, DefaultVisualOfScreen(screen), si->passwd_dialog, cmap, pw->background, &pw->logo_pixels, &pw->logo_npixels, &pw->logo_clipmask, True); } else /* On successive prompts, just resize the window */ { XWindowChanges wc; unsigned int mask = CWX | CWY | CWWidth | CWHeight; wc.x = ssi->x; wc.y = ssi->y; wc.width = ssi->width; wc.height = ssi->height; XConfigureWindow (si->dpy, si->passwd_dialog, mask, &wc); } restore_background(si); XMapRaised (si->dpy, si->passwd_dialog); XSync (si->dpy, False); move_mouse_grab (si, si->passwd_dialog, pw->passwd_cursor, pw->prompt_screen->number); undo_vp_motion (si); si->pw_data = pw; if (cmap) XInstallColormap (si->dpy, cmap); draw_passwd_window (si); return 0; }
void make_splash_dialog (saver_info *si) { int x, y, bw; XSetWindowAttributes attrs; unsigned long attrmask = 0; splash_dialog_data *sp; saver_screen_info *ssi; Colormap cmap; char *f; if (si->sp_data) return; if (!si->prefs.splash_p || si->prefs.splash_duration <= 0) return; ssi = &si->screens[mouse_screen (si)]; cmap = DefaultColormapOfScreen (ssi->screen); sp = (splash_dialog_data *) calloc (1, sizeof(*sp)); sp->prompt_screen = ssi; sp->heading_label = get_string_resource (si->dpy, "splash.heading.label", "Dialog.Label.Label"); sp->body_label = get_string_resource (si->dpy, "splash.body.label", "Dialog.Label.Label"); sp->body2_label = get_string_resource (si->dpy, "splash.body2.label", "Dialog.Label.Label"); sp->demo_label = get_string_resource (si->dpy, "splash.demo.label", "Dialog.Button.Label"); #ifdef PREFS_BUTTON sp->prefs_label = get_string_resource (si->dpy, "splash.prefs.label", "Dialog.Button.Label"); #endif /* PREFS_BUTTON */ sp->help_label = get_string_resource (si->dpy, "splash.help.label", "Dialog.Button.Label"); if (!sp->heading_label) sp->heading_label = strdup("ERROR: REESOURCES NOT INSTALLED CORRECTLY"); if (!sp->body_label) sp->body_label = strdup("ERROR: REESOURCES NOT INSTALLED CORRECTLY"); if (!sp->body2_label) sp->body2_label = strdup("ERROR: REESOURCES NOT INSTALLED CORRECTLY"); if (!sp->demo_label) sp->demo_label = strdup("ERROR"); #ifdef PREFS_BUTTON if (!sp->prefs_label) sp->prefs_label = strdup("ERROR"); #endif /* PREFS_BUTTON */ if (!sp->help_label) sp->help_label = strdup("ERROR"); /* Put the version number in the label. */ { char *s = (char *) malloc (strlen(sp->heading_label) + 20); sprintf(s, sp->heading_label, si->version); free (sp->heading_label); 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->foreground = get_pixel_resource (si->dpy, cmap, "splash.foreground", "Dialog.Foreground"); sp->background = get_pixel_resource (si->dpy, cmap, "splash.background", "Dialog.Background"); if (sp->foreground == sp->background) { /* Make sure the error messages show up. */ sp->foreground = BlackPixelOfScreen (ssi->screen); sp->background = WhitePixelOfScreen (ssi->screen); } sp->button_foreground = get_pixel_resource (si->dpy, cmap, "splash.Button.foreground", "Dialog.Button.Foreground"); sp->button_background = get_pixel_resource (si->dpy, cmap, "splash.Button.background", "Dialog.Button.Background"); sp->shadow_top = get_pixel_resource (si->dpy, cmap, "splash.topShadowColor", "Dialog.Foreground"); sp->shadow_bottom = get_pixel_resource (si->dpy, cmap, "splash.bottomShadowColor", "Dialog.Background"); sp->logo_width = get_integer_resource (si->dpy, "splash.logo.width", "Dialog.Logo.Width"); sp->logo_height = get_integer_resource (si->dpy, "splash.logo.height", "Dialog.Logo.Height"); sp->internal_border = get_integer_resource (si->dpy, "splash.internalBorderWidth", "Dialog.InternalBorderWidth"); sp->shadow_width = get_integer_resource (si->dpy, "splash.shadowThickness", "Dialog.ShadowThickness"); if (sp->logo_width == 0) sp->logo_width = 150; if (sp->logo_height == 0) sp->logo_height = 150; if (sp->internal_border == 0) sp->internal_border = 15; if (sp->shadow_width == 0) sp->shadow_width = 4; { int direction, ascent, descent; XCharStruct overall; sp->width = 0; sp->height = 0; /* Measure the heading_label. */ XTextExtents (sp->heading_font, sp->heading_label, strlen(sp->heading_label), &direction, &ascent, &descent, &overall); if (overall.width > sp->width) sp->width = overall.width; sp->height += ascent + descent; /* Measure the body_label. */ XTextExtents (sp->body_font, sp->body_label, strlen(sp->body_label), &direction, &ascent, &descent, &overall); if (overall.width > sp->width) sp->width = overall.width; sp->height += ascent + descent; /* Measure the body2_label. */ XTextExtents (sp->body_font, sp->body2_label, strlen(sp->body2_label), &direction, &ascent, &descent, &overall); if (overall.width > sp->width) sp->width = overall.width; sp->height += ascent + descent; { Dimension w2 = 0, w3 = 0, w4 = 0; Dimension h2 = 0, h3 = 0, h4 = 0; /* Measure the Demo button. */ XTextExtents (sp->button_font, sp->demo_label, strlen(sp->demo_label), &direction, &ascent, &descent, &overall); w2 = overall.width; h2 = ascent + descent; #ifdef PREFS_BUTTON /* Measure the Prefs button. */ XTextExtents (sp->button_font, sp->prefs_label, strlen(sp->prefs_label), &direction, &ascent, &descent, &overall); w3 = overall.width; h3 = ascent + descent; #else /* !PREFS_BUTTON */ w3 = 0; h3 = 0; #endif /* !PREFS_BUTTON */ /* Measure the Help button. */ XTextExtents (sp->button_font, sp->help_label, strlen(sp->help_label), &direction, &ascent, &descent, &overall); w4 = overall.width; h4 = ascent + descent; w2 = MAX(w2, w3); w2 = MAX(w2, w4); h2 = MAX(h2, h3); h2 = MAX(h2, h4); /* Add some horizontal padding inside the buttons. */ w2 += ascent; w2 += ((ascent + descent) / 2) + (sp->shadow_width * 2); h2 += ((ascent + descent) / 2) + (sp->shadow_width * 2); sp->button_width = w2; sp->button_height = h2; #ifdef PREFS_BUTTON w2 *= 3; #else /* !PREFS_BUTTON */ w2 *= 2; #endif /* !PREFS_BUTTON */ w2 += ((ascent + descent) * 2); /* for space between buttons */ if (w2 > sp->width) sp->width = w2; sp->height += h2; } sp->width += (sp->internal_border * 2); sp->height += (sp->internal_border * 3); if (sp->logo_height > sp->height) sp->height = sp->logo_height; else if (sp->height > sp->logo_height) sp->logo_height = sp->height; sp->logo_width = sp->logo_height; sp->width += sp->logo_width; } attrmask |= CWOverrideRedirect; attrs.override_redirect = True; attrmask |= CWEventMask; attrs.event_mask = (ExposureMask | ButtonPressMask | ButtonReleaseMask); { int sx, sy, w, h; int mouse_x = 0, mouse_y = 0; { 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); if (si->prefs.debug_p) w /= 2; x = sx + (((w + sp->width) / 2) - sp->width); y = sy + (((h + sp->height) / 2) - sp->height); if (x < sx) x = sx; if (y < sy) y = sy; } bw = get_integer_resource (si->dpy, "splash.borderWidth", "Dialog.BorderWidth"); si->splash_dialog = XCreateWindow (si->dpy, RootWindowOfScreen(ssi->screen), x, y, sp->width, sp->height, bw, DefaultDepthOfScreen (ssi->screen), InputOutput, DefaultVisualOfScreen(ssi->screen), attrmask, &attrs); XSetWindowBackground (si->dpy, si->splash_dialog, sp->background); 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, &sp->logo_clipmask, True); XMapRaised (si->dpy, si->splash_dialog); XSync (si->dpy, False); si->sp_data = sp; sp->timer = XtAppAddTimeOut (si->app, si->prefs.splash_duration, unsplash_timer, (XtPointer) si); draw_splash_window (si); XSync (si->dpy, False); }