~ubuntu-branches/debian/sid/xscreensaver/sid

« back to all changes in this revision

Viewing changes to hacks/halftone.c

  • Committer: Bazaar Package Importer
  • Author(s): Jose Luis Rivas, Tormod Volden, Jose Luis Rivas
  • Date: 2008-07-15 14:48:48 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080715144848-c6c6mhyxij0dk2p7
Tags: 5.05-3
[ Tormod Volden ]
* debian/patches/10_jwz-xscreensaver-randr-patch-3.patch:
  from upstream, addresses issues with xrandr/xinerama
  (Closes: #482385, #428797, #471920, #453708, #473681, #479715, #480231)
* fixed typo "screen < real_nscreens" in driver/lock:1527 from above patch
* drop 61_DualHead-nVidia_bug471920.patch (obsolete)
* drop 67_XineRama-mode_bug473681.patch (obsolete)
* fix m6502.o typo in hacks/Makefile.in
* refresh 53_XScreenSaver.ad.in.patch
* refresh (disabled) 60_add-ant-hack.patch

[ Jose Luis Rivas ]
* add xscreensaver-demo desktop file, thanks to Daniel Dickinson
  (Closes: #480592)
* update package descriptions (thanks jwz)
* fix categories in xscreensaver.menu
* change build-deps from xlibmesa-gl-dev to libgl1-mesa-dev,
  xutils to xutils-dev, x-dev to x11proto-core-dev.
* bump Standards-Version to 3.8.0
* add Vcs fields and Homepage to debian/control
* Flurry is not installed until the bug get fixed (Closes: #484112)

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#define DEFAULT_MIN_SPEED      0.001
29
29
#define DEFAULT_MAX_SPEED      0.02
30
30
 
31
 
char *progclass = "Halftone";
32
 
 
33
 
char *defaults [] = {
34
 
  "*delay:              10000",
35
 
  "*count:              10",
36
 
  "*minMass:            0.001",
37
 
  "*maxMass:            0.02",
38
 
  "*minSpeed:           0.001",
39
 
  "*maxSpeed:           0.02",
40
 
  "*spacing:            14",
41
 
  "*sizeFactor:         1.5",
42
 
  "*colors:             200",
43
 
  "*cycleSpeed:         10",
44
 
  0
45
 
};
46
 
 
47
 
XrmOptionDescRec options [] = {
48
 
  { "-delay",           ".delay",       XrmoptionSepArg, 0 },
49
 
  { "-count",           ".count",       XrmoptionSepArg, 0 },
50
 
  { "-minmass",         ".minMass",     XrmoptionSepArg, 0 },
51
 
  { "-maxmass",         ".maxMass",     XrmoptionSepArg, 0 },
52
 
  { "-minspeed",        ".minSpeed",    XrmoptionSepArg, 0 },
53
 
  { "-maxspeed",        ".maxSpeed",    XrmoptionSepArg, 0 },
54
 
  { "-spacing",         ".spacing",     XrmoptionSepArg, 0 },
55
 
  { "-sizefactor",      ".sizeFactor",  XrmoptionSepArg, 0 },
56
 
  { "-colors",          ".colors",      XrmoptionSepArg, 0 },
57
 
  { "-cycle-speed",     ".cycleSpeed",  XrmoptionSepArg, 0 },
58
 
  { 0, 0, 0, 0 }
59
 
};
60
31
 
61
32
typedef struct
62
33
{
77
48
  double* gravity_point_y_inc;
78
49
 
79
50
  /* X stuff */
80
 
  Display *display;
 
51
  Display *dpy;
81
52
  Window window;
82
53
  GC gc;
83
54
 
91
62
  GC buffer_gc;
92
63
  int buffer_width;
93
64
  int buffer_height;
 
65
 
 
66
  int delay;
 
67
 
94
68
} halftone_screen;
95
69
 
96
70
 
104
78
    if (halftone->buffer_width != -1 &&
105
79
        halftone->buffer_height != -1)
106
80
    {
107
 
      XFreePixmap(halftone->display, halftone->buffer);
108
 
      XFreeGC(halftone->display, halftone->buffer_gc);
 
81
      if (halftone->buffer == halftone->window)
 
82
        XFreePixmap(halftone->dpy, halftone->buffer);
 
83
      XFreeGC(halftone->dpy, halftone->buffer_gc);
109
84
    }
110
85
 
111
86
    halftone->buffer_width = attrs->width;
112
87
    halftone->buffer_height = attrs->height;
113
 
    halftone->buffer = XCreatePixmap(halftone->display, halftone->window, halftone->buffer_width, halftone->buffer_height, attrs->depth);
 
88
#ifdef HAVE_COCOA       /* Don't second-guess Quartz's double-buffering */
 
89
    halftone->buffer = halftone->window;
 
90
#else
 
91
    halftone->buffer = XCreatePixmap(halftone->dpy, halftone->window, halftone->buffer_width, halftone->buffer_height, attrs->depth);
 
92
#endif
114
93
 
115
 
    halftone->buffer_gc = XCreateGC(halftone->display, halftone->buffer, GCForeground|GCBackground, &gc_values);
 
94
    halftone->buffer_gc = XCreateGC(halftone->dpy, halftone->buffer, 0, &gc_values);
116
95
  }
117
96
}
118
97
 
134
113
  }
