Window create_full_screen_window (Display *dpy, int screen, Colormap cmap) { XSetWindowAttributes attrs; Window win; Visual *visual; Screen *screen_obj; unsigned long attrmask; int depth; screen_obj = ScreenOfDisplay (dpy, screen); visual = DefaultVisualOfScreen (screen_obj); depth = visual_depth (screen_obj, visual); attrmask = (CWOverrideRedirect | CWEventMask | CWBackingStore | CWColormap | CWCursor); attrs.override_redirect = True; attrs.event_mask = (ExposureMask | KeyPressMask | ButtonPressMask | Button1MotionMask | ButtonReleaseMask); attrs.backing_store = NotUseful; attrs.colormap = cmap; attrs.cursor = XCreateFontCursor (dpy, XC_cross); win = XCreateWindow (dpy, RootWindowOfScreen (screen_obj), 0, 0, WidthOfScreen (screen_obj), HeightOfScreen (screen_obj), 0, depth, InputOutput, visual, attrmask, &attrs); return win; }
/* Returns a pixmap of the xscreensaver logo. */ Pixmap xscreensaver_logo (Screen *screen, Visual *visual, Drawable drawable, Colormap cmap, unsigned long background_color, unsigned long **pixels_ret, int *npixels_ret, Pixmap *mask_ret, Bool big_p) { Display *dpy = DisplayOfScreen (screen); int depth = visual_depth (screen, visual); int iw, ih; XImage *image; Pixmap p = 0; unsigned char *mask = 0; image = minixpm_to_ximage (dpy, visual, cmap, depth, background_color, (screenlocker_xpm), &iw, &ih, pixels_ret, npixels_ret, (mask_ret ? &mask : 0)); if (image) { XGCValues gcv; GC gc; p = XCreatePixmap (dpy, drawable, iw, ih, depth); gc = XCreateGC (dpy, p, 0, &gcv); XPutImage (dpy, p, gc, image, 0, 0, 0, 0, iw, ih); free (image->data); image->data = 0; XDestroyImage (image); XFreeGC (dpy, gc); if (mask_ret && mask) { *mask_ret = (Pixmap) XCreatePixmapFromBitmapData (dpy, drawable, (char *) mask, iw, ih, 1L, 0L, 1); free (mask); } } return p; }
int main (int argc, char **argv) { enum { PASS, SPLASH, TTY } which; Widget toplevel_shell = 0; saver_screen_info ssip; saver_info sip; saver_info *si = &sip; saver_preferences *p = &si->prefs; struct passwd *pw; memset(&sip, 0, sizeof(sip)); memset(&ssip, 0, sizeof(ssip)); si->nscreens = 1; si->screens = si->default_screen = &ssip; ssip.global = si; global_si_kludge = si; real_stderr = stderr; real_stdout = stdout; si->version = (char *) malloc (5); memcpy (si->version, screensaver_id + 17, 4); si->version[4] = 0; progname = argv[0]; { char *s = strrchr(progname, '/'); if (*s) strcpy (progname, s+1); } if (argc != 2) goto USAGE; else if (!strcmp (argv[1], "pass")) which = PASS; else if (!strcmp (argv[1], "splash")) which = SPLASH; else if (!strcmp (argv[1], "tty")) which = TTY; else { USAGE: fprintf (stderr, "usage: %s [ pass | splash | tty ]\n", progname); exit (1); } #ifdef NO_LOCKING if (which == PASS || which == TTY) { fprintf (stderr, "%s: compiled with NO_LOCKING\n", progname); exit (1); } #endif #ifndef NO_LOCKING /* before hack_uid() for proper permissions */ lock_priv_init (argc, argv, True); hack_uid (si); if (! lock_init (argc, argv, True)) { si->locking_disabled_p = True; si->nolock_reason = "error getting password"; } #endif progclass = "XScreenSaver"; if (!setlocale (LC_CTYPE, "")) fprintf (stderr, "%s: warning: could not set default locale\n", progname); if (which != TTY) { toplevel_shell = XtAppInitialize (&si->app, progclass, 0, 0, &argc, argv, fallback, 0, 0); si->dpy = XtDisplay (toplevel_shell); p->db = XtDatabase (si->dpy); si->default_screen->toplevel_shell = toplevel_shell; si->default_screen->screen = XtScreen(toplevel_shell); si->default_screen->default_visual = si->default_screen->current_visual = DefaultVisualOfScreen(si->default_screen->screen); si->default_screen->screensaver_window = RootWindowOfScreen(si->default_screen->screen); si->default_screen->current_depth = visual_depth(si->default_screen->screen, si->default_screen->current_visual); ssip.width = WidthOfScreen(ssip.screen); ssip.height = HeightOfScreen(ssip.screen); db = p->db; XtGetApplicationNameAndClass (si->dpy, &progname, &progclass); load_init_file (si->dpy, &si->prefs); } p->verbose_p = True; pw = getpwuid (getuid ()); si->user = strdup (pw->pw_name); /* si->nscreens = 0; si->screens = si->default_screen = 0; */ while (1) { #ifndef NO_LOCKING if (which == PASS) { si->unlock_cb = gui_auth_conv; si->auth_finished_cb = auth_finished_cb; debug_passwd_window_p = True; xss_authenticate(si, True); if (si->unlock_state == ul_success) fprintf (stderr, "%s: authentication succeeded\n", progname); else fprintf (stderr, "%s: authentication FAILED!\n", progname); XSync(si->dpy, False); fprintf (stderr, "\n######################################\n\n"); sleep (3); } else #endif if (which == SPLASH) { XEvent event; make_splash_dialog (si); XtAppAddTimeOut (si->app, p->splash_duration + 1000, idle_timer, (XtPointer) si); while (si->splash_dialog) { XtAppNextEvent (si->app, &event); if (event.xany.window == si->splash_dialog) handle_splash_event (si, &event); XtDispatchEvent (&event); } XSync (si->dpy, False); sleep (1); } #ifndef NO_LOCKING else if (which == TTY) { si->unlock_cb = text_auth_conv; printf ("%s: Authenticating user %s\n", progname, si->user); xss_authenticate(si, True); if (si->unlock_state == ul_success) printf ("%s: Ok!\n", progname); else printf ("%s: Wrong!\n", progname); } #endif else abort(); } free(si->user); }
/* Synchronize the contents of si->ssi to the current state of the monitors. Doesn't change anything if nothing has changed; otherwise, alters and reuses existing saver_screen_info structs as much as possible. Returns True if anything changed. */ Bool update_screen_layout (saver_info *si) { monitor **monitors = scan_monitors (si); int count = 0; int good_count = 0; int i, j; int seen_screens[100] = { 0, }; if (! layouts_differ_p (monitors, si->monitor_layout)) { free_monitors (monitors); return False; } free_monitors (si->monitor_layout); si->monitor_layout = monitors; check_monitor_sanity (si->monitor_layout); while (monitors[count]) { if (monitors[count]->sanity == S_SANE) good_count++; count++; } if (si->ssi_count == 0) { si->ssi_count = 10; si->screens = (saver_screen_info *) calloc (sizeof(*si->screens), si->ssi_count); } if (si->ssi_count <= good_count) { si->ssi_count = good_count + 10; si->screens = (saver_screen_info *) realloc (si->screens, sizeof(*si->screens) * si->ssi_count); memset (si->screens + si->nscreens, 0, sizeof(*si->screens) * (si->ssi_count - si->nscreens)); } if (! si->screens) abort(); si->nscreens = good_count; /* Regenerate the list of GL visuals as needed. */ if (si->best_gl_visuals) free (si->best_gl_visuals); si->best_gl_visuals = 0; for (i = 0, j = 0; i < count; i++) { monitor *m = monitors[i]; saver_screen_info *ssi = &si->screens[j]; Screen *old_screen = ssi->screen; int sn; if (monitors[i]->sanity != S_SANE) continue; ssi->global = si; ssi->number = j; sn = screen_number (m->screen); ssi->screen = m->screen; ssi->real_screen_number = sn; ssi->real_screen_p = (seen_screens[sn] == 0); seen_screens[sn]++; ssi->default_visual = get_visual_resource (ssi->screen, "visualID", "VisualID", False); ssi->current_visual = ssi->default_visual; ssi->current_depth = visual_depth (ssi->screen, ssi->current_visual); /* If the screen changed (or if this is the first time) we need a new toplevel shell for this screen's depth. */ if (ssi->screen != old_screen) initialize_screen_root_widget (ssi); ssi->poll_mouse_last_root_x = -1; ssi->poll_mouse_last_root_y = -1; ssi->x = m->x; ssi->y = m->y; ssi->width = m->width; ssi->height = m->height; # ifndef DEBUG_MULTISCREEN { saver_preferences *p = &si->prefs; if (p->debug_p # ifdef QUAD_MODE && !p->quad_p # endif ) ssi->width /= 2; } # endif j++; } si->default_screen = &si->screens[0]; return True; }
static unsigned long moire_draw (Display *dpy, Window window, void *closure) { struct state *st = (struct state *) closure; XGCValues gcv; int chunk_size = 20, ii; if (st->draw_y == 0) { moire_init_1 (st); XGetWindowAttributes (st->dpy, st->window, &st->xgwa); st->draw_xo = (random() % st->xgwa.width) - st->xgwa.width/2; st->draw_yo = (random() % st->xgwa.height) - st->xgwa.height/2; st->draw_factor = (random() % st->offset) + 1; st->depth = visual_depth(DefaultScreenOfDisplay(st->dpy), st->xgwa.visual); # ifdef HAVE_XSHM_EXTENSION if (st->use_shm) { st->draw_image = create_xshm_image(st->dpy, st->xgwa.visual, st->depth, ZPixmap, 0, &st->shm_info, st->xgwa.width, 1); if (!st->draw_image) st->use_shm = False; } # endif /* HAVE_XSHM_EXTENSION */ if (!st->draw_image) { st->draw_image = XCreateImage (st->dpy, st->xgwa.visual, st->depth, ZPixmap, 0, /* depth, format, offset */ 0, st->xgwa.width, 1, 8, 0); /* data, w, h, pad, bpl */ st->draw_image->data = (char *) calloc(st->draw_image->height, st->draw_image->bytes_per_line); } } /* for (y = 0; y < st->xgwa.height; y++) */ for (ii = 0; ii < chunk_size; ii++) { int x; for (x = 0; x < st->xgwa.width; x++) { double xx = x + st->draw_xo; double yy = st->draw_y + st->draw_yo; double i = ((xx * xx) + (yy * yy)) / (double) st->draw_factor; if (mono_p) gcv.foreground = ((((long) i) & 1) ? st->fg_pixel : st->bg_pixel); else gcv.foreground = st->colors[((long) i) % st->ncolors].pixel; XPutPixel (st->draw_image, x, 0, gcv.foreground); } # ifdef HAVE_XSHM_EXTENSION if (st->use_shm) XShmPutImage(st->dpy, st->window, st->gc, st->draw_image, 0, 0, 0, st->draw_y, st->xgwa.width, 1, False); else # endif /* HAVE_XSHM_EXTENSION */ XPutImage (st->dpy, st->window, st->gc, st->draw_image, 0, 0, 0, st->draw_y, st->xgwa.width, 1); st->draw_y++; if (st->draw_y >= st->xgwa.height) break; } if (st->draw_y >= st->xgwa.height) { st->draw_y = 0; # ifdef HAVE_XSHM_EXTENSION if (!st->use_shm) # endif /* HAVE_XSHM_EXTENSION */ if (st->draw_image->data) { free(st->draw_image->data); st->draw_image->data = 0; } # ifdef HAVE_XSHM_EXTENSION if (st->use_shm) destroy_xshm_image (st->dpy, st->draw_image, &st->shm_info); else # endif /* HAVE_XSHM_EXTENSION */ XDestroyImage (st->draw_image); st->draw_image = 0; return st->delay * 1000000; } return st->delay * 10000; }
Bool allocate_alpha_colors (Screen *screen, Visual *visual, Colormap cmap, int *nplanesP, Bool additive_p, unsigned long **plane_masks, unsigned long *base_pixelP , ModeInfo* mi) { #ifdef WIN32 return False; #else Display *dpy = DisplayOfScreen (screen); XColor *colors; int nplanes = *nplanesP; int i; if (!has_writable_cells (mi)) cmap = 0; if (!cmap) /* A TrueColor visual, or similar. */ { int depth = visual_depth (screen, visual); unsigned long masks; XVisualInfo vi_in, *vi_out; /* Find out which bits the R, G, and B components actually occupy on this visual. */ vi_in.screen = screen_number (screen); vi_in.visualid = XVisualIDFromVisual (visual); vi_out = XGetVisualInfo (dpy, VisualScreenMask|VisualIDMask, &vi_in, &i); if (! vi_out) return False; masks = vi_out[0].red_mask | vi_out[0].green_mask | vi_out[0].blue_mask; XFree ((char *) vi_out); if (nplanes > depth) nplanes = depth; *nplanesP = nplanes; *base_pixelP = 0; *plane_masks = (unsigned long *) calloc(sizeof(unsigned long), nplanes); /* Pick the planar values randomly, but constrain them to fall within the bit positions of the R, G, and B fields. */ for (i = 0; i < nplanes; i++) (*plane_masks)[i] = LRAND() & masks; } else /* A PseudoColor visual, or similar. */ { if (nplanes > 31) nplanes = 31; *plane_masks = (unsigned long *) malloc(sizeof(unsigned long) * nplanes); nplanes = allocate_color_planes (dpy, cmap, nplanes, *plane_masks, base_pixelP); *nplanesP = nplanes; if (nplanes <= 1) { free(*plane_masks); *plane_masks = 0; return False; } colors = (XColor *) calloc (nplanes, sizeof (XColor)); for (i = 0; i < nplanes; i++) { /* pick the base colors. If we are in subtractive mode, pick higher intensities. */ hsv_to_rgb (NRAND( 360 ), NRAND( 100000 ) / 100000.0 , NRAND( 100000 ) / 200000.0 + (additive_p ? 0.2 : 0.5), &colors[i].red, &colors[i].green, &colors[i].blue); } initialize_transparency_colormap (dpy, cmap, nplanes, *base_pixelP, *plane_masks, colors, additive_p , mi ); XFree ((XPointer) colors); } return True; #endif }