~ubuntu-branches/ubuntu/dapper/xscreensaver/dapper-updates

« back to all changes in this revision

Viewing changes to hacks/spotlight.c

  • Committer: Bazaar Package Importer
  • Author(s): Ralf Hildebrandt
  • Date: 2005-04-09 00:06:43 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20050409000643-z0abtifbt9s20pcc
Tags: 4.21-3
Patch by Joachim Breitner to check more frequently if DPMS kicked in (closes: #303374, #286664).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * spotlight - an xscreensaver module
3
 
 * Copyright (c) 1999 Rick Schultz <rick@skapunx.net>
 
3
 * Copyright (c) 1999, 2001 Rick Schultz <rick@skapunx.net>
4
4
 *
5
5
 * loosely based on the BackSpace module "StefView" by Darcy Brockbank
6
6
 */
8
8
/* modified from a module from the xscreensaver distribution */
9
9
 
10
10
/*
11
 
 * xscreensaver, Copyright (c) 1992, 1993, 1994, 1996, 1997, 1998
 
11
 * xscreensaver, Copyright (c) 1992, 1993, 1994, 1996, 1997, 1998, 2005
12
12
 * Jamie Zawinski <jwz@jwz.org>
13
13
 *
14
14
 * Permission to use, copy, modify, distribute, and sell this software and its
50
50
static int x, y, s;      /* x & y coords of buffer (upper left corner) */
51
51
                         /* s is the width of the buffer */
52
52
 
 
53
static int off = 0;     /* random offset from currentTimeInMs(), so that
 
54
                           two concurrent copies of spotlight have different
 
55
                           behavior. */
 
56
 
53
57
static int oldx, oldy, max_x_speed, max_y_speed;
54
58
                         /* used to keep the new buffer position
55
59
                            over the old spotlight image to make sure 
93
97
  radius = get_integer_resource ("radius", "Integer");
94
98
  if (radius < 0) radius = 125;
95
99
 
 
100
  /* Don't let the spotlight be bigger than 1/4 of the window */
 
101
  if (radius > xgwa.width  / 4) radius = xgwa.width  / 4;
 
102
  if (radius > xgwa.height / 4) radius = xgwa.height / 4;
 
103
 
96
104
  /* do the dance */
97
105
  gcv.function = GXcopy;
98
106
  gcv.subwindow_mode = IncludeInferiors;
105
113
#endif
106
114
  window_gc = XCreateGC(dpy, window, gcflags, &gcv);
107
115
 
108
 
 
109
 
  /* grab screen to window */
110
 
  grab_screen_image(xgwa.screen, window);
111
 
 
112
 
  /* save screen to pixmap for copying later */
 
116
  /* grab screen to pixmap */
113
117
  pm = XCreatePixmap(dpy, window, sizex, sizey, xgwa.depth);
114
 
  XCopyArea(dpy, window, pm, window_gc, 0, 0, sizex, sizey, 0, 0);
115
 
 
 
118
  load_random_image (xgwa.screen, window, pm, NULL, NULL);
 
119
  XClearWindow(dpy, window);
 
120
  XFlush (dpy);
116
121
 
117
122
  /* create buffer to reduce flicker */
118
123
  buffer = XCreatePixmap(dpy, window, sizex, sizey, xgwa.depth);
143
148
 
144
149
  /* avoid remants */
145
150
  max_x_speed = max_y_speed = radius;
 
151
  
 
152
  off = random();
146
153
 
147
154
#ifdef DEBUG
148
155
  /* create GC with white fg */
149
156
  gcv.foreground = fg;
150
157
  white_gc = XCreateGC(dpy, window, gcflags, &gcv);
151
158
#endif
152
 
  
153
 
  /* initialize x and y to avoid initial `jump' across screen */
154
 
  x = ((1 + sin(((float)currentTimeInMs()) / X_PERIOD * 2. * M_PI))/2.0) 
155
 
    * (sizex - s/2) -s/4  + MINX;
156
 
  y = ((1 + sin(((float)currentTimeInMs()) / Y_PERIOD * 2. * M_PI))/2.0) 
157
 
    * (sizey - s/2) -s/4  + MINY;
158
 
 
159
159
}
160
160
 
161
161
 
163
163
 * perform one iteration
164
164
 */
165
165
static void
166
 
onestep (Display *dpy, Window window)
 
166
onestep (Display *dpy, Window window, Bool first_p)
167
167
{
168
168
    long now;
169
169
 
178
178
 
179
179
    s = radius *4 ;   /* s = width of buffer */
180
180
 
181
 
    now = currentTimeInMs();
 
181
    now = currentTimeInMs() + off;
182
182
 
183
183
    /* find new x,y */
184
184
    x = ((1 + sin(((float)now) / X_PERIOD * 2. * M_PI))/2.0) 
186
186
    y = ((1 + sin(((float)now) / Y_PERIOD * 2. * M_PI))/2.0) 
187
187
      * (sizey - s/2) -s/4  + MINY;
188
188
    
189
 
    /* limit change in x and y to buffer width */
190
 
    if ( x < (oldx - max_x_speed) ) x = oldx - max_x_speed;
191
 
    if ( x > (oldx + max_x_speed) ) x = oldx + max_x_speed;
192
 
    if ( y < (oldy - max_y_speed) ) y = oldy - max_y_speed;
193
 
    if ( y > (oldy + max_y_speed) ) y = oldy + max_y_speed;
 
189
    if (!first_p)
 
190
      {
 
191
        /* limit change in x and y to buffer width */
 
192
        if ( x < (oldx - max_x_speed) ) x = oldx - max_x_speed;
 
193
        if ( x > (oldx + max_x_speed) ) x = oldx + max_x_speed;
 
194
        if ( y < (oldy - max_y_speed) ) y = oldy - max_y_speed;
 
195
        if ( y > (oldy + max_y_speed) ) y = oldy + max_y_speed;
 
196
      }
194
197
 
195
198
    /* copy area of screen image (pm) to buffer
196
199
       Clip to a circle */
213
216
char *progclass = "Spotlight";
214
217
 
215
218
char *defaults [] = {
 
219
  ".background:                 black",
 
220
  ".foreground:                 white",
216
221
  "*dontClearRoot:              True",
217
222
 
218
223
#ifdef __sgi    /* really, HAVE_READ_DISPLAY_EXTENSION */
233
238
void
234
239
screenhack (Display *dpy, Window window)
235
240
{
 
241
  Bool first_p = True;
236
242
  init_hack (dpy, window);
237
243
  while (1) {
238
 
    onestep(dpy, window);
 
244
    onestep(dpy, window, first_p);
 
245
    first_p = False;
239
246
    XSync(dpy, False);
240
247
    if (delay) usleep (delay);
241
248
    screenhack_handle_events (dpy);