/* -*- Mode: C; tab-width: 4 -*-
* swirl --- swirly color-cycling patterns.
*/
-#if !defined( lint ) && !defined( SABER )
+#if 0
static const char sccsid[] = "@(#)swirl.c 4.00 97/01/01 xlockmore";
#endif
*/
#ifdef STANDALONE
-# define PROGCLASS "Swirl"
-# define HACK_INIT init_swirl
-# define HACK_DRAW draw_swirl
-# define swirl_opts xlockmore_opts
# define DEFAULTS "*count: 5 \n" \
"*delay: 10000 \n" \
"*ncolors: 200 \n" \
- "*useSHM: True \n"
+ "*useSHM: True \n" \
+ "*fpsSolid: true \n" \
+ "*ignoreRotation: True \n" \
+
# define SMOOTH_COLORS
# define WRITABLE_COLORS
# include "xlockmore.h" /* from the xscreensaver distribution */
-# include <X11/Xutil.h>
# ifdef HAVE_XSHM_EXTENSION
# include "xshm.h"
# endif /* HAVE_XSHM_EXTENSION */
# undef HAVE_XSHM_EXTENSION
#endif /* !STANDALONE */
-ModeSpecOpt swirl_opts = {
+ENTRYPOINT ModeSpecOpt swirl_opts = {
0, NULL, 0, NULL, NULL };
#include <time.h>
*
* - win is the window to draw in
*/
-void
+ENTRYPOINT void
init_swirl(ModeInfo * mi)
{
Display *display = MI_DISPLAY(mi);
/* does the swirls array exist? */
if (swirls == NULL) {
- int i;
-
/* allocate an array, one entry for each screen */
- swirls = (SWIRL_P) calloc(ScreenCount(display), sizeof (SWIRL));
-
- /* initialise them all */
- for (i = 0; i < ScreenCount(display); i++)
- initialise_swirl(mi, &swirls[i]);
+ swirls = (SWIRL_P) calloc(MI_NUM_SCREENS(mi), sizeof (SWIRL));
}
/* get a pointer to this swirl */
swirl = &(swirls[MI_SCREEN(mi)]);
-
- /* get window parameters */
+ initialise_swirl(mi, swirl);
+
+ /* get window parameters */
swirl->win = window;
swirl->width = MI_WIN_WIDTH(mi);
swirl->height = MI_WIN_HEIGHT(mi);
*
* - win is the window to draw in
*/
-void
+ENTRYPOINT void
draw_swirl(ModeInfo * mi)
{
SWIRL_P swirl = &(swirls[MI_SCREEN(mi)]);
if (swirl->drawing) {
#ifdef STANDALONE
if (mi->writable_p)
- rotate_colors(MI_DISPLAY(mi), MI_COLORMAP(mi),
+ rotate_colors(mi->xgwa.screen, MI_COLORMAP(mi),
swirl->rgb_values, swirl->colours, 1);
#else /* !STANDALONE */
- /* rotate the colours */
- install_map(MI_DISPLAY(mi), swirl, swirl->dshift);
+ /* rotate the colours */
+ install_map(MI_DISPLAY(mi), swirl, swirl->dshift);
#endif /* !STANDALONE */
- /* draw a batch of points */
- swirl->batch_todo = BATCH_DRAW;
- while ((swirl->batch_todo > 0) && swirl->drawing) {
- /* draw a point */
- draw_point(mi, swirl);
+ /* draw a batch of points */
+ swirl->batch_todo = BATCH_DRAW;
+ while ((swirl->batch_todo > 0) && swirl->drawing) {
+ /* draw a point */
+ draw_point(mi, swirl);
- /* move to the next point */
- next_point(swirl);
+ /* move to the next point */
+ next_point(swirl);
- /* done a point */
- swirl->batch_todo--;
- }
+ /* done a point */
+ swirl->batch_todo--;
+ }
} else {
#ifdef STANDALONE
if (mi->writable_p)
- rotate_colors(MI_DISPLAY(mi), MI_COLORMAP(mi),
+ rotate_colors(mi->xgwa.screen, MI_COLORMAP(mi),
swirl->rgb_values, swirl->colours, 1);
#else /* !STANDALONE */
- /* rotate the colours */
- install_map(MI_DISPLAY(mi), swirl, swirl->shift);
+ /* rotate the colours */
+ install_map(MI_DISPLAY(mi), swirl, swirl->shift);
#endif /* !STANDALONE */
- /* time for a higher resolution? */
- if (swirl->resolution > swirl->max_resolution) {
- /* move to higher resolution */
- swirl->resolution--;
-
- /* calculate the pixel step for this resulution */
- swirl->r = (1 << (swirl->resolution - 1));
-
- /* start drawing again */
- swirl->drawing = True;
-
- /* start in the middle of the screen */
- swirl->x = (swirl->width - swirl->r) / 2;
- swirl->y = (swirl->height - swirl->r) / 2;
-
- /* initialise spiral drawing parameters */
- swirl->direction = DRAW_RIGHT;
- swirl->dir_todo = 1;
- swirl->dir_done = 0;
- } else {
- /* all done, decide when to restart */
- if (swirl->start_again == -1) {
- /* start the counter */
- swirl->start_again = RESTART;
- } else if (swirl->start_again == 0) {
- /* reset the counter */
- swirl->start_again = -1;
+ /* time for a higher resolution? */
+ if (swirl->resolution > swirl->max_resolution) {
+ /* move to higher resolution */
+ swirl->resolution--;
+
+ /* calculate the pixel step for this resulution */
+ swirl->r = (1 << (swirl->resolution - 1));
+
+ /* start drawing again */
+ swirl->drawing = True;
+
+ /* start in the middle of the screen */
+ swirl->x = (swirl->width - swirl->r) / 2;
+ swirl->y = (swirl->height - swirl->r) / 2;
+
+ /* initialise spiral drawing parameters */
+ swirl->direction = DRAW_RIGHT;
+ swirl->dir_todo = 1;
+ swirl->dir_done = 0;
+ } else {
+ /* all done, decide when to restart */
+ if (swirl->start_again == -1) {
+ /* start the counter */
+ swirl->start_again = RESTART;
+ } else if (swirl->start_again == 0) {
+ /* reset the counter */
+ swirl->start_again = -1;
#ifdef STANDALONE
- /* Pick a new colormap! */
- XClearWindow (MI_DISPLAY(mi), MI_WINDOW(mi));
- free_colors (MI_DISPLAY(mi), MI_COLORMAP(mi),
- mi->colors, mi->npixels);
- make_smooth_colormap (MI_DISPLAY(mi),
- MI_VISUAL(mi),
- MI_COLORMAP(mi),
- mi->colors, &mi->npixels, True,
- &mi->writable_p, True);
- swirl->colours = mi->npixels;
+ /* Pick a new colormap! */
+ XClearWindow (MI_DISPLAY(mi), MI_WINDOW(mi));
+ free_colors (mi->xgwa.screen, MI_COLORMAP(mi),
+ mi->colors, mi->npixels);
+ make_smooth_colormap (mi->xgwa.screen, MI_VISUAL(mi),
+ MI_COLORMAP(mi),
+ mi->colors, &mi->npixels, True,
+ &mi->writable_p, True);
+ swirl->colours = mi->npixels;
#endif /* STANDALONE */
- /* start again */
- init_swirl(mi);
- } else
- /* decrement the counter */
- swirl->start_again--;
- }
+ /* start again */
+ init_swirl(mi);
+ } else
+ /* decrement the counter */
+ swirl->start_again--;
+ }
}
}
}
+ENTRYPOINT void
+reshape_swirl(ModeInfo * mi, int width, int height)
+{
+ XClearWindow (MI_DISPLAY (mi), MI_WINDOW(mi));
+ init_swirl (mi);
+}
+
/****************************************************************/
-void
-release_swirl(ModeInfo * mi)
+ENTRYPOINT void
+release_swirl (ModeInfo * mi)
{
/* does the swirls array exist? */
if (swirls != NULL) {
for (i = 0; i < MI_NUM_SCREENS(mi); i++) {
SWIRL_P swirl = &(swirls[i]);
+#ifndef STANDALONE
if (swirl->cmap != (Colormap) NULL)
XFreeColormap(MI_DISPLAY(mi), swirl->cmap);
+#endif /* STANDALONE */
+#ifndef STANDALONE
if (swirl->rgb_values != NULL)
XFree((void *) swirl->rgb_values);
+#endif /* !STANDALONE */
if (swirl->ximage != NULL)
XDestroyImage(swirl->ximage);
if (swirl->knots)
/****************************************************************/
-void
-refresh_swirl(ModeInfo * mi)
+ENTRYPOINT void
+refresh_swirl (ModeInfo * mi)
{
SWIRL_P swirl = &(swirls[MI_SCREEN(mi)]);
swirl->drawing = False;
}
}
+
+ENTRYPOINT Bool
+swirl_handle_event (ModeInfo *mi, XEvent *event)
+{
+ if (screenhack_event_helper (MI_DISPLAY(mi), MI_WINDOW(mi), event))
+ {
+ reshape_swirl (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
+ return True;
+ }
+ return False;
+}
+
+XSCREENSAVER_MODULE ("Swirl", swirl)