135
114
}
136
115
 
137
 
static halftone_screen * init_halftone(Display *display, Window window)
 
116
static void *
 
117
halftone_init (Display *dpy, Window window)
138
118
{
139
119
  int x, y, i;
140
120
  int count;
150
130
 
151
131
  halftone = (halftone_screen *) calloc (1, sizeof(halftone_screen));
152
132
 
153
 
  halftone->display = display;
 
133
  halftone->dpy = dpy;
154
134
  halftone->window = window;
155
135
 
156
 
  halftone->gc = XCreateGC (halftone->display, halftone->window, GCForeground | GCBackground, &gc_values);
 
136
  halftone->delay = get_integer_resource (dpy, "delay", "Integer");
 
137
  halftone->delay = (halftone->delay < 0 ? DEFAULT_DELAY : halftone->delay);
 
138
 
 
139
  halftone->gc = XCreateGC (halftone->dpy, halftone->window, 0, &gc_values);
157
140
 
158
141
  halftone->buffer_width = -1;
159
142
  halftone->buffer_height = -1;
160
143
  halftone->dots = NULL;
161
144
 
162
145
  /* Read command line arguments and set all settings. */ 
163
 
  count = get_integer_resource ("count", "Count");
 
146
  count = get_integer_resource (dpy, "count", "Count");
164
147
  halftone->gravity_point_count = count < 1 ? DEFAULT_COUNT : count; 
165
148
 
166
 
  spacing = get_integer_resource ("spacing", "Integer");
 
149
  spacing = get_integer_resource (dpy, "spacing", "Integer");
167
150
  halftone->spacing = spacing < 1 ? DEFAULT_SPACING : spacing; 
168
151
 
169
 
  factor = get_float_resource ("sizeFactor", "Double");
 
152
  factor = get_float_resource (dpy, "sizeFactor", "Double");
170
153
  halftone->max_dot_size = 
171
154
    (factor < 0 ? DEFAULT_SIZE_FACTOR : factor) * halftone->spacing; 
172
155
 
173
 
  min_mass = get_float_resource ("minMass", "Double");
 
156
  min_mass = get_float_resource (dpy, "minMass", "Double");
174
157
  min_mass = min_mass < 0 ? DEFAULT_MIN_MASS : min_mass;
175
158
 
176
 
  max_mass = get_float_resource ("maxMass", "Double");
 
159
  max_mass = get_float_resource (dpy, "maxMass", "Double");
177
160
  max_mass = max_mass < 0 ? DEFAULT_MAX_MASS : max_mass;
178
161
  max_mass = max_mass < min_mass ? min_mass : max_mass;
179
162
 
180
 
  min_speed = get_float_resource ("minSpeed", "Double");
 
163
  min_speed = get_float_resource (dpy, "minSpeed", "Double");
181
164
  min_speed = min_speed < 0 ? DEFAULT_MIN_SPEED : min_speed;
182
165
 
183
 
  max_speed = get_float_resource ("maxSpeed", "Double");
 
166
  max_speed = get_float_resource (dpy, "maxSpeed", "Double");
184
167
  max_speed = max_speed < 0 ? DEFAULT_MAX_SPEED : max_speed;
185
168
  max_speed = max_speed < min_speed ? min_speed : max_speed;
186
169
 
203
186
 
204
187
 
205
188
  /* Set up the dots. */
206
 
  XGetWindowAttributes(halftone->display, halftone->window, &attrs);  
 
189
  XGetWindowAttributes(halftone->dpy, halftone->window, &attrs);  
207
190
 
208
 
  halftone->ncolors = get_integer_resource ("colors", "Colors");
 
191
  halftone->ncolors = get_integer_resource (dpy, "colors", "Colors");
209
192
  if (halftone->ncolors < 4) halftone->ncolors = 4;
210
193
  halftone->colors = (XColor *) calloc(halftone->ncolors, sizeof(XColor));
211
 
  make_smooth_colormap (display, attrs.visual, attrs.colormap,
 
194
  make_smooth_colormap (dpy, attrs.visual, attrs.colormap,
212
195
                        halftone->colors, &halftone->ncolors,
213
196
                        True, 0, False);
214
197
  halftone->color0 = 0;
215
198
  halftone->color1 = halftone->ncolors / 2;
216
 
  halftone->cycle_speed = get_integer_resource ("cycleSpeed", "CycleSpeed");
 
199
  halftone->cycle_speed = get_integer_resource (dpy, "cycleSpeed", "CycleSpeed");
217
200
  halftone->color_tick = 0;
218
201
 
219
202
  update_buffer(halftone, &attrs);
230
213
 
231
214
 
232
215
 
233
 
static void fill_circle(Display *display, Window window, GC gc, int x, int y, int size)
 
216
static void fill_circle(Display *dpy, Window window, GC gc, int x, int y, int size)
234
217
{
235
218
  int start_x = x - (size / 2);
236
219
  int start_y = y - (size / 2);
239
222
  int angle1 = 0;
240
223
  int angle2 = 360 * 64; /* A full circle */
241
224
 
242
 
  XFillArc (display, window, gc,
 
225
  XFillArc (dpy, window, gc,
243
226
            start_x, start_y, width, height,
244
227
            angle1, angle2);
245
228
}
256
239
 
257
240
  
258
241
  /* Fill buffer with background color */
259
 
  XSetForeground (halftone->display, halftone->buffer_gc,
 
242
  XSetForeground (halftone->dpy, halftone->buffer_gc,
260
243
                  halftone->colors[halftone->color0].pixel);
261
 
  XFillRectangle(halftone->display, halftone->buffer, halftone->buffer_gc, 0, 0, halftone->buffer_width, halftone->buffer_height);
 
244
  XFillRectangle(halftone->dpy, halftone->buffer, halftone->buffer_gc, 0, 0, halftone->buffer_width, halftone->buffer_height);
262
245
 
263
246
  /* Draw dots on buffer */
264
 
  XSetForeground (halftone->display, halftone->buffer_gc,
 
247
  XSetForeground (halftone->dpy, halftone->buffer_gc,
265
248
                  halftone->colors[halftone->color1].pixel);
266
249
 
267
250
  if (halftone->color_tick++ >= halftone->cycle_speed)
273
256
 
274
257
  for (x = 0; x < halftone->dots_width; x++)
275
258
    for (y = 0; y < halftone->dots_height; y++)
276
 
      fill_circle(halftone->display, halftone->buffer, halftone->buffer_gc,
 
259
      fill_circle(halftone->dpy, halftone->buffer, halftone->buffer_gc,
277
260
                  x_offset + x * halftone->spacing, y_offset + y * halftone->spacing, 
278
261
                  halftone->max_dot_size * halftone->dots[x + y * halftone->dots_width]);
279
262
 
280
263
  /* Copy buffer to window */
281
 
  XCopyArea(halftone->display, halftone->buffer, halftone->window, halftone->gc, 0, 0, halftone->buffer_width, halftone->buffer_height, 0, 0);
 
264
  if (halftone->buffer != halftone->window)
 
265
    XCopyArea(halftone->dpy, halftone->buffer, halftone->window, halftone->gc, 0, 0, halftone->buffer_width, halftone->buffer_height, 0, 0);
282
266
}
283
267
 
284
268
static double calculate_gravity(halftone_screen *halftone, int x, int y)
310
294
  int x, y, i;
311
295
  XWindowAttributes attrs;
312
296
 
313
 
  XGetWindowAttributes(halftone->display, halftone->window, &attrs);
 
297
  XGetWindowAttributes(halftone->dpy, halftone->window, &attrs);
314
298
 
315
299
  /* Make sure we have a valid buffer */
316
300
  update_buffer(halftone, &attrs);
345
329
}
346
330
 
347
331
 
348
 
void screenhack (Display *display, Window window)
349
 
{
350
 
  halftone_screen *halftone = init_halftone(display, window);
351
 
  int delay = get_integer_resource ("delay", "Integer");
352
 
  delay = (delay < 0 ? DEFAULT_DELAY : delay);
353
 
 
354
 
  while (1)
355
 
    {
356
 
      repaint_halftone(halftone);
357
 
      update_halftone(halftone);
358
 
      screenhack_handle_events (display);
359
 
 
360
 
      if (delay != 0) 
361
 
        usleep (delay);
362
 
    }
363
 
}
 
332
static unsigned long
 
333
halftone_draw (Display *dpy, Window window, void *closure)
 
334
{
 
335
  halftone_screen *halftone = (halftone_screen *) closure;
 
336
 
 
337
  repaint_halftone(halftone);
 
338
  update_halftone(halftone);
 
339
 
 
340
  return halftone->delay;
 
341
}
 
342
 
 
343
 
 
344
static void
 
345
halftone_reshape (Display *dpy, Window window, void *closure, 
 
346
                 unsigned int w, unsigned int h)
 
347
{
 
348
}
 
349
 
 
350
static Bool
 
351
halftone_event (Display *dpy, Window window, void *closure, XEvent *event)
 
352
{
 
353
  return False;
 
354
}
 
355
 
 
356
static void
 
357
halftone_free (Display *dpy, Window window, void *closure)
 
358
{
 
359
  halftone_screen *halftone = (halftone_screen *) closure;
 
360
  free (halftone);
 
361
}
 
362
 
 
363
 
 
364
static const char *halftone_defaults [] = {
 
365
  ".background:         Black",
 
366
  "*delay:              10000",
 
367
  "*count:              10",
 
368
  "*minMass:            0.001",
 
369
  "*maxMass:            0.02",
 
370
  "*minSpeed:           0.001",
 
371
  "*maxSpeed:           0.02",
 
372
  "*spacing:            14",
 
373
  "*sizeFactor:         1.5",
 
374
  "*colors:             200",
 
375
  "*cycleSpeed:         10",
 
376
  0
 
377
};
 
378
 
 
379
static XrmOptionDescRec halftone_options [] = {
 
380
  { "-delay",           ".delay",       XrmoptionSepArg, 0 },
 
381
  { "-count",           ".count",       XrmoptionSepArg, 0 },
 
382
  { "-minmass",         ".minMass",     XrmoptionSepArg, 0 },
 
383
  { "-maxmass",         ".maxMass",     XrmoptionSepArg, 0 },
 
384
  { "-minspeed",        ".minSpeed",    XrmoptionSepArg, 0 },
 
385
  { "-maxspeed",        ".maxSpeed",    XrmoptionSepArg, 0 },
 
386
  { "-spacing",         ".spacing",     XrmoptionSepArg, 0 },
 
387
  { "-sizefactor",      ".sizeFactor",  XrmoptionSepArg, 0 },
 
388
  { "-colors",          ".colors",      XrmoptionSepArg, 0 },
 
389
  { "-cycle-speed",     ".cycleSpeed",  XrmoptionSepArg, 0 },
 
390
  { 0, 0, 0, 0 }
 
391
};
 
392
 
 
393
 
 
394
XSCREENSAVER_MODULE ("Halftone", halftone)